Mini-announce: AC-Color 1.1.3

I just uploaded a new version of the ever-unpopular AC-Colour package. (Yes, there's a country where it's spelled that way.) What it already did: Provides a simple strict unboxed RGB colour type, with arithmetic. The three channels can be either Double or Word8. (And there's some low-level hackery to convert between the two. For some reason just using "floor" is awesomely slow, but talking to GHC.Prim directly is much, much faster... which unfortunately makes this package far less portable than it should be!) What it does now: Colour maps. Give it some control points, and it'll (linearly) interpolate between them to give you a function Double -> Colour. (I haven't seen anything else on Hackage that will do this out-of-the-box. I've seen linear blends between two colours, but not fully automatic piece-wise linear maps like this.) Now obviously none of this is terribly earth-shattering. But I find myself needing this often enough that it's annoying to have to spend 10 minutes coding and debugging it every single time I want it. Maybe somebody else will find a use for it too. I paid special attention to trying to make the colour maps as general as possible. (E.g., the parameter range isn't limited to [0..1], it's arbitrary. Going off the end of the range produces sensible results. You can make the map loop. And so on.) Maybe if I'm feeling ambitious I'll try 2D colour maps. (Of course, the problem there is that your control points need not be coplanar - or even form a regular grid!)

Andrew Coppin wrote:
I just uploaded a new version of the AC-Colour package...
Thanks for this. Your algorithm for scaling brightness is not correct however. The RGB values in all popular image formats are not linear. They use a gamma transfer function. So your algorithm will indeed change the colors in an image, not just its brightness. In some cases the change in color can be quite drastic. For a long-winded explanation and many examples, see: http://www.4p8.com/eric.brasseur/gamma.html You may want to implement one of the popular gamma transfer functions, such as BT.709 or sRGB. The former may also be useful for your AC-PPM package, since the PPM image format uses it, as specified in its documentation: http://netpbm.sourceforge.net/doc/ppm.html sRGB is used in most other popular image formats on the web nowadays.
Colour maps. Give it some control points, and it'll (linearly) interpolate between them
Your algorithm for this is actually not linear at all, since RGB values are generally not linear, as above. Regards, Yitz

Yitzchak Gale wrote:
Andrew Coppin wrote:
I just uploaded a new version of the AC-Colour package...
Thanks for this.
Your algorithm for scaling brightness is not correct however. The RGB values in all popular image formats are not linear. They use a gamma transfer function.
My code operates in the linear RGB colourspace. If you want to operate on some other colourspace (e.g., sRGB), you're going to need to convert from it after you load data, and convert to it before you save data. (Personally, I've always considered the gamma transfer function to be a bug. It only exists due to the faulty design of early CRT systems, and it really should have been done away with years ago, but never mind...)
participants (2)
-
Andrew Coppin
-
Yitzchak Gale