nfnt/resize — pull request #2 by blevin (2013-03-17 05:48:04+00:00)
Title: Add gamma / srgb fix

Hello Jan,

Thank you for your high quality image resizing library. I am working on a software rendering project in go today and needed a resize library to prepare mipmaps for texturing. Yours was easy to integrate and gives nice results.

One thing I noticed is that it does not seem to handle gamma. I only noticed because this is an issue I have had to wrestle with in my renderer. It seems the go image libraries do not address the question of color spaces or gamma correction, instead they simply assume values are in sRGB. This is a decent assumption since it is such a broadly used standard, however it means the color values are not energy-linear, and so we cannot do things like linear-interpolate colors or apply filters without having to correct for this.

I linked to a web page that describes the issue pretty well, and came up with a fix. Since you had already taken the step of providing high-quality reconstruction filters (Lanczos) I thought you might be interested. I ran the benchmark and it added about 15% more runtime. Feel free to use it, change it, or ignore it.

Dankeschön,
Brett.

...

Go's image and color libraries do not address the issues of color
profiles or gamma; instead, they appear to use the common working
assumption that colors are expresed in sRGB. This can be an issue
when doing things like resampling an image, since applying linear
operators require values to be an in linear space, not an exponential
space like sRGB. This page has some examples:

http://www.4p8.com/eric.brasseur/gamma.html

This change adds an internal conversion between sRGB and linear
before resampling the signal. It also makes sure to separate alpha,
which is pre-multiplied in color.Color. With this change, the Dalai
Lama example from the page above scales as expected.