Scaling Images

I have an app where you can resize an image with your fingers. At the moment, the resizing is a bit slow. im using the standard Juce `Image.rescaled’ method.

My question is how to do this as efficiently (quickly) as possible. Firstly, is there some way to make OpenGL do the scaling for me. If I make my component use the OpenGL renderer (ie attach to an OGL context), i believe it’s using openGL for some things, however, there appears to be no difference in performance. Also, `paint’ is now called twice, is this normal?

For example, for OGL, should i be creating the image as a `OpenGLImageType’ for this to work. It feels like it’s using software to scale then using OGL to render. am i right, and is there a way to use opengl to scale.

thanks for any tips.

It’s definitely going to be slow that way, since you’re creating a new image each time. There’s not really any way to speed that up without just changing your approach.

To do it efficiently, I’d suggest that you keep drawing the original (unmodified) source image, but vary the transform applied to it while the user is adjusting it (see drawImageTransformed). If it’s a purely visual thing, that’d be all you need to do, but of course if you need the adjustment to be applied to the image, you would do it via Image::rescaled as a final step when they release their control.

Thanks for your suggestion.

What i do now is draw from the original image when resizing, but when resizing finishes, i create a new image. This is also because i’ll need to repaint from this image and importantly, the final image needs to be generated in high quality, whereas whilst resizing, performance is optimal.

The performance is not brilliant. in fact, it’s not much different than before. However, this approach is something i had to do anyhow because of the final high quality requirement. before, i was generating the image every time in low quality, so i never got around to the high quality final.

I’m going to stick with it like this unless i have any better ideas or figure out if i can use OGL.

If you’re drawing from an OpenGLImage, the performance and quality should both be very good…

There must be something daft im doing here.

Im trying to run my app attached to an OpenGL Context under Windows. As in the jucedemo, i attach my context to the top level component.

Firstly, it works, but it appears to be drawing everything twice. When i move a component, i get a flicker as it moves (this doesn’t happen if i do not attach the GL context). Paint is indeed called twice, once for the windows paint and another time inside the GL thread. is this normal?

So, now i need to put my image into type `OpenGLImageType’ i do this by creating a second image and copying over the first one. Since this can only be done when the OGL context is active, i try to do this the first time in paint. This fails however, because the first time is the software renderer.

ok, what i then do is OpenGLContext::getCurrentContext(). if this is set, i create it. then a draw with this OGL image. but unfortunately i get a GL_INVALID_OPERATION in

any ideas?