Jump to content
Software FX Community

color codes in javascript


User (Legacy)

Recommended Posts

Hello All:

I am working in javascript and is having trouble with the color codes that

ChartFx generates for javascript.

Using the CHART_RGB function in Cfxie.inc I was able to pass in the values

for red

Mychart.Color(0) = CHART_RGB(204,00,00); // RED - this works fine

However, when I try to retrieve the color code generated (I have to make my

own legend), the value returned looks nothing like 'RED'

response.write ("this should be red:"+Mychart.Color(0)); // I get

'33554432' ????

If anyone can tell me how to get the RGB values that I put in back that

would be great

Thank you!

Katherine

Link to comment
Share on other sites

ChartFX stores colors as 32-bit numbers (like Windows does), the color

returned will normally be a huge number where some of the bits represent

red, some green and some blue. To add to the problem, to support palletized

images ChartFX also needs to handle colors that include an index to the

palette (instead of its r,g,b components).

I am afraid it will not be easier for you to get back the color in a human

readable form without writing a lot of code that understands how colors are

represented internally in Windows.

--

Regards

JC

Software FX Support

"Katherine Yang" <kyang@cyveillance.com> wrote in message

news:cEW0qdUxBHA.1412@webserver1.softwarefx.com...

> Hello All:

>

> I am working in javascript and is having trouble with the color codes that

> ChartFx generates for javascript.

>

> Using the CHART_RGB function in Cfxie.inc I was able to pass in the values

> for red

>

> Mychart.Color(0) = CHART_RGB(204,00,00); // RED - this works fine

>

> However, when I try to retrieve the color code generated (I have to make

my

> own legend), the value returned looks nothing like 'RED'

>

> response.write ("this should be red:"+Mychart.Color(0)); // I get

> '33554432' ????

>

> If anyone can tell me how to get the RGB values that I put in back that

> would be great

>

> Thank you!

>

> Katherine

>

>

Link to comment
Share on other sites

  • 1 month later...

As long as you are using strict RGB, the numbers "make since."  Each color

is represented with 1 byte (8 bits => 256 colors; 0-255). An integer is 4

bytes. A color stored as an integer is typically made up of the following

(from order of most significant byte to least):

Alpha color (transparency)

Blue

Green

Red

Here is some sample code to retrieve the red, blue, green values from an

integer (mix of JavaScript and VBScript - the code you are wanting is in

JavaScript, I'm not sure if it is possible in VBScript):

BEGIN CODE

-----------------------------

<!-- #include virtual="/Include/CfxIE.inc" -->

<%

Dim red, green, blue

red = 10

green = 200

blue = 140

Response.Write "RGB(10, 200, 140) => " & CHART_RGB(red, green, blue) & "<br

/>" & vbCrLf

Show_RGB CHART_RGB(red,green, blue)

%>

<script language="JavaScript" RUNAT=SERVER>

function Show_RGB(color)

{

Response.Write('Red => ' + (color & 0xff) + '<br />\n');

Response.Write('Green => ' + ((color >> 8) & 0xff) + '<br />\n');

Response.Write('Blue => ' + ((color >> 16) & 0xff) + '<br />\n');

}

</script>

---------------------------

END CODE

I don't know what level of programmer you are or those who later might be

interested in this post, so I will assume just a basic programming level.

Here are a couple of things to note:

1) 0xff is the hexadecimal representation for 255

2) >> is the left bit shift operator

3) & is the bit-wise AND operator - every bit that is turned on (1) in

both the left and right hand values is left on, all others are turned off

(0)

With red being in the least significant byte, I just do a bit-wise AND (&)

with 255. For the other colors, I had to shift their byte to the least

significant byte first, and then bit-wise AND (&) it to get the actual

value.

As far as the index colors that the person from SoftwareFX is talking about,

I've not run into them with the work I have done. If a color is built using

CHART_RGB (or the built-in RGB function in VBScript), it SHOULD be able to

be reversed engineered so to speak using the above method. If you have any

questions or comments, please let me know. Thanks!

Chris

"Katherine Yang" <kyang@cyveillance.com> wrote in message

news:cEW0qdUxBHA.1412@webserver1.softwarefx.com...

> Hello All:

>

> I am working in javascript and is having trouble with the color codes that

> ChartFx generates for javascript.

>

> Using the CHART_RGB function in Cfxie.inc I was able to pass in the values

> for red

>

> Mychart.Color(0) = CHART_RGB(204,00,00); // RED - this works fine

>

> However, when I try to retrieve the color code generated (I have to make

my

> own legend), the value returned looks nothing like 'RED'

>

> response.write ("this should be red:"+Mychart.Color(0)); // I get

> '33554432' ????

>

> If anyone can tell me how to get the RGB values that I put in back that

> would be great

>

> Thank you!

>

> Katherine

>

>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...