nsxiv4fde8c8
Use separate background image for alpha layer; fixes issue #132
+31 −9
2 files changed
| @@ -1,4 +1,4 @@ | |||
| 1 | − | VERSION = git-20140205 | |
| 1 | + | VERSION = git-20140206 | |
| 2 | 2 | ||
| 3 | 3 | PREFIX = /usr/local | |
| 4 | 4 | MANPREFIX = $(PREFIX)/share/man | |
| @@ -441,6 +441,8 @@ void img_render(img_t *img) | |||
| 441 | 441 | win_t *win; | |
| 442 | 442 | int sx, sy, sw, sh; | |
| 443 | 443 | int dx, dy, dw, dh; | |
| 444 | + | Imlib_Image bg; | |
| 445 | + | unsigned long c; | |
| 444 | 446 | ||
| 445 | 447 | if (img == NULL || img->im == NULL || img->win == NULL) | |
| 446 | 448 | return; | |
| @@ -456,8 +458,11 @@ void img_render(img_t *img) | |||
| 456 | 458 | if (!img->dirty) | |
| 457 | 459 | return; | |
| 458 | 460 | ||
| 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) { | |
| 461 | 466 | sx = -img->x / img->zoom; | |
| 462 | 467 | sw = win->w / img->zoom; | |
| 463 | 468 | dx = 0; | |
| @@ -468,7 +473,7 @@ void img_render(img_t *img) | |||
| 468 | 473 | dx = img->x; | |
| 469 | 474 | dw = img->w * img->zoom; | |
| 470 | 475 | } | |
| 471 | − | if (img->y < 0) { | |
| 476 | + | if (img->y <= 0) { | |
| 472 | 477 | sy = -img->y / img->zoom; | |
| 473 | 478 | sh = win->h / img->zoom; | |
| 474 | 479 | dy = 0; | |
| @@ -484,13 +489,30 @@ void img_render(img_t *img) | |||
| 484 | 489 | ||
| 485 | 490 | imlib_context_set_image(img->im); | |
| 486 | 491 | 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 | − | ||
| 491 | 492 | imlib_context_set_drawable(win->pm); | |
| 492 | − | imlib_render_image_part_on_drawable_at_size(sx, sy, sw, sh, dx, dy, dw, dh); | |
| 493 | 493 | ||
| 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 | + | } | |
| 494 | 516 | img->dirty = false; | |
| 495 | 517 | } | |
| 496 | 518 | ||