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.16 by root, Mon Jun 4 16:12:55 2012 UTC vs.
Revision 1.20 by root, Tue Jun 5 14:07:47 2012 UTC

101 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 101 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
102 102
103 XRenderPictureAttributes pa; 103 XRenderPictureAttributes pa;
104 104
105 pa.repeat = RepeatPad; 105 pa.repeat = RepeatPad;
106 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); 106 Picture src = XRenderCreatePicture (dpy, pm , format, CPRepeat, &pa);
107 Pixmap tmp = XCreatePixmap (dpy, pm, w, h, format->depth); 107 Pixmap tmp = XCreatePixmap (dpy, pm, w, h, format->depth);
108 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); 108 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa);
109 XFreePixmap (dpy, tmp); 109 XFreePixmap (dpy, tmp);
110 110
111 if (kernel && params) 111 if (kernel && params)
201} 201}
202 202
203bool 203bool
204rxvt_img::render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y) 204rxvt_img::render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y)
205{ 205{
206 bool argb = format->id == PictStandardARGB32;
207
208 Display *dpy = s->display->dpy; 206 Display *dpy = s->display->dpy;
209 207
210 if (s->visual->c_class != TrueColor) 208 if (s->visual->c_class != TrueColor)
211 return false; 209 return false;
212 210
213 uint32_t red_mask, green_mask, blue_mask, alpha_mask; 211 uint32_t red_mask, green_mask, blue_mask, alpha_mask;
214 212
215 if (argb) 213 red_mask = (uint32_t)format->direct.redMask << format->direct.red;
216 { 214 green_mask = (uint32_t)format->direct.greenMask << format->direct.green;
217 red_mask = 0xff << 16; 215 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; 216 alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha;
228 }
229 217
230 int width_r = ecb_popcount32 (red_mask); 218 int width_r = ecb_popcount32 (red_mask);
231 int width_g = ecb_popcount32 (green_mask); 219 int width_g = ecb_popcount32 (green_mask);
232 int width_b = ecb_popcount32 (blue_mask); 220 int width_b = ecb_popcount32 (blue_mask);
233 int width_a = ecb_popcount32 (alpha_mask); 221 int width_a = ecb_popcount32 (alpha_mask);
241 int sh_a = ecb_ctz32 (alpha_mask); 229 int sh_a = ecb_ctz32 (alpha_mask);
242 230
243 if (width > 32767 || height > 32767) 231 if (width > 32767 || height > 32767)
244 return false; 232 return false;
245 233
246 XImage *ximage = XCreateImage (dpy, s->visual, argb ? 32 : format->depth, ZPixmap, 0, 0, 234 XImage *ximage = XCreateImage (dpy, s->visual, format->depth, ZPixmap, 0, 0,
247 width, height, 32, 0); 235 width, height, 32, 0);
248 if (!ximage) 236 if (!ximage)
249 return false; 237 return false;
250 238
251 if (height > INT_MAX / ximage->bytes_per_line 239 if (height > INT_MAX / ximage->bytes_per_line
322} 310}
323 311
324rxvt_img * 312rxvt_img *
325rxvt_img::clone () 313rxvt_img::clone ()
326{ 314{
315 rxvt_img *img = new rxvt_img (s, format, w, h);
316
327 GC gc = XCreateGC (s->display->dpy, pm, 0, 0); 317 GC gc = XCreateGC (s->display->dpy, pm, 0, 0);
328 Pixmap pm2 = XCreatePixmap (s->display->dpy, pm, w, h, format->depth);
329 XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, w, h, 0, 0); 318 XCopyArea (s->display->dpy, pm, img->pm, gc, 0, 0, w, h, 0, 0);
330 XFreeGC (s->display->dpy, gc); 319 XFreeGC (s->display->dpy, gc);
331 return new rxvt_img (s, format, w, h, pm2);
332}
333 320
321 return img;
322}
323
334rxvt_img * 324rxvt_img *
335rxvt_img::transform (int new_width, int new_height, int repeat, double matrix[9]) 325rxvt_img::sub_rect (int x, int y, int width, int height, int repeat)
336{ 326{
337 rxvt_img *img = new rxvt_img (s, format, new_width, new_height); 327 rxvt_img *img = new rxvt_img (s, format, width, height);
338 328
339 Display *dpy = s->display->dpy; 329 Display *dpy = s->display->dpy;
340 XRenderPictureAttributes pa; 330 XRenderPictureAttributes pa;
341 pa.repeat = repeat; 331 pa.repeat = repeat;
342 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); 332 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa);
343 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 333 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
344 334
335 XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, width, height);
336
337 XRenderFreePicture (dpy, src);
338 XRenderFreePicture (dpy, dst);
339
340 return img;
341}
342
343rxvt_img *
344rxvt_img::transform (int new_width, int new_height, double matrix[9], int repeat)
345{
346 rxvt_img *img = new rxvt_img (s, format, new_width, new_height);
347
348 Display *dpy = s->display->dpy;
349 XRenderPictureAttributes pa;
350 pa.repeat = repeat;
351 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa);
352 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
353
345 XTransform xfrm; 354 XTransform xfrm;
346 355
347 for (int i = 0; i < 3; ++i) 356 for (int i = 0; i < 3; ++i)
348 for (int j = 0; j < 3; ++j) 357 for (int j = 0; j < 3; ++j)
349 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); 358 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]);
350 359
360 XRenderSetPictureFilter (dpy, src, "good", 0, 0);
351 XRenderSetPictureTransform (dpy, src, &xfrm); 361 XRenderSetPictureTransform (dpy, src, &xfrm);
352 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height); 362 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height);
353 363
354 XRenderFreePicture (dpy, src); 364 XRenderFreePicture (dpy, src);
355 XRenderFreePicture (dpy, dst); 365 XRenderFreePicture (dpy, dst);
364 w / (double)new_width, 0, 0, 374 w / (double)new_width, 0, 0,
365 0, h / (double)new_height, 0, 375 0, h / (double)new_height, 0,
366 0, 0, 1 376 0, 0, 1
367 }; 377 };
368 378
369 return transform (new_width, new_height, RepeatNormal, matrix); 379 return transform (new_width, new_height, matrix);
380}
381
382rxvt_img *
383rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi, int repeat)
384{
385 double s = sin (phi);
386 double c = cos (phi);
387
388 double matrix[9] = {
389 c, -s, -c * x + s * y + x,
390 s, c, -s * x - c * y + y,
391 0, 0, 1
392 };
393
394 return transform (new_width, new_height, matrix, repeat);
370} 395}
371 396
372rxvt_img * 397rxvt_img *
373rxvt_img::convert_to (XRenderPictFormat *new_format) 398rxvt_img::convert_to (XRenderPictFormat *new_format)
374{ 399{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines