… | |
… | |
5 | #if HAVE_IMG |
5 | #if HAVE_IMG |
6 | |
6 | |
7 | #define float_to_component(d) ((d) * 65535.99) |
7 | #define float_to_component(d) ((d) * 65535.99) |
8 | |
8 | |
9 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height) |
9 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height) |
10 | : s(screen), w(width), h(height), format(format), shared(false) |
10 | : s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false) |
11 | { |
11 | { |
12 | pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
12 | pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
13 | } |
13 | } |
14 | |
14 | |
15 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) |
15 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) |
16 | : s(screen), pm(pixmap), w(width), h(height), format(format), shared(false) |
16 | : s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false), pm(pixmap) |
17 | { |
17 | { |
18 | } |
18 | } |
19 | |
19 | |
20 | rxvt_img * |
20 | rxvt_img * |
21 | rxvt_img::new_from_root (rxvt_screen *s) |
21 | rxvt_img::new_from_root (rxvt_screen *s) |
… | |
… | |
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 | { |
… | |
… | |
291 | |
293 | |
292 | int rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
294 | int rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
293 | int channels = gdk_pixbuf_get_n_channels (pixbuf); |
295 | int channels = gdk_pixbuf_get_n_channels (pixbuf); |
294 | 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; |
295 | char *line = ximage->data; |
297 | char *line = ximage->data; |
296 | |
|
|
297 | rgba c (0, 0, 0); |
|
|
298 | |
|
|
299 | if (channels == 4 && alpha_mask == 0) |
|
|
300 | { |
|
|
301 | //pix_colors[Color_bg].get (c); |
|
|
302 | //TODO |
|
|
303 | c.r = 0xffff; c.g = 0xc0c0; c.b = 0xcbcb;//D |
|
|
304 | c.r >>= 8; |
|
|
305 | c.g >>= 8; |
|
|
306 | c.b >>= 8; |
|
|
307 | } |
|
|
308 | |
298 | |
309 | for (int y = 0; y < height; y++) |
299 | for (int y = 0; y < height; y++) |
310 | { |
300 | { |
311 | for (int x = 0; x < width; x++) |
301 | for (int x = 0; x < width; x++) |
312 | { |
302 | { |
… | |
… | |
315 | unsigned char r, g, b, a; |
305 | unsigned char r, g, b, a; |
316 | |
306 | |
317 | if (channels == 4) |
307 | if (channels == 4) |
318 | { |
308 | { |
319 | a = pixel[3]; |
309 | a = pixel[3]; |
320 | r = (pixel[0] * a + c.r * (0xff - a)) / 0xff; |
310 | r = pixel[0] * a / 0xff; |
321 | g = (pixel[1] * a + c.g * (0xff - a)) / 0xff; |
311 | g = pixel[1] * a / 0xff; |
322 | b = (pixel[2] * a + c.b * (0xff - a)) / 0xff; |
312 | b = pixel[2] * a / 0xff; |
323 | } |
313 | } |
324 | else |
314 | else |
325 | { |
315 | { |
326 | a = 0xff; |
316 | a = 0xff; |
327 | r = pixel[0]; |
317 | r = pixel[0]; |
… | |
… | |
362 | |
352 | |
363 | return img; |
353 | return img; |
364 | } |
354 | } |
365 | |
355 | |
366 | rxvt_img * |
356 | rxvt_img * |
367 | rxvt_img::sub_rect (int x, int y, int width, int height, int repeat) |
357 | rxvt_img::sub_rect (int x, int y, int width, int height) |
368 | { |
358 | { |
369 | rxvt_img *img = new rxvt_img (s, format, width, height); |
359 | rxvt_img *img = new rxvt_img (s, format, width, height); |
370 | |
360 | |
371 | Display *dpy = s->display->dpy; |
361 | Display *dpy = s->display->dpy; |
372 | XRenderPictureAttributes pa; |
362 | XRenderPictureAttributes pa; |
… | |
… | |
381 | |
371 | |
382 | return img; |
372 | return img; |
383 | } |
373 | } |
384 | |
374 | |
385 | rxvt_img * |
375 | rxvt_img * |
386 | rxvt_img::transform (int new_width, int new_height, double matrix[9], int repeat) |
376 | rxvt_img::transform (int new_width, int new_height, double matrix[9]) |
387 | { |
377 | { |
388 | rxvt_img *img = new rxvt_img (s, format, new_width, new_height); |
378 | rxvt_img *img = new rxvt_img (s, format, new_width, new_height); |
389 | |
379 | |
390 | Display *dpy = s->display->dpy; |
380 | Display *dpy = s->display->dpy; |
391 | XRenderPictureAttributes pa; |
381 | XRenderPictureAttributes pa; |
… | |
… | |
420 | |
410 | |
421 | return transform (new_width, new_height, matrix); |
411 | return transform (new_width, new_height, matrix); |
422 | } |
412 | } |
423 | |
413 | |
424 | rxvt_img * |
414 | rxvt_img * |
425 | rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi, int repeat) |
415 | rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi) |
426 | { |
416 | { |
427 | double s = sin (phi); |
417 | double s = sin (phi); |
428 | double c = cos (phi); |
418 | double c = cos (phi); |
429 | |
419 | |
430 | double matrix[9] = { |
420 | double matrix[9] = { |
431 | c, -s, -c * x + s * y + x, |
421 | c, -s, -c * x + s * y + x, |
432 | s, c, -s * x - c * y + y, |
422 | s, c, -s * x - c * y + y, |
433 | 0, 0, 1 |
423 | 0, 0, 1 |
434 | }; |
424 | }; |
435 | |
425 | |
436 | return transform (new_width, new_height, matrix, repeat); |
426 | return transform (new_width, new_height, matrix); |
437 | } |
427 | } |
438 | |
428 | |
439 | rxvt_img * |
429 | rxvt_img * |
440 | rxvt_img::convert_to (XRenderPictFormat *new_format) |
430 | rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) |
441 | { |
431 | { |
442 | rxvt_img *img = new rxvt_img (s, new_format, w, h); |
432 | rxvt_img *img = new rxvt_img (s, new_format, w, h); |
443 | |
433 | |
444 | Display *dpy = s->display->dpy; |
434 | Display *dpy = s->display->dpy; |
445 | Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0); |
435 | Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0); |
446 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
436 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
|
|
437 | int op = PictOpSrc; |
447 | |
438 | |
|
|
439 | if (format->direct.alphaMask && !new_format->direct.alphaMask) |
|
|
440 | { |
|
|
441 | // does it have to be that complicated |
|
|
442 | rgba c; |
|
|
443 | bg.get (c); |
|
|
444 | |
|
|
445 | XRenderColor rc = { c.r, c.g, c.b, 0xffff }; |
|
|
446 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h); |
|
|
447 | |
|
|
448 | op = PictOpOver; |
|
|
449 | } |
|
|
450 | |
448 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
451 | XRenderComposite (dpy, op, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
449 | |
452 | |
450 | XRenderFreePicture (dpy, src); |
453 | XRenderFreePicture (dpy, src); |
451 | XRenderFreePicture (dpy, dst); |
454 | XRenderFreePicture (dpy, dst); |
452 | |
455 | |
453 | return img; |
456 | return img; |