Archived

This topic is now archived and is closed to further replies.

Glyce

Color Replacement

Recommended Posts

int i,j,current;
unsigned char temp;

for(i=0;ifor(j=0;jcurrent=(i*height+j)*3;
// INSERT BLOCK HERE
}
}

Insert any of these (depending on which you want)

RED/GREEN SWAP:
temp=data[current];
data[current]=data[current+1];
data[current+1]=temp;

RED/BLUE SWAP:
temp=data[current];
data[current]=data[current+2];
data[current+2]=temp;

GREEN/BLUE SWAP:
temp=data[current+1];
data[current+1]=data[current+2];
data[current+2]=temp;

Share this post


Link to post
Share on other sites
unsigned char* temp; // make it a pointer

And just to clarify, the block is supposed to loop through each pixel, assuming you want to swap the red channel of the image with the green channel / etc.

Share this post


Link to post
Share on other sites
replacing color a with color b, fuzzyness f:


for each pixel
dr = pixel.r - a.r
dg = pixel.g - a.g
... same for blue
d = sqrt(dr*dr+dg*dg+db*db);

if (d > fuzzyness) skip to next pixel
else factor (type float) = (float)d / (float)f;

pixel.r = a.r * factor + b.r * (1 - factor)
.. same for green and blue components



this pseudo code should replace all colors within certain range from a to b. fuzzyness is the "tolerance" ie higher fussyness will probably cause more colors to be converted from a to b (experiment with it).

You can load images with image loading libraries such as DevIL, Corona and NextGenIPL (there are more). Most of them support gif/bmp/jpeg/png and other exotic formats.





[ Galactic Conquest | Bananas | My dead site | www.sgi.com | Goegel ]

Share this post


Link to post
Share on other sites