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.22 by sf-exg, Tue Jun 5 15:18:23 2012 UTC vs.
Revision 1.31 by sf-exg, Thu Jun 7 06:08:09 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
7#define float_to_component(d) ((d) * 65535.99)
8
9rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height) 7rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height)
10: s(screen), w(width), h(height), format(format), shared(false) 8: s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false)
11{ 9{
12 pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); 10 pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth);
13} 11}
14 12
15rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) 13rxvt_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) 14: s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false), pm(pixmap)
17{ 15{
18} 16}
19 17
20rxvt_img * 18rxvt_img *
21rxvt_img::new_from_root (rxvt_screen *s) 19rxvt_img::new_from_root (rxvt_screen *s)
65 gdk_pixbuf_get_height (pb) 63 gdk_pixbuf_get_height (pb)
66 ); 64 );
67 65
68 img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0); 66 img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0);
69 67
68 g_object_unref (pb);
69
70 return img; 70 return img;
71} 71}
72 72
73rxvt_img::~rxvt_img () 73rxvt_img::~rxvt_img ()
74{ 74{
198 198
199 return mask; 199 return mask;
200} 200}
201 201
202void 202void
203rxvt_img::brightness (double r, double g, double b, double a) 203rxvt_img::brightness (unsigned short r, unsigned short g, unsigned short b, unsigned short a)
204{ 204{
205 Display *dpy = s->display->dpy; 205 Display *dpy = s->display->dpy;
206 Picture src = create_xrender_mask (dpy, pm, True); 206 Picture src = create_xrender_mask (dpy, pm, True);
207 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); 207 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0);
208 208
209 XRenderColor mask_c; 209 XRenderColor mask_c;
210 mask_c.red = float_to_component (r); 210 mask_c.red = r;
211 mask_c.green = float_to_component (g); 211 mask_c.green = g;
212 mask_c.blue = float_to_component (b); 212 mask_c.blue = b;
213 mask_c.alpha = float_to_component (a); 213 mask_c.alpha = a;
214 XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); 214 XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1);
215 215
216 XRenderComposite (dpy, PictOpAdd, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); 216 XRenderComposite (dpy, PictOpAdd, src, None, dst, 0, 0, 0, 0, 0, 0, w, h);
217
218 XRenderFreePicture (dpy, src);
219 XRenderFreePicture (dpy, dst);
217} 220}
218 221
219void 222void
220rxvt_img::contrast (double r, double g, double b, double a) 223rxvt_img::contrast (unsigned short r, unsigned short g, unsigned short b, unsigned short a)
221{ 224{
222 if (!(s->display->flags & DISPLAY_HAS_RENDER_MUL)) 225 if (!(s->display->flags & DISPLAY_HAS_RENDER_MUL))
223 return; 226 return;
224 227
225 Display *dpy = s->display->dpy; 228 Display *dpy = s->display->dpy;
226 Picture src = create_xrender_mask (dpy, pm, True); 229 Picture src = create_xrender_mask (dpy, pm, True);
227 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); 230 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0);
228 231
229 XRenderColor mask_c; 232 XRenderColor mask_c;
230 mask_c.red = float_to_component (r); 233 mask_c.red = r;
231 mask_c.green = float_to_component (g); 234 mask_c.green = g;
232 mask_c.blue = float_to_component (b); 235 mask_c.blue = b;
233 mask_c.alpha = float_to_component (a); 236 mask_c.alpha = a;
234 XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); 237 XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1);
235 238
236 XRenderComposite (dpy, PictOpMultiply, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); 239 XRenderComposite (dpy, PictOpMultiply, src, None, dst, 0, 0, 0, 0, 0, 0, w, h);
240
241 XRenderFreePicture (dpy, src);
242 XRenderFreePicture (dpy, dst);
237} 243}
238 244
239bool 245bool
240rxvt_img::render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y) 246rxvt_img::render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y)
241{ 247{
285 291
286 int rowstride = gdk_pixbuf_get_rowstride (pixbuf); 292 int rowstride = gdk_pixbuf_get_rowstride (pixbuf);
287 int channels = gdk_pixbuf_get_n_channels (pixbuf); 293 int channels = gdk_pixbuf_get_n_channels (pixbuf);
288 unsigned char *row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; 294 unsigned char *row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels;
289 char *line = ximage->data; 295 char *line = ximage->data;
290
291 rgba c (0, 0, 0);
292
293 if (channels == 4 && alpha_mask == 0)
294 {
295 //pix_colors[Color_bg].get (c);
296 //TODO
297 c.r = 0xffff; c.g = 0xc0c0; c.b = 0xcbcb;//D
298 c.r >>= 8;
299 c.g >>= 8;
300 c.b >>= 8;
301 }
302 296
303 for (int y = 0; y < height; y++) 297 for (int y = 0; y < height; y++)
304 { 298 {
305 for (int x = 0; x < width; x++) 299 for (int x = 0; x < width; x++)
306 { 300 {
309 unsigned char r, g, b, a; 303 unsigned char r, g, b, a;
310 304
311 if (channels == 4) 305 if (channels == 4)
312 { 306 {
313 a = pixel[3]; 307 a = pixel[3];
314 r = (pixel[0] * a + c.r * (0xff - a)) / 0xff; 308 r = pixel[0] * a / 0xff;
315 g = (pixel[1] * a + c.g * (0xff - a)) / 0xff; 309 g = pixel[1] * a / 0xff;
316 b = (pixel[2] * a + c.b * (0xff - a)) / 0xff; 310 b = pixel[2] * a / 0xff;
317 } 311 }
318 else 312 else
319 { 313 {
320 a = 0xff; 314 a = 0xff;
321 r = pixel[0]; 315 r = pixel[0];
356 350
357 return img; 351 return img;
358} 352}
359 353
360rxvt_img * 354rxvt_img *
361rxvt_img::sub_rect (int x, int y, int width, int height, int repeat) 355rxvt_img::sub_rect (int x, int y, int width, int height)
362{ 356{
363 rxvt_img *img = new rxvt_img (s, format, width, height); 357 rxvt_img *img = new rxvt_img (s, format, width, height);
364 358
365 Display *dpy = s->display->dpy; 359 Display *dpy = s->display->dpy;
366 XRenderPictureAttributes pa; 360 XRenderPictureAttributes pa;
375 369
376 return img; 370 return img;
377} 371}
378 372
379rxvt_img * 373rxvt_img *
380rxvt_img::transform (int new_width, int new_height, double matrix[9], int repeat) 374rxvt_img::transform (int new_width, int new_height, double matrix[9])
381{ 375{
382 rxvt_img *img = new rxvt_img (s, format, new_width, new_height); 376 rxvt_img *img = new rxvt_img (s, format, new_width, new_height);
383 377
384 Display *dpy = s->display->dpy; 378 Display *dpy = s->display->dpy;
385 XRenderPictureAttributes pa; 379 XRenderPictureAttributes pa;
414 408
415 return transform (new_width, new_height, matrix); 409 return transform (new_width, new_height, matrix);
416} 410}
417 411
418rxvt_img * 412rxvt_img *
419rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi, int repeat) 413rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi)
420{ 414{
421 double s = sin (phi); 415 double s = sin (phi);
422 double c = cos (phi); 416 double c = cos (phi);
423 417
424 double matrix[9] = { 418 double matrix[9] = {
425 c, -s, -c * x + s * y + x, 419 c, -s, -c * x + s * y + x,
426 s, c, -s * x - c * y + y, 420 s, c, -s * x - c * y + y,
427 0, 0, 1 421 0, 0, 1
428 }; 422 };
429 423
430 return transform (new_width, new_height, matrix, repeat); 424 return transform (new_width, new_height, matrix);
431} 425}
432 426
433rxvt_img * 427rxvt_img *
434rxvt_img::convert_to (XRenderPictFormat *new_format) 428rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg)
435{ 429{
436 rxvt_img *img = new rxvt_img (s, new_format, w, h); 430 rxvt_img *img = new rxvt_img (s, new_format, w, h);
437 431
438 Display *dpy = s->display->dpy; 432 Display *dpy = s->display->dpy;
439 Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0); 433 Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0);
440 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); 434 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0);
435 int op = PictOpSrc;
441 436
437 if (format->direct.alphaMask && !new_format->direct.alphaMask)
438 {
439 // does it have to be that complicated
440 rgba c;
441 bg.get (c);
442
443 XRenderColor rc = { c.r, c.g, c.b, 0xffff };
444 XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);
445
446 op = PictOpOver;
447 }
448
442 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); 449 XRenderComposite (dpy, op, src, None, dst, 0, 0, 0, 0, 0, 0, w, h);
443 450
444 XRenderFreePicture (dpy, src);
445 XRenderFreePicture (dpy, dst); 451 XRenderFreePicture (dpy, src);
452 XRenderFreePicture (dpy, dst);
446 453
454 return img;
455}
456
457rxvt_img *
458rxvt_img::blend (rxvt_img *img, double factor)
459{
460 rxvt_img *img2 = clone ();
461 Display *dpy = s->display->dpy;
462 Picture src = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
463 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0);
464 Picture mask = create_xrender_mask (dpy, img->pm, False);
465
466 XRenderColor mask_c;
467
468 mask_c.alpha = float_to_component (factor);
469 mask_c.red =
470 mask_c.green =
471 mask_c.blue = 0;
472 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
473
474 XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, w, h);
475
476 XRenderFreePicture (dpy, src);
477 XRenderFreePicture (dpy, dst);
478 XRenderFreePicture (dpy, mask);
479
447 return img; 480 return img2;
448} 481}
449 482
450#endif 483#endif
451 484

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines