… | |
… | |
59 | } |
59 | } |
60 | |
60 | |
61 | rxvt_img * |
61 | rxvt_img * |
62 | rxvt_img::new_from_pixbuf (rxvt_screen *s, GdkPixbuf *pb) |
62 | rxvt_img::new_from_pixbuf (rxvt_screen *s, GdkPixbuf *pb) |
63 | { |
63 | { |
|
|
64 | Display *dpy = s->display->dpy; |
|
|
65 | |
64 | int width = gdk_pixbuf_get_width (pb); |
66 | int width = gdk_pixbuf_get_width (pb); |
65 | int height = gdk_pixbuf_get_height (pb); |
67 | int height = gdk_pixbuf_get_height (pb); |
66 | |
68 | |
67 | if (width > 32767 || height > 32767) // well, we *could* upload in chunks |
69 | if (width > 32767 || height > 32767) // well, we *could* upload in chunks |
68 | rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big (maximum size 32768x32768).\n"); |
70 | rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big (maximum size 32768x32768).\n"); |
… | |
… | |
75 | |
77 | |
76 | xi.width = width; |
78 | xi.width = width; |
77 | xi.height = height; |
79 | xi.height = height; |
78 | xi.xoffset = 0; |
80 | xi.xoffset = 0; |
79 | xi.format = ZPixmap; |
81 | xi.format = ZPixmap; |
80 | 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? |
81 | xi.bitmap_unit = 32; |
83 | xi.bitmap_unit = 32; //XY only, unused |
82 | xi.bitmap_bit_order = MSBFirst; |
84 | xi.bitmap_bit_order = LSBFirst; //XY only, unused |
83 | xi.bitmap_pad = 32; |
85 | xi.bitmap_pad = BitmapPad (dpy); |
84 | xi.depth = depth; |
86 | xi.depth = depth; |
85 | xi.bytes_per_line = 0; |
87 | xi.bytes_per_line = 0; |
86 | xi.bits_per_pixel = 32; |
88 | xi.bits_per_pixel = 32; //Z only |
87 | xi.red_mask = 0x00ff0000; |
89 | xi.red_mask = 0x000000ff; //Z only |
88 | xi.green_mask = 0x0000ff00; |
90 | xi.green_mask = 0x0000ff00; //Z only |
89 | xi.blue_mask = 0x000000ff; |
91 | xi.blue_mask = 0x00ff0000; //Z only |
|
|
92 | xi.obdata = 0; // probbaly unused |
90 | |
93 | |
91 | if (!XInitImage (&xi)) |
94 | if (!XInitImage (&xi)) |
92 | rxvt_fatal ("unable to initialise ximage, please report.\n"); |
95 | rxvt_fatal ("unable to initialise ximage, please report.\n"); |
93 | |
96 | |
94 | if (height > INT_MAX / xi.bytes_per_line) |
97 | if (height > INT_MAX / xi.bytes_per_line) |
… | |
… | |
102 | unsigned char *row = gdk_pixbuf_get_pixels (pb); |
105 | unsigned char *row = gdk_pixbuf_get_pixels (pb); |
103 | char *line = xi.data; |
106 | char *line = xi.data; |
104 | |
107 | |
105 | for (int y = 0; y < height; y++) |
108 | for (int y = 0; y < height; y++) |
106 | { |
109 | { |
107 | unsigned char r, g, b, a; |
|
|
108 | unsigned char *data = row; |
110 | unsigned char *src = row; |
|
|
111 | uint32_t *dst = (uint32_t *)line; |
109 | |
112 | |
110 | if (depth == 24) |
113 | if (depth == 24) |
111 | for (int x = 0; x < width; x++) |
114 | for (int x = 0; x < width; x++) |
112 | { |
115 | { |
113 | r = *data++; |
116 | uint8_t r = *src++; |
114 | g = *data++; |
117 | uint8_t g = *src++; |
115 | b = *data++; |
118 | uint8_t b = *src++; |
|
|
119 | |
|
|
120 | uint32_t v = r | (g << 8) | (b << 16); |
|
|
121 | |
|
|
122 | if (ecb_big_endian ()) |
|
|
123 | v = ecb_bswap32 (v); |
|
|
124 | |
116 | *line++ = 0; |
125 | *dst++ = v; |
117 | *line++ = r; |
|
|
118 | *line++ = g; |
|
|
119 | *line++ = b; |
|
|
120 | } |
126 | } |
121 | else |
127 | else |
122 | for (int x = 0; x < width; x++) |
128 | for (int x = 0; x < width; x++) |
123 | { |
129 | { |
124 | r = *data++; |
130 | uint32_t v = *(uint32_t *)src; src += 4; |
125 | g = *data++; |
131 | |
126 | b = *data++; |
132 | if (ecb_big_endian ()) |
127 | a = *data++; |
133 | v = ecb_bswap32 (v); |
|
|
134 | |
128 | *line++ = a; |
135 | *dst++ = v; |
129 | *line++ = r; |
|
|
130 | *line++ = g; |
|
|
131 | *line++ = b; |
|
|
132 | } |
136 | } |
133 | |
137 | |
134 | row += rowstride; |
138 | row += rowstride; |
|
|
139 | line += xi.bytes_per_line; |
135 | } |
140 | } |
136 | |
|
|
137 | Display *dpy = s->display->dpy; |
|
|
138 | |
141 | |
139 | rxvt_img *img = new rxvt_img (s, XRenderFindStandardFormat (dpy, depth == 24 ? PictStandardRGB24 : PictStandardARGB32), 0, 0, width, height); |
142 | rxvt_img *img = new rxvt_img (s, XRenderFindStandardFormat (dpy, depth == 24 ? PictStandardRGB24 : PictStandardARGB32), 0, 0, width, height); |
140 | img->alloc (); |
143 | img->alloc (); |
141 | |
144 | |
142 | GC gc = XCreateGC (dpy, img->pm, 0, 0); |
145 | GC gc = XCreateGC (dpy, img->pm, 0, 0); |