--- rxvt-unicode/src/rxvtimg.C 2012/06/15 18:10:40 1.94 +++ rxvt-unicode/src/rxvtimg.C 2012/06/17 17:06:47 1.97 @@ -1,3 +1,26 @@ +/*----------------------------------------------------------------------* + * File: rxvtimg.C + *----------------------------------------------------------------------* + * + * All portions of code are copyright by their respective author/s. + * Copyright (c) 2012 Marc Lehmann + * Copyright (c) 2012 Emanuele Giaquinta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + *---------------------------------------------------------------------*/ + #include #include #include "../config.h" @@ -18,7 +41,7 @@ { } - mat3x3 (nv matrix[3][3]) + mat3x3 (const nv *matrix) { memcpy (v, matrix, sizeof (v)); } @@ -35,6 +58,9 @@ 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 +73,8 @@ } static mat3x3 translate (nv x, nv y); + static mat3x3 scale (nv s, nv t); + static mat3x3 rotate (nv phi); }; mat3x3 @@ -100,6 +128,30 @@ ); } + 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 @@ -266,7 +318,7 @@ uint8_t b = *src++; uint32_t v = (255 << 24) | (r << 16) | (g << 8) | b; - + if (ecb_big_endian () ? !byte_order_mismatch : byte_order_mismatch) v = ecb_bswap32 (v); @@ -399,7 +451,7 @@ Picture src = picture (); Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); - + XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); XRenderFreePicture (dpy, src); @@ -617,7 +669,7 @@ Picture src = img->picture (); Picture dst = picture (); Picture mask_p = 0; - + if (mask != 1.) { mask_p = create_xrender_mask (dpy, img->pm, False, False); @@ -658,7 +710,7 @@ Picture src = picture (); Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); - + if (alpha) { XRenderColor rc = { 0, 0, 0, 0 }; @@ -696,13 +748,19 @@ } 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 +814,10 @@ 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 +828,14 @@ 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);