auto: use common functions when possible.

This commit is contained in:
Pavel Machek
2024-09-03 13:54:23 +02:00
parent dcc73a1647
commit 8af8441bbd

View File

@@ -450,10 +450,7 @@ static void auto_focus_step(const struct focus_stats *stats)
focus += 10; focus += 10;
set: set:
state_proc.focus.value_req = focus; state_proc.focus.value_req = focus;
clamp_control(&state_proc.focus); update_control(&state_proc.focus);
mp_io_pipeline_set_control_int32(&state_proc.focus.control,
state_proc.focus.value_req);
state_proc.focus.value = state_proc.focus.value_req;
} }
static void static void
@@ -476,6 +473,16 @@ focus_stats(struct focus_stats *stats, const unsigned int *frame, const int widt
stats->sharp = sharp; stats->sharp = sharp;
} }
static void update_exp(controlstate *control, int direction)
{
int step = 0;
int min_step = 4;
step = control->value / 4;
step = step < min_step ? min_step : step;
control->value_req = control->value + (step * direction);
}
static void static void
process_aaa() process_aaa()
{ {
@@ -510,52 +517,34 @@ process_aaa()
if (auto_exposure) { if (auto_exposure) {
int direction = state_proc.stats.exposure; int direction = state_proc.stats.exposure;
int step = 0;
if (direction > 0) { if (direction > 0) {
// Preview is too dark // Preview is too dark
// Try raising the exposure time first // Try raising the exposure time first
if (state_proc.exposure.value < state_proc.exposure.max) { if (state_proc.exposure.value < state_proc.exposure.max) {
step = state_proc.exposure.value / 4; update_exp(&state_proc.exposure, direction);
step = step < 4 ? 4 : step;
state_proc.exposure.value_req =
state_proc.exposure.value +
(step * direction);
printf("Expose + %d\n", printf("Expose + %d\n",
state_proc.exposure.value_req); state_proc.exposure.value_req);
} else if (state_proc.gain.value < state_proc.gain.max) { } else if (state_proc.gain.value < state_proc.gain.max) {
// Raise sensor gain if exposure limit is hit // Raise sensor gain if exposure limit is hit
step = state_proc.gain.value / 4; update_exp(&state_proc.gain, direction);
step = step < 4 ? 4 : step;
state_proc.gain.value_req =
state_proc.gain.value + (step * direction);
printf("Gain + %d\n", state_proc.gain.value_req); printf("Gain + %d\n", state_proc.gain.value_req);
} else { } else {
// Raise sensor gain if exposure limit is hit // Raise sensor dgain if out of ananlog gain
step = state_proc.dgain.value / 4; update_exp(&state_proc.dgain, direction);
step = step < 4 ? 4 : step;
state_proc.dgain.value_req =
state_proc.dgain.value + (step * direction);
printf("D/Gain + %d\n", state_proc.dgain.value_req); printf("D/Gain + %d\n", state_proc.dgain.value_req);
} }
} else if (direction < 0) { } else if (direction < 0) {
// Preview is too bright // Preview is too bright
// Lower the sensor gain first to have less noise // Lower the sensor gain first to have less noise
if (state_proc.dgain.value > 256 /* state_proc.dgain.min FIXME */) { if (state_proc.dgain.value > 256 /* state_proc.dgain.min FIXME */) {
step = state_proc.dgain.value / 4; update_exp(&state_proc.dgain, direction);
state_proc.dgain.value_req =
state_proc.dgain.value + (step * direction);
printf("D/Gain - %d\n", state_proc.gain.value_req); printf("D/Gain - %d\n", state_proc.gain.value_req);
} else if (state_proc.gain.value > 0) { } else if (state_proc.gain.value > 0) {
step = state_proc.gain.value / 4; update_exp(&state_proc.gain, direction);
state_proc.gain.value_req =
state_proc.gain.value + (step * direction);
printf("Gain - %d\n", state_proc.gain.value_req); printf("Gain - %d\n", state_proc.gain.value_req);
} else { } else {
// Shorten the exposure time to go even darker // Shorten the exposure time to go even darker
step = state_proc.exposure.value / 4; update_exp(&state_proc.exposure, direction);
state_proc.exposure.value_req =
state_proc.exposure.value +
(step * direction);
printf("Expose - %d\n", printf("Expose - %d\n",
state_proc.exposure.value_req); state_proc.exposure.value_req);
} }