Jump to content
  • Advertisement
Sign in to follow this  
darenking

SOLVED - C++ ALLEGRO - trying to read and put pixels... help!

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

Howdy! Here's the situation. I've got an 8 bit bitmap. It's grayscale, so all the pixels are varying shades of grey or else black or white. I've put a black pixel in the top left corner, then a white pixel beside it. When I getpixel like this: getpixel(bitmap, 0, 0) getpixel(bitmap, 1, 0) ...I thought I'd get zero for the black pixel and 255 for the white pixel, but for the white pixel I get 16777215. What could it all mean? If anyone knows the answer to this, maybe you can help me write some pixels too... [Edited by - darenking on August 13, 2005 9:26:34 AM]

Share this post


Link to post
Share on other sites
Advertisement
I've investigated further and it seems that as I set_color_depth(32) all BITMAPs will be loaded in as 32, regardless of the bitdepth of the orginal file.

Makes sense?

If that is the case, is there a way or loading in some BITMAPs as 8 bits when you're in 32 bit mode?

Share this post


Link to post
Share on other sites
Here's a way that seems to work. For my white pixel it results in 255, and for the black pixel it results in 0. Haven't tested it on greys...

int colour, alpha;
colour = getpixel(bitmap, 0, 0);
alpha = getr(colour) + getg(colour) + getb(colour);
alpha = MID(0, alpha/2-127, 255);

Although it seems to produce the right result, I'm not happy using it as I don't understand exactly how it works! So if anyone can explain to me how it works, and more importantly point out any pitfalls, ie that it may not be accurate, I'd be very grateful.

I don't know what the MID function does, can't find it on google apart from when applied to strings.

Presumably getr, getg and getb miraculously extract the colour red, green or blue from the integer 'colour', but I'd really like to know how!

Anyone like to explain to a dummy?

Share this post


Link to post
Share on other sites
Ok I guess I will try to be helpfull one more time, although I have never used allegro but im guessing this should be accurate.

The getpixel function is returning an integer which is 32 bit that is why you get in the case of white 16777215 because all the bits are 1(edit: except the alpha which must be zeros because a 32bit integer with all bits set to 1 is 4294967295). Within this integer you have 4-8 bit channels -> Red,Green,Blue,Alpha, all of these are 8 bits each.

This means that the getr,getg,getb functions pull the 8 bit colors out of the 32 bit color, probably through a bitwise shift.

I have never seen an operation like this to get the alpha from an integer, so im not sure what is going on there.

The good news is that you are using a grey scale image so in that case Red = Green = Blue so you could just use getr and have your 0-255 value.

Share this post


Link to post
Share on other sites
I see what you mean; it's grey so all three colours are of the same intensity? So instead of this...

colour = getpixel(bitmap, 0, 0);
alpha = getr(colour) + getg(colour) + getb(colour);
alpha = MID(0, alpha/2-127, 255);

I could do this...

int colour, alpha;
colour = getpixel(bitmap, 0, 0);
alpha = getr(colour)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!