|
|
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 = LSBFirst; // maybe go for host byte order, because servers are usually local? |
223 | xi.byte_order = ImageByteOrder (dpy); |
83 | xi.bitmap_unit = 32; //XY only, unused |
224 | xi.bitmap_unit = 0; //XY only, unused |
84 | xi.bitmap_bit_order = LSBFirst; //XY only, unused |
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; //Z only |
229 | xi.bits_per_pixel = 32; //Z only |
89 | xi.red_mask = 0x000000ff; //Z only |
230 | xi.red_mask = 0x00000000; //Z only, unused |
90 | xi.green_mask = 0x0000ff00; //Z only |
231 | xi.green_mask = 0x00000000; //Z only, unused |
91 | xi.blue_mask = 0x00ff0000; //Z only |
232 | xi.blue_mask = 0x00000000; //Z only, unused |
92 | xi.obdata = 0; // probbaly unused |
233 | xi.obdata = 0; // probably unused |
|
|
234 | |
|
|
235 | bool byte_order_mismatch = byte_order != xi.byte_order; |
93 | |
236 | |
94 | if (!XInitImage (&xi)) |
237 | if (!XInitImage (&xi)) |
95 | rxvt_fatal ("unable to initialise ximage, please report.\n"); |
238 | rxvt_fatal ("unable to initialise ximage, please report.\n"); |
96 | |
239 | |
97 | if (height > INT_MAX / xi.bytes_per_line) |
240 | if (height > INT_MAX / xi.bytes_per_line) |
98 | 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"); |
99 | |
242 | |
100 | xi.data = (char *)rxvt_malloc (height * xi.bytes_per_line); |
243 | xi.data = (char *)rxvt_malloc (height * xi.bytes_per_line); |
101 | |
244 | |
102 | int rowstride = gdk_pixbuf_get_rowstride (pb); |
245 | int rowstride = gdk_pixbuf_get_rowstride (pb); |
103 | |
246 | bool pb_has_alpha = gdk_pixbuf_get_has_alpha (pb); |
104 | assert (3 + (depth == 32) == gdk_pixbuf_get_n_channels (pb)); |
|
|
105 | unsigned char *row = gdk_pixbuf_get_pixels (pb); |
247 | unsigned char *row = gdk_pixbuf_get_pixels (pb); |
|
|
248 | |
106 | char *line = xi.data; |
249 | char *line = xi.data; |
107 | |
250 | |
108 | for (int y = 0; y < height; y++) |
251 | for (int y = 0; y < height; y++) |
109 | { |
252 | { |
110 | unsigned char *src = row; |
253 | unsigned char *src = row; |
111 | uint32_t *dst = (uint32_t *)line; |
254 | uint32_t *dst = (uint32_t *)line; |
112 | |
255 | |
113 | if (depth == 24) |
256 | if (!pb_has_alpha) |
114 | for (int x = 0; x < width; x++) |
257 | for (int x = 0; x < width; x++) |
115 | { |
258 | { |
116 | uint8_t r = *src++; |
259 | uint8_t r = *src++; |
117 | uint8_t g = *src++; |
260 | uint8_t g = *src++; |
118 | uint8_t b = *src++; |
261 | uint8_t b = *src++; |
119 | |
262 | |
120 | uint32_t v = r | (g << 8) | (b << 16); |
263 | uint32_t v = (255 << 24) | (r << 16) | (g << 8) | b; |
121 | |
264 | |
122 | if (ecb_big_endian ()) |
265 | if (ecb_big_endian () ? !byte_order_mismatch : byte_order_mismatch) |
123 | v = ecb_bswap32 (v); |
266 | v = ecb_bswap32 (v); |
124 | |
267 | |
125 | *dst++ = v; |
268 | *dst++ = v; |
126 | } |
269 | } |
127 | else |
270 | else |
… | |
… | |
130 | uint32_t v = *(uint32_t *)src; src += 4; |
273 | uint32_t v = *(uint32_t *)src; src += 4; |
131 | |
274 | |
132 | if (ecb_big_endian ()) |
275 | if (ecb_big_endian ()) |
133 | v = ecb_bswap32 (v); |
276 | v = ecb_bswap32 (v); |
134 | |
277 | |
|
|
278 | v = ecb_rotl32 (v, 8); // abgr to bgra |
|
|
279 | |
|
|
280 | if (!byte_order_mismatch) |
|
|
281 | v = ecb_bswap32 (v); |
|
|
282 | |
135 | *dst++ = v; |
283 | *dst++ = v; |
136 | } |
284 | } |
137 | |
285 | |
138 | row += rowstride; |
286 | row += rowstride; |
139 | line += xi.bytes_per_line; |
287 | line += xi.bytes_per_line; |
140 | } |
288 | } |
141 | |
289 | |
142 | 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); |
143 | img->alloc (); |
291 | img->alloc (); |
144 | |
292 | |
145 | GC gc = XCreateGC (dpy, img->pm, 0, 0); |
293 | GC gc = XCreateGC (dpy, img->pm, 0, 0); |
146 | 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); |
147 | XFreeGC (dpy, gc); |
295 | XFreeGC (dpy, gc); |
… | |
… | |
165 | g_object_unref (pb); |
313 | g_object_unref (pb); |
166 | |
314 | |
167 | return img; |
315 | return img; |
168 | } |
316 | } |
169 | |
317 | |
|
|
318 | # endif |
|
|
319 | |
170 | void |
320 | void |
171 | rxvt_img::destroy () |
321 | rxvt_img::destroy () |
172 | { |
322 | { |
173 | if (--ref->cnt) |
323 | if (--ref->cnt) |
174 | return; |
324 | return; |
… | |
… | |
190 | 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); |
191 | ref = new pixref (w, h); |
341 | ref = new pixref (w, h); |
192 | } |
342 | } |
193 | |
343 | |
194 | Picture |
344 | Picture |
195 | rxvt_img::src_picture () |
345 | rxvt_img::picture () |
196 | { |
346 | { |
197 | Display *dpy = s->display->dpy; |
347 | Display *dpy = s->display->dpy; |
198 | |
348 | |
199 | XRenderPictureAttributes pa; |
349 | XRenderPictureAttributes pa; |
200 | pa.repeat = repeat; |
350 | pa.repeat = repeat; |
… | |
… | |
207 | rxvt_img::unshare () |
357 | rxvt_img::unshare () |
208 | { |
358 | { |
209 | if (ref->cnt == 1 && ref->ours) |
359 | if (ref->cnt == 1 && ref->ours) |
210 | return; |
360 | return; |
211 | |
361 | |
212 | //TODO: maybe should reify instead |
|
|
213 | 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); |
214 | GC gc = XCreateGC (s->display->dpy, pm, 0, 0); |
363 | GC gc = XCreateGC (s->display->dpy, pm, 0, 0); |
215 | 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); |
216 | XFreeGC (s->display->dpy, gc); |
365 | XFreeGC (s->display->dpy, gc); |
217 | |
366 | |
… | |
… | |
220 | pm = pm2; |
369 | pm = pm2; |
221 | ref = new pixref (ref->w, ref->h); |
370 | ref = new pixref (ref->w, ref->h); |
222 | } |
371 | } |
223 | |
372 | |
224 | void |
373 | void |
225 | rxvt_img::fill (const rxvt_color &c) |
374 | rxvt_img::fill (const rgba &c) |
226 | { |
375 | { |
227 | XGCValues gcv; |
376 | XRenderColor rc = { c.r, c.g, c.b, c.a }; |
228 | gcv.foreground = c; |
377 | |
229 | GC gc = XCreateGC (s->display->dpy, pm, GCForeground, &gcv); |
378 | Display *dpy = s->display->dpy; |
230 | XFillRectangle (s->display->dpy, pm, gc, 0, 0, w, h); |
379 | Picture src = picture (); |
231 | 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; |
232 | } |
407 | } |
233 | |
408 | |
234 | static void |
409 | static void |
235 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
410 | get_gaussian_kernel (int radius, int width, nv *kernel, XFixed *params) |
236 | { |
411 | { |
237 | double sigma = radius / 2.0; |
412 | nv sigma = radius / 2.0; |
238 | double scale = sqrt (2.0 * M_PI) * sigma; |
413 | nv scale = sqrt (2.0 * M_PI) * sigma; |
239 | double sum = 0.0; |
414 | nv sum = 0.0; |
240 | |
415 | |
241 | for (int i = 0; i < width; i++) |
416 | for (int i = 0; i < width; i++) |
242 | { |
417 | { |
243 | double x = i - width / 2; |
418 | nv x = i - width / 2; |
244 | kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; |
419 | kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; |
245 | sum += kernel[i]; |
420 | sum += kernel[i]; |
246 | } |
421 | } |
247 | |
422 | |
248 | params[0] = XDoubleToFixed (width); |
423 | params[0] = XDoubleToFixed (width); |
… | |
… | |
258 | if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV)) |
433 | if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV)) |
259 | return clone (); |
434 | return clone (); |
260 | |
435 | |
261 | Display *dpy = s->display->dpy; |
436 | Display *dpy = s->display->dpy; |
262 | int size = max (rh, rv) * 2 + 1; |
437 | int size = max (rh, rv) * 2 + 1; |
263 | double *kernel = (double *)malloc (size * sizeof (double)); |
438 | nv *kernel = (nv *)malloc (size * sizeof (nv)); |
264 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
439 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
265 | 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); |
266 | img->alloc (); |
441 | img->alloc (); |
267 | |
442 | |
268 | Picture src = src_picture (); |
|
|
269 | |
|
|
270 | XRenderPictureAttributes pa; |
443 | XRenderPictureAttributes pa; |
271 | pa.repeat = RepeatPad; |
444 | pa.repeat = RepeatPad; |
272 | 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); |
273 | |
447 | |
274 | Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth); |
448 | Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth); |
275 | Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa); |
449 | Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa); |
276 | XFreePixmap (dpy, tmp_pm); |
450 | XFreePixmap (dpy, tmp_pm); |
277 | |
451 | |
… | |
… | |
293 | |
467 | |
294 | size = rv * 2 + 1; |
468 | size = rv * 2 + 1; |
295 | get_gaussian_kernel (rv, size, kernel, params); |
469 | get_gaussian_kernel (rv, size, kernel, params); |
296 | ::swap (params[0], params[1]); |
470 | ::swap (params[0], params[1]); |
297 | |
471 | |
298 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
472 | XRenderSetPictureFilter (dpy, tmp, FilterConvolution, params, size+2); |
299 | XRenderComposite (dpy, |
473 | XRenderComposite (dpy, |
300 | PictOpSrc, |
474 | PictOpSrc, |
301 | tmp, |
475 | tmp, |
302 | None, |
476 | None, |
303 | dst, |
477 | dst, |
… | |
… | |
307 | w, h); |
481 | w, h); |
308 | } |
482 | } |
309 | |
483 | |
310 | free (kernel); |
484 | free (kernel); |
311 | free (params); |
485 | free (params); |
|
|
486 | |
312 | XRenderFreePicture (dpy, src); |
487 | XRenderFreePicture (dpy, src); |
313 | XRenderFreePicture (dpy, dst); |
488 | XRenderFreePicture (dpy, dst); |
314 | XRenderFreePicture (dpy, tmp); |
489 | XRenderFreePicture (dpy, tmp); |
315 | |
490 | |
316 | return img; |
491 | return img; |
317 | } |
492 | } |
318 | |
493 | |
319 | static Picture |
494 | static Picture |
320 | create_xrender_mask (Display *dpy, Drawable drawable, Bool argb) |
495 | create_xrender_mask (Display *dpy, Drawable drawable, Bool argb, Bool component_alpha) |
321 | { |
496 | { |
322 | Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8); |
497 | Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8); |
323 | |
498 | |
324 | XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8); |
499 | XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8); |
325 | XRenderPictureAttributes pa; |
500 | XRenderPictureAttributes pa; |
326 | pa.repeat = True; |
501 | pa.repeat = RepeatNormal; |
|
|
502 | pa.component_alpha = component_alpha; |
327 | Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); |
503 | Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat | CPComponentAlpha, &pa); |
328 | |
504 | |
329 | XFreePixmap (dpy, pixmap); |
505 | XFreePixmap (dpy, pixmap); |
330 | |
506 | |
331 | return mask; |
507 | return mask; |
332 | } |
508 | } |
333 | |
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 | |
334 | void |
529 | void |
335 | 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) |
336 | { |
531 | { |
|
|
532 | unshare (); |
|
|
533 | |
337 | Display *dpy = s->display->dpy; |
534 | Display *dpy = s->display->dpy; |
338 | Picture src = create_xrender_mask (dpy, pm, True); |
|
|
339 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
535 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
340 | |
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; |
341 | XRenderColor mask_c; |
541 | XRenderColor mask_c; |
342 | mask_c.red = r; |
542 | |
343 | 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)) |
344 | mask_c.blue = b; |
544 | XRenderFillRectangle (dpy, PictOpAdd, dst, &mask_c, 0, 0, w, h); |
345 | 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) }; |
346 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
620 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
|
|
621 | } |
347 | |
622 | |
348 | 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); |
349 | |
624 | |
350 | XRenderFreePicture (dpy, src); |
625 | XRenderFreePicture (dpy, src); |
351 | XRenderFreePicture (dpy, dst); |
626 | XRenderFreePicture (dpy, dst); |
352 | } |
|
|
353 | |
627 | |
354 | void |
628 | if (mask_p) |
355 | rxvt_img::contrast (unsigned short r, unsigned short g, unsigned short b, unsigned short a) |
|
|
356 | { |
|
|
357 | if (!(s->display->flags & DISPLAY_HAS_RENDER_MUL)) |
|
|
358 | return; |
|
|
359 | |
|
|
360 | Display *dpy = s->display->dpy; |
|
|
361 | Picture src = create_xrender_mask (dpy, pm, True); |
|
|
362 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
|
|
363 | |
|
|
364 | XRenderColor mask_c; |
|
|
365 | mask_c.red = r; |
|
|
366 | mask_c.green = g; |
|
|
367 | mask_c.blue = b; |
|
|
368 | mask_c.alpha = a; |
|
|
369 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
|
|
370 | |
|
|
371 | XRenderComposite (dpy, PictOpMultiply, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
|
|
372 | |
|
|
373 | XRenderFreePicture (dpy, src); |
629 | XRenderFreePicture (dpy, mask_p); |
374 | XRenderFreePicture (dpy, dst); |
|
|
375 | } |
630 | } |
376 | |
631 | |
377 | rxvt_img * |
632 | rxvt_img * |
378 | rxvt_img::clone () |
633 | rxvt_img::clone () |
379 | { |
634 | { |
380 | return new rxvt_img (*this); |
635 | return new rxvt_img (*this); |
381 | } |
|
|
382 | |
|
|
383 | static XRenderPictFormat * |
|
|
384 | find_alpha_format_for (Display *dpy, XRenderPictFormat *format) |
|
|
385 | { |
|
|
386 | if (format->direct.alphaMask) |
|
|
387 | return format; // already has alpha |
|
|
388 | |
|
|
389 | // try to find a suitable alpha format, one bit alpha is enough for our purposes |
|
|
390 | if (format->type == PictTypeDirect) |
|
|
391 | for (int n = 0; XRenderPictFormat *f = XRenderFindFormat (dpy, 0, 0, n); ++n) |
|
|
392 | if (f->direct.alphaMask |
|
|
393 | && f->type == PictTypeDirect |
|
|
394 | && ecb_popcount32 (f->direct.redMask ) >= ecb_popcount32 (format->direct.redMask ) |
|
|
395 | && ecb_popcount32 (f->direct.greenMask) >= ecb_popcount32 (format->direct.greenMask) |
|
|
396 | && ecb_popcount32 (f->direct.blueMask ) >= ecb_popcount32 (format->direct.blueMask )) |
|
|
397 | return f; |
|
|
398 | |
|
|
399 | // should be a very good fallback |
|
|
400 | return XRenderFindStandardFormat (dpy, PictStandardARGB32); |
|
|
401 | } |
636 | } |
402 | |
637 | |
403 | rxvt_img * |
638 | rxvt_img * |
404 | rxvt_img::reify () |
639 | rxvt_img::reify () |
405 | { |
640 | { |
406 | if (x == 0 && y == 0 && w == ref->w && h == ref->h) |
641 | if (x == 0 && y == 0 && w == ref->w && h == ref->h) |
407 | return clone (); |
642 | return clone (); |
408 | |
643 | |
409 | Display *dpy = s->display->dpy; |
644 | Display *dpy = s->display->dpy; |
410 | |
645 | |
|
|
646 | // add an alpha channel if... |
411 | bool alpha = !format->direct.alphaMask |
647 | bool alpha = !format->direct.alphaMask // pixmap has none yet |
412 | && (x || y) |
648 | && (x || y) // we need one because of non-zero offset |
413 | && repeat == RepeatNone; |
649 | && repeat == RepeatNone; // and we have no good pixels to fill with |
414 | |
650 | |
415 | 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); |
416 | img->alloc (); |
652 | img->alloc (); |
417 | |
653 | |
418 | Picture src = src_picture (); |
654 | Picture src = picture (); |
419 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
655 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
420 | |
656 | |
421 | if (alpha) |
657 | if (alpha) |
422 | { |
658 | { |
423 | XRenderColor rc = { 0, 0, 0, 0 }; |
659 | XRenderColor rc = { 0, 0, 0, 0 }; |
424 | 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 |
425 | 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); |
426 | } |
662 | } |
427 | else |
663 | else |
428 | 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); |
429 | |
665 | |
430 | XRenderFreePicture (dpy, src); |
666 | XRenderFreePicture (dpy, src); |
431 | XRenderFreePicture (dpy, dst); |
667 | XRenderFreePicture (dpy, dst); |
432 | |
668 | |
433 | return img; |
669 | return img; |
… | |
… | |
436 | rxvt_img * |
672 | rxvt_img * |
437 | 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) |
438 | { |
674 | { |
439 | rxvt_img *img = clone (); |
675 | rxvt_img *img = clone (); |
440 | |
676 | |
441 | img->x += x; |
677 | img->x -= x; |
442 | img->y += y; |
678 | img->y -= y; |
443 | |
679 | |
444 | if (w != width || h != height) |
680 | if (w != width || h != height) |
445 | { |
681 | { |
446 | img->w = width; |
682 | img->w = width; |
447 | img->h = height; |
683 | img->h = height; |
… | |
… | |
453 | |
689 | |
454 | return img; |
690 | return img; |
455 | } |
691 | } |
456 | |
692 | |
457 | rxvt_img * |
693 | rxvt_img * |
458 | rxvt_img::transform (int new_width, int new_height, double matrix[9]) |
694 | rxvt_img::transform (nv matrix[3][3]) |
459 | { |
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 | |
460 | 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); |
461 | img->alloc (); |
726 | img->alloc (); |
462 | |
727 | |
463 | Display *dpy = s->display->dpy; |
728 | Display *dpy = s->display->dpy; |
464 | Picture src = src_picture (); |
729 | Picture src = picture (); |
465 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
730 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
466 | |
731 | |
467 | XTransform xfrm; |
732 | XTransform xfrm; |
468 | |
733 | |
469 | for (int i = 0; i < 3; ++i) |
734 | for (int i = 0; i < 3; ++i) |
470 | for (int j = 0; j < 3; ++j) |
735 | for (int j = 0; j < 3; ++j) |
471 | xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); |
736 | xfrm.matrix [i][j] = XDoubleToFixed (inv [i][j]); |
472 | |
|
|
473 | #if 0 |
|
|
474 | xfrm.matrix [0][2] -= XDoubleToFixed (x);//TODO |
|
|
475 | xfrm.matrix [1][2] -= XDoubleToFixed (y); |
|
|
476 | #endif |
|
|
477 | |
737 | |
478 | XRenderSetPictureFilter (dpy, src, "good", 0, 0); |
738 | XRenderSetPictureFilter (dpy, src, "good", 0, 0); |
479 | XRenderSetPictureTransform (dpy, src, &xfrm); |
739 | XRenderSetPictureTransform (dpy, src, &xfrm); |
480 | 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 |
481 | |
751 | |
482 | XRenderFreePicture (dpy, src); |
752 | XRenderFreePicture (dpy, src); |
483 | XRenderFreePicture (dpy, dst); |
753 | XRenderFreePicture (dpy, dst); |
484 | |
754 | |
485 | return img; |
755 | return img; |
… | |
… | |
489 | rxvt_img::scale (int new_width, int new_height) |
759 | rxvt_img::scale (int new_width, int new_height) |
490 | { |
760 | { |
491 | if (w == new_width && h == new_height) |
761 | if (w == new_width && h == new_height) |
492 | return clone (); |
762 | return clone (); |
493 | |
763 | |
494 | double matrix[9] = { |
764 | nv matrix[3][3] = { |
495 | w / (double)new_width, 0, 0, |
765 | { new_width / (nv)w, 0, 0 }, |
496 | 0, h / (double)new_height, 0, |
766 | { 0, new_height / (nv)h, 0 }, |
497 | 0, 0, 1 |
767 | { 0, 0, 1 } |
498 | }; |
768 | }; |
499 | |
769 | |
500 | int old_repeat_mode = repeat; |
770 | int old_repeat_mode = repeat; |
501 | 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 |
502 | |
772 | |
503 | rxvt_img *img = transform (new_width, new_height, matrix); |
773 | rxvt_img *img = transform (matrix); |
504 | |
774 | |
505 | repeat = old_repeat_mode; |
775 | repeat = old_repeat_mode; |
506 | img->repeat = repeat; |
776 | img->repeat = repeat; |
507 | |
777 | |
508 | return img; |
778 | return img; |
509 | } |
779 | } |
510 | |
780 | |
511 | rxvt_img * |
781 | rxvt_img * |
512 | 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) |
513 | { |
783 | { |
514 | double s = sin (phi); |
784 | nv s = sin (phi); |
515 | double c = cos (phi); |
785 | nv c = cos (phi); |
516 | |
786 | |
517 | double matrix[9] = { |
787 | nv matrix[3][3] = { |
|
|
788 | #if 0 |
518 | c, -s, -c * x + s * y + x, |
789 | { c, -s, cx - c * cx + s * cy }, |
519 | s, c, -s * x - c * y + y, |
790 | { s, c, cy - s * cx - c * cy }, |
520 | 0, 0, 1 |
791 | { 0, 0, 1 } |
|
|
792 | #else |
|
|
793 | { c, -s, 0 }, |
|
|
794 | { s, c, 0 }, |
|
|
795 | { 0, 0, 1 } |
|
|
796 | #endif |
521 | }; |
797 | }; |
522 | |
798 | |
523 | return transform (new_width, new_height, matrix); |
799 | move (-cx, -cy); |
524 | } |
800 | rxvt_img *img = transform (matrix); |
|
|
801 | move ( cx, cy); |
|
|
802 | img->move (cx, cy); |
525 | |
803 | |
|
|
804 | return img; |
|
|
805 | } |
|
|
806 | |
526 | rxvt_img * |
807 | rxvt_img * |
527 | rxvt_img::convert_format (XRenderPictFormat *new_format, const rxvt_color &bg) |
808 | rxvt_img::convert_format (XRenderPictFormat *new_format, const rgba &bg) |
528 | { |
809 | { |
529 | if (new_format == format) |
810 | if (new_format == format) |
530 | return clone (); |
811 | return clone (); |
531 | |
812 | |
532 | 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); |
533 | img->alloc (); |
814 | img->alloc (); |
534 | |
815 | |
535 | Display *dpy = s->display->dpy; |
816 | Display *dpy = s->display->dpy; |
536 | Picture src = src_picture (); |
817 | Picture src = picture (); |
537 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
818 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
538 | int op = PictOpSrc; |
819 | int op = PictOpSrc; |
539 | |
820 | |
540 | if (format->direct.alphaMask && !new_format->direct.alphaMask) |
821 | if (format->direct.alphaMask && !new_format->direct.alphaMask) |
541 | { |
822 | { |
542 | // does it have to be that complicated |
823 | // does it have to be that complicated |
543 | rgba c; |
|
|
544 | bg.get (c); |
|
|
545 | |
|
|
546 | XRenderColor rc = { c.r, c.g, c.b, 0xffff }; |
824 | XRenderColor rc = { bg.r, bg.g, bg.b, bg.a }; |
547 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h); |
825 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h); |
548 | |
826 | |
549 | op = PictOpOver; |
827 | op = PictOpOver; |
550 | } |
828 | } |
551 | |
829 | |
… | |
… | |
556 | |
834 | |
557 | return img; |
835 | return img; |
558 | } |
836 | } |
559 | |
837 | |
560 | rxvt_img * |
838 | rxvt_img * |
561 | rxvt_img::blend (rxvt_img *img, double factor) |
839 | rxvt_img::blend (rxvt_img *img, nv factor) |
562 | { |
840 | { |
563 | rxvt_img *img2 = clone (); |
841 | rxvt_img *img2 = clone (); |
564 | Display *dpy = s->display->dpy; |
842 | Display *dpy = s->display->dpy; |
565 | Picture src = img->src_picture (); |
843 | Picture src = img->picture (); |
566 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
844 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
567 | Picture mask = create_xrender_mask (dpy, img->pm, False); |
845 | Picture mask = create_xrender_mask (dpy, img->pm, False, False); |
568 | |
846 | |
569 | XRenderColor mask_c; |
847 | XRenderColor mask_c; |
570 | |
848 | |
571 | mask_c.alpha = float_to_component (factor); |
849 | mask_c.alpha = float_to_component (factor); |
572 | mask_c.red = |
850 | mask_c.red = |