… | |
… | |
13 | } |
13 | } |
14 | |
14 | |
15 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) |
15 | rxvt_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 | |
|
|
20 | rxvt_img * |
|
|
21 | rxvt_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 | |
20 | rxvt_img * |
52 | rxvt_img * |
21 | rxvt_img::new_from_file (rxvt_screen *s, const char *filename) |
53 | rxvt_img::new_from_file (rxvt_screen *s, const char *filename) |
22 | { |
54 | { |
… | |
… | |
33 | gdk_pixbuf_get_height (pb) |
65 | gdk_pixbuf_get_height (pb) |
34 | ); |
66 | ); |
35 | |
67 | |
36 | 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); |
37 | |
69 | |
|
|
70 | g_object_unref (pb); |
|
|
71 | |
38 | return img; |
72 | return img; |
39 | } |
73 | } |
40 | |
74 | |
41 | rxvt_img::~rxvt_img () |
75 | rxvt_img::~rxvt_img () |
42 | { |
76 | { |
… | |
… | |
87 | |
121 | |
88 | for (int i = 0; i < width; i++) |
122 | for (int i = 0; i < width; i++) |
89 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
123 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
90 | } |
124 | } |
91 | |
125 | |
92 | void |
126 | rxvt_img * |
93 | rxvt_img::blur (int rh, int rv) |
127 | rxvt_img::blur (int rh, int rv) |
94 | { |
128 | { |
95 | if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV)) |
129 | if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV)) |
96 | return; |
130 | return clone (); |
97 | |
131 | |
98 | Display *dpy = s->display->dpy; |
132 | Display *dpy = s->display->dpy; |
99 | int size = max (rh, rv) * 2 + 1; |
133 | int size = max (rh, rv) * 2 + 1; |
100 | double *kernel = (double *)malloc (size * sizeof (double)); |
134 | double *kernel = (double *)malloc (size * sizeof (double)); |
101 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
135 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
|
|
136 | rxvt_img *img = new rxvt_img (s, format, w, h); |
102 | |
137 | |
103 | XRenderPictureAttributes pa; |
138 | XRenderPictureAttributes pa; |
104 | |
139 | |
105 | pa.repeat = RepeatPad; |
140 | pa.repeat = RepeatPad; |
106 | Picture src = XRenderCreatePicture (dpy, pm , format, CPRepeat, &pa); |
141 | Picture src = XRenderCreatePicture (dpy, pm , format, CPRepeat, &pa); |
|
|
142 | Picture dst = XRenderCreatePicture (dpy, img->pm, format, CPRepeat, &pa); |
|
|
143 | |
107 | Pixmap tmp = XCreatePixmap (dpy, pm, w, h, format->depth); |
144 | Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth); |
108 | Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); |
145 | Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa); |
109 | XFreePixmap (dpy, tmp); |
146 | XFreePixmap (dpy, tmp_pm); |
110 | |
147 | |
111 | if (kernel && params) |
148 | if (kernel && params) |
112 | { |
149 | { |
113 | size = rh * 2 + 1; |
150 | size = rh * 2 + 1; |
114 | get_gaussian_kernel (rh, size, kernel, params); |
151 | get_gaussian_kernel (rh, size, kernel, params); |
… | |
… | |
116 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
153 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
117 | XRenderComposite (dpy, |
154 | XRenderComposite (dpy, |
118 | PictOpSrc, |
155 | PictOpSrc, |
119 | src, |
156 | src, |
120 | None, |
157 | None, |
121 | dst, |
158 | tmp, |
122 | 0, 0, |
159 | 0, 0, |
123 | 0, 0, |
160 | 0, 0, |
124 | 0, 0, |
161 | 0, 0, |
125 | w, h); |
162 | w, h); |
126 | |
|
|
127 | ::swap (src, dst); |
|
|
128 | |
163 | |
129 | size = rv * 2 + 1; |
164 | size = rv * 2 + 1; |
130 | get_gaussian_kernel (rv, size, kernel, params); |
165 | get_gaussian_kernel (rv, size, kernel, params); |
131 | ::swap (params[0], params[1]); |
166 | ::swap (params[0], params[1]); |
132 | |
167 | |
133 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
168 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
134 | XRenderComposite (dpy, |
169 | XRenderComposite (dpy, |
135 | PictOpSrc, |
170 | PictOpSrc, |
136 | src, |
171 | tmp, |
137 | None, |
172 | None, |
138 | dst, |
173 | dst, |
139 | 0, 0, |
174 | 0, 0, |
140 | 0, 0, |
175 | 0, 0, |
141 | 0, 0, |
176 | 0, 0, |
… | |
… | |
144 | |
179 | |
145 | free (kernel); |
180 | free (kernel); |
146 | free (params); |
181 | free (params); |
147 | XRenderFreePicture (dpy, src); |
182 | XRenderFreePicture (dpy, src); |
148 | XRenderFreePicture (dpy, dst); |
183 | XRenderFreePicture (dpy, dst); |
|
|
184 | XRenderFreePicture (dpy, tmp); |
|
|
185 | |
|
|
186 | return img; |
149 | } |
187 | } |
150 | |
188 | |
151 | static Picture |
189 | static Picture |
152 | create_xrender_mask (Display *dpy, Drawable drawable, Bool argb) |
190 | create_xrender_mask (Display *dpy, Drawable drawable, Bool argb) |
153 | { |
191 | { |
… | |
… | |
176 | mask_c.blue = float_to_component (b); |
214 | mask_c.blue = float_to_component (b); |
177 | mask_c.alpha = float_to_component (a); |
215 | mask_c.alpha = float_to_component (a); |
178 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
216 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
179 | |
217 | |
180 | XRenderComposite (dpy, PictOpAdd, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
218 | XRenderComposite (dpy, PictOpAdd, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
|
|
219 | |
|
|
220 | XRenderFreePicture (dpy, src); |
|
|
221 | XRenderFreePicture (dpy, dst); |
181 | } |
222 | } |
182 | |
223 | |
183 | void |
224 | void |
184 | rxvt_img::contrast (double r, double g, double b, double a) |
225 | rxvt_img::contrast (double r, double g, double b, double a) |
185 | { |
226 | { |
… | |
… | |
196 | mask_c.blue = float_to_component (b); |
237 | mask_c.blue = float_to_component (b); |
197 | mask_c.alpha = float_to_component (a); |
238 | mask_c.alpha = float_to_component (a); |
198 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
239 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
199 | |
240 | |
200 | XRenderComposite (dpy, PictOpMultiply, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
241 | XRenderComposite (dpy, PictOpMultiply, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
|
|
242 | |
|
|
243 | XRenderFreePicture (dpy, src); |
|
|
244 | XRenderFreePicture (dpy, dst); |
201 | } |
245 | } |
202 | |
246 | |
203 | bool |
247 | bool |
204 | rxvt_img::render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y) |
248 | rxvt_img::render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y) |
205 | { |
249 | { |
… | |
… | |
249 | |
293 | |
250 | int rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
294 | int rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
251 | int channels = gdk_pixbuf_get_n_channels (pixbuf); |
295 | int channels = gdk_pixbuf_get_n_channels (pixbuf); |
252 | 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; |
253 | char *line = ximage->data; |
297 | char *line = ximage->data; |
254 | |
|
|
255 | rgba c (0, 0, 0); |
|
|
256 | |
|
|
257 | if (channels == 4 && alpha_mask == 0) |
|
|
258 | { |
|
|
259 | //pix_colors[Color_bg].get (c); |
|
|
260 | //TODO |
|
|
261 | c.r = 0xffff; c.g = 0xc0c0; c.b = 0xcbcb;//D |
|
|
262 | c.r >>= 8; |
|
|
263 | c.g >>= 8; |
|
|
264 | c.b >>= 8; |
|
|
265 | } |
|
|
266 | |
298 | |
267 | for (int y = 0; y < height; y++) |
299 | for (int y = 0; y < height; y++) |
268 | { |
300 | { |
269 | for (int x = 0; x < width; x++) |
301 | for (int x = 0; x < width; x++) |
270 | { |
302 | { |
… | |
… | |
273 | unsigned char r, g, b, a; |
305 | unsigned char r, g, b, a; |
274 | |
306 | |
275 | if (channels == 4) |
307 | if (channels == 4) |
276 | { |
308 | { |
277 | a = pixel[3]; |
309 | a = pixel[3]; |
278 | r = (pixel[0] * a + c.r * (0xff - a)) / 0xff; |
310 | r = pixel[0] * a / 0xff; |
279 | g = (pixel[1] * a + c.g * (0xff - a)) / 0xff; |
311 | g = pixel[1] * a / 0xff; |
280 | b = (pixel[2] * a + c.b * (0xff - a)) / 0xff; |
312 | b = pixel[2] * a / 0xff; |
281 | } |
313 | } |
282 | else |
314 | else |
283 | { |
315 | { |
284 | a = 0xff; |
316 | a = 0xff; |
285 | r = pixel[0]; |
317 | r = pixel[0]; |
… | |
… | |
315 | rxvt_img *img = new rxvt_img (s, format, w, h); |
347 | rxvt_img *img = new rxvt_img (s, format, w, h); |
316 | |
348 | |
317 | GC gc = XCreateGC (s->display->dpy, pm, 0, 0); |
349 | GC gc = XCreateGC (s->display->dpy, pm, 0, 0); |
318 | XCopyArea (s->display->dpy, pm, img->pm, gc, 0, 0, w, h, 0, 0); |
350 | XCopyArea (s->display->dpy, pm, img->pm, gc, 0, 0, w, h, 0, 0); |
319 | XFreeGC (s->display->dpy, gc); |
351 | XFreeGC (s->display->dpy, gc); |
|
|
352 | |
|
|
353 | return img; |
320 | } |
354 | } |
321 | |
355 | |
322 | rxvt_img * |
356 | rxvt_img * |
323 | rxvt_img::sub_rect (int x, int y, int width, int height, int repeat) |
357 | rxvt_img::sub_rect (int x, int y, int width, int height, int repeat) |
324 | { |
358 | { |
… | |
… | |
407 | XRenderFreePicture (dpy, dst); |
441 | XRenderFreePicture (dpy, dst); |
408 | |
442 | |
409 | return img; |
443 | return img; |
410 | } |
444 | } |
411 | |
445 | |
|
|
446 | rxvt_img * |
|
|
447 | rxvt_img::blend (rxvt_img *img, double factor) |
|
|
448 | { |
|
|
449 | rxvt_img *img2 = clone (); |
|
|
450 | Display *dpy = s->display->dpy; |
|
|
451 | Picture src = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
|
|
452 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
|
|
453 | Picture mask = create_xrender_mask (dpy, img->pm, False); |
|
|
454 | |
|
|
455 | XRenderColor mask_c; |
|
|
456 | |
|
|
457 | mask_c.alpha = float_to_component (factor); |
|
|
458 | mask_c.red = |
|
|
459 | mask_c.green = |
|
|
460 | mask_c.blue = 0; |
|
|
461 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
|
|
462 | |
|
|
463 | XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, w, h); |
|
|
464 | |
|
|
465 | XRenderFreePicture (dpy, src); |
|
|
466 | XRenderFreePicture (dpy, dst); |
|
|
467 | XRenderFreePicture (dpy, mask); |
|
|
468 | |
|
|
469 | return img2; |
|
|
470 | } |
|
|
471 | |
412 | #endif |
472 | #endif |
413 | |
473 | |