drawImage performance on retina ipad with non-retina images


#1

If I create an Animated Application template in the projucer, and set it to display a fullscreen image that scrolls continuously, when I run it on an ipad air 2, I get approximately 27fps. The image is ARGB , fullscreen (but not retina), and I draw it with

drawImageAt(img, 0,0);

Now, if I go into juce_mac_CoreGraphicsContext.mm and in the CoreGraphicsContext::drawImage method add :

CGContextSetInterpolationQuality (context, kCGInterpolationNone);

just before the call to CGContextDrawImage (context, imageRect, image);

Then suddenly I get 60 fps !

The problem does not occur if I draw a retina image (if I double the size of the image and draw it with drawImageTransformed(img, AffineTranform::scale(0.5f)) )


#2

What’s the performance like if you do

g.setImageResamplingQuality (Graphics::ResamplingQuality::lowResamplingQuality)

?


#3

With lowResamplingQuality (which sets kCGInterpolationLow) , it is back to 27fps, it’s is really the kCGInterpolationNone flag that seems to make a difference. I can’t test on a retina mac but I would not be too surprised if it behaves the same way.


#4

I’ve added a new Graphics::ResamplingQuality to the develop branch: Graphics::ResamplingQuality::noResampling.

Doing

g.setImageResamplingQuality (Graphics::noResampling)

should do what you want.


#5

I’ll use that, thanks t0m !


#6

What’s the difference between lowResamplingQuality (which is described as nearest-neighbor in the comments), and the new noResampling ?

Actually, in the CoreGraphicsContext it seems like lowResamplingQuality is not at all mapped to nearest neighbor resampling, but rather to kCGInterpolationLow, which I suppose does some cheap filtering. So maybe the comments are wrong?

Also, how is mediumResamplingQuality handled in CoreGraphicsContext::setInterpolationQuality? Relying on default resampling mode?


#7

I think you’re right (that lowResamplingQuality should have been kCGInterpolationNone), and it seems that CoreGraphicsContext::setInterpolationQuality is missing an entry for the mediumResamplingQuality (which would be kCGInterpolationLow ) ?


#8

Yes exactly, this must be the case. Unless the other GraphicContext implementations also apply some sort of filtering even with the lowResamplingQuality, in which case the comments should be corrected accordingly and the new noResampling quality actually make sense. But otherwise it doesn’t =)

I think it’s very valuable to have a nearest-neighbor image resizing alternative available in a well-defined way on all platforms. Not just for performance reasons, but when dealing with such things as monochromatic graphics or strictly rectangular “perfect shapes”-GUI elements, it’s really handy to be able to resize without applying filters and introducing anti aliasing artifacts.


#9

Yes, you’re correct - lowResamplingQuality should actually map to kCGInterpolationNone.

However, the risk here is that people’s existing JUCE apps may suddenly look worse…


#10

What is the behavior in other GraphicsContext implementations? Does lowResamplingQuality disable resampling (i.e. use nearest-neighbor policy) correctly there?


#11

In some places, yes. It’s hard to get this working completely consistently across all platforms.


#12

If it is not realistic to completely harmonize the behavior across platform, at least try to document the different behaviors. I know i’ve been struggling trying to disable resampling also with the software renderer on windows platform in the past, without really knowing whether it’s supposed to work.


#13

OK, I’ve just changed things again.

Graphics::noResampling no longer exists - please use Graphics::lowResamplingQuality.