472,968 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,968 software developers and data experts.

16-bit colour representation

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-de...92026813&w=1#2
(16-bit PC cards)

Thanks alot.

Jul 25 '07 #1
5 1703
On Jul 25, 9:53 pm, beertje <bjorn...@gmail.comwrote:
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.
>
Here's the full guide:http://lists.kde.org/?l=kde-games-de...92026813&w=1#2
(16-bit PC cards)
Jul 25 '07 #2
beertje wrote:
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
Jul 25 '07 #3
Diez B. Roggisch wrote:
beertje wrote:
>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

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 -------------

Jul 25 '07 #4
Diez B. Roggisch wrote:
beertje wrote:
>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

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 -------------

Jul 25 '07 #5
>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
Darn. I knew I missed _something_...

Diez
Jul 25 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andreas Falck | last post by:
Hi, I ran the code below on two different versions, 4.0.14 and 4.0.16 respectively, both running RH 7.3 on intel. In version mysql server version 4.0.14 the SELECT privelege suffices for...
38
by: Haines Brown | last post by:
I'm having trouble finding the character entity for the French abbreviation for "number" (capital N followed by a small supercript o, period). My references are not listing it. Where would I...
12
by: Olaf Baeyens | last post by:
I am porting some of my buffer class code for C++ to C#. This C++ class allocates a block of memory using m_pBuffer=new BYTE; But since the class is also used for pointers for funtions that uses...
23
by: Steven T. Hatton | last post by:
This is one of the first obstacles I encountered when getting started with C++. I found that everybody had their own idea of what a string is. There was std::string, QString, xercesc::XMLString,...
1
by: Zhongjian Lu | last post by:
Hi Guys, I was processing a UTF-16 coded file with BOM and was not aware of the codecs package at first. I wrote the following code: ===== Code 1============================ for i in...
1
by: David Bertoni | last post by:
Hi all, I'm trying to resolve what appears to me an inconsistency in the XML 1.0 recommendation involving entities encoding in UTF-16 and the requirement for a byte order mark. Section 4.3.3...
7
by: Jimmy Shaw | last post by:
Hi everybody, Is there any SIMPLE way to convert from UTF-16 to UTF-32? I may be mixed up, but is it possible that all UTF-16 "code points" that are 16 bits long appear just the same in UTF-32,...
15
by: arnuld | last post by:
i am not able to figure out the error: /* C++ Primer - 4/e * * exercise 7.16 * STATEMENT: * write a programme that accepts the arguments to main. print * the values passed to main. *...
0
by: Bill Wordsworth | last post by:
This is what I have done so far: In Stored Procedure, I set- * v_xml OUT NVARCHAR2 * v_xml := '<?xml version="1.0" encoding="UTF-16" ?>...'; -- without any chr(10) newline In Application, I...
29
by: Kenzogio | last post by:
Hi, I have a struct "allmsg" and him member : unsigned char card_number; //16 allmsg.card_number
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.