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.73 by sf-exg, Sat Jun 9 17:28:03 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,
230 XRenderFreePicture (dpy, tmp); 316 XRenderFreePicture (dpy, tmp);
231 317
232 return img; 318 return img;
233} 319}
234 320
235static Picture 321static void
236create_xrender_mask (Display *dpy, Drawable drawable, Bool argb) 322extract (int32_t cl0, int32_t cl1, int32_t &c, unsigned short &xc)
237{ 323{
238 Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8); 324 int32_t x = clamp (c, cl0, cl1);
325 c -= x;
326 xc = x;
327}
239 328
240 XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8); 329static bool
241 XRenderPictureAttributes pa; 330extract (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)
242 pa.repeat = True; 331{
243 Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); 332 extract (cl0, cl1, r, xr);
333 extract (cl0, cl1, g, xg);
334 extract (cl0, cl1, b, xb);
335 extract (cl0, cl1, a, xa);
244 336
245 XFreePixmap (dpy, pixmap); 337 return xr | xg | xb | xa;
246
247 return mask;
248} 338}
249 339
250void 340void
251rxvt_img::brightness (unsigned short r, unsigned short g, unsigned short b, unsigned short a) 341rxvt_img::brightness (int32_t r, int32_t g, int32_t b, int32_t a)
252{ 342{
343 unshare ();
344
253 Display *dpy = s->display->dpy; 345 Display *dpy = s->display->dpy;
254 Picture src = create_xrender_mask (dpy, pm, True); 346 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0);
347
348 // loop should not be needed for brightness, as only -1..1 makes sense
349 //while (r | g | b | a)
350 {
351 unsigned short xr, xg, xb, xa;
352 XRenderColor mask_c;
353
354 if (extract (0, 65535, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha))
355 XRenderFillRectangle (dpy, PictOpAdd, dst, &mask_c, 0, 0, w, h);
356
357 if (extract (-65535, 0, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha))
358 {
359 XRenderColor mask_w = { 65535, 65535, 65535, 65535 };
360 XRenderFillRectangle (dpy, PictOpDifference, dst, &mask_w, 0, 0, w, h);
361 mask_c.red = -mask_c.red; //TODO: verify that doing clamp, assign, and negation does the right thing
362 mask_c.green = -mask_c.green;
363 mask_c.blue = -mask_c.blue;
364 mask_c.alpha = -mask_c.alpha;
365 XRenderFillRectangle (dpy, PictOpAdd, dst, &mask_c, 0, 0, w, h);
366 XRenderFillRectangle (dpy, PictOpDifference, dst, &mask_w, 0, 0, w, h);
367 }
368 }
369
370
371 XRenderFreePicture (dpy, dst);
372}
373
374void
375rxvt_img::contrast (int32_t r, int32_t g, int32_t b, int32_t a)
376{
377 if (!(s->display->flags & DISPLAY_HAS_RENDER_MUL))
378 {
379 rxvt_warn ("rxvt_img::contrast operation not supported on this display, RENDER extension too old.\n");
380 return;
381 }
382
383 unshare ();
384
385 Display *dpy = s->display->dpy;
255 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); 386 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0);
256 387
257 XRenderColor mask_c; 388 XRenderColor mask_c;
258 mask_c.red = r; 389 mask_c.red = r;
259 mask_c.green = g; 390 mask_c.green = g;
260 mask_c.blue = b; 391 mask_c.blue = b;
261 mask_c.alpha = a; 392 mask_c.alpha = a;
262 XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); 393 XRenderFillRectangle (dpy, PictOpMultiply, dst, &mask_c, 0, 0, w, h);
263 394
264 XRenderComposite (dpy, PictOpAdd, src, None, dst, 0, 0, 0, 0, 0, 0, w, h);
265
266 XRenderFreePicture (dpy, src);
267 XRenderFreePicture (dpy, dst); 395 XRenderFreePicture (dpy, dst);
268} 396}
269 397
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 * 398rxvt_img *
391rxvt_img::clone () 399rxvt_img::clone ()
392{ 400{
393 return new rxvt_img (*this); 401 return new rxvt_img (*this);
402}
403
404static XRenderPictFormat *
405find_alpha_format_for (Display *dpy, XRenderPictFormat *format)
406{
407 if (format->direct.alphaMask)
408 return format; // already has alpha
409
410 // try to find a suitable alpha format, one bit alpha is enough for our purposes
411 if (format->type == PictTypeDirect)
412 for (int n = 0; XRenderPictFormat *f = XRenderFindFormat (dpy, 0, 0, n); ++n)
413 if (f->direct.alphaMask
414 && f->type == PictTypeDirect
415 && ecb_popcount32 (f->direct.redMask ) >= ecb_popcount32 (format->direct.redMask )
416 && ecb_popcount32 (f->direct.greenMask) >= ecb_popcount32 (format->direct.greenMask)
417 && ecb_popcount32 (f->direct.blueMask ) >= ecb_popcount32 (format->direct.blueMask ))
418 return f;
419
420 // should be a very good fallback
421 return XRenderFindStandardFormat (dpy, PictStandardARGB32);
394} 422}
395 423
396rxvt_img * 424rxvt_img *
397rxvt_img::reify () 425rxvt_img::reify ()
398{ 426{
399 if (x == 0 && y == 0 && w == ref->w && h == ref->h) 427 if (x == 0 && y == 0 && w == ref->w && h == ref->h)
400 return clone (); 428 return clone ();
401 429
402 Display *dpy = s->display->dpy; 430 Display *dpy = s->display->dpy;
403 431
432 // add an alpha channel if...
404 bool alpha = !format->direct.alphaMask 433 bool alpha = !format->direct.alphaMask // pixmap has none yet
405 && (x || y) 434 && (x || y) // we need one because of non-zero offset
406 && repeat == RepeatNone; 435 && repeat == RepeatNone; // and we have no good pixels to fill with
407 436
408 rxvt_img *img = new rxvt_img (s, alpha ? XRenderFindStandardFormat (dpy, PictStandardARGB32) : format, 0, 0, w, h, repeat); 437 rxvt_img *img = new rxvt_img (s, alpha ? find_alpha_format_for (dpy, format) : format, 0, 0, w, h, repeat);
409 img->alloc (); 438 img->alloc ();
410 439
411 Picture src = src_picture (); 440 Picture src = src_picture ();
412 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 441 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
413 442
414 if (alpha) 443 if (alpha)
415 { 444 {
416 XRenderColor rc = { 0, 0, 0, 0 }; 445 XRenderColor rc = { 0, 0, 0, 0 };
417 XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h); 446 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); 447 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, -x, -y, ref->w, ref->h);
419 } 448 }
420 else 449 else
421 XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h); 450 XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h);
422 451
461 490
462 for (int i = 0; i < 3; ++i) 491 for (int i = 0; i < 3; ++i)
463 for (int j = 0; j < 3; ++j) 492 for (int j = 0; j < 3; ++j)
464 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); 493 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]);
465 494
466 xfrm.matrix [0][2] += XDoubleToFixed (x);//TODO 495 xfrm.matrix [0][2] -= XDoubleToFixed (x);//TODO
467 xfrm.matrix [0][3] += XDoubleToFixed (y); 496 xfrm.matrix [1][2] -= XDoubleToFixed (y);
468 497
469 XRenderSetPictureFilter (dpy, src, "good", 0, 0); 498 XRenderSetPictureFilter (dpy, src, "good", 0, 0);
470 XRenderSetPictureTransform (dpy, src, &xfrm); 499 XRenderSetPictureTransform (dpy, src, &xfrm);
471 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height); 500 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height);
472 501
477} 506}
478 507
479rxvt_img * 508rxvt_img *
480rxvt_img::scale (int new_width, int new_height) 509rxvt_img::scale (int new_width, int new_height)
481{ 510{
511 if (w == new_width && h == new_height)
512 return clone ();
513
482 double matrix[9] = { 514 double matrix[9] = {
483 w / (double)new_width, 0, 0, 515 w / (double)new_width, 0, 0,
484 0, h / (double)new_height, 0, 516 0, h / (double)new_height, 0,
485 0, 0, 1 517 0, 0, 1
486 }; 518 };
510 542
511 return transform (new_width, new_height, matrix); 543 return transform (new_width, new_height, matrix);
512} 544}
513 545
514rxvt_img * 546rxvt_img *
515rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) 547rxvt_img::convert_format (XRenderPictFormat *new_format, const rxvt_color &bg)
516{ 548{
517 if (new_format == format) 549 if (new_format == format)
518 return clone (); 550 return clone ();
519 551
520 rxvt_img *img = new rxvt_img (s, new_format, 0, 0, w, h, repeat); 552 rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h, repeat);
521 img->alloc (); 553 img->alloc ();
522
523 printf ("convert %d to %d\n", format->direct.alphaMask, new_format->direct.alphaMask);//D
524 554
525 Display *dpy = s->display->dpy; 555 Display *dpy = s->display->dpy;
526 Picture src = src_picture (); 556 Picture src = src_picture ();
527 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); 557 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0);
528 int op = PictOpSrc; 558 int op = PictOpSrc;
552{ 582{
553 rxvt_img *img2 = clone (); 583 rxvt_img *img2 = clone ();
554 Display *dpy = s->display->dpy; 584 Display *dpy = s->display->dpy;
555 Picture src = img->src_picture (); 585 Picture src = img->src_picture ();
556 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); 586 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0);
557 Picture mask = create_xrender_mask (dpy, img->pm, False); 587
588 Pixmap pixmap = XCreatePixmap (dpy, img->pm, 1, 1, 8);
589 XRenderPictFormat *format = XRenderFindStandardFormat (dpy, PictStandardA8);
590 XRenderPictureAttributes pa;
591 pa.repeat = True;
592 Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa);
593 XFreePixmap (dpy, pixmap);
558 594
559 XRenderColor mask_c; 595 XRenderColor mask_c;
560 596
561 mask_c.alpha = float_to_component (factor); 597 mask_c.alpha = float_to_component (factor);
562 mask_c.red = 598 mask_c.red =

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines