Author: damjan Date: Tue Dec 4 05:10:17 2012 New Revision: 1416781 URL: http://svn.apache.org/viewvc?rev=1416781&view=rev Log: Add support for the PNG tRNS chunk.
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngConstants.java commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngConstants.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngConstants.java?rev=1416781&r1=1416780&r2=1416781&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngConstants.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngConstants.java Tue Dec 4 05:10:17 2012 @@ -28,6 +28,8 @@ public interface PngConstants extends Im new byte[] { 73, 72, 68, 82 }); public final static BinaryConstant PLTE_CHUNK_TYPE = new BinaryConstant( new byte[] { 80, 76, 84, 69 }); + public final static BinaryConstant TRNS_CHUNK_TYPE = new BinaryConstant( + new byte[] { 't', 'R', 'N', 'S'}); public final static BinaryConstant IEND_CHUNK_TYPE = new BinaryConstant( new byte[] { 73, 69, 78, 68 }); public final static BinaryConstant IDAT_CHUNK_TYPE = new BinaryConstant( Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java?rev=1416781&r1=1416780&r2=1416781&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java Tue Dec 4 05:10:17 2012 @@ -251,6 +251,16 @@ public class PngWriter implements PngCon writeChunk(os, PLTE_CHUNK_TYPE.toByteArray(), bytes); } + private void writeChunkTRNS(OutputStream os, Palette palette) throws IOException { + byte[] bytes = new byte[palette.length()]; + + for (int i = 0; i < bytes.length; i++) { + bytes[i] = (byte) (0xff & (palette.getEntry(i) >> 24)); + } + + writeChunk(os, TRNS_CHUNK_TYPE.toByteArray(), bytes); + } + private void writeChunkIEND(OutputStream os) throws IOException { writeChunk(os, IEND_CHUNK_TYPE.toByteArray(), null); }