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

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 *
325rxvt_img::sub_rect (int x, int y, int width, int height, int repeat)
326{
327 rxvt_img *img = new rxvt_img (s, format, width, height);
328
329 Display *dpy = s->display->dpy;
330 XRenderPictureAttributes pa;
331 pa.repeat = repeat;
332 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa);
333 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
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 *
335rxvt_img::transform (int new_width, int new_height, int repeat, double matrix[9]) 344rxvt_img::transform (int new_width, int new_height, double matrix[9], int repeat)
336{ 345{
337 rxvt_img *img = new rxvt_img (s, format, new_width, new_height); 346 rxvt_img *img = new rxvt_img (s, format, new_width, new_height);
338 347
339 Display *dpy = s->display->dpy; 348 Display *dpy = s->display->dpy;
340 XRenderPictureAttributes pa; 349 XRenderPictureAttributes pa;
365 w / (double)new_width, 0, 0, 374 w / (double)new_width, 0, 0,
366 0, h / (double)new_height, 0, 375 0, h / (double)new_height, 0,
367 0, 0, 1 376 0, 0, 1
368 }; 377 };
369 378
370 return transform (new_width, new_height, RepeatNormal, matrix); 379 return transform (new_width, new_height, matrix);
371} 380}
372 381
373rxvt_img * 382rxvt_img *
374rxvt_img::rotate (int new_width, int new_height, int repeat, int x, int y, double phi) 383rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi, int repeat)
375{ 384{
376 double s = sin (phi); 385 double s = sin (phi);
377 double c = cos (phi); 386 double c = cos (phi);
378 387
379 double matrix[9] = { 388 double matrix[9] = {
380 c, -s, -c * x + s * y + x, 389 c, -s, -c * x + s * y + x,
381 s, c, -s * x - c * y + y, 390 s, c, -s * x - c * y + y,
382 0, 0, 1 391 0, 0, 1
383 }; 392 };
384 393
385 return transform (new_width, new_height, repeat, matrix); 394 return transform (new_width, new_height, matrix, repeat);
386} 395}
387 396
388rxvt_img * 397rxvt_img *
389rxvt_img::convert_to (XRenderPictFormat *new_format) 398rxvt_img::convert_to (XRenderPictFormat *new_format)
390{ 399{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines