repo: rxvt-unicode-sixel
action: commit
revision: 
path_from: 
revision_from: 853c74f08650c122568fcb3ddfc9df278fbeafa6:
path_to: 
revision_to: 
git.thebackupbox.net
rxvt-unicode-sixel
git clone git://git.thebackupbox.net/rxvt-unicode-sixel
commit 853c74f08650c122568fcb3ddfc9df278fbeafa6
Author: Emanuele Giaquinta 
Date:   Tue Jun 5 15:18:24 2012 +0000

    Make rxvt_img::blur non-inplace.

diff --git a/src/perl/background b/src/perl/background
index 5906aa2a70711676615e6612a25066de32916f37..
index ..5a4c74fadbc84d33dc95b486271d3a61f0b4e72a 100644
--- a/src/perl/background
+++ b/src/perl/background
@@ -75,9 +75,7 @@ our $MIN_INTERVAL = 1/100;
    sub blur($$$) {
       my ($rh, $rv, $img) = @_;

-      $img = $img->clone;
       $img->blur ($rh, $rv);
-      $img
    }

    sub contrast($$;$$;$) {
diff --git a/src/rxvtimg.C b/src/rxvtimg.C
index 5077fe096ace0d078d2f6357b6716441f609511c..
index ..585751ee0300cd23d2803ce3f2412f38c71cc327 100644
--- a/src/rxvtimg.C
+++ b/src/rxvtimg.C
@@ -121,24 +121,27 @@ get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params)
     params[i+2] = XDoubleToFixed (kernel[i] / sum);
 }

-void
+rxvt_img *
 rxvt_img::blur (int rh, int rv)
 {
   if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV))
-    return;
+    return clone ();

   Display *dpy = s->display->dpy;
   int size = max (rh, rv) * 2 + 1;
   double *kernel = (double *)malloc (size * sizeof (double));
   XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
+  rxvt_img *img = new rxvt_img (s, format, w, h);

   XRenderPictureAttributes pa;

   pa.repeat = RepeatPad;
-  Picture src = XRenderCreatePicture (dpy, pm , format, CPRepeat, &pa);
-  Pixmap tmp = XCreatePixmap (dpy, pm, w, h, format->depth);
-  Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa);
-  XFreePixmap (dpy, tmp);
+  Picture src = XRenderCreatePicture (dpy, pm     , format, CPRepeat, &pa);
+  Picture dst = XRenderCreatePicture (dpy, img->pm, format, CPRepeat, &pa);
+
+  Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth);
+  Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa);
+  XFreePixmap (dpy, tmp_pm);

   if (kernel && params)
     {
@@ -150,14 +153,12 @@ rxvt_img::blur (int rh, int rv)
                         PictOpSrc,
                         src,
                         None,
-                        dst,
+                        tmp,
                         0, 0,
                         0, 0,
                         0, 0,
                         w, h);

-      ::swap (src, dst);
-
       size = rv * 2 + 1;
       get_gaussian_kernel (rv, size, kernel, params);
       ::swap (params[0], params[1]);
@@ -165,7 +166,7 @@ rxvt_img::blur (int rh, int rv)
       XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
       XRenderComposite (dpy,
                         PictOpSrc,
-                        src,
+                        tmp,
                         None,
                         dst,
                         0, 0,
@@ -178,6 +179,9 @@ rxvt_img::blur (int rh, int rv)
   free (params);
   XRenderFreePicture (dpy, src);
   XRenderFreePicture (dpy, dst);
+  XRenderFreePicture (dpy, tmp);
+
+  return img;
 }

 static Picture
diff --git a/src/rxvtimg.h b/src/rxvtimg.h
index dc0411f7b48c62b035a0185e1312f2c9ad15b2a6..
index ..bf08a044fd691aef781f5236f3b435ebad164d1b 100644
--- a/src/rxvtimg.h
+++ b/src/rxvtimg.h
@@ -33,12 +33,12 @@ struct rxvt_img
   // inplace
   void unshare (); // create a copy of the pixmap if !shared
   void fill (const rxvt_color &c);
-  void blur (int rh, int rv);
   void brightness (double r, double g, double b, double a = 1.);
   void contrast (double r, double g, double b, double a = 1.);
   bool render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y);

   // copy
+  rxvt_img *blur (int rh, int rv);
   rxvt_img *clone ();
   rxvt_img *sub_rect (int x, int y, int width, int height, int repeat = RepeatNormal);
   rxvt_img *transform (int new_width, int new_height, double matrix[9], int repeat = RepeatNormal);
diff --git a/src/rxvtperl.xs b/src/rxvtperl.xs
index 015a6fdc362256954745d9f004e0f1ef804a779d..
index ..9e973f60f21eeb804ccffabd3c73c0927bd4383d 100644
--- a/src/rxvtperl.xs
+++ b/src/rxvtperl.xs
@@ -2130,7 +2130,7 @@ rxvt_img::DESTROY ()
 	CODE:
         delete THIS;

-void
+rxvt_img *
 rxvt_img::blur (int rh, int rv)

 void

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