… | |
… | |
65 | gdk_pixbuf_get_height (pb) |
65 | gdk_pixbuf_get_height (pb) |
66 | ); |
66 | ); |
67 | |
67 | |
68 | img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0); |
68 | img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0); |
69 | |
69 | |
|
|
70 | g_object_unref (pb); |
|
|
71 | |
70 | return img; |
72 | return img; |
71 | } |
73 | } |
72 | |
74 | |
73 | rxvt_img::~rxvt_img () |
75 | rxvt_img::~rxvt_img () |
74 | { |
76 | { |
… | |
… | |
212 | mask_c.blue = float_to_component (b); |
214 | mask_c.blue = float_to_component (b); |
213 | mask_c.alpha = float_to_component (a); |
215 | mask_c.alpha = float_to_component (a); |
214 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
216 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
215 | |
217 | |
216 | XRenderComposite (dpy, PictOpAdd, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
218 | XRenderComposite (dpy, PictOpAdd, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
|
|
219 | |
|
|
220 | XRenderFreePicture (dpy, src); |
|
|
221 | XRenderFreePicture (dpy, dst); |
217 | } |
222 | } |
218 | |
223 | |
219 | void |
224 | void |
220 | rxvt_img::contrast (double r, double g, double b, double a) |
225 | rxvt_img::contrast (double r, double g, double b, double a) |
221 | { |
226 | { |
… | |
… | |
232 | mask_c.blue = float_to_component (b); |
237 | mask_c.blue = float_to_component (b); |
233 | mask_c.alpha = float_to_component (a); |
238 | mask_c.alpha = float_to_component (a); |
234 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
239 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
235 | |
240 | |
236 | XRenderComposite (dpy, PictOpMultiply, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
241 | XRenderComposite (dpy, PictOpMultiply, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
|
|
242 | |
|
|
243 | XRenderFreePicture (dpy, src); |
|
|
244 | XRenderFreePicture (dpy, dst); |
237 | } |
245 | } |
238 | |
246 | |
239 | bool |
247 | bool |
240 | rxvt_img::render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y) |
248 | rxvt_img::render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y) |
241 | { |
249 | { |
… | |
… | |
285 | |
293 | |
286 | int rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
294 | int rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
287 | int channels = gdk_pixbuf_get_n_channels (pixbuf); |
295 | int channels = gdk_pixbuf_get_n_channels (pixbuf); |
288 | unsigned char *row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; |
296 | unsigned char *row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; |
289 | char *line = ximage->data; |
297 | char *line = ximage->data; |
290 | |
|
|
291 | rgba c (0, 0, 0); |
|
|
292 | |
|
|
293 | if (channels == 4 && alpha_mask == 0) |
|
|
294 | { |
|
|
295 | //pix_colors[Color_bg].get (c); |
|
|
296 | //TODO |
|
|
297 | c.r = 0xffff; c.g = 0xc0c0; c.b = 0xcbcb;//D |
|
|
298 | c.r >>= 8; |
|
|
299 | c.g >>= 8; |
|
|
300 | c.b >>= 8; |
|
|
301 | } |
|
|
302 | |
298 | |
303 | for (int y = 0; y < height; y++) |
299 | for (int y = 0; y < height; y++) |
304 | { |
300 | { |
305 | for (int x = 0; x < width; x++) |
301 | for (int x = 0; x < width; x++) |
306 | { |
302 | { |
… | |
… | |
309 | unsigned char r, g, b, a; |
305 | unsigned char r, g, b, a; |
310 | |
306 | |
311 | if (channels == 4) |
307 | if (channels == 4) |
312 | { |
308 | { |
313 | a = pixel[3]; |
309 | a = pixel[3]; |
314 | r = (pixel[0] * a + c.r * (0xff - a)) / 0xff; |
310 | r = pixel[0] * a / 0xff; |
315 | g = (pixel[1] * a + c.g * (0xff - a)) / 0xff; |
311 | g = pixel[1] * a / 0xff; |
316 | b = (pixel[2] * a + c.b * (0xff - a)) / 0xff; |
312 | b = pixel[2] * a / 0xff; |
317 | } |
313 | } |
318 | else |
314 | else |
319 | { |
315 | { |
320 | a = 0xff; |
316 | a = 0xff; |
321 | r = pixel[0]; |
317 | r = pixel[0]; |
… | |
… | |
445 | XRenderFreePicture (dpy, dst); |
441 | XRenderFreePicture (dpy, dst); |
446 | |
442 | |
447 | return img; |
443 | return img; |
448 | } |
444 | } |
449 | |
445 | |
|
|
446 | rxvt_img * |
|
|
447 | rxvt_img::blend (rxvt_img *img, double factor) |
|
|
448 | { |
|
|
449 | rxvt_img *img2 = clone (); |
|
|
450 | Display *dpy = s->display->dpy; |
|
|
451 | Picture src = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
|
|
452 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
|
|
453 | Picture mask = create_xrender_mask (dpy, img->pm, False); |
|
|
454 | |
|
|
455 | XRenderColor mask_c; |
|
|
456 | |
|
|
457 | mask_c.alpha = float_to_component (factor); |
|
|
458 | mask_c.red = |
|
|
459 | mask_c.green = |
|
|
460 | mask_c.blue = 0; |
|
|
461 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
|
|
462 | |
|
|
463 | XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, w, h); |
|
|
464 | |
|
|
465 | XRenderFreePicture (dpy, src); |
|
|
466 | XRenderFreePicture (dpy, dst); |
|
|
467 | XRenderFreePicture (dpy, mask); |
|
|
468 | |
|
|
469 | return img2; |
|
|
470 | } |
|
|
471 | |
450 | #endif |
472 | #endif |
451 | |
473 | |