diff options
author | nycex <nycex@cccp.org> | 2020-03-27 01:52:56 +0100 |
---|---|---|
committer | Harry Jeffery <harry@exec64.co.uk> | 2020-05-21 11:22:47 +0100 |
commit | bdfa1fcbae4ce41ecfc92ab0a04a0262875b1730 (patch) | |
tree | 8e69ad483439f4545ac2c9654453351ed7c177fa /src | |
parent | a8c1ffa3cf5e138c56a09f71f636d3dc5d49101f (diff) | |
download | imv-bdfa1fcbae4ce41ecfc92ab0a04a0262875b1730.tar.gz |
fix nearest_neighbour upscaling method
Diffstat (limited to 'src')
-rw-r--r-- | src/canvas.c | 32 | ||||
-rw-r--r-- | src/canvas.h | 4 | ||||
-rw-r--r-- | src/imv.c | 5 |
3 files changed, 25 insertions, 16 deletions
diff --git a/src/canvas.c b/src/canvas.c index eaec538..c185c06 100644 --- a/src/canvas.c +++ b/src/canvas.c @@ -10,6 +10,7 @@ #include <stdarg.h> #include <stdio.h> #include <stdlib.h> +#include <stdbool.h> #ifdef IMV_BACKEND_LIBRSVG #include <librsvg/rsvg.h> @@ -203,7 +204,7 @@ static int convert_pixelformat(enum imv_pixelformat fmt) static void draw_bitmap(struct imv_canvas *canvas, struct imv_bitmap *bitmap, int bx, int by, double scale, - enum upscaling_method upscaling_method) + enum upscaling_method upscaling_method, bool cache_invalidated) { GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); @@ -219,9 +220,19 @@ static void draw_bitmap(struct imv_canvas *canvas, glBindTexture(GL_TEXTURE_RECTANGLE, canvas->cache.texture); - if (canvas->cache.bitmap != bitmap) { - glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + GLint upscaling = 0; + if (upscaling_method == UPSCALING_LINEAR) { + upscaling = GL_LINEAR; + } else if (upscaling_method == UPSCALING_NEAREST_NEIGHBOUR) { + upscaling = GL_NEAREST; + } else { + imv_log(IMV_ERROR, "Unknown upscaling method: %d\n", upscaling_method); + abort(); + } + + if (canvas->cache.bitmap != bitmap || cache_invalidated) { + glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, upscaling); + glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, upscaling); glPixelStorei(GL_UNPACK_ROW_LENGTH, bitmap->width); glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); @@ -232,14 +243,7 @@ static void draw_bitmap(struct imv_canvas *canvas, glEnable(GL_TEXTURE_RECTANGLE); - if (upscaling_method == UPSCALING_LINEAR) { - glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - } else if (upscaling_method == UPSCALING_NEAREST_NEIGHBOUR) { - glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - } else { - imv_log(IMV_ERROR, "Unknown upscaling method: %d\n", upscaling_method); - abort(); - } + glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, upscaling); const int left = bx; const int top = by; @@ -269,11 +273,11 @@ RsvgHandle *imv_image_get_svg(const struct imv_image *image); void imv_canvas_draw_image(struct imv_canvas *canvas, struct imv_image *image, int x, int y, double scale, - enum upscaling_method upscaling_method) + enum upscaling_method upscaling_method, bool cache_invalidated) { struct imv_bitmap *bitmap = imv_image_get_bitmap(image); if (bitmap) { - draw_bitmap(canvas, bitmap, x, y, scale, upscaling_method); + draw_bitmap(canvas, bitmap, x, y, scale, upscaling_method, cache_invalidated); return; } diff --git a/src/canvas.h b/src/canvas.h index 03425d9..fc043e5 100644 --- a/src/canvas.h +++ b/src/canvas.h @@ -1,3 +1,5 @@ +#include <stdbool.h> + #ifndef IMV_CANVAS_H #define IMV_CANVAS_H @@ -46,6 +48,6 @@ void imv_canvas_draw(struct imv_canvas *canvas); /* Blit the given image to the current OpenGL framebuffer */ void imv_canvas_draw_image(struct imv_canvas *canvas, struct imv_image *image, int x, int y, double scale, - enum upscaling_method upscaling_method); + enum upscaling_method upscaling_method, bool cache_invalidated); #endif @@ -92,6 +92,7 @@ struct imv { /* dirty state flags */ bool need_redraw; bool need_rescale; + bool cache_invalidated; /* traverse sub-directories for more images */ bool recursive_load; @@ -1185,7 +1186,7 @@ static void render_window(struct imv *imv) double scale; imv_viewport_get_offset(imv->view, &x, &y); imv_viewport_get_scale(imv->view, &scale); - imv_canvas_draw_image(imv->canvas, imv->current_image, x, y, scale, imv->upscaling_method); + imv_canvas_draw_image(imv->canvas, imv->current_image, x, y, scale, imv->upscaling_method, imv->cache_invalidated); } imv_canvas_clear(imv->canvas); @@ -1229,6 +1230,7 @@ static void render_window(struct imv *imv) /* redraw complete, unset the flag */ imv->need_redraw = false; + imv->cache_invalidated = false; } static char *get_config_path(void) @@ -1650,6 +1652,7 @@ static void command_set_upscaling_method(struct list *args, const char *argstr, } imv->need_redraw = true; + imv->cache_invalidated = true; } static void command_set_slideshow_duration(struct list *args, const char *argstr, void *data) |