Skip to main content
gamedev.net
🔒 Locked

Pixel Colour

Started by dachande Jan 3, 2002 at 11:33 AM 2 replies 150+ views
Original Post
dachande
dachande
Hello, Might anyone here have some good code for reading the pixel colour in a bitmap? I simply want to compare each pixel to the colour white using an If statement. Nice and simple, but I seem to be having a lot of problems with it. My current code does not seem to work. Help would be great! Thanks, Dachande
gregd
gregd
For 16 bit bitmaps, refer to my tutorial site: www.darkfusion.f2s.com
Greg Damon
Kwizatz
Kwizatz
assuming you have decoded the file, and have an array of all the pixels in the bitmap (eighter an unsigned char,unsigned short, or unsigned int depending on resolution);

int nWidth; // holds the width of the bitmap in pixels
unsigned char *pData; // if 8 bits per pixel
unsigned short *pData; // if 16 bits per pixel
// if 24 bits per pixel, it gets complicated cos you have to use unsigned char triplets unsigned char pData[ R ][ G ][ B ]
unsigned int pData; // if 32 bits per pixel
int x,y; // coordinates of pixel t read

PixelReaded = pData[(y*nWidth)+x];

and thats it, not sure if thats your question though, that is subject to optimization (removing the multiply), but it is said that multipling is not as slow as it used to be back in the days.



Edited by - kwizatz on January 3, 2002 2:05:04 PM

Edited by - kwizatz on January 3, 2002 2:05:39 PM

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.