Honestly, I'm not sure if I'm following you at this point...

However, I was not talking about *displaying* a grey-scaled image. Just
using it as way to calculate each pixel's luminance / brightness. Which in
this case will give you the same results as transforming to HLS and reading
the L value.

If you want to manipulate brightness, saturation or hue, the only sane way I
can think of is transfroming to HLS. There's not built-in way to do it that
I'm aware of, so in this case you'dl have to use an AS routine (I've pasted
one such routine I've used for this in the past).

But, since (apparently) you only want to know how dark / light a given pixel
is (and then calculate an average), you can just copy the image to a
BitmapData object and convert it to grey scale. Reading a grey-scaled pixel,
you can know how dark or light it is. Just read any of the RGB channels
(they are equal, because it's a grey scaled image); 0 is black (the
darker value) and 255 is white (the lighter value).

The result is the same as transforming to HLS -- it may vary a bit due to
rounding and such, but it's not a significative difference, I think.

This is faster because most of the "hard work" is done by a native method of
the player, instead of Actionscript code.

Cheers
Juan Pablo Califano


2009/3/29 Karl DeSaulniers <[email protected]>

> I actially wanted to get the density. How dark and how light. Not
> necessarily black and white. Dark color or light color. I also don't want to
> convert any images.  Now if it takes converting the image to calculate, then
> the user can never see this conversion of the photo. Just the conversion of
> the loader. If that makes sense. :)
>
> Sent from losPhone
>
>
> On Mar 29, 2009, at 3:41 PM, Ian Thomas <[email protected]> wrote:
>
> Flash's smoothing may introduce irregularities, I guess.
>>
>> But given that the original poster only wanted to know grey or white,
>> surely it's a good enough approximation for that purpose?
>>
>> Ian
>>
>> On Sun, Mar 29, 2009 at 9:08 PM, Juan Pablo Califano
>> <[email protected]> wrote:
>>
>>> It's indeed much faster (five times faster than transforming to grey
>>> scale),
>>> though the results I'm getting are incorrect (the other 2 methods seems
>>> to
>>> return consistently similar results, though trasnforming to HLS takes
>>> about
>>> 3200 ms for a 1152 x 864 image, and transform to grey scale takes around
>>> 130
>>> ms).
>>>
>>> It could be the case that I'm doing it the wrong way, of course... This
>>> is
>>> the code I'm using.
>>>
>>>
>>> function getAverageFromScaledBitmap(src:DisplayObject):Number {
>>>   var dest:BitmapData = new BitmapData(1,1);
>>>   var mat:Matrix   = new Matrix();
>>>   var sx:Number   = 1 / src.width;
>>>   var sy:Number   = 1 / src.height;
>>>
>>>   mat.scale(sx,sy);
>>>   dest.draw(src,mat,null,null,null,true);
>>>   var hls:Object = ColorUtils.RGBtoHLS(dest.getPixel(0,0));
>>>
>>>   return hls.l;
>>> }
>>> Cheers
>>> Juan Pablo Califano
>>>
>>> 2009/3/29 Ian Thomas <[email protected]>
>>>
>>> On Sun, Mar 29, 2009 at 8:14 PM, Juan Pablo Califano
>>>> <[email protected]> wrote:
>>>>
>>>>> As it's been said already, you could try converting to HLS and the get
>>>>>
>>>> the
>>>>
>>>>> average luminance (brigthness). Here's a handy class to convert from
>>>>> RGB
>>>>>
>>>> to
>>>>
>>>>> HSL and viceversa.
>>>>>
>>>>> http://www.dreaminginflash.com/2007/11/19/hls-to-rgb-rgb-to-hls/
>>>>> Another approach, which might be faster (but you'd have to test it to
>>>>> see
>>>>>
>>>> if
>>>>
>>>>> that's true), could be transforming to bitmap to a grey scale. You
>>>>> would
>>>>> then know how black / white each pixel is, so you could get the average
>>>>> value by adding the value of each pixel and dividing for the total
>>>>> number
>>>>>
>>>> of
>>>>
>>>>> pixels. Instead of reading the whole pixel value, you can just read one
>>>>> channel, because since it' s a grey scale, the three color channels
>>>>> will
>>>>>
>>>> be
>>>>
>>>>> equal.
>>>>>
>>>>
>>>> If you're going to test any kind of average pixel value, it'd be far
>>>> faster to take a bitmap copy of the frame scaled to 1 pixel x 1 pixel
>>>> (with smoothing on) - and just read the colour value of that pixel...
>>>>
>>>> HTH,
>>>>  Ian
>>>>  _______________________________________________
>>>> Flashcoders mailing list
>>>> [email protected]
>>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>>
>>>> _______________________________________________
>>> Flashcoders mailing list
>>> [email protected]
>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>
>>>
>> _______________________________________________
>> Flashcoders mailing list
>> [email protected]
>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to