| 1 |
package { |
|---|
| 2 |
|
|---|
| 3 |
import flash.display.Bitmap; |
|---|
| 4 |
import flash.display.BitmapData; |
|---|
| 5 |
import flash.display.Sprite; |
|---|
| 6 |
import flash.events.Event; |
|---|
| 7 |
import flash.geom.Matrix; |
|---|
| 8 |
import flash.geom.Rectangle; |
|---|
| 9 |
import flash.utils.ByteArray; |
|---|
| 10 |
|
|---|
| 11 |
import net.saqoosha.colorlog.ColorLog; |
|---|
| 12 |
import net.saqoosha.colorlog.SGR; |
|---|
| 13 |
|
|---|
| 14 |
[SWF(width=500, height=500, backgroundColor=0x0, frameRate=15)] |
|---|
| 15 |
|
|---|
| 16 |
public class TestColorLog4 extends Sprite { |
|---|
| 17 |
|
|---|
| 18 |
[Embed(source='saqoosha.jpg')] |
|---|
| 19 |
private static const imageClass:Class; |
|---|
| 20 |
|
|---|
| 21 |
private static const COLORS:Array = [ |
|---|
| 22 |
SGR.BG_NORMAL_BLACK, |
|---|
| 23 |
SGR.BG_BRIGHT_BLUE, |
|---|
| 24 |
SGR.BG_BRIGHT_GREEN, |
|---|
| 25 |
SGR.BG_BRIGHT_CYAN, |
|---|
| 26 |
SGR.BG_BRIGHT_RED, |
|---|
| 27 |
SGR.BG_BRIGHT_MAGENTA, |
|---|
| 28 |
SGR.BG_BRIGHT_YELLOW, |
|---|
| 29 |
SGR.BG_BRIGHT_WHITE |
|---|
| 30 |
]; |
|---|
| 31 |
|
|---|
| 32 |
private var _canvas:BitmapData; |
|---|
| 33 |
private var _y:int; |
|---|
| 34 |
|
|---|
| 35 |
public function TestColorLog4() { |
|---|
| 36 |
this._canvas = new BitmapData(100, 50, false, 0); |
|---|
| 37 |
var b:Bitmap = new Bitmap(this._canvas); |
|---|
| 38 |
b.scaleX = 5; |
|---|
| 39 |
b.scaleY = 10; |
|---|
| 40 |
this.addChild(b); |
|---|
| 41 |
|
|---|
| 42 |
var img:BitmapData = Bitmap(new imageClass()).bitmapData; |
|---|
| 43 |
var mtx:Matrix = new Matrix(100 / img.width, 0, 0, 50 / img.height, 0, 0); |
|---|
| 44 |
this._canvas.draw(img, mtx); |
|---|
| 45 |
|
|---|
| 46 |
this._y = 0; |
|---|
| 47 |
this.addEventListener(Event.ENTER_FRAME, this._update); |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
private function _update(e:Event):void { |
|---|
| 51 |
var n:int = this._canvas.width; |
|---|
| 52 |
var b:ByteArray = this._canvas.getPixels(new Rectangle(0, this._y, n, 1)); |
|---|
| 53 |
// ColorLog.moveTo(this._y + 1, 1); |
|---|
| 54 |
for (var i:int = 0; i < n; i++) { |
|---|
| 55 |
var p:int = i * 4; |
|---|
| 56 |
var c:int = (b[p + 1] & 0x80) ? 0x4 : 0; |
|---|
| 57 |
c |= (b[p + 2] & 0x80) ? 0x2 : 0; |
|---|
| 58 |
c |= (b[p + 3] & 0x80) ? 0x1 : 0; |
|---|
| 59 |
ColorLog.setColor(COLORS[c]); |
|---|
| 60 |
ColorLog.out(' '); |
|---|
| 61 |
} |
|---|
| 62 |
ColorLog.flush(); |
|---|
| 63 |
if (++this._y == this._canvas.height) { |
|---|
| 64 |
this.removeEventListener(Event.ENTER_FRAME, this._update); |
|---|
| 65 |
} |
|---|
| 66 |
} |
|---|
| 67 |
} |
|---|
| 68 |
} |
|---|