
Author 
Topic: Determining original color... (Read 303 times) 

rgovostes

Determining original color...
« on: Jun 19^{th}, 2004, 1:22am » 

I have puzzled over this for a while, and I can't figure out if what I'm trying to do is possible. As many of you have experience with such things, I was hoping one could help? I am trying to determine the shade of red and the transparency used to tint a graphic. I know that what was once white is now RGB(255, 171, 171) and once black is RGB(84, 0, 0). I believe the function for blending two colors is something like this... Code:function blendColors(color one, color two, float ratio) { float r, g, b; r = red(one) * ratio + red(two) * (1  ratio); g = green(one) * ratio + green(two) * (1  ratio); b = blue(one) * ratio + blue(two) * (1  ratio); return color(r, g, b); } 
 You could rewrite one of these to find the value of a in terms of a color value, like Code: 255 * a + g * (1  a) = 171 .'. a = (171  g) / (255  g) 
 But for red you get "a = 1" which it does not... Any help would be appreciated.

« Last Edit: Jun 19^{th}, 2004, 1:22am by rgovostes » 




rgovostes

Re: Determining original color...
« Reply #1 on: Jun 19^{th}, 2004, 1:49am » 

A friend determined it to be RGB(255, 0, 0) at 33% opacity, which is true (255 / 84 = 3; 255 / 171 = 1.5), but is there a way to compute this?




narain

Re: Determining original color...
« Reply #2 on: Jun 19^{th}, 2004, 4:54pm » 

After a little algebra, I got this: Find the amount of change in the colour, ie. final (tinted) value minus original value. In your case, for the red channel, the change from black is (84  0) = 84 and change from white is (255  255) = 0. Call these values dr0 and dr1. Then... ratio = (dr0 + dr1) / 255; tint_red = 255 * dr0 / (dr0 + dr1); So ratio = (84 + 0) / 255 = 0.33 and tint_red = 255 * 84 / (84 + 0) = 255 And hey presto, it's RGB (255, something, something) at 33% opacity. You can use the second formula on the changes in green and blue to get the tint colour. (ratio should come out to be the same for all of them, otherwise you have been deceived: it's not a simple tint.)




