// thick:走査線の太さ、contrast:走査線の明るさ、ghost:画像のぶれ量
private function filterVTR(img:IplImage, thick:int, contrast:int, ghost:int):void {
var f:Boolean = true;
var r:int = 0, g:int = 0, b:int = 0;
var i:int = 0, j:int = 0;
for(var y:int=0;y<img.height;y++){
f = ((y%thick*2)<thick) ? true : false;
pos = img.widthStep*y;
for(var x:int=0;x<img.width;x++){
i = pos + x*4, j = pos + (x + ghost)*4;
r = (img.imageData[i + 1] + img.imageData[j + 1])/2;
g = (img.imageData[i + 2] + img.imageData[j + 2])/2;
b = (img.imageData[i + 3] + img.imageData[j + 3])/2;
if(f){
r += contrast;
g += contrast;
b += contrast;
}
img.imageData[i + 1] = r;
img.imageData[i + 2] = g;
img.imageData[i + 3] = b;
}
}
gammaCorrect(img, 0.8);
}
private function gammaCorrect(img:IplImage, param:Number):void {
var lut:Vector.<int> = new Vector.<int>(256, true);
var gamma:Number = param;
var len:int = img.imageData.length;
for(var i:int=0;i<256;i++){
lut[i] = Math.pow(i/255.0, gamma)*255.0;
}
for(var n:int=0;n<len;n+=4){
img.imageData[n+1] = lut[img.imageData[n+1]];
img.imageData[n+2] = lut[img.imageData[n+2]];
img.imageData[n+3] = lut[img.imageData[n+3]];
}
}