[
https://issues.apache.org/jira/browse/IMAGING-340?focusedWorklogId=839270=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-839270
]
ASF GitHub Bot logged work on IMAGING-340:
--
Author: ASF GitHub Bot
Created on: 15/Jan/23 13:31
Start Date: 15/Jan/23 13:31
Worklog Time Spent: 10m
Work Description: kinow commented on code in PR #269:
URL: https://github.com/apache/commons-imaging/pull/269#discussion_r1070592972
##
src/main/java/org/apache/commons/imaging/formats/png/package-info.java:
##
@@ -16,7 +16,14 @@
*/
/**
- * The PNG image format.
+ * The PNG (Portable Network Graphics) image format.
+ *
+ * The implementation is based on the
+ * http://www.libpng.org/pub/png/spec/1.2/;>PNG specification version
1.2,
+ * and supports the following extensions:
+ *
+ * http://ftp-osl.osuosl.org/pub/libpng/documents/pngext-1.5.0.html;>Extensions
to the PNG 1.2 Specification, Version 1.5.0
+ *
Review Comment:
Thank you! :clap:
##
src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java:
##
@@ -282,21 +263,53 @@ public Dimension getImageSize(final ByteSource
byteSource, final PngImagingParam
@Override
public ImageMetadata getMetadata(final ByteSource byteSource, final
PngImagingParameters params)
throws ImageReadException, IOException {
-final List chunks = readChunks(byteSource, new ChunkType[] {
ChunkType.tEXt, ChunkType.zTXt, ChunkType.iTXt }, false);
+final ChunkType[] chunkTypes = { ChunkType.tEXt, ChunkType.zTXt,
ChunkType.iTXt, ChunkType.eXIf };
+final List chunks = readChunks(byteSource, chunkTypes,
false);
if (chunks.isEmpty()) {
return null;
}
-final GenericImageMetadata result = new GenericImageMetadata();
+final GenericImageMetadata textual = new GenericImageMetadata();
+TiffImageMetadata exif = null;
for (final PngChunk chunk : chunks) {
-final PngTextChunk textChunk = (PngTextChunk) chunk;
+if (chunk instanceof PngTextChunk) {
+final PngTextChunk textChunk = (PngTextChunk) chunk;
+textual.add(textChunk.getKeyword(), textChunk.getText());
+} else if (chunk.chunkType == ChunkType.eXIf.value) {
+if (exif != null) {
+throw new ImageReadException("Duplicate eXIf chunk");
+}
+exif = (TiffImageMetadata) new
TiffImageParser().getMetadata(chunk.getBytes());
+}
Review Comment:
I think we should either log and/or raise an error for any other type here.
##
src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java:
##
@@ -187,29 +190,7 @@ private List readChunks(final InputStream is,
final ChunkType[] chunkT
final int crc = read4Bytes("CRC", is, "Not a Valid PNG File",
getByteOrder());
if (keep) {
-if (chunkType == ChunkType.iCCP.value) {
-result.add(new PngChunkIccp(length, chunkType, crc,
bytes));
-} else if (chunkType == ChunkType.tEXt.value) {
-result.add(new PngChunkText(length, chunkType, crc,
bytes));
-} else if (chunkType == ChunkType.zTXt.value) {
-result.add(new PngChunkZtxt(length, chunkType, crc,
bytes));
-} else if (chunkType == ChunkType.IHDR.value) {
-result.add(new PngChunkIhdr(length, chunkType, crc,
bytes));
-} else if (chunkType == ChunkType.PLTE.value) {
-result.add(new PngChunkPlte(length, chunkType, crc,
bytes));
-} else if (chunkType == ChunkType.pHYs.value) {
-result.add(new PngChunkPhys(length, chunkType, crc,
bytes));
-} else if (chunkType == ChunkType.sCAL.value) {
-result.add(new PngChunkScal(length, chunkType, crc,
bytes));
-} else if (chunkType == ChunkType.IDAT.value) {
-result.add(new PngChunkIdat(length, chunkType, crc,
bytes));
-} else if (chunkType == ChunkType.gAMA.value) {
-result.add(new PngChunkGama(length, chunkType, crc,
bytes));
-} else if (chunkType == ChunkType.iTXt.value) {
-result.add(new PngChunkItxt(length, chunkType, crc,
bytes));
-} else {
-result.add(new PngChunk(length, chunkType, crc, bytes));
-}
+result.add(ChunkType.makeChunk(length, chunkType, crc, bytes));
Review Comment:
:ok_man: :clap: bravo, @Glavo
##
src/main/java/org/apache/commons/imaging/formats/png/PngImageMetadata.java:
##
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *