color conversion

May 23, 2012 at 11:58am
I have a 16 bit number which represents a temperature

i want to convert this number to a rgb values ( 0-255 for Red green and blue ).

red = hot
green = normal
blue = cold

Is there maybe a example or formula some where?

Thnx..
May 23, 2012 at 12:50pm
This is what you need I think:

cout << “\033[22;31m” << “Hello!” << endl;
Which will print: Hello!

The list of codes is as follows:
\033[22;30m - black
\033[22;31m - red
\033[22;32m - green
\033[22;33m - brown
\033[22;34m - blue
\033[22;35m - magenta
\033[22;36m - cyan
\033[22;37m - gray
\033[01;30m - dark gray
\033[01;31m - light red
\033[01;32m - light green
\033[01;33m - yellow
\033[01;34m - light blue
\033[01;35m - light magenta
\033[01;36m - light cyan
\033[01;37m – white
\033[0m – default terminal text colour
May 23, 2012 at 1:41pm
i actually almost got what i want:

1
2
3
int B = 255 - (int)((((double)value) / (double)30000) * (double)255);
int G = 255 - (int)((Math.Abs(((double)value - (double)20000)) / 30000) * 255);
int R = (int)((((double)value - (double)20000) / (double)10000) * 255);


But i want 17000 to turn blue... now it is green...
May 23, 2012 at 2:21pm
closed account (1vRz3TCk)
It may be worth looking into using a different colour space to find a path that goes through the correct hues and then convert the desired point to RGB.

It has been a while since I did anything like this but I remember something about Planckian locus (mired scale) having a smooth transition from blue to red via orange.
May 23, 2012 at 3:22pm
/* IGNORE THIS POST */
Wait... 16Bit Colour... A 0-255 range uses 8 bits. How can you store 3 8-bit colours into a 1 16-bit colour? Why not using a 32bit?
And, i suggest you to have bit-shifting, that's faster.
/* IGNORE THIS POST */
Last edited on May 23, 2012 at 3:32pm
May 23, 2012 at 3:30pm
closed account (1vRz3TCk)
EssGeEich wrote:
How can you store 3 8-bit colours into a 1 16-bit colour?
He is not. He wants to represent a 16-bit temperature value as a 24-bit (RGB) colour.
May 23, 2012 at 3:32pm
Ok, so I'm not into that at all, i don't completely know how a temperature value is stored like.
May 23, 2012 at 3:43pm
Yuck at your casts.
You could use a palette (LUT) if you want more complex mappings
May 24, 2012 at 12:41pm
I changed it to this:
The ConvertTPAData function converts the 16 bit integer to a actual temperture...

1
2
3
4
5
6
7
8
9
double val = ConvertTPAData(item.tpa8[x]);

int B = 255 -   (int)((val / 20) * 255);    
int G = 255 -   (int)((Math.Abs(val - 20) / 90) * 255);   
int R =         (int)(((val - 15) / 25) * 255);  

R = R > 255 ? 255 : ( R < 0 ? 0 : R );
G = G > 255 ? 255 : ( G < 0 ? 0 : G );
B = B > 255 ? 255 : ( B < 0 ? 0 : B );
May 24, 2012 at 1:58pm
closed account (zb0S216C)
Have you tried looking at how Direct3D computes their colours?

 
#define D3DCOLOR_ARGB(a,r,g,b) ((D3DCOLOR)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff))) 

Pretty, don't you think?

Wazzak
Last edited on May 24, 2012 at 1:59pm
Topic archived. No new replies allowed.