repo: rxvt-unicode-sixel action: commit revision: path_from: revision_from: 4b8ef3821227afcc71af5dd226b8a1876d69344d: path_to: revision_to:
commit 4b8ef3821227afcc71af5dd226b8a1876d69344d Author: Marc LehmannDate: Fri Jun 15 18:36:26 2012 +0000 *** empty log message *** diff --git a/src/rxvtimg.C b/src/rxvtimg.C
--- a/src/rxvtimg.C
+++ b/src/rxvtimg.C
@@ -18,7 +18,7 @@ namespace
{
}
- mat3x3 (nv matrix[3][3])
+ mat3x3 (const nv *matrix)
{
memcpy (v, matrix, sizeof (v));
}
@@ -35,6 +35,9 @@ namespace
nv *operator [](int i) { return &v[i][0]; }
const nv *operator [](int i) const { return &v[i][0]; }
+ operator const nv * () const { return &v[0][0]; }
+ operator nv * () { return &v[0][0]; }
+
// quite inefficient, hopefully gcc pulls the w calc out of any loops
nv apply1 (int i, nv x, nv y)
{
@@ -47,6 +50,8 @@ namespace
}
static mat3x3 translate (nv x, nv y);
+ static mat3x3 scale (nv s, nv t);
+ static mat3x3 rotate (nv phi);
};
mat3x3
@@ -100,6 +105,30 @@ namespace
);
}
+ mat3x3
+ mat3x3::scale (nv s, nv t)
+ {
+ return mat3x3 (
+ s, 0, 0,
+ 0, t, 0,
+ 0, 0, 1
+ );
+ }
+
+ // clockwise
+ mat3x3
+ mat3x3::rotate (nv phi)
+ {
+ nv s = sin (phi);
+ nv c = cos (phi);
+
+ return mat3x3 (
+ c, -s, 0,
+ s, c, 0,
+ 0, 0, 1
+ );
+ }
+
}
#if 0
@@ -696,13 +725,19 @@ rxvt_img::sub_rect (int x, int y, int width, int height)
}
rxvt_img *
-rxvt_img::transform (nv matrix[3][3])
+rxvt_img::transform (const nv matrix[3][3])
{
- // calculate new pixel bounding box coordinates
- nv r[2], rmin[2], rmax[2];
+ return transform (mat3x3 (&matrix[0][0]));
+}
+rxvt_img *
+rxvt_img::transform (const nv *matrix)
+{
mat3x3 m (matrix);
+ // calculate new pixel bounding box coordinates
+ nv r[2], rmin[2], rmax[2];
+
for (int i = 0; i < 2; ++i)
{
nv v;
@@ -756,16 +791,10 @@ rxvt_img::scale (int new_width, int new_height)
if (w == new_width && h == new_height)
return clone ();
- nv matrix[3][3] = {
- { new_width / (nv)w, 0, 0 },
- { 0, new_height / (nv)h, 0 },
- { 0, 0, 1 }
- };
-
int old_repeat_mode = repeat;
repeat = RepeatPad; // not right, but xrender can't properly scale it seems
- rxvt_img *img = transform (matrix);
+ rxvt_img *img = transform (mat3x3::scale (new_width / (nv)w, new_height / (nv)h));
repeat = old_repeat_mode;
img->repeat = repeat;
@@ -776,23 +805,14 @@ rxvt_img::scale (int new_width, int new_height)
rxvt_img *
rxvt_img::rotate (int cx, int cy, nv phi)
{
- nv s = sin (phi);
- nv c = cos (phi);
-
- nv matrix[3][3] = {
#if 0
{ c, -s, cx - c * cx + s * cy },
{ s, c, cy - s * cx - c * cy },
{ 0, 0, 1 }
-#else
- { c, -s, 0 },
- { s, c, 0 },
- { 0, 0, 1 }
#endif
- };
move (-cx, -cy);
- rxvt_img *img = transform (matrix);
+ rxvt_img *img = transform (mat3x3::rotate (phi));
move ( cx, cy);
img->move (cx, cy);
diff --git a/src/rxvtimg.h b/src/rxvtimg.h
--- a/src/rxvtimg.h +++ b/src/rxvtimg.h @@ -11,12 +11,8 @@ #include-class rxvt_img +struct rxvt_img { - void destroy (); - Picture picture (); - -public: typedef double nv; // *could* also hold the Pixmap itself @@ -100,7 +96,7 @@ public: rxvt_img *blur (int rh, int rv); rxvt_img *clone (); rxvt_img *sub_rect (int x, int y, int width, int height); - rxvt_img *transform (nv matrix[3][3]); + rxvt_img *transform (const nv matrix[3][3]); rxvt_img *scale (int new_width, int new_height); rxvt_img *rotate (int cx, int cy, nv phi); rxvt_img *convert_format (XRenderPictFormat *format, const rgba &bg); @@ -113,6 +109,12 @@ public: p = this; return this; } + +private: + + void destroy (); + Picture picture (); + rxvt_img *transform (const nv *matrix); }; #endif
-----END OF PAGE-----