Add libmegapixels
This commit is contained in:
55
src/main.c
55
src/main.c
@@ -1,6 +1,5 @@
|
||||
#include "main.h"
|
||||
|
||||
#include "camera_config.h"
|
||||
#include "flash.h"
|
||||
#include "gl_util.h"
|
||||
#include "io_pipeline.h"
|
||||
@@ -21,6 +20,7 @@
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include <gdk/x11/gdkx.h>
|
||||
#endif
|
||||
#include <libmegapixels.h>
|
||||
#include <limits.h>
|
||||
#include <linux/kdev_t.h>
|
||||
#include <linux/media.h>
|
||||
@@ -47,9 +47,12 @@ RENDERDOC_API_1_1_2 *rdoc_api = NULL;
|
||||
|
||||
enum user_control { USER_CONTROL_ISO, USER_CONTROL_SHUTTER };
|
||||
|
||||
libmegapixels_devconfig *configuration = { 0 };
|
||||
libmegapixels_camera *camera = NULL;
|
||||
int current_camera_index = 0;
|
||||
|
||||
static bool camera_is_initialized = false;
|
||||
static const struct mp_camera_config *camera = NULL;
|
||||
static MPMode mode;
|
||||
struct mp_main_state current_state = { 0 };
|
||||
|
||||
static int preview_width = -1;
|
||||
static int preview_height = -1;
|
||||
@@ -128,7 +131,8 @@ update_io_pipeline()
|
||||
mp_io_pipeline_update_state(&io_state);
|
||||
|
||||
// Make the right settings available for the camera
|
||||
gtk_widget_set_visible(flash_button, camera->has_flash);
|
||||
// TODO: Implement flash again
|
||||
gtk_widget_set_visible(flash_button, false);
|
||||
}
|
||||
|
||||
static bool
|
||||
@@ -138,8 +142,8 @@ update_state(const struct mp_main_state *state)
|
||||
camera_is_initialized = true;
|
||||
}
|
||||
|
||||
if (camera == state->camera) {
|
||||
mode = state->mode;
|
||||
if (current_state.camera == state->camera) {
|
||||
current_state.mode = state->mode;
|
||||
|
||||
if (!gain_is_manual) {
|
||||
gain = state->gain;
|
||||
@@ -154,8 +158,8 @@ update_state(const struct mp_main_state *state)
|
||||
has_auto_focus_start = state->has_auto_focus_start;
|
||||
}
|
||||
|
||||
preview_buffer_width = state->image_width;
|
||||
preview_buffer_height = state->image_height;
|
||||
preview_buffer_width = state->mode->width;
|
||||
preview_buffer_height = state->mode->height;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -693,16 +697,11 @@ preview_pressed(GtkGestureClick *gesture, int n_press, double x, double y)
|
||||
static void
|
||||
run_camera_switch_action(GSimpleAction *action, GVariant *param, gpointer user_data)
|
||||
{
|
||||
size_t next_index = camera->index + 1;
|
||||
const struct mp_camera_config *next_camera =
|
||||
mp_get_camera_config(next_index);
|
||||
|
||||
if (!next_camera) {
|
||||
next_index = 0;
|
||||
next_camera = mp_get_camera_config(next_index);
|
||||
current_camera_index++;
|
||||
if (current_camera_index > configuration->count) {
|
||||
current_camera_index = 0;
|
||||
}
|
||||
|
||||
camera = next_camera;
|
||||
camera = configuration->cameras[current_camera_index];
|
||||
update_io_pipeline();
|
||||
}
|
||||
|
||||
@@ -828,11 +827,14 @@ open_iso_controls(GtkWidget *button, gpointer user_data)
|
||||
static void
|
||||
set_shutter(double value)
|
||||
{
|
||||
// TODO: Implement shutter in libmegapixels
|
||||
/*
|
||||
int new_exposure = (int)(value / 360.0 * camera->capture_mode.height);
|
||||
if (new_exposure != exposure) {
|
||||
exposure = new_exposure;
|
||||
update_io_pipeline();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -874,7 +876,8 @@ on_realize(GtkWidget *window, gpointer *data)
|
||||
GtkNative *native = gtk_widget_get_native(window);
|
||||
mp_process_pipeline_init_gl(gtk_native_get_surface(native));
|
||||
|
||||
camera = mp_get_camera_config(0);
|
||||
current_camera_index = 0;
|
||||
camera = configuration->cameras[0];
|
||||
update_io_pipeline();
|
||||
}
|
||||
|
||||
@@ -1338,9 +1341,19 @@ main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!mp_load_config())
|
||||
return 1;
|
||||
char configfile[PATH_MAX];
|
||||
libmegapixels_init(&configuration);
|
||||
if (libmegapixels_find_config(configfile)) {
|
||||
if (!libmegapixels_load_file(configuration, configfile)) {
|
||||
fprintf(stderr, "Could not load config\n");
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if (!libmegapixels_load_uvc(configuration)) {
|
||||
fprintf(stderr, "No config found\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
setenv("LC_NUMERIC", "C", 1);
|
||||
|
||||
|
Reference in New Issue
Block a user