Skip to content

Commit

Permalink
Added PBFilter template and class.
Browse files Browse the repository at this point in the history
  • Loading branch information
og2t committed Sep 27, 2010
1 parent f95614c commit 4540bf6
Show file tree
Hide file tree
Showing 2 changed files with 193 additions and 0 deletions.
76 changes: 76 additions & 0 deletions src/hislope/filters/PBFilterBase.as
@@ -0,0 +1,76 @@
/*---------------------------------------------------------------------------------------------
[AS3] PBFilterBase
=======================================================================================
HiSlope toolkit copyright (c) 2010 Tomek 'Og2t' Augustyn
http://play.blog2t.net/hislope
You are free to use this source code in any non-commercial project.
You are free to modify this source code in anyway you see fit.
You are free to distribute this source code.
You may NOT charge anything for this source code.
This notice and the copyright information must be left intact in any distribution of this source code.
You are encouraged to release any improvements back to the ActionScript community.
VERSION HISTORY:
v0.1 Born on 07/07/2009
USAGE:
TODOs:
DEV IDEAS:
KNOWN ISSUES
---------------------------------------------------------------------------------------------*/

package hislope.filters
{
// IMPORTS ////////////////////////////////////////////////////////////////////////////////

import hislope.filters.IFilter;
import flash.display.Shader;
import flash.filters.ShaderFilter;
import flash.display.ShaderParameter;
import flash.utils.ByteArray;
import hislope.core.Utils;

// CLASS //////////////////////////////////////////////////////////////////////////////////

public class PBFilterBase extends FilterBase implements IFilter
{
// CONSTANTS //////////////////////////////////////////////////////////////////////////
// MEMBERS ////////////////////////////////////////////////////////////////////////////

protected var shaderFilter:ShaderFilter;
protected var shader:Shader;
private var shaderParams:Array = [];

// CONSTRUCTOR ////////////////////////////////////////////////////////////////////////

public function PBFilterBase(pbjFile:Class, PARAMETERS:Array = null)
{
shader = new Shader(new pbjFile() as ByteArray);
shaderFilter = new ShaderFilter(shader);

if (PARAMETERS) Utils.autoDetectKernelParams(shader, PARAMETERS, shaderParams);

super();
}

// PUBLIC METHODS /////////////////////////////////////////////////////////////////////

public function updateShaderParams(PARAMETERS:Array):void
{
// TODO go through all the shadeParams and update the shader according to the PARAMETERS
}

// PRIVATE METHODS ////////////////////////////////////////////////////////////////////
// EVENT HANDLERS /////////////////////////////////////////////////////////////////////
// GETTERS & SETTERS //////////////////////////////////////////////////////////////////
// HELPERS ////////////////////////////////////////////////////////////////////////////
}
}
117 changes: 117 additions & 0 deletions templates/PBFilterTemplate.as
@@ -0,0 +1,117 @@
/*---------------------------------------------------------------------------------------------
[AS3] FilterName
=======================================================================================
HiSlope toolkit copyright (c) 2010 Tomek 'Og2t' Augustyn
http://play.blog2t.net/hislope
You are free to use this source code in any non-commercial project.
You are free to modify this source code in anyway you see fit.
You are free to distribute this source code.
You may NOT charge anything for this source code.
This notice and the copyright information must be left intact in any distribution of this source code.
You are encouraged to release any improvements back to the ActionScript community.
VERSION HISTORY:
v0.1 Born on 09/07/2009
USAGE:
TODOs:
DEV IDEAS:
KNOWN ISSUES:
---------------------------------------------------------------------------------------------*/

package hislope.filters.pixelbender // filter path
{
// IMPORTS ////////////////////////////////////////////////////////////////////////////////

import hislope.display.MetaBitmapData;
import hislope.filters.PBFilterBase;

// CLASS //////////////////////////////////////////////////////////////////////////////////

public class FilterName extends PBFilterBase
{
// CONSTANTS //////////////////////////////////////////////////////////////////////////

private static const NAME:String = "Filter Name";
private static var PARAMETERS:Array = [
{
name: "param1",
label: "param 1",
current: 0.1,
min: 0,
max: 1,
type: "number"
}, {
name: "param2",
label: "param 2",
current: 1,
min: 0,
max: 255,
type: "int"
}
];

private static const DEBUG_VARS:Array = [
"time",
"frames"
];

[Embed("../../pbj/Levels.pbj", mimeType="application/octet-stream")]
private const pbjFile:Class;

// MEMBERS ////////////////////////////////////////////////////////////////////////////

public var time:Number;
public var frames:Number;

// PARAMETERS /////////////////////////////////////////////////////////////////////////

public var param1:Number;
public var param2:int;

// CONSTRUCTOR ////////////////////////////////////////////////////////////////////////

public function FilterName(OVERRIDE:Object = null)
{
super(pbjFile, PARAMETERS);
// init your bitmaps, variables, etc. here

time = 0;
frames = 0;

init(NAME, PARAMETERS, OVERRIDE, DEBUG_VARS);
}

// PUBLIC METHODS /////////////////////////////////////////////////////////////////////

override public function process(metaBmpData:MetaBitmapData):void
{
// do operations

time += param1;
frames += param2;

metaBmpData.applyShader(shaderFilter);

getPreviewFor(metaBmpData);
}

override public function updateParams():void
{
// update parameters if changed

shader.data.time.value = [time];
shader.data.frames.value = [frames];
}

// PRIVATE METHODS ////////////////////////////////////////////////////////////////////
}
}

0 comments on commit 4540bf6

Please sign in to comment.