I am reading Charles Petzold's "Applications = Code + Markup" treatise on WPF.
I have a history with this author. When I was still in High school (or maybe it was mid school), I thought I need to branch out into programming. So I learnt Borland Turbo C. After which I learnt Borland Turbo C++. I always found Windows 3.1 easier to use – well there was nothing to learn, no commands just point and click. So I always wanted to write programs that would run under Windows. This was before internet, and this was in India. So we never had resources like you guys do here in America. Things are different now I am sure, but I am talking maybe the 1980's. So somehow, I managed to land my hands on "Programming Windows". It was sitting in the Army Library. I had no idea who Charles Petzold was, but I brought that book home. I read that book cover to cover, and in a way I owe my career to this man. I understand Windows to its core, because I read that book. I still clearly remember WndProc and message processing because he laid it out very neatly in that book. I can still tell you the difference between PeekMessage and GetMessage because he told me so. And I can tell you, I played a LOT with it, because I wrote an animated wallpaper by passing GetWindow(Null) ß to get a handle of the desktop window and then paint it, and I know they broke it in Windows 98, because it was "insecure".
So, when Charles wrote another book on WPF. I just had to get it. Reading this book in a lot of ways is like a return to Childhood for me. I am in Chapter 2 so far, and much of what he has talked of, even though it is WPF/.NET specific, I was already familiar with – thanks to his excellent previous books that set a good base.
But then I discovered something new, that I decided to share in this blog post.
This is from Chapter 2.
sRGB is represented as A,R,G,B – each of these go from 0-255. This is adequate for representing colors on CRTs, but is inadequate for say a printer that has a much higher range of color display. Or for instance, new fangled LCD monitors that are so darned accurate (surprised to hear that?). So welcome scRGB, which takes 4 values, much like ARGB, but they are float. Interestingly, 0 (RGB) means 0(scRGB). 255(RGB) means > 1(scRGB), but the relationship between them is not linear. Values greater than 1 are there to accommodate colors that are beyond the gamut of video displays (but say a Printer will make sense of them).
Quoting Charles, Cathode ray tubes do not display light in a linear fashion. The light intensity (I) is related to voltage (v) as I = V^(gamma). Gamma is somewhere between 2.2 and 2.5. Add to the complexity, human eyes perceive light as non-linear too. For the most part, the non-linearity of the human eye and the non-linearity of a CRT offset each other. But the relationship isn't exactly linear.
scRGB on the other hand, is designed to be linear in relationship to light intensity. So, the relationship between scG and G is as follows
scG is roughly equal to – (G/255)^2.2
R and B have the same relationship
The transparency channel has a simpler relationship though
scA = A/255
That makes sense.