Anti-aliasing filter for Image minification

Hullo there,

is there a way to enable anti-aliasing for minified Images that I render using the Graphics object within an OpenGL context? I can’t find any option to generate “mip maps” for the Image, or to tell the Graphics object to do adaptive downsampling with a low-pass filter, or the like.

With the high-contrast edges in the image below the artifacts are well visible, it seems like no texture filtering is applied. At “screen resolution” the image looks fine, but if it is significantly scaled down you can observe the typical aliasing artifacts from resampling the image without applying a smoothing operation beforehand.


wireframe-small

Am I missing something, or would I have to implement some form of anti-aliasing myself, e.g. generating a stack of pre-downsampled versions at different resolutions, or using an OpenGL texture with mipmaps and let the hardware handle it? In my case the latter would probably be easier since I’m rendering everything in an OpenGL context already.

Thank you!

1 Like

I’d love to be proven wrong here, but I don’t think there is. My understanding is when you use an OpenGL context like this, and still use juce graphics objects for drawing, it’s all rendered on the cpu into a frame buffer, and OpenGL just displays that pre-rendered image.

If you were to bind the image as a texture, you can leverage antialiasing in OpenGL and that would work out, but if you go that route just be aware any native OpenGL rendering takes place before any juce graphics rendering, so it has to be native OpenGL in the back and juce over the top.

Oh another quirk worth mentioning. The default juce image resampling looks really bad when pushed past a 50% reduction in size. Rather than going straight to 25%, if you do 2 passes of 50% it looks way better. So definitely try the mipmap route, it works well by downsizing in steps of 50% then selecting the nearest size and doing your final resize from there.

1 Like

Hi @Fandusss and thanks for the info! I just tested drawing the image without any OpenGL context involved and the standard software renderer produces the same kind of artifacts, so it seems that anti-aliased image minification is just currently unsupported by JUCE.

In my setting this is not a big deal since I can render the image as an OpenGL texture with mipmaps and don’t have to implement the downscaling/smoothing myself. In general it would be a nice addition to the Graphics implementation to support anti-aliasing of downscaled images without requiring the user to implement their own downsampled image pyramid.