16-bit colour representation

B

beertje

This has me a bit stumped...

I'm trying to extract pictures from a file. So far I'm successfully
retrieved the header and what I think is the colour for each pixel.
Here's the description:

"""
3) The picture data format:
The color information is 15 bit data stored in 16 bit. This means the
most
significant bit is unused. The data is stored line for line in little
endian Intel format starting with top left edge to bottom right edge.
This
is normally called chunky format.

Bit 0.. 4 blue value
Bit 5.. 9 green value
Bit 10..14 red value
"""

So I've got a list of 16-bit numbers, but how to extract RGB info from
those I'm a bit lost. I thought at first I should convert the decimal
(say 23294) into a binary (say 0101101011111110) into something like
this:
blue: 01011
green: 01011
red: 11111

But encountered two problems: First, I don't know what the best way is
to do this conversion, but more importantly I don't see how every
colour could possibly be represented like this. 65535 is presumably
white, but converting this into chunks of 5 gives me a 31, 31, 31, a
dark shade of grey.

I guess I'm on the wrong track completely?

I'm a bit unsure about how to treat what the guide calls 'UWORD'...

Here's the full guide: http://lists.kde.org/?l=kde-games-devel&m=105548792026813&w=1#2
(16-bit PC cards)

Thanks alot.
 
J

John Machin

This has me a bit stumped...

I'm trying to extract pictures from a file. So far I'm successfully
retrieved the header and what I think is the colour for each pixel.
Here's the description:

"""
3) The picture data format:
The color information is 15 bit data stored in 16 bit. This means the
most
significant bit is unused. The data is stored line for line in little
endian Intel format starting with top left edge to bottom right edge.
This
is normally called chunky format.

Bit 0.. 4 blue value
Bit 5.. 9 green value
Bit 10..14 red value
"""

Do yourself a favour -- read the next line in TFM. It says: "To get 8
bit RGB data, all these values must be shifted 3 bits to the left."
So I've got a list of 16-bit numbers, but how to extract RGB info from
those I'm a bit lost. I thought at first I should convert the decimal
(say 23294) into a binary (say 0101101011111110) into something like
this:
blue: 01011
green: 01011
red: 11111

I think you've lost it somewhere; 23294 -> red 22, green 23, blue 30;
see below.
But encountered two problems: First, I don't know what the best way is
to do this conversion,

b = rgb & 31
g = (rgb >> 5) & 31
r = (rgb >> 10) & 31

IOW like you would in C; IOW isn't this whole question OT?
but more importantly I don't see how every
colour could possibly be represented like this. 65535 is presumably
white, but converting this into chunks of 5 gives me a 31, 31, 31, a
dark shade of grey.

It is a dark shade of grey in 8-bit RGB, but it's as white as the
driven snow in 5-bit RGB.

You need to scale it up. TFM indicates rgb8 = rgb5 << 3 -- i.e.
multiply by 8, but 31 * 8 is 248, not 255. You might want to try rgb8
= (rgb5 * 255 + 16) / 31 instead.
I guess I'm on the wrong track completely?

I'm a bit unsure about how to treat what the guide calls 'UWORD'...

TFM says "UWORD is unsigned 16 bit", so you treat it as an Unsigned
(16-bit) WORD, which is what you [should] have been doing.
 
D

Diez B. Roggisch

beertje said:
This has me a bit stumped...

I'm trying to extract pictures from a file. So far I'm successfully
retrieved the header and what I think is the colour for each pixel.
Here's the description:

"""
3) The picture data format:
The color information is 15 bit data stored in 16 bit. This means the
most
significant bit is unused. The data is stored line for line in little
endian Intel format starting with top left edge to bottom right edge.
This
is normally called chunky format.

Bit 0.. 4 blue value
Bit 5.. 9 green value
Bit 10..14 red value
"""

So I've got a list of 16-bit numbers, but how to extract RGB info from
those I'm a bit lost. I thought at first I should convert the decimal
(say 23294) into a binary (say 0101101011111110) into something like
this:
blue: 01011
green: 01011
red: 11111

But encountered two problems: First, I don't know what the best way is
to do this conversion, but more importantly I don't see how every
colour could possibly be represented like this. 65535 is presumably
white, but converting this into chunks of 5 gives me a 31, 31, 31, a
dark shade of grey.

I guess I'm on the wrong track completely?

I'm a bit unsure about how to treat what the guide calls 'UWORD'...

ANDing and SHIFTing are your friends here:

v = 0x0bcd
b = v & 0xf
v >>= 4
g = v & 0xf
v >>= 4
r = v & 0xf
print r, g, b


Diez
 
S

Steve Holden

Diez said:
ANDing and SHIFTing are your friends here:

v = 0x0bcd
b = v & 0xf
v >>= 4
g = v & 0xf
v >>= 4
r = v & 0xf
print r, g, b
Alternatively, using 5-bit colors you would use

b = v & 0x1f
g = (v >> 5) & 0x1f
r = (v >> 10) & 0x1f

regards
Steve

--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------
 
S

Steve Holden

Diez said:
ANDing and SHIFTing are your friends here:

v = 0x0bcd
b = v & 0xf
v >>= 4
g = v & 0xf
v >>= 4
r = v & 0xf
print r, g, b
Alternatively, using 5-bit colors you would use

b = v & 0x1f
g = (v >> 5) & 0x1f
r = (v >> 10) & 0x1f

regards
Steve

--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------
 
D

Diez B. Roggisch

v = 0x0bcd
Alternatively, using 5-bit colors you would use

b = v & 0x1f
g = (v >> 5) & 0x1f
r = (v >> 10) & 0x1f

Darn. I knew I missed _something_...

Diez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top