I have been playing with BitmapData type and getPixelAt to make histograms. When I seen that the flash 10's BitmapData has a new method called histogram I thought it was a new improvement on analyzing BitmapData. Boy was I wrong. it's really really slow and I don't have clue why. Bug maybe??
Here's the code for any one who thinks it maybe that. Whats your thoughts?
FYI: with a for loop and getPixelAt I could still get 25fps at 1ms cycles. Though I have yet to see the frame rate for histogram, I cant event get close to a 1fps.
Actionscript:
-
package
-
{
-
import flash.display.BitmapData;
-
import flash.display.MovieClip;
-
import flash.display.Shape;
-
import flash.display.Sprite;
-
import flash.events.AsyncErrorEvent;
-
import flash.events.Event;
-
import flash.events.TimerEvent;
-
import flash.geom.Rectangle;
-
import flash.media.Video;
-
import flash.net.NetConnection;
-
import flash.net.NetStream;
-
import flash.utils.getTimer;
-
import flash.display.BlendMode;
-
import flash.utils.Timer;
-
-
public class Main extends Sprite
-
{
-
-
private var graphic1:Shape;
-
private var graphic2:Shape;
-
private var graphic3:Shape;
-
private var vect:Vector.<Vector.<Number>> ;
-
private var bmd:BitmapData;
-
private var video_mc:MovieClip;
-
-
private var rect:Rectangle;
-
-
-
public function Main():void
-
{
-
graphic1 = new Shape();
-
graphic2 = new Shape();
-
graphic3 = new Shape();
-
-
stage.scaleMode = "noScale";
-
perspectiveDemo();
-
-
bmd = new BitmapData(video_mc.width, video_mc.height);
-
-
addChild(graphic1);
-
addChild(graphic2);
-
addChild(graphic3);
-
-
graphic1.blendMode = BlendMode.SCREEN;
-
graphic1.x = 30;
-
graphic1.y = 200;
-
//graphic1.scaleY = .15;
-
-
graphic2.blendMode =BlendMode.SCREEN;
-
graphic2.x = 30;
-
graphic2.y = 200;
-
//graphic2.scaleY = .15;
-
-
graphic3.blendMode = BlendMode.SCREEN;
-
graphic3.x = 30;
-
graphic3.y = 200;
-
///graphic3.scaleY = .15;
-
-
}
-
-
-
private function perspectiveDemo():void
-
{
-
-
video_mc = new MovieClip();
-
addChild(video_mc);
-
video_mc.x = 30;
-
video_mc.y = 30;
-
-
var video:Video = new Video(320, 140);
-
var nc:NetConnection = new NetConnection();
-
nc.connect(null);
-
var ns:NetStream = new NetStream(nc);
-
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, handleFakeError);
-
-
-
video_mc.addChild(video);
-
video_mc.x = 400;
-
video.attachNetStream(ns);
-
ns.play("http://gfxcomplex.com/labs/wall-e-tlr3_h320.mov");
-
-
rect = new Rectangle(0, 0, 140, 300)
-
-
var timer:Timer = new Timer(100);
-
timer.addEventListener(TimerEvent.TIMER, checkColor3);
-
timer.start();
-
-
}
-
-
private function handleFakeError(e:AsyncErrorEvent):void
-
{
-
//
-
}
-
-
-
private function checkColor3(e:TimerEvent):void {
-
-
bmd.draw(video_mc);
-
-
vect = bmd.histogram(rect);
-
-
-
for (var i:int = 0; i <256; i++)
-
{
-
-
-
graphic1.graphics.lineStyle(.25, 0xff0000);
-
graphic1.graphics.moveTo(i, 0);
-
graphic1.graphics.lineTo(i, -(vect[0][i]));
-
-
graphic2.graphics.lineStyle(.25, 0x00ff00);
-
graphic2.graphics.moveTo(i, 0);
-
graphic2.graphics.lineTo(i, -(vect[1][i]));
-
-
graphic3.graphics.lineStyle(.25, 0x0000ff);
-
graphic3.graphics.moveTo(i, 0);
-
graphic3.graphics.lineTo(i, -(vect[2][i]));
-
-
}
-
graphic1.graphics.clear();
-
graphic1.graphics.clear();
-
graphic1.graphics.clear();
-
}
-
}
-
}

















That sounds really slow. I did some speed testing, and it seems to work just fine - at least with bitmapdata of a still-photo , yet I don't know how video would affect that ...
How did my code look to you? Maybe I have some bad coding?