1 | #include <math.h> |
1 | #include <math.h> |
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 | |
|
|
7 | #define float_to_component(d) ((d) * 65535.99) |
|
|
8 | |
6 | |
9 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height) |
7 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height) |
10 | : s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false) |
8 | : s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false) |
11 | { |
9 | { |
12 | pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
10 | pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
… | |
… | |
200 | |
198 | |
201 | return mask; |
199 | return mask; |
202 | } |
200 | } |
203 | |
201 | |
204 | void |
202 | void |
205 | rxvt_img::brightness (double r, double g, double b, double a) |
203 | rxvt_img::brightness (unsigned short r, unsigned short g, unsigned short b, unsigned short a) |
206 | { |
204 | { |
207 | Display *dpy = s->display->dpy; |
205 | Display *dpy = s->display->dpy; |
208 | Picture src = create_xrender_mask (dpy, pm, True); |
206 | Picture src = create_xrender_mask (dpy, pm, True); |
209 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
207 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
210 | |
208 | |
211 | XRenderColor mask_c; |
209 | XRenderColor mask_c; |
212 | mask_c.red = float_to_component (r); |
210 | mask_c.red = r; |
213 | mask_c.green = float_to_component (g); |
211 | mask_c.green = g; |
214 | mask_c.blue = float_to_component (b); |
212 | mask_c.blue = b; |
215 | mask_c.alpha = float_to_component (a); |
213 | mask_c.alpha = a; |
216 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
214 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
217 | |
215 | |
218 | XRenderComposite (dpy, PictOpAdd, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
216 | XRenderComposite (dpy, PictOpAdd, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
219 | |
217 | |
220 | XRenderFreePicture (dpy, src); |
218 | XRenderFreePicture (dpy, src); |
221 | XRenderFreePicture (dpy, dst); |
219 | XRenderFreePicture (dpy, dst); |
222 | } |
220 | } |
223 | |
221 | |
224 | void |
222 | void |
225 | rxvt_img::contrast (double r, double g, double b, double a) |
223 | rxvt_img::contrast (unsigned short r, unsigned short g, unsigned short b, unsigned short a) |
226 | { |
224 | { |
227 | if (!(s->display->flags & DISPLAY_HAS_RENDER_MUL)) |
225 | if (!(s->display->flags & DISPLAY_HAS_RENDER_MUL)) |
228 | return; |
226 | return; |
229 | |
227 | |
230 | Display *dpy = s->display->dpy; |
228 | Display *dpy = s->display->dpy; |
231 | Picture src = create_xrender_mask (dpy, pm, True); |
229 | Picture src = create_xrender_mask (dpy, pm, True); |
232 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
230 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
233 | |
231 | |
234 | XRenderColor mask_c; |
232 | XRenderColor mask_c; |
235 | mask_c.red = float_to_component (r); |
233 | mask_c.red = r; |
236 | mask_c.green = float_to_component (g); |
234 | mask_c.green = g; |
237 | mask_c.blue = float_to_component (b); |
235 | mask_c.blue = b; |
238 | mask_c.alpha = float_to_component (a); |
236 | mask_c.alpha = a; |
239 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
237 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
240 | |
238 | |
241 | XRenderComposite (dpy, PictOpMultiply, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
239 | XRenderComposite (dpy, PictOpMultiply, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
242 | |
240 | |
243 | XRenderFreePicture (dpy, src); |
241 | XRenderFreePicture (dpy, src); |