[gtk-vnc] Added option for smooth scaling



commit 9823c725f22b26471775e8e4a6a12c16d48cf132
Author: Felix E. Klee <felix klee inka de>
Date:   Tue Oct 25 00:24:37 2016 +0200

    Added option for smooth scaling
    
    Smooth scaling can now be turned off by setting the option "smoothing"
    to false.

 src/libgtk-vnc_sym.version |    3 ++
 src/vncdisplay.c           |   69 ++++++++++++++++++++++++++++++++++++++++++++
 src/vncdisplay.h           |    3 ++
 3 files changed, 75 insertions(+), 0 deletions(-)
---
diff --git a/src/libgtk-vnc_sym.version b/src/libgtk-vnc_sym.version
index c6b91af..8fa21b6 100644
--- a/src/libgtk-vnc_sym.version
+++ b/src/libgtk-vnc_sym.version
@@ -57,6 +57,9 @@
     vnc_display_set_force_size;
     vnc_display_get_force_size;
 
+    vnc_display_set_smoothing;
+    vnc_display_get_smoothing;
+
 # introduced with 0.3.8
     vnc_display_get_option_entries;
 
diff --git a/src/vncdisplay.c b/src/vncdisplay.c
index 458d8ab..e4c2dc7 100644
--- a/src/vncdisplay.c
+++ b/src/vncdisplay.c
@@ -82,6 +82,7 @@ struct _VncDisplayPrivate
     gboolean allow_scaling;
     gboolean shared_flag;
     gboolean force_size;
+    gboolean smoothing;
 
     GSList *preferable_auths;
     GSList *preferable_vencrypt_subauths;
@@ -114,6 +115,7 @@ enum
     PROP_SCALING,
     PROP_SHARED_FLAG,
     PROP_FORCE_SIZE,
+    PROP_SMOOTHING,
     PROP_DEPTH,
     PROP_GRAB_KEYS,
     PROP_CONNECTION,
@@ -225,6 +227,9 @@ vnc_display_get_property (GObject    *object,
         case PROP_FORCE_SIZE:
             g_value_set_boolean (value, vnc->priv->force_size);
             break;
+        case PROP_SMOOTHING:
+            g_value_set_boolean (value, vnc->priv->smoothing);
+            break;
         case PROP_DEPTH:
             g_value_set_enum (value, vnc->priv->depth);
             break;
@@ -274,6 +279,9 @@ vnc_display_set_property (GObject      *object,
         case PROP_FORCE_SIZE:
             vnc_display_set_force_size (vnc, g_value_get_boolean (value));
             break;
+        case PROP_SMOOTHING:
+            vnc_display_set_smoothing (vnc, g_value_get_boolean (value));
+            break;
         case PROP_DEPTH:
             vnc_display_set_depth (vnc, g_value_get_enum (value));
             break;
@@ -423,6 +431,10 @@ static gboolean draw_event(GtkWidget *widget, cairo_t *cr)
                                      priv->fbCache,
                                      0,
                                      0);
+            if (!priv->smoothing) {
+                cairo_pattern_set_filter(cairo_get_source(cr),
+                                         CAIRO_FILTER_NEAREST);
+            }
         } else {
             cairo_set_source_surface(cr,
                                      priv->fbCache,
@@ -2252,6 +2264,18 @@ static void vnc_display_class_init(VncDisplayClass *klass)
                                                             G_PARAM_STATIC_BLURB));
 
     g_object_class_install_property (object_class,
+                                     PROP_SMOOTHING,
+                                     g_param_spec_boolean ( "smoothing",
+                                                            "Smooth scaling",
+                                                            "Whether we should smoothly interpolate when 
scaling",
+                                                            TRUE,
+                                                            G_PARAM_READWRITE |
+                                                            G_PARAM_CONSTRUCT |
+                                                            G_PARAM_STATIC_NAME |
+                                                            G_PARAM_STATIC_NICK |
+                                                            G_PARAM_STATIC_BLURB));
+
+    g_object_class_install_property (object_class,
                                      PROP_DEPTH,
                                      g_param_spec_enum    ( "depth",
                                                             "Depth",
@@ -2490,6 +2514,7 @@ static void vnc_display_init(VncDisplay *display)
     priv->local_pointer = FALSE;
     priv->shared_flag = FALSE;
     priv->force_size = TRUE;
+    priv->smoothing = TRUE;
     priv->vncgrabseq = vnc_grab_sequence_new_from_string("Control_L+Alt_L");
     priv->vncactiveseq = g_new0(gboolean, priv->vncgrabseq->nkeysyms);
 
@@ -2934,6 +2959,33 @@ void vnc_display_set_force_size(VncDisplay *obj, gboolean enabled)
 
 
 /**
+ * vnc_display_smoothing:
+ * @obj: (transfer none): the VNC display widget
+ * @enabled: TRUE to enable smooth scaling, FALSE otherwise
+ *
+ * Set whether pixels are smoothly interpolated when scaling,
+ * to avoid aliasing.
+ */
+void vnc_display_set_smoothing(VncDisplay *obj, gboolean enabled)
+{
+    int ww, wh;
+
+    g_return_if_fail (VNC_IS_DISPLAY (obj));
+    obj->priv->smoothing = enabled;
+
+    if (obj->priv->fb != NULL) {
+        GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(obj));
+
+        if (window != NULL) {
+            gdk_drawable_get_size(gtk_widget_get_window(GTK_WIDGET(obj)),
+                                  &ww, &wh);
+            gtk_widget_queue_draw_area(GTK_WIDGET(obj), 0, 0, ww, wh);
+        }
+    }
+}
+
+
+/**
  * vnc_display_set_depth:
  * @obj: (transfer none): the VNC display widget
  * @depth: the desired colour depth
@@ -2992,6 +3044,23 @@ gboolean vnc_display_get_force_size(VncDisplay *obj)
 
 
 /**
+ * vnc_display_get_smoothing:
+ * @obj: (transfer none): the VNC display widget
+ *
+ * Determine whether pixels are smoothly interpolated when
+ * scaling.
+ *
+ * Returns: TRUE if smoothing is enabled, FALSE otherwise
+ */
+gboolean vnc_display_get_smoothing(VncDisplay *obj)
+{
+    g_return_val_if_fail (VNC_IS_DISPLAY (obj), FALSE);
+
+    return obj->priv->smoothing;
+}
+
+
+/**
  * vnc_display_get_scaling:
  * @obj: (transfer none): the VNC display widget
  *
diff --git a/src/vncdisplay.h b/src/vncdisplay.h
index b53eee3..57a3f8f 100644
--- a/src/vncdisplay.h
+++ b/src/vncdisplay.h
@@ -134,6 +134,9 @@ gboolean vnc_display_get_scaling(VncDisplay *obj);
 void vnc_display_set_force_size(VncDisplay *obj, gboolean enable);
 gboolean vnc_display_get_force_size(VncDisplay *obj);
 
+void vnc_display_set_smoothing(VncDisplay *obj, gboolean enable);
+gboolean vnc_display_get_smoothing(VncDisplay *obj);
+
 void vnc_display_set_shared_flag(VncDisplay *obj, gboolean shared);
 gboolean vnc_display_get_shared_flag(VncDisplay *obj);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]