We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Help with Color datatype
Page Index Toggle Pages: 1
Help with Color datatype (Read 710 times)
Help with Color datatype
Nov 3rd, 2005, 2:22am
 
I'm using pixels[] to access Hue, Saturation, Brightness information for individual pixels. I'm trying to parse out the HSB values from the color datatype but I don't quite understand the number that I'm getting back:

Some are like this:
-11712443
and others are like this:
-9937324

In the description of the color datatype it says  Alpha, Hue, Saturation, and brightness are each represented with an eight digit number.

I would really appreciate any explanation or insight on the color datatype when returned from pixels[]
Re: Help with Color datatype
Reply #1 - Nov 3rd, 2005, 3:00am
 
It is specified as a 32bit *unsigned* number, however, the int type in Java is signed.  As far as memory is concerned, unsigned and signed are the same thing, it's simply a matter of how the number is displayed.  The details on how signed/negative numbers work in binary I will leave as extended reading.

What matters here is you need to do is get each of the 8bit numbers from that 32bit number.  You can do this as follows (I am assuming the numbers are in the format: 0xAAHHSSBB, and the color is stored in an int variable called c.

int alpha = (c>>24)&0xFF; // Shift the number 24 bits (3 bytes) to the right, and limit it to 0~255.
int hue = (c>>16)&0xFF; // Shift the number 16 bits (2 bytes) to the right, and limit it to 0~255.
int alpha = (c>>8)&0xFF; // Shift the number 8 bits (1 byte) to the right, and limit it to 0~255.
int alpha = c&0xFF; // Limit the number to 0~255.

Although, if I recall, doesn't processing return float type for HSB?

Marcello
Re: Help with Color datatype
Reply #2 - Nov 3rd, 2005, 3:30am
 
You may already know, but just incase...

There are methods, hue(c); saturation(c); and brightness(c); (Where c is a color variable) that return the Hue, Sat, and Brightness variables for you.

Maybe you're not aware of these functions, which could save you work on the long run.
Re: Help with Color datatype
Reply #3 - Nov 3rd, 2005, 4:50am
 
Thanks I'll give it a shot
I appreciate the quick response
Page Index Toggle Pages: 1