package {
import __AS3__.vec.Vector;
import flash.display.*;
[SWF(width = "600", height = "250", backgroundColor = "#000000", frameRate = "30")]
public class Jitter extends Sprite{
[Embed(source = 'assets/picture.jpg')]
public var SrcImg:Class;
private var src:Bitmap;
private var dst:Bitmap;
private var srcData:Vector.<uint>;
private var w:int;
private var h:int;
public function Jitter() {
stage.scaleMode = "noScale";
src = new SrcImg() as Bitmap;
w = src.width;
h = src.height;
dst = new Bitmap(new BitmapData(w, h, false));
addChild(src);
srcData = new Vector.<uint>(w*h, true);
srcData = src.bitmapData.getVector(src.bitmapData.rect);
dst.bitmapData.setVector(dst.bitmapData.rect, filterJitter(srcData, 10));
addChild(dst).x += w;
}
private function filterJitter(src:Vector.<uint>, amount:int):Vector.<uint> {
var dst:Vector.<uint> = new Vector.<uint>(w*h, true);
var nx:int, ny:int;
for (var y:int=0;y<h;y++) {
for (var x:int=0;x<w;x++) {
nx = x + (Math.random() - 0.5)*amount;
ny = y + (Math.random() - 0.5)*amount;
try {
dst[w*y + x] = src[w*ny + nx];
}catch(e:RangeError) {
dst[w*y + x] = src[w*y + x];
}catch(e:ReferenceError) {
dst[w*y + x] = src[w*y + x];
}
}
}
return dst;
}
}
}