Krolyxon
Commit 4fde8c8

Branches

Refs →

nsxiv4fde8c8

Use separate background image for alpha layer; fixes issue #132

Author
Bert Münnich
Date
2014-02-06 22:04 +0100
Parent
72f1b1c
Commit
4fde8c8cbc6a019f1519a086e14ca79291439a48

+31 −9

2 files changed

  1. M Makefile +1 −1
  2. M image.c +30 −8
M Makefile View
@@ -1,4 +1,4 @@
1−VERSION = git-20140205
1+VERSION = git-20140206
22
33 PREFIX = /usr/local
44 MANPREFIX = $(PREFIX)/share/man
M image.c View
@@ -441,6 +441,8 @@ void img_render(img_t *img)
441441 win_t *win;
442442 int sx, sy, sw, sh;
443443 int dx, dy, dw, dh;
444+ Imlib_Image bg;
445+ unsigned long c;
444446
445447 if (img == NULL || img->im == NULL || img->win == NULL)
446448 return;
@@ -456,8 +458,11 @@ void img_render(img_t *img)
456458 if (!img->dirty)
457459 return;
458460
459− /* calculate source and destination offsets */
460− if (img->x < 0) {
461+ /* calculate source and destination offsets:
462+ * - part of image drawn on full window, or
463+ * - full image drawn on part of window
464+ */
465+ if (img->x <= 0) {
461466 sx = -img->x / img->zoom;
462467 sw = win->w / img->zoom;
463468 dx = 0;
@@ -468,7 +473,7 @@ void img_render(img_t *img)
468473 dx = img->x;
469474 dw = img->w * img->zoom;
470475 }
471− if (img->y < 0) {
476+ if (img->y <= 0) {
472477 sy = -img->y / img->zoom;
473478 sh = win->h / img->zoom;
474479 dy = 0;
@@ -484,13 +489,30 @@ void img_render(img_t *img)
484489
485490 imlib_context_set_image(img->im);
486491 imlib_context_set_anti_alias(img->aa);
487−
488− if (!img->alpha && imlib_image_has_alpha())
489− win_draw_rect(win, win->pm, dx, dy, dw, dh, True, 0, win->white);
490−
491492 imlib_context_set_drawable(win->pm);
492− imlib_render_image_part_on_drawable_at_size(sx, sy, sw, sh, dx, dy, dw, dh);
493493
494+ if (imlib_image_has_alpha()) {
495+ bg = imlib_create_image(dw, dh);
496+ imlib_context_set_image(bg);
497+ imlib_image_set_has_alpha(0);
498+
499+ if (img->alpha)
500+ c = win->fullscreen ? win->fscol : win->bgcol;
501+ else
502+ c = win->white;
503+ imlib_context_set_color(c >> 16 & 0xFF, c >> 8 & 0xFF, c & 0xFF, 0xFF);
504+ imlib_image_fill_rectangle(0, 0, dw, dh);
505+
506+ imlib_blend_image_onto_image(img->im, 0, sx, sy, sw, sh, 0, 0, dw, dh);
507+ imlib_context_set_color_modifier(NULL);
508+ imlib_render_image_on_drawable(dx, dy);
509+
510+ imlib_free_image();
511+ if (img->gamma != 0)
512+ imlib_context_set_color_modifier(img->cmod);
513+ } else {
514+ imlib_render_image_part_on_drawable_at_size(sx, sy, sw, sh, dx, dy, dw, dh);
515+ }
494516 img->dirty = false;
495517 }
496518