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.75 by sf-exg, Sun Jun 10 07:51:45 2012 UTC vs.
Revision 1.76 by root, Sun Jun 10 10:29:26 2012 UTC

63 if (width > 32767 || height > 32767) // well, we *could* upload in chunks 63 if (width > 32767 || height > 32767) // well, we *could* upload in chunks
64 rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big (maximum size 32768x32768).\n"); 64 rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big (maximum size 32768x32768).\n");
65 65
66 // since we require rgb24/argb32 formats from xrender we assume 66 // since we require rgb24/argb32 formats from xrender we assume
67 // that both 24 and 32 bpp MUST be supported by any screen that supports xrender 67 // that both 24 and 32 bpp MUST be supported by any screen that supports xrender
68 int depth = gdk_pixbuf_get_has_alpha (pb) ? 32 : 24;
69 68
70 int byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; 69 int byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
71 70
72 XImage xi; 71 XImage xi;
73 72
77 xi.format = ZPixmap; 76 xi.format = ZPixmap;
78 xi.byte_order = ImageByteOrder (dpy); 77 xi.byte_order = ImageByteOrder (dpy);
79 xi.bitmap_unit = 0; //XY only, unused 78 xi.bitmap_unit = 0; //XY only, unused
80 xi.bitmap_bit_order = 0; //XY only, unused 79 xi.bitmap_bit_order = 0; //XY only, unused
81 xi.bitmap_pad = BitmapPad (dpy); 80 xi.bitmap_pad = BitmapPad (dpy);
82 xi.depth = depth; 81 xi.depth = 32;
83 xi.bytes_per_line = 0; 82 xi.bytes_per_line = 0;
84 xi.bits_per_pixel = 32; //Z only 83 xi.bits_per_pixel = 32; //Z only
85 xi.red_mask = 0x00000000; //Z only, unused 84 xi.red_mask = 0x00000000; //Z only, unused
86 xi.green_mask = 0x00000000; //Z only, unused 85 xi.green_mask = 0x00000000; //Z only, unused
87 xi.blue_mask = 0x00000000; //Z only, unused 86 xi.blue_mask = 0x00000000; //Z only, unused
96 rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big for Xlib.\n"); 95 rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big for Xlib.\n");
97 96
98 xi.data = (char *)rxvt_malloc (height * xi.bytes_per_line); 97 xi.data = (char *)rxvt_malloc (height * xi.bytes_per_line);
99 98
100 int rowstride = gdk_pixbuf_get_rowstride (pb); 99 int rowstride = gdk_pixbuf_get_rowstride (pb);
101 100 bool pb_has_alpha = gdk_pixbuf_get_has_alpha (pb);
102 assert (3 + (depth == 32) == gdk_pixbuf_get_n_channels (pb));
103 unsigned char *row = gdk_pixbuf_get_pixels (pb); 101 unsigned char *row = gdk_pixbuf_get_pixels (pb);
102
104 char *line = xi.data; 103 char *line = xi.data;
105 104
106 for (int y = 0; y < height; y++) 105 for (int y = 0; y < height; y++)
107 { 106 {
108 unsigned char *src = row; 107 unsigned char *src = row;
109 uint32_t *dst = (uint32_t *)line; 108 uint32_t *dst = (uint32_t *)line;
110 109
111 if (depth == 24) 110 if (!pb_has_alpha)
112 for (int x = 0; x < width; x++) 111 for (int x = 0; x < width; x++)
113 { 112 {
114 uint8_t r = *src++; 113 uint8_t r = *src++;
115 uint8_t g = *src++; 114 uint8_t g = *src++;
116 uint8_t b = *src++; 115 uint8_t b = *src++;
117 116
118 uint32_t v = (r << 16) | (g << 8) | b; 117 uint32_t v = (255 << 24) | (r << 16) | (g << 8) | b;
119 118
120 if (ecb_big_endian () ? !byte_order_mismatch : byte_order_mismatch) 119 if (ecb_big_endian () ? !byte_order_mismatch : byte_order_mismatch)
121 v = ecb_bswap32 (v); 120 v = ecb_bswap32 (v);
122 121
123 *dst++ = v; 122 *dst++ = v;
140 139
141 row += rowstride; 140 row += rowstride;
142 line += xi.bytes_per_line; 141 line += xi.bytes_per_line;
143 } 142 }
144 143
145 rxvt_img *img = new rxvt_img (s, XRenderFindStandardFormat (dpy, depth == 24 ? PictStandardRGB24 : PictStandardARGB32), 0, 0, width, height); 144 rxvt_img *img = new rxvt_img (s, XRenderFindStandardFormat (dpy, PictStandardARGB32), 0, 0, width, height);
146 img->alloc (); 145 img->alloc ();
147 146
148 GC gc = XCreateGC (dpy, img->pm, 0, 0); 147 GC gc = XCreateGC (dpy, img->pm, 0, 0);
149 XPutImage (dpy, img->pm, gc, &xi, 0, 0, 0, 0, width, height); 148 XPutImage (dpy, img->pm, gc, &xi, 0, 0, 0, 0, width, height);
150 XFreeGC (dpy, gc); 149 XFreeGC (dpy, gc);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines