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/03/21 18:03:23 UTC

[commons-imaging] branch master updated (8d7622b0 -> b72e9853)

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 8d7622b0 Remove dead comments
     new caf06cf6 Javadoc
     new bc9a3f58 Use try-with-resources
     new 5b2f5c72 Fix null check
     new b72e9853 Normalize NPE messages

The 4 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:
 .../org/apache/commons/imaging/ImageFormat.java    |   4 +-
 .../java/org/apache/commons/imaging/Imaging.java   |  12 +-
 .../imaging/formats/jpeg/iptc/IptcBlock.java       |   5 +-
 .../imaging/formats/ico/IcoRoundtripTest.java      | 184 ++++++++++-----------
 4 files changed, 96 insertions(+), 109 deletions(-)


[commons-imaging] 03/04: Fix null check

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 5b2f5c7241ab8bae2470619a6b971359d3ea5920
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Mar 21 14:02:44 2023 -0400

    Fix null check
    
    Normalize NPE message
---
 .../java/org/apache/commons/imaging/formats/jpeg/iptc/IptcBlock.java | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcBlock.java b/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcBlock.java
index 016ed3d2..b83043e9 100644
--- a/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcBlock.java
+++ b/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcBlock.java
@@ -29,8 +29,8 @@ public class IptcBlock {
     private final byte[] blockData;
 
     public IptcBlock(final int blockType, final byte[] blockNameBytes, final byte[] blockData) {
-        Objects.requireNonNull(blockNameBytes, "Block name bytes must not be null.");
-        Objects.requireNonNull(blockNameBytes, "Block data bytes must not be null.");
+        Objects.requireNonNull(blockNameBytes, "blockNameBytes");
+        Objects.requireNonNull(blockData, "blockData");
         this.blockData = blockData;
         this.blockNameBytes = blockNameBytes;
         this.blockType = blockType;
@@ -48,7 +48,6 @@ public class IptcBlock {
         return blockData.clone();
     }
 
-
     public boolean isIPTCBlock() {
         return blockType == IptcConstants.IMAGE_RESOURCE_BLOCK_IPTC_DATA;
     }


[commons-imaging] 01/04: Javadoc

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 caf06cf63f81bb824d35626e9e81a8567f935392
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Mar 21 13:52:06 2023 -0400

    Javadoc
---
 src/main/java/org/apache/commons/imaging/ImageFormat.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/commons/imaging/ImageFormat.java b/src/main/java/org/apache/commons/imaging/ImageFormat.java
index ff1b1a44..bc97071c 100644
--- a/src/main/java/org/apache/commons/imaging/ImageFormat.java
+++ b/src/main/java/org/apache/commons/imaging/ImageFormat.java
@@ -23,14 +23,14 @@ package org.apache.commons.imaging;
 public interface ImageFormat {
 
     /**
-     * Get the name of this {@link ImageFormat}.
+     * Gets the name of this {@link ImageFormat}.
      *
      * @return String name
      */
     String getName();
 
     /**
-     * Get the file extension associated with this {@link ImageFormat}.
+     * Gets the file extension associated with this {@link ImageFormat}.
      *
      * @return String extension
      */


[commons-imaging] 02/04: 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 bc9a3f588b196855b189c1d17c1cc54d0ebc1c3a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Mar 21 13:59:37 2023 -0400

    Use try-with-resources
---
 .../imaging/formats/ico/IcoRoundtripTest.java      | 184 ++++++++++-----------
 1 file changed, 86 insertions(+), 98 deletions(-)

diff --git a/src/test/java/org/apache/commons/imaging/formats/ico/IcoRoundtripTest.java b/src/test/java/org/apache/commons/imaging/formats/ico/IcoRoundtripTest.java
index 788ff255..2ad3e4dd 100644
--- a/src/test/java/org/apache/commons/imaging/formats/ico/IcoRoundtripTest.java
+++ b/src/test/java/org/apache/commons/imaging/formats/ico/IcoRoundtripTest.java
@@ -337,22 +337,20 @@ public class IcoRoundtripTest extends IcoBaseTest {
     public void testNormalIcons() throws Exception {
         final int foreground = 0xFFF000E0;
         final int background = 0xFF102030;
-        for (final Map.Entry<Integer,BitmapGenerator> entry : generatorMap.entrySet()) {
+        for (final Map.Entry<Integer, BitmapGenerator> entry : generatorMap.entrySet()) {
             final int bitDepth = entry.getKey();
             final BitmapGenerator bitmapGenerator = entry.getValue();
 
             final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            final BinaryOutputStream bos = BinaryOutputStream.littleEndian(baos);
-            final byte[] bitmap = bitmapGenerator.generateBitmap(foreground,
-                    background, (bitDepth <= 8) ? (1 << bitDepth) : 0);
-            writeICONDIR(bos, 0, 1, 1);
-            writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, bitDepth,
-                    40 + bitmap.length);
-            writeBITMAPINFOHEADER(bos, 16, 2 * 16, 1, bitDepth, 0, 0, 0);
-            bos.write(bitmap);
-            bos.flush();
-            writeAndReadImageData("16x16x" + bitDepth, baos.toByteArray(),
-                    foreground, background);
+            try (final BinaryOutputStream bos = BinaryOutputStream.littleEndian(baos)) {
+                final byte[] bitmap = bitmapGenerator.generateBitmap(foreground, background, (bitDepth <= 8) ? (1 << bitDepth) : 0);
+                writeICONDIR(bos, 0, 1, 1);
+                writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, bitDepth, 40 + bitmap.length);
+                writeBITMAPINFOHEADER(bos, 16, 2 * 16, 1, bitDepth, 0, 0, 0);
+                bos.write(bitmap);
+                bos.flush();
+                writeAndReadImageData("16x16x" + bitDepth, baos.toByteArray(), foreground, background);
+            }
         }
     }
 
@@ -366,21 +364,20 @@ public class IcoRoundtripTest extends IcoBaseTest {
             final BitmapGenerator bitmapGenerator = entry.getValue();
 
             final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            final BinaryOutputStream bos = BinaryOutputStream.littleEndian(baos);
-            final byte[] bitmap = bitmapGenerator.generateBitmap(foreground,
-                    background, (bitDepth <= 8) ? (1 << bitDepth) : 0);
-            writeICONDIR(bos, 0, 1, 1);
-            writeICONDIRENTRY(bos, 3 /* width, should be 16 */, 4 /*
-                                                                   * height,
-                                                                   * should be
-                                                                   * 16
-                                                                   */, 7 /*
-                                                                          * colorCount
-                                                                          * ,
-                                                                          * should
-                                                                          * be 2
-                                                                          * or 0
-                                                                          */,
+            try (final BinaryOutputStream bos = BinaryOutputStream.littleEndian(baos)) {
+                final byte[] bitmap = bitmapGenerator.generateBitmap(foreground, background, (bitDepth <= 8) ? (1 << bitDepth) : 0);
+                writeICONDIR(bos, 0, 1, 1);
+                writeICONDIRENTRY(bos, 3 /* width, should be 16 */, 4 /*
+                                                                       * height,
+                                                                       * should be
+                                                                       * 16
+                                                                       */, 7 /*
+                                                                              * colorCount
+                                                                              * ,
+                                                                              * should
+                                                                              * be 2
+                                                                              * or 0
+                                                                              */,
                     20 /* reserved, should be 0 */, 11 /*
                                                         * planes, should be 1 or
                                                         * 0
@@ -390,9 +387,10 @@ public class IcoRoundtripTest extends IcoBaseTest {
                                                                 * bitDepth
                                                                 */,
                     40 + bitmap.length);
-            writeBITMAPINFOHEADER(bos, 16, 2 * 16, 1, bitDepth, 0, 0, 0);
-            bos.write(bitmap);
-            bos.flush();
+                writeBITMAPINFOHEADER(bos, 16, 2 * 16, 1, bitDepth, 0, 0, 0);
+                bos.write(bitmap);
+                bos.flush();
+            }
             writeAndReadImageData(
                     "16x16x" + bitDepth + "-corrupt-icondirentry",
                     baos.toByteArray(), foreground, background);
@@ -408,44 +406,38 @@ public class IcoRoundtripTest extends IcoBaseTest {
             final BitmapGenerator bitmapGenerator = entry.getValue();
 
             final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            final BinaryOutputStream bos = BinaryOutputStream.littleEndian(baos);
-            final byte[] bitmap = bitmapGenerator.generateBitmap(foreground,
-                    background, 2);
-            writeICONDIR(bos, 0, 1, 1);
-            writeICONDIRENTRY(bos, 3, 4, 7, 20, 11, 19, 40 + bitmap.length);
-            writeBITMAPINFOHEADER(bos, 16, 2 * 16, 1, bitDepth, 0, 2, 0);
-            bos.write(bitmap);
-            bos.flush();
-            writeAndReadImageData("16x16x" + bitDepth + "-custom-palette",
-                    baos.toByteArray(), foreground, background);
-        }
+            try (final BinaryOutputStream bos = BinaryOutputStream.littleEndian(baos)) {
+                final byte[] bitmap = bitmapGenerator.generateBitmap(foreground, background, 2);
+                writeICONDIR(bos, 0, 1, 1);
+                writeICONDIRENTRY(bos, 3, 4, 7, 20, 11, 19, 40 + bitmap.length);
+                writeBITMAPINFOHEADER(bos, 16, 2 * 16, 1, bitDepth, 0, 2, 0);
+                bos.write(bitmap);
+                bos.flush();
+                writeAndReadImageData("16x16x" + bitDepth + "-custom-palette", baos.toByteArray(), foreground, background);
+            }}
     }
 
     @Test
     public void testZeroColorPlanes() throws Exception {
         final int foreground = 0xFFF000E0;
         final int background = 0xFF102030;
-        for (final Map.Entry<Integer,BitmapGenerator> entry : generatorMap.entrySet()) {
+        for (final Map.Entry<Integer, BitmapGenerator> entry : generatorMap.entrySet()) {
             final int bitDepth = entry.getKey();
             final BitmapGenerator bitmapGenerator = entry.getValue();
 
             final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            final BinaryOutputStream bos = BinaryOutputStream.littleEndian(baos);
-            final byte[] bitmap = bitmapGenerator.generateBitmap(foreground,
-                    background, (bitDepth <= 8) ? (1 << bitDepth) : 0);
-            writeICONDIR(bos, 0, 1, 1);
-            writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, bitDepth,
-                    40 + bitmap.length);
-            writeBITMAPINFOHEADER(bos, 16, 2 * 16, 0 /* should be 1 */,
-                    bitDepth, 0, 0, 0);
-            bos.write(bitmap);
-            bos.flush();
+            try (final BinaryOutputStream bos = BinaryOutputStream.littleEndian(baos)) {
+                final byte[] bitmap = bitmapGenerator.generateBitmap(foreground, background, (bitDepth <= 8) ? (1 << bitDepth) : 0);
+                writeICONDIR(bos, 0, 1, 1);
+                writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, bitDepth, 40 + bitmap.length);
+                writeBITMAPINFOHEADER(bos, 16, 2 * 16, 0 /* should be 1 */, bitDepth, 0, 0, 0);
+                bos.write(bitmap);
+                bos.flush();
+            }
 
             boolean threw = false;
             try {
-                writeAndReadImageData(
-                        "16x16x" + bitDepth + "-zero-colorPlanes",
-                        baos.toByteArray(), foreground, background);
+                writeAndReadImageData("16x16x" + bitDepth + "-zero-colorPlanes", baos.toByteArray(), foreground, background);
             } catch (final ImageReadException imageReadException) {
                 threw = true;
             }
@@ -456,18 +448,17 @@ public class IcoRoundtripTest extends IcoBaseTest {
     @Test
     public void testBitfieldCompression() throws Exception {
         final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        final BinaryOutputStream bos = BinaryOutputStream.littleEndian(baos);
-        final byte[] bitmap = new GeneratorFor32BitBitmaps().generate32bitRGBABitmap(
-                0xFFFF0000, 0xFFFFFFFF, 0, true);
-        writeICONDIR(bos, 0, 1, 1);
-        writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, 32, 40 + bitmap.length);
-        writeBITMAPINFOHEADER(bos, 16, 2 * 16, 1, 32, 3 /* BI_BITFIELDS */, 0,
-                0);
-        bos.write4Bytes(0x000000FF); // red mask
-        bos.write4Bytes(0x0000FF00); // green mask
-        bos.write4Bytes(0x00FF0000); // blue mask
-        bos.write(bitmap);
-        bos.flush();
+        try (final BinaryOutputStream bos = BinaryOutputStream.littleEndian(baos)) {
+            final byte[] bitmap = new GeneratorFor32BitBitmaps().generate32bitRGBABitmap(0xFFFF0000, 0xFFFFFFFF, 0, true);
+            writeICONDIR(bos, 0, 1, 1);
+            writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, 32, 40 + bitmap.length);
+            writeBITMAPINFOHEADER(bos, 16, 2 * 16, 1, 32, 3 /* BI_BITFIELDS */, 0, 0);
+            bos.write4Bytes(0x000000FF); // red mask
+            bos.write4Bytes(0x0000FF00); // green mask
+            bos.write4Bytes(0x00FF0000); // blue mask
+            bos.write(bitmap);
+            bos.flush();
+        }
         writeAndReadImageData("16x16x32-bitfield-compressed",
                 baos.toByteArray(), 0xFF0000FF, 0xFFFFFFFF);
     }
@@ -477,50 +468,47 @@ public class IcoRoundtripTest extends IcoBaseTest {
         final int foreground = 0xFFF000E0;
         final int background = 0xFF102030;
         final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        final BinaryOutputStream bos = BinaryOutputStream.littleEndian(baos);
-        // For 32 bit RGBA, the AND mask can be missing:
-        final byte[] bitmap = new GeneratorFor32BitBitmaps().generate32bitRGBABitmap(
-                foreground, background, 0, false);
-        writeICONDIR(bos, 0, 1, 1);
-        writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, 32, 40 + bitmap.length);
-        writeBITMAPINFOHEADER(bos, 16, 2 * 16, 1, 32, 0, 0, 0);
-        bos.write(bitmap);
-        bos.flush();
-        writeAndReadImageData("16x16x32-no-mask", baos.toByteArray(),
-                foreground, background);
+        try (final BinaryOutputStream bos = BinaryOutputStream.littleEndian(baos)) {
+            // For 32 bit RGBA, the AND mask can be missing:
+            final byte[] bitmap = new GeneratorFor32BitBitmaps().generate32bitRGBABitmap(foreground, background, 0, false);
+            writeICONDIR(bos, 0, 1, 1);
+            writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, 32, 40 + bitmap.length);
+            writeBITMAPINFOHEADER(bos, 16, 2 * 16, 1, 32, 0, 0, 0);
+            bos.write(bitmap);
+            bos.flush();
+        }
+        writeAndReadImageData("16x16x32-no-mask", baos.toByteArray(), foreground, background);
     }
 
     @Test
     public void testAlphaVersusANDMask() throws Exception {
         final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        final BinaryOutputStream bos = BinaryOutputStream.littleEndian(baos);
-        final byte[] bitmap = new GeneratorFor32BitBitmaps().generate32bitRGBABitmap(
-                0xFF000000, 0x00000000, 0, true);
-        writeICONDIR(bos, 0, 1, 1);
-        writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, 32, 40 + bitmap.length);
-        writeBITMAPINFOHEADER(bos, 16, 2 * 16, 1, 32, 0, 0, 0);
-        bos.write(bitmap);
-        bos.flush();
+        try (final BinaryOutputStream bos = BinaryOutputStream.littleEndian(baos)) {
+            final byte[] bitmap = new GeneratorFor32BitBitmaps().generate32bitRGBABitmap(0xFF000000, 0x00000000, 0, true);
+            writeICONDIR(bos, 0, 1, 1);
+            writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, 32, 40 + bitmap.length);
+            writeBITMAPINFOHEADER(bos, 16, 2 * 16, 1, 32, 0, 0, 0);
+            bos.write(bitmap);
+            bos.flush();
+        }
         // The AND mask is fully opaque, yet the fully transparent alpha should
         // win:
-        writeAndReadImageData("16x16x32-alpha-vs-mask", baos.toByteArray(),
-                0xFF000000, 0x00000000);
+        writeAndReadImageData("16x16x32-alpha-vs-mask", baos.toByteArray(), 0xFF000000, 0x00000000);
     }
 
     @Test
     public void testFullyTransparent32bitRGBA() throws Exception {
         final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        final BinaryOutputStream bos = BinaryOutputStream.littleEndian(baos);
-        final byte[] bitmap = new GeneratorFor32BitBitmaps().generate32bitRGBABitmap(
-                0x00000000, 0x00FFFFFF, 0, true);
-        writeICONDIR(bos, 0, 1, 1);
-        writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, 32, 40 + bitmap.length);
-        writeBITMAPINFOHEADER(bos, 16, 2 * 16, 1, 32, 0, 0, 0);
-        bos.write(bitmap);
-        bos.flush();
+        try (final BinaryOutputStream bos = BinaryOutputStream.littleEndian(baos)) {
+            final byte[] bitmap = new GeneratorFor32BitBitmaps().generate32bitRGBABitmap(0x00000000, 0x00FFFFFF, 0, true);
+            writeICONDIR(bos, 0, 1, 1);
+            writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, 32, 40 + bitmap.length);
+            writeBITMAPINFOHEADER(bos, 16, 2 * 16, 1, 32, 0, 0, 0);
+            bos.write(bitmap);
+            bos.flush();
+        }
         // Because every pixel is fully transparent, ***ALPHA GETS IGNORED***:
-        writeAndReadImageData("16x16x32-fully-transparent", baos.toByteArray(),
-                0xFF000000, 0xFFFFFFFF);
+        writeAndReadImageData("16x16x32-fully-transparent", baos.toByteArray(), 0xFF000000, 0xFFFFFFFF);
     }
 
     private void writeAndReadImageData(final String description, final byte[] rawData,


[commons-imaging] 04/04: Normalize NPE messages

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 b72e985386ef700e50ec726a132fbb67deb175c1
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Mar 21 14:03:19 2023 -0400

    Normalize NPE messages
---
 src/main/java/org/apache/commons/imaging/Imaging.java | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/commons/imaging/Imaging.java b/src/main/java/org/apache/commons/imaging/Imaging.java
index 1406f07f..b973b0ea 100644
--- a/src/main/java/org/apache/commons/imaging/Imaging.java
+++ b/src/main/java/org/apache/commons/imaging/Imaging.java
@@ -901,18 +901,18 @@ public final class Imaging {
      * provide this data.</p>
      *
      * @param src a valid BufferedImage object
-     * @param os the OutputStream to which the output image is to be written
+     * @param outputStream the OutputStream to which the output image is to be written
      * @param format the format in which the output image is to be written
      * @throws ImageWriteException in the event of a format violation, unsupported image format, etc.
      * @throws IOException in the event of an unrecoverable I/O exception.
      * @see ImagingConstants
      */
-    public static void writeImage(final BufferedImage src, final OutputStream os, final ImageFormat format) throws ImageWriteException, IOException {
-        Objects.requireNonNull(src, "src must not be null");
-        Objects.requireNonNull(os, "os must not be null");
-        Objects.requireNonNull(format, "format must not be null");
+    public static void writeImage(final BufferedImage src, final OutputStream outputStream, final ImageFormat format) throws ImageWriteException, IOException {
+        Objects.requireNonNull(src, "src");
+        Objects.requireNonNull(outputStream, "outputStream");
+        Objects.requireNonNull(format, "format");
 
         final ImageParser<?> imageParser = Util.getImageParser(format);
-        imageParser.writeImage(src, os, null);
+        imageParser.writeImage(src, outputStream, null);
     }
 }