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