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

Comparing rxvt-unicode/src/background.C (file contents):
Revision 1.209 by sf-exg, Fri May 11 12:21:22 2012 UTC vs.
Revision 1.210 by sf-exg, Sat May 12 09:43:06 2012 UTC

346rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, 346rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc,
347 int src_x, int src_y, int dst_x, int dst_y, 347 int src_x, int src_y, int dst_x, int dst_y,
348 unsigned int width, unsigned int height) 348 unsigned int width, unsigned int height)
349{ 349{
350 XImage *ximage; 350 XImage *ximage;
351 char *data, *line; 351 char *line;
352 int bytes_per_pixel;
353 int width_r, width_g, width_b, width_a; 352 int width_r, width_g, width_b, width_a;
354 int sh_r, sh_g, sh_b, sh_a; 353 int sh_r, sh_g, sh_b, sh_a;
355 uint32_t alpha_mask; 354 uint32_t alpha_mask;
356 int rowstride; 355 int rowstride;
357 int channels; 356 int channels;
366 alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha; 365 alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha;
367 else 366 else
368#endif 367#endif
369 alpha_mask = 0; 368 alpha_mask = 0;
370 369
371 if (depth == 24 || depth == 32)
372 bytes_per_pixel = 4;
373 else if (depth == 15 || depth == 16)
374 bytes_per_pixel = 2;
375 else
376 return false;
377
378 width_r = ecb_popcount32 (visual->red_mask); 370 width_r = ecb_popcount32 (visual->red_mask);
379 width_g = ecb_popcount32 (visual->green_mask); 371 width_g = ecb_popcount32 (visual->green_mask);
380 width_b = ecb_popcount32 (visual->blue_mask); 372 width_b = ecb_popcount32 (visual->blue_mask);
381 width_a = ecb_popcount32 (alpha_mask); 373 width_a = ecb_popcount32 (alpha_mask);
382 374
386 sh_r = ecb_ctz32 (visual->red_mask); 378 sh_r = ecb_ctz32 (visual->red_mask);
387 sh_g = ecb_ctz32 (visual->green_mask); 379 sh_g = ecb_ctz32 (visual->green_mask);
388 sh_b = ecb_ctz32 (visual->blue_mask); 380 sh_b = ecb_ctz32 (visual->blue_mask);
389 sh_a = ecb_ctz32 (alpha_mask); 381 sh_a = ecb_ctz32 (alpha_mask);
390 382
391 if (width > INT_MAX / height / bytes_per_pixel) 383 if (width > 32767 || height > 32767)
392 return false; 384 return false;
393 385
394 data = (char *)malloc (width * height * bytes_per_pixel); 386 ximage = XCreateImage (dpy, visual, depth, ZPixmap, 0, 0,
395 if (!data) 387 width, height, 32, 0);
388 if (!ximage)
396 return false; 389 return false;
397 390
398 ximage = XCreateImage (dpy, visual, depth, ZPixmap, 0, data, 391 if (height > INT_MAX / ximage->bytes_per_line
399 width, height, bytes_per_pixel * 8, 0); 392 || !(ximage->data = (char *)malloc (height * ximage->bytes_per_line)))
400 if (!ximage)
401 { 393 {
402 free (data); 394 XDestroyImage (ximage);
403 return false; 395 return false;
404 } 396 }
405 397
406 ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; 398 ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
407 399
408 rowstride = gdk_pixbuf_get_rowstride (pixbuf); 400 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
409 channels = gdk_pixbuf_get_n_channels (pixbuf); 401 channels = gdk_pixbuf_get_n_channels (pixbuf);
410 row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; 402 row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels;
411 line = data; 403 line = ximage->data;
412 404
413 rgba c (0, 0, 0); 405 rgba c (0, 0, 0);
414 406
415 if (channels == 4 && alpha_mask == 0) 407 if (channels == 4 && alpha_mask == 0)
416 { 408 {
446 value = ((r >> (8 - width_r)) << sh_r) 438 value = ((r >> (8 - width_r)) << sh_r)
447 | ((g >> (8 - width_g)) << sh_g) 439 | ((g >> (8 - width_g)) << sh_g)
448 | ((b >> (8 - width_b)) << sh_b) 440 | ((b >> (8 - width_b)) << sh_b)
449 | ((a >> (8 - width_a)) << sh_a); 441 | ((a >> (8 - width_a)) << sh_a);
450 442
451 if (bytes_per_pixel == 4) 443 if (ximage->bits_per_pixel == 32)
452 ((uint32_t *)line)[x] = value; 444 ((uint32_t *)line)[x] = value;
453 else 445 else
454 ((uint16_t *)line)[x] = value; 446 XPutPixel (ximage, x, y, value);
455 } 447 }
456 448
457 row += rowstride; 449 row += rowstride;
458 line += ximage->bytes_per_line; 450 line += ximage->bytes_per_line;
459 } 451 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines