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.49 by root, Thu Jun 7 19:24:13 2012 UTC vs.
Revision 1.55 by root, Thu Jun 7 20:26:21 2012 UTC

71 71
72 // since we require rgb24/argb32 formats from xrender we assume 72 // since we require rgb24/argb32 formats from xrender we assume
73 // that both 24 and 32 bpp MUST be supported by any screen that supports xrender 73 // that both 24 and 32 bpp MUST be supported by any screen that supports xrender
74 int depth = gdk_pixbuf_get_has_alpha (pb) ? 32 : 24; 74 int depth = gdk_pixbuf_get_has_alpha (pb) ? 32 : 24;
75 75
76 int byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
77
76 XImage xi; 78 XImage xi;
77 79
78 xi.width = width; 80 xi.width = width;
79 xi.height = height; 81 xi.height = height;
80 xi.xoffset = 0; 82 xi.xoffset = 0;
81 xi.format = ZPixmap; 83 xi.format = ZPixmap;
82 xi.byte_order = MSBFirst; // maybe go for host byte order, because servers are usually local? 84 xi.byte_order = ImageByteOrder (dpy);
83 xi.bitmap_unit = 32; 85 xi.bitmap_unit = 0; //XY only, unused
84 xi.bitmap_bit_order = MSBFirst; 86 xi.bitmap_bit_order = 0; //XY only, unused
85 xi.bitmap_pad = BitmapPad (dpy); 87 xi.bitmap_pad = BitmapPad (dpy);
86 xi.depth = depth; 88 xi.depth = depth;
87 xi.bytes_per_line = 0; 89 xi.bytes_per_line = 0;
88 xi.bits_per_pixel = 32; 90 xi.bits_per_pixel = 32; //Z only
89 xi.red_mask = 0x00ff0000; 91 xi.red_mask = 0x00000000; //Z only, unused
90 xi.green_mask = 0x0000ff00; 92 xi.green_mask = 0x00000000; //Z only, unused
91 xi.blue_mask = 0x000000ff; 93 xi.blue_mask = 0x00000000; //Z only, unused
94 xi.obdata = 0; // probably unused
95
96 bool byte_order_mismatch = byte_order != xi.byte_order;
92 97
93 if (!XInitImage (&xi)) 98 if (!XInitImage (&xi))
94 rxvt_fatal ("unable to initialise ximage, please report.\n"); 99 rxvt_fatal ("unable to initialise ximage, please report.\n");
95 100
96 if (height > INT_MAX / xi.bytes_per_line) 101 if (height > INT_MAX / xi.bytes_per_line)
104 unsigned char *row = gdk_pixbuf_get_pixels (pb); 109 unsigned char *row = gdk_pixbuf_get_pixels (pb);
105 char *line = xi.data; 110 char *line = xi.data;
106 111
107 for (int y = 0; y < height; y++) 112 for (int y = 0; y < height; y++)
108 { 113 {
109 unsigned char r, g, b, a;
110 unsigned char *data = row; 114 unsigned char *src = row;
115 uint32_t *dst = (uint32_t *)line;
111 116
112 if (depth == 24) 117 if (depth == 24)
113 for (int x = 0; x < width; x++) 118 for (int x = 0; x < width; x++)
114 { 119 {
115 r = *data++; 120 uint8_t r = *src++;
116 g = *data++; 121 uint8_t g = *src++;
117 b = *data++; 122 uint8_t b = *src++;
123
124 uint32_t v = (r << 16) | (g << 8) | b;
125
126 if (ecb_big_endian ())
127 v = ecb_bswap32 (v);
128
129 if (byte_order_mismatch)
130 v = ecb_bswap32 (v);
131
118 *line++ = 0; 132 *dst++ = v;
119 *line++ = r;
120 *line++ = g;
121 *line++ = b;
122 } 133 }
123 else 134 else
124 for (int x = 0; x < width; x++) 135 for (int x = 0; x < width; x++)
125 { 136 {
126 uint32_t v = *(uint32_t *)data; data += 4; 137 uint32_t v = *(uint32_t *)src; src += 4;
127 v = ecb_big_endian () ? ecb_rotr32 (v, 8) : ecb_rotl32 (v, 8); 138
128 *(uint32_t *)line = x; line += 4; 139 if (ecb_little_endian ())
140 v = ecb_bswap32 (v);
141
142 v = ecb_rotr32 (v, 8);
143
144 if (byte_order_mismatch)
145 v = ecb_bswap32 (v);
146
147 *dst++ = v;
129 } 148 }
130 149
131 row += rowstride; 150 row += rowstride;
151 line += xi.bytes_per_line;
132 } 152 }
133 153
134 rxvt_img *img = new rxvt_img (s, XRenderFindStandardFormat (dpy, depth == 24 ? PictStandardRGB24 : PictStandardARGB32), 0, 0, width, height); 154 rxvt_img *img = new rxvt_img (s, XRenderFindStandardFormat (dpy, depth == 24 ? PictStandardRGB24 : PictStandardARGB32), 0, 0, width, height);
135 img->alloc (); 155 img->alloc ();
136 156

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines