Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need an algorithm for Multiplying colors

Status
Not open for further replies.

jimmywages

Programmer
Dec 12, 2002
11
0
0
US
Hi.

I need an algorithm to produce the "multiply" effect (as seen on Illustrator and Photoshop). It's not simply multiplying the RGB values, for example the color R:108 G:161 B:162 multiplied by the color R:26 G:9 B: 128 makes R:18 G:7 B:96.

If you know how to do it or know where I can find out, I'd appreciate it a lot! Thanks in advance,

~jimmy.
 
I am not sure, but I think what you are looking for are convolution matrices. Try a search on the Internet for that.

Convolution matrices are associated with the notion of "image filters".Basically, you have a square matrix that is walked around an image, with the center element being the current image pixel.

You obtain the color value of the current pixel in the resulted image by multiplying the two pixel matrices, element by element - not by following the matrix multiplication algorithm.
You add those products and you set the corresponding pixel result in the new image...

If your filter is F[3][3] and the image is A, if I remember correctly, you take an image chunk of A[3][3], where A[2][2] is your current element.
The "filtered" element value is obtained:
A[1][1]*F[1][1] + A[1][2]*F[1][2] +...A[3][2]*F[3][2]+A[3][3]*F[3][3]...
or something very similar to this...

I'm sure I was not extremely clear with this, but the best documentation is the Internet itself. That's how I found out about it in the first place.

Cheers... [red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
once stated: methane@personal.ro
 
A simple way to multiply color values in RGB format:

Code:
void colorMul( int r1, int g1, int b2, int r2, int g2, int b2, int* rr, int *rg, int *rb)
{
    float fr1 = r1 / 255.0f;
    float fg1 = g1 / 255.0f;
    float rb1 = b1 / 255.0f;
    float fr2 = r2 / 255.0f;
    float fg2 = g2 / 255.0f;
    float rb2 = b2 / 255.0f;

    *rr = (int)(fr1 * fr2 * 255.0f);
    *rg = (int)(fg1 * fg2 * 255.0f);
    *rb = (int)(fb1 * fb2 * 255.0f);
}

rr, rg, and rb are the result values:
Use like this:

int r,g,b;
colorMul( 165, 200, 100, 200, 100, 20, &r, &g, &b );


Greetz,
Tobi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top