Home arrow static arrow Java Programming [Archive] - bitwise
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - bitwise
This topic has 2 replies on 1 page.

Posts:143
Registered: 6/24/04
bitwise   
Jun 29, 2004 7:37 AM



 
could anyone please explain what this snippet of code does here..
for( int 1=0; i<iw*ih; i++)   {   int p = pixels[i];   int r = 0xff& (p >> 16);   int g = 0xff& (p >> 8);   int b = 0xff& (p);   int y = (int) (.33 * r + .56 * g + .11 * b);   hist [y]++;
cheers
Dinaz Sheriff
 

Posts:342
Registered: 5/22/98
Re: bitwise   
Jun 29, 2004 8:12 AM (reply 1 of 2)



 
These lines of code extract red, green and blue values from an int where the second byte contains 0-255 value for red, the next byte for green and the last byte for blue.
This is done by shifting the four bytes in the inrt value to the right in order to place the value of the component you are interested in at the very end of the int (lowest order byte).
The ANDing with 0xff is to make sure you only get the value of the last byte.
<div class="jive-quote">int r = 0xff& (p >> 16);int g = 0xff& (p >> 8);int b = 0xff& (p);</div>

e.g
0xFE00 >> 8 is equal to 0xFE
0xFF & 0x88FE00 >> 8 is also equal to 0xFE.

The byte at the end (00) is lost in the right shift, and the byte at the front (88) is thrown away by the ORing with 0xFF.

I can only assume the next few lines create a histogram, but I am assuming that based on the variable namne. I don't know much about image processing.

<div class="jive-quote">int y = (int) (.33 * r + .56 * g + .11 * b);hist [y]++;
cheers
[/code]

Hope that's helpful, but I doubt it. I am having a few hassles explaining things today; Brain's gone into Homer mode.

Graeme
 

Posts:143
Registered: 6/24/04
Re: bitwise   
Jun 29, 2004 8:47 AM (reply 2 of 2)



 

Hope that's helpful, but I doubt it. I am having a few
hassles explaining things today; Brain's gone into
Homer mode.

Graeme

My brain in always in Homer mode

 
This topic has 2 replies on 1 page.