21x21 平坦化フィルター
なぜかdivisorの値を半分にしないとだめらしい。そんなもんだっけ・・?
/**
* Copyright keno42 ( http://wonderfl.net/user/keno42 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/8Nzn
*/
package {
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.text.TextField;
import flash.filters.ConvolutionFilter;
public class FlashTest extends Sprite {
public function FlashTest() {
// write as3 code here..
var bmd:BitmapData = new BitmapData(21,21,true,0xFF000000);
bmd.setPixel32(10,10,0xFFFFFFFF);
// bmd.fillRect( new Rectangle(50, 50, 100, 100), 0xFFFF0000);
// bmd.fillRect( new Rectangle(120, 120, 100, 100), 0xFF0000FF);
for( var i:int = 0; i < 10; i++)
bmd.applyFilter(bmd, bmd.rect, new Point(), new ConvolutionFilter(3, 3, [
0.37, 0.61, 0.37,
0.61, 1.00, 0.61,
0.37, 0.61, 0.37
], 1.8));
var str:String = "";
for( var y:int = 0; y < 21; y++ ){
for( var x:int = 0; x < 21; x++){
str += (0xFF & bmd.getPixel32(x,y)) + ", ";
}
str += "\n";
}
/* // 13x13
var temp:Array = [
0, 0, 0, 1, 3, 4, 5, 4, 3, 1, 0, 0, 0,
0, 0, 3, 7, 13, 18, 20, 18, 13, 7, 3, 0, 0,
0, 3, 9, 22, 37, 50, 55, 50, 37, 22, 9, 3, 0,
1, 7, 22, 46, 76, 102, 112, 102, 76, 46, 22, 7, 1,
3, 13, 37, 76, 124, 165, 181, 165, 124, 76, 37, 13, 3,
4, 18, 50, 102, 165, 218, 238, 218, 165, 102, 50, 18, 4,
5, 20, 55, 112, 181, 238, 255, 238, 181, 112, 55, 20, 5,
4, 18, 50, 102, 165, 218, 238, 218, 165, 102, 50, 18, 4,
3, 13, 37, 76, 124, 165, 181, 165, 124, 76, 37, 13, 3,
1, 7, 22, 46, 76, 102, 112, 102, 76, 46, 22, 7, 1,
0, 3, 9, 22, 37, 50, 55, 50, 37, 22, 9, 3, 0,
0, 0, 3, 7, 13, 18, 20, 18, 13, 7, 3, 0, 0,
0, 0, 0, 1, 3, 4, 5, 4, 3, 1, 0, 0, 0];
*/
var tmp:int = 0;
var temp:Array = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 5, 12, 21, 29, 32, 29, 21, 12, 5, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 5, 21, 56, 110, 171, 218, 235, 218, 171, 110, 56, 21, 5, 0, 0, 0, 0,
0, 0, 0, 8, 40, 118, 231, 255, 255, 255, 255, 255, 255, 255, 231, 118, 40, 8, 0, 0, 0,
0, 0, 5, 40, 147, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 147, 40, 5, 0, 0,
0, 1, 21, 118, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 118, 21, 1, 0,
0, 5, 56, 231, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 231, 56, 5, 0,
0, 12, 110, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 110, 12, 0,
0, 21, 171, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 171, 21, 0,
1, 29, 218, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 218, 29, 1,
1, 32, 235, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 235, 32, 1,
1, 29, 218, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 218, 29, 1,
0, 21, 171, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 171, 21, 0,
0, 12, 110, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 110, 12, 0,
0, 5, 56, 231, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 231, 56, 5, 0,
0, 1, 21, 118, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 118, 21, 1, 0,
0, 0, 5, 40, 147, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 147, 40, 5, 0, 0,
0, 0, 0, 8, 40, 118, 231, 255, 255, 255, 255, 255, 255, 255, 231, 118, 40, 8, 0, 0, 0,
0, 0, 0, 0, 5, 21, 56, 110, 171, 218, 235, 218, 171, 110, 56, 21, 5, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 5, 12, 21, 29, 32, 29, 21, 12, 5, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0];
for( var i:int = 0; i < temp.length; i++){
tmp += temp[i];
}
bmd = new BitmapData(465, 465, true, 0xFFFFFFFF);
bmd.fillRect( new Rectangle( 200, 200, 200, 100 ), 0xFFFF0000);
bmd.applyFilter(bmd, bmd.rect, new Point(), new ConvolutionFilter(21, 21, temp, tmp/2));
addChild(new Bitmap(bmd));
var tf:TextField = new TextField;
tf.autoSize = "left";
addChild(tf);
tf.text = str;
tf.appendText( "divisor: " + String(tmp) + "(/2 is better for some reason?)" );
}
}
}