… | |
… | |
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 | #if 0 |
|
|
8 | struct pict |
|
|
9 | { |
|
|
10 | Display *dpy; |
|
|
11 | Picture pic; |
|
|
12 | |
|
|
13 | operator Picture () const |
|
|
14 | { |
|
|
15 | return pic; |
|
|
16 | } |
|
|
17 | |
|
|
18 | pict () |
|
|
19 | : pic (0) |
|
|
20 | { |
|
|
21 | } |
|
|
22 | |
|
|
23 | pict (rxvt_img *img, XRenderPictFormat *format = 0) |
|
|
24 | : dpy (img->s->display->dpy) |
|
|
25 | { |
|
|
26 | XRenderPictureAttributes pa; |
|
|
27 | pa.repeat = img->repeat; |
|
|
28 | pic = XRenderCreatePicture (dpy, img->pm, format ? format : img->format, CPRepeat, &pa); |
|
|
29 | } |
|
|
30 | |
|
|
31 | ~pict () |
|
|
32 | { |
|
|
33 | if (pic) |
|
|
34 | XRenderFreePicture (dpy, pic); |
|
|
35 | } |
|
|
36 | }; |
|
|
37 | #endif |
|
|
38 | |
|
|
39 | static XRenderPictFormat * |
|
|
40 | find_alpha_format_for (Display *dpy, XRenderPictFormat *format) |
|
|
41 | { |
|
|
42 | if (format->direct.alphaMask) |
|
|
43 | return format; // already has alpha |
|
|
44 | |
|
|
45 | // try to find a suitable alpha format, one bit alpha is enough for our purposes |
|
|
46 | if (format->type == PictTypeDirect) |
|
|
47 | for (int n = 0; XRenderPictFormat *f = XRenderFindFormat (dpy, 0, 0, n); ++n) |
|
|
48 | if (f->direct.alphaMask |
|
|
49 | && f->type == PictTypeDirect |
|
|
50 | && ecb_popcount32 (f->direct.redMask ) >= ecb_popcount32 (format->direct.redMask ) |
|
|
51 | && ecb_popcount32 (f->direct.greenMask) >= ecb_popcount32 (format->direct.greenMask) |
|
|
52 | && ecb_popcount32 (f->direct.blueMask ) >= ecb_popcount32 (format->direct.blueMask )) |
|
|
53 | return f; |
|
|
54 | |
|
|
55 | // should be a very good fallback |
|
|
56 | return XRenderFindStandardFormat (dpy, PictStandardARGB32); |
|
|
57 | } |
|
|
58 | |
7 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height) |
59 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height, int repeat) |
8 | : s(screen), x(x), y(y), w(width), h(height), format(format), repeat(RepeatNormal), |
60 | : s(screen), x(x), y(y), w(width), h(height), format(format), repeat(repeat), |
9 | pm(0), refcnt(0) |
61 | pm(0), ref(0) |
10 | { |
62 | { |
11 | } |
63 | } |
12 | |
64 | |
13 | rxvt_img::rxvt_img (const rxvt_img &img) |
65 | rxvt_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) |
66 | : s(img.s), x(img.x), y(img.y), w(img.w), h(img.h), format(img.format), repeat(img.repeat), pm(img.pm), ref(img.ref) |
15 | { |
67 | { |
16 | if (refcnt) |
|
|
17 | ++*refcnt; |
68 | ++ref->cnt; |
18 | } |
69 | } |
19 | |
|
|
20 | #if 0 |
|
|
21 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) |
|
|
22 | : s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false), pm(pixmap) |
|
|
23 | { |
|
|
24 | } |
|
|
25 | #endif |
|
|
26 | |
70 | |
27 | rxvt_img * |
71 | rxvt_img * |
28 | rxvt_img::new_from_root (rxvt_screen *s) |
72 | rxvt_img::new_from_root (rxvt_screen *s) |
29 | { |
73 | { |
30 | Display *dpy = s->display->dpy; |
74 | Display *dpy = s->display->dpy; |
… | |
… | |
51 | root_pm_w, |
95 | root_pm_w, |
52 | root_pm_h |
96 | root_pm_h |
53 | ); |
97 | ); |
54 | |
98 | |
55 | img->pm = root_pixmap; |
99 | img->pm = root_pixmap; |
|
|
100 | img->ref = new pixref (root_pm_w, root_pm_h); |
|
|
101 | img->ref->ours = false; |
|
|
102 | |
|
|
103 | return img; |
|
|
104 | } |
|
|
105 | |
|
|
106 | # if HAVE_PIXBUF |
|
|
107 | |
|
|
108 | rxvt_img * |
|
|
109 | rxvt_img::new_from_pixbuf (rxvt_screen *s, GdkPixbuf *pb) |
|
|
110 | { |
|
|
111 | Display *dpy = s->display->dpy; |
|
|
112 | |
|
|
113 | int width = gdk_pixbuf_get_width (pb); |
|
|
114 | int height = gdk_pixbuf_get_height (pb); |
|
|
115 | |
|
|
116 | if (width > 32767 || height > 32767) // well, we *could* upload in chunks |
|
|
117 | rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big (maximum size 32768x32768).\n"); |
|
|
118 | |
|
|
119 | // since we require rgb24/argb32 formats from xrender we assume |
|
|
120 | // that both 24 and 32 bpp MUST be supported by any screen that supports xrender |
|
|
121 | |
|
|
122 | int byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
|
|
123 | |
|
|
124 | XImage xi; |
|
|
125 | |
|
|
126 | xi.width = width; |
|
|
127 | xi.height = height; |
|
|
128 | xi.xoffset = 0; |
|
|
129 | xi.format = ZPixmap; |
|
|
130 | xi.byte_order = ImageByteOrder (dpy); |
|
|
131 | xi.bitmap_unit = 0; //XY only, unused |
|
|
132 | xi.bitmap_bit_order = 0; //XY only, unused |
|
|
133 | xi.bitmap_pad = BitmapPad (dpy); |
|
|
134 | xi.depth = 32; |
|
|
135 | xi.bytes_per_line = 0; |
|
|
136 | xi.bits_per_pixel = 32; //Z only |
|
|
137 | xi.red_mask = 0x00000000; //Z only, unused |
|
|
138 | xi.green_mask = 0x00000000; //Z only, unused |
|
|
139 | xi.blue_mask = 0x00000000; //Z only, unused |
|
|
140 | xi.obdata = 0; // probably unused |
|
|
141 | |
|
|
142 | bool byte_order_mismatch = byte_order != xi.byte_order; |
|
|
143 | |
|
|
144 | if (!XInitImage (&xi)) |
|
|
145 | rxvt_fatal ("unable to initialise ximage, please report.\n"); |
|
|
146 | |
|
|
147 | if (height > INT_MAX / xi.bytes_per_line) |
|
|
148 | rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big for Xlib.\n"); |
|
|
149 | |
|
|
150 | xi.data = (char *)rxvt_malloc (height * xi.bytes_per_line); |
|
|
151 | |
|
|
152 | int rowstride = gdk_pixbuf_get_rowstride (pb); |
|
|
153 | bool pb_has_alpha = gdk_pixbuf_get_has_alpha (pb); |
|
|
154 | unsigned char *row = gdk_pixbuf_get_pixels (pb); |
|
|
155 | |
|
|
156 | char *line = xi.data; |
|
|
157 | |
|
|
158 | for (int y = 0; y < height; y++) |
|
|
159 | { |
|
|
160 | unsigned char *src = row; |
|
|
161 | uint32_t *dst = (uint32_t *)line; |
|
|
162 | |
|
|
163 | if (!pb_has_alpha) |
|
|
164 | for (int x = 0; x < width; x++) |
|
|
165 | { |
|
|
166 | uint8_t r = *src++; |
|
|
167 | uint8_t g = *src++; |
|
|
168 | uint8_t b = *src++; |
|
|
169 | |
|
|
170 | uint32_t v = (255 << 24) | (r << 16) | (g << 8) | b; |
|
|
171 | |
|
|
172 | if (ecb_big_endian () ? !byte_order_mismatch : byte_order_mismatch) |
|
|
173 | v = ecb_bswap32 (v); |
|
|
174 | |
|
|
175 | *dst++ = v; |
|
|
176 | } |
|
|
177 | else |
|
|
178 | for (int x = 0; x < width; x++) |
|
|
179 | { |
|
|
180 | uint32_t v = *(uint32_t *)src; src += 4; |
|
|
181 | |
|
|
182 | if (ecb_big_endian ()) |
|
|
183 | v = ecb_bswap32 (v); |
|
|
184 | |
|
|
185 | v = ecb_rotl32 (v, 8); // abgr to bgra |
|
|
186 | |
|
|
187 | if (!byte_order_mismatch) |
|
|
188 | v = ecb_bswap32 (v); |
|
|
189 | |
|
|
190 | *dst++ = v; |
|
|
191 | } |
|
|
192 | |
|
|
193 | row += rowstride; |
|
|
194 | line += xi.bytes_per_line; |
|
|
195 | } |
|
|
196 | |
|
|
197 | rxvt_img *img = new rxvt_img (s, XRenderFindStandardFormat (dpy, PictStandardARGB32), 0, 0, width, height); |
|
|
198 | img->alloc (); |
|
|
199 | |
|
|
200 | GC gc = XCreateGC (dpy, img->pm, 0, 0); |
|
|
201 | XPutImage (dpy, img->pm, gc, &xi, 0, 0, 0, 0, width, height); |
|
|
202 | XFreeGC (dpy, gc); |
|
|
203 | |
|
|
204 | free (xi.data); |
56 | |
205 | |
57 | return img; |
206 | return img; |
58 | } |
207 | } |
59 | |
208 | |
60 | rxvt_img * |
209 | rxvt_img * |
… | |
… | |
64 | GdkPixbuf *pb = gdk_pixbuf_new_from_file (filename, &err); |
213 | GdkPixbuf *pb = gdk_pixbuf_new_from_file (filename, &err); |
65 | |
214 | |
66 | if (!pb) |
215 | if (!pb) |
67 | rxvt_fatal ("rxvt_img::new_from_file: %s\n", err->message); |
216 | rxvt_fatal ("rxvt_img::new_from_file: %s\n", err->message); |
68 | |
217 | |
69 | rxvt_img *img = new rxvt_img ( |
218 | rxvt_img *img = new_from_pixbuf (s, pb); |
70 | s, |
|
|
71 | XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24), |
|
|
72 | 0, |
|
|
73 | 0, |
|
|
74 | gdk_pixbuf_get_width (pb), |
|
|
75 | gdk_pixbuf_get_height (pb) |
|
|
76 | ); |
|
|
77 | img->alloc (); |
|
|
78 | img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0); |
|
|
79 | |
219 | |
80 | g_object_unref (pb); |
220 | g_object_unref (pb); |
81 | |
221 | |
82 | return img; |
222 | return img; |
83 | } |
223 | } |
|
|
224 | |
|
|
225 | # endif |
84 | |
226 | |
85 | void |
227 | void |
86 | rxvt_img::destroy () |
228 | rxvt_img::destroy () |
87 | { |
229 | { |
88 | if (!refcnt || --*refcnt) |
230 | if (--ref->cnt) |
89 | return; |
231 | return; |
90 | |
232 | |
91 | if (pm) |
233 | if (pm && ref->ours) |
92 | XFreePixmap (s->display->dpy, pm); |
234 | XFreePixmap (s->display->dpy, pm); |
93 | |
235 | |
94 | delete refcnt; |
236 | delete ref; |
95 | } |
237 | } |
96 | |
238 | |
97 | rxvt_img::~rxvt_img () |
239 | rxvt_img::~rxvt_img () |
98 | { |
240 | { |
99 | destroy (); |
241 | destroy (); |
… | |
… | |
101 | |
243 | |
102 | void |
244 | void |
103 | rxvt_img::alloc () |
245 | rxvt_img::alloc () |
104 | { |
246 | { |
105 | pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
247 | pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
106 | refcnt = new int (1); |
248 | ref = new pixref (w, h); |
|
|
249 | } |
|
|
250 | |
|
|
251 | Picture |
|
|
252 | rxvt_img::picture () |
|
|
253 | { |
|
|
254 | Display *dpy = s->display->dpy; |
|
|
255 | |
|
|
256 | XRenderPictureAttributes pa; |
|
|
257 | pa.repeat = repeat; |
|
|
258 | Picture pic = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
|
|
259 | |
|
|
260 | return pic; |
107 | } |
261 | } |
108 | |
262 | |
109 | void |
263 | void |
110 | rxvt_img::unshare () |
264 | rxvt_img::unshare () |
111 | { |
265 | { |
112 | if (refcnt && *refcnt == 1) |
266 | if (ref->cnt == 1 && ref->ours) |
113 | return; |
267 | return; |
114 | |
268 | |
115 | Pixmap pm2 = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
269 | Pixmap pm2 = XCreatePixmap (s->display->dpy, s->display->root, ref->w, ref->h, format->depth); |
116 | GC gc = XCreateGC (s->display->dpy, pm, 0, 0); |
270 | GC gc = XCreateGC (s->display->dpy, pm, 0, 0); |
117 | XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, w, h, 0, 0); |
271 | XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, ref->w, ref->h, 0, 0); |
118 | XFreeGC (s->display->dpy, gc); |
272 | XFreeGC (s->display->dpy, gc); |
119 | |
273 | |
120 | destroy (); |
274 | destroy (); |
121 | |
275 | |
122 | pm = pm2; |
276 | pm = pm2; |
123 | refcnt = new int (1); |
277 | ref = new pixref (ref->w, ref->h); |
124 | } |
278 | } |
125 | |
279 | |
126 | void |
280 | void |
127 | rxvt_img::fill (const rxvt_color &c) |
281 | rxvt_img::fill (const rgba &c) |
128 | { |
282 | { |
129 | XGCValues gcv; |
283 | XRenderColor rc = { c.r, c.g, c.b, c.a }; |
130 | gcv.foreground = c; |
284 | |
131 | GC gc = XCreateGC (s->display->dpy, pm, GCForeground, &gcv); |
285 | Display *dpy = s->display->dpy; |
132 | XFillRectangle (s->display->dpy, pm, gc, 0, 0, w, h); |
286 | Picture src = picture (); |
133 | XFreeGC (s->display->dpy, gc); |
287 | XRenderFillRectangle (dpy, PictOpSrc, src, &rc, 0, 0, w, h); |
|
|
288 | XRenderFreePicture (dpy, src); |
|
|
289 | } |
|
|
290 | |
|
|
291 | void |
|
|
292 | rxvt_img::add_alpha () |
|
|
293 | { |
|
|
294 | if (format->direct.alphaMask) |
|
|
295 | return; |
|
|
296 | |
|
|
297 | Display *dpy = s->display->dpy; |
|
|
298 | |
|
|
299 | rxvt_img *img = new rxvt_img (s, find_alpha_format_for (dpy, format), x, y, w, h, repeat); |
|
|
300 | img->alloc (); |
|
|
301 | |
|
|
302 | Picture src = picture (); |
|
|
303 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
|
|
304 | |
|
|
305 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
|
|
306 | |
|
|
307 | XRenderFreePicture (dpy, src); |
|
|
308 | XRenderFreePicture (dpy, dst); |
|
|
309 | |
|
|
310 | ::swap (img->ref, ref); |
|
|
311 | ::swap (img->pm , pm ); |
|
|
312 | |
|
|
313 | delete img; |
134 | } |
314 | } |
135 | |
315 | |
136 | static void |
316 | static void |
137 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
317 | get_gaussian_kernel (int radius, int width, rxvt_img::nv *kernel, XFixed *params) |
138 | { |
318 | { |
139 | double sigma = radius / 2.0; |
319 | rxvt_img::nv sigma = radius / 2.0; |
140 | double scale = sqrt (2.0 * M_PI) * sigma; |
320 | rxvt_img::nv scale = sqrt (2.0 * M_PI) * sigma; |
141 | double sum = 0.0; |
321 | rxvt_img::nv sum = 0.0; |
142 | |
322 | |
143 | for (int i = 0; i < width; i++) |
323 | for (int i = 0; i < width; i++) |
144 | { |
324 | { |
145 | double x = i - width / 2; |
325 | rxvt_img::nv x = i - width / 2; |
146 | kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; |
326 | kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; |
147 | sum += kernel[i]; |
327 | sum += kernel[i]; |
148 | } |
328 | } |
149 | |
329 | |
150 | params[0] = XDoubleToFixed (width); |
330 | params[0] = XDoubleToFixed (width); |
… | |
… | |
160 | if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV)) |
340 | if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV)) |
161 | return clone (); |
341 | return clone (); |
162 | |
342 | |
163 | Display *dpy = s->display->dpy; |
343 | Display *dpy = s->display->dpy; |
164 | int size = max (rh, rv) * 2 + 1; |
344 | int size = max (rh, rv) * 2 + 1; |
165 | double *kernel = (double *)malloc (size * sizeof (double)); |
345 | nv *kernel = (nv *)malloc (size * sizeof (nv)); |
166 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
346 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
167 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h); |
347 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); |
168 | img->alloc (); |
348 | img->alloc (); |
169 | |
349 | |
170 | XRenderPictureAttributes pa; |
350 | XRenderPictureAttributes pa; |
171 | |
|
|
172 | pa.repeat = RepeatPad; |
351 | pa.repeat = RepeatPad; |
173 | Picture src = XRenderCreatePicture (dpy, pm , format, CPRepeat, &pa); |
352 | Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
174 | Picture dst = XRenderCreatePicture (dpy, img->pm, format, CPRepeat, &pa); |
353 | Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0); |
175 | |
354 | |
176 | Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth); |
355 | Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth); |
177 | Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa); |
356 | Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa); |
178 | XFreePixmap (dpy, tmp_pm); |
357 | XFreePixmap (dpy, tmp_pm); |
179 | |
358 | |
… | |
… | |
195 | |
374 | |
196 | size = rv * 2 + 1; |
375 | size = rv * 2 + 1; |
197 | get_gaussian_kernel (rv, size, kernel, params); |
376 | get_gaussian_kernel (rv, size, kernel, params); |
198 | ::swap (params[0], params[1]); |
377 | ::swap (params[0], params[1]); |
199 | |
378 | |
200 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
379 | XRenderSetPictureFilter (dpy, tmp, FilterConvolution, params, size+2); |
201 | XRenderComposite (dpy, |
380 | XRenderComposite (dpy, |
202 | PictOpSrc, |
381 | PictOpSrc, |
203 | tmp, |
382 | tmp, |
204 | None, |
383 | None, |
205 | dst, |
384 | dst, |
… | |
… | |
209 | w, h); |
388 | w, h); |
210 | } |
389 | } |
211 | |
390 | |
212 | free (kernel); |
391 | free (kernel); |
213 | free (params); |
392 | free (params); |
|
|
393 | |
214 | XRenderFreePicture (dpy, src); |
394 | XRenderFreePicture (dpy, src); |
215 | XRenderFreePicture (dpy, dst); |
395 | XRenderFreePicture (dpy, dst); |
216 | XRenderFreePicture (dpy, tmp); |
396 | XRenderFreePicture (dpy, tmp); |
217 | |
397 | |
218 | return img; |
398 | return img; |
219 | } |
399 | } |
220 | |
400 | |
221 | static Picture |
401 | static Picture |
222 | create_xrender_mask (Display *dpy, Drawable drawable, Bool argb) |
402 | create_xrender_mask (Display *dpy, Drawable drawable, Bool argb, Bool component_alpha) |
223 | { |
403 | { |
224 | Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8); |
404 | Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8); |
225 | |
405 | |
226 | XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8); |
406 | XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8); |
227 | XRenderPictureAttributes pa; |
407 | XRenderPictureAttributes pa; |
228 | pa.repeat = True; |
408 | pa.repeat = RepeatNormal; |
|
|
409 | pa.component_alpha = component_alpha; |
229 | Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); |
410 | Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat | CPComponentAlpha, &pa); |
230 | |
411 | |
231 | XFreePixmap (dpy, pixmap); |
412 | XFreePixmap (dpy, pixmap); |
232 | |
413 | |
233 | return mask; |
414 | return mask; |
234 | } |
415 | } |
235 | |
416 | |
|
|
417 | static void |
|
|
418 | extract (int32_t cl0, int32_t cl1, int32_t &c, unsigned short &xc) |
|
|
419 | { |
|
|
420 | int32_t x = clamp (c, cl0, cl1); |
|
|
421 | c -= x; |
|
|
422 | xc = x; |
|
|
423 | } |
|
|
424 | |
|
|
425 | static bool |
|
|
426 | extract (int32_t cl0, int32_t cl1, int32_t &r, int32_t &g, int32_t &b, int32_t &a, unsigned short &xr, unsigned short &xg, unsigned short &xb, unsigned short &xa) |
|
|
427 | { |
|
|
428 | extract (cl0, cl1, r, xr); |
|
|
429 | extract (cl0, cl1, g, xg); |
|
|
430 | extract (cl0, cl1, b, xb); |
|
|
431 | extract (cl0, cl1, a, xa); |
|
|
432 | |
|
|
433 | return xr | xg | xb | xa; |
|
|
434 | } |
|
|
435 | |
236 | void |
436 | void |
237 | rxvt_img::brightness (unsigned short r, unsigned short g, unsigned short b, unsigned short a) |
437 | rxvt_img::brightness (int32_t r, int32_t g, int32_t b, int32_t a) |
238 | { |
438 | { |
|
|
439 | unshare (); |
|
|
440 | |
239 | Display *dpy = s->display->dpy; |
441 | Display *dpy = s->display->dpy; |
240 | Picture src = create_xrender_mask (dpy, pm, True); |
|
|
241 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
442 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
242 | |
443 | |
|
|
444 | // loop should not be needed for brightness, as only -1..1 makes sense |
|
|
445 | //while (r | g | b | a) |
|
|
446 | { |
|
|
447 | unsigned short xr, xg, xb, xa; |
243 | XRenderColor mask_c; |
448 | XRenderColor mask_c; |
244 | mask_c.red = r; |
449 | |
245 | mask_c.green = g; |
450 | if (extract (0, 65535, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha)) |
246 | mask_c.blue = b; |
|
|
247 | mask_c.alpha = a; |
|
|
248 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
451 | XRenderFillRectangle (dpy, PictOpAdd, dst, &mask_c, 0, 0, w, h); |
249 | |
452 | |
250 | XRenderComposite (dpy, PictOpAdd, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
453 | if (extract (-65535, 0, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha)) |
|
|
454 | { |
|
|
455 | XRenderColor mask_w = { 65535, 65535, 65535, 65535 }; |
|
|
456 | XRenderFillRectangle (dpy, PictOpDifference, dst, &mask_w, 0, 0, w, h); |
|
|
457 | mask_c.red = -mask_c.red; //TODO: verify that doing clamp, assign, and negation does the right thing |
|
|
458 | mask_c.green = -mask_c.green; |
|
|
459 | mask_c.blue = -mask_c.blue; |
|
|
460 | mask_c.alpha = -mask_c.alpha; |
|
|
461 | XRenderFillRectangle (dpy, PictOpAdd, dst, &mask_c, 0, 0, w, h); |
|
|
462 | XRenderFillRectangle (dpy, PictOpDifference, dst, &mask_w, 0, 0, w, h); |
|
|
463 | } |
|
|
464 | } |
251 | |
465 | |
252 | XRenderFreePicture (dpy, src); |
|
|
253 | XRenderFreePicture (dpy, dst); |
466 | XRenderFreePicture (dpy, dst); |
254 | } |
467 | } |
255 | |
468 | |
256 | void |
469 | void |
257 | rxvt_img::contrast (unsigned short r, unsigned short g, unsigned short b, unsigned short a) |
470 | rxvt_img::contrast (int32_t r, int32_t g, int32_t b, int32_t a) |
258 | { |
471 | { |
259 | if (!(s->display->flags & DISPLAY_HAS_RENDER_MUL)) |
472 | if (r < 0 || g < 0 || b < 0 || a < 0) |
260 | return; |
473 | rxvt_fatal ("rxvt_img::contrast does not support negative values.\n"); |
261 | |
474 | |
|
|
475 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); |
|
|
476 | img->alloc (); |
|
|
477 | img->fill (rgba (0, 0, 0, 0)); |
|
|
478 | |
|
|
479 | // premultiply (yeah, these are not exact, sue me or fix it) |
|
|
480 | r = (r * (a >> 8)) >> 8; |
|
|
481 | g = (g * (a >> 8)) >> 8; |
|
|
482 | b = (b * (a >> 8)) >> 8; |
|
|
483 | |
262 | Display *dpy = s->display->dpy; |
484 | Display *dpy = s->display->dpy; |
263 | Picture src = create_xrender_mask (dpy, pm, True); |
485 | |
|
|
486 | Picture src = picture (); |
264 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
487 | Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0); |
|
|
488 | Picture mul = create_xrender_mask (dpy, pm, True, True); |
265 | |
489 | |
|
|
490 | //TODO: this operator does not yet implement some useful contrast |
|
|
491 | while (r | g | b | a) |
|
|
492 | { |
|
|
493 | unsigned short xr, xg, xb, xa; |
266 | XRenderColor mask_c; |
494 | XRenderColor mask_c; |
267 | mask_c.red = r; |
|
|
268 | mask_c.green = g; |
|
|
269 | mask_c.blue = b; |
|
|
270 | mask_c.alpha = a; |
|
|
271 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
|
|
272 | |
495 | |
273 | XRenderComposite (dpy, PictOpMultiply, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
496 | if (extract (0, 65535, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha)) |
274 | |
|
|
275 | XRenderFreePicture (dpy, src); |
|
|
276 | XRenderFreePicture (dpy, dst); |
|
|
277 | } |
|
|
278 | |
|
|
279 | bool |
|
|
280 | rxvt_img::render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y) |
|
|
281 | { |
|
|
282 | Display *dpy = s->display->dpy; |
|
|
283 | |
|
|
284 | if (s->visual->c_class != TrueColor) |
|
|
285 | return false; |
|
|
286 | |
|
|
287 | uint32_t red_mask, green_mask, blue_mask, alpha_mask; |
|
|
288 | |
|
|
289 | red_mask = (uint32_t)format->direct.redMask << format->direct.red; |
|
|
290 | green_mask = (uint32_t)format->direct.greenMask << format->direct.green; |
|
|
291 | blue_mask = (uint32_t)format->direct.blueMask << format->direct.blue; |
|
|
292 | alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha; |
|
|
293 | |
|
|
294 | int width_r = ecb_popcount32 (red_mask); |
|
|
295 | int width_g = ecb_popcount32 (green_mask); |
|
|
296 | int width_b = ecb_popcount32 (blue_mask); |
|
|
297 | int width_a = ecb_popcount32 (alpha_mask); |
|
|
298 | |
|
|
299 | if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8) |
|
|
300 | return false; |
|
|
301 | |
|
|
302 | int sh_r = ecb_ctz32 (red_mask); |
|
|
303 | int sh_g = ecb_ctz32 (green_mask); |
|
|
304 | int sh_b = ecb_ctz32 (blue_mask); |
|
|
305 | int sh_a = ecb_ctz32 (alpha_mask); |
|
|
306 | |
|
|
307 | if (width > 32767 || height > 32767) |
|
|
308 | return false; |
|
|
309 | |
|
|
310 | XImage *ximage = XCreateImage (dpy, s->visual, format->depth, ZPixmap, 0, 0, |
|
|
311 | width, height, 32, 0); |
|
|
312 | if (!ximage) |
|
|
313 | return false; |
|
|
314 | |
|
|
315 | if (height > INT_MAX / ximage->bytes_per_line |
|
|
316 | || !(ximage->data = (char *)malloc (height * ximage->bytes_per_line))) |
|
|
317 | { |
|
|
318 | XDestroyImage (ximage); |
|
|
319 | return false; |
|
|
320 | } |
|
|
321 | |
|
|
322 | GC gc = XCreateGC (dpy, pm, 0, 0); |
|
|
323 | |
|
|
324 | ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
|
|
325 | |
|
|
326 | int rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
|
|
327 | int channels = gdk_pixbuf_get_n_channels (pixbuf); |
|
|
328 | unsigned char *row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; |
|
|
329 | char *line = ximage->data; |
|
|
330 | |
|
|
331 | for (int y = 0; y < height; y++) |
|
|
332 | { |
|
|
333 | for (int x = 0; x < width; x++) |
|
|
334 | { |
497 | { |
335 | unsigned char *pixel = row + x * channels; |
498 | XRenderFillRectangle (dpy, PictOpSrc, mul, &mask_c, 0, 0, 1, 1); |
336 | uint32_t value; |
499 | XRenderComposite (dpy, PictOpAdd, src, mul, dst, 0, 0, 0, 0, 0, 0, w, h); |
337 | unsigned char r, g, b, a; |
|
|
338 | |
|
|
339 | if (channels == 4) |
|
|
340 | { |
|
|
341 | a = pixel[3]; |
|
|
342 | r = pixel[0] * a / 0xff; |
|
|
343 | g = pixel[1] * a / 0xff; |
|
|
344 | b = pixel[2] * a / 0xff; |
|
|
345 | } |
|
|
346 | else |
|
|
347 | { |
|
|
348 | a = 0xff; |
|
|
349 | r = pixel[0]; |
|
|
350 | g = pixel[1]; |
|
|
351 | b = pixel[2]; |
|
|
352 | } |
|
|
353 | |
|
|
354 | value = ((r >> (8 - width_r)) << sh_r) |
|
|
355 | | ((g >> (8 - width_g)) << sh_g) |
|
|
356 | | ((b >> (8 - width_b)) << sh_b) |
|
|
357 | | ((a >> (8 - width_a)) << sh_a); |
|
|
358 | |
|
|
359 | if (ximage->bits_per_pixel == 32) |
|
|
360 | ((uint32_t *)line)[x] = value; |
|
|
361 | else |
|
|
362 | XPutPixel (ximage, x, y, value); |
|
|
363 | } |
500 | } |
|
|
501 | } |
364 | |
502 | |
365 | row += rowstride; |
503 | XRenderFreePicture (dpy, mul); |
366 | line += ximage->bytes_per_line; |
504 | XRenderFreePicture (dpy, dst); |
|
|
505 | XRenderFreePicture (dpy, src); |
|
|
506 | |
|
|
507 | ::swap (img->ref, ref); |
|
|
508 | ::swap (img->pm , pm ); |
|
|
509 | |
|
|
510 | delete img; |
|
|
511 | } |
|
|
512 | |
|
|
513 | void |
|
|
514 | rxvt_img::draw (rxvt_img *img, int op, nv mask) |
|
|
515 | { |
|
|
516 | unshare (); |
|
|
517 | |
|
|
518 | Display *dpy = s->display->dpy; |
|
|
519 | Picture src = img->picture (); |
|
|
520 | Picture dst = picture (); |
|
|
521 | Picture mask_p = 0; |
|
|
522 | |
|
|
523 | if (mask != 1.) |
367 | } |
524 | { |
|
|
525 | mask_p = create_xrender_mask (dpy, img->pm, False, False); |
|
|
526 | XRenderColor mask_c = { 0, 0, 0, float_to_component (mask) }; |
|
|
527 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
|
|
528 | } |
368 | |
529 | |
369 | XPutImage (dpy, pm, gc, ximage, 0, 0, dst_x, dst_y, width, height); |
530 | XRenderComposite (dpy, op, src, mask_p, dst, x - img->x, y - img->y, 0, 0, 0, 0, w, h); |
370 | XDestroyImage (ximage); |
|
|
371 | XFreeGC (dpy, gc); |
|
|
372 | |
531 | |
373 | return true; |
532 | XRenderFreePicture (dpy, src); |
|
|
533 | XRenderFreePicture (dpy, dst); |
|
|
534 | |
|
|
535 | if (mask_p) |
|
|
536 | XRenderFreePicture (dpy, mask_p); |
374 | } |
537 | } |
375 | |
538 | |
376 | rxvt_img * |
539 | rxvt_img * |
377 | rxvt_img::clone () |
540 | rxvt_img::clone () |
378 | { |
541 | { |
… | |
… | |
380 | } |
543 | } |
381 | |
544 | |
382 | rxvt_img * |
545 | rxvt_img * |
383 | rxvt_img::reify () |
546 | rxvt_img::reify () |
384 | { |
547 | { |
385 | rxvt_img *img = new rxvt_img (s, format, 0, 0, w, h); |
548 | if (x == 0 && y == 0 && w == ref->w && h == ref->h) |
|
|
549 | return clone (); |
|
|
550 | |
|
|
551 | Display *dpy = s->display->dpy; |
|
|
552 | |
|
|
553 | // add an alpha channel if... |
|
|
554 | bool alpha = !format->direct.alphaMask // pixmap has none yet |
|
|
555 | && (x || y) // we need one because of non-zero offset |
|
|
556 | && repeat == RepeatNone; // and we have no good pixels to fill with |
|
|
557 | |
|
|
558 | rxvt_img *img = new rxvt_img (s, alpha ? find_alpha_format_for (dpy, format) : format, 0, 0, w, h, repeat); |
386 | img->alloc (); |
559 | img->alloc (); |
387 | |
560 | |
388 | // todo, if x==0 and y==0 and w==real width we could clone |
561 | Picture src = picture (); |
389 | // but that involves an rtt to find pixmap width. |
|
|
390 | |
|
|
391 | Display *dpy = s->display->dpy; |
|
|
392 | XRenderPictureAttributes pa; |
|
|
393 | pa.repeat = repeat; |
|
|
394 | Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
|
|
395 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
562 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
396 | |
563 | |
|
|
564 | if (alpha) |
|
|
565 | { |
|
|
566 | XRenderColor rc = { 0, 0, 0, 0 }; |
|
|
567 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);//TODO: split into four fillrectangles |
|
|
568 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, x, y, ref->w, ref->h); |
|
|
569 | } |
|
|
570 | else |
397 | XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h); |
571 | XRenderComposite (dpy, PictOpSrc, src, None, dst, -x, -y, 0, 0, 0, 0, w, h); |
398 | |
572 | |
399 | XRenderFreePicture (dpy, src); |
573 | XRenderFreePicture (dpy, src); |
400 | XRenderFreePicture (dpy, dst); |
574 | XRenderFreePicture (dpy, dst); |
401 | |
575 | |
402 | return img; |
576 | return img; |
403 | } |
577 | } |
… | |
… | |
405 | rxvt_img * |
579 | rxvt_img * |
406 | rxvt_img::sub_rect (int x, int y, int width, int height) |
580 | rxvt_img::sub_rect (int x, int y, int width, int height) |
407 | { |
581 | { |
408 | rxvt_img *img = clone (); |
582 | rxvt_img *img = clone (); |
409 | |
583 | |
410 | img->x += x; |
584 | img->x -= x; |
411 | img->y += y; |
585 | img->y -= y; |
|
|
586 | |
|
|
587 | if (w != width || h != height) |
|
|
588 | { |
412 | img->w = width; |
589 | img->w = width; |
413 | img->h = height; |
590 | img->h = height; |
414 | |
591 | |
415 | return img; |
592 | rxvt_img *img2 = img->reify (); |
416 | } |
593 | delete img; |
|
|
594 | img = img2; |
|
|
595 | } |
417 | |
596 | |
418 | rxvt_img * |
597 | return img; |
419 | rxvt_img::transform (int new_width, int new_height, double matrix[9]) |
598 | } |
|
|
599 | |
|
|
600 | static void |
|
|
601 | mat_invert (rxvt_img::nv mat[3][3], rxvt_img::nv (&inv)[3][3]) |
420 | { |
602 | { |
|
|
603 | rxvt_img::nv s0 = mat [2][2] * mat [1][1] - mat [2][1] * mat [1][2]; |
|
|
604 | rxvt_img::nv s1 = mat [2][1] * mat [0][2] - mat [2][2] * mat [0][1]; |
|
|
605 | rxvt_img::nv s2 = mat [1][2] * mat [0][1] - mat [1][1] * mat [0][2]; |
|
|
606 | |
|
|
607 | rxvt_img::nv invdet = 1. / (mat [0][0] * s0 + mat [1][0] * s1 + mat [2][0] * s2); |
|
|
608 | |
|
|
609 | inv [0][0] = invdet * s0; |
|
|
610 | inv [0][1] = invdet * s1; |
|
|
611 | inv [0][2] = invdet * s2; |
|
|
612 | |
|
|
613 | inv [1][0] = invdet * (mat [2][0] * mat [1][2] - mat [2][2] * mat [1][0]); |
|
|
614 | inv [1][1] = invdet * (mat [2][2] * mat [0][0] - mat [2][0] * mat [0][2]); |
|
|
615 | inv [1][2] = invdet * (mat [1][0] * mat [0][2] - mat [1][2] * mat [0][0]); |
|
|
616 | |
|
|
617 | inv [2][0] = invdet * (mat [2][1] * mat [1][0] - mat [2][0] * mat [1][1]); |
|
|
618 | inv [2][1] = invdet * (mat [2][0] * mat [0][1] - mat [2][1] * mat [0][0]); |
|
|
619 | inv [2][2] = invdet * (mat [1][1] * mat [0][0] - mat [1][0] * mat [0][1]); |
|
|
620 | } |
|
|
621 | |
|
|
622 | static rxvt_img::nv |
|
|
623 | mat_apply (rxvt_img::nv mat[3][3], int i, rxvt_img::nv x, rxvt_img::nv y) |
|
|
624 | { |
|
|
625 | rxvt_img::nv v = mat [i][0] * x + mat [i][1] * y + mat [i][2]; |
|
|
626 | rxvt_img::nv w = mat [2][0] * x + mat [2][1] * y + mat [2][2]; |
|
|
627 | |
|
|
628 | return v * (1. / w); |
|
|
629 | } |
|
|
630 | |
|
|
631 | rxvt_img * |
|
|
632 | rxvt_img::transform (nv matrix[3][3]) |
|
|
633 | { |
|
|
634 | // calculate new pixel bounding box coordinates |
|
|
635 | nv rmin[2], rmax[2]; |
|
|
636 | |
|
|
637 | for (int i = 0; i < 2; ++i) |
|
|
638 | { |
|
|
639 | nv v; |
|
|
640 | |
|
|
641 | v = mat_apply (matrix, i, 0+x, 0+y); rmin [i] = rmax [i] = v; |
|
|
642 | v = mat_apply (matrix, i, w+x, 0+y); min_it (rmin [i], v); max_it (rmax [i], v); |
|
|
643 | v = mat_apply (matrix, i, 0+x, h+y); min_it (rmin [i], v); max_it (rmax [i], v); |
|
|
644 | v = mat_apply (matrix, i, w+x, h+y); min_it (rmin [i], v); max_it (rmax [i], v); |
|
|
645 | } |
|
|
646 | |
|
|
647 | // TODO: adjust matrix for subpixel accuracy |
|
|
648 | int dx = floor (rmin [0]); |
|
|
649 | int dy = floor (rmin [1]); |
|
|
650 | |
|
|
651 | int new_width = ceil (rmax [0] - dx); |
|
|
652 | int new_height = ceil (rmax [1] - dy); |
|
|
653 | |
|
|
654 | nv inv[3][3]; |
|
|
655 | mat_invert (matrix, inv); |
|
|
656 | |
421 | rxvt_img *img = new rxvt_img (s, format, 0, 0, new_width, new_height); |
657 | rxvt_img *img = new rxvt_img (s, format, dx, dy, new_width, new_height, repeat); |
422 | img->alloc (); |
658 | img->alloc (); |
423 | |
659 | |
424 | Display *dpy = s->display->dpy; |
660 | Display *dpy = s->display->dpy; |
425 | XRenderPictureAttributes pa; |
661 | Picture src = picture (); |
426 | pa.repeat = repeat; |
|
|
427 | Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
|
|
428 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
662 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
429 | |
663 | |
430 | XTransform xfrm; |
664 | XTransform xfrm; |
431 | |
665 | |
432 | for (int i = 0; i < 3; ++i) |
666 | for (int i = 0; i < 3; ++i) |
433 | for (int j = 0; j < 3; ++j) |
667 | for (int j = 0; j < 3; ++j) |
434 | xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); |
668 | xfrm.matrix [i][j] = XDoubleToFixed (inv [i][j]); |
435 | |
|
|
436 | xfrm.matrix [0][2] += XDoubleToFixed (x);//TODO |
|
|
437 | xfrm.matrix [0][3] += XDoubleToFixed (y); |
|
|
438 | |
669 | |
439 | XRenderSetPictureFilter (dpy, src, "good", 0, 0); |
670 | XRenderSetPictureFilter (dpy, src, "good", 0, 0); |
440 | XRenderSetPictureTransform (dpy, src, &xfrm); |
671 | XRenderSetPictureTransform (dpy, src, &xfrm); |
441 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height); |
672 | XRenderComposite (dpy, PictOpSrc, src, None, dst, dx, dy, 0, 0, 0, 0, new_width, new_height); |
442 | |
673 | |
443 | XRenderFreePicture (dpy, src); |
674 | XRenderFreePicture (dpy, src); |
444 | XRenderFreePicture (dpy, dst); |
675 | XRenderFreePicture (dpy, dst); |
445 | |
676 | |
446 | return img; |
677 | return img; |
447 | } |
678 | } |
448 | |
679 | |
449 | rxvt_img * |
680 | rxvt_img * |
450 | rxvt_img::scale (int new_width, int new_height) |
681 | rxvt_img::scale (int new_width, int new_height) |
451 | { |
682 | { |
452 | double matrix[9] = { |
683 | if (w == new_width && h == new_height) |
453 | w / (double)new_width, 0, 0, |
684 | return clone (); |
454 | 0, h / (double)new_height, 0, |
685 | |
|
|
686 | nv matrix[3][3] = { |
|
|
687 | { new_width / (nv)w, 0, 0 }, |
|
|
688 | { 0, new_height / (nv)h, 0 }, |
455 | 0, 0, 1 |
689 | { 0, 0, 1 } |
456 | }; |
690 | }; |
457 | |
691 | |
458 | return transform (new_width, new_height, matrix); |
692 | int old_repeat_mode = repeat; |
459 | } |
693 | repeat = RepeatPad; // not right, but xrender can't properly scale it seems |
460 | |
694 | |
|
|
695 | rxvt_img *img = transform (matrix); |
|
|
696 | |
|
|
697 | repeat = old_repeat_mode; |
|
|
698 | img->repeat = repeat; |
|
|
699 | |
|
|
700 | return img; |
|
|
701 | } |
|
|
702 | |
461 | rxvt_img * |
703 | rxvt_img * |
462 | rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi) |
704 | rxvt_img::rotate (int cx, int cy, nv phi) |
463 | { |
705 | { |
464 | double s = sin (phi); |
706 | nv s = sin (phi); |
465 | double c = cos (phi); |
707 | nv c = cos (phi); |
466 | |
708 | |
467 | double matrix[9] = { |
709 | nv matrix[3][3] = { |
468 | c, -s, -c * x + s * y + x, |
710 | { c, -s, cx - c * cx + s * cy + 200 }, |
469 | s, c, -s * x - c * y + y, |
711 | { s, c, cy - s * cx - c * cy }, |
470 | 0, 0, 1 |
712 | { 0, 0, 1 } |
|
|
713 | //{ c, -s, 0 }, |
|
|
714 | //{ s, c, 0 }, |
|
|
715 | //{ 0, 0, 1 } |
471 | }; |
716 | }; |
472 | |
717 | |
473 | return transform (new_width, new_height, matrix); |
718 | //move (-cx, -cy); |
474 | } |
719 | rxvt_img *img = transform (matrix); |
|
|
720 | //move ( cx, cy); |
|
|
721 | //img->move (cx, cy); |
475 | |
722 | |
|
|
723 | return img; |
|
|
724 | } |
|
|
725 | |
476 | rxvt_img * |
726 | rxvt_img * |
477 | rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) |
727 | rxvt_img::convert_format (XRenderPictFormat *new_format, const rgba &bg) |
478 | { |
728 | { |
479 | if (new_format == format) |
729 | if (new_format == format) |
480 | return clone (); |
730 | return clone (); |
481 | |
731 | |
482 | rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h); |
732 | rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h, repeat); |
483 | img->alloc (); |
733 | img->alloc (); |
484 | |
734 | |
485 | Display *dpy = s->display->dpy; |
735 | Display *dpy = s->display->dpy; |
486 | Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0); |
736 | Picture src = picture (); |
487 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
737 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
488 | int op = PictOpSrc; |
738 | int op = PictOpSrc; |
489 | |
739 | |
490 | if (format->direct.alphaMask && !new_format->direct.alphaMask) |
740 | if (format->direct.alphaMask && !new_format->direct.alphaMask) |
491 | { |
741 | { |
492 | // does it have to be that complicated |
742 | // does it have to be that complicated |
493 | rgba c; |
|
|
494 | bg.get (c); |
|
|
495 | |
|
|
496 | XRenderColor rc = { c.r, c.g, c.b, 0xffff }; |
743 | XRenderColor rc = { bg.r, bg.g, bg.b, bg.a }; |
497 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h); |
744 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h); |
498 | |
745 | |
499 | op = PictOpOver; |
746 | op = PictOpOver; |
500 | } |
747 | } |
501 | |
748 | |
… | |
… | |
506 | |
753 | |
507 | return img; |
754 | return img; |
508 | } |
755 | } |
509 | |
756 | |
510 | rxvt_img * |
757 | rxvt_img * |
511 | rxvt_img::blend (rxvt_img *img, double factor) |
758 | rxvt_img::blend (rxvt_img *img, nv factor) |
512 | { |
759 | { |
513 | rxvt_img *img2 = clone (); |
760 | rxvt_img *img2 = clone (); |
514 | Display *dpy = s->display->dpy; |
761 | Display *dpy = s->display->dpy; |
515 | Picture src = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
762 | Picture src = img->picture (); |
516 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
763 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
517 | Picture mask = create_xrender_mask (dpy, img->pm, False); |
764 | Picture mask = create_xrender_mask (dpy, img->pm, False, False); |
518 | |
765 | |
519 | XRenderColor mask_c; |
766 | XRenderColor mask_c; |
520 | |
767 | |
521 | mask_c.alpha = float_to_component (factor); |
768 | mask_c.alpha = float_to_component (factor); |
522 | mask_c.red = |
769 | mask_c.red = |