In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

YCbCr Color Plane(forked from: YIQ Color Plane)

Get Adobe Flash player
by Aquioux 21 Oct 2010
/**
 * Copyright Aquioux ( http://wonderfl.net/user/Aquioux )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/vZMF
 */

// forked from Aquioux's YIQ Color Plane
package {
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    [SWF(width = "465", height = "465", frameRate = "30", backgroundColor = "#FFFFFF")]
    
    /**
     * YCbCr Color Plane
     * @see http://en.wikipedia.org/wiki/YCbCr
     * @author YOSHIDA, Akio (Aquioux)
     */
    public class Main extends Sprite {
        private const SW:int = stage.stageWidth;
        private const SH:int = stage.stageHeight;
        private const CX:int = SW / 2;
        private const CY:int = SH / 2;

        public function Main() {
            var bmd:BitmapData = new BitmapData(SW, SH, false);
            var bm:Bitmap = new Bitmap(bmd);
            for (var h:int = 0; h < SH; h++) {
                for (var w:int = 0; w < SW; w++) {
                    var cb:Number = w / CX - 1;
                    var cr:Number = h / CY - 1;
                    var color:uint = ycbcrToRgb(0.5, cb, cr);
                    bmd.setPixel(w, h, color);
                }
            }
            bm.scaleY = -1;
            bm.y = SH;
            addChild(bm);
        }
        
        private function ycbcrToRgb(y:Number, cb:Number, cr:Number):uint {
            var r:Number = y              + 1.402 * cr;
            var g:Number = y - 0.344 * cb - 0.714 * cr;
            var b:Number = y + 1.772 * cb
            r *= 255;
            g *= 255;
            b *= 255;
            r >> 0;
            g >> 0;
            b >> 0;
            if (r < 0) r = 0;
            if (g < 0) g = 0;
            if (b < 0) b = 0;
            if (r > 255) r = 255;
            if (g > 255) g = 255;
            if (b > 255) b = 255;
            return r << 16 | g << 8 | b;
        }
    }
}