Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 06-06-2004, 11:12 PM   #1 (permalink)
jimst
Registered User
 
Join Date: Jun 2004
Posts: 4
jimst is on a distinguished road
12 bit RGB to 16 bit RGB conversion

Could anybody tell me how to convert 12 bit RGB to 16 bit RGB?
Thanks for the help in advance.
jimst is offline   Reply With Quote
Old 06-07-2004, 10:35 AM   #2 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
here's code that does pretty much the same thing for 16->32 conversion (taken from directfb). adjust it to do what you want.

Code:
#define RGB16_TO_RGB32(pixel)  ( (((pixel) & 0xF800) << 8) | \
                                 (((pixel) & 0x07E0) << 5) | \
                                 (((pixel) & 0x001F) << 3) )
joe_bruin is offline   Reply With Quote
Old 06-07-2004, 05:41 PM   #3 (permalink)
jimst
Registered User
 
Join Date: Jun 2004
Posts: 4
jimst is on a distinguished road
thank you, joe_bruin!
Looking at the code, I guess it'll be
Code:
#define RGB12_TO_RGB16(pixel)  ( (((pixel) & 0x0F00) << 4) | \
                                 (((pixel) & 0x00E0) << 3) | \
                                 (((pixel) & 0x001F) << 1) )
jimst is offline   Reply With Quote
Old 06-07-2004, 07:01 PM   #4 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
not quite (but close).

a 12bit RGB pixel is composed of 4 bits of red, 4 of green, and 4 of blue. if you have a 16bit variable holding the pixel, it's 0000RRRRGGGGBBBB (where every letter is 1 bit).

a 16bit RGB pixel is:
RRRRRGGGGGGBBBBB (5 reds, 6 greens, 5 blue bits).

the reds you have correct. the greens, you're a little off. you're missing one green bit. for the blue, you've captured an extra green bit.
joe_bruin is offline   Reply With Quote
Old 06-08-2004, 03:35 AM   #5 (permalink)
jimst
Registered User
 
Join Date: Jun 2004
Posts: 4
jimst is on a distinguished road
Thank you very much.
But I don't understand about the greens... Do you mean I have to shift more?
jimst is offline   Reply With Quote
Old 06-08-2004, 10:26 AM   #6 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
no. your shifting is right, your masks are a little off. here's what's being evaluated right now:

Code:
#define RGB12_TO_RGB16(pixel)  \
((((pixel) & 0x0F00) << 4) | \
 (((pixel) & 0x00E0) << 3) | \
 (((pixel) & 0x001F) << 1) )

#define RGB12_TO_RGB16(0000RRRRGGGGBBBB)  \
(((0000RRRR00000000) << 4) | \
 ((00000000GGG00000) << 3) | \
 ((00000000000GBBBB) << 1) )
joe_bruin is offline   Reply With Quote
Old 06-08-2004, 04:59 PM   #7 (permalink)
jimst
Registered User
 
Join Date: Jun 2004
Posts: 4
jimst is on a distinguished road
Now I see, thank you very much for good explanation!
jimst is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 02:58 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting