84 points · by jmillikin · 16y ago · 23 comments
1. People writing image scaling libraries are big on speed. Many, like libswscale, are intended for realtime video playback on systems without graphics overlay acceleration. They contain truckloads of shortcuts to cheat wherever possible in the name of performance.
2. A "correct" method requires one of two things:
A. Performing one LUT per input pixel to the tapfilter, plus one LUT per output pixel (see http://news.ycombinator.com/item?id=1142084). This completely eliminates any possibility of SIMD. Other LUT schemes are also possible, like LUT[pixelX][pixelY].
B. Converting the entire image to linear 16-bit colorspace internally, then converting it back. This adds a slow preprocessing (and postprocessing) step and halves the speed of image processing.
Since both have huge speed impacts, most people writing graphics libraries don't like to do them.
Oh, and standard GPU-accelerated overlays can't really do either of these.
Python Image Library does gamma correct rescale by default. I did not realize this until I wrote my own implementation. I thought it would be several times slower than the built in, but it was only 3% slower. Boy was I surprised when I figured out why.
Then here's a simpler explanation:
We need to blend pixel values X and Y.
Normal image-scaling algorithms perform the operation (X+Y)/2, because this is fast.
However, the correct operation is ToNonLinear((ToLinear(X)+ToLinear(Y))/2), because X and Y represent a nonlinear scale, similar to how adding a 60db and 60db sound doesn't result in a 120db sound.
I almost wish gamma was a more obvious encoding process, like gzipping a file, rather than a simple function. That would save a lot of conceptual pain.
Rescaling and in general resampling is a lot simpler. These days it's pretty inexcusable not to do it in linear space. Here's my own exploration of that problem from a couple of years back:
http://petewarden.typepad.com/searchbrowser/2008/08/why-font...
Compositing and interpolating should definitely be done in linear space though.
Pretty sure GIMP’s main goal is to just do what Photoshop does.
Some RAW formats are 14 and some 12. High-end Hasseblads are 16. It is not unlikely that future sensors will go beyond 16 bit. Therefore it makes sense to design the workflow around 32-bit processing. Otherwise you are stuck re-architecting your entire workflow. Witness the number of Photoshop filters which only work at 8-bit.
(As for scaling in particular: many plugins already exist using better methods than bicubic interpolation, and avoiding problems like the lack of gamma correction, etc.)
But I'm not a graphics designer or whatever