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.50 by root, Thu Jun 7 19:42:09 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");
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;
82 xi.bitmap_bit_order = MSBFirst; 84 xi.bitmap_bit_order = LSBFirst;
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;
87 xi.red_mask = 0x00ff0000; 89 xi.red_mask = 0x000000ff;
88 xi.green_mask = 0x0000ff00; 90 xi.green_mask = 0x0000ff00;
89 xi.blue_mask = 0x000000ff; 91 xi.blue_mask = 0x00ff0000;
90 92
91 if (!XInitImage (&xi)) 93 if (!XInitImage (&xi))
92 rxvt_fatal ("unable to initialise ximage, please report.\n"); 94 rxvt_fatal ("unable to initialise ximage, please report.\n");
93 95
94 if (height > INT_MAX / xi.bytes_per_line) 96 if (height > INT_MAX / xi.bytes_per_line)
102 unsigned char *row = gdk_pixbuf_get_pixels (pb); 104 unsigned char *row = gdk_pixbuf_get_pixels (pb);
103 char *line = xi.data; 105 char *line = xi.data;
104 106
105 for (int y = 0; y < height; y++) 107 for (int y = 0; y < height; y++)
106 { 108 {
107 unsigned char r, g, b, a;
108 unsigned char *data = row; 109 unsigned char *src = row;
110 uint32_t *dst = (uint32_t *)line;
109 111
110 if (depth == 24) 112 if (depth == 24)
111 for (int x = 0; x < width; x++) 113 for (int x = 0; x < width; x++)
112 { 114 {
113 r = *data++; 115 uint8_t r = *src++;
114 g = *data++; 116 uint8_t g = *src++;
115 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
116 *line++ = 0; 124 *dst++ = x;
117 *line++ = r;
118 *line++ = g;
119 *line++ = b;
120 } 125 }
121 else 126 else
122 for (int x = 0; x < width; x++) 127 for (int x = 0; x < width; x++)
123 { 128 {
124 r = *data++; 129 uint32_t v = *(uint32_t *)src; src += 4;
125 g = *data++; 130 v = ecb_big_endian () ? ecb_rotr32 (v, 8) : ecb_rotl32 (v, 8);
126 b = *data++; 131 *dst++ = ecb_bswap32 (v);
127 a = *data++;
128 *line++ = a;
129 *line++ = r;
130 *line++ = g;
131 *line++ = b;
132 } 132 }
133 133
134 row += rowstride; 134 row += rowstride;
135 line += xi.bytes_per_line;
135 } 136 }
136
137 Display *dpy = s->display->dpy;
138 137
139 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);
140 img->alloc (); 139 img->alloc ();
141 140
142 GC gc = XCreateGC (dpy, img->pm, 0, 0); 141 GC gc = XCreateGC (dpy, img->pm, 0, 0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines