Hi, Let's say the monitor is 1920x1080, the image is 4128x3096. It has to be scaled down when we want to see the whole image, but this is currently done without interpolation, and the resulting image looks ugly.
Is it possible to add eg 'Cubic' or 'Linear' interpolation when scaling image down?
-- regards, Mariusz Białończyk https://skyboo.net | https://github.com/manio
I also had the same issue. However I changed the code to leverage the built in OpenGL mipmap based downscaling to help with the look of downscaled images. It works kinda nicely as far as I have tested it.
I've attached the patch file.
diff --git a/src/canvas.c b/src/canvas.c index 2710efd..bae6df2 100644 --- a/src/canvas.c +++ b/src/canvas.c @@ -174,10 +167,14 @@ void imv_canvas_draw(struct imv_canvas *canvas) glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_TRIANGLE_FAN);
- glTexCoord2i(0, 0); glVertex2i(0.0, 0.0);
- glTexCoord2i(canvas->width, 0); glVertex2i(1.0, 0.0);
- glTexCoord2i(canvas->width, canvas->height); glVertex2i(1.0, 1.0);
- glTexCoord2i(0, canvas->height); glVertex2i(0.0, 1.0);
- glTexCoord2i(0, 0);
- glVertex2i(0.0, 0.0);
- glTexCoord2i(canvas->width, 0);
- glVertex2i(1.0, 0.0);
- glTexCoord2i(canvas->width, canvas->height);
- glVertex2i(1.0, 1.0);
- glTexCoord2i(0, canvas->height);
- glVertex2i(0.0, 1.0); glEnd(); glDisable(GL_BLEND);
@@ -222,7 +215,7 @@ static void draw_bitmap(struct imv_canvas *canvas,
const int format = convert_pixelformat(bitmap->format);
- glBindTexture(GL_TEXTURE_RECTANGLE, canvas->cache.texture);
glBindTexture(GL_TEXTURE_2D, canvas->cache.texture);
GLint upscaling = 0; if (upscaling_method == UPSCALING_LINEAR) { @@ -235,19 +228,21 @@ static void draw_bitmap(struct imv_canvas *canvas, }
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);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, upscaling); glPixelStorei(GL_UNPACK_ROW_LENGTH, bitmap->width); glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
- glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA8, bitmap->width, bitmap->height,
0, format, GL_UNSIGNED_INT_8_8_8_8_REV, bitmap->data);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, bitmap->width, bitmap->height, 0,
format, GL_UNSIGNED_INT_8_8_8_8_REV, bitmap->data);
- glGenerateMipmap(GL_TEXTURE_2D); } canvas->cache.bitmap = bitmap;
- glEnable(GL_TEXTURE_RECTANGLE);
- glEnable(GL_TEXTURE_2D);
- glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, upscaling);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, upscaling);
const int left = bx; const int top = by; @@ -267,16 +262,20 @@ static void draw_bitmap(struct imv_canvas *canvas, glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_TRIANGLE_FAN);
- glTexCoord2i(0, 0); glVertex2i(left, top);
- glTexCoord2i(bitmap->width, 0); glVertex2i(right, top);
- glTexCoord2i(bitmap->width, bitmap->height); glVertex2i(right, bottom);
- glTexCoord2i(0, bitmap->height); glVertex2i(left, bottom);
glTexCoord2i(0, 0);
glVertex2i(left, top);
glTexCoord2i(1, 0);
glVertex2i(right, top);
glTexCoord2i(1, 1);
glVertex2i(right, bottom);
glTexCoord2i(0, 1);
glVertex2i(left, bottom); glEnd();
glDisable(GL_BLEND);
- glBindTexture(GL_TEXTURE_RECTANGLE, 0);
- glDisable(GL_TEXTURE_RECTANGLE);
- glBindTexture(GL_TEXTURE_2D, 0);
- glDisable(GL_TEXTURE_2D); glPopMatrix(); }
Seems like there is no good way to attach files here without them getting mangled.. :/
Here is a gist with the patch file: https://gist.github.com/DarkDefender/7d8a53fd1a62f65461e42b32ec56ed67
On Fri, Jan 20, 2023 at 10:41:50PM +0000, Sebastian Parborg wrote:
I also had the same issue. However I changed the code to leverage the built in OpenGL mipmap based downscaling to help with the look of downscaled images. It works kinda nicely as far as I have tested it.
I've attached the patch file. Thank you Sebastian, It is not as good as eg gimp but looks much nicer... And if I understand correctly it is a way faster on GPU then computing it on CPU :)
I applied your patch and here the results for my sample image: https://skyboo.net/temp/imv/before.png https://skyboo.net/temp/imv/after.png
-- regards, Mariusz Białończyk https://skyboo.net | https://github.com/manio
So, is this happening?
What git commit of imv was this patch made for?