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.
I've done something similar sometime ago, so based in that, I've put
together an example of this idea.
import flash.filters.ColorMatrixFilter;
import flash.geom.Rectangle;
import flash.geom.Point;
function getGreyFilter():ColorMatrixFilter {
// luminance coefficients
const rWeight:Number = 0.212671;
const gWeight:Number = 0.715160;
const bWeight:Number = 0.072169;
var colMatrix:Array = [
rWeight, gWeight, bWeight, 0, 0,
rWeight, gWeight, bWeight, 0, 0,
rWeight, gWeight, bWeight, 0, 0,
0, 0, 0,
1, 0
];
return new ColorMatrixFilter(colMatrix);
}
function toGreyScale(src:DisplayObject):BitmapData {
var dest:BitmapData = new BitmapData(src.width,src.height);
var greyFilter:ColorMatrixFilter = getGreyFilter();
dest.draw(src);
dest.applyFilter(dest,new Rectangle(0,0,src.width,src.height),new
Point(0,0),greyFilter);
return dest;
}
function getGreyAverageValue(src:DisplayObject):Number {
var greyBmd:BitmapData = toGreyScale(src);
var rows:int = greyBmd.height;
var cols:int = greyBmd.width;
var accum:int = 0;
for(var r:int = 0; r < rows; r++) {
for(var c:int = 0; c < cols; c++) {
accum += greyBmd.getPixel(c,r) & 0xff; // take just one
of the
RGB channels, since they all have the same value
}
}
return accum / (rows * cols);
}
var avgGrey:Number = getGreyAverageValue(src_mc); // a value in the
range
0-255
trace(avgGrey.toString(16));
Cheers
Juan Pablo Califano
2009/3/29 Karl DeSaulniers <[email protected]>
Wow,
Thank you oo so much.
I hope it hasn't been too much trouble, but I really appreciate the
help.
Best
Karl DeSaulniers
Design Drumm
http://designdrumm.com
On Mar 29, 2009, at 6:21 AM, Anthony Pace wrote:
http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/
wwhelp.htm?context=LiveDocs_Parts&file=00001955.html
Karl DeSaulniers wrote:
Here is my other question.
How to identify a pixel in as2.
I haven't google'd it yet so that answer my be already out there,
but I
thought I'd ask.
Sent from losPhone
On Mar 29, 2009, at 5:48 AM, Anthony Pace
<[email protected]>
wrote:
just noticed that wikipedia has some decent info
http://en.wikipedia.org/wiki/HSV_color_space
Karl DeSaulniers wrote:
Yeh I was going to see if I could adopt the theory into as
Sent from losPhone
On Mar 29, 2009, at 2:23 AM, Anthony Pace <[email protected]
>
wrote:
I just realized the link I have you with the java doesn't
really show
you anything other than how to use java's Color.RGBtoHSB
function... yikes,
I told you I was tired
This might be a little more helpful.
http://www.easyrgb.com/index.php?X=MATH&H=20#text20
Karl DeSaulniers wrote:
Your not alone burning the late night pixels.
Thanks for your response, this is a good idea.
Then you can get some kind of value that will translate to a
function.
Hmmmm..
very interesting.
Thanks for the links too.
gnight
Karl DeSaulniers
Design Drumm
http://designdrumm.com
On Mar 29, 2009, at 1:48 AM, Anthony Pace wrote:
Hi Karl,
Kind of tired, so the easiest way I can think of to do this
is to
evaluate and convert each pixel's RGB values to HSB and then
average your
found values for all the pixels in the region the loader is
to be displayed
within.
Hue, Saturation, Brightness..... if the brightness is less
than 50%
(or 70% to 75% considering how colour value in black levels
are shown in
most displays) go with the light coloured loader, else go
with dark.
http://www.google.ca/search?hl=en&q=rgb+to+hsb&btnG=Google
+Search&meta=
http://www.exampledepot.com/egs/java.awt/color_Hsb.html
(should
be easy to convert to as3)
You could also use the inverse colour of a pixel to make it
pop.
Anyone else have any bright ideas? Seriously, I am sure
somebody
knows a better way.
Hoping my 2:41am ramblings help,
Anthony Pace
Karl DeSaulniers wrote:
I was wondering is there a way to recognize the density of
pixels
in flash AS2 or AS3? The darkness or lightness.
For instance, say I have a loader that is dynamically
loaded and
normally it would be, say, white.
But lets say I want it to have a script that detects the
pixel
density of the MC behind it so as to let the loader mc know
to play on frame
1 or frame 2.
Frame 1 having a white loader and frame 2 having a black or
grey
loader.
That way when the loader is dynamically placed over a MC
with a
picture in it,
it will detect if there is a white picture (placing a black
loader)
or if its a color picture (placing the white loader on top)?
Usage would be for say a photo gallery and while one
picture is
being displayed, and the user clicks a new photo,
the previous photo does not remove until the new one is
loaded.
Thus if I have a white loader and the previous photo was
white
under the loader,
the loader is hard to see and the user sometimes does not
know that
anything is happening.
I basically think it would just take a script that would
map out
the x and y of the loader
and read the pixel density of the MC directly behind the
Loader
(reason for the x and y theory)
then switch so the user will always see a loader. Either
grey or
white depending.
Sounds good in my head, may not be too good (or easy) in code
though.
Any thoughts would be great,
Thanks,
Karl DeSaulniers
Design Drumm
http://designdrumm.com
_______________________________________________
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
_______________________________________________
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