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.42 by root, Thu Jun 7 11:52:26 2012 UTC vs.
Revision 1.75 by sf-exg, Sun Jun 10 07:51:45 2012 UTC

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;
56 img->ref->ours = false; 49 img->ref->ours = false;
57 50
58 return img; 51 return img;
59} 52}
60 53
54# if HAVE_PIXBUF
55rxvt_img *
56rxvt_img::new_from_pixbuf (rxvt_screen *s, GdkPixbuf *pb)
57{
58 Display *dpy = s->display->dpy;
59
60 int width = gdk_pixbuf_get_width (pb);
61 int height = gdk_pixbuf_get_height (pb);
62
63 if (width > 32767 || height > 32767) // well, we *could* upload in chunks
64 rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big (maximum size 32768x32768).\n");
65
66 // since we require rgb24/argb32 formats from xrender we assume
67 // that both 24 and 32 bpp MUST be supported by any screen that supports xrender
68 int depth = gdk_pixbuf_get_has_alpha (pb) ? 32 : 24;
69
70 int byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
71
72 XImage xi;
73
74 xi.width = width;
75 xi.height = height;
76 xi.xoffset = 0;
77 xi.format = ZPixmap;
78 xi.byte_order = ImageByteOrder (dpy);
79 xi.bitmap_unit = 0; //XY only, unused
80 xi.bitmap_bit_order = 0; //XY only, unused
81 xi.bitmap_pad = BitmapPad (dpy);
82 xi.depth = depth;
83 xi.bytes_per_line = 0;
84 xi.bits_per_pixel = 32; //Z only
85 xi.red_mask = 0x00000000; //Z only, unused
86 xi.green_mask = 0x00000000; //Z only, unused
87 xi.blue_mask = 0x00000000; //Z only, unused
88 xi.obdata = 0; // probably unused
89
90 bool byte_order_mismatch = byte_order != xi.byte_order;
91
92 if (!XInitImage (&xi))
93 rxvt_fatal ("unable to initialise ximage, please report.\n");
94
95 if (height > INT_MAX / xi.bytes_per_line)
96 rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big for Xlib.\n");
97
98 xi.data = (char *)rxvt_malloc (height * xi.bytes_per_line);
99
100 int rowstride = gdk_pixbuf_get_rowstride (pb);
101
102 assert (3 + (depth == 32) == gdk_pixbuf_get_n_channels (pb));
103 unsigned char *row = gdk_pixbuf_get_pixels (pb);
104 char *line = xi.data;
105
106 for (int y = 0; y < height; y++)
107 {
108 unsigned char *src = row;
109 uint32_t *dst = (uint32_t *)line;
110
111 if (depth == 24)
112 for (int x = 0; x < width; x++)
113 {
114 uint8_t r = *src++;
115 uint8_t g = *src++;
116 uint8_t b = *src++;
117
118 uint32_t v = (r << 16) | (g << 8) | b;
119
120 if (ecb_big_endian () ? !byte_order_mismatch : byte_order_mismatch)
121 v = ecb_bswap32 (v);
122
123 *dst++ = v;
124 }
125 else
126 for (int x = 0; x < width; x++)
127 {
128 uint32_t v = *(uint32_t *)src; src += 4;
129
130 if (ecb_big_endian ())
131 v = ecb_bswap32 (v);
132
133 v = ecb_rotl32 (v, 8); // abgr to bgra
134
135 if (!byte_order_mismatch)
136 v = ecb_bswap32 (v);
137
138 *dst++ = v;
139 }
140
141 row += rowstride;
142 line += xi.bytes_per_line;
143 }
144
145 rxvt_img *img = new rxvt_img (s, XRenderFindStandardFormat (dpy, depth == 24 ? PictStandardRGB24 : PictStandardARGB32), 0, 0, width, height);
146 img->alloc ();
147
148 GC gc = XCreateGC (dpy, img->pm, 0, 0);
149 XPutImage (dpy, img->pm, gc, &xi, 0, 0, 0, 0, width, height);
150 XFreeGC (dpy, gc);
151
152 free (xi.data);
153
154 return img;
155}
156
61rxvt_img * 157rxvt_img *
62rxvt_img::new_from_file (rxvt_screen *s, const char *filename) 158rxvt_img::new_from_file (rxvt_screen *s, const char *filename)
63{ 159{
64 GError *err = 0; 160 GError *err = 0;
65 GdkPixbuf *pb = gdk_pixbuf_new_from_file (filename, &err); 161 GdkPixbuf *pb = gdk_pixbuf_new_from_file (filename, &err);
66 162
67 if (!pb) 163 if (!pb)
68 rxvt_fatal ("rxvt_img::new_from_file: %s\n", err->message); 164 rxvt_fatal ("rxvt_img::new_from_file: %s\n", err->message);
69 165
70 rxvt_img *img = new rxvt_img ( 166 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 167
81 g_object_unref (pb); 168 g_object_unref (pb);
82 169
83 return img; 170 return img;
84} 171}
172# endif
85 173
86void 174void
87rxvt_img::destroy () 175rxvt_img::destroy ()
88{ 176{
89 if (--ref->cnt) 177 if (--ref->cnt)
123rxvt_img::unshare () 211rxvt_img::unshare ()
124{ 212{
125 if (ref->cnt == 1 && ref->ours) 213 if (ref->cnt == 1 && ref->ours)
126 return; 214 return;
127 215
128 //TODO: maybe should reify instead
129 Pixmap pm2 = XCreatePixmap (s->display->dpy, s->display->root, ref->w, ref->h, format->depth); 216 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); 217 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); 218 XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, ref->w, ref->h, 0, 0);
132 XFreeGC (s->display->dpy, gc); 219 XFreeGC (s->display->dpy, gc);
133 220
179 double *kernel = (double *)malloc (size * sizeof (double)); 266 double *kernel = (double *)malloc (size * sizeof (double));
180 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 267 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
181 rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); 268 rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat);
182 img->alloc (); 269 img->alloc ();
183 270
184 Picture src = src_picture ();
185
186 XRenderPictureAttributes pa; 271 XRenderPictureAttributes pa;
187 pa.repeat = RepeatPad; 272 pa.repeat = RepeatPad;
188 Picture dst = XRenderCreatePicture (dpy, img->pm, format, CPRepeat, &pa); 273 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa);
274 Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0);
189 275
190 Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth); 276 Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth);
191 Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa); 277 Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa);
192 XFreePixmap (dpy, tmp_pm); 278 XFreePixmap (dpy, tmp_pm);
193 279
209 295
210 size = rv * 2 + 1; 296 size = rv * 2 + 1;
211 get_gaussian_kernel (rv, size, kernel, params); 297 get_gaussian_kernel (rv, size, kernel, params);
212 ::swap (params[0], params[1]); 298 ::swap (params[0], params[1]);
213 299
214 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 300 XRenderSetPictureFilter (dpy, tmp, FilterConvolution, params, size+2);
215 XRenderComposite (dpy, 301 XRenderComposite (dpy,
216 PictOpSrc, 302 PictOpSrc,
217 tmp, 303 tmp,
218 None, 304 None,
219 dst, 305 dst,
231 317
232 return img; 318 return img;
233} 319}
234 320
235static Picture 321static Picture
236create_xrender_mask (Display *dpy, Drawable drawable, Bool argb) 322create_xrender_mask (Display *dpy, Drawable drawable, Bool argb, Bool component_alpha)
237{ 323{
238 Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8); 324 Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8);
239 325
240 XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8); 326 XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8);
241 XRenderPictureAttributes pa; 327 XRenderPictureAttributes pa;
242 pa.repeat = True; 328 pa.repeat = RepeatNormal;
329 pa.component_alpha = component_alpha;
243 Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); 330 Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat | CPComponentAlpha, &pa);
244 331
245 XFreePixmap (dpy, pixmap); 332 XFreePixmap (dpy, pixmap);
246 333
247 return mask; 334 return mask;
248} 335}
249 336
337static void
338extract (int32_t cl0, int32_t cl1, int32_t &c, unsigned short &xc)
339{
340 int32_t x = clamp (c, cl0, cl1);
341 c -= x;
342 xc = x;
343}
344
345static bool
346extract (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)
347{
348 extract (cl0, cl1, r, xr);
349 extract (cl0, cl1, g, xg);
350 extract (cl0, cl1, b, xb);
351 extract (cl0, cl1, a, xa);
352
353 return xr | xg | xb | xa;
354}
355
250void 356void
251rxvt_img::brightness (unsigned short r, unsigned short g, unsigned short b, unsigned short a) 357rxvt_img::brightness (int32_t r, int32_t g, int32_t b, int32_t a)
252{ 358{
359 unshare ();
360
253 Display *dpy = s->display->dpy; 361 Display *dpy = s->display->dpy;
254 Picture src = create_xrender_mask (dpy, pm, True);
255 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); 362 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0);
256 363
364 // loop should not be needed for brightness, as only -1..1 makes sense
365 //while (r | g | b | a)
366 {
367 unsigned short xr, xg, xb, xa;
257 XRenderColor mask_c; 368 XRenderColor mask_c;
258 mask_c.red = r; 369
259 mask_c.green = g; 370 if (extract (0, 65535, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha))
260 mask_c.blue = b; 371 XRenderFillRectangle (dpy, PictOpAdd, dst, &mask_c, 0, 0, w, h);
261 mask_c.alpha = a; 372
373 if (extract (-65535, 0, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha))
374 {
375 XRenderColor mask_w = { 65535, 65535, 65535, 65535 };
376 XRenderFillRectangle (dpy, PictOpDifference, dst, &mask_w, 0, 0, w, h);
377 mask_c.red = -mask_c.red; //TODO: verify that doing clamp, assign, and negation does the right thing
378 mask_c.green = -mask_c.green;
379 mask_c.blue = -mask_c.blue;
380 mask_c.alpha = -mask_c.alpha;
381 XRenderFillRectangle (dpy, PictOpAdd, dst, &mask_c, 0, 0, w, h);
382 XRenderFillRectangle (dpy, PictOpDifference, dst, &mask_w, 0, 0, w, h);
383 }
384 }
385
386 XRenderFreePicture (dpy, dst);
387}
388
389void
390rxvt_img::contrast (int32_t r, int32_t g, int32_t b, int32_t a)
391{
392 if (r < 0 || g < 0 || b < 0 || a < 0)
393 rxvt_fatal ("rxvt_img::contrast does not support negative values.\n");
394
395 rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat);
396 img->alloc ();
397
398 {
399 rxvt_color empty;
400 empty.set (s, rgba (0, 0, 0, 0));
401 img->fill (empty);
402 }
403
404 // premultiply (yeah, these are not exact, sue me or fix it)
405 r = (r * (a >> 8)) >> 8;
406 g = (g * (a >> 8)) >> 8;
407 b = (b * (a >> 8)) >> 8;
408
409 Display *dpy = s->display->dpy;
410
411 Picture src = src_picture ();
412 Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0);
413 Picture mul = create_xrender_mask (dpy, pm, True, True);
414
415 //TODO: this operator does not yet implement some useful contrast
416 while (r | g | b | a)
417 {
418 unsigned short xr, xg, xb, xa;
419 XRenderColor mask_c;
420
421 if (extract (0, 65535, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha))
422 {
262 XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); 423 XRenderFillRectangle (dpy, PictOpSrc, mul, &mask_c, 0, 0, 1, 1);
263
264 XRenderComposite (dpy, PictOpAdd, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); 424 XRenderComposite (dpy, PictOpAdd, src, mul, dst, 0, 0, 0, 0, 0, 0, w, h);
425 }
426 }
265 427
428 XRenderFreePicture (dpy, mul);
429 XRenderFreePicture (dpy, dst);
266 XRenderFreePicture (dpy, src); 430 XRenderFreePicture (dpy, src);
267 XRenderFreePicture (dpy, dst);
268}
269 431
270void 432 ::swap (img->ref, ref);
271rxvt_img::contrast (unsigned short r, unsigned short g, unsigned short b, unsigned short a) 433 ::swap (img->pm , pm );
272{
273 if (!(s->display->flags & DISPLAY_HAS_RENDER_MUL))
274 return;
275 434
276 Display *dpy = s->display->dpy; 435 delete img;
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} 436}
389 437
390rxvt_img * 438rxvt_img *
391rxvt_img::clone () 439rxvt_img::clone ()
392{ 440{
393 return new rxvt_img (*this); 441 return new rxvt_img (*this);
442}
443
444static XRenderPictFormat *
445find_alpha_format_for (Display *dpy, XRenderPictFormat *format)
446{
447 if (format->direct.alphaMask)
448 return format; // already has alpha
449
450 // try to find a suitable alpha format, one bit alpha is enough for our purposes
451 if (format->type == PictTypeDirect)
452 for (int n = 0; XRenderPictFormat *f = XRenderFindFormat (dpy, 0, 0, n); ++n)
453 if (f->direct.alphaMask
454 && f->type == PictTypeDirect
455 && ecb_popcount32 (f->direct.redMask ) >= ecb_popcount32 (format->direct.redMask )
456 && ecb_popcount32 (f->direct.greenMask) >= ecb_popcount32 (format->direct.greenMask)
457 && ecb_popcount32 (f->direct.blueMask ) >= ecb_popcount32 (format->direct.blueMask ))
458 return f;
459
460 // should be a very good fallback
461 return XRenderFindStandardFormat (dpy, PictStandardARGB32);
394} 462}
395 463
396rxvt_img * 464rxvt_img *
397rxvt_img::reify () 465rxvt_img::reify ()
398{ 466{
399 if (x == 0 && y == 0 && w == ref->w && h == ref->h) 467 if (x == 0 && y == 0 && w == ref->w && h == ref->h)
400 return clone (); 468 return clone ();
401 469
402 Display *dpy = s->display->dpy; 470 Display *dpy = s->display->dpy;
403 471
472 // add an alpha channel if...
404 bool alpha = !format->direct.alphaMask 473 bool alpha = !format->direct.alphaMask // pixmap has none yet
405 && (x || y) 474 && (x || y) // we need one because of non-zero offset
406 && repeat == RepeatNone; 475 && repeat == RepeatNone; // and we have no good pixels to fill with
407 476
408 rxvt_img *img = new rxvt_img (s, alpha ? XRenderFindStandardFormat (dpy, PictStandardARGB32) : format, 0, 0, w, h, repeat); 477 rxvt_img *img = new rxvt_img (s, alpha ? find_alpha_format_for (dpy, format) : format, 0, 0, w, h, repeat);
409 img->alloc (); 478 img->alloc ();
410 479
411 Picture src = src_picture (); 480 Picture src = src_picture ();
412 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 481 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
413 482
414 if (alpha) 483 if (alpha)
415 { 484 {
416 XRenderColor rc = { 0, 0, 0, 0 }; 485 XRenderColor rc = { 0, 0, 0, 0 };
417 XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h); 486 XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);//TODO: split into four fillrectangles
418 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, -x, -y, ref->w, ref->h); 487 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, -x, -y, ref->w, ref->h);
419 } 488 }
420 else 489 else
421 XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h); 490 XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h);
422 491
461 530
462 for (int i = 0; i < 3; ++i) 531 for (int i = 0; i < 3; ++i)
463 for (int j = 0; j < 3; ++j) 532 for (int j = 0; j < 3; ++j)
464 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); 533 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]);
465 534
466 xfrm.matrix [0][2] += XDoubleToFixed (x);//TODO 535 xfrm.matrix [0][2] -= XDoubleToFixed (x);//TODO
467 xfrm.matrix [0][3] += XDoubleToFixed (y); 536 xfrm.matrix [1][2] -= XDoubleToFixed (y);
468 537
469 XRenderSetPictureFilter (dpy, src, "good", 0, 0); 538 XRenderSetPictureFilter (dpy, src, "good", 0, 0);
470 XRenderSetPictureTransform (dpy, src, &xfrm); 539 XRenderSetPictureTransform (dpy, src, &xfrm);
471 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height); 540 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height);
472 541
477} 546}
478 547
479rxvt_img * 548rxvt_img *
480rxvt_img::scale (int new_width, int new_height) 549rxvt_img::scale (int new_width, int new_height)
481{ 550{
551 if (w == new_width && h == new_height)
552 return clone ();
553
482 double matrix[9] = { 554 double matrix[9] = {
483 w / (double)new_width, 0, 0, 555 w / (double)new_width, 0, 0,
484 0, h / (double)new_height, 0, 556 0, h / (double)new_height, 0,
485 0, 0, 1 557 0, 0, 1
486 }; 558 };
510 582
511 return transform (new_width, new_height, matrix); 583 return transform (new_width, new_height, matrix);
512} 584}
513 585
514rxvt_img * 586rxvt_img *
515rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) 587rxvt_img::convert_format (XRenderPictFormat *new_format, const rxvt_color &bg)
516{ 588{
517 if (new_format == format) 589 if (new_format == format)
518 return clone (); 590 return clone ();
519 591
520 rxvt_img *img = new rxvt_img (s, new_format, 0, 0, w, h, repeat); 592 rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h, repeat);
521 img->alloc (); 593 img->alloc ();
522
523 printf ("convert %d to %d\n", format->direct.alphaMask, new_format->direct.alphaMask);//D
524 594
525 Display *dpy = s->display->dpy; 595 Display *dpy = s->display->dpy;
526 Picture src = src_picture (); 596 Picture src = src_picture ();
527 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); 597 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0);
528 int op = PictOpSrc; 598 int op = PictOpSrc;
552{ 622{
553 rxvt_img *img2 = clone (); 623 rxvt_img *img2 = clone ();
554 Display *dpy = s->display->dpy; 624 Display *dpy = s->display->dpy;
555 Picture src = img->src_picture (); 625 Picture src = img->src_picture ();
556 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); 626 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0);
557 Picture mask = create_xrender_mask (dpy, img->pm, False); 627 Picture mask = create_xrender_mask (dpy, img->pm, False, False);
558 628
559 XRenderColor mask_c; 629 XRenderColor mask_c;
560 630
561 mask_c.alpha = float_to_component (factor); 631 mask_c.alpha = float_to_component (factor);
562 mask_c.red = 632 mask_c.red =

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines