Allow manually changing the focus using controls
This commit is contained in:

committed by
Martijn Braam

parent
64f93cd8f2
commit
8f37625309
@@ -67,6 +67,16 @@
|
|||||||
</style>
|
</style>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</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>
|
<child>
|
||||||
<object class="GtkButton" id="flash-controls-button">
|
<object class="GtkButton" id="flash-controls-button">
|
||||||
<property name="valign">start</property>
|
<property name="valign">start</property>
|
||||||
|
40
data/focus-auto-symbolic.svg
Normal file
40
data/focus-auto-symbolic.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 8.8 KiB |
41
data/focus-man-symbolic.svg
Normal file
41
data/focus-man-symbolic.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 10 KiB |
@@ -28,5 +28,7 @@
|
|||||||
<file preprocess="xml-stripblanks">iso-auto-symbolic.svg</file>
|
<file preprocess="xml-stripblanks">iso-auto-symbolic.svg</file>
|
||||||
<file preprocess="xml-stripblanks">shutter-man-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">shutter-auto-symbolic.svg</file>
|
||||||
|
<file preprocess="xml-stripblanks">focus-man-symbolic.svg</file>
|
||||||
|
<file preprocess="xml-stripblanks">focus-auto-symbolic.svg</file>
|
||||||
</gresource>
|
</gresource>
|
||||||
</gresources>
|
</gresources>
|
||||||
|
@@ -75,6 +75,11 @@ update_process_pipeline()
|
|||||||
mp_camera_control_get_int32(&state_io.exposure.control);
|
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;
|
float balance_red = 1.0f;
|
||||||
float balance_blue = 1.0f;
|
float balance_blue = 1.0f;
|
||||||
if (state_io.red.control.id && state_io.blue.control.id) {
|
if (state_io.red.control.id && state_io.blue.control.id) {
|
||||||
@@ -245,6 +250,28 @@ update_controls()
|
|||||||
start_focus();
|
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) {
|
if (state_io.gain.manual != state_io.gain.manual_req) {
|
||||||
mp_camera_control_set_bool_bg(mpcamera,
|
mp_camera_control_set_bool_bg(mpcamera,
|
||||||
&state_io.gain.auto_control,
|
&state_io.gain.auto_control,
|
||||||
@@ -420,10 +447,19 @@ static void
|
|||||||
init_controls()
|
init_controls()
|
||||||
{
|
{
|
||||||
MPControl focus_control;
|
MPControl focus_control;
|
||||||
if (mp_camera_query_control(state_io.camera->sensor_fd,
|
// 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,
|
V4L2_CID_FOCUS_ABSOLUTE,
|
||||||
&focus_control)) {
|
&focus_control)) {
|
||||||
state_io.focus.control = 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 {
|
} else {
|
||||||
state_io.focus.control.id = 0;
|
state_io.focus.control.id = 0;
|
||||||
}
|
}
|
||||||
|
46
src/main.c
46
src/main.c
@@ -68,9 +68,10 @@ GtkWidget *preview_bottom_box;
|
|||||||
GtkWidget *message_box;
|
GtkWidget *message_box;
|
||||||
GtkWidget *message_label;
|
GtkWidget *message_label;
|
||||||
|
|
||||||
GtkWidget *flash_button;
|
|
||||||
GtkWidget *iso_button;
|
GtkWidget *iso_button;
|
||||||
GtkWidget *shutter_button;
|
GtkWidget *shutter_button;
|
||||||
|
GtkWidget *focus_button;
|
||||||
|
GtkWidget *flash_button;
|
||||||
|
|
||||||
LfbEvent *capture_event;
|
LfbEvent *capture_event;
|
||||||
static GtkWidget *movie;
|
static GtkWidget *movie;
|
||||||
@@ -172,6 +173,13 @@ update_state(const mp_state_main *new_state)
|
|||||||
gtk_button_set_icon_name(GTK_BUTTON(iso_button), icon_name);
|
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.control = new_state->gain.control;
|
||||||
state.gain.auto_control = new_state->gain.auto_control;
|
state.gain.auto_control = new_state->gain.auto_control;
|
||||||
state.gain.value = new_state->gain.value;
|
state.gain.value = new_state->gain.value;
|
||||||
@@ -204,6 +212,7 @@ update_state(const mp_state_main *new_state)
|
|||||||
// Make the right settings available for the camera
|
// Make the right settings available for the camera
|
||||||
gtk_widget_set_visible(iso_button, state.gain.control.id != 0);
|
gtk_widget_set_visible(iso_button, state.gain.control.id != 0);
|
||||||
gtk_widget_set_visible(shutter_button, state.exposure.control.id != 0);
|
gtk_widget_set_visible(shutter_button, state.exposure.control.id != 0);
|
||||||
|
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
|
// Even if there's no flash led/v4l, it'll just default to using the screen
|
||||||
// as flash, so always enable this button
|
// as flash, so always enable this button
|
||||||
gtk_widget_set_visible(flash_button, true);
|
gtk_widget_set_visible(flash_button, true);
|
||||||
@@ -915,6 +924,24 @@ 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
|
static void
|
||||||
open_shutter_controls(GtkWidget *button, gpointer user_data)
|
open_shutter_controls(GtkWidget *button, gpointer user_data)
|
||||||
{
|
{
|
||||||
@@ -930,6 +957,19 @@ open_shutter_controls(GtkWidget *button, gpointer user_data)
|
|||||||
set_shutter_auto);
|
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
|
static void
|
||||||
flash_button_clicked(GtkWidget *button, gpointer user_data)
|
flash_button_clicked(GtkWidget *button, gpointer user_data)
|
||||||
{
|
{
|
||||||
@@ -1254,6 +1294,8 @@ activate(GtkApplication *app, gpointer data)
|
|||||||
GTK_WIDGET(gtk_builder_get_object(builder, "iso-controls-button"));
|
GTK_WIDGET(gtk_builder_get_object(builder, "iso-controls-button"));
|
||||||
shutter_button = GTK_WIDGET(
|
shutter_button = GTK_WIDGET(
|
||||||
gtk_builder_get_object(builder, "shutter-controls-button"));
|
gtk_builder_get_object(builder, "shutter-controls-button"));
|
||||||
|
focus_button =
|
||||||
|
GTK_WIDGET(gtk_builder_get_object(builder, "focus-controls-button"));
|
||||||
flash_button =
|
flash_button =
|
||||||
GTK_WIDGET(gtk_builder_get_object(builder, "flash-controls-button"));
|
GTK_WIDGET(gtk_builder_get_object(builder, "flash-controls-button"));
|
||||||
GtkWidget *setting_dng_button =
|
GtkWidget *setting_dng_button =
|
||||||
@@ -1290,6 +1332,8 @@ activate(GtkApplication *app, gpointer data)
|
|||||||
g_signal_connect(iso_button, "clicked", G_CALLBACK(open_iso_controls), NULL);
|
g_signal_connect(iso_button, "clicked", G_CALLBACK(open_iso_controls), NULL);
|
||||||
g_signal_connect(
|
g_signal_connect(
|
||||||
shutter_button, "clicked", G_CALLBACK(open_shutter_controls), NULL);
|
shutter_button, "clicked", G_CALLBACK(open_shutter_controls), NULL);
|
||||||
|
g_signal_connect(
|
||||||
|
focus_button, "clicked", G_CALLBACK(open_focus_controls), NULL);
|
||||||
g_signal_connect(
|
g_signal_connect(
|
||||||
flash_button, "clicked", G_CALLBACK(flash_button_clicked), NULL);
|
flash_button, "clicked", G_CALLBACK(flash_button_clicked), NULL);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user