开发者

15Bit Color Components, Bit shifting

开发者 https://www.devze.com 2023-03-09 15:49 出处:网络
Okay bit shifting is still a bit weird to me. I\'ve got a 16bit value. The first 15 bits are colors and the last bit is alpha.

Okay bit shifting is still a bit weird to me.

I've got a 16bit value. The first 15 bits are colors and the last bit is alpha.

I have done this with 24 and 32 bit colors no problem as they are nice byte siz开发者_开发问答e's to deal with, but I cant seem to get this to work with 15/16 bits.

This is what I've done in the past, with 24/32 bit colors

(m_colorValue >> RED_CHANNEL) & 0xFF;

I'm trying to split the value into 4 values. 3 5 bit color values and 1 alpha value. I don't know what mask I should be using.

Thanks.


If I understand correctly:

red = (packed >> 0) & 0x1F;
green = (packed >> 5) & 0x1F;
blue = (packed >> 10) & 0x1F;
alpha = (packed >> 15) & 0x01;

packed should better be an unsigned and I'm probably off for the order.


use bit shifting.

ushort s;
ushort b= s&0x1F // first five bits
ushort g= (s>>5)&0x1F // second five bits

etc...


Your question is pretty vague, but if you're trying to extract the individual color components from an RGB1555 this should do the trick:

unsigned short color;

const unsigned int 
    a = color & 0x8000, 
    r = color & 0x7C00, 
    g = color & 0x03E0, 
    b = color & 0x1F; 
0

精彩评论

暂无评论...
验证码 换一张
取 消