Jump to content
  • Advertisement

Archived

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

Asker

Extract Pixel Colors...

This topic is 6154 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

I need some C++ code to extract the color data of every pixel in a 16-color .BMP into an array of ints. I''m planing on using the putpixel(); function in BGI to display the picture Can some one please help me...

Share this post


Link to post
Share on other sites
Advertisement
Okay now i stored the pixel data for a 4-Bit .bmp into a char but every byte is 2 pixel, how can i read the second pixel,

Share this post


Link to post
Share on other sites
You need to use a binary mask to extract the nibble (4bits) that you want:

    
#define HIGH_NIBBLE(x) (x >> 4)

#define LOW_NIBBLE(x) (x & 0x0F)


To get the highest four bits you shift everything over to the right by 4 bits. To get the low four bits you and with 0x0F which is 00001111 in binary. Since x and 0 is 0 and x and 1 is x, this effectively clears out the top 4 bits.

Edited by - invective on November 14, 2001 12:30:30 PM

Share this post


Link to post
Share on other sites
okay I load the byte into a

char color;

and then I do it like this

int low = color && 0x0f;
int high = (color >> 4);

I don''t know if this is the right way, Is it???

Share this post


Link to post
Share on other sites
quote:
Original post by Asker
I don''t know if this is the right way, Is it???


Eternally useful advice: try it out.

Share this post


Link to post
Share on other sites
yeah i have, but it doesn't read all the pixel it skips every other pixel. The first comes out right but the second is just a 1,(is doesn't matter which color the second pixel is it just keeps on coming out as a 1) or is that how it's suppose to be??? or am I doing something wrong??...


Edited by - Asker on November 18, 2001 9:16:46 AM

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!