flash on 2010-10-3
PBT2から使えるようになったパラメータタイプを使って入力データのwidthとheightを取ろうとしてもFPでは0になるでござるの巻
♥0 |
Line 115 |
Modified 2010-10-03 00:53:00 |
MIT License
archived:2017-03-20 17:12:13
ActionScript3 source code
/**
* Copyright zahir ( http://wonderfl.net/user/zahir )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/1Qyb
*/
/*
<languageVersion : 1.0;>
kernel NewFilter
< namespace : "jp.zahir";
vendor : "zahir";
version : 1;
description : "your description";
>
{
input image4 src;
output pixel4 dst;
parameter float2 size<
parameterType : "inputSize";
inputSizeName : "src";
>;
void
evaluatePixel(){
float4 a = sampleLinear( src, outCoord() );
dst = pixel4( size.x, size.y, 0.0, 1.0 );
}
}
*/
package
{
import __AS3__.vec.Vector;
import flash.display.Bitmap;
import flash.display.Loader;
import flash.display.ShaderJob;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.ShaderEvent;
import flash.filters.ShaderFilter;
import flash.net.FileFilter;
import flash.net.FileReference;
import flash.text.TextField;
[SWF(width="465",height="465")]
public class PbjTest extends Sprite
{
private const FFilter:Array = [ new FileFilter("load jpg file","*.jpg") ];
private var t:TextField;
private var btn:Btn;
private var f:FileReference;
private var l:Loader;
private var bmp:Bitmap;
private var s:NewFilter;
private var sj:ShaderJob;
private var v:Vector.<Number>;
public function PbjTest()
{
addChild( ( t = new TextField() ) );
t.width = t.height = 465;
addChild( ( btn = new Btn() ) );
btn.x = 465 - btn.width - 10;
btn.y = 10;
btn.addEventListener( MouseEvent.MOUSE_UP, startLoad );
v = new Vector.<Number>();
f = new FileReference();
l = new Loader();
s = new NewFilter();
sj = new ShaderJob( s, v, 1,1);
sj.addEventListener(ShaderEvent.COMPLETE, function(e:ShaderEvent):void{
t.text = "width :: " + v[0];
t.appendText("\nheight :: " + v[1]);
});
}
private function startLoad( e:MouseEvent ):void
{
f.addEventListener(Event.SELECT, onSelect );
f.browse( FFilter );
}
private function onSelect( e:Event ):void
{
f.removeEventListener(Event.SELECT, onSelect );
f.addEventListener(Event.COMPLETE, onComp);
f.load();
}
private function onComp(e:Event):void
{
f.removeEventListener( Event.COMPLETE, onComp );
l.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComp );
l.loadBytes( f.data );
}
private function loadComp(e:Event):void
{
l.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadComp );
bmp = l.content as Bitmap;
s.src( bmp.bitmapData, bmp.width, bmp.height );
/*
sj.width = bmp.width;
sj.height = bmp.height;
*/
sj.start( false );
}
}
}
import flash.display.Shader;
import flash.utils.ByteArray;
import mx.utils.Base64Decoder;
import flash.display.Sprite;
import flash.text.TextField;
class NewFilter extends Shader{
static private var code:ByteArray;
// static initializer
{
static var dec:Base64Decoder = new Base64Decoder() ;
dec.decode(
"pQEAAACkCQBOZXdGaWx0ZXKgDG5hbWVzcGFjZQBqcC56YWhpcgCgDHZlbmRvcgB6YWhpcgCgCHZl" +
"cnNpb24AAQCgDGRlc2NyaXB0aW9uAHlvdXIgZGVzY3JpcHRpb24AoQECAAAMX091dENvb3JkAKMA" +
"BHNyYwChAgQBAA9kc3QAoQECAAADc2l6ZQCiDHBhcmFtZXRlclR5cGUAaW5wdXRTaXplAKIMaW5w" +
"dXRTaXplTmFtZQBzcmMAMQIA8QAAEAAdAwDzAgAbAB0CAIAAAIAAHQIAQAAAwAAyBACAAAAAAB0C" +
"ACAEAAAAMgQAgD+AAAAdAgAQBAAAAB0BAPMCABsA" );
code = dec.toByteArray();
dec = null;
}
public function NewFilter(){
super( code );
}
public function src( input:*, width:int, height:int):void{
data[ "src" ].input = input;
data[ "src" ].width = width;
data[ "src" ].height = height;
}
}
class Btn extends Sprite
{
private var t:TextField;
public function Btn()
{
addChild( ( t = new TextField()) );
t.autoSize = "left";
t.text = "load";
t.textColor = 0xFFFFFF;
t.mouseEnabled = false;
graphics.beginFill(0);
graphics.drawRect( 0,0, t.width + 20, t.height + 10 );
graphics.endFill();
t.x = (width - t.width) >> 1;
t.y = (height - t.height) >> 1;
this.buttonMode = true;
}
}