diff options
author | Bert <ber.t@gmx.com> | 2011-02-16 18:16:00 +0100 |
---|---|---|
committer | Bert <ber.t@gmx.com> | 2011-02-16 18:16:00 +0100 |
commit | 8919204a2e666e12216240a792bfff7a391d4d43 (patch) | |
tree | 057989f1a75c90f7257cc08f118e0197c2e87cef /image.c | |
parent | 89ec18385b1d9e76463afd443b25c203a83c94cb (diff) |
Render thumbnails
Diffstat (limited to 'image.c')
-rw-r--r-- | image.c | 47 |
1 files changed, 26 insertions, 21 deletions
@@ -110,6 +110,32 @@ int img_load(img_t *img, const char *filename) { return 1; } +int img_load_thumb(thumb_t *tn, const char *filename) { + int w, h; + float z, zw, zh; + + if (!tn) + return 0; + + if (!_imlib_load_image(filename)) + return 0; + + w = imlib_image_get_width(); + h = imlib_image_get_height(); + zw = (float) THUMB_SIZE / (float) w; + zh = (float) THUMB_SIZE / (float) h; + z = MIN(zw, zh); + tn->w = z * w; + tn->h = z * h; + + imlib_context_set_drawable(tn->pm); + imlib_render_image_part_on_drawable_at_size(0, 0, w, h, + 0, 0, tn->w, tn->h); + imlib_free_image(); + + return 1; +} + void img_check_pan(img_t *img, win_t *win) { if (!img || !win) return; @@ -149,27 +175,6 @@ int img_fit(img_t *img, win_t *win) { return oz != img->zoom; } -int img_load_thumb(thumb_t *tn, const char *filename) { - int w; - int h; - - if (!tn) - return 0; - - if (!_imlib_load_image(filename)) - return 0; - - w = imlib_image_get_width(); - h = imlib_image_get_height(); - - imlib_context_set_drawable(tn->pm); - imlib_render_image_part_on_drawable_at_size(0, 0, w, h, - 0, 0, THUMB_SIZE, THUMB_SIZE); - imlib_free_image(); - - return 1; -} - void img_render(img_t *img, win_t *win) { int sx, sy, sw, sh; int dx, dy, dw, dh; |