Thursday, August 18, 2011

The Ramp

[Please note that this post is part of a series describing my first wobbly steps into the world of ICC color profiles. The aim is to build an ICC color profile editor from scratch. Seeing how I started this project with no knowledgde whatsoever on the subject, it's wise to realise that some of my findings described in these posts are incorrect. The incorrect conclusions are usually corrected in later posts. For the whole series in one go, click here.]

Well, I'm not sure if anyone is actually reading this, but I made some progress.

Small steps...

If you remember, last time I figured out that my dirty grays were due to the calibration part of the color profile, and that my dirty screen didn't have anything to do with the color translation math within the profile (I'm not even sure if you can call it that mind you, the math to convert colors is actually done by something called a CMM, but let's not get into that)...

Turns out the stuff that makes my screen itch is indeed part of the video card, and it's called a gamma-ramp.

The numbers within the gamma-ramp are causing the yellow cast.

Then I found two useful functions in the Windows API, to read and set the gamma ramp of the video card.

I then built myself a little component to actually show the curves - a fascinating detour in the world of linear functions, splines and bezier curves - and there I had it...

Of the three colors that make up my screen (red, green and blue) blue gamma was pulled away too much, resulting in unbalanced grays.

Then I figured out that within a color profile, the numbers that look like the gamma ramp, are stored in what's called TRC tags (Tone Reproduction Curve). There's four of those, but my system can only handle three (red, green, and blue, the fourth one is for gray).

Well, so far so good.

I'm now able to browse through a list of color profiles, show the effect on a loaded photo, and show TRC's stored in the profile.

Obviously, the next step is to actually load those curves straight into the video card (and make that optional), so the calibration effect of the gamma curves in color profiles for a display is immediately visible.

Then to complete this phase and to be able to correct the yellow cast, I need to make the curves editable.

But of course I ran into a snag, which I haven't figured out yet.


The snag

The gamma curves differ.

When I read the data directly from the profile, I get different curves then when I read the gamma-ramp from the video card after the profile is loaded.

Quite simple: the profile TRC data can't be applied directly to the gamma-ramp in the video card. There's a bit of calculus involved, and I haven't figured out yet what the formula is.

I now suspect the TRC tags themselves are just a standard setting, and the deviation for dark, middle and light tones sits in a private tag, because the TRC tags in some profiles do not actually point to a collection of numbers at all, but to a small piece of text saying 'gamma 2.2'. I understand what the text means, and gamma 2.2 is easy to create as a lookup table, but now I have to figure out how my gamma ramp in the video card gets out of whack when the curves just state 'gamma 2.2' (because they do in my mysterious spyder profile).

Where are the numbers coming from? If it was just a standard calculation I wouldn't have yellow grays, but neutral grays. No doubt they're coming from another tag in the profile (possibly vendor specific), because my video card doesn't know what 'gamma 2.2' means. It needs the numbers. So... I need to delve deeper into the profile...

I'll get there...

No comments:

Post a Comment