From 20690ceb40295952dcddd168062424f27012ac9c Mon Sep 17 00:00:00 2001 From: Luca Deltodesco Date: Thu, 22 Aug 2013 16:02:21 +0100 Subject: [PATCH 1/2] Added build32RGBA to png.Tools --- format/png/Tools.hx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/format/png/Tools.hx b/format/png/Tools.hx index 5cc6fe94..dfe2f2ec 100644 --- a/format/png/Tools.hx +++ b/format/png/Tools.hx @@ -610,6 +610,30 @@ class Tools { return l; } + /** + Creates PNG data from bytes that contains four bytes in RGBA format for each pixel. + **/ + public static function build32RGBA( width : Int, height : Int, data : haxe.io.Bytes ) : Data { + var rgba = haxe.io.Bytes.alloc(width * height * 4 + height); + // translate ARGB to RGBA and add filter byte + var w = 0, r = 0; + for( y in 0...height ) { + rgba.set(w++,0); // no filter for this scanline + for( x in 0...width ) { + rgba.set(w++,data.get(r)); // r + rgba.set(w++,data.get(r+1)); // g + rgba.set(w++,data.get(r+2)); // b + rgba.set(w++,data.get(r+3)); // a + r += 4; + } + } + var l = new List(); + l.add(CHeader({ width : width, height : height, colbits : 8, color : ColTrue(true), interlaced : false })); + l.add(CData(format.tools.Deflate.run(rgba))); + l.add(CEnd); + return l; + } + /** Creates PNG data from bytes that contains four bytes in ARGB format for each pixel. **/ From 36762d5904034b7fa7fe01e1a14c2c559e04523d Mon Sep 17 00:00:00 2001 From: Luca Deltodesco Date: Thu, 22 Aug 2013 16:03:32 +0100 Subject: [PATCH 2/2] Fix comment on build32RGBA --- format/png/Tools.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/format/png/Tools.hx b/format/png/Tools.hx index dfe2f2ec..9307c47e 100644 --- a/format/png/Tools.hx +++ b/format/png/Tools.hx @@ -615,7 +615,7 @@ class Tools { **/ public static function build32RGBA( width : Int, height : Int, data : haxe.io.Bytes ) : Data { var rgba = haxe.io.Bytes.alloc(width * height * 4 + height); - // translate ARGB to RGBA and add filter byte + // add filter byte var w = 0, r = 0; for( y in 0...height ) { rgba.set(w++,0); // no filter for this scanline