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.23 by sf-exg, Tue Jun 5 18:48:21 2012 UTC vs.
Revision 1.30 by root, Wed Jun 6 22:01:44 2012 UTC

5#if HAVE_IMG 5#if HAVE_IMG
6 6
7#define float_to_component(d) ((d) * 65535.99) 7#define float_to_component(d) ((d) * 65535.99)
8 8
9rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height) 9rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height)
10: s(screen), w(width), h(height), format(format), shared(false) 10: s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false)
11{ 11{
12 pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); 12 pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth);
13} 13}
14 14
15rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) 15rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap)
16: s(screen), pm(pixmap), w(width), h(height), format(format), shared(false) 16: s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false), pm(pixmap)
17{ 17{
18} 18}
19 19
20rxvt_img * 20rxvt_img *
21rxvt_img::new_from_root (rxvt_screen *s) 21rxvt_img::new_from_root (rxvt_screen *s)
65 gdk_pixbuf_get_height (pb) 65 gdk_pixbuf_get_height (pb)
66 ); 66 );
67 67
68 img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0); 68 img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0);
69 69
70 g_object_unref (pb);
71
70 return img; 72 return img;
71} 73}
72 74
73rxvt_img::~rxvt_img () 75rxvt_img::~rxvt_img ()
74{ 76{
291 293
292 int rowstride = gdk_pixbuf_get_rowstride (pixbuf); 294 int rowstride = gdk_pixbuf_get_rowstride (pixbuf);
293 int channels = gdk_pixbuf_get_n_channels (pixbuf); 295 int channels = gdk_pixbuf_get_n_channels (pixbuf);
294 unsigned char *row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; 296 unsigned char *row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels;
295 char *line = ximage->data; 297 char *line = ximage->data;
296
297 rgba c (0, 0, 0);
298
299 if (channels == 4 && alpha_mask == 0)
300 {
301 //pix_colors[Color_bg].get (c);
302 //TODO
303 c.r = 0xffff; c.g = 0xc0c0; c.b = 0xcbcb;//D
304 c.r >>= 8;
305 c.g >>= 8;
306 c.b >>= 8;
307 }
308 298
309 for (int y = 0; y < height; y++) 299 for (int y = 0; y < height; y++)
310 { 300 {
311 for (int x = 0; x < width; x++) 301 for (int x = 0; x < width; x++)
312 { 302 {
315 unsigned char r, g, b, a; 305 unsigned char r, g, b, a;
316 306
317 if (channels == 4) 307 if (channels == 4)
318 { 308 {
319 a = pixel[3]; 309 a = pixel[3];
320 r = (pixel[0] * a + c.r * (0xff - a)) / 0xff; 310 r = pixel[0] * a / 0xff;
321 g = (pixel[1] * a + c.g * (0xff - a)) / 0xff; 311 g = pixel[1] * a / 0xff;
322 b = (pixel[2] * a + c.b * (0xff - a)) / 0xff; 312 b = pixel[2] * a / 0xff;
323 } 313 }
324 else 314 else
325 { 315 {
326 a = 0xff; 316 a = 0xff;
327 r = pixel[0]; 317 r = pixel[0];
362 352
363 return img; 353 return img;
364} 354}
365 355
366rxvt_img * 356rxvt_img *
367rxvt_img::sub_rect (int x, int y, int width, int height, int repeat) 357rxvt_img::sub_rect (int x, int y, int width, int height)
368{ 358{
369 rxvt_img *img = new rxvt_img (s, format, width, height); 359 rxvt_img *img = new rxvt_img (s, format, width, height);
370 360
371 Display *dpy = s->display->dpy; 361 Display *dpy = s->display->dpy;
372 XRenderPictureAttributes pa; 362 XRenderPictureAttributes pa;
381 371
382 return img; 372 return img;
383} 373}
384 374
385rxvt_img * 375rxvt_img *
386rxvt_img::transform (int new_width, int new_height, double matrix[9], int repeat) 376rxvt_img::transform (int new_width, int new_height, double matrix[9])
387{ 377{
388 rxvt_img *img = new rxvt_img (s, format, new_width, new_height); 378 rxvt_img *img = new rxvt_img (s, format, new_width, new_height);
389 379
390 Display *dpy = s->display->dpy; 380 Display *dpy = s->display->dpy;
391 XRenderPictureAttributes pa; 381 XRenderPictureAttributes pa;
420 410
421 return transform (new_width, new_height, matrix); 411 return transform (new_width, new_height, matrix);
422} 412}
423 413
424rxvt_img * 414rxvt_img *
425rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi, int repeat) 415rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi)
426{ 416{
427 double s = sin (phi); 417 double s = sin (phi);
428 double c = cos (phi); 418 double c = cos (phi);
429 419
430 double matrix[9] = { 420 double matrix[9] = {
431 c, -s, -c * x + s * y + x, 421 c, -s, -c * x + s * y + x,
432 s, c, -s * x - c * y + y, 422 s, c, -s * x - c * y + y,
433 0, 0, 1 423 0, 0, 1
434 }; 424 };
435 425
436 return transform (new_width, new_height, matrix, repeat); 426 return transform (new_width, new_height, matrix);
437} 427}
438 428
439rxvt_img * 429rxvt_img *
440rxvt_img::convert_to (XRenderPictFormat *new_format) 430rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg)
441{ 431{
442 rxvt_img *img = new rxvt_img (s, new_format, w, h); 432 rxvt_img *img = new rxvt_img (s, new_format, w, h);
443 433
444 Display *dpy = s->display->dpy; 434 Display *dpy = s->display->dpy;
445 Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0); 435 Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0);
446 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); 436 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0);
437 int op = PictOpSrc;
447 438
439 if (format->direct.alphaMask && !new_format->direct.alphaMask)
440 {
441 // does it have to be that complicated
442 rgba c;
443 bg.get (c);
444
445 XRenderColor rc = { c.r, c.g, c.b, 0xffff };
446 XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);
447
448 op = PictOpOver;
449 }
450
448 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); 451 XRenderComposite (dpy, op, src, None, dst, 0, 0, 0, 0, 0, 0, w, h);
449 452
450 XRenderFreePicture (dpy, src);
451 XRenderFreePicture (dpy, dst); 453 XRenderFreePicture (dpy, src);
454 XRenderFreePicture (dpy, dst);
452 455
456 return img;
457}
458
459rxvt_img *
460rxvt_img::blend (rxvt_img *img, double factor)
461{
462 rxvt_img *img2 = clone ();
463 Display *dpy = s->display->dpy;
464 Picture src = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
465 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0);
466 Picture mask = create_xrender_mask (dpy, img->pm, False);
467
468 XRenderColor mask_c;
469
470 mask_c.alpha = float_to_component (factor);
471 mask_c.red =
472 mask_c.green =
473 mask_c.blue = 0;
474 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
475
476 XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, w, h);
477
478 XRenderFreePicture (dpy, src);
479 XRenderFreePicture (dpy, dst);
480 XRenderFreePicture (dpy, mask);
481
453 return img; 482 return img2;
454} 483}
455 484
456#endif 485#endif
457 486

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines