How to sum RGBA colors

1.3k views Asked by At

I'm searching a way to sum two RGBA colors. Here's what I do :

RGBA c1, c2
RGB c3 = rgba_to_rgb(c1)
RGB c4 = rgba_to_rgb(c2)

RGB r = c3 + c4

RGBA r1 = rgb_to_rgba(r) // I don't know how to implement this function

How can I sum c1 and c2 without converting them to RGB. In my program I have to sum four RGBA colors. I have this instruction :

Color r = 1.f/4 * (c1+c2+c3+c4)

I have to implement the + operator for RGBA colors.

Edit:

For RGB color when sum two colors I do this :

RGB r;
r.red = c1.red + c2.red
r.green = c1.green + c2.green
r.blue = c1.blue + c2.blue

I don't know what to do for RGBA color. My first idea is to convert the two colors to RGB then do the sum (because I know how to do it for RGB colors) then convert back to RGBA. The second solution is to find out how to directly the addition with RGBA colors.

0

There are 0 answers