thisandagain/color — pull request #9 by mpstx (2013-02-12 22:51:37+00:00)
Title: CIE Lab Colorspace

Hi. I needed CieLAB colorspace conversion for a project I'm working on, so I thought I'd contribute to your well-organized EDColor tools. I appreciate the fact that there are tests and an example project, so I tried to include updates to those as well.

One interesting thing though....

UIColor API's use 0.0 to 1.0 to represent the color components. You've been able to stick with that in the categories you've developed so far. I think most people will expect that to be the valid range of values for each of the color components in most colorspaces.

CieLAB is a bit of a different animal though. It's a non-linear colorspace. Theoretically, L has a range of 0 to 100, A has a range of +/- 200, and B has a range of +/- 500. In practical terms though, on the current iOS devices, with the default white-point I've chosen to fix the class on, L has a range of 0 to 100, A has a range of -86 to 98, and B has a range of -107 to 95. A and B's ranges depend on the chosen white-point and the device's color gamut. When testing and checking color conversions with online tools like http://www.easyrgb.com/index.php?X=CALC , these strange looking L,A,B numbers are what you have to plugin to get something useful out -- whereas when putting in RGB values, there is a RGB0-1 mode. Also, other [Cie]LAB references refer to values in terms of these awkward but standard value ranges that change depending on device capabilities and white-point.

My initial leaning is to stick with the CIE LAB standard ranges in this UIColor category as it's a bit easier to connect the dots when you consult other sources on CIE Lab values and colors. If you think it's a big deal though we could do something -- i.e. normalize 0.0 to 1.0 to these ranges, or split the API a bit to have one set of raw methods (which use the standard but awkward CieLAB ranges), and one set of methods which use the standard UIColor 0.0 to 1.0 ranges.

Anyways, hope this is a useful contribution.

- Matt