Skip to main content
GameDev.net gamedev.net
🔒 Locked

Computing colors

Started by Kucek Feb 27, 2003 at 10:28 AM 4 replies 700+ views
Original Post
Kucek
Kucek
Hi, I''d like to make a 2D picture in grayscale and then change dynamicaly the main color (red for exemple) and compute all the shadows and illumination on my picture based on the gray level. I know i can use : gray * color / 255 but with this white will become my color and i won''t have illumination. I''d like to have something like the texture editor of 3dsmax where you have a gray sphere and when you give a color to the sphere you still have the shadows and illumination (you have colors from black to your new color and from your new color to white). I hope i''m clear enough Thanks, Kucek
JonnyQuest
JonnyQuest
I'm not entirely sure, but if I understand you correctly, you want a transfer function from greyscale to another colour.
You could either do it entirely customly by using a lookup table for mapping brightness to colours - that would give you maximum flexibility. (e.g. 0 maps to [0, 0, 10], 1 maps to [10, 5, 20] etc.)
Other than that you can use colour correction curves which are available in every better graphics program. (I know they're in Paint Shop Pro, the GIMP, Ulead PhotoImpact, etc.)
They basically map a value of a channel (red, green, blue) to another, and you define this using a curve. In the GIMP you find it under Image->Colours->Curves, other programs will be somewhat similar.
For your Red effect, you'd want curves shaped something like:

Red:
____
| /
| /
| /
|/
+--------

Blue & Green:

| /
| /
| /
| /
+--------

Hope this helps in some way or another.

edit: urgh, formatting!

- JQ
#define NULL 1

[edited by - JonnyQuest on February 27, 2003 1:44:20 PM]
~phil
Kucek
Kucek
Hi,
Here's 2 images to show an example :
http://mapage.noos.fr/guillaume.rouchon/gray_sphere.png
http://mapage.noos.fr/guillaume.rouchon/red_sphere.png
(sorry don't know how to put them in the post)

I'd like to know if there's an algorithm were i can compute a red sphere using the gray one ?
I try using lookup tables : i first compute a table for each component (red, green and blue) from black to my color component (red for example) at index 0 to 127 (128 values) then from my color component to white at index 128 to 255. Then i parse my gray sphere and get the color in the lookup table (new_red = TblRed[MaskRed]...)
The problem is that i loose precision, from black to red i could have 255 values and i only have 128 and it's the same from red to white

I'm not sure it can be done in one pass, maybe i should compute my red sphere without illumination (specular color i think ?) first then use a mask to add illumination. But in this case, how can i extract this illumination mask from my gray sphere ?
Lot's of question but i'll be happy if someone can help me

Thanks,
Kucek

edit: oops, posted without login and image not good

[edited by - Kucek on March 2, 2003 4:47:03 AM]
vanillacoke
vanillacoke
It seems like the answer to your question is very simple, so I feel like I''m not really answering the question.

You just map [black...gray...white] to [black...mycolor...white]. To do this you first map [black...gray] to [black...mycolor] and then [gray...white] to [mycolor...white]. Are you asking specifically how to do this? I always just use a linear interpolation for each color, and I never have trouble with a loss of data.
You know what I never noticed before?
Kucek
Kucek
Thanks vanillacoke

Kucek

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.