Browse Source

auto: use common functions when possible.

Pavel Machek 6 months ago
parent
commit
8af8441bbd
1 changed files with 18 additions and 29 deletions
  1. 18 29
      src/process_pipeline.c

+ 18 - 29
src/process_pipeline.c

@@ -450,10 +450,7 @@ static void auto_focus_step(const struct focus_stats *stats)
 	focus += 10;
  set:
 	state_proc.focus.value_req = focus;
-	clamp_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;
+	update_control(&state_proc.focus);
 }
 
 static void
@@ -476,6 +473,16 @@ focus_stats(struct focus_stats *stats, const unsigned int *frame, const int widt
 	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
 process_aaa()
 {
@@ -510,52 +517,34 @@ process_aaa()
 
         if (auto_exposure) {
                 int direction = state_proc.stats.exposure;
-                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;
-                                step = step < 4 ? 4 : step;
-                                state_proc.exposure.value_req =
-                                        state_proc.exposure.value +
-                                        (step * direction);
+				update_exp(&state_proc.exposure, direction);
                                 printf("Expose + %d\n",
                                        state_proc.exposure.value_req);
                         } 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);
+				update_exp(&state_proc.gain, 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);
+                                // Raise sensor dgain if out of ananlog gain
+				update_exp(&state_proc.dgain, 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.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);
+				update_exp(&state_proc.dgain, 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);
+				update_exp(&state_proc.gain, direction);
                                 printf("Gain - %d\n", state_proc.gain.value_req);
                         } else {
                                 // Shorten the exposure time to go even darker
-                                step = state_proc.exposure.value / 4;
-                                state_proc.exposure.value_req =
-                                        state_proc.exposure.value +
-                                        (step * direction);
+				update_exp(&state_proc.exposure, direction);
                                 printf("Expose - %d\n",
                                        state_proc.exposure.value_req);
                         }