3 Commits a2f57c02ac ... 197017c86d

Autor SHA1 Mensaje Fecha
  Kristian Vos 197017c86d Don't call libmegapixels_open twice in a row in io_pipeline hace 5 meses
  Kristian Vos af77351b89 Allow manually changing the focus using controls hace 5 meses
  Kristian Vos b3b8932dee Run clang-format on a few files hace 5 meses

+ 10 - 0
data/camera.ui

@@ -67,6 +67,16 @@
                             </style>
                           </object>
                         </child>
+                        <child>
+                          <object class="GtkButton" id="focus-controls-button">
+                            <property name="valign">start</property>
+                            <property name="icon-name">focus-auto-symbolic</property>
+                            <style>
+                              <class name="flat"/>
+                              <class name="control"/>
+                            </style>
+                          </object>
+                        </child>
                         <child>
                           <object class="GtkButton" id="flash-controls-button">
                             <property name="valign">start</property>

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 34 - 0
data/focus-auto-symbolic.svg


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 34 - 0
data/focus-man-symbolic.svg


+ 2 - 0
data/me.gapixels.Megapixels.gresource.xml

@@ -28,5 +28,7 @@
     <file preprocess="xml-stripblanks">iso-auto-symbolic.svg</file>
     <file preprocess="xml-stripblanks">shutter-man-symbolic.svg</file>
     <file preprocess="xml-stripblanks">shutter-auto-symbolic.svg</file>
+    <file preprocess="xml-stripblanks">focus-man-symbolic.svg</file>
+    <file preprocess="xml-stripblanks">focus-auto-symbolic.svg</file>
   </gresource>
 </gresources>

+ 2 - 6
src/camera.c

@@ -672,9 +672,7 @@ mp_control_list_free(MPControlList *list)
 }
 
 bool
-mp_camera_query_control(int fd,
-                        uint32_t id,
-                        MPControl *control)
+mp_camera_query_control(int fd, uint32_t id, MPControl *control)
 {
         struct v4l2_query_ext_ctrl ctrl = {};
         ctrl.id = id;
@@ -706,9 +704,7 @@ mp_camera_query_control(int fd,
 }
 
 static bool
-control_impl_int32(MPControl *control,
-                   int request,
-                   int32_t *value)
+control_impl_int32(MPControl *control, int request, int32_t *value)
 {
         struct v4l2_ext_control ctrl = {};
         ctrl.id = control->id;

+ 85 - 34
src/io_pipeline.c

@@ -66,11 +66,18 @@ update_process_pipeline()
         pipeline_changed = false;
         // Grab the latest control values
         if (!state_io.gain.manual && state_io.gain.control.id) {
-                state_io.gain.value = mp_camera_control_get_int32(&state_io.gain.control);
+                state_io.gain.value =
+                        mp_camera_control_get_int32(&state_io.gain.control);
         }
 
         if (!state_io.exposure.manual && state_io.exposure.control.id) {
-                state_io.exposure.value = mp_camera_control_get_int32(&state_io.exposure.control);
+                state_io.exposure.value =
+                        mp_camera_control_get_int32(&state_io.exposure.control);
+        }
+
+        if (!state_io.focus.manual && state_io.focus.control.id) {
+                state_io.focus.value =
+                        mp_camera_control_get_int32(&state_io.focus.control);
         }
 
         float balance_red = 1.0f;
@@ -153,14 +160,14 @@ capture(MPPipeline *pipeline, const void *data)
 
         // Disable the autogain/exposure while taking the burst
         mp_camera_control_set_int32(&state_io.gain.auto_control, 0);
-        mp_camera_control_set_int32(&state_io.exposure.auto_control, V4L2_EXPOSURE_MANUAL);
+        mp_camera_control_set_int32(&state_io.exposure.auto_control,
+                                    V4L2_EXPOSURE_MANUAL);
 
         // Get current gain to calculate a burst length;
         // with low gain there's 3, with the max automatic gain of the ov5640
         // the value seems to be 248 which creates a 5 frame burst
         // for manual gain you can go up to 11 frames
-        state_io.gain.value =
-                mp_camera_control_get_int32(&state_io.gain.control);
+        state_io.gain.value = mp_camera_control_get_int32(&state_io.gain.control);
         gain_norm = (float)state_io.gain.value / (float)state_io.gain.max;
         state_io.burst_length = (int)fmax(sqrtf(gain_norm) * 10, 2) + 1;
         state_io.burst_length = MAX(1, state_io.burst_length);
@@ -243,6 +250,28 @@ update_controls()
                 start_focus();
         }
 
+        // Change focus manual/auto if it got changed by the user
+        if (state_io.focus.manual != state_io.focus.manual_req) {
+                state_io.focus.manual = state_io.focus.manual_req;
+                if (state_io.focus.auto_control.id > 0) {
+                        mp_camera_control_set_bool_bg(mpcamera,
+                                                      &state_io.focus.auto_control,
+                                                      !state_io.gain.manual_req);
+                }
+                state_changed = true;
+        }
+
+        // If focus is manual, OR auto but no auto control, and the value got
+        // updated by the program/user, update the manual control
+        if ((state_io.focus.manual ||
+             (!state_io.focus.manual && state_io.focus.auto_control.id == 0)) &&
+            state_io.focus.value != state_io.focus.value_req) {
+                mp_camera_control_set_int32_bg(
+                        mpcamera, &state_io.focus.control, state_io.focus.value_req);
+                state_io.focus.value = state_io.focus.value_req;
+                state_changed = true;
+        }
+
         if (state_io.gain.manual != state_io.gain.manual_req) {
                 mp_camera_control_set_bool_bg(mpcamera,
                                               &state_io.gain.auto_control,
@@ -254,9 +283,8 @@ update_controls()
         if ((state_io.gain.manual ||
              (!state_io.gain.manual && state_io.gain.auto_control.id == 0)) &&
             state_io.gain.value != state_io.gain.value_req) {
-                mp_camera_control_set_int32_bg(mpcamera,
-                                               &state_io.gain.control,
-                                               state_io.gain.value_req);
+                mp_camera_control_set_int32_bg(
+                        mpcamera, &state_io.gain.control, state_io.gain.value_req);
                 state_io.gain.value = state_io.gain.value_req;
                 state_changed = true;
         }
@@ -334,8 +362,9 @@ do_aaa()
 static void
 on_frame(MPBuffer buffer, void *_data)
 {
-        // Don't process frame when the window is not active, unless we're capturing an image,
-        // in which case the flash window may be active instead of this window
+        // Don't process frame when the window is not active, unless we're capturing
+        // an image, in which case the flash window may be active instead of this
+        // window
         if (!check_window_active() && state_io.captures_remaining == 0) {
                 return;
         }
@@ -418,17 +447,28 @@ static void
 init_controls()
 {
         MPControl focus_control;
-        if (mp_camera_query_control(
-                state_io.camera->sensor_fd, V4L2_CID_FOCUS_ABSOLUTE, &focus_control)) {
+        // V4L2_CID_FOCUS_ABSOLUTE exists on the sensor for PP, but on the lens for
+        // PPP. Check both, if applicable.
+        if ((state_io.camera->lens_fd > 0 &&
+             mp_camera_query_control(state_io.camera->lens_fd,
+                                     V4L2_CID_FOCUS_ABSOLUTE,
+                                     &focus_control)) ||
+            mp_camera_query_control(state_io.camera->sensor_fd,
+                                    V4L2_CID_FOCUS_ABSOLUTE,
+                                    &focus_control)) {
                 state_io.focus.control = focus_control;
+                state_io.focus.max = focus_control.max;
+                state_io.focus.value =
+                        mp_camera_control_get_int32(&state_io.focus.control);
         } else {
                 state_io.focus.control.id = 0;
         }
 
         MPControl auto_focus_control;
-        if (mp_camera_query_control(state_io.camera->sensor_fd, V4L2_CID_FOCUS_AUTO, &auto_focus_control)) {
-                mp_camera_control_set_bool_bg(
-                        mpcamera, &auto_focus_control, true);
+        if (mp_camera_query_control(state_io.camera->sensor_fd,
+                                    V4L2_CID_FOCUS_AUTO,
+                                    &auto_focus_control)) {
+                mp_camera_control_set_bool_bg(mpcamera, &auto_focus_control, true);
                 state_io.focus.auto_control = auto_focus_control;
         } else {
                 state_io.focus.auto_control.id = 0;
@@ -438,11 +478,13 @@ init_controls()
                 state_io.camera->sensor_fd, V4L2_CID_AUTO_FOCUS_START, NULL);
 
         MPControl gain_control;
-        if (mp_camera_query_control(state_io.camera->sensor_fd, V4L2_CID_GAIN, &gain_control)) {
+        if (mp_camera_query_control(
+                    state_io.camera->sensor_fd, V4L2_CID_GAIN, &gain_control)) {
                 state_io.gain.control = gain_control;
                 state_io.gain.max = gain_control.max;
-        } else if (mp_camera_query_control(
-                           state_io.camera->sensor_fd, V4L2_CID_ANALOGUE_GAIN, &gain_control)) {
+        } else if (mp_camera_query_control(state_io.camera->sensor_fd,
+                                           V4L2_CID_ANALOGUE_GAIN,
+                                           &gain_control)) {
                 state_io.gain.control = gain_control;
                 state_io.gain.max = gain_control.max;
         } else {
@@ -450,13 +492,16 @@ init_controls()
                 state_io.gain.control.id = 0;
         }
         if (state_io.gain.control.id) {
-                state_io.gain.value = mp_camera_control_get_int32(&state_io.gain.control);
+                state_io.gain.value =
+                        mp_camera_control_get_int32(&state_io.gain.control);
         } else {
                 state_io.gain.value = 0;
         }
 
         MPControl auto_gain_control;
-        if (mp_camera_query_control(state_io.camera->sensor_fd, V4L2_CID_AUTOGAIN, &auto_gain_control)) {
+        if (mp_camera_query_control(state_io.camera->sensor_fd,
+                                    V4L2_CID_AUTOGAIN,
+                                    &auto_gain_control)) {
                 state_io.gain.auto_control = auto_gain_control;
                 state_io.gain.manual =
                         mp_camera_control_get_bool(&auto_gain_control) == 0;
@@ -465,27 +510,33 @@ init_controls()
         }
 
         MPControl exposure_control;
-        if (mp_camera_query_control(state_io.camera->sensor_fd, V4L2_CID_EXPOSURE, &exposure_control)) {
+        if (mp_camera_query_control(state_io.camera->sensor_fd,
+                                    V4L2_CID_EXPOSURE,
+                                    &exposure_control)) {
                 state_io.exposure.control = exposure_control;
                 state_io.exposure.max = exposure_control.max;
-                state_io.exposure.value = mp_camera_control_get_int32(&exposure_control);
+                state_io.exposure.value =
+                        mp_camera_control_get_int32(&exposure_control);
         } else {
                 state_io.exposure.control.id = 0;
         }
 
         MPControl auto_exposure_control;
-        if (mp_camera_query_control(
-                    state_io.camera->sensor_fd, V4L2_CID_EXPOSURE_AUTO, &auto_exposure_control)) {
+        if (mp_camera_query_control(state_io.camera->sensor_fd,
+                                    V4L2_CID_EXPOSURE_AUTO,
+                                    &auto_exposure_control)) {
                 state_io.exposure.auto_control = auto_exposure_control;
                 state_io.exposure.manual =
-                        mp_camera_control_get_int32(&auto_exposure_control) == V4L2_EXPOSURE_MANUAL;
+                        mp_camera_control_get_int32(&auto_exposure_control) ==
+                        V4L2_EXPOSURE_MANUAL;
         } else {
                 state_io.exposure.auto_control.id = 0;
         }
 
         MPControl red_control;
-        if (mp_camera_query_control(
-                    state_io.camera->sensor_fd, V4L2_CID_RED_BALANCE, &red_control)) {
+        if (mp_camera_query_control(state_io.camera->sensor_fd,
+                                    V4L2_CID_RED_BALANCE,
+                                    &red_control)) {
                 state_io.red.control = red_control;
                 state_io.red.max = red_control.max;
         } else {
@@ -493,8 +544,9 @@ init_controls()
         }
 
         MPControl blue_control;
-        if (mp_camera_query_control(
-                    state_io.camera->sensor_fd, V4L2_CID_BLUE_BALANCE, &blue_control)) {
+        if (mp_camera_query_control(state_io.camera->sensor_fd,
+                                    V4L2_CID_BLUE_BALANCE,
+                                    &blue_control)) {
                 state_io.blue.control = blue_control;
                 state_io.blue.max = blue_control.max;
         } else {
@@ -525,7 +577,6 @@ update_state(MPPipeline *pipeline, const mp_state_io *new_state)
 
                 state_io.camera = new_state->camera;
                 if (state_io.camera) {
-                        libmegapixels_open(state_io.camera);
                         mpcamera = mp_camera_new(state_io.camera);
                         state_io.mode_preview = NULL;
                         state_io.mode_capture = NULL;
@@ -621,10 +672,10 @@ update_state(MPPipeline *pipeline, const mp_state_io *new_state)
 void
 mp_io_pipeline_update_state(const mp_state_io *state)
 {
-	if (!pipeline) {
-		printf("no pipeline\n");
-		exit(1);
-	}
+        if (!pipeline) {
+                printf("no pipeline\n");
+                exit(1);
+        }
         mp_pipeline_invoke(pipeline,
                            (MPPipelineCallback)update_state,
                            state,

+ 72 - 22
src/main.c

@@ -68,9 +68,10 @@ GtkWidget *preview_bottom_box;
 GtkWidget *message_box;
 GtkWidget *message_label;
 
-GtkWidget *flash_button;
 GtkWidget *iso_button;
 GtkWidget *shutter_button;
+GtkWidget *focus_button;
+GtkWidget *flash_button;
 
 LfbEvent *capture_event;
 static GtkWidget *movie;
@@ -160,15 +161,25 @@ static bool
 update_state(const mp_state_main *new_state)
 {
         if (state.exposure.manual != new_state->exposure.manual) {
-                const char *icon_name = new_state->exposure.manual ? "shutter-man-symbolic" : "shutter-auto-symbolic";
+                const char *icon_name = new_state->exposure.manual ?
+                                                "shutter-man-symbolic" :
+                                                "shutter-auto-symbolic";
                 gtk_button_set_icon_name(GTK_BUTTON(shutter_button), icon_name);
         }
 
         if (state.gain.manual != new_state->gain.manual) {
-                const char *icon_name = new_state->gain.manual ? "iso-man-symbolic" : "iso-auto-symbolic";
+                const char *icon_name = new_state->gain.manual ? "iso-man-symbolic" :
+                                                                 "iso-auto-symbolic";
                 gtk_button_set_icon_name(GTK_BUTTON(iso_button), icon_name);
         }
 
+        if (state.focus.manual != new_state->focus.manual) {
+                const char *icon_name = new_state->focus.manual ?
+                                                "focus-man-symbolic" :
+                                                "focus-auto-symbolic";
+                gtk_button_set_icon_name(GTK_BUTTON(focus_button), icon_name);
+        }
+
         state.gain.control = new_state->gain.control;
         state.gain.auto_control = new_state->gain.auto_control;
         state.gain.value = new_state->gain.value;
@@ -201,7 +212,9 @@ update_state(const mp_state_main *new_state)
         // Make the right settings available for the camera
         gtk_widget_set_visible(iso_button, state.gain.control.id != 0);
         gtk_widget_set_visible(shutter_button, state.exposure.control.id != 0);
-        // Even if there's no flash led/v4l, it'll just default to using the screen as flash, so always enable this button
+        gtk_widget_set_visible(focus_button, state.focus.control.id != 0);
+        // Even if there's no flash led/v4l, it'll just default to using the screen
+        // as flash, so always enable this button
         gtk_widget_set_visible(flash_button, true);
 
         return false;
@@ -911,11 +924,29 @@ set_shutter_auto(bool is_auto)
         }
 }
 
+static void
+set_focus(double value)
+{
+        if (state.focus.value != (int)value) {
+                state.focus.value_req = (int)value;
+                update_io_pipeline();
+        }
+}
+
+static void
+set_focus_auto(bool is_auto)
+{
+        if (state.focus.manual != !is_auto) {
+                state.focus.manual_req = !is_auto;
+                update_io_pipeline();
+        }
+}
+
 static void
 open_shutter_controls(GtkWidget *button, gpointer user_data)
 {
-        float value =
-                (float)state.exposure.value * 360.0f / (float)state.camera->current_mode->height;
+        float value = (float)state.exposure.value * 360.0f /
+                      (float)state.camera->current_mode->height;
         open_controls(button,
                       "Shutter",
                       1.0,
@@ -926,6 +957,19 @@ open_shutter_controls(GtkWidget *button, gpointer user_data)
                       set_shutter_auto);
 }
 
+static void
+open_focus_controls(GtkWidget *button, gpointer user_data)
+{
+        open_controls(button,
+                      "Focus",
+                      0,
+                      state.focus.max,
+                      state.focus.value,
+                      !state.focus.manual,
+                      set_focus,
+                      set_focus_auto);
+}
+
 static void
 flash_button_clicked(GtkWidget *button, gpointer user_data)
 {
@@ -940,30 +984,33 @@ flash_button_clicked(GtkWidget *button, gpointer user_data)
 void
 notify_movie_progress(void)
 {
-	if (!movie_start) {
+        if (!movie_start) {
                 // Recording started
-                gtk_button_set_icon_name(GTK_BUTTON(movie), "video-recording-symbolic");
+                gtk_button_set_icon_name(GTK_BUTTON(movie),
+                                         "video-recording-symbolic");
         }
 }
 
 void
 notify_movie_message(gchar *msg)
 {
-	gtk_button_set_label(GTK_BUTTON(movie), msg);
+        gtk_button_set_label(GTK_BUTTON(movie), msg);
 }
 
 void
 on_movie_clicked(GtkWidget *widget, gpointer user_data)
 {
-	if (movie_start) {
-		movie_start = 0;
-                gtk_button_set_icon_name(GTK_BUTTON(movie), "video-processing-symbolic");
-		on_movie_stop();
-	} else {
-		movie_start = 1;
-                gtk_button_set_icon_name(GTK_BUTTON(movie), "video-recording-symbolic");
-		on_movie_start();
-	}
+        if (movie_start) {
+                movie_start = 0;
+                gtk_button_set_icon_name(GTK_BUTTON(movie),
+                                         "video-processing-symbolic");
+                on_movie_stop();
+        } else {
+                movie_start = 1;
+                gtk_button_set_icon_name(GTK_BUTTON(movie),
+                                         "video-recording-symbolic");
+                on_movie_start();
+        }
 }
 
 static void
@@ -1247,6 +1294,8 @@ activate(GtkApplication *app, gpointer data)
                 GTK_WIDGET(gtk_builder_get_object(builder, "iso-controls-button"));
         shutter_button = GTK_WIDGET(
                 gtk_builder_get_object(builder, "shutter-controls-button"));
+        focus_button =
+                GTK_WIDGET(gtk_builder_get_object(builder, "focus-controls-button"));
         flash_button =
                 GTK_WIDGET(gtk_builder_get_object(builder, "flash-controls-button"));
         GtkWidget *setting_dng_button =
@@ -1266,7 +1315,7 @@ activate(GtkApplication *app, gpointer data)
         preview_top_box = GTK_WIDGET(gtk_builder_get_object(builder, "top-box"));
         preview_bottom_box =
                 GTK_WIDGET(gtk_builder_get_object(builder, "bottom-box"));
-	movie = GTK_WIDGET(gtk_builder_get_object(builder, "movie"));
+        movie = GTK_WIDGET(gtk_builder_get_object(builder, "movie"));
 
         message_box = GTK_WIDGET(gtk_builder_get_object(builder, "message-box"));
         message_label = GTK_WIDGET(gtk_builder_get_object(builder, "message-label"));
@@ -1283,13 +1332,14 @@ activate(GtkApplication *app, gpointer data)
         g_signal_connect(iso_button, "clicked", G_CALLBACK(open_iso_controls), NULL);
         g_signal_connect(
                 shutter_button, "clicked", G_CALLBACK(open_shutter_controls), NULL);
+        g_signal_connect(
+                focus_button, "clicked", G_CALLBACK(open_focus_controls), NULL);
         g_signal_connect(
                 flash_button, "clicked", G_CALLBACK(flash_button_clicked), NULL);
 
-	g_signal_connect(movie, "clicked",
-			 G_CALLBACK(on_movie_clicked), NULL);
+        g_signal_connect(movie, "clicked", G_CALLBACK(on_movie_clicked), NULL);
 
-	setup_fb_switch(builder);
+        setup_fb_switch(builder);
 
         // Setup actions
         create_simple_action(app, "capture", G_CALLBACK(run_capture_action));

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio