Browse Source

Close the AAA loop

Martijn Braam 1 year ago
parent
commit
16dfb9ba19
3 changed files with 61 additions and 51 deletions
  1. 21 23
      src/io_pipeline.c
  2. 36 28
      src/main.c
  3. 4 0
      src/process_pipeline.c

+ 21 - 23
src/io_pipeline.c

@@ -103,28 +103,6 @@ update_process_pipeline()
                 .balance = { balance_red, 1.0f, balance_blue },
         };
 
-        struct mp_process_pipeline_state pipeline_state = {
-                .camera = state_io.camera,
-                .configuration = state_io.configuration,
-                .burst_length = state_io.burst_length,
-                .preview_width = state_io.preview_width,
-                .preview_height = state_io.preview_height,
-                .device_rotation = state_io.device_rotation,
-                .gain_is_manual = state_io.gain.manual,
-                .gain = state_io.gain.value,
-                .gain_max = state_io.gain.max,
-                .balance_red = balance_red,
-                .balance_blue = balance_blue,
-                .exposure_is_manual = state_io.exposure.manual,
-                .exposure = state_io.exposure.value,
-                .has_auto_focus_continuous = state_io.focus.control != 0,
-                .has_auto_focus_start = state_io.can_af_trigger,
-                .flash_enabled = state_io.flash_enabled,
-                .control_gain = state_io.gain.control != 0,
-                .control_exposure = state_io.exposure.control != 0,
-                .control_focus = state_io.focus.control != 0,
-                .control_flash = true,
-        };
         mp_process_pipeline_update_state(&new_state);
 }
 
@@ -242,7 +220,9 @@ update_controls()
                 state_io.gain.manual = state_io.gain.manual_req;
         }
 
-        if (state_io.gain.manual && state_io.gain.value != state_io.gain.value_req) {
+        if ((state_io.gain.manual ||
+             (!state_io.gain.manual && state_io.gain.auto_control == 0)) &&
+            state_io.gain.value != state_io.gain.value_req) {
                 mp_camera_control_set_int32_bg(state_io.camera,
                                                state_io.gain.control,
                                                state_io.gain.value_req);
@@ -267,6 +247,19 @@ update_controls()
         }
 }
 
+static void
+do_aaa()
+{
+        if (!state_io.exposure.manual && state_io.exposure.auto_control == 0) {
+                int step = state_io.gain.value / 16;
+                if (step < 1) {
+                        step = 1;
+                }
+                state_io.gain.value_req = state_io.gain.value;
+                state_io.gain.value_req += step * state_io.stats.exposure;
+        }
+}
+
 static void
 on_frame(MPBuffer buffer, void *_data)
 {
@@ -276,6 +269,7 @@ on_frame(MPBuffer buffer, void *_data)
         }
 
         // Only update controls right after a frame was captured
+        do_aaa();
         update_controls();
 
         // When the mode is switched while capturing we get a couple blank frames,
@@ -536,6 +530,10 @@ update_state(MPPipeline *pipeline, const mp_state_io *new_state)
                 state_io.focus.manual_req = new_state->focus.manual_req;
 
                 state_io.flash_enabled = new_state->flash_enabled;
+
+                state_io.stats.exposure = new_state->stats.exposure;
+                state_io.stats.whitebalance = new_state->stats.whitebalance;
+                state_io.stats.focus = new_state->stats.focus;
         }
 
         update_process_pipeline();

+ 36 - 28
src/main.c

@@ -131,13 +131,12 @@ update_io_pipeline()
                 .focus.max = state.focus.max,
                 .focus.manual = state.focus.manual,
                 .focus.manual_req = state.focus.manual_req,
+
+                .stats.exposure = state.stats.exposure,
+                .stats.whitebalance = state.stats.whitebalance,
+                .stats.focus = state.stats.focus,
         };
         mp_io_pipeline_update_state(&new_state);
-
-        // Make the right settings available for the camera
-        gtk_widget_set_visible(flash_button, state.control_flash);
-        gtk_widget_set_visible(iso_button, state.gain.control != 0);
-        gtk_widget_set_visible(shutter_button, state.exposure.control != 0);
 }
 
 /*
@@ -146,33 +145,42 @@ update_io_pipeline()
 static bool
 update_state(const mp_state_main *new_state)
 {
-        if (state.camera == new_state->camera) {
-                state.gain.control = new_state->gain.control;
-                state.gain.auto_control = new_state->gain.auto_control;
-                state.gain.value = new_state->gain.value;
-                state.gain.max = new_state->gain.max;
-                state.gain.manual = new_state->gain.manual;
-
-                state.exposure.control = new_state->exposure.control;
-                state.exposure.auto_control = new_state->exposure.auto_control;
-                state.exposure.value = new_state->exposure.value;
-                state.exposure.max = new_state->exposure.max;
-                state.exposure.manual = new_state->exposure.manual;
-
-                state.focus.control = new_state->focus.control;
-                state.focus.auto_control = new_state->focus.auto_control;
-                state.focus.value = new_state->focus.value;
-                state.focus.max = new_state->focus.max;
-                state.focus.manual = new_state->focus.manual;
-
-                state.has_auto_focus_continuous =
-                        new_state->has_auto_focus_continuous;
-                state.has_auto_focus_start = new_state->has_auto_focus_start;
-        }
+        state.gain.control = new_state->gain.control;
+        state.gain.auto_control = new_state->gain.auto_control;
+        state.gain.value = new_state->gain.value;
+        state.gain.max = new_state->gain.max;
+        state.gain.manual = new_state->gain.manual;
+
+        state.exposure.control = new_state->exposure.control;
+        state.exposure.auto_control = new_state->exposure.auto_control;
+        state.exposure.value = new_state->exposure.value;
+        state.exposure.max = new_state->exposure.max;
+        state.exposure.manual = new_state->exposure.manual;
+
+        state.focus.control = new_state->focus.control;
+        state.focus.auto_control = new_state->focus.auto_control;
+        state.focus.value = new_state->focus.value;
+        state.focus.max = new_state->focus.max;
+        state.focus.manual = new_state->focus.manual;
+
+        state.has_auto_focus_continuous =
+                new_state->has_auto_focus_continuous;
+        state.has_auto_focus_start = new_state->has_auto_focus_start;
 
         state.preview_buffer_width = new_state->preview_buffer_width;
         state.preview_buffer_height = new_state->preview_buffer_height;
 
+        state.stats.exposure = new_state->stats.exposure;
+        state.stats.whitebalance = new_state->stats.whitebalance;
+        state.stats.focus = new_state->stats.focus;
+
+        // Make the right settings available for the camera
+        gtk_widget_set_visible(flash_button, state.control_flash);
+        gtk_widget_set_visible(iso_button, state.gain.control != 0);
+        gtk_widget_set_visible(shutter_button, state.exposure.control != 0);
+
+        update_io_pipeline();
+
         return false;
 }
 

+ 4 - 0
src/process_pipeline.c

@@ -1033,6 +1033,10 @@ update_state(MPPipeline *pipeline, const mp_state_proc *new_state)
                 .focus.value = state_proc.focus.value,
                 .focus.max = state_proc.focus.max,
                 .focus.manual = state_proc.focus.manual,
+
+                .stats.exposure = state_proc.stats.exposure,
+                .stats.whitebalance = state_proc.stats.whitebalance,
+                .stats.focus = state_proc.stats.focus,
         };
         mp_main_update_state(&new_main);
 }