No, pretty much the way hsb <--> rgb works, you need to have the numbers
separate. You could probably create some awkward transform that tries really
hard not to break them up, but it would end up being a lot more complicated,
and not worth it.

Besides, going from 0xRRGGBB to 0xRR, 0xGG, 0xBB is very fast (just 3 ANDs
and 2 bitshifts).

// takes a color in the form 0xRRGGBB returns an object with the fields r,
g, and b
function hex2rgb(c:Number):Object
{
   return {
              r:(c>>16)&0xff,
              g:(c>>8)&0xff,
              b:c&0xff
             };
}

// takes an object with fields r, g, and b, returns a color in the form
0xRRGGBB
function rgb2hex(c:Object):Number
{
   return (c.r<<16) | (c.g<<8) | (c.b);
}

and then here's a quick test:

var c = hex2rgb(0xabcdef);
trace("r=0x"+c.r.toString(16)+" g=0x"+c.g.toString(16)+"
b=0x"+c.b.toString(16));
trace("color=0x"+rgb2hex(c).toString(16));


then, assuming your rgb2hsv and hsv2rgb functions take an object as input,
you could do:

// read in hsv from a pixel
var hsv:Object = rgb2hsv(hex2rgb(bmp.getPixel(x,y)));

// transform hsv.h, hsv.s, hsv.v, etc
hsv.h /= 2;
hsv.s = 50;
hsv.v = Math.random()*100;

// put back our transformed pixel
bmp.setPixel(x,y,rgb2hex(hsv2rgb(hsv)));

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

Now, this is all theoretical, but I don't think flash 8 is fast enough to do
this calculation on a real-time video of any decent size. flash 9 might be
able to handle it.

But if you just want to do some color transforms, i'd suggest looking at the
built in transform classes instead of trying to do it yourself
pixel-by-pixel. These should be much faster, because the transform code will
be native, instead of in actionscript. They are pretty flexible, you can do
a lot with them.

-David R

On 9/15/06, Mike Mountain <[EMAIL PROTECTED]> wrote:

OK - seeing as you asked so nicely

Instead of splitting it up into 3 different components R, G and B then
doing a calculation on each of these in turn to find H S and B ,applying
some transform on H and B and then turning these back into R G and B - then
in turn combining this to find a flash friendly hex value - I'd like to know
if it's possible to go

Hex - Hsb - transform - Hex

or to find HSB from hex do I have to split out the RGB components?

Any clearer?

M

________________________________

From: [EMAIL PROTECTED] on behalf of Ammon
Sent: Fri 15/09/2006 17:07
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Hex to HSB



Mike Mountain wrote:
> Thanks, but I was hoping this would be possible without having to
> convert to RGB first - I basically want to do pixel by pixel colour
> transform on a copy of a video whilst it's being played so it needs to
> be ultra efficient.

I'm sorry... but explain to my how a hex number of the form 0xRRGGBB
isn't _already_ an RGB value? :P

Ammon
_______________________________________________
Flashcoders@chattyfig.figleaf.com
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




_______________________________________________
Flashcoders@chattyfig.figleaf.com
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


_______________________________________________
Flashcoders@chattyfig.figleaf.com
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

Reply via email to