You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/05/14 16:24:11 UTC

[commons-imaging] branch master updated (c35d6509 -> cd2adad9)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-imaging.git


    from c35d6509 Javadoc: Fix unsupported tag on Java 11
     new e5172028 Remove truly useless parenthesis
     new daf01a7d Remove unused methods
     new bfbed174 Use generics
     new d3f4abb7 Use try-with-resources
     new c81758aa Use generics
     new 5ef4b33c Refactor for immutability
     new 3785f0f9 Use try-with-resources
     new 8e605e2e Use try-with-resources
     new f94107ca Inline comment
     new 4dc2fc5d Use try-with-resources
     new b5e24b79 Use generics
     new 363de3c7 Use try-with-resources
     new bf80eda7 Possible NPE
     new cd2adad9 Use try-with-resources

The 14 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/commons/imaging/Imaging.java   |  2 +-
 .../commons/imaging/common/BasicCParser.java       |  2 +-
 .../commons/imaging/common/BinaryConstant.java     | 16 -----
 .../imaging/common/mylzw/MyBitInputStream.java     |  9 +--
 .../imaging/common/mylzw/MyLzwCompressor.java      | 56 ++++++++---------
 .../imaging/common/mylzw/MyLzwDecompressor.java    | 63 +++++++++----------
 .../commons/imaging/formats/icns/IcnsDecoder.java  |  4 +-
 .../imaging/formats/jpeg/decoder/JpegDecoder.java  |  5 +-
 .../imaging/formats/jpeg/iptc/IptcParser.java      | 71 +++++++++++-----------
 .../formats/jpeg/segments/App13Segment.java        |  3 +-
 .../psd/datareaders/CompressedDataReader.java      | 28 ++++-----
 .../psd/datareaders/UncompressedDataReader.java    |  2 +-
 .../tiff/write/TiffImageWriterLossless.java        | 11 ++--
 .../commons/imaging/palette/QuantizedPalette.java  |  2 +-
 14 files changed, 126 insertions(+), 148 deletions(-)


[commons-imaging] 10/14: Use try-with-resources

Posted by gg...@apache.org.
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 4dc2fc5dcc1b554d649b7d642e164243362db0c8
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun May 14 11:34:18 2023 -0400

    Use try-with-resources
    
    Format tweak
---
 .../org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java b/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java
index d91f3f0a..4152b2c3 100644
--- a/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java
+++ b/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java
@@ -414,8 +414,7 @@ public class JpegDecoder extends BinaryFileParser implements JpegUtils.Visitor {
 
     @Override
     public void visitSOS(final int marker, final byte[] markerBytes, final byte[] imageData) {
-        final ByteArrayInputStream is = new ByteArrayInputStream(imageData);
-        try {
+        try (ByteArrayInputStream is = new ByteArrayInputStream(imageData)) {
             // read the scan header
             final int segmentLength = read2Bytes("segmentLength", is,"Not a Valid JPEG File", getByteOrder());
             final byte[] sosSegmentBytes = readBytes("SosSegment", is, segmentLength - 2, "Not a Valid JPEG File");
@@ -547,7 +546,7 @@ public class JpegDecoder extends BinaryFileParser implements JpegUtils.Visitor {
             ioException = ioEx;
         } catch (final RuntimeException ex) {
             // Corrupt images can throw NPE and IOOBE
-            imageReadException = new ImageReadException("Error parsing JPEG",ex);
+            imageReadException = new ImageReadException("Error parsing JPEG", ex);
         }
     }
 }


[commons-imaging] 13/14: Possible NPE

Posted by gg...@apache.org.
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 bf80eda7b18524a41db57a265cff9c3d5ea7ac34
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun May 14 12:23:45 2023 -0400

    Possible NPE
---
 src/main/java/org/apache/commons/imaging/palette/QuantizedPalette.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/imaging/palette/QuantizedPalette.java b/src/main/java/org/apache/commons/imaging/palette/QuantizedPalette.java
index 80fe80db..9c355b48 100644
--- a/src/main/java/org/apache/commons/imaging/palette/QuantizedPalette.java
+++ b/src/main/java/org/apache/commons/imaging/palette/QuantizedPalette.java
@@ -35,7 +35,7 @@ public class QuantizedPalette implements Palette {
         straight = Allocator.array(1 << (precision * 3), ColorSpaceSubset[]::new, ColorSpaceSubset.SHALLOW_SIZE);
 
         for (int i = 0; i < this.subsets.size(); i++) {
-            final ColorSpaceSubset subset = subsets.get(i);
+            final ColorSpaceSubset subset = this.subsets.get(i);
             subset.setIndex(i);
 
             for (int u = subset.mins[0]; u <= subset.maxs[0]; u++) {


[commons-imaging] 08/14: Use try-with-resources

Posted by gg...@apache.org.
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 8e605e2e62edc7063952c0453815eb0bbdb68cbe
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun May 14 11:32:17 2023 -0400

    Use try-with-resources
---
 .../imaging/common/mylzw/MyLzwDecompressor.java    | 60 +++++++++++-----------
 1 file changed, 29 insertions(+), 31 deletions(-)

diff --git a/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwDecompressor.java b/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwDecompressor.java
index a6abfb87..d4da85ec 100644
--- a/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwDecompressor.java
+++ b/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwDecompressor.java
@@ -107,44 +107,42 @@ public final class MyLzwDecompressor {
     public byte[] decompress(final InputStream is, final int expectedLength) throws IOException {
         int code;
         int oldCode = -1;
-        final MyBitInputStream mbis = new MyBitInputStream(is, byteOrder, tiffLZWMode);
-
-        final ByteArrayOutputStream baos = new ByteArrayOutputStream(Allocator.checkByteArray(expectedLength));
-
-        clearTable();
-
-        while ((code = getNextCode(mbis)) != eoiCode) {
-            if (code == clearCode) {
-                clearTable();
-
-                if (written >= expectedLength) {
-                    break;
+        try (MyBitInputStream mbis = new MyBitInputStream(is, byteOrder, tiffLZWMode);
+                ByteArrayOutputStream baos = new ByteArrayOutputStream(Allocator.checkByteArray(expectedLength))) {
+
+            clearTable();
+
+            while ((code = getNextCode(mbis)) != eoiCode) {
+                if (code == clearCode) {
+                    clearTable();
+
+                    if (written >= expectedLength) {
+                        break;
+                    }
+                    code = getNextCode(mbis);
+
+                    if (code == eoiCode) {
+                        break;
+                    }
+                    writeToResult(baos, stringFromCode(code));
+                } else if (isInTable(code)) {
+                    writeToResult(baos, stringFromCode(code));
+
+                    addStringToTable(appendBytes(stringFromCode(oldCode), firstChar(stringFromCode(code))));
+                } else {
+                    final byte[] outString = appendBytes(stringFromCode(oldCode), firstChar(stringFromCode(oldCode)));
+                    writeToResult(baos, outString);
+                    addStringToTable(outString);
                 }
-                code = getNextCode(mbis);
+                oldCode = code;
 
-                if (code == eoiCode) {
+                if (written >= expectedLength) {
                     break;
                 }
-                writeToResult(baos, stringFromCode(code));
-            } else if (isInTable(code)) {
-                writeToResult(baos, stringFromCode(code));
-
-                addStringToTable(appendBytes(stringFromCode(oldCode),
-                        firstChar(stringFromCode(code))));
-            } else {
-                final byte[] outString = appendBytes(stringFromCode(oldCode),
-                        firstChar(stringFromCode(oldCode)));
-                writeToResult(baos, outString);
-                addStringToTable(outString);
             }
-            oldCode = code;
 
-            if (written >= expectedLength) {
-                break;
-            }
+            return baos.toByteArray();
         }
-
-        return baos.toByteArray();
     }
 
     private byte firstChar(final byte[] bytes) {


[commons-imaging] 07/14: Use try-with-resources

Posted by gg...@apache.org.
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 3785f0f9097b81227d1d62f667df952011c42dfa
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun May 14 11:30:24 2023 -0400

    Use try-with-resources
---
 .../imaging/common/mylzw/MyLzwCompressor.java      | 56 +++++++++++-----------
 1 file changed, 27 insertions(+), 29 deletions(-)

diff --git a/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwCompressor.java b/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwCompressor.java
index 30bb6baa..5e00ea27 100644
--- a/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwCompressor.java
+++ b/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwCompressor.java
@@ -175,37 +175,35 @@ public class MyLzwCompressor {
     }
 
     public byte[] compress(final byte[] bytes) throws IOException {
-        final ByteArrayOutputStream baos = new ByteArrayOutputStream(Allocator.checkByteArray(bytes.length));
-        final MyBitOutputStream bos = new MyBitOutputStream(baos, byteOrder);
-
-        initializeStringTable();
-        clearTable();
-        writeClearCode(bos);
-
-        int wStart = 0;
-        int wLength = 0;
-
-        for (int i = 0; i < bytes.length; i++) {
-            if (isInTable(bytes, wStart, wLength + 1)) {
-                wLength++;
-            } else {
-                final int code = codeFromString(bytes, wStart, wLength);
-                writeDataCode(bos, code);
-                addTableEntry(bos, bytes, wStart, wLength + 1);
-
-                wStart = i;
-                wLength = 1;
+        try (ByteArrayOutputStream baos = new ByteArrayOutputStream(Allocator.checkByteArray(bytes.length));
+                MyBitOutputStream bos = new MyBitOutputStream(baos, byteOrder)) {
+
+            initializeStringTable();
+            clearTable();
+            writeClearCode(bos);
+
+            int wStart = 0;
+            int wLength = 0;
+
+            for (int i = 0; i < bytes.length; i++) {
+                if (isInTable(bytes, wStart, wLength + 1)) {
+                    wLength++;
+                } else {
+                    final int code = codeFromString(bytes, wStart, wLength);
+                    writeDataCode(bos, code);
+                    addTableEntry(bos, bytes, wStart, wLength + 1);
+
+                    wStart = i;
+                    wLength = 1;
+                }
             }
-        }
-
-        final int code = codeFromString(bytes, wStart, wLength);
-        writeDataCode(bos, code);
 
-        writeEoiCode(bos);
-
-        bos.flushCache();
-
-        return baos.toByteArray();
+            final int code = codeFromString(bytes, wStart, wLength);
+            writeDataCode(bos, code);
+            writeEoiCode(bos);
+            bos.flushCache();
+            return baos.toByteArray();
+        }
     }
 
     private void incrementCodeSize() {


[commons-imaging] 11/14: Use generics

Posted by gg...@apache.org.
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 b5e24b796904251fcfb74d0eee6150d7b17c7286
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun May 14 11:36:23 2023 -0400

    Use generics
---
 .../org/apache/commons/imaging/formats/jpeg/segments/App13Segment.java | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App13Segment.java b/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App13Segment.java
index dffd880c..22de875f 100644
--- a/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App13Segment.java
+++ b/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App13Segment.java
@@ -22,6 +22,7 @@ import java.io.InputStream;
 
 import org.apache.commons.imaging.ImageReadException;
 import org.apache.commons.imaging.ImagingParameters;
+import org.apache.commons.imaging.formats.jpeg.JpegImagingParameters;
 import org.apache.commons.imaging.formats.jpeg.iptc.IptcParser;
 import org.apache.commons.imaging.formats.jpeg.iptc.PhotoshopApp13Data;
 
@@ -55,7 +56,7 @@ public class App13Segment extends AppnSegment {
         return new IptcParser().isPhotoshopJpegSegment(getSegmentData());
     }
 
-    public PhotoshopApp13Data parsePhotoshopSegment(final ImagingParameters params)
+    public PhotoshopApp13Data parsePhotoshopSegment(final ImagingParameters<JpegImagingParameters> params)
             throws ImageReadException, IOException {
         /*
          * In practice, App13 segments are only used for Photoshop/IPTC


[commons-imaging] 05/14: Use generics

Posted by gg...@apache.org.
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 c81758aa73b28e3e02347c30cf68f3953c528310
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun May 14 11:26:03 2023 -0400

    Use generics
---
 src/main/java/org/apache/commons/imaging/Imaging.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/imaging/Imaging.java b/src/main/java/org/apache/commons/imaging/Imaging.java
index fd86e310..ae506f4f 100644
--- a/src/main/java/org/apache/commons/imaging/Imaging.java
+++ b/src/main/java/org/apache/commons/imaging/Imaging.java
@@ -613,7 +613,7 @@ public final class Imaging {
     public static String getXmpXml(final ByteSource byteSource) throws ImageReadException, IOException {
         final ImageParser<?> imageParser = ImageParserFactory.getImageParser(byteSource);
         if (imageParser instanceof XmpEmbeddable) {
-            return ((XmpEmbeddable) imageParser).getXmpXml(byteSource, null);
+            return ((XmpEmbeddable<?>) imageParser).getXmpXml(byteSource, null);
         }
         return null;
     }


[commons-imaging] 06/14: Refactor for immutability

Posted by gg...@apache.org.
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 5ef4b33c3293d57ef829f5dc000b9e988879b390
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun May 14 11:28:16 2023 -0400

    Refactor for immutability
---
 .../apache/commons/imaging/common/mylzw/MyBitInputStream.java    | 9 +++------
 .../apache/commons/imaging/common/mylzw/MyLzwDecompressor.java   | 5 +----
 .../imaging/formats/psd/datareaders/CompressedDataReader.java    | 2 +-
 .../imaging/formats/psd/datareaders/UncompressedDataReader.java  | 2 +-
 4 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/apache/commons/imaging/common/mylzw/MyBitInputStream.java b/src/main/java/org/apache/commons/imaging/common/mylzw/MyBitInputStream.java
index 443b0fc6..3e73c9fe 100644
--- a/src/main/java/org/apache/commons/imaging/common/mylzw/MyBitInputStream.java
+++ b/src/main/java/org/apache/commons/imaging/common/mylzw/MyBitInputStream.java
@@ -23,14 +23,15 @@ import java.nio.ByteOrder;
 public class MyBitInputStream extends InputStream {
     private final InputStream is;
     private final ByteOrder byteOrder;
-    private boolean tiffLZWMode;
+    private final boolean tiffLZWMode;
     private long bytesRead;
     private int bitsInCache;
     private int bitCache;
 
-    public MyBitInputStream(final InputStream is, final ByteOrder byteOrder) {
+    public MyBitInputStream(final InputStream is, final ByteOrder byteOrder, final boolean tiffLZWMode) {
         this.byteOrder = byteOrder;
         this.is = is;
+        this.tiffLZWMode = tiffLZWMode;
     }
 
     public void flushCache() {
@@ -90,8 +91,4 @@ public class MyBitInputStream extends InputStream {
         return result;
     }
 
-    public void setTiffLZWMode() {
-        tiffLZWMode = true;
-    }
-
 }
diff --git a/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwDecompressor.java b/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwDecompressor.java
index 47048f55..a6abfb87 100644
--- a/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwDecompressor.java
+++ b/src/main/java/org/apache/commons/imaging/common/mylzw/MyLzwDecompressor.java
@@ -107,10 +107,7 @@ public final class MyLzwDecompressor {
     public byte[] decompress(final InputStream is, final int expectedLength) throws IOException {
         int code;
         int oldCode = -1;
-        final MyBitInputStream mbis = new MyBitInputStream(is, byteOrder);
-        if (tiffLZWMode) {
-            mbis.setTiffLZWMode();
-        }
+        final MyBitInputStream mbis = new MyBitInputStream(is, byteOrder, tiffLZWMode);
 
         final ByteArrayOutputStream baos = new ByteArrayOutputStream(Allocator.checkByteArray(expectedLength));
 
diff --git a/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/CompressedDataReader.java b/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/CompressedDataReader.java
index 584397b1..33c0462d 100644
--- a/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/CompressedDataReader.java
+++ b/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/CompressedDataReader.java
@@ -73,7 +73,7 @@ public class CompressedDataReader implements DataReader {
 
                 final byte[] unpacked = new PackBits().decompress(packed, width);
                 final InputStream bais = new ByteArrayInputStream(unpacked);
-                final MyBitInputStream mbis = new MyBitInputStream(bais, ByteOrder.BIG_ENDIAN);
+                final MyBitInputStream mbis = new MyBitInputStream(bais, ByteOrder.BIG_ENDIAN, false);
                 // we want all samples to be bytes
                 try (BitsToByteInputStream bbis = new BitsToByteInputStream(mbis, 8)) {
                     final int[] scanline = bbis.readBitsArray(depth, width);
diff --git a/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/UncompressedDataReader.java b/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/UncompressedDataReader.java
index 6e7a7f24..19b0ee46 100644
--- a/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/UncompressedDataReader.java
+++ b/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/UncompressedDataReader.java
@@ -48,7 +48,7 @@ public class UncompressedDataReader implements DataReader {
 
         final int channelCount = dataParser.getBasicChannelsCount();
         final int depth = header.depth;
-        final MyBitInputStream mbis = new MyBitInputStream(is, ByteOrder.BIG_ENDIAN);
+        final MyBitInputStream mbis = new MyBitInputStream(is, ByteOrder.BIG_ENDIAN, false);
         // we want all samples to be bytes
         try (BitsToByteInputStream bbis = new BitsToByteInputStream(mbis, 8)) {
             final int[][][] data = new int[Allocator.check(channelCount)][Allocator


[commons-imaging] 12/14: Use try-with-resources

Posted by gg...@apache.org.
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 363de3c7826068c11b2c15c0e08570695cea20eb
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun May 14 11:39:45 2023 -0400

    Use try-with-resources
    
    Format tweaks
---
 .../psd/datareaders/CompressedDataReader.java      | 28 ++++++++++------------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/CompressedDataReader.java b/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/CompressedDataReader.java
index 33c0462d..9b86fe0d 100644
--- a/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/CompressedDataReader.java
+++ b/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/CompressedDataReader.java
@@ -42,9 +42,8 @@ public class CompressedDataReader implements DataReader {
     }
 
     @Override
-    public void readData(final InputStream is, final BufferedImage bi,
-            final PsdImageContents imageContents, final BinaryFileParser bfp)
-            throws ImageReadException, IOException {
+    public void readData(final InputStream is, final BufferedImage bi, final PsdImageContents imageContents,
+            final BinaryFileParser bfp) throws ImageReadException, IOException {
         final PsdHeaderInfo header = imageContents.header;
         final int width = header.columns;
         final int height = header.rows;
@@ -53,8 +52,8 @@ public class CompressedDataReader implements DataReader {
         final int scanlineCount = height * header.channels;
         final int[] scanlineByteCounts = Allocator.intArray(scanlineCount);
         for (int i = 0; i < scanlineCount; i++) {
-            scanlineByteCounts[i] = BinaryFunctions.read2Bytes("scanline_bytecount[" + i
-                    + "]", is, "PSD: bad Image Data", bfp.getByteOrder());
+            scanlineByteCounts[i] = BinaryFunctions.read2Bytes("scanline_bytecount[" + i + "]", is,
+                    "PSD: bad Image Data", bfp.getByteOrder());
         }
         // System.out.println("fImageContents.Compression: "
         // + imageContents.Compression);
@@ -67,22 +66,21 @@ public class CompressedDataReader implements DataReader {
         for (int channel = 0; channel < channelCount; channel++) {
             for (int y = 0; y < height; y++) {
                 final int index = channel * height + y;
-                final byte[] packed = BinaryFunctions.readBytes("scanline",
-                        is, scanlineByteCounts[index],
+                final byte[] packed = BinaryFunctions.readBytes("scanline", is, scanlineByteCounts[index],
                         "PSD: Missing Image Data");
 
                 final byte[] unpacked = new PackBits().decompress(packed, width);
-                final InputStream bais = new ByteArrayInputStream(unpacked);
-                final MyBitInputStream mbis = new MyBitInputStream(bais, ByteOrder.BIG_ENDIAN, false);
-                // we want all samples to be bytes
-                try (BitsToByteInputStream bbis = new BitsToByteInputStream(mbis, 8)) {
-                    final int[] scanline = bbis.readBitsArray(depth, width);
-                    data[channel][y] = scanline;
+                try (InputStream bais = new ByteArrayInputStream(unpacked);
+                        MyBitInputStream mbis = new MyBitInputStream(bais, ByteOrder.BIG_ENDIAN, false)) {
+                    // we want all samples to be bytes
+                    try (BitsToByteInputStream bbis = new BitsToByteInputStream(mbis, 8)) {
+                        final int[] scanline = bbis.readBitsArray(depth, width);
+                        data[channel][y] = scanline;
+                    }
                 }
             }
         }
-
         dataParser.parseData(data, bi, imageContents);
-
     }
+
 }


[commons-imaging] 03/14: Use generics

Posted by gg...@apache.org.
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 bfbed1744fc9a595c10a890769e632606571ba0a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun May 14 11:09:06 2023 -0400

    Use generics
---
 .../java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java  | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java b/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java
index 2ec6355a..47b4291a 100644
--- a/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java
+++ b/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java
@@ -49,6 +49,7 @@ import org.apache.commons.imaging.common.BinaryFunctions;
 import org.apache.commons.imaging.common.BinaryOutputStream;
 import org.apache.commons.imaging.common.ByteConversions;
 import org.apache.commons.imaging.formats.jpeg.JpegConstants;
+import org.apache.commons.imaging.formats.jpeg.JpegImagingParameters;
 import org.apache.commons.imaging.internal.Debug;
 
 public class IptcParser extends BinaryFileParser {
@@ -390,7 +391,7 @@ public class IptcParser extends BinaryFileParser {
      * Some IPTC blocks are missing this first "record version" record, so we
      * don't require it.
      */
-    public PhotoshopApp13Data parsePhotoshopSegment(final byte[] bytes, final ImagingParameters params)
+    public PhotoshopApp13Data parsePhotoshopSegment(final byte[] bytes, final ImagingParameters<JpegImagingParameters> params)
             throws ImageReadException, IOException {
         final boolean strict =  params != null && params.isStrict();
 


[commons-imaging] 04/14: Use try-with-resources

Posted by gg...@apache.org.
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 d3f4abb735de98b4e4f93894c3200fbef1588cd4
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun May 14 11:15:15 2023 -0400

    Use try-with-resources
---
 .../imaging/formats/jpeg/iptc/IptcParser.java      | 68 +++++++++++-----------
 1 file changed, 35 insertions(+), 33 deletions(-)

diff --git a/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java b/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java
index 47b4291a..a1e284d5 100644
--- a/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java
+++ b/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java
@@ -82,7 +82,9 @@ public class IptcParser extends BinaryFileParser {
             if (Charset.isSupported(codedCharsetString)) {
                 return Charset.forName(codedCharsetString);
             }
-        } catch (final IllegalArgumentException e) { }
+        } catch (final IllegalArgumentException ignored) {
+            // ignored
+        }
         // check if encoding is a escape sequence
         // normalize encoding byte sequence
         final byte[] codedCharsetNormalized = Allocator.byteArray(codedCharset.length);
@@ -469,45 +471,45 @@ public class IptcParser extends BinaryFileParser {
         return blockData;
     }
 
-    public byte[] writePhotoshopApp13Segment(final PhotoshopApp13Data data)
-            throws IOException, ImageWriteException {
-        final ByteArrayOutputStream os = new ByteArrayOutputStream();
-        final BinaryOutputStream bos = BinaryOutputStream.bigEndian(os);
+    public byte[] writePhotoshopApp13Segment(final PhotoshopApp13Data data) throws IOException, ImageWriteException {
+        try (ByteArrayOutputStream os = new ByteArrayOutputStream();
+                BinaryOutputStream bos = BinaryOutputStream.bigEndian(os)) {
 
-        JpegConstants.PHOTOSHOP_IDENTIFICATION_STRING.writeTo(bos);
+            JpegConstants.PHOTOSHOP_IDENTIFICATION_STRING.writeTo(bos);
 
-        final List<IptcBlock> blocks = data.getRawBlocks();
-        for (final IptcBlock block : blocks) {
-            bos.write4Bytes(JpegConstants.CONST_8BIM);
+            final List<IptcBlock> blocks = data.getRawBlocks();
+            for (final IptcBlock block : blocks) {
+                bos.write4Bytes(JpegConstants.CONST_8BIM);
 
-            if (block.getBlockType() < 0 || block.getBlockType() > 0xffff) {
-                throw new ImageWriteException("Invalid IPTC block type.");
-            }
-            bos.write2Bytes(block.getBlockType());
+                if (block.getBlockType() < 0 || block.getBlockType() > 0xffff) {
+                    throw new ImageWriteException("Invalid IPTC block type.");
+                }
+                bos.write2Bytes(block.getBlockType());
 
-            final byte[] blockNameBytes = block.getBlockNameBytes();
-            if (blockNameBytes.length > 255) {
-                throw new ImageWriteException("IPTC block name is too long: " + blockNameBytes.length);
-            }
-            bos.write(blockNameBytes.length);
-            bos.write(blockNameBytes);
-            if (blockNameBytes.length % 2 == 0) {
-                bos.write(0); // pad to even size, including length byte.
-            }
+                final byte[] blockNameBytes = block.getBlockNameBytes();
+                if (blockNameBytes.length > 255) {
+                    throw new ImageWriteException("IPTC block name is too long: " + blockNameBytes.length);
+                }
+                bos.write(blockNameBytes.length);
+                bos.write(blockNameBytes);
+                if (blockNameBytes.length % 2 == 0) {
+                    bos.write(0); // pad to even size, including length byte.
+                }
 
-            final byte[] blockData = block.getBlockData();
-            if (blockData.length > IptcConstants.IPTC_NON_EXTENDED_RECORD_MAXIMUM_SIZE) {
-                throw new ImageWriteException("IPTC block data is too long: " + blockData.length);
-            }
-            bos.write4Bytes(blockData.length);
-            bos.write(blockData);
-            if (blockData.length % 2 == 1) {
-                bos.write(0); // pad to even size
+                final byte[] blockData = block.getBlockData();
+                if (blockData.length > IptcConstants.IPTC_NON_EXTENDED_RECORD_MAXIMUM_SIZE) {
+                    throw new ImageWriteException("IPTC block data is too long: " + blockData.length);
+                }
+                bos.write4Bytes(blockData.length);
+                bos.write(blockData);
+                if (blockData.length % 2 == 1) {
+                    bos.write(0); // pad to even size
+                }
             }
-        }
 
-        bos.flush();
-        return os.toByteArray();
+            bos.flush();
+            return os.toByteArray();
+        }
     }
 
 }


[commons-imaging] 14/14: Use try-with-resources

Posted by gg...@apache.org.
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 cd2adad958febd358ee9af8964eee7f9d189825f
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun May 14 12:23:59 2023 -0400

    Use try-with-resources
---
 .../imaging/formats/tiff/write/TiffImageWriterLossless.java   | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java b/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java
index 36951633..4e3e6600 100644
--- a/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java
+++ b/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java
@@ -295,9 +295,10 @@ public class TiffImageWriterLossless extends TiffImageWriterBase {
         // copy old data (including maker notes, etc.)
         System.arraycopy(exifBytes, 0, output, 0, Math.min(exifBytes.length, output.length));
 
-        final BufferOutputStream headerStream = new BufferOutputStream(output, 0);
-        final BinaryOutputStream headerBinaryStream = BinaryOutputStream.create(headerStream, byteOrder);
-        writeImageFileHeader(headerBinaryStream, rootDirectory.getOffset());
+        try (BufferOutputStream headerStream = new BufferOutputStream(output, 0);
+                BinaryOutputStream headerBinaryStream = BinaryOutputStream.create(headerStream, byteOrder)) {
+            writeImageFileHeader(headerBinaryStream, rootDirectory.getOffset());
+        }
 
         // zero out the parsed pieces of old exif segment, in case we don't
         // overwrite them.
@@ -308,8 +309,8 @@ public class TiffImageWriterLossless extends TiffImageWriterBase {
 
         // write in the new items
         for (final TiffOutputItem outputItem : outputItems) {
-            try (BinaryOutputStream bos = BinaryOutputStream.create(
-                    new BufferOutputStream(output, (int) outputItem.getOffset()), byteOrder)) {
+            try (BinaryOutputStream bos = BinaryOutputStream
+                    .create(new BufferOutputStream(output, (int) outputItem.getOffset()), byteOrder)) {
                 outputItem.writeItem(bos);
             }
         }


[commons-imaging] 02/14: Remove unused methods

Posted by gg...@apache.org.
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 daf01a7d44216652b2f5299c5ffbca00e5ea0bdf
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun May 14 11:07:20 2023 -0400

    Remove unused methods
---
 .../apache/commons/imaging/common/BinaryConstant.java    | 16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/src/main/java/org/apache/commons/imaging/common/BinaryConstant.java b/src/main/java/org/apache/commons/imaging/common/BinaryConstant.java
index 2b0e2532..39dda0d3 100644
--- a/src/main/java/org/apache/commons/imaging/common/BinaryConstant.java
+++ b/src/main/java/org/apache/commons/imaging/common/BinaryConstant.java
@@ -31,18 +31,6 @@ public class BinaryConstant {
         return Arrays.equals(value, bytes);
     }
 
-    public boolean equals(final byte[] bytes, final int offset, final int length) {
-        if (value.length != length) {
-            return false;
-        }
-        for (int i = 0; i < length; i++) {
-            if (value[i] != bytes[offset + i]) {
-                return false;
-            }
-        }
-        return true;
-    }
-
     @Override
     public boolean equals(final Object obj) {
         if (obj == null) {
@@ -68,10 +56,6 @@ public class BinaryConstant {
         return value.length;
     }
 
-    public byte[] toByteArray() {
-        return value.clone();
-    }
-
     public void writeTo(final OutputStream os) throws IOException {
         for (final byte element : value) {
             os.write(element);


[commons-imaging] 01/14: Remove truly useless parenthesis

Posted by gg...@apache.org.
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 e5172028dee9b76132308391c5de208c05729b2e
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun May 14 11:05:15 2023 -0400

    Remove truly useless parenthesis
---
 src/main/java/org/apache/commons/imaging/common/BasicCParser.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/imaging/common/BasicCParser.java b/src/main/java/org/apache/commons/imaging/common/BasicCParser.java
index 3fbd432c..5513cf5b 100644
--- a/src/main/java/org/apache/commons/imaging/common/BasicCParser.java
+++ b/src/main/java/org/apache/commons/imaging/common/BasicCParser.java
@@ -173,7 +173,7 @@ public class BasicCParser {
         boolean hadStar = false;
         boolean hadBackSlash = false;
         final ByteArrayOutputStream out = new ByteArrayOutputStream();
-        boolean seenFirstComment = (firstComment == null);
+        boolean seenFirstComment = firstComment == null;
         final StringBuilder directiveBuffer = new StringBuilder();
         for (int c = is.read(); c != -1; c = is.read()) {
             if (inComment) {


[commons-imaging] 09/14: Inline comment

Posted by gg...@apache.org.
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 f94107caefc89425f1bec2012779b86d5557c0f9
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun May 14 11:34:00 2023 -0400

    Inline comment
---
 .../java/org/apache/commons/imaging/formats/icns/IcnsDecoder.java     | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/imaging/formats/icns/IcnsDecoder.java b/src/main/java/org/apache/commons/imaging/formats/icns/IcnsDecoder.java
index 55556ded..90a7128f 100644
--- a/src/main/java/org/apache/commons/imaging/formats/icns/IcnsDecoder.java
+++ b/src/main/java/org/apache/commons/imaging/formats/icns/IcnsDecoder.java
@@ -226,7 +226,9 @@ final class IcnsDecoder {
                 if (imageType.getWidth() <= 32) {
                     try {
                         image = decodeImageImpl(imageType, imageElement, icnsElements);
-                    } catch (final Exception ignored) { }
+                    } catch (final Exception ignored) {
+                        // ignored
+                    }
                 }
                 if (image == null) {
                     image = new BufferedImage(imageType.getWidth(), imageType.getHeight(), BufferedImage.TYPE_INT_ARGB);