[AS3.0] カラー補正クラスに挑戦! (3)

対象の DisplayObject のカラー補正をする ColorMatrixManangerクラス をAS3.0クラスで作ってみる。 :bouzu:

ColorMatrixFilterクラスColorMatrixクラスを使ってみた。
PhotoLoaderクラスも使ったよ。

:caution: 要 Flash Player 9 以上

This movie requires Flash Player 9.0.0

ColorMatrixManager.as (jp.nya.project.controls.ColorMatrixManager.as)
:banana: [AS3.0] カラー補正クラスに挑戦! (2) 参照。

PhotoLoader.as (jp.nya.project.controls.PhotoLoader.as)
:banana: [AS3.0] PhotoLoaderクラスに挑戦! (1) 参照。

Main.as
package {

  import flash.display.Sprite;
  import mx.core.BitmapAsset;
  import jp.nya.project.controls.PhotoLoader;
  import jp.nya.project.utils.ColorMatrixManager;
  import jp.nya.project.controls.Menu;
  import jp.nya.project.controls.Slider;
  import jp.nya.project.controls.Wheel;

  import jp.nya.project.events.CompoEvent;

  [SWF(backgroundColor="#FFFFFF", width="360", height="470", frameRate="30")]

  public class Main extends Sprite {
    // プロパティ
    private var colorMatrixManager:ColorMatrixManager;
    private var loader:PhotoLoader;
    private var photoList:Array;
    private var photoID:uint = 0;
    private var menu:Menu;
    private var slider1:Slider;
    private var slider2:Slider;
    private var slider3:Slider;
    private var wheel:Wheel;

    // コンストラクタ
    public function Main() {
      init();
    }

    // メソッド
    private function init():void {
      loader = new PhotoLoader();
      loader.x = 20;
      loader.y = 40;
      addChild(loader);
      loader.addEventListener(PhotoLoader.COMPLETE, complete, false, 0, true);
      photoList = new Array();
      photoList.push({label: "photo1", path: "photo1.jpg"});
      photoList.push({label: "photo2", path: "photo2.jpg"});
      photoList.push({label: "photo3", path: "photo3.jpg"});
      photoList.push({label: "photo4", path: "photo4.jpg"});
      menu = new Menu();
      addChild(menu);
      menu.x = 30;
      menu.y = 10;
      menu.init({label: "photo"});
      menu.dataProvider = photoList;
      menu.initialize(photoID);

      menu.addEventListener(CompoEvent.SELECT, select, false, 0, true);
      load(photoID);
      slider1 = new Slider();
      slider1.x = 30;
      slider1.y = 260;
      addChild(slider1);
      slider1.init({label: "brightOffset", width: 200, grid: 10, min: -100, max: 100, init: 0});
      slider1.addEventListener(CompoEvent.CHANGE, change1, false, 0, true);
      slider2 = new Slider();
      slider2.x = 30;
      slider2.y = 320;
      addChild(slider2);
      slider2.init({label: "saturation", width: 200, grid: 10, min: 0, max: 200, init: 100});
      slider2.addEventListener(CompoEvent.CHANGE, change2, false, 0, true);
      slider3 = new Slider();
      slider3.x = 30;
      slider3.y = 380;
      addChild(slider3);
      slider3.init({label: "saturation", width: 200, grid: 10, min: 0, max: 200, init: 100});
      slider3.addEventListener(CompoEvent.CHANGE, change3, false, 0, true);
      wheel = new Wheel();
      wheel.x = 250;
      wheel.y = 260;
      addChild(wheel);
      wheel.init({label: "hue", angle: 0});
      wheel.addEventListener(CompoEvent.CHANGE, change4, false, 0, true);
    }
    private function load(id:uint):void {
      var filePath:String = photoList[id].path;
      loader.load(filePath);
    }
    private function complete(evt:Event):void {
      colorMatrixManager = new ColorMatrixManager(PhotoLoader(evt.target));
      reset(null);
    }
    private function change1(evt:CompoEvent):void {
      colorMatrixManager.brightness(evt.value);
    }
    private function change2(evt:CompoEvent):void {
      colorMatrixManager.contrast(evt.value);
    }
    private function change3(evt:CompoEvent):void {
      colorMatrixManager.saturation(evt.value);
    }
    private function change4(evt:CompoEvent):void {
      colorMatrixManager.hue(evt.value);
    }

  }

}

Xcode + Flex 2 SDK + Terminal
$ mxmlc -library-path+=components/Menu.swc,components/Slider.swc,components/Wheel.swc Main.as
とする。