Jump to content
  • Advertisement
Sign in to follow this  
MTclip

ignoring bits ..DWORD ?

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

ok i have a DWORD* that contains the image info.. now what i would like to do is ignore all of the bits except the alpha bits.. the first 2 values i believe..

imageData = (DWORD*)alphaRect.pBits;

for( int y = 0; y < pLevel->m_vTextures->m_frameHeight; y ++)
   {
     for( int x = 0; x < pLevel->m_vTextures->m_frameWidth; x++)
      {
	  // divide by 4   alpha | red | green | blue
          int index = y *alphaRect.Pitch / 4 + x;
          if (imageData[index] ==  /* I JUST WANT TO CHECK THE ALPHA HERE*/)
	  imageData[index] = 0xffff0000; //red
      }
   }


i guess that might not make a lot of since .. but if I have this 0xffffffff -> ----------------^(how do i ignore every thing from here on ) giving me 0xff.. also im gonna check on this .. but what are the "0x" for thanks ;P

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
You could try using logical AND:

0xFFFFFFFF & 0xFF000000 = 0xFF000000

would that work?

Oh, and the 0x tells you that the number is in base-16 (hexidecimal)

Share this post


Link to post
Share on other sites
Quote:
Original post by MTclip
ok i have a DWORD* that contains the image info..
now what i would like to do is ignore all of the bits except the alpha bits..
the first 2 values i believe..
*** Source Snippet Removed ***

i guess that might not make a lot of since .. but
if I have this 0xffffffff ->
----------------^(how do i ignore every thing from here on )
giving me 0xff..


also im gonna check on this .. but what are the "0x" for

thanks ;P


Are you talking about 24-bit images?

a simple AND should do the trick:

var & 0xff000000

Share this post


Link to post
Share on other sites
the 0x signifies that this is an address stored in Hexadecimal form, 0-9 and A-F represent 10 through 15 in decimal....
One way to get the 2 highest order bits would be to bit shift all the other bits off the end, and then bit shift back. However an easier solution just occured to me and that would be to perform an AND operation ( & ) with 0xff000000, this should tell you what the two high order bits are. hope that helps

EDIT: beaten to the punch twice over!! damn, at least i tried.

Share this post


Link to post
Share on other sites
hmm .. ok i understand that it is a hexadecimal..

im not sure what you mean by &....

it is a 32bit image
basically i only want to check the alpha part of the image ... thus allowing the other colors to be anything... i think i just a revalation while typing so im gonna try something.... base on what all of you said...

;P

EDIT::: I PLUGGED IT IN LIKE THIS


if (imageData[index]& 0xFF000000 == 0xFF000000 /*== 0xff*/)
imageData[index] = 0xffff0000; //red


did not quite do what i thought.. but that was interesting
turned every thing sparkley red....

Share this post


Link to post
Share on other sites
ahh ha.. got it

if (imageData[index] & 0xFF000000 )
imageData[index] = 0xffff0000; //red

thanks ...

Share this post


Link to post
Share on other sites
-- looks as if i spoke to soon...

im actually not to sure what that code above actually does.. it apeared to work until i did further testing...

... what exactly was
if (imageData[index] & 0xFF000000 )
.... that doing

I need it to only test the imageData against the 0xff
so that the rest of image data can be any thing else

im reading up on the other bitwise stuff " | & ^ "


again thanks for anyhelp :p


Share this post


Link to post
Share on other sites
Okay you'll have to jump down to the binary level to understand bitwise operators
first here's some random dword that just happened to jump into my head:
0x9CCA5B2D - 10011100110010100101101100101101

Now if you only want to read the first 8bits of that (the alpha byte)
then you use the following hex numeral:
0xff000000 - 11111111000000000000000000000000

As you can see in it's binary form it only marks the first 8 bits of the the number as true (since those are the exact ones you want to extract)
When you use the bitwise AND operator it returns a result where each bit is only true if that same bit in both original values is also true. like so:

0x9CCA5B2D - 10011100110010100101101100101101
0xff000000 - 11111111000000000000000000000000 &
---------------------------------------------
0x9C000000 - 10011100000000000000000000000000
---------------------------------------------

If you want to turn that result into a single char value then just bitshift it to the right 24 bits (3 bytes):
char alpha=(imageData[index]&0xff000000)>>24;

so you'll end up with:
0x0000009C - 00000000000000000000000010011100

which will be clipped to a single char of:
0x9C - 10011100 - 156


The OR operator returns a 1 in the result when either of the bits in the 2 originals contains a 1

and the XOR returns a 1 when either one or the other contains a 1 (but not both)

& - AND
| - OR
^ - XOR

I also believe that instead of using the symbols you can use the words themselves in full caps
Hopefully I've written this before you've done a load of reading & found out for yourself so it isn't a total waste :P

[Edited by - ProPuke on July 26, 2005 5:49:47 AM]

Share this post


Link to post
Share on other sites
hey thanks for the nice info..
if you dont mind maybe you can tell me if this is not right..

I am expecting this to only change the pixels with a white(0xff000000) alpha value to a red (0xffff0000)color value



if( (imageData[index] & 0xFF000000) == 0xFF000000 )
{
imageData[index]= 0xFFFF0000;
}




...

Share this post


Link to post
Share on other sites
White is 0xffffffff, not 0xff000000 (the latter is the black pixels).

The mask is 0xaarrggbb (aa=alpha, rr=red, gg=green, bb=blue).
Having R,G and B full (=0xff) gives you white.

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!