You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by eb...@apache.org on 2013/11/28 00:47:52 UTC
svn commit: r1546236 - in
/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png:
ChunkType.java PngConstants.java PngImageParser.java PngWriter.java
Author: ebourg
Date: Wed Nov 27 23:47:51 2013
New Revision: 1546236
URL: http://svn.apache.org/r1546236
Log:
Moved the PNG chunk types into an enum
Added:
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/ChunkType.java (with props)
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/PngImageParser.java
commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java
Added: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/ChunkType.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/ChunkType.java?rev=1546236&view=auto
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/ChunkType.java (added)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/ChunkType.java Wed Nov 27 23:47:51 2013
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.imaging.formats.png;
+
+import org.apache.commons.imaging.common.BinaryFunctions;
+
+/**
+ * Type of a PNG chunk.
+ *
+ * @see <a href="http://www.w3.org/TR/PNG/#11Chunks">Portable Network Graphics Specification - Chunk specifications</a>
+ */
+public enum ChunkType {
+
+ /** Image header */
+ IHDR,
+
+ /** Palette */
+ PLTE,
+
+ /** Image data */
+ IDAT,
+
+ /** Image trailer */
+ IEND,
+
+ /** Transparency */
+ tRNS,
+
+ /** Image gamma */
+ gAMA,
+
+ /** Embedded ICC profile */
+ iCCP,
+
+ /** Standard RGB colour space */
+ sRGB,
+
+ /** Textual data */
+ tEXt,
+
+ /** Compressed textual data */
+ zTXt,
+
+ /** International textual data */
+ iTXt,
+
+ /** Physical pixel dimensions */
+ pHYs;
+
+ final byte[] array;
+ final int value;
+
+ private ChunkType() {
+ char[] chars = name().toCharArray();
+ array = name().getBytes();
+ value = BinaryFunctions.charsToQuad(chars[0], chars[1], chars[2], chars[3]);
+ }
+}
Propchange: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/ChunkType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/ChunkType.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
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=1546236&r1=1546235&r2=1546236&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 Wed Nov 27 23:47:51 2013
@@ -17,37 +17,11 @@
package org.apache.commons.imaging.formats.png;
import org.apache.commons.imaging.common.BinaryConstant;
-import org.apache.commons.imaging.common.BinaryFunctions;
public interface PngConstants {
public static final int COMPRESSION_DEFLATE_INFLATE = 0;
- public static final BinaryConstant IHDR_CHUNK_TYPE = new BinaryConstant(new byte[] { 'I', 'H', 'D', 'R' });
- public static final BinaryConstant PLTE_CHUNK_TYPE = new BinaryConstant(new byte[] { 'P', 'L', 'T', 'E' });
- public static final BinaryConstant tRNS_CHUNK_TYPE = new BinaryConstant(new byte[] { 't', 'R', 'N', 'S' });
- public static final BinaryConstant IEND_CHUNK_TYPE = new BinaryConstant(new byte[] { 'I', 'E', 'N', 'D' });
- public static final BinaryConstant IDAT_CHUNK_TYPE = new BinaryConstant(new byte[] { 'I', 'D', 'A', 'T' });
- public static final BinaryConstant iTXt_CHUNK_TYPE = new BinaryConstant(new byte[] { 'i', 'T', 'X', 't' });
- public static final BinaryConstant tEXt_CHUNK_TYPE = new BinaryConstant(new byte[] { 't', 'E', 'X', 't' });
- public static final BinaryConstant zTXt_CHUNK_TYPE = new BinaryConstant(new byte[] { 'z', 'T', 'X', 't' });
- public static final BinaryConstant pHYs_CHUNK_TYPE = new BinaryConstant(new byte[] { 'p', 'H', 'Y', 's' });
-
- public static final int IEND = BinaryFunctions.charsToQuad('I', 'E', 'N', 'D');
- public static final int IHDR = BinaryFunctions.charsToQuad('I', 'H', 'D', 'R');
- public static final int iCCP = BinaryFunctions.charsToQuad('i', 'C', 'C', 'P');
- public static final int tEXt = BinaryFunctions.charsToQuad('t', 'E', 'X', 't');
- public static final int zTXt = BinaryFunctions.charsToQuad('z', 'T', 'X', 't');
- public static final int pHYs = BinaryFunctions.charsToQuad('p', 'H', 'Y', 's');
- public static final int PLTE = BinaryFunctions.charsToQuad('P', 'L', 'T', 'E');
- public static final int IDAT = BinaryFunctions.charsToQuad('I', 'D', 'A', 'T');
- public static final int tRNS = BinaryFunctions.charsToQuad('t', 'R', 'N', 'S');
- public static final int gAMA = BinaryFunctions.charsToQuad('g', 'A', 'M', 'A');
- public static final int sRGB = BinaryFunctions.charsToQuad('s', 'R', 'G', 'B');
-
- // XMP chunk type.
- public static final int iTXt = BinaryFunctions.charsToQuad('i', 'T', 'X', 't');
-
public static final BinaryConstant PNG_SIGNATURE = new BinaryConstant(
new byte[] { (byte) 0x89, 'P', 'N', 'G', '\r', '\n', 0x1A, '\n', });
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java?rev=1546236&r1=1546235&r2=1546236&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java Wed Nov 27 23:47:51 2013
@@ -113,7 +113,7 @@ public class PngImageParser extends Imag
return chunkTypes;
}
- public boolean hasChuckType(final ByteSource byteSource, final int chunkType)
+ public boolean hasChuckType(final ByteSource byteSource, final ChunkType chunkType)
throws ImageReadException, IOException {
InputStream is = null;
boolean canThrow = false;
@@ -121,7 +121,7 @@ public class PngImageParser extends Imag
is = byteSource.getInputStream();
readSignature(is);
- final List<PngChunk> chunks = readChunks(is, new int[] { chunkType, }, true);
+ final List<PngChunk> chunks = readChunks(is, new ChunkType[] { chunkType }, true);
canThrow = true;
return !chunks.isEmpty();
} finally {
@@ -129,21 +129,21 @@ public class PngImageParser extends Imag
}
}
- private boolean keepChunk(final int chunkType, final int[] chunkTypes) {
+ private boolean keepChunk(final int chunkType, final ChunkType[] chunkTypes) {
// System.out.println("keepChunk: ");
if (chunkTypes == null) {
return true;
}
- for (final int chunkType2 : chunkTypes) {
- if (chunkType2 == chunkType) {
+ for (final ChunkType chunkType2 : chunkTypes) {
+ if (chunkType2.value == chunkType) {
return true;
}
}
return false;
}
- private List<PngChunk> readChunks(final InputStream is, final int[] chunkTypes,
+ private List<PngChunk> readChunks(final InputStream is, final ChunkType[] chunkTypes,
final boolean returnAfterFirst) throws ImageReadException, IOException {
final List<PngChunk> result = new ArrayList<PngChunk>();
@@ -178,23 +178,23 @@ public class PngImageParser extends Imag
final int crc = read4Bytes("CRC", is, "Not a Valid PNG File", getByteOrder());
if (keep) {
- if (chunkType == PngConstants.iCCP) {
+ if (chunkType == ChunkType.iCCP.value) {
result.add(new PngChunkIccp(length, chunkType, crc, bytes));
- } else if (chunkType == PngConstants.tEXt) {
+ } else if (chunkType == ChunkType.tEXt.value) {
result.add(new PngChunkText(length, chunkType, crc, bytes));
- } else if (chunkType == PngConstants.zTXt) {
+ } else if (chunkType == ChunkType.zTXt.value) {
result.add(new PngChunkZtxt(length, chunkType, crc, bytes));
- } else if (chunkType == PngConstants.IHDR) {
+ } else if (chunkType == ChunkType.IHDR.value) {
result.add(new PngChunkIhdr(length, chunkType, crc, bytes));
- } else if (chunkType == PngConstants.PLTE) {
+ } else if (chunkType == ChunkType.PLTE.value) {
result.add(new PngChunkPlte(length, chunkType, crc, bytes));
- } else if (chunkType == PngConstants.pHYs) {
+ } else if (chunkType == ChunkType.pHYs.value) {
result.add(new PngChunkPhys(length, chunkType, crc, bytes));
- } else if (chunkType == PngConstants.IDAT) {
+ } else if (chunkType == ChunkType.IDAT.value) {
result.add(new PngChunkIdat(length, chunkType, crc, bytes));
- } else if (chunkType == PngConstants.gAMA) {
+ } else if (chunkType == ChunkType.gAMA.value) {
result.add(new PngChunkGama(length, chunkType, crc, bytes));
- } else if (chunkType == PngConstants.iTXt) {
+ } else if (chunkType == ChunkType.iTXt.value) {
result.add(new PngChunkItxt(length, chunkType, crc, bytes));
} else {
result.add(new PngChunk(length, chunkType, crc, bytes));
@@ -205,7 +205,7 @@ public class PngImageParser extends Imag
}
}
- if (chunkType == PngConstants.IEND) {
+ if (chunkType == ChunkType.IEND.value) {
break;
}
@@ -222,7 +222,7 @@ public class PngImageParser extends Imag
}
- private List<PngChunk> readChunks(final ByteSource byteSource, final int[] chunkTypes,
+ private List<PngChunk> readChunks(final ByteSource byteSource, final ChunkType[] chunkTypes,
final boolean returnAfterFirst) throws ImageReadException, IOException {
InputStream is = null;
boolean canThrow = false;
@@ -242,7 +242,7 @@ public class PngImageParser extends Imag
@Override
public byte[] getICCProfileBytes(final ByteSource byteSource, final Map<String, Object> params)
throws ImageReadException, IOException {
- final List<PngChunk> chunks = readChunks(byteSource, new int[] { PngConstants.iCCP, },
+ final List<PngChunk> chunks = readChunks(byteSource, new ChunkType[] { ChunkType.iCCP },
true);
if ((chunks == null) || (chunks.isEmpty())) {
@@ -264,8 +264,7 @@ public class PngImageParser extends Imag
@Override
public Dimension getImageSize(final ByteSource byteSource, final Map<String, Object> params)
throws ImageReadException, IOException {
- final List<PngChunk> chunks = readChunks(byteSource, new int[] { PngConstants.IHDR, },
- true);
+ final List<PngChunk> chunks = readChunks(byteSource, new ChunkType[] { ChunkType.IHDR, }, true);
if ((chunks == null) || (chunks.isEmpty())) {
throw new ImageReadException("Png: No chunks");
@@ -287,8 +286,7 @@ public class PngImageParser extends Imag
@Override
public IImageMetadata getMetadata(final ByteSource byteSource, final Map<String, Object> params)
throws ImageReadException, IOException {
- final List<PngChunk> chunks = readChunks(byteSource,
- new int[] { PngConstants.tEXt, PngConstants.zTXt, }, true);
+ final List<PngChunk> chunks = readChunks(byteSource, new ChunkType[] { ChunkType.tEXt, ChunkType.zTXt, }, true);
if ((chunks == null) || (chunks.isEmpty())) {
return null;
@@ -397,11 +395,11 @@ public class PngImageParser extends Imag
throw new ImageReadException("PNG: unknown color type: " + colorType);
}
- private List<PngChunk> filterChunks(final List<PngChunk> chunks, final int type) {
+ private List<PngChunk> filterChunks(final List<PngChunk> chunks, final ChunkType type) {
final List<PngChunk> result = new ArrayList<PngChunk>();
for (PngChunk chunk : chunks) {
- if (chunk.chunkType == type) {
+ if (chunk.chunkType == type.value) {
result.add(chunk);
}
}
@@ -476,14 +474,14 @@ public class PngImageParser extends Imag
@Override
public ImageInfo getImageInfo(final ByteSource byteSource, final Map<String, Object> params)
throws ImageReadException, IOException {
- final List<PngChunk> chunks = readChunks(byteSource, new int[] {
- PngConstants.IHDR,
- PngConstants.pHYs,
- PngConstants.tEXt,
- PngConstants.zTXt,
- PngConstants.tRNS,
- PngConstants.PLTE,
- PngConstants.iTXt,
+ final List<PngChunk> chunks = readChunks(byteSource, new ChunkType[] {
+ ChunkType.IHDR,
+ ChunkType.pHYs,
+ ChunkType.tEXt,
+ ChunkType.zTXt,
+ ChunkType.tRNS,
+ ChunkType.PLTE,
+ ChunkType.iTXt,
}, false);
// if(chunks!=null)
@@ -493,7 +491,7 @@ public class PngImageParser extends Imag
throw new ImageReadException("PNG: no chunks");
}
- final List<PngChunk> IHDRs = filterChunks(chunks, PngConstants.IHDR);
+ final List<PngChunk> IHDRs = filterChunks(chunks, ChunkType.IHDR);
if (IHDRs.size() != 1) {
throw new ImageReadException("PNG contains more than one Header");
}
@@ -502,7 +500,7 @@ public class PngImageParser extends Imag
boolean transparent = false;
- final List<PngChunk> tRNSs = filterChunks(chunks, PngConstants.tRNS);
+ final List<PngChunk> tRNSs = filterChunks(chunks, ChunkType.tRNS);
if (!tRNSs.isEmpty()) {
transparent = true;
} else {
@@ -513,7 +511,7 @@ public class PngImageParser extends Imag
PngChunkPhys pngChunkpHYs = null;
- final List<PngChunk> pHYss = filterChunks(chunks, PngConstants.pHYs);
+ final List<PngChunk> pHYss = filterChunks(chunks, ChunkType.pHYs);
if (pHYss.size() > 1) {
throw new ImageReadException("PNG contains more than one pHYs: "
+ pHYss.size());
@@ -521,9 +519,9 @@ public class PngImageParser extends Imag
pngChunkpHYs = (PngChunkPhys) pHYss.get(0);
}
- final List<PngChunk> tEXts = filterChunks(chunks, PngConstants.tEXt);
- final List<PngChunk> zTXts = filterChunks(chunks, PngConstants.zTXt);
- final List<PngChunk> iTXts = filterChunks(chunks, PngConstants.iTXt);
+ final List<PngChunk> tEXts = filterChunks(chunks, ChunkType.tEXt);
+ final List<PngChunk> zTXts = filterChunks(chunks, ChunkType.zTXt);
+ final List<PngChunk> iTXts = filterChunks(chunks, ChunkType.iTXt);
final List<String> comments = new ArrayList<String>();
final List<PngText> textChunks = new ArrayList<PngText>();
@@ -580,7 +578,7 @@ public class PngImageParser extends Imag
boolean usesPalette = false;
- final List<PngChunk> PLTEs = filterChunks(chunks, PngConstants.PLTE);
+ final List<PngChunk> PLTEs = filterChunks(chunks, ChunkType.PLTE);
if (PLTEs.size() > 1) {
usesPalette = true;
}
@@ -628,28 +626,28 @@ public class PngImageParser extends Imag
// throw new ImageWriteException("Unknown parameter: " + firstKey);
// }
- final List<PngChunk> chunks = readChunks(byteSource, new int[] {
- PngConstants.IHDR,
- PngConstants.PLTE,
- PngConstants.IDAT,
- PngConstants.tRNS,
- PngConstants.iCCP,
- PngConstants.gAMA,
- PngConstants.sRGB,
+ final List<PngChunk> chunks = readChunks(byteSource, new ChunkType[] {
+ ChunkType.IHDR,
+ ChunkType.PLTE,
+ ChunkType.IDAT,
+ ChunkType.tRNS,
+ ChunkType.iCCP,
+ ChunkType.gAMA,
+ ChunkType.sRGB,
}, false);
if ((chunks == null) || (chunks.isEmpty())) {
throw new ImageReadException("PNG: no chunks");
}
- final List<PngChunk> IHDRs = filterChunks(chunks, PngConstants.IHDR);
+ final List<PngChunk> IHDRs = filterChunks(chunks, ChunkType.IHDR);
if (IHDRs.size() != 1) {
throw new ImageReadException("PNG contains more than one Header");
}
final PngChunkIhdr pngChunkIHDR = (PngChunkIhdr) IHDRs.get(0);
- final List<PngChunk> PLTEs = filterChunks(chunks, PngConstants.PLTE);
+ final List<PngChunk> PLTEs = filterChunks(chunks, ChunkType.PLTE);
if (PLTEs.size() > 1) {
throw new ImageReadException("PNG contains more than one Palette");
}
@@ -661,7 +659,7 @@ public class PngImageParser extends Imag
// -----
- final List<PngChunk> IDATs = filterChunks(chunks, PngConstants.IDAT);
+ final List<PngChunk> IDATs = filterChunks(chunks, ChunkType.IDAT);
if (IDATs.isEmpty()) {
throw new ImageReadException("PNG missing image data");
}
@@ -680,7 +678,7 @@ public class PngImageParser extends Imag
TransparencyFilter transparencyFilter = null;
- final List<PngChunk> tRNSs = filterChunks(chunks, PngConstants.tRNS);
+ final List<PngChunk> tRNSs = filterChunks(chunks, ChunkType.tRNS);
if (!tRNSs.isEmpty()) {
final PngChunk pngChunktRNS = tRNSs.get(0);
transparencyFilter = getTransparencyFilter(pngChunkIHDR.colorType,
@@ -690,9 +688,9 @@ public class PngImageParser extends Imag
ICC_Profile iccProfile = null;
GammaCorrection gammaCorrection = null;
{
- final List<PngChunk> sRGBs = filterChunks(chunks, PngConstants.sRGB);
- final List<PngChunk> gAMAs = filterChunks(chunks, PngConstants.gAMA);
- final List<PngChunk> iCCPs = filterChunks(chunks, PngConstants.iCCP);
+ final List<PngChunk> sRGBs = filterChunks(chunks, ChunkType.sRGB);
+ final List<PngChunk> gAMAs = filterChunks(chunks, ChunkType.gAMA);
+ final List<PngChunk> iCCPs = filterChunks(chunks, ChunkType.iCCP);
if (sRGBs.size() > 1) {
throw new ImageReadException("PNG: unexpected sRGB chunk");
}
@@ -819,7 +817,7 @@ public class PngImageParser extends Imag
imageInfo.toString(pw, "");
final List<PngChunk> chunks = readChunks(byteSource, null, false);
- final List<PngChunk> IHDRs = filterChunks(chunks, PngConstants.IHDR);
+ final List<PngChunk> IHDRs = filterChunks(chunks, ChunkType.IHDR);
if (IHDRs.size() != 1) {
if (getDebug()) {
System.out.println("PNG contains more than one Header");
@@ -868,8 +866,7 @@ public class PngImageParser extends Imag
public String getXmpXml(final ByteSource byteSource, final Map<String, Object> params)
throws ImageReadException, IOException {
- final List<PngChunk> chunks = readChunks(byteSource, new int[] { PngConstants.iTXt, },
- false);
+ final List<PngChunk> chunks = readChunks(byteSource, new ChunkType[] { ChunkType.iTXt }, false);
if ((chunks == null) || (chunks.isEmpty())) {
return null;
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=1546236&r1=1546235&r2=1546236&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 Wed Nov 27 23:47:51 2013
@@ -68,18 +68,18 @@ public class PngWriter {
os.write(0xff & (value >> 0));
}
- private void writeChunk(final OutputStream os, final byte[] chunkType,
+ private void writeChunk(final OutputStream os, final ChunkType chunkType,
final byte[] data) throws IOException {
final int dataLength = data == null ? 0 : data.length;
writeInt(os, dataLength);
- os.write(chunkType);
+ os.write(chunkType.array);
if (data != null) {
os.write(data);
}
final PngCrc png_crc = new PngCrc();
- final long crc1 = png_crc.start_partial_crc(chunkType, chunkType.length);
+ final long crc1 = png_crc.start_partial_crc(chunkType.array, chunkType.array.length);
final long crc2 = data == null ? crc1 : png_crc.continue_partial_crc(
crc1, data, data.length);
final int crc = (int) png_crc.finish_partial_crc(crc2);
@@ -123,7 +123,7 @@ public class PngWriter {
// Debug.debug("baos", baos.toByteArray());
- writeChunk(os, PngConstants.IHDR_CHUNK_TYPE.toByteArray(), baos.toByteArray());
+ writeChunk(os, ChunkType.IHDR, baos.toByteArray());
}
private void writeChunkiTXt(final OutputStream os, final PngText.Itxt text)
@@ -154,7 +154,7 @@ public class PngWriter {
baos.write(deflate(text.text.getBytes("utf-8")));
- writeChunk(os, PngConstants.iTXt_CHUNK_TYPE.toByteArray(), baos.toByteArray());
+ writeChunk(os, ChunkType.iTXt, baos.toByteArray());
}
private void writeChunkzTXt(final OutputStream os, final PngText.Ztxt text)
@@ -178,7 +178,7 @@ public class PngWriter {
// text
baos.write(deflate(text.text.getBytes("ISO-8859-1")));
- writeChunk(os, PngConstants.zTXt_CHUNK_TYPE.toByteArray(), baos.toByteArray());
+ writeChunk(os, ChunkType.zTXt, baos.toByteArray());
}
private void writeChunktEXt(final OutputStream os, final PngText.Text text)
@@ -199,7 +199,7 @@ public class PngWriter {
// text
baos.write(text.text.getBytes("ISO-8859-1"));
- writeChunk(os, PngConstants.tEXt_CHUNK_TYPE.toByteArray(), baos.toByteArray());
+ writeChunk(os, ChunkType.tEXt, baos.toByteArray());
}
public final byte[] deflate(final byte[] bytes) throws IOException {
@@ -245,7 +245,7 @@ public class PngWriter {
baos.write(deflate(xmpXml.getBytes("utf-8")));
- writeChunk(os, PngConstants.iTXt_CHUNK_TYPE.toByteArray(), baos.toByteArray());
+ writeChunk(os, ChunkType.iTXt, baos.toByteArray());
}
private void writeChunkPLTE(final OutputStream os, final Palette palette)
@@ -263,7 +263,7 @@ public class PngWriter {
bytes[index + 2] = (byte) (0xff & (rgb >> 0));
}
- writeChunk(os, PngConstants.PLTE_CHUNK_TYPE.toByteArray(), bytes);
+ writeChunk(os, ChunkType.PLTE, bytes);
}
private void writeChunkTRNS(final OutputStream os, final Palette palette) throws IOException {
@@ -273,16 +273,16 @@ public class PngWriter {
bytes[i] = (byte) (0xff & (palette.getEntry(i) >> 24));
}
- writeChunk(os, PngConstants.tRNS_CHUNK_TYPE.toByteArray(), bytes);
+ writeChunk(os, ChunkType.tRNS, bytes);
}
private void writeChunkIEND(final OutputStream os) throws IOException {
- writeChunk(os, PngConstants.IEND_CHUNK_TYPE.toByteArray(), null);
+ writeChunk(os, ChunkType.IEND, null);
}
private void writeChunkIDAT(final OutputStream os, final byte[] bytes)
throws IOException {
- writeChunk(os, PngConstants.IDAT_CHUNK_TYPE.toByteArray(), bytes);
+ writeChunk(os, ChunkType.IDAT, bytes);
}
private void writeChunkPHYS(final OutputStream os, final int xPPU, final int yPPU, final byte units)
@@ -297,7 +297,7 @@ public class PngWriter {
bytes[6] = (byte) (0xff & (yPPU >> 8));
bytes[7] = (byte) (0xff & (yPPU >> 0));
bytes[8] = units;
- writeChunk(os, PngConstants.pHYs_CHUNK_TYPE.toByteArray(), bytes);
+ writeChunk(os, ChunkType.pHYs, bytes);
}
private byte getColourType(final boolean hasAlpha, final boolean isGrayscale) {