[Xfce4-commits] [apps/xfce4-terminal] 01/01: Scale huge background image resolution to 8K

noreply at xfce.org noreply at xfce.org
Sat Jan 21 14:16:30 CET 2017


This is an automated email from the git hooks/post-receive script.

f2404 pushed a commit to branch master
in repository apps/xfce4-terminal.

commit 24735e7686824098cd32425edad735fc08d1915f
Author: Igor <f2404 at yandex.ru>
Date:   Sat Jan 21 16:14:11 2017 +0300

    Scale huge background image resolution to 8K
    
    This allows to drastically decrease RAM usage when a huge image is selected
    as max 8K image will be stored in memory.
---
 terminal/terminal-image-loader.c | 76 +++++++++++++++++++++++++++++-----------
 terminal/terminal-image-loader.h | 10 +++---
 2 files changed, 60 insertions(+), 26 deletions(-)

diff --git a/terminal/terminal-image-loader.c b/terminal/terminal-image-loader.c
index a9cf7ad..b9fbbc2 100644
--- a/terminal/terminal-image-loader.c
+++ b/terminal/terminal-image-loader.c
@@ -25,26 +25,30 @@
 #include <terminal/terminal-image-loader.h>
 #include <terminal/terminal-private.h>
 
-
-
-static void terminal_image_loader_finalize         (GObject             *object);
-static void terminal_image_loader_check            (TerminalImageLoader *loader);
-static void terminal_image_loader_tile             (TerminalImageLoader *loader,
-                                                    GdkPixbuf           *target,
-                                                    gint                 width,
-                                                    gint                 height);
-static void terminal_image_loader_center           (TerminalImageLoader *loader,
-                                                    GdkPixbuf           *target,
-                                                    gint                 width,
-                                                    gint                 height);
-static void terminal_image_loader_scale            (TerminalImageLoader *loader,
-                                                    GdkPixbuf           *target,
-                                                    gint                 width,
-                                                    gint                 height);
-static void terminal_image_loader_stretch          (TerminalImageLoader *loader,
-                                                    GdkPixbuf           *target,
-                                                    gint                 width,
-                                                    gint                 height);
+/* max image resolution is 8K */
+#define MAX_IMAGE_WIDTH  7680
+#define MAX_IMAGE_HEIGHT 4320
+
+
+
+static void terminal_image_loader_finalize (GObject             *object);
+static void terminal_image_loader_check    (TerminalImageLoader *loader);
+static void terminal_image_loader_tile     (TerminalImageLoader *loader,
+                                            GdkPixbuf           *target,
+                                            gint                 width,
+                                            gint                 height);
+static void terminal_image_loader_center   (TerminalImageLoader *loader,
+                                            GdkPixbuf           *target,
+                                            gint                 width,
+                                            gint                 height);
+static void terminal_image_loader_scale    (TerminalImageLoader *loader,
+                                            GdkPixbuf           *target,
+                                            gint                 width,
+                                            gint                 height);
+static void terminal_image_loader_stretch  (TerminalImageLoader *loader,
+                                            GdkPixbuf           *target,
+                                            gint                 width,
+                                            gint                 height);
 
 
 struct _TerminalImageLoaderClass
@@ -115,9 +119,12 @@ terminal_image_loader_check (TerminalImageLoader *loader)
 {
   TerminalBackgroundStyle selected_style;
   GdkRGBA                 selected_color;
+  GdkPixbuf              *tmp;
   gboolean                invalidate = FALSE;
   gchar                  *selected_color_spec;
   gchar                  *selected_path;
+  gint                    width;
+  gint                    height;
 
   terminal_return_if_fail (TERMINAL_IS_IMAGE_LOADER (loader));
 
@@ -134,7 +141,34 @@ terminal_image_loader_check (TerminalImageLoader *loader)
 
       if (GDK_IS_PIXBUF (loader->pixbuf))
         g_object_unref (G_OBJECT (loader->pixbuf));
-      loader->pixbuf = gdk_pixbuf_new_from_file (loader->path, NULL);
+
+      tmp = gdk_pixbuf_new_from_file (loader->path, NULL);
+      width = gdk_pixbuf_get_width (tmp);
+      height = gdk_pixbuf_get_height (tmp);
+
+      if (width <= MAX_IMAGE_WIDTH && height <= MAX_IMAGE_HEIGHT)
+        loader->pixbuf = tmp;
+      else
+        {
+          /* scale image resolution down to 8K */
+          gdouble xscale = (gdouble) MAX_IMAGE_WIDTH / width;
+          gdouble yscale = (gdouble) MAX_IMAGE_HEIGHT / height;
+
+          if (xscale < yscale)
+            yscale = xscale;
+          else
+            xscale = yscale;
+          width = (gint) (width * xscale);
+          height = (gint) (height * yscale);
+
+          loader->pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (tmp),
+                                           gdk_pixbuf_get_has_alpha (tmp),
+                                           gdk_pixbuf_get_bits_per_sample (tmp),
+                                           width, height);
+          gdk_pixbuf_composite (tmp, loader->pixbuf, 0, 0, width, height,
+                                0, 0, xscale, yscale, GDK_INTERP_BILINEAR, 255);
+          g_object_unref (G_OBJECT (tmp));
+        }
 
       invalidate = TRUE;
     }
diff --git a/terminal/terminal-image-loader.h b/terminal/terminal-image-loader.h
index 4a427fa..a720347 100644
--- a/terminal/terminal-image-loader.h
+++ b/terminal/terminal-image-loader.h
@@ -34,13 +34,13 @@ G_BEGIN_DECLS
 typedef struct _TerminalImageLoaderClass TerminalImageLoaderClass;
 typedef struct _TerminalImageLoader      TerminalImageLoader;
 
-GType                terminal_image_loader_get_type   (void) G_GNUC_CONST;
+GType                terminal_image_loader_get_type (void) G_GNUC_CONST;
 
-TerminalImageLoader *terminal_image_loader_get        (void);
+TerminalImageLoader *terminal_image_loader_get      (void);
 
-GdkPixbuf           *terminal_image_loader_load (TerminalImageLoader *loader,
-                                                 gint                 width,
-                                                 gint                 height);
+GdkPixbuf           *terminal_image_loader_load     (TerminalImageLoader *loader,
+                                                     gint                 width,
+                                                     gint                 height);
 
 G_END_DECLS
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list