In other words, to make your above code to compute brightness work from a
value returned by getPixel(), just change the few first line of the HSB
method from:
RGBtoHSB = function(rgb){
var r = rgb.r
var g = rgb.g
var b = rgb.b
...
to:
RGBtoHSB = function(var pixelvalue){
var r = pixelvalue >> 16 & 0xFF;
var g = pixelvalue >> 8 & 0xFF;
var b = pixelvalue & 0xFF;
...
...then call it this way:
var pixel = getPixel(....);
var hsb = RGBtoHSB(pixel);
then simply use hsb.b
Hope it helps explaining :-)
B.
-------------------
you could even recode the method to just return the brightness alone (no
Hue, no Saturation): (NOTE: this has not been tested - I simply stripped
off the unnecessary code from the previous method)
function computeBrightness(pixelvalue)
{
var r = pixelvalue >> 16 & 0xFF;
var g = pixelvalue >> 8 & 0xFF;
var b = pixelvalue & 0xFF;
var bright = Math.max(Math.max(r,g),b);
return Math.round((bright/255)*100);
}
If I understand correctly, this should return a number from 0 to 100
representing the "brightness". Which is in fact only the "highest" channel
value. (scaled down to the 0-100 range).
2006/7/29, Zeh Fernando <[EMAIL PROTECTED]>:
> Thanks very much for your response Martin but I don't understand it. I
> don't
> have three vars called R G and B. I just have a number which was retuned
> from getPixel. Am I being stupid? I can't see how I should do what you
> sugest. Pease explain a little further.
That number you're getting is a color. You're just seeing it in decimal
form, rather than hexadecimal form. It's the same thing. For example, the
value for white is either 16777215 or 0xffffff (the two are the SAME
number,
just represented in two different ways).
On 0xffffff, the first "ff" pair is R, then G, then B. Like when you have
html color, "#ffffff".
To extract the single R G and B values from a color, simply apply Martin's
code to the color.
var color = 0xffc1e2; // or the one returned by getPixel, same thing
var r = color >> 16 & 0xFF
var g = color >> 8 & 0xFF
var b = color & 0xFF
Then R, G, and B will contain the values for each channel, going from 0 to
255.
Calculating brightness from that is one whole different matter, though.
- Zeh
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com