I'm doing this in flash 9, the hex to rgb conversion is sweet and plenty fast 
enough, it's when I throw in the HSB conversion that is bogs down. It has to be 
done pixel by pixel as the type of transform depends on the input value of each 
individual pixel.
 
[We're doing tilemap adjustments for a large screen made up of LED panels (so 
small res, think 340 by 122 pxls) so we have to do both Gamma and Colour 
correction.]
 
M

________________________________

From: [EMAIL PROTECTED] on behalf of David Rorex
Sent: Fri 15/09/2006 23:47
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Hex to HSB



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


_______________________________________________
[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

Reply via email to