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.13 by root, Mon Jun 4 15:30:41 2012 UTC vs.
Revision 1.14 by root, Mon Jun 4 15:53:12 2012 UTC

31 XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24), 31 XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24),
32 gdk_pixbuf_get_width (pb), 32 gdk_pixbuf_get_width (pb),
33 gdk_pixbuf_get_height (pb) 33 gdk_pixbuf_get_height (pb)
34 ); 34 );
35 35
36 img->render (pb, 0, 0, img->w, img->h, 0, 0); 36 img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0);
37 37
38 return img; 38 return img;
39} 39}
40 40
41rxvt_img::~rxvt_img () 41rxvt_img::~rxvt_img ()
198 XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); 198 XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1);
199 199
200 XRenderComposite (dpy, PictOpMultiply, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); 200 XRenderComposite (dpy, PictOpMultiply, src, None, dst, 0, 0, 0, 0, 0, 0, w, h);
201} 201}
202 202
203void 203bool
204rxvt_img::render (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y) 204rxvt_img::render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y)
205{ 205{
206 bool argb = format->id == PictStandardARGB32;
207
208 Display *dpy = s->display->dpy;
209
210 if (s->visual->c_class != TrueColor)
211 return false;
212
213 uint32_t red_mask, green_mask, blue_mask, alpha_mask;
214
215 if (argb)
216 {
217 red_mask = 0xff << 16;
218 green_mask = 0xff << 8;
219 blue_mask = 0xff;
220 alpha_mask = 0xff << 24;
221 }
222 else
223 {
224 red_mask = s->visual->red_mask;
225 green_mask = s->visual->green_mask;
226 blue_mask = s->visual->blue_mask;
227 alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha;
228 }
229
230 int width_r = ecb_popcount32 (red_mask);
231 int width_g = ecb_popcount32 (green_mask);
232 int width_b = ecb_popcount32 (blue_mask);
233 int width_a = ecb_popcount32 (alpha_mask);
234
235 if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8)
236 return false;
237
238 int sh_r = ecb_ctz32 (red_mask);
239 int sh_g = ecb_ctz32 (green_mask);
240 int sh_b = ecb_ctz32 (blue_mask);
241 int sh_a = ecb_ctz32 (alpha_mask);
242
243 if (width > 32767 || height > 32767)
244 return false;
245
246 XImage *ximage = XCreateImage (dpy, s->visual, argb ? 32 : format->depth, ZPixmap, 0, 0,
247 width, height, 32, 0);
248 if (!ximage)
249 return false;
250
251 if (height > INT_MAX / ximage->bytes_per_line
252 || !(ximage->data = (char *)malloc (height * ximage->bytes_per_line)))
253 {
254 XDestroyImage (ximage);
255 return false;
256 }
257
258 GC gc = XCreateGC (dpy, pm, 0, 0);
259
260 ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
261
262 int rowstride = gdk_pixbuf_get_rowstride (pixbuf);
263 int channels = gdk_pixbuf_get_n_channels (pixbuf);
264 unsigned char *row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels;
265 char *line = ximage->data;
266
267 rgba c (0, 0, 0);
268
269 if (channels == 4 && alpha_mask == 0)
270 {
271 //pix_colors[Color_bg].get (c);
206 //TODO 272 //TODO
273 c.r >>= 8;
274 c.g >>= 8;
275 c.b >>= 8;
276 }
277
278 for (int y = 0; y < height; y++)
279 {
280 for (int x = 0; x < width; x++)
281 {
282 unsigned char *pixel = row + x * channels;
283 uint32_t value;
284 unsigned char r, g, b, a;
285
286 if (channels == 4)
287 {
288 a = pixel[3];
289 r = (pixel[0] * a + c.r * (0xff - a)) / 0xff;
290 g = (pixel[1] * a + c.g * (0xff - a)) / 0xff;
291 b = (pixel[2] * a + c.b * (0xff - a)) / 0xff;
292 }
293 else
294 {
295 a = 0xff;
296 r = pixel[0];
297 g = pixel[1];
298 b = pixel[2];
299 }
300
301 value = ((r >> (8 - width_r)) << sh_r)
302 | ((g >> (8 - width_g)) << sh_g)
303 | ((b >> (8 - width_b)) << sh_b)
304 | ((a >> (8 - width_a)) << sh_a);
305
306 if (ximage->bits_per_pixel == 32)
307 ((uint32_t *)line)[x] = value;
308 else
309 XPutPixel (ximage, x, y, value);
310 }
311
312 row += rowstride;
313 line += ximage->bytes_per_line;
314 }
315
316 XPutImage (dpy, pm, gc, ximage, 0, 0, dst_x, dst_y, width, height);
317 XDestroyImage (ximage);
318 XFreeGC (dpy, gc);
319
320 return true;
207} 321}
208 322
209rxvt_img * 323rxvt_img *
210rxvt_img::clone () 324rxvt_img::clone ()
211{ 325{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines