ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtimg.C
(Generate patch)

Comparing rxvt-unicode/src/rxvtimg.C (file contents):
Revision 1.36 by root, Thu Jun 7 08:45:34 2012 UTC vs.
Revision 1.71 by sf-exg, Sat Jun 9 14:18:53 2012 UTC

2#include "../config.h" 2#include "../config.h"
3#include "rxvt.h" 3#include "rxvt.h"
4 4
5#if HAVE_IMG 5#if HAVE_IMG
6 6
7rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height) 7rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height, int repeat)
8: s(screen), x(x), y(y), w(width), h(height), format(format), repeat(RepeatNormal), 8: s(screen), x(x), y(y), w(width), h(height), format(format), repeat(repeat),
9 pm(0), ref(0) 9 pm(0), ref(0)
10{ 10{
11} 11}
12 12
13rxvt_img::rxvt_img (const rxvt_img &img) 13rxvt_img::rxvt_img (const rxvt_img &img)
14: s(img.s), x(img.x), y(img.y), w(img.w), h(img.h), format(img.format), repeat(img.repeat), pm(img.pm), ref(img.ref) 14: s(img.s), x(img.x), y(img.y), w(img.w), h(img.h), format(img.format), repeat(img.repeat), pm(img.pm), ref(img.ref)
15{ 15{
16 ++ref->cnt; 16 ++ref->cnt;
17} 17}
18
19#if 0
20rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap)
21: s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false), pm(pixmap)
22{
23}
24#endif
25 18
26rxvt_img * 19rxvt_img *
27rxvt_img::new_from_root (rxvt_screen *s) 20rxvt_img::new_from_root (rxvt_screen *s)
28{ 21{
29 Display *dpy = s->display->dpy; 22 Display *dpy = s->display->dpy;
57 50
58 return img; 51 return img;
59} 52}
60 53
61rxvt_img * 54rxvt_img *
55rxvt_img::new_from_pixbuf (rxvt_screen *s, GdkPixbuf *pb)
56{
57 Display *dpy = s->display->dpy;
58
59 int width = gdk_pixbuf_get_width (pb);
60 int height = gdk_pixbuf_get_height (pb);
61
62 if (width > 32767 || height > 32767) // well, we *could* upload in chunks
63 rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big (maximum size 32768x32768).\n");
64
65 // since we require rgb24/argb32 formats from xrender we assume
66 // that both 24 and 32 bpp MUST be supported by any screen that supports xrender
67 int depth = gdk_pixbuf_get_has_alpha (pb) ? 32 : 24;
68
69 int byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
70
71 XImage xi;
72
73 xi.width = width;
74 xi.height = height;
75 xi.xoffset = 0;
76 xi.format = ZPixmap;
77 xi.byte_order = ImageByteOrder (dpy);
78 xi.bitmap_unit = 0; //XY only, unused
79 xi.bitmap_bit_order = 0; //XY only, unused
80 xi.bitmap_pad = BitmapPad (dpy);
81 xi.depth = depth;
82 xi.bytes_per_line = 0;
83 xi.bits_per_pixel = 32; //Z only
84 xi.red_mask = 0x00000000; //Z only, unused
85 xi.green_mask = 0x00000000; //Z only, unused
86 xi.blue_mask = 0x00000000; //Z only, unused
87 xi.obdata = 0; // probably unused
88
89 bool byte_order_mismatch = byte_order != xi.byte_order;
90
91 if (!XInitImage (&xi))
92 rxvt_fatal ("unable to initialise ximage, please report.\n");
93
94 if (height > INT_MAX / xi.bytes_per_line)
95 rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big for Xlib.\n");
96
97 xi.data = (char *)rxvt_malloc (height * xi.bytes_per_line);
98
99 int rowstride = gdk_pixbuf_get_rowstride (pb);
100
101 assert (3 + (depth == 32) == gdk_pixbuf_get_n_channels (pb));
102 unsigned char *row = gdk_pixbuf_get_pixels (pb);
103 char *line = xi.data;
104
105 for (int y = 0; y < height; y++)
106 {
107 unsigned char *src = row;
108 uint32_t *dst = (uint32_t *)line;
109
110 if (depth == 24)
111 for (int x = 0; x < width; x++)
112 {
113 uint8_t r = *src++;
114 uint8_t g = *src++;
115 uint8_t b = *src++;
116
117 uint32_t v = (r << 16) | (g << 8) | b;
118
119 if (ecb_big_endian () ? !byte_order_mismatch : byte_order_mismatch)
120 v = ecb_bswap32 (v);
121
122 *dst++ = v;
123 }
124 else
125 for (int x = 0; x < width; x++)
126 {
127 uint32_t v = *(uint32_t *)src; src += 4;
128
129 if (ecb_big_endian ())
130 v = ecb_bswap32 (v);
131
132 v = ecb_rotl32 (v, 8); // abgr to bgra
133
134 if (!byte_order_mismatch)
135 v = ecb_bswap32 (v);
136
137 *dst++ = v;
138 }
139
140 row += rowstride;
141 line += xi.bytes_per_line;
142 }
143
144 rxvt_img *img = new rxvt_img (s, XRenderFindStandardFormat (dpy, depth == 24 ? PictStandardRGB24 : PictStandardARGB32), 0, 0, width, height);
145 img->alloc ();
146
147 GC gc = XCreateGC (dpy, img->pm, 0, 0);
148 XPutImage (dpy, img->pm, gc, &xi, 0, 0, 0, 0, width, height);
149 XFreeGC (dpy, gc);
150
151 free (xi.data);
152
153 return img;
154}
155
156rxvt_img *
62rxvt_img::new_from_file (rxvt_screen *s, const char *filename) 157rxvt_img::new_from_file (rxvt_screen *s, const char *filename)
63{ 158{
64 GError *err = 0; 159 GError *err = 0;
65 GdkPixbuf *pb = gdk_pixbuf_new_from_file (filename, &err); 160 GdkPixbuf *pb = gdk_pixbuf_new_from_file (filename, &err);
66 161
67 if (!pb) 162 if (!pb)
68 rxvt_fatal ("rxvt_img::new_from_file: %s\n", err->message); 163 rxvt_fatal ("rxvt_img::new_from_file: %s\n", err->message);
69 164
70 rxvt_img *img = new rxvt_img ( 165 rxvt_img *img = new_from_pixbuf (s, pb);
71 s,
72 XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24),
73 0,
74 0,
75 gdk_pixbuf_get_width (pb),
76 gdk_pixbuf_get_height (pb)
77 );
78 img->alloc ();
79 img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0);
80 166
81 g_object_unref (pb); 167 g_object_unref (pb);
82 168
83 return img; 169 return img;
84} 170}
123rxvt_img::unshare () 209rxvt_img::unshare ()
124{ 210{
125 if (ref->cnt == 1 && ref->ours) 211 if (ref->cnt == 1 && ref->ours)
126 return; 212 return;
127 213
128 //TODO: maybe should reify instead
129 Pixmap pm2 = XCreatePixmap (s->display->dpy, s->display->root, ref->w, ref->h, format->depth); 214 Pixmap pm2 = XCreatePixmap (s->display->dpy, s->display->root, ref->w, ref->h, format->depth);
130 GC gc = XCreateGC (s->display->dpy, pm, 0, 0); 215 GC gc = XCreateGC (s->display->dpy, pm, 0, 0);
131 XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, ref->w, ref->h, 0, 0); 216 XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, ref->w, ref->h, 0, 0);
132 XFreeGC (s->display->dpy, gc); 217 XFreeGC (s->display->dpy, gc);
133 218
176 261
177 Display *dpy = s->display->dpy; 262 Display *dpy = s->display->dpy;
178 int size = max (rh, rv) * 2 + 1; 263 int size = max (rh, rv) * 2 + 1;
179 double *kernel = (double *)malloc (size * sizeof (double)); 264 double *kernel = (double *)malloc (size * sizeof (double));
180 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 265 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
181 rxvt_img *img = new rxvt_img (s, format, x, y, w, h); 266 rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat);
182 img->alloc (); 267 img->alloc ();
183
184 Picture src = src_picture ();
185 268
186 XRenderPictureAttributes pa; 269 XRenderPictureAttributes pa;
187 pa.repeat = RepeatPad; 270 pa.repeat = RepeatPad;
188 Picture dst = XRenderCreatePicture (dpy, img->pm, format, CPRepeat, &pa); 271 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa);
272 Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0);
189 273
190 Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth); 274 Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth);
191 Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa); 275 Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa);
192 XFreePixmap (dpy, tmp_pm); 276 XFreePixmap (dpy, tmp_pm);
193 277
209 293
210 size = rv * 2 + 1; 294 size = rv * 2 + 1;
211 get_gaussian_kernel (rv, size, kernel, params); 295 get_gaussian_kernel (rv, size, kernel, params);
212 ::swap (params[0], params[1]); 296 ::swap (params[0], params[1]);
213 297
214 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 298 XRenderSetPictureFilter (dpy, tmp, FilterConvolution, params, size+2);
215 XRenderComposite (dpy, 299 XRenderComposite (dpy,
216 PictOpSrc, 300 PictOpSrc,
217 tmp, 301 tmp,
218 None, 302 None,
219 dst, 303 dst,
245 XFreePixmap (dpy, pixmap); 329 XFreePixmap (dpy, pixmap);
246 330
247 return mask; 331 return mask;
248} 332}
249 333
334static void
335extract (int32_t cl0, int32_t cl1, int32_t &c, unsigned short &xc)
336{
337 int32_t x = clamp (c, cl0, cl1);
338 c -= x;
339 xc = x;
340}
341
342static bool
343extract (int32_t cl0, int32_t cl1, int32_t &r, int32_t &g, int32_t &b, int32_t &a, unsigned short &xr, unsigned short &xg, unsigned short &xb, unsigned short &xa)
344{
345 extract (cl0, cl1, r, xr);
346 extract (cl0, cl1, g, xg);
347 extract (cl0, cl1, b, xb);
348 extract (cl0, cl1, a, xa);
349
350 return xr | xg | xb | xa;
351}
352
250void 353void
251rxvt_img::brightness (unsigned short r, unsigned short g, unsigned short b, unsigned short a) 354rxvt_img::brightness (int32_t r, int32_t g, int32_t b, int32_t a)
252{ 355{
356 unshare ();
357
253 Display *dpy = s->display->dpy; 358 Display *dpy = s->display->dpy;
254 Picture src = create_xrender_mask (dpy, pm, True); 359 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0);
360
361 // loop should not be needed for brightness, as only -1..1 makes sense
362 //while (r | g | b | a)
363 {
364 unsigned short xr, xg, xb, xa;
365 XRenderColor mask_c;
366
367 if (extract (0, 65535, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha))
368 XRenderFillRectangle (dpy, PictOpAdd, dst, &mask_c, 0, 0, w, h);
369
370 if (extract (-65535, 0, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha))
371 {
372 XRenderColor mask_w = { 65535, 65535, 65535, 65535 };
373 XRenderFillRectangle (dpy, PictOpDifference, dst, &mask_w, 0, 0, w, h);
374 mask_c.red = -mask_c.red; //TODO: verify that doing clamp, assign, and negation does the right thing
375 mask_c.green = -mask_c.green;
376 mask_c.blue = -mask_c.blue;
377 mask_c.alpha = -mask_c.alpha;
378 XRenderFillRectangle (dpy, PictOpAdd, dst, &mask_c, 0, 0, w, h);
379 XRenderFillRectangle (dpy, PictOpDifference, dst, &mask_w, 0, 0, w, h);
380 }
381 }
382
383
384 XRenderFreePicture (dpy, dst);
385}
386
387void
388rxvt_img::contrast (int32_t r, int32_t g, int32_t b, int32_t a)
389{
390 if (!(s->display->flags & DISPLAY_HAS_RENDER_MUL))
391 {
392 rxvt_warn ("rxvt_img::contrast operation not supported on this display, RENDER extension too old.\n");
393 return;
394 }
395
396 unshare ();
397
398 Display *dpy = s->display->dpy;
255 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); 399 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0);
256 400
257 XRenderColor mask_c; 401 XRenderColor mask_c;
258 mask_c.red = r; 402 mask_c.red = r;
259 mask_c.green = g; 403 mask_c.green = g;
260 mask_c.blue = b; 404 mask_c.blue = b;
261 mask_c.alpha = a; 405 mask_c.alpha = a;
262 XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); 406 XRenderFillRectangle (dpy, PictOpMultiply, dst, &mask_c, 0, 0, w, h);
263 407
264 XRenderComposite (dpy, PictOpAdd, src, None, dst, 0, 0, 0, 0, 0, 0, w, h);
265
266 XRenderFreePicture (dpy, src);
267 XRenderFreePicture (dpy, dst); 408 XRenderFreePicture (dpy, dst);
268} 409}
269 410
270void
271rxvt_img::contrast (unsigned short r, unsigned short g, unsigned short b, unsigned short a)
272{
273 if (!(s->display->flags & DISPLAY_HAS_RENDER_MUL))
274 return;
275
276 Display *dpy = s->display->dpy;
277 Picture src = create_xrender_mask (dpy, pm, True);
278 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0);
279
280 XRenderColor mask_c;
281 mask_c.red = r;
282 mask_c.green = g;
283 mask_c.blue = b;
284 mask_c.alpha = a;
285 XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1);
286
287 XRenderComposite (dpy, PictOpMultiply, src, None, dst, 0, 0, 0, 0, 0, 0, w, h);
288
289 XRenderFreePicture (dpy, src);
290 XRenderFreePicture (dpy, dst);
291}
292
293bool
294rxvt_img::render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y)
295{
296 Display *dpy = s->display->dpy;
297
298 if (s->visual->c_class != TrueColor)
299 return false;
300
301 uint32_t red_mask, green_mask, blue_mask, alpha_mask;
302
303 red_mask = (uint32_t)format->direct.redMask << format->direct.red;
304 green_mask = (uint32_t)format->direct.greenMask << format->direct.green;
305 blue_mask = (uint32_t)format->direct.blueMask << format->direct.blue;
306 alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha;
307
308 int width_r = ecb_popcount32 (red_mask);
309 int width_g = ecb_popcount32 (green_mask);
310 int width_b = ecb_popcount32 (blue_mask);
311 int width_a = ecb_popcount32 (alpha_mask);
312
313 if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8)
314 return false;
315
316 int sh_r = ecb_ctz32 (red_mask);
317 int sh_g = ecb_ctz32 (green_mask);
318 int sh_b = ecb_ctz32 (blue_mask);
319 int sh_a = ecb_ctz32 (alpha_mask);
320
321 if (width > 32767 || height > 32767)
322 return false;
323
324 XImage *ximage = XCreateImage (dpy, s->visual, format->depth, ZPixmap, 0, 0,
325 width, height, 32, 0);
326 if (!ximage)
327 return false;
328
329 if (height > INT_MAX / ximage->bytes_per_line
330 || !(ximage->data = (char *)malloc (height * ximage->bytes_per_line)))
331 {
332 XDestroyImage (ximage);
333 return false;
334 }
335
336 GC gc = XCreateGC (dpy, pm, 0, 0);
337
338 ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
339
340 int rowstride = gdk_pixbuf_get_rowstride (pixbuf);
341 int channels = gdk_pixbuf_get_n_channels (pixbuf);
342 unsigned char *row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels;
343 char *line = ximage->data;
344
345 for (int y = 0; y < height; y++)
346 {
347 for (int x = 0; x < width; x++)
348 {
349 unsigned char *pixel = row + x * channels;
350 uint32_t value;
351 unsigned char r, g, b, a;
352
353 if (channels == 4)
354 {
355 a = pixel[3];
356 r = pixel[0] * a / 0xff;
357 g = pixel[1] * a / 0xff;
358 b = pixel[2] * a / 0xff;
359 }
360 else
361 {
362 a = 0xff;
363 r = pixel[0];
364 g = pixel[1];
365 b = pixel[2];
366 }
367
368 value = ((r >> (8 - width_r)) << sh_r)
369 | ((g >> (8 - width_g)) << sh_g)
370 | ((b >> (8 - width_b)) << sh_b)
371 | ((a >> (8 - width_a)) << sh_a);
372
373 if (ximage->bits_per_pixel == 32)
374 ((uint32_t *)line)[x] = value;
375 else
376 XPutPixel (ximage, x, y, value);
377 }
378
379 row += rowstride;
380 line += ximage->bytes_per_line;
381 }
382
383 XPutImage (dpy, pm, gc, ximage, 0, 0, dst_x, dst_y, width, height);
384 XDestroyImage (ximage);
385 XFreeGC (dpy, gc);
386
387 return true;
388}
389
390rxvt_img * 411rxvt_img *
391rxvt_img::clone () 412rxvt_img::clone ()
392{ 413{
393 return new rxvt_img (*this); 414 return new rxvt_img (*this);
415}
416
417static XRenderPictFormat *
418find_alpha_format_for (Display *dpy, XRenderPictFormat *format)
419{
420 if (format->direct.alphaMask)
421 return format; // already has alpha
422
423 // try to find a suitable alpha format, one bit alpha is enough for our purposes
424 if (format->type == PictTypeDirect)
425 for (int n = 0; XRenderPictFormat *f = XRenderFindFormat (dpy, 0, 0, n); ++n)
426 if (f->direct.alphaMask
427 && f->type == PictTypeDirect
428 && ecb_popcount32 (f->direct.redMask ) >= ecb_popcount32 (format->direct.redMask )
429 && ecb_popcount32 (f->direct.greenMask) >= ecb_popcount32 (format->direct.greenMask)
430 && ecb_popcount32 (f->direct.blueMask ) >= ecb_popcount32 (format->direct.blueMask ))
431 return f;
432
433 // should be a very good fallback
434 return XRenderFindStandardFormat (dpy, PictStandardARGB32);
394} 435}
395 436
396rxvt_img * 437rxvt_img *
397rxvt_img::reify () 438rxvt_img::reify ()
398{ 439{
399 if (x == 0 && y == 0 && w == ref->w && h == ref->h) 440 if (x == 0 && y == 0 && w == ref->w && h == ref->h)
400 return clone (); 441 return clone ();
401 442
402 rxvt_img *img = new rxvt_img (s, format, 0, 0, w, h); 443 Display *dpy = s->display->dpy;
444
445 // add an alpha channel if...
446 bool alpha = !format->direct.alphaMask // pixmap has none yet
447 && (x || y) // we need one because of non-zero offset
448 && repeat == RepeatNone; // and we have no good pixels to fill with
449
450 rxvt_img *img = new rxvt_img (s, alpha ? find_alpha_format_for (dpy, format) : format, 0, 0, w, h, repeat);
403 img->alloc (); 451 img->alloc ();
404
405 Display *dpy = s->display->dpy;
406 452
407 Picture src = src_picture (); 453 Picture src = src_picture ();
408 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 454 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
409 455
456 if (alpha)
457 {
458 XRenderColor rc = { 0, 0, 0, 0 };
459 XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);//TODO: split into four fillrectangles
460 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, -x, -y, ref->w, ref->h);
461 }
462 else
410 XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h); 463 XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h);
411 464
412 XRenderFreePicture (dpy, src); 465 XRenderFreePicture (dpy, src);
413 XRenderFreePicture (dpy, dst); 466 XRenderFreePicture (dpy, dst);
414 467
415 return img; 468 return img;
416} 469}
417 470
418rxvt_img * 471rxvt_img *
419rxvt_img::sub_rect (int x, int y, int width, int height) 472rxvt_img::sub_rect (int x, int y, int width, int height)
420{ 473{
421 bool need_reify = w < width || h < height;
422
423 rxvt_img *img = clone (); 474 rxvt_img *img = clone ();
424 475
425 img->x += x; 476 img->x += x;
426 img->y += y; 477 img->y += y;
478
479 if (w != width || h != height)
480 {
427 img->w = width; 481 img->w = width;
428 img->h = height; 482 img->h = height;
429 483
430 if (need_reify) 484 rxvt_img *img2 = img->reify ();
431 img->reify (); 485 delete img;
486 img = img2;
487 }
432 488
433 return img; 489 return img;
434} 490}
435 491
436rxvt_img * 492rxvt_img *
437rxvt_img::transform (int new_width, int new_height, double matrix[9]) 493rxvt_img::transform (int new_width, int new_height, double matrix[9])
438{ 494{
439 rxvt_img *img = new rxvt_img (s, format, 0, 0, new_width, new_height); 495 rxvt_img *img = new rxvt_img (s, format, 0, 0, new_width, new_height, repeat);
440 img->alloc (); 496 img->alloc ();
441 497
442 Display *dpy = s->display->dpy; 498 Display *dpy = s->display->dpy;
443 Picture src = src_picture (); 499 Picture src = src_picture ();
444 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 500 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
447 503
448 for (int i = 0; i < 3; ++i) 504 for (int i = 0; i < 3; ++i)
449 for (int j = 0; j < 3; ++j) 505 for (int j = 0; j < 3; ++j)
450 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); 506 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]);
451 507
452 xfrm.matrix [0][2] += XDoubleToFixed (x);//TODO 508 xfrm.matrix [0][2] -= XDoubleToFixed (x);//TODO
453 xfrm.matrix [0][3] += XDoubleToFixed (y); 509 xfrm.matrix [1][2] -= XDoubleToFixed (y);
454 510
455 XRenderSetPictureFilter (dpy, src, "good", 0, 0); 511 XRenderSetPictureFilter (dpy, src, "good", 0, 0);
456 XRenderSetPictureTransform (dpy, src, &xfrm); 512 XRenderSetPictureTransform (dpy, src, &xfrm);
457 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height); 513 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height);
458 514
463} 519}
464 520
465rxvt_img * 521rxvt_img *
466rxvt_img::scale (int new_width, int new_height) 522rxvt_img::scale (int new_width, int new_height)
467{ 523{
524 if (w == new_width && h == new_height)
525 return clone ();
526
468 double matrix[9] = { 527 double matrix[9] = {
469 w / (double)new_width, 0, 0, 528 w / (double)new_width, 0, 0,
470 0, h / (double)new_height, 0, 529 0, h / (double)new_height, 0,
471 0, 0, 1 530 0, 0, 1
472 }; 531 };
473 532
533 int old_repeat_mode = repeat;
534 repeat = RepeatPad; // not right, but xrender can't proeprly scale it seems
535
474 return transform (new_width, new_height, matrix); 536 rxvt_img *img = transform (new_width, new_height, matrix);
537
538 repeat = old_repeat_mode;
539 img->repeat = repeat;
540
541 return img;
475} 542}
476 543
477rxvt_img * 544rxvt_img *
478rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi) 545rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi)
479{ 546{
488 555
489 return transform (new_width, new_height, matrix); 556 return transform (new_width, new_height, matrix);
490} 557}
491 558
492rxvt_img * 559rxvt_img *
493rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) 560rxvt_img::convert_format (XRenderPictFormat *new_format, const rxvt_color &bg)
494{ 561{
495 if (new_format == format) 562 if (new_format == format)
496 return clone (); 563 return clone ();
497 564
498 rxvt_img *img = new rxvt_img (s, new_format, 0, 0, w, h); 565 rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h, repeat);
499 img->alloc (); 566 img->alloc ();
500 567
501 Display *dpy = s->display->dpy; 568 Display *dpy = s->display->dpy;
502 Picture src = src_picture (); 569 Picture src = src_picture ();
503 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); 570 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0);
526rxvt_img * 593rxvt_img *
527rxvt_img::blend (rxvt_img *img, double factor) 594rxvt_img::blend (rxvt_img *img, double factor)
528{ 595{
529 rxvt_img *img2 = clone (); 596 rxvt_img *img2 = clone ();
530 Display *dpy = s->display->dpy; 597 Display *dpy = s->display->dpy;
531 Picture src = src_picture (); 598 Picture src = img->src_picture ();
532 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); 599 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0);
533 Picture mask = create_xrender_mask (dpy, img->pm, False); 600 Picture mask = create_xrender_mask (dpy, img->pm, False);
534 601
535 XRenderColor mask_c; 602 XRenderColor mask_c;
536 603

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines