aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab+samsung@kernel.org>2018-09-04 20:37:01 (GMT)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>2018-09-05 10:18:57 (GMT)
commitf676a8dbc674f7e076b8166de6c6d7887ea7b3da (patch)
tree4813081178f11ea78093db1d25c8449f434dc400
parentb7c0e34d931af0bf04437e22b2490bee671e123f (diff)
add support for scaling the image with cairoscale_gtk_output
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>
-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 d731b86..1a61add 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)
@@ -606,6 +630,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);
diff --git a/src/callbacks.h b/src/callbacks.h
index c0c2e1b..2920cd4 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -68,6 +68,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 5b434e3..4096007 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 d991a63..e17d9a2 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