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.30 by root, Wed Jun 6 22:01:44 2012 UTC vs.
Revision 1.32 by root, Thu Jun 7 07:53:12 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), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false) 8: s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal),
9 pm(0), refcnt(0)
11{ 10{
12 pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth);
13} 11}
14 12
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), refcnt(img.refcnt)
15{
16 if (refcnt)
17 ++*refcnt;
18}
19
20#if 0
15rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) 21rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap)
16: s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false), pm(pixmap) 22: s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false), pm(pixmap)
17{ 23{
18} 24}
25#endif
19 26
20rxvt_img * 27rxvt_img *
21rxvt_img::new_from_root (rxvt_screen *s) 28rxvt_img::new_from_root (rxvt_screen *s)
22{ 29{
23 Display *dpy = s->display->dpy; 30 Display *dpy = s->display->dpy;
38 45
39 rxvt_img *img = new rxvt_img ( 46 rxvt_img *img = new rxvt_img (
40 s, 47 s,
41 XRenderFindVisualFormat (dpy, DefaultVisual (dpy, s->display->screen)), 48 XRenderFindVisualFormat (dpy, DefaultVisual (dpy, s->display->screen)),
42 root_pm_w, 49 root_pm_w,
43 root_pm_h, 50 root_pm_h
44 root_pixmap
45 ); 51 );
46 52
47 img->shared = true; 53 img->pm = root_pixmap;
48 54
49 return img; 55 return img;
50} 56}
51 57
52rxvt_img * 58rxvt_img *
62 s, 68 s,
63 XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24), 69 XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24),
64 gdk_pixbuf_get_width (pb), 70 gdk_pixbuf_get_width (pb),
65 gdk_pixbuf_get_height (pb) 71 gdk_pixbuf_get_height (pb)
66 ); 72 );
67 73 img->alloc ();
68 img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0); 74 img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0);
69 75
70 g_object_unref (pb); 76 g_object_unref (pb);
71 77
72 return img; 78 return img;
73} 79}
74 80
81void
82rxvt_img::destroy ()
83{
84 if (!refcnt || --*refcnt)
85 return;
86
87 if (pm)
88 XFreePixmap (s->display->dpy, pm);
89
90 delete refcnt;
91}
92
75rxvt_img::~rxvt_img () 93rxvt_img::~rxvt_img ()
76{ 94{
77 if (!shared) 95 destroy ();
78 XFreePixmap (s->display->dpy, pm); 96}
97
98void
99rxvt_img::alloc ()
100{
101 pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth);
102 refcnt = new int (1);
79} 103}
80 104
81void 105void
82rxvt_img::unshare () 106rxvt_img::unshare ()
83{ 107{
84 if (!shared) 108 if (refcnt && *refcnt == 1)
85 return; 109 return;
86 110
87 rxvt_img *img = clone (); 111 Pixmap pm2 = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth);
112 GC gc = XCreateGC (s->display->dpy, pm, 0, 0);
113 XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, w, h, 0, 0);
114 XFreeGC (s->display->dpy, gc);
88 115
89 ::swap (pm , img->pm); 116 destroy ();
90 ::swap (shared, img->shared);
91 117
92 delete img; 118 pm = pm2;
119 refcnt = new int (1);
93} 120}
94 121
95void 122void
96rxvt_img::fill (const rxvt_color &c) 123rxvt_img::fill (const rxvt_color &c)
97{ 124{
132 Display *dpy = s->display->dpy; 159 Display *dpy = s->display->dpy;
133 int size = max (rh, rv) * 2 + 1; 160 int size = max (rh, rv) * 2 + 1;
134 double *kernel = (double *)malloc (size * sizeof (double)); 161 double *kernel = (double *)malloc (size * sizeof (double));
135 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 162 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
136 rxvt_img *img = new rxvt_img (s, format, w, h); 163 rxvt_img *img = new rxvt_img (s, format, w, h);
164 img->alloc ();
137 165
138 XRenderPictureAttributes pa; 166 XRenderPictureAttributes pa;
139 167
140 pa.repeat = RepeatPad; 168 pa.repeat = RepeatPad;
141 Picture src = XRenderCreatePicture (dpy, pm , format, CPRepeat, &pa); 169 Picture src = XRenderCreatePicture (dpy, pm , format, CPRepeat, &pa);
200 228
201 return mask; 229 return mask;
202} 230}
203 231
204void 232void
205rxvt_img::brightness (double r, double g, double b, double a) 233rxvt_img::brightness (unsigned short r, unsigned short g, unsigned short b, unsigned short a)
206{ 234{
207 Display *dpy = s->display->dpy; 235 Display *dpy = s->display->dpy;
208 Picture src = create_xrender_mask (dpy, pm, True); 236 Picture src = create_xrender_mask (dpy, pm, True);
209 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); 237 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0);
210 238
211 XRenderColor mask_c; 239 XRenderColor mask_c;
212 mask_c.red = float_to_component (r); 240 mask_c.red = r;
213 mask_c.green = float_to_component (g); 241 mask_c.green = g;
214 mask_c.blue = float_to_component (b); 242 mask_c.blue = b;
215 mask_c.alpha = float_to_component (a); 243 mask_c.alpha = a;
216 XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); 244 XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1);
217 245
218 XRenderComposite (dpy, PictOpAdd, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); 246 XRenderComposite (dpy, PictOpAdd, src, None, dst, 0, 0, 0, 0, 0, 0, w, h);
219 247
220 XRenderFreePicture (dpy, src); 248 XRenderFreePicture (dpy, src);
221 XRenderFreePicture (dpy, dst); 249 XRenderFreePicture (dpy, dst);
222} 250}
223 251
224void 252void
225rxvt_img::contrast (double r, double g, double b, double a) 253rxvt_img::contrast (unsigned short r, unsigned short g, unsigned short b, unsigned short a)
226{ 254{
227 if (!(s->display->flags & DISPLAY_HAS_RENDER_MUL)) 255 if (!(s->display->flags & DISPLAY_HAS_RENDER_MUL))
228 return; 256 return;
229 257
230 Display *dpy = s->display->dpy; 258 Display *dpy = s->display->dpy;
231 Picture src = create_xrender_mask (dpy, pm, True); 259 Picture src = create_xrender_mask (dpy, pm, True);
232 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); 260 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0);
233 261
234 XRenderColor mask_c; 262 XRenderColor mask_c;
235 mask_c.red = float_to_component (r); 263 mask_c.red = r;
236 mask_c.green = float_to_component (g); 264 mask_c.green = g;
237 mask_c.blue = float_to_component (b); 265 mask_c.blue = b;
238 mask_c.alpha = float_to_component (a); 266 mask_c.alpha = a;
239 XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); 267 XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1);
240 268
241 XRenderComposite (dpy, PictOpMultiply, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); 269 XRenderComposite (dpy, PictOpMultiply, src, None, dst, 0, 0, 0, 0, 0, 0, w, h);
242 270
243 XRenderFreePicture (dpy, src); 271 XRenderFreePicture (dpy, src);
342} 370}
343 371
344rxvt_img * 372rxvt_img *
345rxvt_img::clone () 373rxvt_img::clone ()
346{ 374{
347 rxvt_img *img = new rxvt_img (s, format, w, h); 375 return new rxvt_img (*this);
348
349 GC gc = XCreateGC (s->display->dpy, pm, 0, 0);
350 XCopyArea (s->display->dpy, pm, img->pm, gc, 0, 0, w, h, 0, 0);
351 XFreeGC (s->display->dpy, gc);
352
353 return img;
354} 376}
355 377
356rxvt_img * 378rxvt_img *
357rxvt_img::sub_rect (int x, int y, int width, int height) 379rxvt_img::sub_rect (int x, int y, int width, int height)
358{ 380{
359 rxvt_img *img = new rxvt_img (s, format, width, height); 381 rxvt_img *img = new rxvt_img (s, format, width, height);
382 img->alloc ();
360 383
361 Display *dpy = s->display->dpy; 384 Display *dpy = s->display->dpy;
362 XRenderPictureAttributes pa; 385 XRenderPictureAttributes pa;
363 pa.repeat = repeat; 386 pa.repeat = repeat;
364 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); 387 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa);
374 397
375rxvt_img * 398rxvt_img *
376rxvt_img::transform (int new_width, int new_height, double matrix[9]) 399rxvt_img::transform (int new_width, int new_height, double matrix[9])
377{ 400{
378 rxvt_img *img = new rxvt_img (s, format, new_width, new_height); 401 rxvt_img *img = new rxvt_img (s, format, new_width, new_height);
402 img->alloc ();
379 403
380 Display *dpy = s->display->dpy; 404 Display *dpy = s->display->dpy;
381 XRenderPictureAttributes pa; 405 XRenderPictureAttributes pa;
382 pa.repeat = repeat; 406 pa.repeat = repeat;
383 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); 407 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa);
427} 451}
428 452
429rxvt_img * 453rxvt_img *
430rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) 454rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg)
431{ 455{
456 if (new_format == format)
457 return clone ();
458
432 rxvt_img *img = new rxvt_img (s, new_format, w, h); 459 rxvt_img *img = new rxvt_img (s, new_format, w, h);
460 img->alloc ();
433 461
434 Display *dpy = s->display->dpy; 462 Display *dpy = s->display->dpy;
435 Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0); 463 Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0);
436 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); 464 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0);
437 int op = PictOpSrc; 465 int op = PictOpSrc;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines