aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab+samsung@kernel.org>2018-09-04 17:37:01 -0300
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>2018-09-05 14:33:35 -0300
commit0715aaefb72e27e5e1a811386236ce7da8e5e47e (patch)
tree1e657189a615d268480229a47632921b3c74eb68 /src
parenta64c94d43fe1044d76d003254eaa5e843cc2ee51 (diff)
add support for scaling the image with cairo
It is easy to scale the image with cairo. Add support for it. For now, it reserves about 2/3 of the screen for the image stream display, keeping 1/3 reserved for the interface. It probably makes sense to add ways for the user to change the scale. It should be noticed that the snapshots won't be affected for the scale; will keep using the image resolution. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Diffstat (limited to 'src')
-rw-r--r--src/callbacks.c51
-rw-r--r--src/callbacks.h1
-rw-r--r--src/camorama-window.c9
-rw-r--r--src/main.c4
-rw-r--r--src/v4l.h2
5 files changed, 47 insertions, 20 deletions
diff --git a/src/callbacks.c b/src/callbacks.c
index 5f8df42..3d2ec9f 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -351,10 +351,44 @@ void on_preferences1_activate(GtkMenuItem *menuitem, gpointer user_data)
gtk_widget_show(prefswindow);
}
+void set_image_scale(cam_t *cam)
+{
+ gchar *title;
+ float f;
+
+ if (cam->width > 0.66 * cam->screen_width || cam->height > 0.66 * cam->screen_height) {
+ cam->scale = (0.66 * cam->screen_width) / cam->width;
+ f = (0.66 * cam->screen_height) / cam->height;
+
+ if (f < cam->scale)
+ cam->scale = f;
+ if (cam->scale < 0.1f)
+ cam->scale = 0.1f;
+ } else {
+ cam->scale = 1.f;
+ }
+
+ gtk_widget_set_size_request(GTK_WIDGET(gtk_builder_get_object(cam->xml, "da")),
+ cam->width * cam->scale,
+ cam->height * cam->scale);
+
+ gtk_window_resize(GTK_WINDOW(GTK_WIDGET(gtk_builder_get_object(cam->xml, "main_window"))),
+ 320, 240);
+
+ if (cam->scale == (float)1.)
+ title = g_strdup_printf("Camorama - %s - %dx%d", cam->name,
+ cam->width, cam->height);
+ else
+ title = g_strdup_printf("Camorama - %s - %dx%d (scale: %d%%)", cam->name,
+ cam->width, cam->height, (int)(cam->scale * 100.f));
+ gtk_window_set_title(GTK_WINDOW(GTK_WIDGET(gtk_builder_get_object(cam->xml, "main_window"))),
+ title);
+ g_free(title);
+}
+
void on_change_size_activate(GtkWidget *widget, cam_t *cam)
{
gchar const *name;
- gchar *title;
unsigned int width = 0, height = 0;
name = gtk_widget_get_name(widget);
@@ -390,17 +424,7 @@ void on_change_size_activate(GtkWidget *widget, cam_t *cam)
if (cam->read == FALSE)
start_streaming(cam);
- gtk_widget_set_size_request(GTK_WIDGET(gtk_builder_get_object(cam->xml, "da")),
- cam->width, cam->height);
-
- gtk_window_resize(GTK_WINDOW(GTK_WIDGET(gtk_builder_get_object(cam->xml, "main_window"))),
- 320, 240);
-
- title = g_strdup_printf("Camorama - %s - %dx%d",
- cam->name, cam->width, cam->height);
- gtk_window_set_title(GTK_WINDOW(GTK_WIDGET(gtk_builder_get_object(cam->xml, "main_window"))),
- title);
- g_free(title);
+ set_image_scale(cam);
}
void on_show_adjustments_activate(GtkToggleButton *button, cam_t *cam)
@@ -590,6 +614,9 @@ static void show_buffer(cam_t *cam)
gdk_cairo_rectangle(cr, &rect);
+ if (cam->scale != 1.f)
+ cairo_scale(cr, cam->scale, cam->scale);
+
cairo_fill(cr);
cairo_destroy(cr);
cairo_surface_destroy(surface);
diff --git a/src/callbacks.h b/src/callbacks.h
index 30e15b2..3b6007c 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -69,6 +69,7 @@ void wb_change(GtkHScale *, cam_t *);
gboolean on_drawingarea_expose_event(GtkWidget *, GdkEventExpose *,
cam_t *);
void update_tooltip(cam_t *cam);
+void set_image_scale(cam_t *cam);
G_END_DECLS
diff --git a/src/camorama-window.c b/src/camorama-window.c
index c5c0857..ff1333c 100644
--- a/src/camorama-window.c
+++ b/src/camorama-window.c
@@ -194,7 +194,6 @@ static void tray_clicked_callback(GtkStatusIcon *status, guint button,
void load_interface(cam_t *cam)
{
unsigned int i;
- gchar *title;
GdkPixbuf *logo = NULL;
GtkCellRenderer *cell;
GtkWidget *small_res, *new_res;
@@ -258,11 +257,6 @@ void load_interface(cam_t *cam)
* glade_xml_signal_autoconnect(xml);
* this won't work, can't pass data to callbacks. have to do it individually :(*/
- title = g_strdup_printf("Camorama - %s - %dx%d", cam->name,
- cam->width, cam->height);
- gtk_window_set_title(GTK_WINDOW(window), title);
- g_free(title);
-
gtk_window_set_icon(GTK_WINDOW(window), logo);
gtk_window_set_icon(GTK_WINDOW(GTK_WIDGET(gtk_builder_get_object(cam->xml, "prefswindow"))), logo);
@@ -562,8 +556,7 @@ void load_interface(cam_t *cam)
gtk_widget_set_sensitive(GTK_WIDGET(gtk_builder_get_object(cam->xml, "string_entry")),
cam->usestring);
- gtk_widget_set_size_request(GTK_WIDGET(gtk_builder_get_object(cam->xml, "da")),
- cam->width, cam->height);
+ set_image_scale(cam);
prefswindow = GTK_WIDGET(gtk_builder_get_object(cam->xml, "prefswindow"));
}
diff --git a/src/main.c b/src/main.c
index 257e4ee..1420c01 100644
--- a/src/main.c
+++ b/src/main.c
@@ -65,6 +65,7 @@ int main(int argc, char *argv[])
cam->height = 0;
cam->res = NULL;
cam->n_res = 0;
+ cam->scale = 1.f;
bindtextdomain(PACKAGE_NAME, PACKAGE_LOCALE_DIR);
bind_textdomain_codeset(PACKAGE_NAME, "UTF-8");
@@ -85,6 +86,9 @@ int main(int argc, char *argv[])
cam->width = x;
cam->height = y;
+ cam->screen_width = gdk_screen_width();
+ cam->screen_height = gdk_screen_height();
+
if (ver) {
fprintf(stderr, _("\n\nCamorama version %s\n\n"), PACKAGE_VERSION);
exit(0);
diff --git a/src/v4l.h b/src/v4l.h
index 1d4fa1f..bc81061 100644
--- a/src/v4l.h
+++ b/src/v4l.h
@@ -50,7 +50,9 @@ struct resolutions {
typedef struct camera {
int dev;
unsigned int width, height;
+ unsigned int screen_width, screen_height;
int bpp;
+ float scale;
CamoImageSize size;
char name[32];
int contrast, brightness, whiteness, colour, hue, bytesperline;

Privacy Policy