kinow commented on a change in pull request #38: Cleaned up PNG component.
URL: https://github.com/apache/commons-imaging/pull/38#discussion_r284486669
 
 

 ##########
 File path: src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java
 ##########
 @@ -74,46 +207,47 @@ private void writeChunk(final OutputStream os, final 
ChunkType chunkType,
                 crc1, data, data.length);
         final int crc = (int) png_crc.finish_partial_crc(crc2);
 
-        writeInt(os, crc);
+        writeInt(outputStream, crc);
     }
 
-    private static class ImageHeader {
-        public final int width;
-        public final int height;
-        public final byte bitDepth;
-        public final PngColorType pngColorType;
-        public final byte compressionMethod;
-        public final byte filterMethod;
-        public final InterlaceMethod interlaceMethod;
-
-        ImageHeader(final int width, final int height, final byte bitDepth,
-                final PngColorType pngColorType, final byte compressionMethod, 
final byte filterMethod,
-                final InterlaceMethod interlaceMethod) {
-            this.width = width;
-            this.height = height;
-            this.bitDepth = bitDepth;
-            this.pngColorType = pngColorType;
-            this.compressionMethod = compressionMethod;
-            this.filterMethod = filterMethod;
-            this.interlaceMethod = interlaceMethod;
+    /**
+     * Puts the chunk contents (including length, type and CRC) into
+     * the output stream provided.
+     *
+     * Also calculates the CRC if required. (used by writeHeader)
+     *
+     * @param outputStream stream into which chunk is to be written
+     * @param chunk chunk to write
+     * @throws IOException
+     */
+    private void writeChunk(final DataOutputStream outputStream,
+            final PngChunk chunk) throws IOException {
+        outputStream.writeInt(chunk.contentSize());
+        outputStream.writeInt(chunk.chunkType.toCode());
+
+        if (chunk.getBytes() != null) {
+            outputStream.write(chunk.getBytes());
         }
 
-    }
+        int chunkCRC;
 
-    private void writeChunkIHDR(final OutputStream os, final ImageHeader 
value) throws IOException {
-        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        writeInt(baos, value.width);
-        writeInt(baos, value.height);
-        baos.write(0xff & value.bitDepth);
-        baos.write(0xff & value.pngColorType.getValue());
-        baos.write(0xff & value.compressionMethod);
-        baos.write(0xff & value.filterMethod);
-        baos.write(0xff & value.interlaceMethod.ordinal());
-
-        writeChunk(os, ChunkType.IHDR, baos.toByteArray());
+        if (chunk.wasChanged(true)) {
 
 Review comment:
   This looks weird. I think either `if (chunk.changed)`, or `if 
(chunk.hasChanged())` would be expected instead?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to