dgain: Introduce digital gain

This commit is contained in:
Pavel Machek
2024-08-31 22:06:03 +00:00
parent bbc077f528
commit 7c59259f27
5 changed files with 82 additions and 6 deletions

View File

@@ -505,7 +505,6 @@ process_aaa()
int step = 0;
if (direction > 0) {
// Preview is too dark
// Try raising the exposure time first
if (state_proc.exposure.value < state_proc.exposure.max) {
step = state_proc.exposure.value / 4;
@@ -515,19 +514,30 @@ process_aaa()
(step * direction);
printf("Expose + %d\n",
state_proc.exposure.value_req);
} else {
} else if (state_proc.gain.value < state_proc.gain.max) {
// Raise sensor gain if exposure limit is hit
step = state_proc.gain.value / 4;
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);
}
} else {
// Raise sensor gain if exposure limit is hit
step = state_proc.dgain.value / 4;
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);
}
} else if (direction < 0) {
// Preview is too bright
// Lower the sensor gain first to have less noise
if (state_proc.gain.value > 0) {
if (state_proc.dgain.value > 256 /* state_proc.dgain.min FIXME */) {
step = state_proc.dgain.value / 4;
state_proc.dgain.value_req =
state_proc.dgain.value + (step * direction);
printf("D/Gain - %d\n", state_proc.gain.value_req);
} else if (state_proc.gain.value > 0) {
step = state_proc.gain.value / 4;
state_proc.gain.value_req =
state_proc.gain.value + (step * direction);
@@ -544,12 +554,16 @@ process_aaa()
}
clamp_control(&state_proc.gain);
clamp_control(&state_proc.dgain);
clamp_control(&state_proc.exposure);
mp_io_pipeline_set_control_int32(&state_proc.gain.control,
state_proc.gain.value_req);
mp_io_pipeline_set_control_int32(&state_proc.dgain.control,
state_proc.dgain.value_req);
mp_io_pipeline_set_control_int32(&state_proc.exposure.control,
state_proc.exposure.value_req);
state_proc.gain.value = state_proc.gain.value_req;
state_proc.dgain.value = state_proc.dgain.value_req;
state_proc.exposure.value = state_proc.exposure.value_req;
}
@@ -1378,6 +1392,12 @@ update_state(MPPipeline *pipeline, const mp_state_proc *new_state)
state_proc.gain.max = new_state->gain.max;
state_proc.gain.manual = new_state->gain.manual;
state_proc.dgain.control = new_state->dgain.control;
state_proc.dgain.auto_control = new_state->dgain.auto_control;
state_proc.dgain.value = new_state->dgain.value;
state_proc.dgain.max = new_state->dgain.max;
state_proc.dgain.manual = new_state->dgain.manual;
state_proc.exposure.control = new_state->exposure.control;
state_proc.exposure.auto_control = new_state->exposure.auto_control;
state_proc.exposure.value = new_state->exposure.value;
@@ -1453,6 +1473,13 @@ update_state(MPPipeline *pipeline, const mp_state_proc *new_state)
.gain.max = state_proc.gain.max,
.gain.manual = state_proc.gain.manual,
.dgain.control = state_proc.dgain.control,
.dgain.auto_control = state_proc.dgain.auto_control,
.dgain.value = state_proc.dgain.value,
.dgain.value_req = state_proc.dgain.value_req,
.dgain.max = state_proc.dgain.max,
.dgain.manual = state_proc.dgain.manual,
.exposure.control = state_proc.exposure.control,
.exposure.auto_control = state_proc.exposure.auto_control,
.exposure.value = state_proc.exposure.value,