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.18 by sf-exg, Tue Jun 5 12:30:37 2012 UTC vs.
Revision 1.22 by sf-exg, Tue Jun 5 15:18:23 2012 UTC

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), pm(pixmap), w(width), h(height), format(format), shared(false)
17{ 17{
18}
19
20rxvt_img *
21rxvt_img::new_from_root (rxvt_screen *s)
22{
23 Display *dpy = s->display->dpy;
24 unsigned int root_pm_w, root_pm_h;
25 Pixmap root_pixmap = s->display->get_pixmap_property (s->display->xa[XA_XROOTPMAP_ID]);
26 if (root_pixmap == None)
27 root_pixmap = s->display->get_pixmap_property (s->display->xa[XA_ESETROOT_PMAP_ID]);
28
29 if (root_pixmap == None)
30 return 0;
31
32 Window wdummy;
33 int idummy;
34 unsigned int udummy;
35
36 if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pm_w, &root_pm_h, &udummy, &udummy))
37 return 0;
38
39 rxvt_img *img = new rxvt_img (
40 s,
41 XRenderFindVisualFormat (dpy, DefaultVisual (dpy, s->display->screen)),
42 root_pm_w,
43 root_pm_h,
44 root_pixmap
45 );
46
47 img->shared = true;
48
49 return img;
18} 50}
19 51
20rxvt_img * 52rxvt_img *
21rxvt_img::new_from_file (rxvt_screen *s, const char *filename) 53rxvt_img::new_from_file (rxvt_screen *s, const char *filename)
22{ 54{
87 119
88 for (int i = 0; i < width; i++) 120 for (int i = 0; i < width; i++)
89 params[i+2] = XDoubleToFixed (kernel[i] / sum); 121 params[i+2] = XDoubleToFixed (kernel[i] / sum);
90} 122}
91 123
92void 124rxvt_img *
93rxvt_img::blur (int rh, int rv) 125rxvt_img::blur (int rh, int rv)
94{ 126{
95 if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV)) 127 if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV))
96 return; 128 return clone ();
97 129
98 Display *dpy = s->display->dpy; 130 Display *dpy = s->display->dpy;
99 int size = max (rh, rv) * 2 + 1; 131 int size = max (rh, rv) * 2 + 1;
100 double *kernel = (double *)malloc (size * sizeof (double)); 132 double *kernel = (double *)malloc (size * sizeof (double));
101 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 133 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
134 rxvt_img *img = new rxvt_img (s, format, w, h);
102 135
103 XRenderPictureAttributes pa; 136 XRenderPictureAttributes pa;
104 137
105 pa.repeat = RepeatPad; 138 pa.repeat = RepeatPad;
106 Picture src = XRenderCreatePicture (dpy, pm , format, CPRepeat, &pa); 139 Picture src = XRenderCreatePicture (dpy, pm , format, CPRepeat, &pa);
140 Picture dst = XRenderCreatePicture (dpy, img->pm, format, CPRepeat, &pa);
141
107 Pixmap tmp = XCreatePixmap (dpy, pm, w, h, format->depth); 142 Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth);
108 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); 143 Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa);
109 XFreePixmap (dpy, tmp); 144 XFreePixmap (dpy, tmp_pm);
110 145
111 if (kernel && params) 146 if (kernel && params)
112 { 147 {
113 size = rh * 2 + 1; 148 size = rh * 2 + 1;
114 get_gaussian_kernel (rh, size, kernel, params); 149 get_gaussian_kernel (rh, size, kernel, params);
116 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 151 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
117 XRenderComposite (dpy, 152 XRenderComposite (dpy,
118 PictOpSrc, 153 PictOpSrc,
119 src, 154 src,
120 None, 155 None,
121 dst, 156 tmp,
122 0, 0, 157 0, 0,
123 0, 0, 158 0, 0,
124 0, 0, 159 0, 0,
125 w, h); 160 w, h);
126
127 ::swap (src, dst);
128 161
129 size = rv * 2 + 1; 162 size = rv * 2 + 1;
130 get_gaussian_kernel (rv, size, kernel, params); 163 get_gaussian_kernel (rv, size, kernel, params);
131 ::swap (params[0], params[1]); 164 ::swap (params[0], params[1]);
132 165
133 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 166 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
134 XRenderComposite (dpy, 167 XRenderComposite (dpy,
135 PictOpSrc, 168 PictOpSrc,
136 src, 169 tmp,
137 None, 170 None,
138 dst, 171 dst,
139 0, 0, 172 0, 0,
140 0, 0, 173 0, 0,
141 0, 0, 174 0, 0,
144 177
145 free (kernel); 178 free (kernel);
146 free (params); 179 free (params);
147 XRenderFreePicture (dpy, src); 180 XRenderFreePicture (dpy, src);
148 XRenderFreePicture (dpy, dst); 181 XRenderFreePicture (dpy, dst);
182 XRenderFreePicture (dpy, tmp);
183
184 return img;
149} 185}
150 186
151static Picture 187static Picture
152create_xrender_mask (Display *dpy, Drawable drawable, Bool argb) 188create_xrender_mask (Display *dpy, Drawable drawable, Bool argb)
153{ 189{
310} 346}
311 347
312rxvt_img * 348rxvt_img *
313rxvt_img::clone () 349rxvt_img::clone ()
314{ 350{
351 rxvt_img *img = new rxvt_img (s, format, w, h);
352
315 GC gc = XCreateGC (s->display->dpy, pm, 0, 0); 353 GC gc = XCreateGC (s->display->dpy, pm, 0, 0);
316 Pixmap pm2 = XCreatePixmap (s->display->dpy, pm, w, h, format->depth);
317 XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, w, h, 0, 0); 354 XCopyArea (s->display->dpy, pm, img->pm, gc, 0, 0, w, h, 0, 0);
318 XFreeGC (s->display->dpy, gc); 355 XFreeGC (s->display->dpy, gc);
319 return new rxvt_img (s, format, w, h, pm2);
320}
321 356
357 return img;
358}
359
322rxvt_img * 360rxvt_img *
361rxvt_img::sub_rect (int x, int y, int width, int height, int repeat)
362{
363 rxvt_img *img = new rxvt_img (s, format, width, height);
364
365 Display *dpy = s->display->dpy;
366 XRenderPictureAttributes pa;
367 pa.repeat = repeat;
368 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa);
369 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
370
371 XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, width, height);
372
373 XRenderFreePicture (dpy, src);
374 XRenderFreePicture (dpy, dst);
375
376 return img;
377}
378
379rxvt_img *
323rxvt_img::transform (int new_width, int new_height, int repeat, double matrix[9]) 380rxvt_img::transform (int new_width, int new_height, double matrix[9], int repeat)
324{ 381{
325 rxvt_img *img = new rxvt_img (s, format, new_width, new_height); 382 rxvt_img *img = new rxvt_img (s, format, new_width, new_height);
326 383
327 Display *dpy = s->display->dpy; 384 Display *dpy = s->display->dpy;
328 XRenderPictureAttributes pa; 385 XRenderPictureAttributes pa;
353 w / (double)new_width, 0, 0, 410 w / (double)new_width, 0, 0,
354 0, h / (double)new_height, 0, 411 0, h / (double)new_height, 0,
355 0, 0, 1 412 0, 0, 1
356 }; 413 };
357 414
358 return transform (new_width, new_height, RepeatNormal, matrix); 415 return transform (new_width, new_height, matrix);
359} 416}
360 417
361rxvt_img * 418rxvt_img *
362rxvt_img::rotate (int new_width, int new_height, int repeat, int x, int y, double phi) 419rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi, int repeat)
363{ 420{
364 double s = sin (phi); 421 double s = sin (phi);
365 double c = cos (phi); 422 double c = cos (phi);
366 423
367 double matrix[9] = { 424 double matrix[9] = {
368 c, -s, -c * x + s * y + x, 425 c, -s, -c * x + s * y + x,
369 s, c, -s * x - c * y + y, 426 s, c, -s * x - c * y + y,
370 0, 0, 1 427 0, 0, 1
371 }; 428 };
372 429
373 return transform (new_width, new_height, repeat, matrix); 430 return transform (new_width, new_height, matrix, repeat);
374} 431}
375 432
376rxvt_img * 433rxvt_img *
377rxvt_img::convert_to (XRenderPictFormat *new_format) 434rxvt_img::convert_to (XRenderPictFormat *new_format)
378{ 435{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines