From b5a57976be7b9ac73b503528bc7826fbbe334bec Mon Sep 17 00:00:00 2001 From: Assaf Lavie Date: Sun, 31 Mar 2013 16:01:23 +0300 Subject: [PATCH] Much more efficient encoding of non-transparent PNG. Using SetPixels is much faster (about 5x as fast) than copying the pixels one by one. --- src/com/adobe/images/PNGEncoder.as | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/com/adobe/images/PNGEncoder.as b/src/com/adobe/images/PNGEncoder.as index 83c95f6..c6de593 100644 --- a/src/com/adobe/images/PNGEncoder.as +++ b/src/com/adobe/images/PNGEncoder.as @@ -72,9 +72,10 @@ package com.adobe.images var j:int; if ( !img.transparent ) { for(j=0;j < img.width;j++) { - p = img.getPixel(j,i); - IDAT.writeUnsignedInt( - uint(((p&0xFFFFFF) << 8)|0xFF)); + // ARGB -> RGBA + var pixelsARGB : ByteArray = img.getPixels(new Rectangle(0, i, img.width, 1)); + IDAT.writeBytes(pixelsARGB, 1, pixelsARGB.length - 1); + IDAT.writeBytes(pixelsARGB, 0, 1); } } else { for(j=0;j < img.width;j++) {