… | |
… | |
77 | |
77 | |
78 | xi.width = width; |
78 | xi.width = width; |
79 | xi.height = height; |
79 | xi.height = height; |
80 | xi.xoffset = 0; |
80 | xi.xoffset = 0; |
81 | xi.format = ZPixmap; |
81 | xi.format = ZPixmap; |
82 | xi.byte_order = MSBFirst; // maybe go for host byte order, because servers are usually local? |
82 | xi.byte_order = LSBFirst; // maybe go for host byte order, because servers are usually local? |
83 | xi.bitmap_unit = 32; |
83 | xi.bitmap_unit = 32; |
84 | xi.bitmap_bit_order = MSBFirst; |
84 | xi.bitmap_bit_order = LSBFirst; |
85 | xi.bitmap_pad = BitmapPad (dpy); |
85 | xi.bitmap_pad = BitmapPad (dpy); |
86 | xi.depth = depth; |
86 | xi.depth = depth; |
87 | xi.bytes_per_line = 0; |
87 | xi.bytes_per_line = 0; |
88 | xi.bits_per_pixel = 32; |
88 | xi.bits_per_pixel = 32; |
89 | xi.red_mask = 0x00ff0000; |
89 | xi.red_mask = 0x000000ff; |
90 | xi.green_mask = 0x0000ff00; |
90 | xi.green_mask = 0x0000ff00; |
91 | xi.blue_mask = 0x000000ff; |
91 | xi.blue_mask = 0x00ff0000; |
92 | |
92 | |
93 | if (!XInitImage (&xi)) |
93 | if (!XInitImage (&xi)) |
94 | rxvt_fatal ("unable to initialise ximage, please report.\n"); |
94 | rxvt_fatal ("unable to initialise ximage, please report.\n"); |
95 | |
95 | |
96 | if (height > INT_MAX / xi.bytes_per_line) |
96 | if (height > INT_MAX / xi.bytes_per_line) |
… | |
… | |
104 | unsigned char *row = gdk_pixbuf_get_pixels (pb); |
104 | unsigned char *row = gdk_pixbuf_get_pixels (pb); |
105 | char *line = xi.data; |
105 | char *line = xi.data; |
106 | |
106 | |
107 | for (int y = 0; y < height; y++) |
107 | for (int y = 0; y < height; y++) |
108 | { |
108 | { |
109 | unsigned char r, g, b, a; |
|
|
110 | unsigned char *data = row; |
109 | unsigned char *src = row; |
|
|
110 | uint32_t *dst = (uint32_t *)line; |
111 | |
111 | |
112 | if (depth == 24) |
112 | if (depth == 24) |
113 | for (int x = 0; x < width; x++) |
113 | for (int x = 0; x < width; x++) |
114 | { |
114 | { |
115 | r = *data++; |
115 | uint8_t r = *src++; |
116 | g = *data++; |
116 | uint8_t g = *src++; |
117 | b = *data++; |
117 | uint8_t b = *src++; |
|
|
118 | |
|
|
119 | uint32_t v = r | (g << 8) | (b << 16); |
|
|
120 | |
|
|
121 | if (ecb_big_endian ()) |
|
|
122 | v = ecb_bswap32 (v); |
|
|
123 | |
118 | *line++ = 0; |
124 | *dst++ = x; |
119 | *line++ = r; |
|
|
120 | *line++ = g; |
|
|
121 | *line++ = b; |
|
|
122 | } |
125 | } |
123 | else |
126 | else |
124 | for (int x = 0; x < width; x++) |
127 | for (int x = 0; x < width; x++) |
125 | { |
128 | { |
126 | uint32_t v = *(uint32_t *)data; data += 4; |
129 | uint32_t v = *(uint32_t *)src; src += 4; |
127 | v = ecb_big_endian () ? ecb_rotr32 (v, 8) : ecb_rotl32 (v, 8); |
130 | v = ecb_big_endian () ? ecb_rotr32 (v, 8) : ecb_rotl32 (v, 8); |
128 | *(uint32_t *)line = x; line += 4; |
131 | *dst++ = ecb_bswap32 (v); |
129 | } |
132 | } |
130 | |
133 | |
131 | row += rowstride; |
134 | row += rowstride; |
|
|
135 | line += xi.bytes_per_line; |
132 | } |
136 | } |
133 | |
137 | |
134 | rxvt_img *img = new rxvt_img (s, XRenderFindStandardFormat (dpy, depth == 24 ? PictStandardRGB24 : PictStandardARGB32), 0, 0, width, height); |
138 | rxvt_img *img = new rxvt_img (s, XRenderFindStandardFormat (dpy, depth == 24 ? PictStandardRGB24 : PictStandardARGB32), 0, 0, width, height); |
135 | img->alloc (); |
139 | img->alloc (); |
136 | |
140 | |