Jump to content

  • Log In with Google      Sign In   
  • Create Account


16-Bit Shifting


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 PsYcHoPrOg   Members   -  Reputation: 115

Like
Likes
Like

Posted 13 February 2000 - 10:13 AM

I did not understand several parts of the code that I looked at from one of the articles. One of those parts were the "N<<=1" in the for loop. The other part is in the next part, outside of the for loop. Why do the variables for the rgb16->position.rgbBlue, rgb->position.rgbRed, and rgb->position.rgbGreen equal what he made them equal. And why does rgb->position.rgbBlue = 0? Anyway, the code is in the next post. By the way, don''t comment on some of the syntax errors in the code. I took it directly from an article.

Sponsor:

#2 PsYcHoPrOg   Members   -  Reputation: 115

Like
Likes
Like

Posted 13 February 2000 - 10:15 AM


<
char r=0, g=0, b=0;
for(int n = 1; n<65536; N<<=1)
{
IF(ddsd.ddpfPixelFormat.dwRBitMask & N)
++R;
IF(ddsd.ddpfPixelFormat.dwRBitMask & N)
++G;
IF(ddsd.ddpfPixelFormat.dwRBitMask & N)
++B;
}

// THIS IS THE PART THAT ASSUMES THE FORMAT IS RGB
RGB16->dwRBitMask = ddsd.ddpfPixelFormat.dwRBitMask;
rgb16->Position.rgbRed = g + b;

rgb16->dwGBitMask = ddsd.ddpfPixelFormat.dwGBitMask;
rgb16->Position.rgbGreen = b;

rgb16->dwBBitMask = ddsd.ddpfPixelFormat.dwBBitMask;
rgb16->Position.rgbBlue = 0;
>

#3 Gav   Members   -  Reputation: 124

Like
Likes
Like

Posted 13 February 2000 - 10:27 AM

firstly N<<1 multiples N by 2. << is the shift left operator. ie it shifts the variable a certain number of places to the left. eg if you have the binary number 0010 and use 0010<<1 you get 0100. As each digit is a power of 2 this multiples the number by two. In the example 2 becomes 4. Hope that makes sense.

For the second part, this is because of how the colour information for the pixel is stored. For 16 bit pixels it is usually RRRRRGGGGGGBBBBB. The mask that DDraw returns is 1111100000000000 for red, 11111100000 for green and 11111 for blue. The for loop sets B to 5, G to 6 and R to 5 ie the number of bits for each colour value. BTW the code in the for loop is wrong, the second and third bitmasks should be for green and blue respectively.

The start position for red is therefore the number of bits for green and the number of bits for blue. ie g+b. The start position for green is the number of bits for blue ie b. As blue is the first colour its start position is 0.

This may be better explained in the 16bit pixel plotting articles here on GameDev.net under the developer resources section.

No sense being pessimistic. It wouldn''t work anyway.

#4 trixter   Members   -  Reputation: 122

Like
Likes
Like

Posted 13 February 2000 - 10:29 AM

n<<=1 does this

for time thru n = 1 = 00000000000000000000000000000001b
after 1st n<<=1: n = 2 = 00000000000000000000000000000010b
after 2nd n<<=1: n = 4 = 00000000000000000000000000000100b
and so on...

65536 = 00000000000000010000000000000000b


color bits: RRRRRGGGGGGBBBBB for RGB16 565
red position starts after the blue and green bits.
green position starts after the blue bits.
blue position starts at the beginning.


maybe this''ll help somehow




#5 PsYcHoPrOg   Members   -  Reputation: 115

Like
Likes
Like

Posted 13 February 2000 - 10:45 AM

Thank you both. I understand completely now. Thank you for answering my post.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS