|
@@ -46,16 +46,11 @@ RENDERDOC_API_1_1_2 *rdoc_api = NULL;
|
|
|
|
|
|
#define APP_ID "org.postmarketos.Megapixels"
|
|
#define APP_ID "org.postmarketos.Megapixels"
|
|
|
|
|
|
-enum user_control { USER_CONTROL_ISO, USER_CONTROL_SHUTTER };
|
|
|
|
-
|
|
|
|
mp_state_main state;
|
|
mp_state_main state;
|
|
|
|
|
|
static bool camera_is_initialized = false;
|
|
static bool camera_is_initialized = false;
|
|
-struct mp_main_state current_state = { 0 };
|
|
|
|
|
|
|
|
static MPProcessPipelineBuffer *current_preview_buffer = NULL;
|
|
static MPProcessPipelineBuffer *current_preview_buffer = NULL;
|
|
-static int preview_buffer_width = -1;
|
|
|
|
-static int preview_buffer_height = -1;
|
|
|
|
|
|
|
|
static char last_path[260] = "";
|
|
static char last_path[260] = "";
|
|
|
|
|
|
@@ -115,39 +110,35 @@ update_io_pipeline()
|
|
}
|
|
}
|
|
|
|
|
|
static bool
|
|
static bool
|
|
-update_state(const struct mp_main_state *state)
|
|
|
|
|
|
+update_state(const mp_state_main *new_state)
|
|
{
|
|
{
|
|
if (!camera_is_initialized) {
|
|
if (!camera_is_initialized) {
|
|
camera_is_initialized = true;
|
|
camera_is_initialized = true;
|
|
}
|
|
}
|
|
|
|
|
|
- if (current_state.camera == state->camera) {
|
|
|
|
- current_state.mode = state->mode;
|
|
|
|
-
|
|
|
|
- if (!state.gain_is_manual) {
|
|
|
|
- state.gain = state->gain;
|
|
|
|
- }
|
|
|
|
- state.gain_max = state->gain_max;
|
|
|
|
|
|
+ if (state.camera == new_state->camera) {
|
|
|
|
+ state.gain_is_manual = new_state->gain_is_manual;
|
|
|
|
+ state.gain = new_state->gain;
|
|
|
|
+ state.gain_max = new_state->gain_max;
|
|
|
|
|
|
- if (!state.exposure_is_manual) {
|
|
|
|
- state.exposure = state->exposure;
|
|
|
|
- }
|
|
|
|
|
|
+ state.exposure_is_manual = new_state->exposure_is_manual;
|
|
|
|
+ state.exposure = new_state->exposure;
|
|
|
|
|
|
- has_auto_focus_continuous = state->has_auto_focus_continuous;
|
|
|
|
- has_auto_focus_start = state->has_auto_focus_start;
|
|
|
|
|
|
+ state.has_auto_focus_continuous =
|
|
|
|
+ new_state->has_auto_focus_continuous;
|
|
|
|
+ state.has_auto_focus_start = new_state->has_auto_focus_start;
|
|
}
|
|
}
|
|
|
|
|
|
- preview_buffer_width = state->image_width;
|
|
|
|
- preview_buffer_height = state->image_height;
|
|
|
|
-
|
|
|
|
|
|
+ state.preview_buffer_width = new_state->preview_buffer_width;
|
|
|
|
+ state.preview_buffer_height = new_state->preview_buffer_height;
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
void
|
|
void
|
|
-mp_main_update_state(const struct mp_main_state *state)
|
|
|
|
|
|
+mp_main_update_state(const mp_state_main *new_state)
|
|
{
|
|
{
|
|
- struct mp_main_state *state_copy = malloc(sizeof(struct mp_main_state));
|
|
|
|
- *state_copy = *state;
|
|
|
|
|
|
+ mp_state_main *state_copy = malloc(sizeof(mp_state_main));
|
|
|
|
+ *state_copy = *new_state;
|
|
|
|
|
|
g_main_context_invoke_full(g_main_context_default(),
|
|
g_main_context_invoke_full(g_main_context_default(),
|
|
G_PRIORITY_DEFAULT_IDLE,
|
|
G_PRIORITY_DEFAULT_IDLE,
|
|
@@ -308,11 +299,11 @@ position_preview(float *offset_x, float *offset_y, float *size_x, float *size_y)
|
|
{
|
|
{
|
|
int buffer_width, buffer_height;
|
|
int buffer_width, buffer_height;
|
|
if (state.device_rotation == 0 || state.device_rotation == 180) {
|
|
if (state.device_rotation == 0 || state.device_rotation == 180) {
|
|
- buffer_width = preview_buffer_width;
|
|
|
|
- buffer_height = preview_buffer_height;
|
|
|
|
|
|
+ buffer_width = state.preview_buffer_width;
|
|
|
|
+ buffer_height = state.preview_buffer_height;
|
|
} else {
|
|
} else {
|
|
- buffer_width = preview_buffer_height;
|
|
|
|
- buffer_height = preview_buffer_width;
|
|
|
|
|
|
+ buffer_width = state.preview_buffer_height;
|
|
|
|
+ buffer_height = state.preview_buffer_width;
|
|
}
|
|
}
|
|
|
|
|
|
int scale_factor = gtk_widget_get_scale_factor(preview);
|
|
int scale_factor = gtk_widget_get_scale_factor(preview);
|
|
@@ -322,18 +313,19 @@ position_preview(float *offset_x, float *offset_y, float *size_x, float *size_y)
|
|
gtk_widget_get_allocated_height(preview_bottom_box) * scale_factor;
|
|
gtk_widget_get_allocated_height(preview_bottom_box) * scale_factor;
|
|
int inner_height = state.preview_height - top_height - bottom_height;
|
|
int inner_height = state.preview_height - top_height - bottom_height;
|
|
|
|
|
|
- double scale = MIN(state.preview_width / (float)buffer_width,
|
|
|
|
- state.preview_height / (float)buffer_height);
|
|
|
|
|
|
+ float scale = (float)MIN(state.preview_width / (float)buffer_width,
|
|
|
|
+ state.preview_height / (float)buffer_height);
|
|
|
|
|
|
- *size_x = scale * buffer_width;
|
|
|
|
- *size_y = scale * buffer_height;
|
|
|
|
|
|
+ *size_x = scale * (float)buffer_width;
|
|
|
|
+ *size_y = scale * (float)buffer_height;
|
|
|
|
|
|
- *offset_x = (state.preview_width - *size_x) / 2.0;
|
|
|
|
|
|
+ *offset_x = ((float)state.preview_width - *size_x) / 2.0f;
|
|
|
|
|
|
- if (*size_y > inner_height) {
|
|
|
|
- *offset_y = (state.preview_height - *size_y) / 2.0;
|
|
|
|
|
|
+ if (*size_y > (float)inner_height) {
|
|
|
|
+ *offset_y = ((float)state.preview_height - *size_y) / 2.0f;
|
|
} else {
|
|
} else {
|
|
- *offset_y = top_height + (inner_height - *size_y) / 2.0;
|
|
|
|
|
|
+ *offset_y =
|
|
|
|
+ (float)top_height + ((float)inner_height - *size_y) / 2.0f;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -344,7 +336,7 @@ preview_draw(GtkGLArea *area, GdkGLContext *ctx, gpointer data)
|
|
return FALSE;
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
|
|
- if (!camera_is_initialized) {
|
|
|
|
|
|
+ if (current_preview_buffer == NULL) {
|
|
return FALSE;
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -417,11 +409,12 @@ preview_draw(GtkGLArea *area, GdkGLContext *ctx, gpointer data)
|
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
for (int i = 0; i < 4; ++i) {
|
|
vertices[i * 2] =
|
|
vertices[i * 2] =
|
|
- 2 * vertices[i * 2] / preview_buffer_width -
|
|
|
|
|
|
+ 2 * vertices[i * 2] /
|
|
|
|
+ state.preview_buffer_width -
|
|
1.0;
|
|
1.0;
|
|
vertices[i * 2 + 1] =
|
|
vertices[i * 2 + 1] =
|
|
1.0 - 2 * vertices[i * 2 + 1] /
|
|
1.0 - 2 * vertices[i * 2 + 1] /
|
|
- preview_buffer_height;
|
|
|
|
|
|
+ state.preview_buffer_height;
|
|
}
|
|
}
|
|
|
|
|
|
if (gtk_gl_area_get_use_es(area)) {
|
|
if (gtk_gl_area_get_use_es(area)) {
|
|
@@ -651,9 +644,9 @@ preview_pressed(GtkGestureClick *gesture, int n_press, double x, double y)
|
|
position_preview(&offset_x, &offset_y, &size_x, &size_y);
|
|
position_preview(&offset_x, &offset_y, &size_x, &size_y);
|
|
|
|
|
|
int zbar_x = (x - offset_x) * scale_factor / size_x *
|
|
int zbar_x = (x - offset_x) * scale_factor / size_x *
|
|
- preview_buffer_width;
|
|
|
|
|
|
+ state.preview_buffer_width;
|
|
int zbar_y = (y - offset_y) * scale_factor / size_y *
|
|
int zbar_y = (y - offset_y) * scale_factor / size_y *
|
|
- preview_buffer_height;
|
|
|
|
|
|
+ state.preview_buffer_height;
|
|
|
|
|
|
for (uint8_t i = 0; i < zbar_result->size; ++i) {
|
|
for (uint8_t i = 0; i < zbar_result->size; ++i) {
|
|
MPZBarCode *code = &zbar_result->codes[i];
|
|
MPZBarCode *code = &zbar_result->codes[i];
|
|
@@ -780,7 +773,7 @@ static void
|
|
set_gain(double value)
|
|
set_gain(double value)
|
|
{
|
|
{
|
|
if (state.gain != (int)value) {
|
|
if (state.gain != (int)value) {
|
|
- state.gain = value;
|
|
|
|
|
|
+ state.gain = (int)value;
|
|
update_io_pipeline();
|
|
update_io_pipeline();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -848,8 +841,8 @@ flash_button_clicked(GtkWidget *button, gpointer user_data)
|
|
state.flash_enabled = !state.flash_enabled;
|
|
state.flash_enabled = !state.flash_enabled;
|
|
update_io_pipeline();
|
|
update_io_pipeline();
|
|
|
|
|
|
- const char *icon_name =
|
|
|
|
- state.flash_enabled ? "flash-enabled-symbolic" : "flash-disabled-symbolic";
|
|
|
|
|
|
+ const char *icon_name = state.flash_enabled ? "flash-enabled-symbolic" :
|
|
|
|
+ "flash-disabled-symbolic";
|
|
gtk_button_set_icon_name(GTK_BUTTON(button), icon_name);
|
|
gtk_button_set_icon_name(GTK_BUTTON(button), icon_name);
|
|
}
|
|
}
|
|
|
|
|