You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by da...@apache.org on 2012/12/04 06:10:18 UTC
svn commit: r1416781 - in
/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png:
PngConstants.java PngWriter.java
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);
}