Adding RGB Colors

Drakkon

Diamond Member
Aug 14, 2001
8,401
1
0
Anybody with any methods on adding two RGB colors together to produce a a color similar to what you would expect? like if u had #0000FF + #FF0000 not end up with #FF00FF (fucia) but more of a purple (ie #995C99)?
 

Haircut

Platinum Member
Apr 23, 2000
2,248
0
0
If you want to find the colour that is in between the two other colours then you can add up the RGB values and divide by two

i.e. #0000FF and #FF0000 will become #FF00FF/2 which would be somewhere around #7F007F
 

MonkeyK

Golden Member
May 27, 2001
1,396
8
81
No way.

(000100 + 000001)/2 = 000080, hardly halfway between. You need to split the color into each 8 bit component, add those and divide by two seperately.

I am not sure which mask is which, but something like this. (Have not tried it yet)
R1 = color1 AND FF0000
G1 = color1 AND 00FF00
B1 = color1 AND 0000FF

R2 = color2 AND FF0000
G2 = color2 AND 00FF00
B2 = color2 AND 0000FF

R3 = (R1+R2)/2
G3 = (G1+G2)/2
B3 = (B1+B2)/2

color3 = R3 OR G3 OR B3

edit: you also need to look out for overflow when computing R3 in my example above.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
you divide them into seperate bytes for R, G, and B, and then average them.

Red: FF0000
Blue: 0000FF

Divided up:

FF 00 00
00 00 FF

Averaged:

7F 00 7F

Like Haircut said.
 

Haircut

Platinum Member
Apr 23, 2000
2,248
0
0
MonkeyX, I kinda assumed he would separate the r, g and b components out when doing the calculation.

One thing I should point out with this method is that it will not find the colour you would get by mixing two pigments of the colours, it merely gives you the colour in the middle of the two on an RGB colour wheel, to get an approximation of that would be a little more complicated and would probably involve converting the RGB values to another (subtractive) format, averaging those values and converting back to RGB.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: Haircut
One thing I should point out with this method is that it will not find the colour you would get by mixing two pigments of the colours, it merely gives you the colour in the middle of the two on an RGB colour wheel, to get an approximation of that would be a little more complicated and would probably involve converting the RGB values to another (subtractive) format, averaging those values and converting back to RGB.

This method may not give the same results as mixing inks, but it does give the same results as blending in photoshop