Your code doesn't make use of the colors and their values though. Are you still thinking on how you would make use of those bits?
There are two SEPARATE issues with regards to RGB:
1. Preston mentioning the constant intensity; the idea that, no matter what the mix of RGB components are, it always totals up to the overall intensity value set in the sequence. If I want white, rather than each RGB component displaying 255/255/255, it would be more like 85/85/85. I think that's what is meant...
2. Controlling for intensity variations in the separate colors themselves. For example, a red led that displays "brighter" than a blue led at the same intensity value. This would mean, when mixing for purple, for example, the shade might be affected by the inherent difference in brightness or power of the led color component. This is what Joe is talking about when he mentions separate curves for each color. Controlling for variations in RGB individual color intensity would help with color mixing so that the output color would remain true in the actual display.
First off, you can use a simplified version of the formula in an excel spreadsheet, which will be easier than running code:
Y=(X/255)^G*255 where X is raw DMX value, G is gamma and Y is gamma-corrected DMX
You are completely right about your two points above - however the reality is that the second point may make results of the first point moot. That is, if the blue LED is is actually lower in brightness and is perceived as dimmer, then bluer color will be "dimmer" even if you normalize the DMX values.
Getting the perceived brightness normalized across colors has actually turned into a pretty tough puzzle, because you don't want to effect the hue.
There are some formulas for calculating luminance, but my guess is it will be difficult to do this and preserve predictable color mixing.
Luminance (standard, objective): (0.2126*R) + (0.7152*G) + (0.0722*B)
Luminance (perceived option 1): (0.299*R + 0.587*G + 0.114*B)
Luminance (perceived option 2, slower to calculate): sqrt( 0.241*R^2 + 0.691*G^2 + 0.068*B^2 )
When applying dimming curves to RGB, you can't just apply gamma correction to RGB individually, you have to apply it while in HSV colorspace to the V or intensity, and then let the colorspace conversion handle the reduction in RGB. If you apply dimming to each RGB channel, it really screws with color mixing.
Then there is the interesting area of using LAB colorspace.
Right now I think most of us are using HSV to do color mixing and blends. This lets us blend a single hue value. But the color mixing is light based, so mixing blue and yellow = white, where as in LAB space it would be green, like when you mix paints.
While I ultimately don't think classic displays care about precise color or gamma correction, there are a couple reasons to keep exploring this area:
video projection on a matrix - this requires more "true color" and gamma correction so that things don't look washed out. I'm perhaps a black sheep here as I really have no interest in pixel based matrix's in displays, as to me they just look like low res screens rather than architecturally or landscape integrated lighting.
The LAB colorspace could also be interesting to provide alternative color transitions compared to the classic "rainbow" spread that is familiar. I have other ways of doing custom blends, but LAB might be another option, and more efficient than my current multi-segment envelope approach.
If you want a good geeky article on LAB, check out:
http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/
-Preston