ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtimg.C
(Generate patch)

Comparing rxvt-unicode/src/rxvtimg.C (file contents):
Revision 1.29 by root, Wed Jun 6 20:55:36 2012 UTC vs.
Revision 1.31 by sf-exg, Thu Jun 7 06:08:09 2012 UTC

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#define float_to_component(d) ((d) * 65535.99)
8
9rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height) 7rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height)
10: s(screen), w(width), h(height), format(format), 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);
13} 11}
14 12
15rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) 13rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap)
16: s(screen), pm(pixmap), w(width), h(height), format(format), shared(false) 14: s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false), pm(pixmap)
17{ 15{
18} 16}
19 17
20rxvt_img * 18rxvt_img *
21rxvt_img::new_from_root (rxvt_screen *s) 19rxvt_img::new_from_root (rxvt_screen *s)
200 198
201 return mask; 199 return mask;
202} 200}
203 201
204void 202void
205rxvt_img::brightness (double r, double g, double b, double a) 203rxvt_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
224void 222void
225rxvt_img::contrast (double r, double g, double b, double a) 223rxvt_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);
352 350
353 return img; 351 return img;
354} 352}
355 353
356rxvt_img * 354rxvt_img *
357rxvt_img::sub_rect (int x, int y, int width, int height, int repeat) 355rxvt_img::sub_rect (int x, int y, int width, int height)
358{ 356{
359 rxvt_img *img = new rxvt_img (s, format, width, height); 357 rxvt_img *img = new rxvt_img (s, format, width, height);
360 358
361 Display *dpy = s->display->dpy; 359 Display *dpy = s->display->dpy;
362 XRenderPictureAttributes pa; 360 XRenderPictureAttributes pa;
371 369
372 return img; 370 return img;
373} 371}
374 372
375rxvt_img * 373rxvt_img *
376rxvt_img::transform (int new_width, int new_height, double matrix[9], int repeat) 374rxvt_img::transform (int new_width, int new_height, double matrix[9])
377{ 375{
378 rxvt_img *img = new rxvt_img (s, format, new_width, new_height); 376 rxvt_img *img = new rxvt_img (s, format, new_width, new_height);
379 377
380 Display *dpy = s->display->dpy; 378 Display *dpy = s->display->dpy;
381 XRenderPictureAttributes pa; 379 XRenderPictureAttributes pa;
410 408
411 return transform (new_width, new_height, matrix); 409 return transform (new_width, new_height, matrix);
412} 410}
413 411
414rxvt_img * 412rxvt_img *
415rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi, int repeat) 413rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi)
416{ 414{
417 double s = sin (phi); 415 double s = sin (phi);
418 double c = cos (phi); 416 double c = cos (phi);
419 417
420 double matrix[9] = { 418 double matrix[9] = {
421 c, -s, -c * x + s * y + x, 419 c, -s, -c * x + s * y + x,
422 s, c, -s * x - c * y + y, 420 s, c, -s * x - c * y + y,
423 0, 0, 1 421 0, 0, 1
424 }; 422 };
425 423
426 return transform (new_width, new_height, matrix, repeat); 424 return transform (new_width, new_height, matrix);
427} 425}
428 426
429rxvt_img * 427rxvt_img *
430rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) 428rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg)
431{ 429{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines