repo: rxvt-unicode-sixel
action: commit
revision: 
path_from: 
revision_from: f978a897bdfd954a2e45a693eade22896cf63e76:
path_to: 
revision_to: 
git.thebackupbox.net
rxvt-unicode-sixel
git clone git://git.thebackupbox.net/rxvt-unicode-sixel
commit f978a897bdfd954a2e45a693eade22896cf63e76
Author: Marc Lehmann 
Date:   Tue Jun 5 13:39:26 2012 +0000

    *** empty log message ***

diff --git a/src/perl/background b/src/perl/background
index b4b203903ffce5024e39a75450c84ec0062b03f9..
index ..8964124d93049180c67e425591608352096537f2 100644
--- a/src/perl/background
+++ b/src/perl/background
@@ -1,6 +1,7 @@
 #! perl

-our $EXPR = 'move load "/root/pix/das_fette_schwein.jpg", left, top';
+our $EXPR = 'move load "/root/pix/das_fette_schwein.jpg", repeat_wrap, X, Y';
+$EXPR = 'rotate load "/root/pix/das_fette_schwein.jpg", W, H, 50, 50, counter 1/60, repeat_mirror';
 #$EXPR = 'blur root, 10, 10'
 #$EXPR = 'blur move (root, -x, -y), 5, 5'
 #resize load "/root/pix/das_fette_schwein.jpg", w, h
@@ -28,35 +29,53 @@ our ($l, $t, $w, $h);
       die "root op not supported, exg, we need you";
    }

+#   sub clone($) {
+#      $_[0]->clone
+#   }
+
+   sub subrect($$$$$;$) {
+      $_[0]->sub_rect ($_[1], $_[2], $_[3], $_[4], $_[5])
+   }
+
    sub resize($$$) {
       $_[0]->scale ($_[1], $_[2])
    }

-   sub move($$$) {
+   sub move($$$;$) {
       # TODO: must be simpler
-      $_[0]->transform ($_[0]->w, $_[0]->h, $_[1],
-         1, 0, -$_[2],
-         0, 1, -$_[3],
-         0, 0,      1,
+      $_[0]->transform ($_[0]->w, $_[0]->h,
+         1, 0, $_[1],
+         0, 1, $_[2],
+         0, 0,     1,
+         $_[3],
       )
    }

-   sub rotate($$$$) {
-      $_[0]->rotate ($_[0], $_[1], $_[2], $_[3] * (3.14159265 / 180))
+   sub rotate($$$$$$;$) {
+      $_[0]->rotate (
+         $_[1],
+         $_[2],
+         $_[3] * $_[0]->w * .01,
+         $_[4] * $_[0]->h * .01,
+         $_[5] * (3.14159265 / 180),
+         $_[6],
+      )
    }

    sub blur($$$) {
       my ($img, $rh, $rv) = @_;

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

    sub contrast($$;$$;$) {
       my ($img, $r, $g, $b, $a) = @_;
+
       ($g, $b) = ($r, $r) if @_ < 4;
       $a       = 1        if @_ < 5;
+
       $img = $img->clone;
       $img->contrast ($r, $g, $b, $a);
       $img
@@ -64,17 +83,19 @@ our ($l, $t, $w, $h);

    sub brightness($$;$$;$) {
       my ($img, $r, $g, $b, $a) = @_;
+
       ($g, $b) = ($r, $r) if @_ < 4;
       $a       = 1        if @_ < 5;
+
       $img = $img->clone;
       $img->brightness ($r, $g, $b, $a);
       $img
    }

-   sub left  () { $new->{position_sensitive} = 1; $l }
-   sub top   () { $new->{position_sensitive} = 1; $t }
-   sub width () { $new->{size_sensitive}     = 1; $w }
-   sub height() { $new->{size_sensitive}     = 1; $h }
+   sub X() { $new->{position_sensitive} = 1; $l }
+   sub Y() { $new->{position_sensitive} = 1; $t }
+   sub W() { $new->{size_sensitive}     = 1; $w }
+   sub H() { $new->{size_sensitive}     = 1; $h }

    sub now() { urxvt::NOW }

@@ -98,7 +119,6 @@ sub parse_expr {
 sub set_expr {
    my ($self, $expr) = @_;

-   local $Data::Dumper::Deparse=1; use Data::Dumper; warn Dumper $expr;#d#
    $self->{expr} = $expr;
    $self->recalculate;
 }
@@ -115,8 +135,6 @@ sub recalculate {
    ($l, $t, $w, $h) =
       $self->get_geometry;

-      warn "$l, $t";#d#
-
    my $img = eval { $self->{expr}->() };
    warn $@ if $@;#d#

@@ -141,9 +159,9 @@ sub recalculate {
       $self->disable ("size_change");
    }

-   # TODO: install handlers for geometry changes &c
+   $img = $img->sub_rect (0, 0, $w, $h)
+      if $img->w != $w || $img->h != $h;

-   warn $img;
    $self->set_background ($img);
    $self->scr_recolour (0);
    $self->want_refresh;
diff --git a/src/rxvtimg.C b/src/rxvtimg.C
index ef965cfa4817776f0d92ca280fbc689e41b81c5c..
index ..e11480a207d9e9b52b6de770ebf309d0d6652076 100644
--- a/src/rxvtimg.C
+++ b/src/rxvtimg.C
@@ -312,15 +312,34 @@ rxvt_img::render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int
 rxvt_img *
 rxvt_img::clone ()
 {
+  rxvt_img *img = new rxvt_img (s, format, w, h);
+
   GC gc = XCreateGC (s->display->dpy, pm, 0, 0);
-  Pixmap pm2 = XCreatePixmap (s->display->dpy, pm, w, h, format->depth);
-  XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, w, h, 0, 0);
+  XCopyArea (s->display->dpy, pm, img->pm, gc, 0, 0, w, h, 0, 0);
   XFreeGC (s->display->dpy, gc);
-  return new rxvt_img (s, format, w, h, pm2);
 }

 rxvt_img *
-rxvt_img::transform (int new_width, int new_height, int repeat, double matrix[9])
+rxvt_img::sub_rect (int x, int y, int width, int height, int repeat)
+{
+  rxvt_img *img = new rxvt_img (s, format, width, height);
+
+  Display *dpy = s->display->dpy;
+  XRenderPictureAttributes pa;
+  pa.repeat = repeat;
+  Picture src = XRenderCreatePicture (dpy,      pm,      format, CPRepeat, &pa);
+  Picture dst = XRenderCreatePicture (dpy, img->pm, img->format,        0,   0);
+
+  XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, width, height);
+
+  XRenderFreePicture (dpy, src);
+  XRenderFreePicture (dpy, dst);
+
+  return img;
+}
+
+rxvt_img *
+rxvt_img::transform (int new_width, int new_height, double matrix[9], int repeat)
 {
   rxvt_img *img = new rxvt_img (s, format, new_width, new_height);

@@ -355,11 +374,11 @@ rxvt_img::scale (int new_width, int new_height)
     0,                      0, 1
   };

-  return transform (new_width, new_height, RepeatNormal, matrix);
+  return transform (new_width, new_height, matrix);
 }

 rxvt_img *
-rxvt_img::rotate (int new_width, int new_height, int repeat, int x, int y, double phi)
+rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi, int repeat)
 {
   double s = sin (phi);
   double c = cos (phi);
@@ -370,7 +389,7 @@ rxvt_img::rotate (int new_width, int new_height, int repeat, int x, int y, doubl
     0,  0,                  1
   };

-  return transform (new_width, new_height, repeat, matrix);
+  return transform (new_width, new_height, matrix, repeat);
 }

 rxvt_img *
diff --git a/src/rxvtimg.h b/src/rxvtimg.h
index 4307d07e23c3e9b5955d6873e3ea0325f9951861..
index ..dc0411f7b48c62b035a0185e1312f2c9ad15b2a6 100644
--- a/src/rxvtimg.h
+++ b/src/rxvtimg.h
@@ -40,9 +40,10 @@ struct rxvt_img

   // copy
   rxvt_img *clone ();
-  rxvt_img *transform (int new_width, int new_height, int repeat, double matrix[9]);
+  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);
   rxvt_img *scale (int new_width, int new_height);
-  rxvt_img *rotate (int new_width, int new_height, int repeat, int x, int y, double phi);
+  rxvt_img *rotate (int new_width, int new_height, int x, int y, double phi, int repeat = RepeatNormal);
   rxvt_img *convert_to (XRenderPictFormat *format);
 };

diff --git a/src/rxvtperl.xs b/src/rxvtperl.xs
index 686a73e4e3f551d9a950f5d019303bf5b9c8b290..
index ..e695582f504452702bd83c9ec1818c5d58209a76 100644
--- a/src/rxvtperl.xs
+++ b/src/rxvtperl.xs
@@ -54,6 +54,8 @@
 typedef char *		octet_string;
 typedef char *		utf8_string;

+typedef int		render_repeat_mode;
+
 typedef GdkPixbuf *	urxvt__pixbuf;
 typedef rxvt_img *	urxvt__img;

@@ -847,6 +849,22 @@ fatal (const char *msg)
 void
 _exit (int status)

+void
+catch_fatal (SV *block)
+	PROTOTYPE: &
+        CODE:
+        try
+          {
+            PUSHMARK (SP);
+            PUTBACK;
+            call_sv (block, G_VOID | G_DISCARD);
+            SPAGAIN;
+          }
+        catch (const rxvt_failure_exception &e)
+          {
+            croak ("rxvt_fatal exception caught, trying to continue.");
+          }
+
 NV
 NOW ()
 	CODE:
@@ -2128,20 +2146,23 @@ rxvt_img *
 rxvt_img::clone ()

 rxvt_img *
-rxvt_img::transform (int new_width, int new_height, int repeat, NV p11, NV p12, NV p13, NV p21, NV p22, NV p23, NV p31, NV p32, NV p33)
+rxvt_img::sub_rect (int x, int y, int width, int height, render_repeat_mode repeat = RepeatNormal)
+
+rxvt_img *
+rxvt_img::transform (int new_width, int new_height, NV p11, NV p12, NV p13, NV p21, NV p22, NV p23, NV p31, NV p32, NV p33, render_repeat_mode repeat = RepeatNormal)
 	INIT:
         double matrix[9] = {
           p11, p12, p13,
           p21, p22, p23,
           p31, p32, p33
         };
-	C_ARGS: new_width, new_height, repeat, matrix
+	C_ARGS: new_width, new_height, matrix, repeat

 rxvt_img *
 rxvt_img::scale (int new_width, int new_height)

 rxvt_img *
-rxvt_img::rotate (int new_width, int new_height, int repeat, int x, int y, NV phi)
+rxvt_img::rotate (int new_width, int new_height, int x, int y, NV phi, render_repeat_mode repeat = RepeatNormal)

 #endif

diff --git a/src/rxvttoolkit.C b/src/rxvttoolkit.C
index a3625533c7e6a72a78c131d28f29765d41170c30..
index ..40295ba6217502a4838617ea3cf15127d0b26a31 100644
--- a/src/rxvttoolkit.C
+++ b/src/rxvttoolkit.C
@@ -475,6 +475,9 @@ bool rxvt_display::ref_init ()
     {
       flags |= DISPLAY_HAS_RENDER;

+      if (major > 0 || (major == 0 && minor >= 10))
+        flags |= DISPLAY_HAS_RENDER_10;
+
       if (major > 0 || (major == 0 && minor >= 11))
         flags |= DISPLAY_HAS_RENDER_MUL;

diff --git a/src/rxvttoolkit.h b/src/rxvttoolkit.h
index deaef64586c0b8196454c2391d50710c6e59c1d7..
index ..5f5a3aea3e3b07945b6c8597043aaeebe0508e1b 100644
--- a/src/rxvttoolkit.h
+++ b/src/rxvttoolkit.h
@@ -220,8 +220,9 @@ struct rxvt_screen

 enum {
   DISPLAY_HAS_RENDER      = 1 << 0,
-  DISPLAY_HAS_RENDER_MUL  = 1 << 1,
-  DISPLAY_HAS_RENDER_CONV = 1 << 2,
+  DISPLAY_HAS_RENDER_10   = 1 << 1,
+  DISPLAY_HAS_RENDER_MUL  = 1 << 2,
+  DISPLAY_HAS_RENDER_CONV = 1 << 3,
 };

 struct rxvt_display : refcounted
diff --git a/src/typemap b/src/typemap
index 7655489ba47e39b05d6c362e4ca3744a22705f71..
index ..429b8e914ce66b37377d0d68d800fa6fdf8fcf53 100644
--- a/src/typemap
+++ b/src/typemap
@@ -15,6 +15,8 @@ rxvt_img *		IMG

 GError **		T_UV

+render_repeat_mode	RENDER_REPEAT_MODE
+
 INPUT

 TERM
@@ -34,6 +36,16 @@ IMG
         else
           croak (\"%s is not of type urxvt::img\", \"$var\")

+RENDER_REPEAT_MODE
+	if (SvOK ($arg))
+          {
+	    $var = SvIV ($arg);
+            if ($var != RepeatNone && $var != RepeatNormal && $var != RepeatPad && $var != RepeatReflect)
+              croak (\"invalid repeat mode specified (%d)\\n\", $var);
+          }
+        else
+          $var = RepeatNormal;
+
 OUTPUT

 TERM

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