This is an automated email from the ASF dual-hosted git repository. kinow pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-imaging.git
commit d689c03e73d9a6ac8bad147c19504e414fc368c2 Author: Bruno P. Kinoshita <ki...@apache.org> AuthorDate: Sat May 15 17:34:42 2021 +1200 [IMAGING-159] Replace tabs by spaces and fix compiler issues --- .../java/org/apache/commons/imaging/Imaging.java | 10 +- .../imaging/formats/png/PngImagingParameters.java | 88 ++++---- .../commons/imaging/formats/png/PngWriter.java | 6 +- .../formats/tiff/TiffImagingParameters.java | 230 ++++++++++----------- .../formats/tiff/write/TiffImageWriterBase.java | 4 +- .../commons/imaging/formats/gif/GifReadTest.java | 5 +- .../commons/imaging/formats/icns/IcnsReadTest.java | 16 +- .../commons/imaging/formats/png/PngReadTest.java | 3 +- .../png/PngWithInvalidPngChunkSizeTest.java | 24 +-- 9 files changed, 192 insertions(+), 194 deletions(-) diff --git a/src/main/java/org/apache/commons/imaging/Imaging.java b/src/main/java/org/apache/commons/imaging/Imaging.java index 83f81c7..1682bb0 100644 --- a/src/main/java/org/apache/commons/imaging/Imaging.java +++ b/src/main/java/org/apache/commons/imaging/Imaging.java @@ -721,14 +721,14 @@ public final class Imaging { // See getImageParser @SuppressWarnings("unchecked") - private static ImageInfo getImageInfo(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { + private static ImageInfo getImageInfo(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return Imaging.getImageParser(byteSource).getImageInfo(byteSource, params); } // TODO: We have no way of knowing whether the returned ImageParser will accept the ImagingParameters, // even if we specified generic types for the static methods. @SuppressWarnings("rawtypes") - private static ImageParser getImageParser(final ByteSource byteSource) throws ImageReadException, IOException { + private static ImageParser getImageParser(final ByteSource byteSource) throws ImageReadException, IOException { final ImageFormat format = guessFormat(byteSource); if (!format.equals(ImageFormats.UNKNOWN)) { @@ -969,7 +969,7 @@ public final class Imaging { * @throws ImageReadException if it fails to parse the image * @throws IOException if it fails to read the image data */ - public static String getXmpXml(final ByteSource byteSource, final XmpImagingParameters params) + public static String getXmpXml(final ByteSource byteSource, final XmpImagingParameters params) throws ImageReadException, IOException { final ImageParser<?> imageParser = getImageParser(byteSource); if (imageParser instanceof XmpEmbeddable) { @@ -1516,13 +1516,13 @@ public final class Imaging { */ // TODO: fix generics due to ImageParser retrieved via getAllImageParsers, and the given ImagingParameters type @SuppressWarnings({ "unchecked", "rawtypes" }) - public static void writeImage(final BufferedImage src, final OutputStream os, + public static void writeImage(final BufferedImage src, final OutputStream os, ImagingParameters params) throws ImageWriteException, IOException { Objects.requireNonNull(params, "You must provide a valid imaging parameters object."); final ImageParser<?>[] imageParsers = ImageParser.getAllImageParsers(); - ImageParser imageParser = null; + ImageParser imageParser = null; for (final ImageParser<?> imageParser2 : imageParsers) { if (imageParser2.canAcceptType(params.getImageFormat())) { imageParser = imageParser2; diff --git a/src/main/java/org/apache/commons/imaging/formats/png/PngImagingParameters.java b/src/main/java/org/apache/commons/imaging/formats/png/PngImagingParameters.java index 5c462b1..1f859f8 100644 --- a/src/main/java/org/apache/commons/imaging/formats/png/PngImagingParameters.java +++ b/src/main/java/org/apache/commons/imaging/formats/png/PngImagingParameters.java @@ -27,74 +27,74 @@ import org.apache.commons.imaging.common.XmpImagingParameters; */ public class PngImagingParameters extends XmpImagingParameters { - public static final byte DEFAULT_BIT_DEPTH = 8; + public static final byte DEFAULT_BIT_DEPTH = 8; - /** - * Bit depth. Default value is {@literal 8}. - */ - private byte bitDepth = DEFAULT_BIT_DEPTH; + /** + * Bit depth. Default value is {@literal 8}. + */ + private byte bitDepth = DEFAULT_BIT_DEPTH; - private boolean forceIndexedColor = false; + private boolean forceIndexedColor = false; - private boolean forceTrueColor = false; + private boolean forceTrueColor = false; - /** + /** * Used in write operations to indicate the Physical Scale - sCAL. * * <p>Valid values: PhysicalScale</p> * * @see org.apache.commons.imaging.formats.png.PhysicalScale */ - private PhysicalScale physicalScale = null; + private PhysicalScale physicalScale = null; - /** + /** * <p>Only used when writing Png images.</p> * * <p>Valid values: a list of WriteTexts.</p> */ - private List<? extends PngText> textChunks = null; + private List<? extends PngText> textChunks = null; - public PngImagingParameters() { - setImageFormat(ImageFormats.PNG); - } + public PngImagingParameters() { + setImageFormat(ImageFormats.PNG); + } - public byte getBitDepth() { - return bitDepth; - } + public byte getBitDepth() { + return bitDepth; + } - public void setBitDepth(byte bitDepth) { - this.bitDepth = bitDepth; - } + public void setBitDepth(byte bitDepth) { + this.bitDepth = bitDepth; + } - public boolean isForceIndexedColor() { - return forceIndexedColor; - } + public boolean isForceIndexedColor() { + return forceIndexedColor; + } - public void setForceIndexedColor(boolean forceIndexedColor) { - this.forceIndexedColor = forceIndexedColor; - } + public void setForceIndexedColor(boolean forceIndexedColor) { + this.forceIndexedColor = forceIndexedColor; + } - public boolean isForceTrueColor() { - return forceTrueColor; - } + public boolean isForceTrueColor() { + return forceTrueColor; + } - public void setForceTrueColor(boolean forceTrueColor) { - this.forceTrueColor = forceTrueColor; - } + public void setForceTrueColor(boolean forceTrueColor) { + this.forceTrueColor = forceTrueColor; + } - public PhysicalScale getPhysicalScale() { - return physicalScale; - } + public PhysicalScale getPhysicalScale() { + return physicalScale; + } - public void setPhysicalScale(PhysicalScale physicalScale) { - this.physicalScale = physicalScale; - } + public void setPhysicalScale(PhysicalScale physicalScale) { + this.physicalScale = physicalScale; + } - public List<? extends PngText> getTextChunks() { - return textChunks != null ? Collections.unmodifiableList(textChunks) : null; - } + public List<? extends PngText> getTextChunks() { + return textChunks != null ? Collections.unmodifiableList(textChunks) : null; + } - public void setTextChunks(List<? extends PngText> textChunks) { - this.textChunks = textChunks; - } + public void setTextChunks(List<? extends PngText> textChunks) { + this.textChunks = textChunks; + } } diff --git a/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java b/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java index a2dac83..b2f3daa 100644 --- a/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java +++ b/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java @@ -430,9 +430,9 @@ class PngWriter { final PhysicalScale physicalScale = params.getPhysicalScale(); if (physicalScale != null) { writeChunkSCAL( - os, - physicalScale.getHorizontalUnitsPerPixel(), - physicalScale.getVerticalUnitsPerPixel(), + os, + physicalScale.getHorizontalUnitsPerPixel(), + physicalScale.getVerticalUnitsPerPixel(), physicalScale.isInMeters() ? (byte) 1 : (byte) 2); } diff --git a/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImagingParameters.java b/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImagingParameters.java index 54c0047..4c13726 100644 --- a/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImagingParameters.java +++ b/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImagingParameters.java @@ -26,61 +26,61 @@ import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; */ public class TiffImagingParameters extends XmpImagingParameters { - /** - * Indicates whether to read embedded thumbnails or not. Only applies to read EXIF metadata from JPEG/JFIF files. - * - * <p>Default value is {@code true}.</p> - */ - private boolean readThumbnails = true; - - /** - * User provided {@code TiffOutputSet} used to write into the image's EXIF metadata. - */ - private TiffOutputSet exif = null; - - /** - * X-coordinate of a sub-image. - */ - private Integer subImageX = null; - - /** - * Y-coordinate of a sub-image. - */ - private Integer subImageY = null; - - /** - * Width of a sub-image. - */ - private Integer subImageWidth = null; - - /** - * Height of a sub-image. - */ - private Integer subImageHeight = null; - - /** - * Specifies that an application-specified photometric interpreter + /** + * Indicates whether to read embedded thumbnails or not. Only applies to read EXIF metadata from JPEG/JFIF files. + * + * <p>Default value is {@code true}.</p> + */ + private boolean readThumbnails = true; + + /** + * User provided {@code TiffOutputSet} used to write into the image's EXIF metadata. + */ + private TiffOutputSet exif = null; + + /** + * X-coordinate of a sub-image. + */ + private Integer subImageX = null; + + /** + * Y-coordinate of a sub-image. + */ + private Integer subImageY = null; + + /** + * Width of a sub-image. + */ + private Integer subImageWidth = null; + + /** + * Height of a sub-image. + */ + private Integer subImageHeight = null; + + /** + * Specifies that an application-specified photometric interpreter * is to be used when reading TIFF files to convert raster data samples * to RGB values for the output image. * * <p>The value supplied with this key should be a valid instance of * a class that implements PhotometricInterpreter.</p> - */ - private PhotometricInterpreter customPhotometricInterpreter = null; + */ + private PhotometricInterpreter customPhotometricInterpreter = null; - /** - * TIFF compression algorithm, if any. - */ - private Integer compression = null; + /** + * TIFF compression algorithm, if any. + */ + private Integer compression = null; - /** + /** * Specifies the amount of memory in bytes to be used for a strip * or tile size when employing LZW compression. The default is * 8000 (roughly 8K). Minimum value is 8000. */ - private Integer lzwCompressionBlockSize = null; + private Integer lzwCompressionBlockSize = null; - /** + /** * Used in write operations to indicate the desired T.4 options to * use when using TIFF_COMPRESSION_CCITT_GROUP_3. * @@ -88,107 +88,107 @@ public class TiffImagingParameters extends XmpImagingParameters { * TIFF_FLAG_T4_OPTIONS_2D, TIFF_FLAG_T4_OPTIONS_UNCOMPRESSED_MODE, * and TIFF_FLAG_T4_OPTIONS_FILL flags.</p> */ - private Integer t4Options = null; + private Integer t4Options = null; - /** + /** * Used in write operations to indicate the desired T.6 options to * use when using TIFF_COMPRESSION_CCITT_GROUP_4. * * <p>Valid values: any Integer containing either zero or * TIFF_FLAG_T6_OPTIONS_UNCOMPRESSED_MODE.</p> */ - private Integer t6Options = null; + private Integer t6Options = null; - public TiffImagingParameters() { - setImageFormat(ImageFormats.TIFF); - } + public TiffImagingParameters() { + setImageFormat(ImageFormats.TIFF); + } - public boolean isReadThumbnails() { - return readThumbnails; - } + public boolean isReadThumbnails() { + return readThumbnails; + } - public void setReadThumbnails(boolean readThumbnails) { - this.readThumbnails = readThumbnails; - } + public void setReadThumbnails(boolean readThumbnails) { + this.readThumbnails = readThumbnails; + } - public TiffOutputSet getExif() { - return exif; - } + public TiffOutputSet getExif() { + return exif; + } - public void setExif(TiffOutputSet exif) { - this.exif = exif; - } + public void setExif(TiffOutputSet exif) { + this.exif = exif; + } - public Integer getSubImageX() { - return subImageX; - } + public Integer getSubImageX() { + return subImageX; + } - public void setSubImageX(Integer subImageX) { - this.subImageX = subImageX; - } + public void setSubImageX(Integer subImageX) { + this.subImageX = subImageX; + } - public Integer getSubImageY() { - return subImageY; - } + public Integer getSubImageY() { + return subImageY; + } - public void setSubImageY(Integer subImageY) { - this.subImageY = subImageY; - } + public void setSubImageY(Integer subImageY) { + this.subImageY = subImageY; + } - public Integer getSubImageWidth() { - return subImageWidth; - } + public Integer getSubImageWidth() { + return subImageWidth; + } - public void setSubImageWidth(Integer subImageWidth) { - this.subImageWidth = subImageWidth; - } + public void setSubImageWidth(Integer subImageWidth) { + this.subImageWidth = subImageWidth; + } - public Integer getSubImageHeight() { - return subImageHeight; - } + public Integer getSubImageHeight() { + return subImageHeight; + } - public void setSubImageHeight(Integer subImageHeight) { - this.subImageHeight = subImageHeight; - } + public void setSubImageHeight(Integer subImageHeight) { + this.subImageHeight = subImageHeight; + } - public PhotometricInterpreter getCustomPhotometricInterpreter() { - return customPhotometricInterpreter; - } + public PhotometricInterpreter getCustomPhotometricInterpreter() { + return customPhotometricInterpreter; + } - public void setCustomPhotometricInterpreter(PhotometricInterpreter customPhotometricInterpreter) { - this.customPhotometricInterpreter = customPhotometricInterpreter; - } + public void setCustomPhotometricInterpreter(PhotometricInterpreter customPhotometricInterpreter) { + this.customPhotometricInterpreter = customPhotometricInterpreter; + } - public Integer getCompression() { - return compression; - } + public Integer getCompression() { + return compression; + } - public void setCompression(Integer compression) { - this.compression = compression; - } + public void setCompression(Integer compression) { + this.compression = compression; + } - public Integer getLzwCompressionBlockSize() { - return lzwCompressionBlockSize; - } + public Integer getLzwCompressionBlockSize() { + return lzwCompressionBlockSize; + } - public void setLzwCompressionBlockSize(Integer lzwCompressionBlockSize) { - this.lzwCompressionBlockSize = lzwCompressionBlockSize; - } + public void setLzwCompressionBlockSize(Integer lzwCompressionBlockSize) { + this.lzwCompressionBlockSize = lzwCompressionBlockSize; + } - public Integer getT4Options() { - return t4Options; - } + public Integer getT4Options() { + return t4Options; + } - public void setT4Options(Integer t4Options) { - this.t4Options = t4Options; - } + public void setT4Options(Integer t4Options) { + this.t4Options = t4Options; + } - public Integer getT6Options() { - return t6Options; - } + public Integer getT6Options() { + return t6Options; + } - public void setT6Options(Integer t6Options) { - this.t6Options = t6Options; - } + public void setT6Options(Integer t6Options) { + this.t6Options = t6Options; + } } diff --git a/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterBase.java b/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterBase.java index 696cede..325b089 100644 --- a/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterBase.java +++ b/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterBase.java @@ -341,8 +341,8 @@ public abstract class TiffImageWriterBase { int stripSizeInBits = 64000; // the default from legacy implementation Integer compressionParameter = params.getCompression(); if (compressionParameter != null) { - compression = compressionParameter.intValue(); - final Integer stripSizeInBytes = params.getLzwCompressionBlockSize(); + compression = compressionParameter.intValue(); + final Integer stripSizeInBytes = params.getLzwCompressionBlockSize(); if (stripSizeInBytes != null) { if (stripSizeInBytes < 8000) { throw new ImageWriteException( diff --git a/src/test/java/org/apache/commons/imaging/formats/gif/GifReadTest.java b/src/test/java/org/apache/commons/imaging/formats/gif/GifReadTest.java index ea69a9e..fff48c9 100644 --- a/src/test/java/org/apache/commons/imaging/formats/gif/GifReadTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/gif/GifReadTest.java @@ -25,7 +25,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; -import java.util.Collections; import java.util.List; import java.util.stream.Stream; @@ -161,7 +160,7 @@ public class GifReadTest extends GifBaseTest { final String input = "/images/gif/oss-fuzz-33501/clusterfuzz-testcase-minimized-ImagingGifFuzzer-5914278319226880"; final String file = GifReadTest.class.getResource(input).getFile(); final GifImageParser parser = new GifImageParser(); - assertThrows(ImageReadException.class, () -> parser.getBufferedImage(new ByteSourceFile(new File(file)), Collections.emptyMap())); + assertThrows(ImageReadException.class, () -> parser.getBufferedImage(new ByteSourceFile(new File(file)), new GifImagingParameters())); } /** @@ -180,7 +179,7 @@ public class GifReadTest extends GifBaseTest { final String input = "/images/gif/oss-fuzz-33464/clusterfuzz-testcase-minimized-ImagingGifFuzzer-5174009164595200"; final String file = GifReadTest.class.getResource(input).getFile(); final GifImageParser parser = new GifImageParser(); - assertThrows(ImageReadException.class, () -> parser.getBufferedImage(new ByteSourceFile(new File(file)), Collections.emptyMap())); + assertThrows(ImageReadException.class, () -> parser.getBufferedImage(new ByteSourceFile(new File(file)), new GifImagingParameters())); } /** diff --git a/src/test/java/org/apache/commons/imaging/formats/icns/IcnsReadTest.java b/src/test/java/org/apache/commons/imaging/formats/icns/IcnsReadTest.java index 61fc17f..35bc133 100644 --- a/src/test/java/org/apache/commons/imaging/formats/icns/IcnsReadTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/icns/IcnsReadTest.java @@ -52,11 +52,11 @@ public class IcnsReadTest extends IcnsBaseTest { * @return stream of test arguments */ public static Stream<Arguments> provideIcnsImagesWithMonoAndJpegPngData() { - return Arrays - .asList( - Arguments.of("/images/icns/IMAGING-248/python.icns", 7), - Arguments.of("/images/icns/IMAGING-248/groovy.icns", 3)) - .stream(); + return Arrays + .asList( + Arguments.of("/images/icns/IMAGING-248/python.icns", 7), + Arguments.of("/images/icns/IMAGING-248/groovy.icns", 3)) + .stream(); } @Disabled(value = "RoundtripTest has to be fixed befor implementation can throw UnsupportedOperationException") @@ -90,8 +90,8 @@ public class IcnsReadTest extends IcnsBaseTest { @ParameterizedTest() @MethodSource("provideIcnsImagesWithMonoAndJpegPngData") public void testIcnsElementMonoPngJpeg(final String file, final int numberOfImages) throws ImageReadException, IOException { - final File testFile = new File(IcnsReadTest.class.getResource(file).getFile()); - final List<BufferedImage> images = new IcnsImageParser().getAllBufferedImages(testFile); - assertEquals(numberOfImages, images.size()); + final File testFile = new File(IcnsReadTest.class.getResource(file).getFile()); + final List<BufferedImage> images = new IcnsImageParser().getAllBufferedImages(testFile); + assertEquals(numberOfImages, images.size()); } } diff --git a/src/test/java/org/apache/commons/imaging/formats/png/PngReadTest.java b/src/test/java/org/apache/commons/imaging/formats/png/PngReadTest.java index 646af64..7655477 100644 --- a/src/test/java/org/apache/commons/imaging/formats/png/PngReadTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/png/PngReadTest.java @@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; -import java.util.Collections; import java.util.List; import org.apache.commons.imaging.ImageInfo; @@ -92,7 +91,7 @@ public class PngReadTest extends PngBaseTest { final String input = "/images/png/oss-fuzz-33691/clusterfuzz-testcase-minimized-ImagingPngFuzzer-6177282101215232"; final String file = PngReadTest.class.getResource(input).getFile(); final PngImageParser parser = new PngImageParser(); - assertThrows(ImageReadException.class, () -> parser.getBufferedImage(new ByteSourceFile(new File(file)), Collections.emptyMap())); + assertThrows(ImageReadException.class, () -> parser.getBufferedImage(new ByteSourceFile(new File(file)), new PngImagingParameters())); } /** diff --git a/src/test/java/org/apache/commons/imaging/formats/png/PngWithInvalidPngChunkSizeTest.java b/src/test/java/org/apache/commons/imaging/formats/png/PngWithInvalidPngChunkSizeTest.java index c631ae3..108444d 100644 --- a/src/test/java/org/apache/commons/imaging/formats/png/PngWithInvalidPngChunkSizeTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/png/PngWithInvalidPngChunkSizeTest.java @@ -31,20 +31,20 @@ import org.junit.jupiter.api.Test; */ public class PngWithInvalidPngChunkSizeTest { - /** - * Test that an image with an invalid PNG chunk size causes an - * ImageReadException instead of other exception types. - */ - @Test - public void testPngWithInvalidPngChunkSize() { - final File imageFile = new File( - JpegWithInvalidDhtSegmentTest.class.getResource("/IMAGING-211/testfile_2.png").getFile()); - final PngImagingParameters params = new PngImagingParameters(); + /** + * Test that an image with an invalid PNG chunk size causes an + * ImageReadException instead of other exception types. + */ + @Test + public void testPngWithInvalidPngChunkSize() { + final File imageFile = new File( + JpegWithInvalidDhtSegmentTest.class.getResource("/IMAGING-211/testfile_2.png").getFile()); + final PngImagingParameters params = new PngImagingParameters(); params.setBufferedImageFactory(new ManagedImageBufferedImageFactory()); - Assertions.assertThrows(ImageReadException.class, () -> Imaging.getBufferedImage(imageFile, params)); - } + Assertions.assertThrows(ImageReadException.class, () -> Imaging.getBufferedImage(imageFile, params)); + } - /** + /** * Test that an image with an invalid negative PNG chunk size causes an * ImageReadException instead of other exception types. */