-- Leo's gemini proxy

-- Connecting to git.thebackupbox.net:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

repo: rxvt-unicode-sixel
action: commit
revision:
path_from:
revision_from: d026c739ddd6244e472ee0cc4a87dddb25acaee1:
path_to:
revision_to:

git.thebackupbox.net

rxvt-unicode-sixel

git://git.thebackupbox.net/rxvt-unicode-sixel

commit d026c739ddd6244e472ee0cc4a87dddb25acaee1
Author: Emanuele Giaquinta <emanuele.giaquinta@gmail.com>
Date:   Thu May 31 05:53:46 2012 +0000

    Refactor tint/blur variables and methods into a new image_effects
    object, so as to be able to apply such effects to multiple images.

diff --git a/src/background.C b/src/background.C

index 0f122ccddc916dff8de800d32522edc5cd527c29..

index ..1a938b98abc812d04d8cdc1ac9133164b1b5417d 100644

--- a/src/background.C
+++ b/src/background.C
@@ -605,6 +605,11 @@ rxvt_term::render_image (rxvt_image &image)
                               dst_width, dst_height, need_blend);
         }

+      if (image.need_blur ())
+        blur_pixmap (tmp_pixmap, new_pmap_width, new_pmap_height, need_blend, image.h_blurRadius, image.v_blurRadius);
+      if (image.need_tint ())
+        tint_pixmap (tmp_pixmap, new_pmap_width, new_pmap_height, need_blend, image.tint, image.tint_set, image.shade);
+
 #if XRENDER
       if (need_blend)
         {
@@ -743,9 +748,8 @@ rxvt_image::set_file (const char *file)

 # endif /* BG_IMAGE_FROM_FILE */

-# ifdef ENABLE_TRANSPARENCY
 bool
-rxvt_term::bg_set_blur (const char *geom)
+image_effects::set_blur (const char *geom)
 {
   bool changed = false;
   unsigned int hr, vr;
@@ -776,21 +780,12 @@ rxvt_term::bg_set_blur (const char *geom)
 }

 bool
-rxvt_term::bg_set_tint (rxvt_color &new_tint)
+image_effects::set_tint (const rxvt_color &new_tint)
 {
-  if (!(bg_flags & BG_TINT_SET) || tint != new_tint)
+  if (!tint_set || tint != new_tint)
     {
       tint = new_tint;
-      bg_flags |= BG_TINT_SET;
-
-      rgba c;
-      tint.get (c);
-      if ((c.r <= 0x00ff || c.r >= 0xff00)
-          && (c.g <= 0x00ff || c.g >= 0xff00)
-          && (c.b <= 0x00ff || c.b >= 0xff00))
-        bg_flags |= BG_TINT_BITAND;
-      else
-        bg_flags &= ~BG_TINT_BITAND;
+      tint_set = true;

       return true;
     }
@@ -799,7 +794,7 @@ rxvt_term::bg_set_tint (rxvt_color &new_tint)
 }

 bool
-rxvt_term::bg_set_shade (const char *shade_str)
+image_effects::set_shade (const char *shade_str)
 {
   int new_shade = atoi (shade_str);

@@ -840,7 +835,7 @@ get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params)
 #endif

 bool
-rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height)
+rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height, bool argb, int h_blurRadius, int v_blurRadius)
 {
   bool ret = false;
 #if XRENDER
@@ -852,7 +847,8 @@ rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height)
   XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));

   XRenderPictureAttributes pa;
-  XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
+  XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32)
+                                   : XRenderFindVisualFormat (dpy, visual);

   pa.repeat = RepeatPad;
   Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa);
@@ -905,11 +901,19 @@ rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height)
 }

 bool
-rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height)
+rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height, bool argb, rxvt_color &tint, bool tint_set, int shade)
 {
   bool ret = false;

-  if (shade == 100 && (bg_flags & BG_TINT_BITAND))
+  rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
+
+  if (tint_set)
+    tint.get (c);
+
+  if (shade == 100
+      && (c.r <= 0x00ff || c.r >= 0xff00)
+      && (c.g <= 0x00ff || c.g >= 0xff00)
+      && (c.b <= 0x00ff || c.b >= 0xff00))
     {
       XGCValues gcv;
       GC gc;
@@ -931,11 +935,6 @@ rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height)
 #  if XRENDER
   else if (bg_flags & BG_HAS_RENDER)
     {
-      rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
-
-      if (bg_flags & BG_TINT_SET)
-        tint.get (c);
-
       if (shade <= 100)
         {
           c.r = c.r * shade / 100;
@@ -949,7 +948,8 @@ rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height)
           c.b = c.b * (200 - shade) / 100;
         }

-      XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
+      XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32)
+                                       : XRenderFindVisualFormat (dpy, visual);

       Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0);

@@ -995,6 +995,7 @@ rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height)
   return ret;
 }

+# ifdef ENABLE_TRANSPARENCY
 /*
  * Builds a pixmap of the same size as the terminal window that contains
  * the tiled portion of the root pixmap that is supposed to be covered by
@@ -1095,19 +1096,21 @@ rxvt_term::make_transparency_pixmap ()
     {
       XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height);
       ret = true;
-      bool need_blur = h_blurRadius && v_blurRadius;
-      bool need_tint = shade != 100 || (bg_flags & BG_TINT_SET);
+      bool need_blur = root_effects.need_blur ();
+      bool need_tint = root_effects.need_tint ();

       if (!(bg_flags & BG_CLIENT_RENDER))
         {
           if (need_blur)
             {
-              if (blur_pixmap (bg_pixmap, window_width, window_height))
+              if (blur_pixmap (bg_pixmap, window_width, window_height, false,
+                               root_effects.h_blurRadius, root_effects.v_blurRadius))
                 need_blur = false;
             }
           if (need_tint)
             {
-              if (tint_pixmap (bg_pixmap, window_width, window_height))
+              if (tint_pixmap (bg_pixmap, window_width, window_height, false,
+                               root_effects.tint, root_effects.tint_set, root_effects.shade))
                 need_tint = false;
             }
           if (need_tint)
@@ -1116,7 +1119,7 @@ rxvt_term::make_transparency_pixmap ()
               if (ximage)
                 {
                   /* our own client-side tinting */
-                  tint_ximage (ximage);
+                  tint_ximage (ximage, root_effects.tint, root_effects.tint_set, root_effects.shade);

                   XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height);
                   XDestroyImage (ximage);
@@ -1185,10 +1188,6 @@ rxvt_term::bg_render ()
 void
 rxvt_term::bg_init ()
 {
-#ifdef ENABLE_TRANSPARENCY
-  shade = 100;
-#endif
-
   bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV);
 #if XRENDER
   int major, minor;
@@ -1236,9 +1235,6 @@ rxvt_term::bg_init ()
 #endif
 }

-#endif /* HAVE_BG_PIXMAP */
-
-#ifdef ENABLE_TRANSPARENCY
 /* based on code from aterm-0.4.2 */

 static inline void
@@ -1254,7 +1250,7 @@ fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned
 }

 void
-rxvt_term::tint_ximage (XImage *ximage)
+rxvt_term::tint_ximage (XImage *ximage, rxvt_color &tint, bool tint_set, int shade)
 {
   unsigned int size_r, size_g, size_b;
   int sh_r, sh_g, sh_b;
@@ -1289,7 +1285,7 @@ rxvt_term::tint_ximage (XImage *ximage)

   rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);

-  if (bg_flags & BG_TINT_SET)
+  if (tint_set)
     tint.get (c);

   /* prepare limits for color transformation (each channel is handled separately) */
@@ -1349,4 +1345,5 @@ rxvt_term::tint_ximage (XImage *ximage)

   free (lookup);
 }
-#endif /* ENABLE_TRANSPARENCY */
+
+#endif /* HAVE_BG_PIXMAP */
diff --git a/src/command.C b/src/command.C

index 3425349b00e20447733b8ab6b09b4f4a35102e65..

index ..cf838b5ac5061880ac94e001ba7c7c30191b75e8 100644

--- a/src/command.C
+++ b/src/command.C
@@ -3439,7 +3439,7 @@ rxvt_term::process_xterm_seq (int op, char *str, char resp)
           bool changed = false;

           if (ISSET_PIXCOLOR (Color_tint))
-            changed = bg_set_tint (pix_colors_focused [Color_tint]);
+            changed = root_effects.set_tint (pix_colors_focused [Color_tint]);

           if (changed)
             update_background ();
diff --git a/src/init.C b/src/init.C

index b65c91a96f8e07f102ea869cf3da0b6d7430a54d..

index ..da0633906c92a96bbf6f8f1423e1057e5bdd6e28 100644

--- a/src/init.C
+++ b/src/init.C
@@ -820,13 +820,13 @@ rxvt_term::init2 (int argc, const char *const *argv)
         bg_set_transparent ();

         if (rs [Rs_blurradius])
-          bg_set_blur (rs [Rs_blurradius]);
+          root_effects.set_blur (rs [Rs_blurradius]);

         if (ISSET_PIXCOLOR (Color_tint))
-          bg_set_tint (pix_colors_focused [Color_tint]);
+          root_effects.set_tint (pix_colors_focused [Color_tint]);

         if (rs [Rs_shade])
-          bg_set_shade (rs [Rs_shade]);
+          root_effects.set_shade (rs [Rs_shade]);

         bg_set_root_pixmap ();
         XSelectInput (dpy, display->root, PropertyChangeMask);
diff --git a/src/rxvt.h b/src/rxvt.h

index 5ef33c547339b65077df1a89e946727eb1b579d2..

index ..a0d66489ecde889575d1f9f6a075518146fe7046 100644

--- a/src/rxvt.h
+++ b/src/rxvt.h
@@ -211,6 +211,36 @@ struct localise_env
 };

 #ifdef HAVE_BG_PIXMAP
+struct image_effects
+{
+  bool tint_set;
+  rxvt_color tint;
+  int shade;
+  int h_blurRadius, v_blurRadius;
+
+  image_effects ()
+  {
+    tint_set     =
+    h_blurRadius =
+    v_blurRadius = 0;
+    shade = 100;
+  }
+
+  bool need_tint ()
+  {
+    return shade != 100 || tint_set;
+  }
+
+  bool need_blur ()
+  {
+    return h_blurRadius && v_blurRadius;
+  }
+
+  bool set_tint (const rxvt_color &new_tint);
+  bool set_shade (const char *shade_str);
+  bool set_blur (const char *geom);
+};
+
 # ifdef BG_IMAGE_FROM_FILE
 enum {
   IM_IS_SET            = 1 << 0,
@@ -229,7 +259,7 @@ enum {
   defaultAlign = centerAlign,
 };

-struct rxvt_image
+struct rxvt_image : image_effects
 {
   unsigned short alpha;
   uint8_t flags;
@@ -1167,9 +1197,6 @@ struct rxvt_term : zero_initialized, rxvt_vars, rxvt_screen
     BG_HAS_RENDER        = 1 << 3,
     BG_HAS_RENDER_CONV   = 1 << 4,
     BG_CLIENT_RENDER     = 1 << 5,
-
-    BG_TINT_SET          = 1 << 6,
-    BG_TINT_BITAND       = 1 << 7,
   };

   uint8_t bg_flags;
@@ -1188,25 +1215,20 @@ struct rxvt_term : zero_initialized, rxvt_vars, rxvt_screen

 # ifdef ENABLE_TRANSPARENCY
   Pixmap      root_pixmap; /* current root pixmap set */
-  rxvt_color  tint;
-  int         shade;
-  int         h_blurRadius, v_blurRadius;
+  image_effects root_effects;

   void bg_set_transparent ()
   {
     bg_flags |= BG_IS_TRANSPARENT;
   }
   void bg_set_root_pixmap ();
-  bool bg_set_tint (rxvt_color &new_tint);
-  bool bg_set_shade (const char *shade_str);
-  bool bg_set_blur (const char *geom);
-
-  bool blur_pixmap (Pixmap pixmap, int width, int height);
-  bool tint_pixmap (Pixmap pixmap, int width, int height);
-  void tint_ximage (XImage *ximage);
   bool make_transparency_pixmap ();
 # endif

+  bool blur_pixmap (Pixmap pixmap, int width, int height, bool argb, int h_blurRadius, int v_blurRadius);
+  bool tint_pixmap (Pixmap pixmap, int width, int height, bool argb, rxvt_color &tint, bool tint_set, int shade);
+  void tint_ximage (XImage *ximage, rxvt_color &tint, bool tint_set, int shade);
+
   ev_tstamp bg_valid_since;

   Pixmap bg_pixmap;

-----END OF PAGE-----

-- Response ended

-- Page fetched on Sun Jun 2 11:45:33 2024