LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 09-20-2005, 11:18 AM   #1
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Rep: Reputation: 35
Need several RGB convertion functions


I'm using wxWidgets (and following OpenGL Game Development book).

VC++ has such functions (macros?) which are used in the book:

1) long RGB (GLubyte r, GLubyte g, GLubyte b);
2) GLubyte GetRValue (long rgb);
3) GLubyte GetGValue (long rgb);
4) GLubyte GetBValue (long rgb);

I need these functions in wxWidgets, but I don't have the slightest idea how to implement them.

Any ideas?

Thanks.
 
Old 09-20-2005, 12:07 PM   #2
Thinking
Member
 
Registered: Oct 2003
Posts: 249

Rep: Reputation: 30
i'm not sure if this works and i'm not the binary shift expert but try this:

typedef GLubyte char

#define GetRValue(rgb) rgb&0xFF0000
#define GetGValue(rgb) rgb&0x00FF00
#define GetBValue(rgb) rgb&0x0000FF

long RGB(char r,char g,char b){
long color=0;
color&=r;
color<<=8;
color&=g;
color<<=8;
color&=b;
return color;
}

if the above code works
i think a macro will also do it:
#define RGB(r,g,b) ((((r<<8)&g)<<8)&b)
 
Old 09-20-2005, 01:26 PM   #3
addy86
Member
 
Registered: Nov 2004
Location: Germany
Distribution: Debian Testing
Posts: 332

Rep: Reputation: 31
You forgot shifting (and always use parentheses with macros):
Code:
#define GetRValue(rgb) (((rgb)&0xFF0000)>>16)
#define GetGValue(rgb) (((rgb)&0x00FF00)>>8
#define GetBValue(rgb) ((rgb)&0x0000FF)

You have to use the or-operator:
Code:
long RGB(char r,char g,char b){
  return ( r << 16 ) | ( g << 8 ) | b;
}
The macro:
Code:
#define RGB(r,g,b) (((r)<<16)|((g)<<8)|(b))
 
Old 09-20-2005, 01:42 PM   #4
Thinking
Member
 
Registered: Oct 2003
Posts: 249

Rep: Reputation: 30
got it
your right
thx ;-)
 
Old 09-21-2005, 06:07 AM   #5
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
Thanks, Thinking, addy86.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
convertion from doc file to pdf in bulk sujith_deva General 6 12-10-2004 12:20 AM
convertion of dvd,avi or mpg to YUV422P arpspatel Linux - Newbie 0 09-29-2004 12:33 PM
pointers to functions/member functions champ Programming 2 03-28-2003 07:22 PM
MS Access to Mysql Convertion Error. hubergeek Linux - Software 0 03-17-2003 12:55 PM
rgb color question ...... purpleburple Linux - General 2 07-25-2002 03:17 PM


All times are GMT -5. The time now is 10:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration