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.126 by sf-exg, Wed Dec 1 15:39:00 2010 UTC vs.
Revision 1.127 by sf-exg, Thu Dec 2 11:02:16 2010 UTC

657} 657}
658# endif /* HAVE_AFTERIMAGE */ 658# endif /* HAVE_AFTERIMAGE */
659 659
660# ifdef HAVE_PIXBUF 660# ifdef HAVE_PIXBUF
661bool 661bool
662bgPixmap_t::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc,
663 int src_x, int src_y, int dst_x, int dst_y,
664 unsigned int width, unsigned int height)
665{
666 XImage *ximage;
667 char *data, *line;
668 int bytes_per_pixel;
669 int width_r, width_g, width_b;
670 int sh_r, sh_g, sh_b;
671 int rowstride;
672 int channels;
673 unsigned char *row;
674 Visual *visual = target->visual;
675 int depth = target->depth;
676
677 if (visual->c_class != TrueColor)
678 return false;
679
680 if (depth == 24 || depth == 32)
681 bytes_per_pixel = 4;
682 else if (depth == 15 || depth == 16)
683 bytes_per_pixel = 2;
684 else
685 return false;
686
687 width_r = rxvt_popcount (visual->red_mask);
688 width_g = rxvt_popcount (visual->green_mask);
689 width_b = rxvt_popcount (visual->blue_mask);
690
691 if (width_r > 8 || width_g > 8 || width_b > 8)
692 return false;
693
694 sh_r = rxvt_ctz (visual->red_mask);
695 sh_g = rxvt_ctz (visual->green_mask);
696 sh_b = rxvt_ctz (visual->blue_mask);
697
698 if (width > INT_MAX / height / bytes_per_pixel)
699 return false;
700
701 data = (char *)malloc (width * height * bytes_per_pixel);
702 if (!data)
703 return false;
704
705 ximage = XCreateImage (target->dpy, visual, depth, ZPixmap, 0, data,
706 width, height, bytes_per_pixel * 8, 0);
707 if (!ximage)
708 {
709 free (data);
710 return false;
711 }
712
713 ximage->byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst;
714
715 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
716 channels = gdk_pixbuf_get_n_channels (pixbuf);
717 row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels;
718 line = data;
719
720 for (int y = 0; y < height; y++)
721 {
722 for (int x = 0; x < width; x++)
723 {
724 unsigned char *pixel = row + x * channels;
725 uint32_t value;
726
727 value = ((pixel[0] >> (8 - width_r)) << sh_r)
728 | ((pixel[1] >> (8 - width_g)) << sh_g)
729 | ((pixel[2] >> (8 - width_b)) << sh_b);
730
731 if (bytes_per_pixel == 4)
732 ((uint32_t *)line)[x] = value;
733 else
734 ((uint16_t *)line)[x] = value;
735 }
736
737 row += rowstride;
738 line += ximage->bytes_per_line;
739 }
740
741 XPutImage (target->dpy, pixmap, gc, ximage, 0, 0, dst_x, dst_y, width, height);
742 XDestroyImage (ximage);
743 return true;
744}
745
746bool
662bgPixmap_t::render_image (unsigned long background_flags) 747bgPixmap_t::render_image (unsigned long background_flags)
663{ 748{
664 if (target == NULL) 749 if (target == NULL)
665 return false; 750 return false;
666 751
747 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); 832 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
748 833
749 if (h_scale == 0 || v_scale == 0) 834 if (h_scale == 0 || v_scale == 0)
750 { 835 {
751 Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth); 836 Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth);
752 gdk_pixbuf_xlib_render_to_drawable (result, tile, gc, 837 pixbuf_to_pixmap (result, tile, gc,
753 0, 0, 838 0, 0,
754 0, 0, 839 0, 0,
755 image_width, image_height, 840 image_width, image_height);
756 XLIB_RGB_DITHER_NONE,
757 0, 0);
758 841
759 gcv.tile = tile; 842 gcv.tile = tile;
760 gcv.fill_style = FillTiled; 843 gcv.fill_style = FillTiled;
761 gcv.ts_x_origin = x; 844 gcv.ts_x_origin = x;
762 gcv.ts_y_origin = y; 845 gcv.ts_y_origin = y;
777 || dst_x + dst_width < new_pmap_width 860 || dst_x + dst_width < new_pmap_width
778 || dst_y + dst_height < new_pmap_height) 861 || dst_y + dst_height < new_pmap_height)
779 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 862 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
780 863
781 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 864 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
782 gdk_pixbuf_xlib_render_to_drawable (result, pixmap, gc, 865 pixbuf_to_pixmap (result, pixmap, gc,
783 src_x, src_y, 866 src_x, src_y,
784 dst_x, dst_y, 867 dst_x, dst_y,
785 dst_width, dst_height, 868 dst_width, dst_height);
786 XLIB_RGB_DITHER_NONE,
787 0, 0);
788 } 869 }
789 870
790#if XRENDER 871#if XRENDER
791 if (background_flags) 872 if (background_flags)
792 { 873 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines