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.47 by root, Thu Jun 7 19:06:26 2012 UTC vs.
Revision 1.58 by root, Thu Jun 7 20:35:35 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines