This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-imaging.git
commit 6366b427ba98fb45855de98afc887b7396bff585 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Tue May 16 10:27:38 2023 -0400 Encapsulate PngChunk --- .../imaging/formats/png/PngImageParser.java | 6 ++-- .../imaging/formats/png/chunks/PngChunk.java | 42 ++++++++++++++++++---- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java b/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java index 7c165c07..38592172 100644 --- a/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java +++ b/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java @@ -115,7 +115,7 @@ public class PngImageParser extends ImageParser<PngImagingParameters> implement for (int i = 0; i < chunks.size(); i++) { final PngChunk chunk = chunks.get(i); - printCharQuad(pw, "\t" + i + ": ", chunk.chunkType); + printCharQuad(pw, "\t" + i + ": ", chunk.getChunkType()); } pw.println(""); @@ -129,7 +129,7 @@ public class PngImageParser extends ImageParser<PngImagingParameters> implement final List<PngChunk> result = new ArrayList<>(); for (final PngChunk chunk : chunks) { - if (chunk.chunkType == type.value) { + if (chunk.getChunkType() == type.value) { result.add(chunk); } } @@ -337,7 +337,7 @@ public class PngImageParser extends ImageParser<PngImagingParameters> implement final List<PngChunk> chunks = readChunks(is, null, false); final List<String> chunkTypes = Allocator.arrayList(chunks.size()); for (final PngChunk chunk : chunks) { - chunkTypes.add(getChunkTypeName(chunk.chunkType)); + chunkTypes.add(getChunkTypeName(chunk.getChunkType())); } return chunkTypes; } diff --git a/src/main/java/org/apache/commons/imaging/formats/png/chunks/PngChunk.java b/src/main/java/org/apache/commons/imaging/formats/png/chunks/PngChunk.java index 5fc95e2e..8f34572f 100644 --- a/src/main/java/org/apache/commons/imaging/formats/png/chunks/PngChunk.java +++ b/src/main/java/org/apache/commons/imaging/formats/png/chunks/PngChunk.java @@ -29,16 +29,16 @@ import org.apache.commons.imaging.common.BinaryFileParser; */ public class PngChunk extends BinaryFileParser { - public final int length; - public final int chunkType; - public final int crc; + private final int length; + private final int chunkType; + private final int crc; private final byte[] bytes; private final boolean[] propertyBits; - public final boolean ancillary; - public final boolean isPrivate; - public final boolean reserved; - public final boolean safeToCopy; + private final boolean ancillary; + private final boolean isPrivate; + private final boolean reserved; + private final boolean safeToCopy; /** * Constructs a new instance. @@ -79,6 +79,14 @@ public class PngChunk extends BinaryFileParser { return bytes.clone(); } + public int getChunkType() { + return chunkType; + } + + public int getCrc() { + return crc; + } + /** * Gets a new {@link ByteArrayInputStream} for the chunk bytes. * @@ -90,6 +98,10 @@ public class PngChunk extends BinaryFileParser { return new ByteArrayInputStream(bytes); } + public int getLength() { + return length; + } + /** * Gets a copy of the chunk property bits. * @@ -99,4 +111,20 @@ public class PngChunk extends BinaryFileParser { return propertyBits.clone(); } + public boolean isAncillary() { + return ancillary; + } + + public boolean isPrivate() { + return isPrivate; + } + + public boolean isReserved() { + return reserved; + } + + public boolean isSafeToCopy() { + return safeToCopy; + } + }