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.14 by root, Mon Jun 4 15:53:12 2012 UTC vs.
Revision 1.21 by sf-exg, Tue Jun 5 14:59:44 2012 UTC

13} 13}
14 14
15rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) 15rxvt_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) 16: s(screen), pm(pixmap), w(width), h(height), format(format), shared(false)
17{ 17{
18}
19
20rxvt_img *
21rxvt_img::new_from_root (rxvt_screen *s)
22{
23 Display *dpy = s->display->dpy;
24 unsigned int root_pm_w, root_pm_h;
25 Pixmap root_pixmap = s->display->get_pixmap_property (s->display->xa[XA_XROOTPMAP_ID]);
26 if (root_pixmap == None)
27 root_pixmap = s->display->get_pixmap_property (s->display->xa[XA_ESETROOT_PMAP_ID]);
28
29 if (root_pixmap == None)
30 return 0;
31
32 Window wdummy;
33 int idummy;
34 unsigned int udummy;
35
36 if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pm_w, &root_pm_h, &udummy, &udummy))
37 return 0;
38
39 rxvt_img *img = new rxvt_img (
40 s,
41 XRenderFindVisualFormat (dpy, DefaultVisual (dpy, s->display->screen)),
42 root_pm_w,
43 root_pm_h,
44 root_pixmap
45 );
46
47 img->shared = true;
48
49 return img;
18} 50}
19 51
20rxvt_img * 52rxvt_img *
21rxvt_img::new_from_file (rxvt_screen *s, const char *filename) 53rxvt_img::new_from_file (rxvt_screen *s, const char *filename)
22{ 54{
101 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 133 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
102 134
103 XRenderPictureAttributes pa; 135 XRenderPictureAttributes pa;
104 136
105 pa.repeat = RepeatPad; 137 pa.repeat = RepeatPad;
106 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); 138 Picture src = XRenderCreatePicture (dpy, pm , format, CPRepeat, &pa);
107 Pixmap tmp = XCreatePixmap (dpy, pm, w, h, format->depth); 139 Pixmap tmp = XCreatePixmap (dpy, pm, w, h, format->depth);
108 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); 140 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa);
109 XFreePixmap (dpy, tmp); 141 XFreePixmap (dpy, tmp);
110 142
111 if (kernel && params) 143 if (kernel && params)
201} 233}
202 234
203bool 235bool
204rxvt_img::render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y) 236rxvt_img::render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y)
205{ 237{
206 bool argb = format->id == PictStandardARGB32;
207
208 Display *dpy = s->display->dpy; 238 Display *dpy = s->display->dpy;
209 239
210 if (s->visual->c_class != TrueColor) 240 if (s->visual->c_class != TrueColor)
211 return false; 241 return false;
212 242
213 uint32_t red_mask, green_mask, blue_mask, alpha_mask; 243 uint32_t red_mask, green_mask, blue_mask, alpha_mask;
214 244
215 if (argb) 245 red_mask = (uint32_t)format->direct.redMask << format->direct.red;
216 { 246 green_mask = (uint32_t)format->direct.greenMask << format->direct.green;
217 red_mask = 0xff << 16; 247 blue_mask = (uint32_t)format->direct.blueMask << format->direct.blue;
218 green_mask = 0xff << 8;
219 blue_mask = 0xff;
220 alpha_mask = 0xff << 24;
221 }
222 else
223 {
224 red_mask = s->visual->red_mask;
225 green_mask = s->visual->green_mask;
226 blue_mask = s->visual->blue_mask;
227 alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha; 248 alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha;
228 }
229 249
230 int width_r = ecb_popcount32 (red_mask); 250 int width_r = ecb_popcount32 (red_mask);
231 int width_g = ecb_popcount32 (green_mask); 251 int width_g = ecb_popcount32 (green_mask);
232 int width_b = ecb_popcount32 (blue_mask); 252 int width_b = ecb_popcount32 (blue_mask);
233 int width_a = ecb_popcount32 (alpha_mask); 253 int width_a = ecb_popcount32 (alpha_mask);
241 int sh_a = ecb_ctz32 (alpha_mask); 261 int sh_a = ecb_ctz32 (alpha_mask);
242 262
243 if (width > 32767 || height > 32767) 263 if (width > 32767 || height > 32767)
244 return false; 264 return false;
245 265
246 XImage *ximage = XCreateImage (dpy, s->visual, argb ? 32 : format->depth, ZPixmap, 0, 0, 266 XImage *ximage = XCreateImage (dpy, s->visual, format->depth, ZPixmap, 0, 0,
247 width, height, 32, 0); 267 width, height, 32, 0);
248 if (!ximage) 268 if (!ximage)
249 return false; 269 return false;
250 270
251 if (height > INT_MAX / ximage->bytes_per_line 271 if (height > INT_MAX / ximage->bytes_per_line
268 288
269 if (channels == 4 && alpha_mask == 0) 289 if (channels == 4 && alpha_mask == 0)
270 { 290 {
271 //pix_colors[Color_bg].get (c); 291 //pix_colors[Color_bg].get (c);
272 //TODO 292 //TODO
293 c.r = 0xffff; c.g = 0xc0c0; c.b = 0xcbcb;//D
273 c.r >>= 8; 294 c.r >>= 8;
274 c.g >>= 8; 295 c.g >>= 8;
275 c.b >>= 8; 296 c.b >>= 8;
276 } 297 }
277 298
321} 342}
322 343
323rxvt_img * 344rxvt_img *
324rxvt_img::clone () 345rxvt_img::clone ()
325{ 346{
347 rxvt_img *img = new rxvt_img (s, format, w, h);
348
326 GC gc = XCreateGC (s->display->dpy, pm, 0, 0); 349 GC gc = XCreateGC (s->display->dpy, pm, 0, 0);
327 Pixmap pm2 = XCreatePixmap (s->display->dpy, pm, w, h, format->depth);
328 XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, w, h, 0, 0); 350 XCopyArea (s->display->dpy, pm, img->pm, gc, 0, 0, w, h, 0, 0);
329 XFreeGC (s->display->dpy, gc); 351 XFreeGC (s->display->dpy, gc);
330 return new rxvt_img (s, format, w, h, pm2);
331}
332 352
353 return img;
354}
355
333rxvt_img * 356rxvt_img *
334rxvt_img::transform (int new_width, int new_height, int repeat, double matrix[9]) 357rxvt_img::sub_rect (int x, int y, int width, int height, int repeat)
335{ 358{
336 rxvt_img *img = new rxvt_img (s, format, new_width, new_height); 359 rxvt_img *img = new rxvt_img (s, format, width, height);
337 360
338 Display *dpy = s->display->dpy; 361 Display *dpy = s->display->dpy;
339 XRenderPictureAttributes pa; 362 XRenderPictureAttributes pa;
340 pa.repeat = repeat; 363 pa.repeat = repeat;
341 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); 364 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa);
342 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 365 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
343 366
367 XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, width, height);
368
369 XRenderFreePicture (dpy, src);
370 XRenderFreePicture (dpy, dst);
371
372 return img;
373}
374
375rxvt_img *
376rxvt_img::transform (int new_width, int new_height, double matrix[9], int repeat)
377{
378 rxvt_img *img = new rxvt_img (s, format, new_width, new_height);
379
380 Display *dpy = s->display->dpy;
381 XRenderPictureAttributes pa;
382 pa.repeat = repeat;
383 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa);
384 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
385
344 XTransform xfrm; 386 XTransform xfrm;
345 387
346 for (int i = 0; i < 3; ++i) 388 for (int i = 0; i < 3; ++i)
347 for (int j = 0; j < 3; ++j) 389 for (int j = 0; j < 3; ++j)
348 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); 390 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]);
349 391
392 XRenderSetPictureFilter (dpy, src, "good", 0, 0);
350 XRenderSetPictureTransform (dpy, src, &xfrm); 393 XRenderSetPictureTransform (dpy, src, &xfrm);
351 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height); 394 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height);
352 395
353 XRenderFreePicture (dpy, src); 396 XRenderFreePicture (dpy, src);
354 XRenderFreePicture (dpy, dst); 397 XRenderFreePicture (dpy, dst);
358 401
359rxvt_img * 402rxvt_img *
360rxvt_img::scale (int new_width, int new_height) 403rxvt_img::scale (int new_width, int new_height)
361{ 404{
362 double matrix[9] = { 405 double matrix[9] = {
363 new_width / (double)w, 0, 0, 406 w / (double)new_width, 0, 0,
364 0, new_height / (double)h, 0, 407 0, h / (double)new_height, 0,
365 0, 0, 1 408 0, 0, 1
366 }; 409 };
367 410
368 return transform (new_width, new_height, RepeatNormal, matrix); 411 return transform (new_width, new_height, matrix);
412}
413
414rxvt_img *
415rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi, int repeat)
416{
417 double s = sin (phi);
418 double c = cos (phi);
419
420 double matrix[9] = {
421 c, -s, -c * x + s * y + x,
422 s, c, -s * x - c * y + y,
423 0, 0, 1
424 };
425
426 return transform (new_width, new_height, matrix, repeat);
369} 427}
370 428
371rxvt_img * 429rxvt_img *
372rxvt_img::convert_to (XRenderPictFormat *new_format) 430rxvt_img::convert_to (XRenderPictFormat *new_format)
373{ 431{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines