Jump to content
  • Advertisement

Archived

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

Glyce

Color Replacement

This topic is 5415 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone have any information or tutorials about replacing one color with another in an image? I''m looking for either Bitmap, JPEG, or GIF.

Share this post


Link to post
Share on other sites
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!