Reputation: 35
In general, why do we first left-shifted it only to be right-shifted again? Is it related to something like ensuring that pixel value is positive? code Snipped->
for(k=0; k<Width; k++)
{
if(shiftFlag != 8)
{
p1 = pix_rgb[i][2*k] << 24;
p2 = (pix_rgb[i][2*k+1] <<24 ) >>> 8;
tempCount = p1 | p2;
tempCount = tempCount >>> 16;
}
else
tempCount = (pix_rgb[i][k] << 24) >>> 24;
if(tempCount>maxBand[i])
maxBand[i]=tempCount;
if(tempCount<minBand[i])
minBand[i]=tempCount;
}
Upvotes: 2
Views: 65
Reputation: 124275
Based on name of pix_rgb
I am assuming that pix_rgb[i][k]
holds an int
represesnting color which usually on 32 bits (which is size of int
) is written in form
AAAAAAAARRRRRRRRGGGGGGGGBBBBBBBB
| | | |
| | | blue
| | green
| red
alpha/transparency
By pix_rgb[i][k] << 24
you are shifting all bits to left and set most right 24 bits to 0.
So AAAAAAAARRRRRRRRGGGGGGGGBBBBBBBB
will become
BBBBBBBB000000000000000000000000
^^^^^^^^^^^^^^^^^^^^^^^^ <<24
Now with (pix_rgb[i][k] << 24) >>> 24
you can think of it as BBBBBBBB000000000000000000000000 >>> 24
where you are shifting bits to right but at the same time you are guaranteed that most left bits will be filled with 0 (if we would use >> 24
we could fill it with 1 if first B
would also be 1).
So BBBBBBBB000000000000000000000000
will be changed into
000000000000000000000000BBBBBBBB
^^^^^^^^^^^^^^^^^^^^^^^^ >>>24
In other words we got int
which holds value which represents only blue color.
In short
pix_rgb[i][k] << 24
was used to remove all bits except BBBBBBBB
>>>24
was used to set BBBBBBBB
back at lower indexes of int
so we could treat it as value from range 0-255.Upvotes: 2