diff --git a/src/main/java/org/apache/commons/imaging/ImageParser.java b/src/main/java/org/apache/commons/imaging/ImageParser.java index c3a061fba..758d4cb73 100644 --- a/src/main/java/org/apache/commons/imaging/ImageParser.java +++ b/src/main/java/org/apache/commons/imaging/ImageParser.java @@ -26,7 +26,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; -import java.util.Map; import org.apache.commons.imaging.common.BinaryFileParser; import org.apache.commons.imaging.common.BufferedImageFactory; @@ -76,24 +75,6 @@ * the intentions of the original. Therefore, you should not assume * that the documentation is perfect, especially in the more obscure * and specialized areas of implementation. - * - *

The "Map params" argument

- * - * Many of the methods specified by this class accept an argument of - * type Map giving a list of parameters to be used when processing an - * image. For example, some of the output formats permit the specification - * of different kinds of image compression or color models. Some of the - * reading methods permit the calling application to require strict - * format compliance. In many cases, however, an application will not - * require the use of this argument. While some of the ImageParser - * implementations check for (and ignore) null arguments for this parameter, - * not all of them do (at least not at the time these notes were written). - * Therefore, a prudent programmer will always supply an valid, though - * empty instance of a Map implementation when calling such methods. - * Generally, the java HashMap class is useful for this purpose. - * - *

Additionally, developers creating or enhancing classes derived - * from ImageParser are encouraged to include such checks in their code. */ public abstract class ImageParser extends BinaryFileParser { @@ -169,7 +150,7 @@ public final ImageMetadata getMetadata(final ByteSource byteSource) throws Image * implementation. * @throws IOException In the event of unsuccessful data read operation. */ - public abstract ImageMetadata getMetadata(ByteSource byteSource, Map params) + public abstract ImageMetadata getMetadata(ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException; /** @@ -215,7 +196,7 @@ public final ImageMetadata getMetadata(final byte[] bytes) throws ImageReadExcep * parser implementation. * @throws IOException In the event of unsuccessful data read operation. */ - public final ImageMetadata getMetadata(final byte[] bytes, final Map params) + public final ImageMetadata getMetadata(final byte[] bytes, final ImagingParameters params) throws ImageReadException, IOException { return getMetadata(new ByteSourceArray(bytes), params); } @@ -264,7 +245,7 @@ public final ImageMetadata getMetadata(final File file) throws ImageReadExceptio * @throws IOException In the event of unsuccessful file read or * access operation. */ - public final ImageMetadata getMetadata(final File file, final Map params) + public final ImageMetadata getMetadata(final File file, final ImagingParameters params) throws ImageReadException, IOException { if (getDebug()) { System.out.println(getName() + ".getMetadata" + ": " @@ -302,7 +283,7 @@ public final ImageMetadata getMetadata(final File file, final Map params) + public abstract ImageInfo getImageInfo(ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException; /** @@ -348,7 +329,7 @@ public final ImageInfo getImageInfo(final ByteSource byteSource) throws ImageRea * @throws IOException In the event of unsuccessful data * access operation. */ - public final ImageInfo getImageInfo(final byte[] bytes, final Map params) + public final ImageInfo getImageInfo(final byte[] bytes, final ImagingParameters params) throws ImageReadException, IOException { return getImageInfo(new ByteSourceArray(bytes), params); } @@ -377,7 +358,7 @@ public final ImageInfo getImageInfo(final byte[] bytes, final Map params) + public final ImageInfo getImageInfo(final File file, final ImagingParameters params) throws ImageReadException, IOException { if (!canAcceptExtension(file)) { return null; @@ -505,7 +486,7 @@ public final List getAllBufferedImages(final File file) throws Im * parser implementation. * @throws IOException In the event of unsuccessful read or access operation. */ - public abstract BufferedImage getBufferedImage(ByteSource byteSource, Map params) + public abstract BufferedImage getBufferedImage(ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException; /** @@ -523,7 +504,7 @@ public abstract BufferedImage getBufferedImage(ByteSource byteSource, Map params) + public final BufferedImage getBufferedImage(final byte[] bytes, final ImagingParameters params) throws ImageReadException, IOException { return getBufferedImage(new ByteSourceArray(bytes), params); } @@ -543,7 +524,7 @@ public final BufferedImage getBufferedImage(final byte[] bytes, final Map params) + public final BufferedImage getBufferedImage(final File file, final ImagingParameters params) throws ImageReadException, IOException { if (!canAcceptExtension(file)) { return null; @@ -575,7 +556,7 @@ public final BufferedImage getBufferedImage(final File file, final Map params) + public void writeImage(final BufferedImage src, final OutputStream os, final ImagingParameters params) throws ImageWriteException, IOException { os.close(); // we are obligated to close stream. @@ -609,7 +590,7 @@ public final Dimension getImageSize(final byte[] bytes) throws ImageReadExceptio * parser implementation. * @throws IOException In the event of unsuccessful read or access operation. */ - public final Dimension getImageSize(final byte[] bytes, final Map params) + public final Dimension getImageSize(final byte[] bytes, final ImagingParameters params) throws ImageReadException, IOException { return getImageSize(new ByteSourceArray(bytes), params); } @@ -640,7 +621,7 @@ public final Dimension getImageSize(final File file) throws ImageReadException, * parser implementation. * @throws IOException In the event of unsuccessful read or access operation. */ - public final Dimension getImageSize(final File file, final Map params) + public final Dimension getImageSize(final File file, final ImagingParameters params) throws ImageReadException, IOException { if (!canAcceptExtension(file)) { @@ -662,7 +643,7 @@ public final Dimension getImageSize(final File file, final Map p * parser implementation. * @throws IOException In the event of unsuccessful read or access operation. */ - public abstract Dimension getImageSize(ByteSource byteSource, Map params) + public abstract Dimension getImageSize(ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException; /** @@ -682,7 +663,7 @@ public abstract Dimension getImageSize(ByteSource byteSource, Map params) + public abstract String getXmpXml(ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException; /** @@ -715,7 +696,7 @@ public final byte[] getICCProfileBytes(final byte[] bytes) throws ImageReadExcep * parser implementation. * @throws IOException In the event of unsuccessful read or access operation. */ - public final byte[] getICCProfileBytes(final byte[] bytes, final Map params) + public final byte[] getICCProfileBytes(final byte[] bytes, final ImagingParameters params) throws ImageReadException, IOException { return getICCProfileBytes(new ByteSourceArray(bytes), params); } @@ -750,7 +731,7 @@ public final byte[] getICCProfileBytes(final File file) throws ImageReadExceptio * parser implementation. * @throws IOException In the event of unsuccessful read or access operation. */ - public final byte[] getICCProfileBytes(final File file, final Map params) + public final byte[] getICCProfileBytes(final File file, final ImagingParameters params) throws ImageReadException, IOException { if (!canAcceptExtension(file)) { return null; @@ -777,7 +758,7 @@ public final byte[] getICCProfileBytes(final File file, final Map params) + public abstract byte[] getICCProfileBytes(ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException; /** @@ -846,6 +827,7 @@ public final String dumpImageFile(final ByteSource byteSource) * Write the ImageInfo and format-specific information for the image * content of the specified byte source to a PrintWriter * + * @param pw * @param byteSource A valid byte source. * @return A valid PrintWriter. * @throws ImageReadException In the event that the the specified content @@ -954,13 +936,12 @@ protected final boolean canAcceptExtension(final String filename) { * @param params A valid Map object, or a null. * @return A valid instance of an implementation of a IBufferedImageFactory. */ - protected BufferedImageFactory getBufferedImageFactory(final Map params) { - if (params == null) { + protected BufferedImageFactory getBufferedImageFactory(final ImagingParameters params) { + if (params == null || params.isBufferedImageFactoryPresent() == false) { return new SimpleBufferedImageFactory(); } - final BufferedImageFactory result = (BufferedImageFactory) params - .get(ImagingConstants.BUFFERED_IMAGE_FACTORY); + final BufferedImageFactory result = params.getBufferedImageFactory(); if (null != result) { return result; @@ -970,19 +951,18 @@ protected BufferedImageFactory getBufferedImageFactory(final Map } /** - * A utility method to search a params specification and determine - * whether it contains the ImagingConstants.PARAM_KEY_STRICT - * specification. Intended - * for internal use by ImageParser implementations. + * A utility method to whether we have a parameter object and if the STRICT + * flag is set or not. + * Intended for internal use by ImageParser implementations. * - * @param params A valid Map object (or a null). + * @param params A valid parameter object (or a null). * @return If the params specify strict format compliance, true; * otherwise, false. */ - public static boolean isStrict(final Map params) { - if (params == null || !params.containsKey(ImagingConstants.PARAM_KEY_STRICT)) { + public static boolean isStrict(final ImagingParameters params) { + if (params == null) { return false; } - return ((Boolean) params.get(ImagingConstants.PARAM_KEY_STRICT)).booleanValue(); + return params.getStrict(); } } diff --git a/src/main/java/org/apache/commons/imaging/Imaging.java b/src/main/java/org/apache/commons/imaging/Imaging.java index e81188859..68362f3fe 100644 --- a/src/main/java/org/apache/commons/imaging/Imaging.java +++ b/src/main/java/org/apache/commons/imaging/Imaging.java @@ -26,10 +26,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.HashMap; import java.util.List; import java.util.Locale; -import java.util.Map; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.common.bytesource.ByteSource; @@ -40,8 +38,6 @@ import org.apache.commons.imaging.icc.IccProfileParser; import org.apache.commons.imaging.util.IoUtils; -import static org.apache.commons.imaging.ImagingConstants.*; - /** * The primary application programming interface (API) to the Imaging library. * @@ -92,11 +88,9 @@ *

* *

- * Optional parameters are specified using a Map object (typically, - * a Java HashMap) to specify a set of keys and values for input. - * The specification for support keys is provided by the ImagingConstants - * interface as well as by format-specific interfaces such as - * JpegContants or TiffConstants. + * Optional parameters are specified using a parameter object, ImagingParameters. + * This class is overridden by format-specific parameter object classes such as + * ImagingParametersJpeg or ImagingParametersTiff. *

* *

Example code

@@ -375,11 +369,11 @@ public static ICC_Profile getICCProfile(final byte[] bytes) * @param bytes * Byte array containing an image file. * @param params - * Map of optional parameters, defined in ImagingConstants. + * Optional parameters, defined in ImagingParameters. * @return An instance of ICC_Profile or null if the image contains no ICC * profile.. */ - public static ICC_Profile getICCProfile(final byte[] bytes, final Map params) + public static ICC_Profile getICCProfile(final byte[] bytes, final ImagingParameters params) throws ImageReadException, IOException { return getICCProfile(new ByteSourceArray(bytes), params); } @@ -411,12 +405,12 @@ public static ICC_Profile getICCProfile(final InputStream is, final String filen * @param filename * Filename associated with image data (optional). * @param params - * Map of optional parameters, defined in ImagingConstants. + * Optional parameters, defined in ImagingParameters. * @return An instance of ICC_Profile or null if the image contains no ICC * profile.. */ public static ICC_Profile getICCProfile(final InputStream is, final String filename, - final Map params) throws ImageReadException, IOException { + final ImagingParameters params) throws ImageReadException, IOException { return getICCProfile(new ByteSourceInputStream(is, filename), params); } @@ -443,16 +437,16 @@ public static ICC_Profile getICCProfile(final File file) * @param file * File containing image data. * @param params - * Map of optional parameters, defined in ImagingConstants. + * Optional parameters, defined in ImagingParameters. * @return An instance of ICC_Profile or null if the image contains no ICC * profile.. */ - public static ICC_Profile getICCProfile(final File file, final Map params) + public static ICC_Profile getICCProfile(final File file, final ImagingParameters params) throws ImageReadException, IOException { return getICCProfile(new ByteSourceFile(file), params); } - protected static ICC_Profile getICCProfile(final ByteSource byteSource, final Map params) + protected static ICC_Profile getICCProfile(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final byte[] bytes = getICCProfileBytes(byteSource, params); if (bytes == null) { @@ -501,12 +495,12 @@ public static byte[] getICCProfileBytes(final byte[] bytes) * @param bytes * Byte array containing an image file. * @param params - * Map of optional parameters, defined in ImagingConstants. + * Optional parameters, defined in ImagingParameters. * @return A byte array. * @see IccProfileParser * @see ICC_Profile */ - public static byte[] getICCProfileBytes(final byte[] bytes, final Map params) + public static byte[] getICCProfileBytes(final byte[] bytes, final ImagingParameters params) throws ImageReadException, IOException { return getICCProfileBytes(new ByteSourceArray(bytes), params); } @@ -541,17 +535,17 @@ public static byte[] getICCProfileBytes(final File file) * @param file * File containing image data. * @param params - * Map of optional parameters, defined in ImagingConstants. + * Optional parameters, defined in ImagingParameters. * @return A byte array. * @see IccProfileParser * @see ICC_Profile */ - public static byte[] getICCProfileBytes(final File file, final Map params) + public static byte[] getICCProfileBytes(final File file, final ImagingParameters params) throws ImageReadException, IOException { return getICCProfileBytes(new ByteSourceFile(file), params); } - private static byte[] getICCProfileBytes(final ByteSource byteSource, final Map params) + private static byte[] getICCProfileBytes(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final ImageParser imageParser = getImageParser(byteSource); @@ -572,12 +566,12 @@ private static byte[] getICCProfileBytes(final ByteSource byteSource, final Map< * @param bytes * Byte array containing an image file. * @param params - * Map of optional parameters, defined in ImagingConstants. + * Optional parameters, defined in ImagingParameters. * @return An instance of ImageInfo. * @see ImageInfo */ public static ImageInfo getImageInfo(final String filename, final byte[] bytes, - final Map params) throws ImageReadException, IOException { + final ImagingParameters params) throws ImageReadException, IOException { return getImageInfo(new ByteSourceArray(filename, bytes), params); } @@ -637,12 +631,12 @@ public static ImageInfo getImageInfo(final InputStream is, final String filename * @param filename * Filename associated with image data (optional). * @param params - * Map of optional parameters, defined in ImagingConstants. + * Optional parameters, defined in ImagingParameters. * @return An instance of ImageInfo. * @see ImageInfo */ public static ImageInfo getImageInfo(final InputStream is, final String filename, - final Map params) throws ImageReadException, IOException { + final ImagingParameters params) throws ImageReadException, IOException { return getImageInfo(new ByteSourceInputStream(is, filename), params); } @@ -677,11 +671,11 @@ public static ImageInfo getImageInfo(final byte[] bytes) * @param bytes * Byte array containing an image file. * @param params - * Map of optional parameters, defined in ImagingConstants. + * Optional parameters, defined in ImagingParameters. * @return An instance of ImageInfo. * @see ImageInfo */ - public static ImageInfo getImageInfo(final byte[] bytes, final Map params) + public static ImageInfo getImageInfo(final byte[] bytes, final ImagingParameters params) throws ImageReadException, IOException { return getImageInfo(new ByteSourceArray(bytes), params); } @@ -698,11 +692,11 @@ public static ImageInfo getImageInfo(final byte[] bytes, final Map params) + public static ImageInfo getImageInfo(final File file, final ImagingParameters params) throws ImageReadException, IOException { return getImageInfo(new ByteSourceFile(file), params); } @@ -726,7 +720,7 @@ public static ImageInfo getImageInfo(final File file) throws ImageReadException, return getImageInfo(file, null); } - private static ImageInfo getImageInfo(final ByteSource byteSource, final Map params) + private static ImageInfo getImageInfo(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final ImageParser imageParser = getImageParser(byteSource); @@ -785,11 +779,11 @@ public static Dimension getImageSize(final InputStream is, final String filename * @param filename * Filename associated with image data (optional). * @param params - * Map of optional parameters, defined in ImagingConstants. + * Optional parameters, defined in ImagingParameters. * @return The width and height of the image. */ public static Dimension getImageSize(final InputStream is, final String filename, - final Map params) throws ImageReadException, IOException { + final ImagingParameters params) throws ImageReadException, IOException { return getImageSize(new ByteSourceInputStream(is, filename), params); } @@ -813,10 +807,10 @@ public static Dimension getImageSize(final byte[] bytes) * @param bytes * Byte array containing an image file. * @param params - * Map of optional parameters, defined in ImagingConstants. + * Optional parameters, defined in ImagingParameters. * @return The width and height of the image. */ - public static Dimension getImageSize(final byte[] bytes, final Map params) + public static Dimension getImageSize(final byte[] bytes, final ImagingParameters params) throws ImageReadException, IOException { return getImageSize(new ByteSourceArray(bytes), params); } @@ -841,15 +835,15 @@ public static Dimension getImageSize(final File file) throws ImageReadException, * @param file * File containing image data. * @param params - * Map of optional parameters, defined in ImagingConstants. + * Optional parameters, defined in ImagingParameters. * @return The width and height of the image. */ - public static Dimension getImageSize(final File file, final Map params) + public static Dimension getImageSize(final File file, final ImagingParameters params) throws ImageReadException, IOException { return getImageSize(new ByteSourceFile(file), params); } - public static Dimension getImageSize(final ByteSource byteSource, final Map params) + public static Dimension getImageSize(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final ImageParser imageParser = getImageParser(byteSource); @@ -880,10 +874,10 @@ public static String getXmpXml(final InputStream is, final String filename) * @param filename * Filename associated with image data (optional). * @param params - * Map of optional parameters, defined in ImagingConstants. + * Optional parameters, defined in ImagingParameters. * @return Xmp Xml as String, if present. Otherwise, returns null. */ - public static String getXmpXml(final InputStream is, final String filename, final Map params) + public static String getXmpXml(final InputStream is, final String filename, final ImagingParameters params) throws ImageReadException, IOException { return getXmpXml(new ByteSourceInputStream(is, filename), params); } @@ -908,10 +902,10 @@ public static String getXmpXml(final byte[] bytes) throws ImageReadException, * @param bytes * Byte array containing an image file. * @param params - * Map of optional parameters, defined in ImagingConstants. + * Optional parameters, defined in ImagingParameters. * @return Xmp Xml as String, if present. Otherwise, returns null. */ - public static String getXmpXml(final byte[] bytes, final Map params) + public static String getXmpXml(final byte[] bytes, final ImagingParameters params) throws ImageReadException, IOException { return getXmpXml(new ByteSourceArray(bytes), params); } @@ -936,10 +930,10 @@ public static String getXmpXml(final File file) throws ImageReadException, * @param file * File containing image data. * @param params - * Map of optional parameters, defined in ImagingConstants. + * Optional parameters, defined in ImagingParameters. * @return Xmp Xml as String, if present. Otherwise, returns null. */ - public static String getXmpXml(final File file, final Map params) + public static String getXmpXml(final File file, final ImagingParameters params) throws ImageReadException, IOException { return getXmpXml(new ByteSourceFile(file), params); } @@ -951,10 +945,10 @@ public static String getXmpXml(final File file, final Map params * @param byteSource * File containing image data. * @param params - * Map of optional parameters, defined in ImagingConstants. + * Optional parameters, defined in ImagingParameters. * @return Xmp Xml as String, if present. Otherwise, returns null. */ - public static String getXmpXml(final ByteSource byteSource, final Map params) + public static String getXmpXml(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final ImageParser imageParser = getImageParser(byteSource); @@ -1000,11 +994,11 @@ public static ImageMetadata getMetadata(final byte[] bytes) * @param bytes * Byte array containing an image file. * @param params - * Map of optional parameters, defined in ImagingConstants. + * Optional parameters, defined in ImagingParameters. * @return An instance of IImageMetadata. * @see org.apache.commons.imaging.common.ImageMetadata */ - public static ImageMetadata getMetadata(final byte[] bytes, final Map params) + public static ImageMetadata getMetadata(final byte[] bytes, final ImagingParameters params) throws ImageReadException, IOException { return getMetadata(new ByteSourceArray(bytes), params); } @@ -1052,12 +1046,12 @@ public static ImageMetadata getMetadata(final InputStream is, final String filen * @param filename * Filename associated with image data (optional). * @param params - * Map of optional parameters, defined in ImagingConstants. + * Optional parameters, defined in ImagingParameters. * @return An instance of IImageMetadata. * @see org.apache.commons.imaging.common.ImageMetadata */ public static ImageMetadata getMetadata(final InputStream is, final String filename, - final Map params) throws ImageReadException, IOException { + final ImagingParameters params) throws ImageReadException, IOException { return getMetadata(new ByteSourceInputStream(is, filename), params); } @@ -1100,16 +1094,16 @@ public static ImageMetadata getMetadata(final File file) * @param file * File containing image data. * @param params - * Map of optional parameters, defined in ImagingConstants. + * Optional parameters, defined in ImagingParameters. * @return An instance of IImageMetadata. * @see org.apache.commons.imaging.common.ImageMetadata */ - public static ImageMetadata getMetadata(final File file, final Map params) + public static ImageMetadata getMetadata(final File file, final ImagingParameters params) throws ImageReadException, IOException { return getMetadata(new ByteSourceFile(file), params); } - private static ImageMetadata getMetadata(final ByteSource byteSource, final Map params) + private static ImageMetadata getMetadata(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final ImageParser imageParser = getImageParser(byteSource); @@ -1274,8 +1268,8 @@ public static BufferedImage getBufferedImage(final InputStream is) /** * Reads the first image from an InputStream - * using data-processing options specified through a parameters - * map. Options may be configured using the ImagingContants + * using data-processing options specified through a parameter + * object. Options may be configured using the ImagingParameters * interface or the various format-specific implementations provided * by this package. *

@@ -1286,17 +1280,17 @@ public static BufferedImage getBufferedImage(final InputStream is) * image info, metadata and ICC profiles from all image formats that * provide this data. * @param is a valid ImageStream from which to read data. - * @param params an optional parameters map specifying options + * @param params an optional parameter object specifying options * @return if successful, a valid buffered image * @throws ImageReadException in the event of a processing error * while reading an image (i.e. a format violation, etc.). * @throws IOException in the event of an unrecoverable I/O exception. */ - public static BufferedImage getBufferedImage(final InputStream is, final Map params) + public static BufferedImage getBufferedImage(final InputStream is, final ImagingParameters params) throws ImageReadException, IOException { String filename = null; - if (params != null && params.containsKey(PARAM_KEY_FILENAME)) { - filename = (String) params.get(PARAM_KEY_FILENAME); + if (params != null && params.isFileNameHintPresent()) { + filename = params.getFileNameHint(); } return getBufferedImage(new ByteSourceInputStream(is, filename), params); } @@ -1342,7 +1336,7 @@ public static BufferedImage getBufferedImage(final byte[] bytes) * while reading an image (i.e. a format violation, etc.). * @throws IOException in the event of an unrecoverable I/O exception. */ - public static BufferedImage getBufferedImage(final byte[] bytes, final Map params) + public static BufferedImage getBufferedImage(final byte[] bytes, final ImagingParameters params) throws ImageReadException, IOException { return getBufferedImage(new ByteSourceArray(bytes), params); } @@ -1373,8 +1367,8 @@ public static BufferedImage getBufferedImage(final File file) /** * Reads the first image from a file - * using data-processing options specified through a parameters - * map. Options may be configured using the ImagingContants + * using data-processing options specified through a parameter + * object. Options may be configured using the ImagingParameters * interface or the various format-specific implementations provided * by this package. *

@@ -1385,12 +1379,13 @@ public static BufferedImage getBufferedImage(final File file) * image info, metadata and ICC profiles from all image formats that * provide this data. * @param file a valid reference to a file containing image data. + * @param params * @return if successful, a valid buffered image * @throws ImageReadException in the event of a processing error * while reading an image (i.e. a format violation, etc.). * @throws IOException in the event of an unrecoverable I/O exception. */ - public static BufferedImage getBufferedImage(final File file, final Map params) + public static BufferedImage getBufferedImage(final File file, final ImagingParameters params) throws ImageReadException, IOException { return getBufferedImage(new ByteSourceFile(file), params); } @@ -1398,20 +1393,20 @@ public static BufferedImage getBufferedImage(final File file, final Map params) throws ImageReadException, IOException { + final ImagingParameters params) throws ImageReadException, IOException { final ImageParser imageParser = getImageParser(byteSource); - if (null == params) { - params = new HashMap(); - } + + // ensure that the parameter object is not null + final ImagingParameters parameters = (params == null) ? new ImagingParameters() : params; - return imageParser.getBufferedImage(byteSource, params); + return imageParser.getBufferedImage(byteSource, parameters); } /** * Writes the content of a BufferedImage to a file using the specified * image format. Specifications for storing the file (such as data compression, * color models, metadata tags, etc.) may be specified using an optional - * parameters map. These specifications are defined in the ImagingConstants + * parameter object. These specifications are defined in the ImagingParameters * interface or in various format-specific implementations. *

* Image writing is not supported for all graphics formats. @@ -1428,10 +1423,10 @@ private static BufferedImage getBufferedImage(final ByteSource byteSource, * @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 + * @see ImagingParameters */ public static void writeImage(final BufferedImage src, final File file, - final ImageFormat format, final Map params) throws ImageWriteException, + final ImageFormat format, final ImagingParameters params) throws ImageWriteException, IOException { OutputStream os = null; boolean canThrow = false; @@ -1451,7 +1446,7 @@ public static void writeImage(final BufferedImage src, final File file, * Writes the content of a BufferedImage to a byte array using the specified * image format. Specifications for storing the file (such as data compression, * color models, metadata tags, etc.) may be specified using an optional - * parameters map. These specifications are defined in the ImagingConstants + * parameter object. These specifications are defined in the ImagingParameters * interface or in various format-specific implementations. *

* Image writing is not supported for all graphics formats. @@ -1468,10 +1463,10 @@ public static void writeImage(final BufferedImage src, final File file, * @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 + * @see ImagingParameters */ public static byte[] writeImageToBytes(final BufferedImage src, - final ImageFormat format, final Map params) throws ImageWriteException, + final ImageFormat format, final ImagingParameters params) throws ImageWriteException, IOException { final ByteArrayOutputStream os = new ByteArrayOutputStream(); @@ -1485,7 +1480,7 @@ public static byte[] writeImageToBytes(final BufferedImage src, * Writes the content of a BufferedImage to an OutputStream using the specified * image format. Specifications for storing the file (such as data compression, * color models, metadata tags, etc.) may be specified using an optional - * parameters map. These specifications are defined in the ImagingConstants + * parameter object. These specifications are defined in the ImagingParameters * interface or in various format-specific implementations. *

* Image writing is not supported for all graphics formats. @@ -1502,19 +1497,17 @@ public static byte[] writeImageToBytes(final BufferedImage src, * @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 + * @see ImagingParameters */ public static void writeImage(final BufferedImage src, final OutputStream os, - final ImageFormat format, Map params) throws ImageWriteException, + final ImageFormat format, final ImagingParameters params) throws ImageWriteException, IOException { final ImageParser[] imageParsers = ImageParser.getAllImageParsers(); - // make sure params are non-null - if (params == null) { - params = new HashMap(); - } - - params.put(PARAM_KEY_FORMAT, format); + // ensure that the parameter object is not null + final ImagingParameters parameters = (params == null) ? new ImagingParameters() : params; + // add format parameter + parameters.setImageFormat(format); ImageParser imageParser = null; for (final ImageParser imageParser2 : imageParsers) { @@ -1524,7 +1517,7 @@ public static void writeImage(final BufferedImage src, final OutputStream os, } } if (imageParser != null) { - imageParser.writeImage(src, os, params); + imageParser.writeImage(src, os, parameters); } else { throw new ImageWriteException("Unknown Format: " + format); } diff --git a/src/main/java/org/apache/commons/imaging/ImagingConstants.java b/src/main/java/org/apache/commons/imaging/ImagingConstants.java deleted file mode 100644 index 56d7a2e74..000000000 --- a/src/main/java/org/apache/commons/imaging/ImagingConstants.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.imaging; - -/** - * Defines constants that may be used in passing options to - * ImageParser read/write implementations, the utility routines - * implemented in the Imaging class, and throughout the - * Apache Commons Imaging package. Individual ImageParser - * implementations may define their own format-specific options. - */ -public final class ImagingConstants { - - /** - * Parameter key. Applies to read and write operations. - *

- * Valid values: Boolean.TRUE and Boolean.FALSE. - */ - public final static String PARAM_KEY_VERBOSE = "VERBOSE"; - - /** - * Parameter key. Used to hint the filename when reading from a byte array - * or InputStream. The filename hint can help disambiguate what file the - * image format. - *

- * Applies to read operations. - *

- * Valid values: filename as string - *

- * - * @see java.io.InputStream - */ - public final static String PARAM_KEY_FILENAME = "FILENAME"; - - /** - * Parameter key. Used in write operations to indicate desired image format. - *

- * Valid values: Any format defined in ImageFormat, such as - * ImageFormat.IMAGE_FORMAT_PNG. - *

- * - * @see org.apache.commons.imaging.ImageFormats - */ - public final static String PARAM_KEY_FORMAT = "FORMAT"; - - /** - * Parameter key. Used in write operations to indicate desired compression - * algorithm. - *

- * Currently only applies to writing TIFF image files. - *

- * Valid values: TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED, - * TiffConstants.TIFF_COMPRESSION_CCITT_1D, - * TiffConstants.TIFF_COMPRESSION_LZW, - * TiffConstants.TIFF_COMPRESSION_PACKBITS. - *

- * - * @see org.apache.commons.imaging.formats.tiff.constants.TiffConstants - */ - public final static String PARAM_KEY_COMPRESSION = "COMPRESSION"; - - public final static String BUFFERED_IMAGE_FACTORY = "BUFFERED_IMAGE_FACTORY"; - - /** - * Parameter key. Indicates whether to read embedded thumbnails. - *

- * Only applies to read EXIF metadata from JPEG/JFIF files. - *

- * Valid values: Boolean.TRUE and Boolean.FALSE. - *

- * - * @see org.apache.commons.imaging.formats.tiff.constants.TiffConstants - */ - public final static String PARAM_KEY_READ_THUMBNAILS = "READ_THUMBNAILS"; - - /** - * Parameter key. Indicates whether to throw exceptions when parsing invalid - * files, or whether to tolerate small problems. - *

- * Valid values: Boolean.TRUE and Boolean.FALSE. Default value: - * Boolean.FALSE. - *

- * - * @see org.apache.commons.imaging.formats.tiff.constants.TiffConstants - */ - public final static String PARAM_KEY_STRICT = "STRICT"; - - /** - * Parameter key. - * - * Only used when writing images. - *

- * Valid values: TiffOutputSet to write into the image's EXIF metadata. - *

- * - * @see org.apache.commons.imaging.formats.tiff.write.TiffOutputSet - */ - public final static String PARAM_KEY_EXIF = "EXIF"; - - /** - * Parameter key. - * - * Only used when writing images. - *

- * Valid values: String of XMP XML. - *

- */ - public final static String PARAM_KEY_XMP_XML = "XMP_XML"; - - /** - * Parameter key. Used in write operations to indicate the desired pixel - * density (DPI), and/or aspect ratio. - *

- * Valid values: PixelDensity - *

- * - * @see org.apache.commons.imaging.PixelDensity - */ - public final static String PARAM_KEY_PIXEL_DENSITY = "PIXEL_DENSITY"; - - private ImagingConstants() { - } -} diff --git a/src/main/java/org/apache/commons/imaging/ImagingParameters.java b/src/main/java/org/apache/commons/imaging/ImagingParameters.java new file mode 100644 index 000000000..91ece80fe --- /dev/null +++ b/src/main/java/org/apache/commons/imaging/ImagingParameters.java @@ -0,0 +1,310 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.imaging; + +import org.apache.commons.imaging.common.BufferedImageFactory; + +/** + * This class is a POJO holding data for parameters as requested in IMAGING-159. + * It holds data needed for all image formats. For data needed only by one + * particular format there are inherited classes. + *

+ * There are two kinds of parameters: with and without default value. For + * parameters without default value it implements lazy initialization: + *
+ * After getting an instance there is no value present. Accessing + * the value with getX() in this state will cause a RuntimeException. + * There is always a isXPresent() method for this parameter which returns + * {@code false} in this state. + *
+ * Once you provided a value using setX() you may access this value with getX(). + * The isXPresent() method will return {@code true} now. + *

+ * Other parameters have a default value. This is told in the javadoc for their + * getX() method. They don't have a isXPresent() method. You may access them any time. + */ +public class ImagingParameters { + + private boolean verbose; + + private boolean strict; + + private String fileNameHint; + + private String xmpXmlAsString; + + private ImageFormat imageFormat; + + private BufferedImageFactory bufferedImageFactory; + + private PixelDensity pixelDensity; + + /** + * This gives you a parameter object with default values. + */ + public ImagingParameters() { + this.verbose = false; + this.strict = false; + this.fileNameHint = null; + this.xmpXmlAsString = null; + this.imageFormat = null; + this.bufferedImageFactory = null; + this.pixelDensity = null; + } + + //****** verbose ****** + /** + * Tells if the verbose mode is turned on/off. + *

+ * Parameter applies to read and write operations. + * @return Valid values: {@code true} means {@literal "verbose mode enabled"} + * and {@code false} means {@literal "verbose mode disabled"} (default value). + */ + public boolean getVerbose() { + return this.verbose; + } + + /** + * Turns the verbose mode on. + * Parameter applies to read and write operations. + * @param value {@code true} = verbose mode on; {@code false} = verbose mode off + */ + public void setVerbose(final boolean value) { + this.verbose = value; + } + + //****** strict ****** + + /** + * Parameter indicates whether to throw exceptions when parsing invalid + * files, or whether to tolerate small problems. + * @return Valid values: {@code true} causes it to throw exceptions + * when parsing invalid files and {@code false} let it tolerate small problems + * (default value) + * @see org.apache.commons.imaging.formats.tiff.constants.TiffConstants + */ + public boolean getStrict() { + return this.strict; + } + + /** + * Parameter indicates whether to throw exceptions when parsing invalid + * files, or whether to tolerate small problems. + * This method switches the behavior so that it throws exceptions when + * parsing invalid files. + * @param value {@code true} = strict mode on; {@code false} = strict mode off + */ + public void setStrict(final boolean value) { + this.strict = value; + } + + //****** fileNameHint ****** + + /** + * Parameter used to hint the filename when reading from a byte array + * or InputStream. The filename hint can help disambiguate what file the + * image format. + *

+ * Applies to read operations. + * @return {@code true} if there is a value present, {@code false} else. + */ + public boolean isFileNameHintPresent() { + return this.fileNameHint != null; + } + + /** + * Parameter used to hint the filename when reading from a byte array + * or InputStream. The filename hint can help disambiguate what file the + * image format. + *

+ * Applies to read operations. + * @return Valid values: filename as string + * @see java.io.InputStream + */ + public String getFileNameHint() { + String value = this.fileNameHint; + checkIfParameterIsPresent(value); + return value; + } + + /** + * Parameter used to hint the filename when reading from a byte array + * or InputStream. The filename hint can help disambiguate what file the + * image format. + *

+ * Applies to read operations. + * @param value Valid values: filename as string + * @see java.io.InputStream + */ + public void setFileNameHint(final String value) { + checkIfValueIsNull(value, "fileNameHint"); + this.fileNameHint = value; + } + + //****** xmpXmlAsString ****** + + /** + * Parameter key. + * + * Only used when writing images. Valid values: String of XMP XML. + * @return {@code true} if there is a value present, {@code false} else. + */ + public boolean isXmpXmlAsStringPresent() { + return this.xmpXmlAsString != null; + } + + /** + * Parameter key. + * + * Only used when writing images. + * @return Valid values: String of XMP XML. + */ + public String getXmpXmlAsString() { + String value = this.xmpXmlAsString; + checkIfParameterIsPresent(value); + return value; + } + + /** + * Parameter key. + * + * Only used when writing images. + * @param value Valid values: String of XMP XML. + */ + public void setXmpXmlAsString(final String value) { + checkIfValueIsNull(value, "xmpXmlAsString"); + this.xmpXmlAsString = value; + } + + //****** imageFormat ****** + + /** + * Parameter used in write operations to indicate desired image format. + * @return {@code true} if there is a value present, {@code false} else. + */ + public boolean isImageFormatPresent() { + return this.imageFormat != null; + } + + /** + * Parameter used in write operations to indicate desired image format. + * @return Valid values: Any format defined in ImageFormat, such as + * ImageFormat.IMAGE_FORMAT_PNG. + */ + public ImageFormat getImageFormat() { + ImageFormat value = this.imageFormat; + checkIfParameterIsPresent(value); + return value; + } + + /** + * Parameter used in write operations to indicate desired image format. + * @param value Valid values: Any format defined in ImageFormat, such as + * ImageFormat.IMAGE_FORMAT_PNG. + */ + public void setImageFormat(final ImageFormat value) { + checkIfValueIsNull(value, "imageFormat"); + this.imageFormat = value; + } + + //****** bufferedImageFactory ****** + + /** + * + * @return {@code true} if there is a value present, {@code false} else. + */ + public boolean isBufferedImageFactoryPresent() { + return this.bufferedImageFactory != null; + } + + /** + * + * @return A BufferedImageFactory + */ + public BufferedImageFactory getBufferedImageFactory() { + BufferedImageFactory value = this.bufferedImageFactory; + checkIfParameterIsPresent(value); + return value; + } + + /** + * + * @param value A BufferedImageFactory + */ + public void setBufferedImageFactory(final BufferedImageFactory value) { + checkIfValueIsNull(value, "bufferedImageFactory"); + this.bufferedImageFactory = value; + } + + //****** pixelDensity ****** + + /** + * Parameter key. Used in write operations to indicate the desired pixel + * density (DPI), and/or aspect ratio. + * @return {@code true} if there is a value present, {@code false} else. + * @see org.apache.commons.imaging.PixelDensity + */ + public boolean isPixelDensityPresent() { + return this.pixelDensity != null; + } + + /** + * Parameter key. Used in write operations to indicate the desired pixel + * density (DPI), and/or aspect ratio. + * @return Valid values: PixelDensity + * @see org.apache.commons.imaging.PixelDensity + */ + public PixelDensity getPixelDensity() { + PixelDensity value = this.pixelDensity; + checkIfParameterIsPresent(value); + return value; + } + + /** + * Parameter key. Used in write operations to indicate the desired pixel + * density (DPI), and/or aspect ratio. + * @param value Valid values: PixelDensity + * @see org.apache.commons.imaging.PixelDensity + */ + public void setPixelDensity(final PixelDensity value) { + checkIfValueIsNull(value, "pixelDensity"); + this.pixelDensity = value; + } + + //****** check methods ****** + + /** + * Throws a RuntimeException if a given value is {code null}. + * @param value + */ + final void checkIfValueIsNull(final Object value, final String parameterName) { + if (value == null) { + throw new IllegalArgumentException("The value for the parameter " + parameterName + " must not null."); + } + } + + /** + * Throws a RuntimeException if the value for this parameter isn't set yet. + * @param value + */ + final void checkIfParameterIsPresent(final Object value) { + if (value == null) { + throw new IllegalStateException("You tried to get a value which is not present."); + } + } +} diff --git a/src/main/java/org/apache/commons/imaging/ImagingParametersJpeg.java b/src/main/java/org/apache/commons/imaging/ImagingParametersJpeg.java new file mode 100644 index 000000000..e6bcb99da --- /dev/null +++ b/src/main/java/org/apache/commons/imaging/ImagingParametersJpeg.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.imaging; + +/** + * This class is a POJO holding data for parameters as requested in IMAGING-159. + * It holds additional data needed for the JPEG/JFIF format only. + */ +public final class ImagingParametersJpeg extends ImagingParameters { + + private boolean readThumbnails; + + /** + * This gives you a parameter object with default values. + */ + public ImagingParametersJpeg() { + this.readThumbnails = false; + } + + //****** readThumbnails ****** + + /** + * Parameter key. Indicates whether to read embedded thumbnails. + *

+ * Only applies to read EXIF metadata from JPEG/JFIF files. + *

+ * Default value: {@code false} + * @return Valid values:{@code true} (causes it to read embedded thumbnails + * and {@code false} (don't read embedded thumbnails, default value). + */ + public boolean getReadThumbnails() { + return this.readThumbnails; + } + + /** + * Call this method to indicate to read embedded thumbnails. + *

+ * Only applies to read EXIF metadata from JPEG/JFIF files. + * @param value {@code true} = read embedded thumbnails; + * {@code false} = don't read embedded thumbnails + */ + public void setReadThumbnails(final boolean value) { + this.readThumbnails = value; + } +} diff --git a/src/main/java/org/apache/commons/imaging/ImagingParametersPcx.java b/src/main/java/org/apache/commons/imaging/ImagingParametersPcx.java new file mode 100644 index 000000000..66eaf75b7 --- /dev/null +++ b/src/main/java/org/apache/commons/imaging/ImagingParametersPcx.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.imaging; + +/** + * This class is a POJO holding data for parameters as requested in IMAGING-159. + * It holds additional data needed for the PCX format only. + */ +public final class ImagingParametersPcx extends ImagingParameters { + + private Integer compressionLevel; + private Integer bitDepth; + + /** + * This gives you a parameter object with default values. + */ + public ImagingParametersPcx() { + this.compressionLevel = null; + this.bitDepth = null; + } + + //****** compressionLevel ****** + + /** + * Returns {@code true} if the parameter compression level was set, {@code false} else. + * @return + */ + public boolean isCompressionLevelPresent() { + return this.compressionLevel != null; + } + + /** + * Parameter used in write operations to indicate desired compression + * algorithm. + *

+ * Currently only applies to writing PCX image files. + *

+ * Default value: PcxConstants.PCX_COMPRESSION_UNCOMPRESSED + * @return Valid values: + * PcxConstants.PCX_COMPRESSION_UNCOMPRESSED, + * PcxConstants.PCX_COMPRESSION_RLE + */ + public int getCompressionLevel() { + Integer value = this.compressionLevel; + checkIfParameterIsPresent(value); + return value; + } + + /** + * Parameter used in write operations to indicate desired compression + * algorithm. + *

+ * Currently only applies to writing PCX image files. + * @param value Valid values: + * PcxConstants.PCX_COMPRESSION_UNCOMPRESSED, + * PcxConstants.PCX_COMPRESSION_RLE + */ + public void setCompressionLevel(final int value) { + this.compressionLevel = value; + } + + //****** bitDepth ****** + + /** + * Returns {@code true} if the parameter bit depth was set, {@code false} else. + * @return + */ + public boolean isBitDepthPresent() { + return this.bitDepth != null; + } + + /** + * Returns a value for the bit depth of a PCX image. + * @return + */ + public int getBitDepth() { + Integer value = this.bitDepth; + checkIfParameterIsPresent(value); + return value; + } + + /** + * Sets the bit depth of a PCX image. + * @param value + */ + public void setBitDepth(final int value) { + this.bitDepth = value; + } +} diff --git a/src/main/java/org/apache/commons/imaging/ImagingParametersPng.java b/src/main/java/org/apache/commons/imaging/ImagingParametersPng.java new file mode 100644 index 000000000..89c1d444d --- /dev/null +++ b/src/main/java/org/apache/commons/imaging/ImagingParametersPng.java @@ -0,0 +1,142 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.imaging; + +import java.util.List; +import org.apache.commons.imaging.formats.png.PngText; + +/** + * This class is a POJO holding data for parameters as requested in IMAGING-159. + * It holds additional data needed for the PNG format only. + */ +public final class ImagingParametersPng extends ImagingParameters { + + private Byte bitDepth; + private boolean forceIndexedColor; + private boolean forceTrueColor; + private List textChunks; + + /** + * This gives you a parameter object with default values. + */ + public ImagingParametersPng() { + this.bitDepth = null; + this.forceIndexedColor = false; + this.forceTrueColor = false; + this.textChunks = null; + } + + //****** bitDepth ****** + + /** + * Returns {@code true} if the parameter bit depth was set, {@code false} else. + * @return + */ + public boolean isBitDepthPresent() { + return this.bitDepth != null; + } + + /** + * Returns the bit depth of a PNG image. + * @return the bit depth + */ + public byte getBitDepth() { + Byte value = this.bitDepth; + checkIfParameterIsPresent(value); + return value; + } + + /** + * Sets the bit depth of a PNG image. + * @param value the bit depth + */ + public void setBitDepth(final byte value) { + this.bitDepth = value; + } + + // ****** getForceIndexedColor ****** + + /** + * {@code true} = force indexed color; {@code false} = don't force indexed color + *

+ * Default value: {@code false} + * @return + */ + public boolean getForceIndexedColor() { + return this.forceIndexedColor; + } + + /** + * force indexed color + * @param value {@code true} = force indexed color; + * {@code false} = don't force indexed color + */ + public void setForceIndexedColor(final boolean value) { + this.forceIndexedColor = value; + } + + // ****** getForceTrueColor ****** + + /** + * {@code true} = force true color; {@code false} = don't force true color + *

+ * Default value: {@code false} + * @return + */ + public boolean getForceTrueColor() { + return this.forceTrueColor; + } + + /** + * force true color + * @param value {@code true} = force true color; + * {@code false} = don't force true color + */ + public void setForceTrueColor(final boolean value) { + this.forceTrueColor = value; + } + + //****** textChunks ****** + + /** + * Returns {@code true} if text chunks are present, {@code false} else. + * @return + */ + public boolean hasTextChunks() { + return this.textChunks != null; + } + + /** + * Returns the text chunks for a PNG image. + * @return the text chunks + */ + public List getTextChunks() { + List value = this.textChunks; + checkIfParameterIsPresent(value); + return value; + } + + /** + * Sets the text chunks for a PNG image. + * @param textChunks the text chunks + */ + public void setTextChunks(final List textChunks) { + checkIfValueIsNull(textChunks, "textChunks"); + this.textChunks = textChunks; + } +} diff --git a/src/main/java/org/apache/commons/imaging/ImagingParametersPnm.java b/src/main/java/org/apache/commons/imaging/ImagingParametersPnm.java new file mode 100644 index 000000000..17cf4a782 --- /dev/null +++ b/src/main/java/org/apache/commons/imaging/ImagingParametersPnm.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.imaging; + +/** + * This class is a POJO holding data for parameters as requested in IMAGING-159. + * It holds additional data needed for the PNM format only. + */ +public final class ImagingParametersPnm extends ImagingParameters { + + private boolean useRawbits; + + /** + * This gives you a parameter object with default values. + */ + public ImagingParametersPnm() { + this.useRawbits = true; + } + + // ****** getUseRawbits ****** + + /** + * {@code true} = use raw bits; {@code false} = don't use raw bits + *

+ * Default value: {@code false} + * @return + */ + public boolean getUseRawbits() { + return this.useRawbits; + } + + /** + * use raw bits + * @param value value {@code true} = use raw bits; + * {@code false} = don't use raw bits + */ + public void setUseRawbits(final boolean value) { + this.useRawbits = value; + } +} diff --git a/src/main/java/org/apache/commons/imaging/ImagingParametersTiff.java b/src/main/java/org/apache/commons/imaging/ImagingParametersTiff.java new file mode 100644 index 000000000..f9910596c --- /dev/null +++ b/src/main/java/org/apache/commons/imaging/ImagingParametersTiff.java @@ -0,0 +1,400 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.imaging; + +import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; + +/** + * This class is a POJO holding data for parameters as requested in IMAGING-159. + * It holds additional data needed for the TIFF format only. + */ +public final class ImagingParametersTiff extends ImagingParameters { + + private Integer compressionLevel; + + private Integer compressionBlockSize; + + private TiffOutputSet outputSetForMetaData; + + private boolean readThumbnails; + + private Integer t4options; + + private Integer t6options; + + private Integer subImageX; + + private Integer subImageY; + + private Integer subImageWidth; + + private Integer subImageHeight; + + + /** + * This gives you a parameter object with default values. + */ + public ImagingParametersTiff() { + this.compressionLevel = null; + this.compressionBlockSize = null; + this.outputSetForMetaData = null; + this.readThumbnails = false; + this.t4options = null; + this.t6options = null; + this.subImageX = null; + this.subImageY = null; + this.subImageWidth = null; + this.subImageHeight = null; + } + + //****** compressionLevel ****** + + /** + * Returns {@code true} if there is a value present, {@code false} else. + * @return + */ + public boolean isCompressionLevelPresent() { + return this.compressionLevel != null; + } + + /** + * Parameter used in write operations to indicate desired compression + * algorithm. + *

+ * Currently only applies to writing TIFF image files. + *

+ * Default value: TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED + * @return Valid values: + * TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED, + * TiffConstants.TIFF_COMPRESSION_CCITT_1D, + * TiffConstants.TIFF_COMPRESSION_LZW, + * TiffConstants.TIFF_COMPRESSION_PACKBITS + */ + public int getCompressionLevel() { + Integer value = this.compressionLevel; + checkIfParameterIsPresent(value); + return value; + } + + /** + * Parameter used in write operations to indicate desired compression + * algorithm. + *

+ * Currently only applies to writing TIFF image files. + * @param value Valid values: + * TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED, + * TiffConstants.TIFF_COMPRESSION_CCITT_1D, + * TiffConstants.TIFF_COMPRESSION_LZW, + * TiffConstants.TIFF_COMPRESSION_PACKBITS + */ + public void setCompressionLevel(final int value) { + this.compressionLevel = value; + } + + //****** compressionBlockSize ****** + + /** + * Returns {@code true} if there is a value present, {@code false} else. + * @return + */ + public boolean isCompressionBlockSizePresent() { + return this.compressionBlockSize != 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. + * @return the compression block size + */ + public int getCompressionBlockSize() { + Integer value = this.compressionBlockSize; + checkIfParameterIsPresent(value); + return value; + } + + /** + * 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. + * @param value the compression block size + */ + public void setCompressionBlockSize(final int value) { + this.compressionBlockSize = value; + } + + //****** tiffOutputSetForMetaData ****** + + /** + * Parameter key. + * + * Only used when writing images. + *

+ * Valid values: TiffOutputSet to write into the image's EXIF metadata. + * @return {@code true} if there is a value present, {@code false} else. + */ + public boolean isOutputSetPresent() { + return this.outputSetForMetaData != null; + } + + /** + * Parameter key. + * + * Only used when writing images. + * @return Valid values: TiffOutputSet to write into the image's EXIF metadata. + */ + public TiffOutputSet getOutputSet() { + TiffOutputSet value = this.outputSetForMetaData; + checkIfParameterIsPresent(value); + return value; + } + + /** + * Parameter key. + * + * Only used when writing images. + * @param value Valid values: TiffOutputSet to write into the image's EXIF metadata. + */ + public void setOutputSet(final TiffOutputSet value) { + checkIfValueIsNull(value, "outputSet"); + this.outputSetForMetaData = value; + } + + //****** readThumbnails ****** + + /** + * Parameter key. Indicates whether to read embedded thumbnails. + * Default value: don't read embedded thumbnails + * @return Valid values:{@code true} (causes it to read embedded thumbnails + * and {@code false} (don't read embedded thumbnails). + */ + public boolean getReadThumbnails() { + return this.readThumbnails; + } + + /** + * Call this method to indicate to read embedded thumbnails. + * @param value {@code true} = read embedded thumbnails; + * {@code false} = don't read embedded thumbnails + */ + public void setReadThumbnails(final boolean value) { + this.readThumbnails = value; + } + + //****** t4 options ****** + + /** + * Returns {@code true} if there is a value present, {@code false} else. + * @return + */ + public boolean isT4optionsPresent() { + return this.t4options != null; + } + + /** + * Used in write operations to indicate the desired + * T.4 options to use when using TIFF_COMPRESSION_CCITT_GROUP_3. + *

+ * Valid values: any Integer containing a mixture of the + * TIFF_FLAG_T4_OPTIONS_2D, TIFF_FLAG_T4_OPTIONS_UNCOMPRESSED_MODE, + * and TIFF_FLAG_T4_OPTIONS_FILL flags. + * @return desired t4 options + */ + public int getT4options() { + Integer value = this.t4options; + checkIfParameterIsPresent(value); + return value; + } + + /** + * Used in write operations to indicate the desired + * T.4 options to use when using TIFF_COMPRESSION_CCITT_GROUP_3. + *

+ * Valid values: any Integer containing a mixture of the + * TIFF_FLAG_T4_OPTIONS_2D, TIFF_FLAG_T4_OPTIONS_UNCOMPRESSED_MODE, + * and TIFF_FLAG_T4_OPTIONS_FILL flags. + * @param value desired t4 options + */ + public void setT4options(final int value) { + this.t4options = value; + } + + //****** t6 options ****** + + /** + * Returns {@code true} if there is a value present, {@code false} else. + * @return + */ + public boolean isT6optionsPresent() { + return this.t6options != null; + } + + /** + * Used in write operations to indicate the desired + * T.6 options to use when using TIFF_COMPRESSION_CCITT_GROUP_4. + *

+ * Valid values: any Integer containing either zero or + * TIFF_FLAG_T6_OPTIONS_UNCOMPRESSED_MODE. + * @return desired t6 options + */ + public int getT6options() { + Integer value = this.t6options; + checkIfParameterIsPresent(value); + return value; + } + + /** + * Used in write operations to indicate the desired + * T.6 options to use when using TIFF_COMPRESSION_CCITT_GROUP_4. + *

+ * Valid values: any Integer containing either zero or + * TIFF_FLAG_T6_OPTIONS_UNCOMPRESSED_MODE. + * @param value desired t6 options + */ + public void setT6options(final int value) { + this.t6options = value; + } + + //****** subImageX ****** + + /** + * Returns {@code true} if there is a value present, {@code false} else. + * @return + */ + public boolean isSubImageX_Present() { + return this.subImageX != null; + } + + /** + * Parameter used in read operations to indicate the X coordinate of the sub-image. + *

+ * Currently only applies to read TIFF image files. + * @return the x coordinate of the sub-image + */ + public int getSubImageX() { + Integer value = this.subImageX; + checkIfParameterIsPresent(value); + return value; + } + + /** + * Parameter used in read operations to indicate the X coordinate of the sub-image. + *

+ * Currently only applies to read TIFF image files. + * @param value the x coordinate of the sub-image + */ + public void setSubImageX(final int value) { + this.subImageX = value; + } + + //****** subImageY ****** + + /** + * Returns {@code true} if there is a value present, {@code false} else. + * @return + */ + public boolean isSubImageY_Present() { + return this.subImageY != null; + } + + /** + * Parameter used in read operations to indicate the Y coordinate of the sub-image. + *

+ * Currently only applies to read TIFF image files. + * @return the y coordinate of the sub-image + */ + public int getSubImageY() { + Integer value = this.subImageY; + checkIfParameterIsPresent(value); + return value; + } + + /** + * Parameter used in read operations to indicate the Y coordinate of the sub-image. + *

+ * Currently only applies to read TIFF image files. + * @param value the y coordinate of the sub-image + */ + public void setSubImageY(final int value) { + this.subImageY = value; + } + + //****** subImageWidth ****** + + /** + * Returns {@code true} if there is a value present, {@code false} else. + * @return + */ + public boolean isSubImageWidth_Present() { + return this.subImageWidth != null; + } + + /** + * Parameter used in read operations to indicate the width of the sub-image. + *

+ * Currently only applies to read TIFF image files. + * @return the width of the sub-image + */ + public int getSubImageWidth() { + Integer value = this.subImageWidth; + checkIfParameterIsPresent(value); + return value; + } + + /** + * Parameter used in read operations to indicate the width of the sub-image. + *

+ * Currently only applies to read TIFF image files. + * @param value the width of the sub-image + */ + public void setSubImageWidth(final int value) { + this.subImageWidth = value; + } + + //****** subImageHeight ****** + + /** + * Returns {@code true} if there is a value present, {@code false} else. + * @return + */ + public boolean isSubImageHeight_Present() { + return this.subImageHeight != null; + } + + /** + * Parameter used in read operations to indicate the height of the sub-image. + *

+ * Currently only applies to read TIFF image files. + * @return the height of the sub-image + */ + public int getSubImageHeight() { + Integer value = this.subImageHeight; + checkIfParameterIsPresent(value); + return value; + } + + /** + * Parameter used in read operations to indicate the height of the sub-image. + *

+ * Currently only applies to read TIFF image files. + * @param value the height of the sub-image + */ + public void setSubImageHeight(final int value) { + this.subImageHeight = value; + } +} diff --git a/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java b/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java index 79ec0d93b..6091e9b77 100644 --- a/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java +++ b/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java @@ -25,9 +25,7 @@ import java.io.PrintWriter; import java.nio.ByteOrder; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.FormatCompliance; import org.apache.commons.imaging.ImageFormat; @@ -36,6 +34,7 @@ import org.apache.commons.imaging.ImageParser; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.PixelDensity; import org.apache.commons.imaging.common.BinaryOutputStream; import org.apache.commons.imaging.common.ImageMetadata; @@ -45,7 +44,6 @@ import org.apache.commons.imaging.palette.SimplePalette; import org.apache.commons.imaging.util.IoUtils; -import static org.apache.commons.imaging.ImagingConstants.*; import static org.apache.commons.imaging.common.BinaryFunctions.*; public class BmpImageParser extends ImageParser { @@ -486,27 +484,17 @@ private BmpHeaderInfo readBmpHeaderInfo(final ByteSource byteSource, } @Override - public byte[] getICCProfileBytes(final ByteSource byteSource, final Map params) + public byte[] getICCProfileBytes(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } @Override - public Dimension getImageSize(final ByteSource byteSource, Map params) + public Dimension getImageSize(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { - // make copy of params; we'll clear keys as we consume them. - params = (params == null) ? new HashMap() : new HashMap(params); - - final boolean verbose = Boolean.TRUE.equals(params.get(PARAM_KEY_VERBOSE)); - - if (params.containsKey(PARAM_KEY_VERBOSE)) { - params.remove(PARAM_KEY_VERBOSE); - } - - if (!params.isEmpty()) { - final Object firstKey = params.keySet().iterator().next(); - throw new ImageReadException("Unknown parameter: " + firstKey); - } + // ensure that the parameter object is not null + final ImagingParameters parameters = (params == null) ? new ImagingParameters() : params; + final boolean verbose = parameters.getVerbose(); final BmpHeaderInfo bhi = readBmpHeaderInfo(byteSource, verbose); @@ -519,7 +507,7 @@ public Dimension getImageSize(final ByteSource byteSource, Map p } @Override - public ImageMetadata getMetadata(final ByteSource byteSource, final Map params) + public ImageMetadata getMetadata(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { // TODO this should throw UnsupportedOperationException, but RoundtripTest has to be refactored completely before this can be changed return null; @@ -549,21 +537,13 @@ private String getBmpTypeDescription(final int identifier1, final int identifier } @Override - public ImageInfo getImageInfo(final ByteSource byteSource, Map params) + public ImageInfo getImageInfo(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { - // make copy of params; we'll clear keys as we consume them. - params = (params == null) ? new HashMap() : new HashMap(params); - - final boolean verbose = Boolean.TRUE.equals(params.get(PARAM_KEY_VERBOSE)); - - if (params.containsKey(PARAM_KEY_VERBOSE)) { - params.remove(PARAM_KEY_VERBOSE); - } - - if (!params.isEmpty()) { - final Object firstKey = params.keySet().iterator().next(); - throw new ImageReadException("Unknown parameter: " + firstKey); - } + + // ensure that the parameter object is not null + final ImagingParameters parameters = (params == null) ? new ImagingParameters() : params; + + final boolean verbose = parameters.getVerbose(); InputStream is = null; ImageContents ic = null; @@ -663,7 +643,7 @@ public FormatCompliance getFormatCompliance(final ByteSource byteSource) } @Override - public BufferedImage getBufferedImage(final ByteSource byteSource, final Map params) + public BufferedImage getBufferedImage(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { InputStream is = null; boolean canThrow = false; @@ -677,25 +657,14 @@ public BufferedImage getBufferedImage(final ByteSource byteSource, final Map params) + public BufferedImage getBufferedImage(final InputStream inputStream, final ImagingParameters params) throws ImageReadException, IOException { - // make copy of params; we'll clear keys as we consume them. - params = (params == null) ? new HashMap() : new HashMap(params); - - final boolean verbose = Boolean.TRUE.equals(params.get(PARAM_KEY_VERBOSE)); - - if (params.containsKey(PARAM_KEY_VERBOSE)) { - params.remove(PARAM_KEY_VERBOSE); - } - if (params.containsKey(BUFFERED_IMAGE_FACTORY)) { - params.remove(BUFFERED_IMAGE_FACTORY); - } - - if (!params.isEmpty()) { - final Object firstKey = params.keySet().iterator().next(); - throw new ImageReadException("Unknown parameter: " + firstKey); - } - + + // ensure that the parameter object is not null + final ImagingParameters parameters = (params == null) ? new ImagingParameters() : params; + + final boolean verbose = parameters.getVerbose(); + final ImageContents ic = readImageContents(inputStream, FormatCompliance.getDefault(), verbose); if (ic == null) { @@ -725,26 +694,13 @@ public BufferedImage getBufferedImage(final InputStream inputStream, Map params) + public void writeImage(final BufferedImage src, final OutputStream os, final ImagingParameters params) throws ImageWriteException, IOException { - // make copy of params; we'll clear keys as we consume them. - params = (params == null) ? new HashMap() : new HashMap(params); - - PixelDensity pixelDensity = null; - - // clear format key. - if (params.containsKey(PARAM_KEY_FORMAT)) { - params.remove(PARAM_KEY_FORMAT); - } - if (params.containsKey(PARAM_KEY_PIXEL_DENSITY)) { - pixelDensity = (PixelDensity) params - .remove(PARAM_KEY_PIXEL_DENSITY); - } - if (!params.isEmpty()) { - final Object firstKey = params.keySet().iterator().next(); - throw new ImageWriteException("Unknown parameter: " + firstKey); - } + // ensure that the parameter object is not null + final ImagingParameters parameters = (params == null) ? new ImagingParameters() : params; + final PixelDensity pixelDensity = (parameters.isPixelDensityPresent()) ? parameters.getPixelDensity() : null; + final SimplePalette palette = new PaletteFactory().makeExactRgbPaletteSimple( src, 256); @@ -811,11 +767,12 @@ public void writeImage(final BufferedImage src, final OutputStream os, Map params) + public String getXmpXml(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } - } diff --git a/src/main/java/org/apache/commons/imaging/formats/dcx/DcxImageParser.java b/src/main/java/org/apache/commons/imaging/formats/dcx/DcxImageParser.java index 39d1ed078..ff5e9b7db 100644 --- a/src/main/java/org/apache/commons/imaging/formats/dcx/DcxImageParser.java +++ b/src/main/java/org/apache/commons/imaging/formats/dcx/DcxImageParser.java @@ -24,9 +24,7 @@ import java.io.PrintWriter; import java.nio.ByteOrder; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.ImageFormat; import org.apache.commons.imaging.ImageFormats; @@ -34,16 +32,14 @@ import org.apache.commons.imaging.ImageParser; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; -import org.apache.commons.imaging.PixelDensity; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.BinaryOutputStream; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.common.bytesource.ByteSource; import org.apache.commons.imaging.common.bytesource.ByteSourceInputStream; -import org.apache.commons.imaging.formats.pcx.PcxConstants; import org.apache.commons.imaging.formats.pcx.PcxImageParser; import org.apache.commons.imaging.util.IoUtils; -import static org.apache.commons.imaging.ImagingConstants.*; import static org.apache.commons.imaging.common.BinaryFunctions.*; public class DcxImageParser extends ImageParser { @@ -79,28 +75,28 @@ protected ImageFormat[] getAcceptedTypes() { // FIXME should throw UOE @Override - public ImageMetadata getMetadata(final ByteSource byteSource, final Map params) + public ImageMetadata getMetadata(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } // FIXME should throw UOE @Override - public ImageInfo getImageInfo(final ByteSource byteSource, final Map params) + public ImageInfo getImageInfo(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } // FIXME should throw UOE @Override - public Dimension getImageSize(final ByteSource byteSource, final Map params) + public Dimension getImageSize(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } // FIXME should throw UOE @Override - public byte[] getICCProfileBytes(final ByteSource byteSource, final Map params) + public byte[] getICCProfileBytes(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } @@ -173,7 +169,7 @@ public boolean dumpImageFile(final PrintWriter pw, final ByteSource byteSource) @Override public final BufferedImage getBufferedImage(final ByteSource byteSource, - final Map params) throws ImageReadException, IOException { + final ImagingParameters params) throws ImageReadException, IOException { final List list = getAllBufferedImages(byteSource); if (list.isEmpty()) { return null; @@ -195,7 +191,7 @@ public List getAllBufferedImages(final ByteSource byteSource) final ByteSourceInputStream pcxSource = new ByteSourceInputStream( stream, null); final BufferedImage image = pcxImageParser.getBufferedImage( - pcxSource, new HashMap()); + pcxSource, new ImagingParameters()); images.add(image); canThrow = true; } finally { @@ -206,40 +202,11 @@ public List getAllBufferedImages(final ByteSource byteSource) } @Override - public void writeImage(final BufferedImage src, final OutputStream os, Map params) + public void writeImage(final BufferedImage src, final OutputStream os, final ImagingParameters params) throws ImageWriteException, IOException { - // make copy of params; we'll clear keys as we consume them. - params = (params == null) ? new HashMap() : new HashMap(params); - - final HashMap pcxParams = new HashMap(); - - // clear format key. - if (params.containsKey(PARAM_KEY_FORMAT)) { - params.remove(PARAM_KEY_FORMAT); - } - - if (params.containsKey(PcxConstants.PARAM_KEY_PCX_COMPRESSION)) { - final Object value = params - .remove(PcxConstants.PARAM_KEY_PCX_COMPRESSION); - pcxParams.put(PcxConstants.PARAM_KEY_PCX_COMPRESSION, value); - } - if (params.containsKey(PARAM_KEY_PIXEL_DENSITY)) { - final Object value = params.remove(PARAM_KEY_PIXEL_DENSITY); - if (value != null) { - if (!(value instanceof PixelDensity)) { - throw new ImageWriteException( - "Invalid pixel density parameter"); - } - pcxParams.put(PARAM_KEY_PIXEL_DENSITY, value); - } - } - - - if (!params.isEmpty()) { - final Object firstKey = params.keySet().iterator().next(); - throw new ImageWriteException("Unknown parameter: " + firstKey); - } + // ensure that the parameter object is not null + final ImagingParameters pcxParams = (params == null) ? new ImagingParameters() : params; final int headerSize = 4 + 1024 * 4; @@ -264,9 +231,11 @@ public void writeImage(final BufferedImage src, final OutputStream os, Map params) + public String getXmpXml(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } diff --git a/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java b/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java index 4bfdde388..85d3aab82 100644 --- a/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java +++ b/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java @@ -26,9 +26,7 @@ import java.io.UnsupportedEncodingException; import java.nio.ByteOrder; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.FormatCompliance; import org.apache.commons.imaging.ImageFormat; @@ -37,6 +35,7 @@ import org.apache.commons.imaging.ImageParser; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.BinaryOutputStream; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.common.ImageBuilder; @@ -47,7 +46,6 @@ import org.apache.commons.imaging.palette.PaletteFactory; import org.apache.commons.imaging.util.IoUtils; -import static org.apache.commons.imaging.ImagingConstants.*; import static org.apache.commons.imaging.common.BinaryFunctions.*; public class GifImageParser extends ImageParser { @@ -465,13 +463,13 @@ private ImageContents readFile(final ByteSource byteSource, } @Override - public byte[] getICCProfileBytes(final ByteSource byteSource, final Map params) + public byte[] getICCProfileBytes(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } @Override - public Dimension getImageSize(final ByteSource byteSource, final Map params) + public Dimension getImageSize(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final ImageContents blocks = readFile(byteSource, false); @@ -498,7 +496,7 @@ public Dimension getImageSize(final ByteSource byteSource, final Map params) + public ImageMetadata getMetadata(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } @@ -518,7 +516,7 @@ private List getComments(final List blocks) throws IOException } @Override - public ImageInfo getImageInfo(final ByteSource byteSource, final Map params) + public ImageInfo getImageInfo(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final ImageContents blocks = readFile(byteSource, false); @@ -642,7 +640,7 @@ public FormatCompliance getFormatCompliance(final ByteSource byteSource) } @Override - public BufferedImage getBufferedImage(final ByteSource byteSource, final Map params) + public BufferedImage getBufferedImage(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final ImageContents imageContents = readFile(byteSource, false); @@ -755,32 +753,15 @@ private void writeAsSubBlocks(final OutputStream os, final byte[] bytes) throws } @Override - public void writeImage(final BufferedImage src, final OutputStream os, Map params) + public void writeImage(final BufferedImage src, final OutputStream os, final ImagingParameters params) throws ImageWriteException, IOException { - // make copy of params; we'll clear keys as we consume them. - params = new HashMap(params); - - final boolean verbose = Boolean.TRUE.equals(params.get(PARAM_KEY_VERBOSE)); - - // clear format key. - if (params.containsKey(PARAM_KEY_FORMAT)) { - params.remove(PARAM_KEY_FORMAT); - } - if (params.containsKey(PARAM_KEY_VERBOSE)) { - params.remove(PARAM_KEY_VERBOSE); - } - - String xmpXml = null; - if (params.containsKey(PARAM_KEY_XMP_XML)) { - xmpXml = (String) params.get(PARAM_KEY_XMP_XML); - params.remove(PARAM_KEY_XMP_XML); - } - - if (!params.isEmpty()) { - final Object firstKey = params.keySet().iterator().next(); - throw new ImageWriteException("Unknown parameter: " + firstKey); - } + + // ensure that the parameter object is not null + final ImagingParameters parameters = (params == null) ? new ImagingParameters() : params; + final boolean verbose = parameters.getVerbose(); + final String xmpXml = (parameters.isXmpXmlAsStringPresent()) ? parameters.getXmpXmlAsString(): null; + final int width = src.getWidth(); final int height = src.getHeight(); @@ -1011,9 +992,11 @@ public void writeImage(final BufferedImage src, final OutputStream os, Map params) + public String getXmpXml(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { InputStream is = null; diff --git a/src/main/java/org/apache/commons/imaging/formats/icns/IcnsImageParser.java b/src/main/java/org/apache/commons/imaging/formats/icns/IcnsImageParser.java index 4a0a9223c..56780d4e1 100644 --- a/src/main/java/org/apache/commons/imaging/formats/icns/IcnsImageParser.java +++ b/src/main/java/org/apache/commons/imaging/formats/icns/IcnsImageParser.java @@ -24,9 +24,7 @@ import java.io.PrintWriter; import java.nio.ByteOrder; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.ImageFormat; import org.apache.commons.imaging.ImageFormats; @@ -34,12 +32,12 @@ import org.apache.commons.imaging.ImageParser; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.BinaryOutputStream; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.common.bytesource.ByteSource; import org.apache.commons.imaging.util.IoUtils; -import static org.apache.commons.imaging.ImagingConstants.*; import static org.apache.commons.imaging.common.BinaryFunctions.*; public class IcnsImageParser extends ImageParser { @@ -73,25 +71,14 @@ protected ImageFormat[] getAcceptedTypes() { // FIXME should throw UOE @Override - public ImageMetadata getMetadata(final ByteSource byteSource, final Map params) + public ImageMetadata getMetadata(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } @Override - public ImageInfo getImageInfo(final ByteSource byteSource, Map params) + public ImageInfo getImageInfo(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { - // make copy of params; we'll clear keys as we consume them. - params = (params == null) ? new HashMap() : new HashMap(params); - - if (params.containsKey(PARAM_KEY_VERBOSE)) { - params.remove(PARAM_KEY_VERBOSE); - } - - if (!params.isEmpty()) { - final Object firstKey = params.keySet().iterator().next(); - throw new ImageReadException("Unknown parameter: " + firstKey); - } final IcnsContents contents = readImage(byteSource); final List images = IcnsDecoder @@ -109,20 +96,9 @@ public ImageInfo getImageInfo(final ByteSource byteSource, Map p } @Override - public Dimension getImageSize(final ByteSource byteSource, Map params) + public Dimension getImageSize(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { - // make copy of params; we'll clear keys as we consume them. - params = (params == null) ? new HashMap() : new HashMap(params); - - if (params.containsKey(PARAM_KEY_VERBOSE)) { - params.remove(PARAM_KEY_VERBOSE); - } - - if (!params.isEmpty()) { - final Object firstKey = params.keySet().iterator().next(); - throw new ImageReadException("Unknown parameter: " + firstKey); - } - + final IcnsContents contents = readImage(byteSource); final List images = IcnsDecoder .decodeAllImages(contents.icnsElements); @@ -134,7 +110,7 @@ public Dimension getImageSize(final ByteSource byteSource, Map p } @Override - public byte[] getICCProfileBytes(final ByteSource byteSource, final Map params) + public byte[] getICCProfileBytes(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } @@ -267,7 +243,7 @@ public boolean dumpImageFile(final PrintWriter pw, final ByteSource byteSource) @Override public final BufferedImage getBufferedImage(final ByteSource byteSource, - final Map params) throws ImageReadException, IOException { + final ImagingParameters params) throws ImageReadException, IOException { final IcnsContents icnsContents = readImage(byteSource); final List result = IcnsDecoder .decodeAllImages(icnsContents.icnsElements); @@ -285,20 +261,8 @@ public List getAllBufferedImages(final ByteSource byteSource) } @Override - public void writeImage(final BufferedImage src, final OutputStream os, Map params) + public void writeImage(final BufferedImage src, final OutputStream os, final ImagingParameters params) throws ImageWriteException, IOException { - // make copy of params; we'll clear keys as we consume them. - params = (params == null) ? new HashMap() : new HashMap(params); - - // clear format key. - if (params.containsKey(PARAM_KEY_FORMAT)) { - params.remove(PARAM_KEY_FORMAT); - } - - if (!params.isEmpty()) { - final Object firstKey = params.keySet().iterator().next(); - throw new ImageWriteException("Unknown parameter: " + firstKey); - } IcnsType imageType; if (src.getWidth() == 16 && src.getHeight() == 16) { @@ -355,9 +319,11 @@ public void writeImage(final BufferedImage src, final OutputStream os, Map params) + public String getXmpXml(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } diff --git a/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java b/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java index 8e2f74289..b2812e103 100644 --- a/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java +++ b/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java @@ -26,9 +26,7 @@ import java.io.PrintWriter; import java.nio.ByteOrder; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.ImageFormat; import org.apache.commons.imaging.ImageFormats; @@ -37,6 +35,7 @@ import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.PixelDensity; import org.apache.commons.imaging.common.BinaryOutputStream; import org.apache.commons.imaging.common.ImageMetadata; @@ -46,7 +45,6 @@ import org.apache.commons.imaging.palette.SimplePalette; import org.apache.commons.imaging.util.IoUtils; -import static org.apache.commons.imaging.ImagingConstants.*; import static org.apache.commons.imaging.common.BinaryFunctions.*; public class IcoImageParser extends ImageParser { @@ -80,28 +78,28 @@ protected ImageFormat[] getAcceptedTypes() { // TODO should throw UOE @Override - public ImageMetadata getMetadata(final ByteSource byteSource, final Map params) + public ImageMetadata getMetadata(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } // TODO should throw UOE @Override - public ImageInfo getImageInfo(final ByteSource byteSource, final Map params) + public ImageInfo getImageInfo(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } // TODO should throw UOE @Override - public Dimension getImageSize(final ByteSource byteSource, final Map params) + public Dimension getImageSize(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } // TODO should throw UOE @Override - public byte[] getICCProfileBytes(final ByteSource byteSource, final Map params) + public byte[] getICCProfileBytes(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } @@ -586,7 +584,7 @@ public boolean dumpImageFile(final PrintWriter pw, final ByteSource byteSource) @Override public final BufferedImage getBufferedImage(final ByteSource byteSource, - final Map params) throws ImageReadException, IOException { + final ImagingParameters params) throws ImageReadException, IOException { final ImageContents contents = readImage(byteSource); final FileHeader fileHeader = contents.fileHeader; if (fileHeader.iconCount > 0) { @@ -638,22 +636,13 @@ public List getAllBufferedImages(final ByteSource byteSource) // } @Override - public void writeImage(final BufferedImage src, final OutputStream os, Map params) + public void writeImage(final BufferedImage src, final OutputStream os, final ImagingParameters params) throws ImageWriteException, IOException { - // make copy of params; we'll clear keys as we consume them. - params = (params == null) ? new HashMap() : new HashMap(params); - - // clear format key. - if (params.containsKey(PARAM_KEY_FORMAT)) { - params.remove(PARAM_KEY_FORMAT); - } - final PixelDensity pixelDensity = (PixelDensity) params.remove(PARAM_KEY_PIXEL_DENSITY); - - if (!params.isEmpty()) { - final Object firstKey = params.keySet().iterator().next(); - throw new ImageWriteException("Unknown parameter: " + firstKey); - } + // ensure that the parameter object is not null + final ImagingParameters parameters = (params == null) ? new ImagingParameters() : params; + + final PixelDensity pixelDensity = (parameters.isPixelDensityPresent()) ? parameters.getPixelDensity(): null; final PaletteFactory paletteFactory = new PaletteFactory(); final SimplePalette palette = paletteFactory @@ -826,9 +815,11 @@ public void writeImage(final BufferedImage src, final OutputStream os, Map params) + public String getXmpXml(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } diff --git a/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageParser.java b/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageParser.java index a3bd557e2..7629096a9 100644 --- a/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageParser.java +++ b/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageParser.java @@ -26,15 +26,15 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.ImageFormat; import org.apache.commons.imaging.ImageFormats; import org.apache.commons.imaging.ImageInfo; import org.apache.commons.imaging.ImageParser; import org.apache.commons.imaging.ImageReadException; +import org.apache.commons.imaging.ImagingParameters; +import org.apache.commons.imaging.ImagingParametersJpeg; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.common.bytesource.ByteSource; import org.apache.commons.imaging.formats.jpeg.decoder.JpegDecoder; @@ -57,7 +57,6 @@ import org.apache.commons.imaging.formats.tiff.constants.TiffTagConstants; import org.apache.commons.imaging.util.Debug; -import static org.apache.commons.imaging.ImagingConstants.*; import static org.apache.commons.imaging.common.BinaryFunctions.*; public class JpegImageParser extends ImageParser { @@ -93,7 +92,7 @@ protected String[] getAcceptedExtensions() { @Override public final BufferedImage getBufferedImage(final ByteSource byteSource, - final Map params) throws ImageReadException, IOException { + final ImagingParameters params) throws ImageReadException, IOException { final JpegDecoder jpegDecoder = new JpegDecoder(); return jpegDecoder.decode(byteSource); } @@ -273,7 +272,7 @@ public List readSegments(final ByteSource byteSource, final int[] marke } @Override - public byte[] getICCProfileBytes(final ByteSource byteSource, final Map params) + public byte[] getICCProfileBytes(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final List segments = readSegments(byteSource, new int[] { JpegConstants.JPEG_APP2_MARKER, }, false); @@ -307,7 +306,7 @@ public byte[] getICCProfileBytes(final ByteSource byteSource, final Map params) + public ImageMetadata getMetadata(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final TiffImageMetadata exif = getExifMetadata(byteSource, params); @@ -338,22 +337,27 @@ private List filterAPP1Segments(final List segments) { return result; } - public TiffImageMetadata getExifMetadata(final ByteSource byteSource, Map params) + public TiffImageMetadata getExifMetadata(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final byte[] bytes = getExifRawData(byteSource); if (null == bytes) { return null; } - + + // if no parameters were given we assume that thumbnails should be read + // to transport this decision we need a parameter object specific for JPEGs + final ImagingParameters parameters; if (params == null) { - params = new HashMap(); + ImagingParametersJpeg jpegParameters; + jpegParameters = new ImagingParametersJpeg(); + jpegParameters.setReadThumbnails(true); + parameters = jpegParameters; } - if (!params.containsKey(PARAM_KEY_READ_THUMBNAILS)) { - params.put(PARAM_KEY_READ_THUMBNAILS, Boolean.TRUE); + else { + parameters = params; } - return (TiffImageMetadata) new TiffImageParser().getMetadata(bytes, - params); + return (TiffImageMetadata) new TiffImageParser().getMetadata(bytes, parameters); } public byte[] getExifRawData(final ByteSource byteSource) @@ -519,9 +523,11 @@ public boolean visitSegment(final int marker, final byte[] markerBytes, * @param params * Map of optional parameters, defined in ImagingConstants. * @return Xmp Xml as String, if present. Otherwise, returns null. + * @throws org.apache.commons.imaging.ImageReadException + * @throws java.io.IOException */ @Override - public String getXmpXml(final ByteSource byteSource, final Map params) + public String getXmpXml(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final List result = new ArrayList(); @@ -569,7 +575,7 @@ public boolean visitSegment(final int marker, final byte[] markerBytes, } public JpegPhotoshopMetadata getPhotoshopMetadata(final ByteSource byteSource, - final Map params) throws ImageReadException, IOException { + final ImagingParameters params) throws ImageReadException, IOException { final List segments = readSegments(byteSource, new int[] { JpegConstants.JPEG_APP13_MARKER, }, false); @@ -598,7 +604,7 @@ public JpegPhotoshopMetadata getPhotoshopMetadata(final ByteSource byteSource, } @Override - public Dimension getImageSize(final ByteSource byteSource, final Map params) + public Dimension getImageSize(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final List segments = readSegments(byteSource, new int[] { // kJFIFMarker, @@ -632,7 +638,7 @@ public Dimension getImageSize(final ByteSource byteSource, final Map params) + public ImageInfo getImageInfo(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { // List allSegments = readSegments(byteSource, null, false); 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 17698a067..3995a8320 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 @@ -26,11 +26,10 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; -import org.apache.commons.imaging.ImagingConstants; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.BinaryFileParser; import org.apache.commons.imaging.common.BinaryOutputStream; import org.apache.commons.imaging.common.ByteConversions; @@ -95,10 +94,14 @@ public boolean isPhotoshopJpegSegment(final byte[] segmentData) { * Some IPTC blocks are missing this first "record version" record, so we * don't require it. */ - public PhotoshopApp13Data parsePhotoshopSegment(final byte[] bytes, final Map params) + public PhotoshopApp13Data parsePhotoshopSegment(final byte[] bytes, final ImagingParameters params) throws ImageReadException, IOException { - final boolean strict = params != null && Boolean.TRUE.equals(params.get(ImagingConstants.PARAM_KEY_STRICT)); - final boolean verbose = params != null && Boolean.TRUE.equals(params.get(ImagingConstants.PARAM_KEY_VERBOSE)); + + // ensure that the parameter object is not null + final ImagingParameters parameters = (params == null) ? new ImagingParameters() : params; + + final boolean strict = parameters.getStrict(); + final boolean verbose = parameters.getVerbose(); return parsePhotoshopSegment(bytes, verbose, strict); } diff --git a/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/JpegIptcRewriter.java b/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/JpegIptcRewriter.java index 78c3dc47a..d3adbbc64 100644 --- a/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/JpegIptcRewriter.java +++ b/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/JpegIptcRewriter.java @@ -22,12 +22,11 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.bytesource.ByteSource; import org.apache.commons.imaging.common.bytesource.ByteSourceArray; import org.apache.commons.imaging.common.bytesource.ByteSourceFile; @@ -50,6 +49,9 @@ public class JpegIptcRewriter extends JpegRewriter { * Image file. * @param os * OutputStream to write the image to. + * @throws org.apache.commons.imaging.ImageReadException + * @throws java.io.IOException + * @throws org.apache.commons.imaging.ImageWriteException * * @see java.io.File * @see java.io.OutputStream @@ -70,6 +72,9 @@ public void removeIPTC(final File src, final OutputStream os) * Byte array containing Jpeg image data. * @param os * OutputStream to write the image to. + * @throws org.apache.commons.imaging.ImageReadException + * @throws java.io.IOException + * @throws org.apache.commons.imaging.ImageWriteException */ public void removeIPTC(final byte[] src, final OutputStream os) throws ImageReadException, IOException, ImageWriteException { @@ -87,6 +92,9 @@ public void removeIPTC(final byte[] src, final OutputStream os) * InputStream containing Jpeg image data. * @param os * OutputStream to write the image to. + * @throws org.apache.commons.imaging.ImageReadException + * @throws java.io.IOException + * @throws org.apache.commons.imaging.ImageWriteException */ public void removeIPTC(final InputStream src, final OutputStream os) throws ImageReadException, IOException, ImageWriteException { @@ -104,6 +112,9 @@ public void removeIPTC(final InputStream src, final OutputStream os) * ByteSource containing Jpeg image data. * @param os * OutputStream to write the image to. + * @throws org.apache.commons.imaging.ImageReadException + * @throws java.io.IOException + * @throws org.apache.commons.imaging.ImageWriteException */ public void removeIPTC(final ByteSource byteSource, final OutputStream os) throws ImageReadException, IOException, ImageWriteException { @@ -119,7 +130,7 @@ public void removeIPTC(final ByteSource byteSource, final OutputStream os) if (photoshopApp13Segments.size() == 1) { final JFIFPieceSegment oldSegment = (JFIFPieceSegment) photoshopApp13Segments .get(0); - final Map params = new HashMap(); + final ImagingParameters params = new ImagingParameters(); final PhotoshopApp13Data oldData = new IptcParser() .parsePhotoshopSegment(oldSegment.segmentData, params); final List newBlocks = oldData.getNonIptcBlocks(); @@ -146,6 +157,9 @@ public void removeIPTC(final ByteSource byteSource, final OutputStream os) * OutputStream to write the image to. * @param newData * structure containing IPTC data. + * @throws org.apache.commons.imaging.ImageReadException + * @throws java.io.IOException + * @throws org.apache.commons.imaging.ImageWriteException */ public void writeIPTC(final byte[] src, final OutputStream os, final PhotoshopApp13Data newData) throws ImageReadException, IOException, @@ -165,6 +179,9 @@ public void writeIPTC(final byte[] src, final OutputStream os, * OutputStream to write the image to. * @param newData * structure containing IPTC data. + * @throws org.apache.commons.imaging.ImageReadException + * @throws java.io.IOException + * @throws org.apache.commons.imaging.ImageWriteException */ public void writeIPTC(final InputStream src, final OutputStream os, final PhotoshopApp13Data newData) throws ImageReadException, IOException, @@ -184,6 +201,9 @@ public void writeIPTC(final InputStream src, final OutputStream os, * OutputStream to write the image to. * @param newData * structure containing IPTC data. + * @throws org.apache.commons.imaging.ImageReadException + * @throws java.io.IOException + * @throws org.apache.commons.imaging.ImageWriteException */ public void writeIPTC(final File src, final OutputStream os, final PhotoshopApp13Data newData) throws ImageReadException, IOException, ImageWriteException { @@ -202,6 +222,9 @@ public void writeIPTC(final File src, final OutputStream os, final PhotoshopApp1 * OutputStream to write the image to. * @param newData * structure containing IPTC data. + * @throws org.apache.commons.imaging.ImageReadException + * @throws java.io.IOException + * @throws org.apache.commons.imaging.ImageWriteException */ public void writeIPTC(final ByteSource byteSource, final OutputStream os, PhotoshopApp13Data newData) throws ImageReadException, IOException, 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 18c63f401..bbb27c85c 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 @@ -19,9 +19,9 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.util.Map; import org.apache.commons.imaging.ImageReadException; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.formats.jpeg.JpegImageParser; import org.apache.commons.imaging.formats.jpeg.iptc.IptcParser; import org.apache.commons.imaging.formats.jpeg.iptc.PhotoshopApp13Data; @@ -62,7 +62,7 @@ public boolean isPhotoshopJpegSegment() { return new IptcParser().isPhotoshopJpegSegment(getSegmentData()); } - public PhotoshopApp13Data parsePhotoshopSegment(final Map params) + public PhotoshopApp13Data parsePhotoshopSegment(final ImagingParameters params) throws ImageReadException, IOException { /* * In practice, App13 segments are only used for Photoshop/IPTC diff --git a/src/main/java/org/apache/commons/imaging/formats/pcx/PcxConstants.java b/src/main/java/org/apache/commons/imaging/formats/pcx/PcxConstants.java index 864123a83..afb45d9ab 100644 --- a/src/main/java/org/apache/commons/imaging/formats/pcx/PcxConstants.java +++ b/src/main/java/org/apache/commons/imaging/formats/pcx/PcxConstants.java @@ -10,18 +10,14 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * under the License. */ package org.apache.commons.imaging.formats.pcx; public final class PcxConstants { - public static final String PARAM_KEY_PCX_COMPRESSION = "PCX_COMPRESSION"; public static final int PCX_COMPRESSION_UNCOMPRESSED = 0; public static final int PCX_COMPRESSION_RLE = 1; - public static final String PARAM_KEY_PCX_BIT_DEPTH = "PCX_BIT_DEPTH"; - private PcxConstants() { } } diff --git a/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java b/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java index c605eef81..788083bbd 100644 --- a/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java +++ b/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java @@ -34,8 +34,6 @@ import java.nio.ByteOrder; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; import java.util.Properties; import org.apache.commons.imaging.ImageFormat; @@ -43,12 +41,12 @@ import org.apache.commons.imaging.ImageInfo; import org.apache.commons.imaging.ImageParser; import org.apache.commons.imaging.ImageReadException; -import org.apache.commons.imaging.ImageWriteException; +import org.apache.commons.imaging.ImageWriteException; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.common.bytesource.ByteSource; import org.apache.commons.imaging.util.IoUtils; -import static org.apache.commons.imaging.ImagingConstants.*; import static org.apache.commons.imaging.common.BinaryFunctions.*; import static org.apache.commons.imaging.common.ByteConversions.*; @@ -94,13 +92,13 @@ protected ImageFormat[] getAcceptedTypes() { } @Override - public ImageMetadata getMetadata(final ByteSource byteSource, final Map params) + public ImageMetadata getMetadata(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } @Override - public ImageInfo getImageInfo(final ByteSource byteSource, final Map params) + public ImageInfo getImageInfo(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final PcxHeader pcxHeader = readPcxHeader(byteSource); final Dimension size = getImageSize(byteSource, params); @@ -127,7 +125,7 @@ public ImageInfo getImageInfo(final ByteSource byteSource, final Map params) + public Dimension getImageSize(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final PcxHeader pcxHeader = readPcxHeader(byteSource); final int xSize = pcxHeader.xMax - pcxHeader.xMin + 1; @@ -142,7 +140,7 @@ public Dimension getImageSize(final ByteSource byteSource, final Map params) + public byte[] getICCProfileBytes(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } @@ -514,13 +512,11 @@ private BufferedImage readImage(final PcxHeader pcxHeader, final InputStream is, @Override public final BufferedImage getBufferedImage(final ByteSource byteSource, - Map params) throws ImageReadException, IOException { - params = (params == null) ? new HashMap() : new HashMap(params); - boolean isStrict = false; - final Object strictness = params.get(PARAM_KEY_STRICT); - if (strictness != null) { - isStrict = ((Boolean) strictness).booleanValue(); - } + final ImagingParameters params) throws ImageReadException, IOException { + + // ensure that the parameter object is not null + final ImagingParameters parameters = (params == null) ? new ImagingParameters() : params; + boolean isStrict = parameters.getStrict(); InputStream is = null; boolean canThrow = false; @@ -536,7 +532,7 @@ public final BufferedImage getBufferedImage(final ByteSource byteSource, } @Override - public void writeImage(final BufferedImage src, final OutputStream os, final Map params) + public void writeImage(final BufferedImage src, final OutputStream os, final ImagingParameters params) throws ImageWriteException, IOException { new PcxWriter(params).writeImage(src, os); } @@ -550,9 +546,11 @@ public void writeImage(final BufferedImage src, final OutputStream os, final Map * @param params * Map of optional parameters, defined in ImagingConstants. * @return Xmp Xml as String, if present. Otherwise, returns null. + * @throws org.apache.commons.imaging.ImageReadException + * @throws java.io.IOException */ @Override - public String getXmpXml(final ByteSource byteSource, final Map params) + public String getXmpXml(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } diff --git a/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java b/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java index 05a340698..cca27bb1e 100644 --- a/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java +++ b/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java @@ -10,7 +10,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * under the License. */ package org.apache.commons.imaging.formats.pcx; @@ -20,11 +19,10 @@ import java.io.OutputStream; import java.nio.ByteOrder; import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; import org.apache.commons.imaging.ImageWriteException; -import org.apache.commons.imaging.ImagingConstants; +import org.apache.commons.imaging.ImagingParameters; +import org.apache.commons.imaging.ImagingParametersPcx; import org.apache.commons.imaging.PixelDensity; import org.apache.commons.imaging.common.BinaryOutputStream; import org.apache.commons.imaging.palette.PaletteFactory; @@ -32,65 +30,45 @@ class PcxWriter { private int encoding; - private int bitDepth = -1; - private PixelDensity pixelDensity; + private int bitDepth; + private final PixelDensity pixelDensity; - public PcxWriter(Map params) throws ImageWriteException { - // make copy of params; we'll clear keys as we consume them. - params = (params == null) ? new HashMap() : new HashMap(params); - - // clear format key. - if (params.containsKey(ImagingConstants.PARAM_KEY_FORMAT)) { - params.remove(ImagingConstants.PARAM_KEY_FORMAT); + public PcxWriter(final ImagingParameters params) throws ImageWriteException { + // set default values + this.encoding = PcxImageParser.PcxHeader.ENCODING_RLE; + this.bitDepth = -1; + + // ensure that the parameter object is not null + final ImagingParameters parameters = (params == null) ? new ImagingParameters() : params; + + // getting properties which are not specific for PCF format + if (parameters.isPixelDensityPresent()) { + this.pixelDensity = parameters.getPixelDensity(); } - - // uncompressed PCX files are not even documented in ZSoft's spec, - // let alone supported by most image viewers - encoding = PcxImageParser.PcxHeader.ENCODING_RLE; - if (params.containsKey(PcxConstants.PARAM_KEY_PCX_COMPRESSION)) { - final Object value = params.remove(PcxConstants.PARAM_KEY_PCX_COMPRESSION); - if (value != null) { - if (!(value instanceof Number)) { - throw new ImageWriteException( - "Invalid compression parameter: " + value); - } - final int compression = ((Number) value).intValue(); - if (compression == PcxConstants.PCX_COMPRESSION_UNCOMPRESSED) { - encoding = PcxImageParser.PcxHeader.ENCODING_UNCOMPRESSED; - } - } + else { + // DPI is mandatory, so we have to invent something + this.pixelDensity = PixelDensity.createFromPixelsPerInch(72, 72); } - - if (params.containsKey(PcxConstants.PARAM_KEY_PCX_BIT_DEPTH)) { - final Object value = params.remove(PcxConstants.PARAM_KEY_PCX_BIT_DEPTH); - if (value != null) { - if (!(value instanceof Number)) { - throw new ImageWriteException( - "Invalid bit depth parameter: " + value); + + // getting properties which are specific for PCF format if provided + // if we can cast the generic parameter object to a PCX-specific one they are + if (parameters instanceof ImagingParametersPcx) { + final ImagingParametersPcx parametersPcx = (ImagingParametersPcx) parameters; + + // get the compression level for PCX + // uncompressed PCX files are not even documented in ZSoft's spec, + // let alone supported by most image viewers + if (parametersPcx.isCompressionLevelPresent()) { + if (parametersPcx.getCompressionLevel() == PcxConstants.PCX_COMPRESSION_UNCOMPRESSED) { + this.encoding = PcxImageParser.PcxHeader.ENCODING_UNCOMPRESSED; } - bitDepth = ((Number) value).intValue(); } - } - - if (params.containsKey(ImagingConstants.PARAM_KEY_PIXEL_DENSITY)) { - final Object value = params.remove(ImagingConstants.PARAM_KEY_PIXEL_DENSITY); - if (value != null) { - if (!(value instanceof PixelDensity)) { - throw new ImageWriteException( - "Invalid pixel density parameter"); - } - pixelDensity = (PixelDensity) value; + + // get the bit depth for PCX + if (parametersPcx.isCompressionLevelPresent()) { + this.bitDepth = parametersPcx.getBitDepth(); } } - if (pixelDensity == null) { - // DPI is mandatory, so we have to invent something - pixelDensity = PixelDensity.createFromPixelsPerInch(72, 72); - } - - if (!params.isEmpty()) { - final Object firstKey = params.keySet().iterator().next(); - throw new ImageWriteException("Unknown parameter: " + firstKey); - } } private void writeScanLine(final BinaryOutputStream bos, final byte[] scanline) diff --git a/src/main/java/org/apache/commons/imaging/formats/png/PngConstants.java b/src/main/java/org/apache/commons/imaging/formats/png/PngConstants.java index c712d1172..352abc8b5 100644 --- a/src/main/java/org/apache/commons/imaging/formats/png/PngConstants.java +++ b/src/main/java/org/apache/commons/imaging/formats/png/PngConstants.java @@ -25,13 +25,6 @@ public final class PngConstants { public static final BinaryConstant PNG_SIGNATURE = new BinaryConstant( new byte[] { (byte) 0x89, 'P', 'N', 'G', '\r', '\n', 0x1A, '\n', }); - public static final String PARAM_KEY_PNG_BIT_DEPTH = "PNG_BIT_DEPTH"; - public static final String PARAM_KEY_PNG_FORCE_INDEXED_COLOR = "PNG_FORCE_INDEXED_COLOR"; - public static final String PARAM_KEY_PNG_FORCE_TRUE_COLOR = "PNG_FORCE_TRUE_COLOR"; - - // public static final Object PARAM_KEY_PNG_BIT_DEPTH_YES = "YES"; - // public static final Object PARAM_KEY_PNG_BIT_DEPTH_NO = "NO"; - public static final byte COMPRESSION_TYPE_INFLATE_DEFLATE = 0; public static final byte FILTER_METHOD_ADAPTIVE = 0; @@ -59,16 +52,6 @@ public final class PngConstants { public static final String XMP_KEYWORD = "XML:com.adobe.xmp"; - /** - * Parameter key. - * - * Only used when writing Png images. - *

- * Valid values: a list of WriteTexts. - *

- */ - public static final String PARAM_KEY_PNG_TEXT_CHUNKS = "PNG_TEXT_CHUNKS"; - private PngConstants() { } } diff --git a/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java b/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java index c7c1b6685..0da1d4a5c 100644 --- a/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java +++ b/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java @@ -29,9 +29,7 @@ import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.zip.InflaterInputStream; import org.apache.commons.imaging.ColorTools; @@ -41,6 +39,7 @@ import org.apache.commons.imaging.ImageParser; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.common.GenericImageMetadata; import org.apache.commons.imaging.common.bytesource.ByteSource; @@ -62,7 +61,6 @@ import org.apache.commons.imaging.icc.IccProfileParser; import org.apache.commons.imaging.util.IoUtils; -import static org.apache.commons.imaging.ImagingConstants.*; import static org.apache.commons.imaging.common.BinaryFunctions.*; public class PngImageParser extends ImageParser { @@ -102,7 +100,10 @@ public static String getChunkTypeName(final int chunkType) { } /** + * @param is * @return List of String-formatted chunk types, ie. "tRNs". + * @throws org.apache.commons.imaging.ImageReadException + * @throws java.io.IOException */ public List getChuckTypes(final InputStream is) throws ImageReadException, IOException { @@ -241,7 +242,7 @@ private List readChunks(final ByteSource byteSource, final ChunkType[] } @Override - public byte[] getICCProfileBytes(final ByteSource byteSource, final Map params) + public byte[] getICCProfileBytes(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final List chunks = readChunks(byteSource, new ChunkType[] { ChunkType.iCCP }, true); @@ -263,7 +264,7 @@ public byte[] getICCProfileBytes(final ByteSource byteSource, final Map params) + public Dimension getImageSize(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final List chunks = readChunks(byteSource, new ChunkType[] { ChunkType.IHDR, }, true); @@ -281,7 +282,7 @@ public Dimension getImageSize(final ByteSource byteSource, final Map params) + public ImageMetadata getMetadata(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final List chunks = readChunks(byteSource, new ChunkType[] { ChunkType.tEXt, ChunkType.zTXt, }, true); @@ -333,7 +334,7 @@ private TransparencyFilter getTransparencyFilter(PngColorType pngColorType, PngC } @Override - public ImageInfo getImageInfo(final ByteSource byteSource, final Map params) + public ImageInfo getImageInfo(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final List chunks = readChunks(byteSource, new ChunkType[] { ChunkType.IHDR, @@ -469,18 +470,8 @@ public ImageInfo getImageInfo(final ByteSource byteSource, final Map params) + public BufferedImage getBufferedImage(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { - params = (params == null) ? new HashMap() : new HashMap(params); - - if (params.containsKey(PARAM_KEY_VERBOSE)) { - params.remove(PARAM_KEY_VERBOSE); - } - - // if (params.size() > 0) { - // Object firstKey = params.keySet().iterator().next(); - // throw new ImageWriteException("Unknown parameter: " + firstKey); - // } final List chunks = readChunks(byteSource, new ChunkType[] { ChunkType.IHDR, @@ -692,13 +683,13 @@ public boolean dumpImageFile(final PrintWriter pw, final ByteSource byteSource) } @Override - public void writeImage(final BufferedImage src, final OutputStream os, final Map params) + public void writeImage(final BufferedImage src, final OutputStream os, final ImagingParameters params) throws ImageWriteException, IOException { new PngWriter(params).writeImage(src, os, params); } @Override - public String getXmpXml(final ByteSource byteSource, final Map params) + public String getXmpXml(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final List chunks = readChunks(byteSource, new ChunkType[] { ChunkType.iTXt }, false); 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 7b0be7e6f..9100d1e46 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 @@ -21,13 +21,12 @@ import java.io.IOException; import java.io.OutputStream; import java.io.UnsupportedEncodingException; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.zip.DeflaterOutputStream; import org.apache.commons.imaging.ImageWriteException; -import org.apache.commons.imaging.ImagingConstants; +import org.apache.commons.imaging.ImagingParameters; +import org.apache.commons.imaging.ImagingParametersPng; import org.apache.commons.imaging.PixelDensity; import org.apache.commons.imaging.palette.Palette; import org.apache.commons.imaging.palette.PaletteFactory; @@ -42,8 +41,8 @@ public PngWriter(final boolean verbose) { this.verbose = verbose; } - public PngWriter(final Map params) { - this.verbose = params != null && Boolean.TRUE.equals(params.get(ImagingConstants.PARAM_KEY_VERBOSE)); + public PngWriter(final ImagingParameters params) { + this.verbose = params != null && Boolean.TRUE.equals(params.getVerbose()); } /* @@ -297,12 +296,14 @@ private void writeChunkPHYS(final OutputStream os, final int xPPU, final int yPP writeChunk(os, ChunkType.pHYs, bytes); } - private byte getBitDepth(final PngColorType pngColorType, final Map params) { + private byte getBitDepth(final PngColorType pngColorType, final ImagingParameters params) { byte depth = 8; - - Object o = params.get(PngConstants.PARAM_KEY_PNG_BIT_DEPTH); - if (o instanceof Number) { - depth = ((Number) o).byteValue(); + + if (params instanceof ImagingParametersPng) { + final ImagingParametersPng parameters = (ImagingParametersPng) params; + if (parameters.isBitDepthPresent()) { + depth = parameters.getBitDepth(); + } } return pngColorType.isBitDepthAllowed(depth) ? depth : 8; @@ -366,42 +367,10 @@ public int getPaletteIndex(final int rgb) throws ImageWriteException { tEXt Yes None zTXt Yes None */ - public void writeImage(final BufferedImage src, final OutputStream os, Map params) + public void writeImage(final BufferedImage src, final OutputStream os, final ImagingParameters params) throws ImageWriteException, IOException { - // make copy of params; we'll clear keys as we consume them. - params = new HashMap(params); - - // clear format key. - if (params.containsKey(ImagingConstants.PARAM_KEY_FORMAT)) { - params.remove(ImagingConstants.PARAM_KEY_FORMAT); - } - // clear verbose key. - if (params.containsKey(ImagingConstants.PARAM_KEY_VERBOSE)) { - params.remove(ImagingConstants.PARAM_KEY_VERBOSE); - } - - final Map rawParams = new HashMap(params); - if (params.containsKey(PngConstants.PARAM_KEY_PNG_FORCE_TRUE_COLOR)) { - params.remove(PngConstants.PARAM_KEY_PNG_FORCE_TRUE_COLOR); - } - if (params.containsKey(PngConstants.PARAM_KEY_PNG_FORCE_INDEXED_COLOR)) { - params.remove(PngConstants.PARAM_KEY_PNG_FORCE_INDEXED_COLOR); - } - if (params.containsKey(PngConstants.PARAM_KEY_PNG_BIT_DEPTH)) { - params.remove(PngConstants.PARAM_KEY_PNG_BIT_DEPTH); - } - if (params.containsKey(ImagingConstants.PARAM_KEY_XMP_XML)) { - params.remove(ImagingConstants.PARAM_KEY_XMP_XML); - } - if (params.containsKey(PngConstants.PARAM_KEY_PNG_TEXT_CHUNKS)) { - params.remove(PngConstants.PARAM_KEY_PNG_TEXT_CHUNKS); - } - params.remove(ImagingConstants.PARAM_KEY_PIXEL_DENSITY); - if (!params.isEmpty()) { - final Object firstKey = params.keySet().iterator().next(); - throw new ImageWriteException("Unknown parameter: " + firstKey); - } - params = rawParams; + // ensure that the parameter object is not null + final ImagingParameters parameters = (params == null) ? new ImagingParameters() : params; final int width = src.getWidth(); final int height = src.getHeight(); @@ -419,8 +388,22 @@ public void writeImage(final BufferedImage src, final OutputStream os, Map outputTexts = (List) params.get(PngConstants.PARAM_KEY_PNG_TEXT_CHUNKS); - for (Object outputText : outputTexts) { - final PngText text = (PngText) outputText; - if (text instanceof PngText.Text) { - writeChunktEXt(os, (PngText.Text) text); - } else if (text instanceof PngText.Ztxt) { - writeChunkzTXt(os, (PngText.Ztxt) text); - } else if (text instanceof PngText.Itxt) { - writeChunkiTXt(os, (PngText.Itxt) text); - } else { - throw new ImageWriteException( - "Unknown text to embed in PNG: " + text); + + // text chunks are parameters specific for PNG images + // so we need to ask first if parameters specific for PNG images are provided + // than ask for text chunks + if (parameters instanceof ImagingParametersPng) { + final ImagingParametersPng parametersPng = (ImagingParametersPng) parameters; + if (parametersPng.hasTextChunks()) { + final List outputTexts = parametersPng.getTextChunks(); + for (PngText text : outputTexts) { + // there are different kind of png texts + // each one requires a different action + if (text instanceof PngText.Text) { + writeChunktEXt(os, (PngText.Text) text); + } + else if (text instanceof PngText.Ztxt) { + writeChunkzTXt(os, (PngText.Ztxt) text); + } + else if (text instanceof PngText.Itxt) { + writeChunkiTXt(os, (PngText.Itxt) text); + } + else { + throw new ImageWriteException( + "Unknown text to embed in PNG: " + text); + } } } } diff --git a/src/main/java/org/apache/commons/imaging/formats/pnm/PamWriter.java b/src/main/java/org/apache/commons/imaging/formats/pnm/PamWriter.java index 61ecf5d39..4849fda67 100644 --- a/src/main/java/org/apache/commons/imaging/formats/pnm/PamWriter.java +++ b/src/main/java/org/apache/commons/imaging/formats/pnm/PamWriter.java @@ -20,14 +20,14 @@ import java.awt.image.BufferedImage; import java.io.IOException; import java.io.OutputStream; -import java.util.Map; import org.apache.commons.imaging.ImageWriteException; +import org.apache.commons.imaging.ImagingParameters; class PamWriter implements PnmWriter { - public void writeImage(final BufferedImage src, final OutputStream os, - final Map params) throws ImageWriteException, IOException { + public void writeImage(final BufferedImage src, final OutputStream os, final ImagingParameters params) + throws ImageWriteException, IOException { os.write(PnmConstants.PNM_PREFIX_BYTE); os.write(PnmConstants.PAM_RAW_CODE); diff --git a/src/main/java/org/apache/commons/imaging/formats/pnm/PbmWriter.java b/src/main/java/org/apache/commons/imaging/formats/pnm/PbmWriter.java index 19a674077..d9e600e1d 100644 --- a/src/main/java/org/apache/commons/imaging/formats/pnm/PbmWriter.java +++ b/src/main/java/org/apache/commons/imaging/formats/pnm/PbmWriter.java @@ -19,19 +19,19 @@ import java.awt.image.BufferedImage; import java.io.IOException; import java.io.OutputStream; -import java.util.Map; import org.apache.commons.imaging.ImageWriteException; +import org.apache.commons.imaging.ImagingParameters; class PbmWriter implements PnmWriter { - private boolean rawbits; + private final boolean rawbits; public PbmWriter(final boolean rawbits) { this.rawbits = rawbits; } - public void writeImage(final BufferedImage src, final OutputStream os, final Map params) + public void writeImage(final BufferedImage src, final OutputStream os, final ImagingParameters params) throws ImageWriteException, IOException { os.write(PnmConstants.PNM_PREFIX_BYTE); os.write(rawbits ? PnmConstants.PBM_RAW_CODE : PnmConstants.PBM_TEXT_CODE); diff --git a/src/main/java/org/apache/commons/imaging/formats/pnm/PgmWriter.java b/src/main/java/org/apache/commons/imaging/formats/pnm/PgmWriter.java index be4a54ab0..87575cc80 100644 --- a/src/main/java/org/apache/commons/imaging/formats/pnm/PgmWriter.java +++ b/src/main/java/org/apache/commons/imaging/formats/pnm/PgmWriter.java @@ -19,19 +19,19 @@ import java.awt.image.BufferedImage; import java.io.IOException; import java.io.OutputStream; -import java.util.Map; import org.apache.commons.imaging.ImageWriteException; +import org.apache.commons.imaging.ImagingParameters; class PgmWriter implements PnmWriter { - private boolean rawbits; + private final boolean rawbits; public PgmWriter(boolean rawbits) { this.rawbits = rawbits; } - public void writeImage(final BufferedImage src, final OutputStream os, final Map params) + public void writeImage(final BufferedImage src, final OutputStream os, final ImagingParameters params) throws ImageWriteException, IOException { // System.out.println // (b1 == 0x50 && b2 == 0x36) diff --git a/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java b/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java index c333d02f5..4ff1b4d46 100644 --- a/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java +++ b/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java @@ -24,9 +24,7 @@ import java.io.PrintWriter; import java.nio.ByteOrder; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.StringTokenizer; import org.apache.commons.imaging.ImageFormat; @@ -35,20 +33,19 @@ import org.apache.commons.imaging.ImageParser; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; +import org.apache.commons.imaging.ImagingParameters; +import org.apache.commons.imaging.ImagingParametersPnm; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.common.ImageBuilder; import org.apache.commons.imaging.common.bytesource.ByteSource; import org.apache.commons.imaging.palette.PaletteFactory; import org.apache.commons.imaging.util.IoUtils; -import static org.apache.commons.imaging.ImagingConstants.*; import static org.apache.commons.imaging.common.BinaryFunctions.*; public class PnmImageParser extends ImageParser { private static final String DEFAULT_EXTENSION = ".pnm"; - private static final String[] ACCEPTED_EXTENSIONS = { ".pbm", ".pgm", - ".ppm", ".pnm", ".pam" }; - public static final String PARAM_KEY_PNM_RAWBITS = "PNM_RAWBITS"; + private static final String[] ACCEPTED_EXTENSIONS = { ".pbm", ".pgm", ".ppm", ".pnm", ".pam" }; public static final String PARAM_VALUE_PNM_RAWBITS_YES = "YES"; public static final String PARAM_VALUE_PNM_RAWBITS_NO = "NO"; @@ -201,13 +198,13 @@ private FileInfo readHeader(final ByteSource byteSource) } @Override - public byte[] getICCProfileBytes(final ByteSource byteSource, final Map params) + public byte[] getICCProfileBytes(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } @Override - public Dimension getImageSize(final ByteSource byteSource, final Map params) + public Dimension getImageSize(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final FileInfo info = readHeader(byteSource); @@ -219,13 +216,13 @@ public Dimension getImageSize(final ByteSource byteSource, final Map params) + public ImageMetadata getMetadata(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } @Override - public ImageInfo getImageInfo(final ByteSource byteSource, final Map params) + public ImageInfo getImageInfo(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final FileInfo info = readHeader(byteSource); @@ -282,7 +279,7 @@ public boolean dumpImageFile(final PrintWriter pw, final ByteSource byteSource) } @Override - public BufferedImage getBufferedImage(final ByteSource byteSource, final Map params) + public BufferedImage getBufferedImage(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { InputStream is = null; boolean canThrow = false; @@ -308,22 +305,16 @@ public BufferedImage getBufferedImage(final ByteSource byteSource, final Map params) + public void writeImage(final BufferedImage src, final OutputStream os, final ImagingParameters params) throws ImageWriteException, IOException { PnmWriter writer = null; boolean useRawbits = true; final boolean hasAlpha = new PaletteFactory().hasTransparency(src); if (params != null) { - final Object useRawbitsParam = params.get(PARAM_KEY_PNM_RAWBITS); - if (useRawbitsParam != null) { - if (useRawbitsParam.equals(PARAM_VALUE_PNM_RAWBITS_NO)) { - useRawbits = false; - } - } - - final Object subtype = params.get(PARAM_KEY_FORMAT); - if (subtype != null) { + // read generic parameters + if (params.isImageFormatPresent()) { + final ImageFormat subtype = params.getImageFormat(); if (subtype.equals(ImageFormats.PBM)) { writer = new PbmWriter(useRawbits); } else if (subtype.equals(ImageFormats.PGM)) { @@ -334,6 +325,12 @@ public void writeImage(final BufferedImage src, final OutputStream os, Map(params); - } else { - params = new HashMap(); - } - - // clear format key. - if (params.containsKey(PARAM_KEY_FORMAT)) { - params.remove(PARAM_KEY_FORMAT); - } - - if (!params.isEmpty()) { - final Object firstKey = params.keySet().iterator().next(); - throw new ImageWriteException("Unknown parameter: " + firstKey); - } - writer.writeImage(src, os, params); } @@ -373,9 +353,11 @@ public void writeImage(final BufferedImage src, final OutputStream os, Map params) + public String getXmpXml(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } diff --git a/src/main/java/org/apache/commons/imaging/formats/pnm/PnmWriter.java b/src/main/java/org/apache/commons/imaging/formats/pnm/PnmWriter.java index 5a73362bb..dadbb7d92 100644 --- a/src/main/java/org/apache/commons/imaging/formats/pnm/PnmWriter.java +++ b/src/main/java/org/apache/commons/imaging/formats/pnm/PnmWriter.java @@ -19,13 +19,13 @@ import java.awt.image.BufferedImage; import java.io.IOException; import java.io.OutputStream; -import java.util.Map; import org.apache.commons.imaging.ImageWriteException; +import org.apache.commons.imaging.ImagingParameters; interface PnmWriter { void writeImage(BufferedImage src, OutputStream os, - Map params) throws ImageWriteException, IOException; + final ImagingParameters params) throws ImageWriteException, IOException; } diff --git a/src/main/java/org/apache/commons/imaging/formats/pnm/PpmWriter.java b/src/main/java/org/apache/commons/imaging/formats/pnm/PpmWriter.java index d4577ae78..5fc21ca41 100644 --- a/src/main/java/org/apache/commons/imaging/formats/pnm/PpmWriter.java +++ b/src/main/java/org/apache/commons/imaging/formats/pnm/PpmWriter.java @@ -19,19 +19,19 @@ import java.awt.image.BufferedImage; import java.io.IOException; import java.io.OutputStream; -import java.util.Map; import org.apache.commons.imaging.ImageWriteException; +import org.apache.commons.imaging.ImagingParameters; class PpmWriter implements PnmWriter { - private boolean rawbits; + private final boolean rawbits; public PpmWriter(boolean rawbits) { this.rawbits = rawbits; } - public void writeImage(final BufferedImage src, final OutputStream os, final Map params) + public void writeImage(final BufferedImage src, final OutputStream os, final ImagingParameters params) throws ImageWriteException, IOException { // System.out.println // (b1 == 0x50 && b2 == 0x36) diff --git a/src/main/java/org/apache/commons/imaging/formats/psd/PsdImageParser.java b/src/main/java/org/apache/commons/imaging/formats/psd/PsdImageParser.java index 9f1a3505f..39f97ba44 100644 --- a/src/main/java/org/apache/commons/imaging/formats/psd/PsdImageParser.java +++ b/src/main/java/org/apache/commons/imaging/formats/psd/PsdImageParser.java @@ -26,13 +26,13 @@ import java.nio.ByteOrder; import java.util.ArrayList; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.ImageFormat; import org.apache.commons.imaging.ImageFormats; import org.apache.commons.imaging.ImageInfo; import org.apache.commons.imaging.ImageParser; import org.apache.commons.imaging.ImageReadException; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.common.bytesource.ByteSource; import org.apache.commons.imaging.formats.psd.dataparsers.DataParser; @@ -412,7 +412,7 @@ private ImageContents readImageContents(final ByteSource byteSource) } @Override - public byte[] getICCProfileBytes(final ByteSource byteSource, final Map params) + public byte[] getICCProfileBytes(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final List blocks = readImageResourceBlocks(byteSource, new int[] { IMAGE_RESOURCE_ID_ICC_PROFILE, }, 1); @@ -430,7 +430,7 @@ public byte[] getICCProfileBytes(final ByteSource byteSource, final Map params) + public Dimension getImageSize(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final PsdHeaderInfo bhi = readHeader(byteSource); if (bhi == null) { @@ -442,7 +442,7 @@ public Dimension getImageSize(final ByteSource byteSource, final Map params) + public ImageMetadata getMetadata(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } @@ -472,7 +472,7 @@ private int getChannelsPerMode(final int mode) { } @Override - public ImageInfo getImageInfo(final ByteSource byteSource, final Map params) + public ImageInfo getImageInfo(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final ImageContents imageContents = readImageContents(byteSource); // ImageContents imageContents = readImage(byteSource, false); @@ -596,7 +596,7 @@ public boolean dumpImageFile(final PrintWriter pw, final ByteSource byteSource) } @Override - public BufferedImage getBufferedImage(final ByteSource byteSource, final Map params) + public BufferedImage getBufferedImage(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final ImageContents imageContents = readImageContents(byteSource); // ImageContents imageContents = readImage(byteSource, false); @@ -718,9 +718,11 @@ public BufferedImage getBufferedImage(final ByteSource byteSource, final Map params) + public String getXmpXml(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final ImageContents imageContents = readImageContents(byteSource); diff --git a/src/main/java/org/apache/commons/imaging/formats/rgbe/RgbeImageParser.java b/src/main/java/org/apache/commons/imaging/formats/rgbe/RgbeImageParser.java index 6ad05c37b..484eaa9b3 100644 --- a/src/main/java/org/apache/commons/imaging/formats/rgbe/RgbeImageParser.java +++ b/src/main/java/org/apache/commons/imaging/formats/rgbe/RgbeImageParser.java @@ -29,13 +29,13 @@ import java.io.IOException; import java.nio.ByteOrder; import java.util.ArrayList; -import java.util.Map; import org.apache.commons.imaging.ImageFormat; import org.apache.commons.imaging.ImageFormats; import org.apache.commons.imaging.ImageInfo; import org.apache.commons.imaging.ImageParser; import org.apache.commons.imaging.ImageReadException; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.common.bytesource.ByteSource; import org.apache.commons.imaging.util.IoUtils; @@ -72,7 +72,7 @@ protected ImageFormat[] getAcceptedTypes() { } @Override - public ImageMetadata getMetadata(final ByteSource byteSource, final Map params) + public ImageMetadata getMetadata(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final RgbeInfo info = new RgbeInfo(byteSource); boolean canThrow = false; @@ -86,7 +86,7 @@ public ImageMetadata getMetadata(final ByteSource byteSource, final Map params) + public ImageInfo getImageInfo(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final RgbeInfo info = new RgbeInfo(byteSource); boolean canThrow = false; @@ -106,7 +106,7 @@ public ImageInfo getImageInfo(final ByteSource byteSource, final Map params) + public BufferedImage getBufferedImage(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final RgbeInfo info = new RgbeInfo(byteSource); boolean canThrow = false; @@ -132,7 +132,7 @@ public BufferedImage getBufferedImage(final ByteSource byteSource, final Map params) + public Dimension getImageSize(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final RgbeInfo info = new RgbeInfo(byteSource); boolean canThrow = false; @@ -146,13 +146,13 @@ public Dimension getImageSize(final ByteSource byteSource, final Map params) + public byte[] getICCProfileBytes(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } @Override - public String getXmpXml(final ByteSource byteSource, final Map params) + public String getXmpXml(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } diff --git a/src/main/java/org/apache/commons/imaging/formats/tiff/TiffDirectory.java b/src/main/java/org/apache/commons/imaging/formats/tiff/TiffDirectory.java index 34f37e723..0c9da54a2 100644 --- a/src/main/java/org/apache/commons/imaging/formats/tiff/TiffDirectory.java +++ b/src/main/java/org/apache/commons/imaging/formats/tiff/TiffDirectory.java @@ -22,9 +22,9 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.ImageReadException; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.ByteConversions; import org.apache.commons.imaging.common.RationalNumber; import org.apache.commons.imaging.formats.tiff.constants.TiffConstants; @@ -144,11 +144,11 @@ public boolean hasTiffImageData() throws ImageReadException { public BufferedImage getTiffImage(final ByteOrder byteOrder) throws ImageReadException, IOException { - final Map params = null; + final ImagingParameters params = null; return getTiffImage(byteOrder, params); } - public BufferedImage getTiffImage(final ByteOrder byteOrder, final Map params) + public BufferedImage getTiffImage(final ByteOrder byteOrder, final ImagingParameters params) throws ImageReadException, IOException { if (null == tiffImageData) { return null; diff --git a/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageParser.java b/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageParser.java index 9224833ba..7f7797c39 100644 --- a/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageParser.java +++ b/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageParser.java @@ -26,7 +26,6 @@ import java.nio.ByteOrder; import java.util.ArrayList; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.FormatCompliance; import org.apache.commons.imaging.ImageFormat; @@ -35,11 +34,12 @@ import org.apache.commons.imaging.ImageParser; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; +import org.apache.commons.imaging.ImagingParameters; +import org.apache.commons.imaging.ImagingParametersTiff; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.common.ImageBuilder; import org.apache.commons.imaging.common.bytesource.ByteSource; import org.apache.commons.imaging.formats.tiff.TiffDirectory.ImageDataElement; -import org.apache.commons.imaging.formats.tiff.constants.TiffConstants; import org.apache.commons.imaging.formats.tiff.constants.TiffEpTagConstants; import org.apache.commons.imaging.formats.tiff.constants.TiffTagConstants; import org.apache.commons.imaging.formats.tiff.datareaders.DataReader; @@ -81,7 +81,7 @@ protected ImageFormat[] getAcceptedTypes() { } @Override - public byte[] getICCProfileBytes(final ByteSource byteSource, final Map params) + public byte[] getICCProfileBytes(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final FormatCompliance formatCompliance = FormatCompliance.getDefault(); final TiffContents contents = new TiffReader(isStrict(params)) @@ -93,7 +93,7 @@ public byte[] getICCProfileBytes(final ByteSource byteSource, final Map params) + public Dimension getImageSize(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final FormatCompliance formatCompliance = FormatCompliance.getDefault(); final TiffContents contents = new TiffReader(isStrict(params)) @@ -116,7 +116,7 @@ public Dimension getImageSize(final ByteSource byteSource, final Map params) + public ImageMetadata getMetadata(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final FormatCompliance formatCompliance = FormatCompliance.getDefault(); final TiffReader tiffReader = new TiffReader(isStrict(params)); @@ -144,7 +144,7 @@ public ImageMetadata getMetadata(final ByteSource byteSource, final Map params) + public ImageInfo getImageInfo(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final FormatCompliance formatCompliance = FormatCompliance.getDefault(); final TiffContents contents = new TiffReader(isStrict(params)) @@ -303,7 +303,7 @@ public ImageInfo getImageInfo(final ByteSource byteSource, final Map params) + public String getXmpXml(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final FormatCompliance formatCompliance = FormatCompliance.getDefault(); final TiffContents contents = new TiffReader(isStrict(params)) @@ -346,7 +346,7 @@ public boolean dumpImageFile(final PrintWriter pw, final ByteSource byteSource) { final FormatCompliance formatCompliance = FormatCompliance .getDefault(); - final Map params = null; + final ImagingParameters params = null; final TiffContents contents = new TiffReader(true).readContents( byteSource, params, formatCompliance); @@ -391,13 +391,13 @@ public boolean dumpImageFile(final PrintWriter pw, final ByteSource byteSource) public FormatCompliance getFormatCompliance(final ByteSource byteSource) throws ImageReadException, IOException { final FormatCompliance formatCompliance = FormatCompliance.getDefault(); - final Map params = null; + final ImagingParameters params = null; new TiffReader(isStrict(params)).readContents(byteSource, params, formatCompliance); return formatCompliance; } - public List collectRawImageData(final ByteSource byteSource, final Map params) + public List collectRawImageData(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final FormatCompliance formatCompliance = FormatCompliance.getDefault(); final TiffContents contents = new TiffReader(isStrict(params)) @@ -431,7 +431,7 @@ public List collectRawImageData(final ByteSource byteSource, final Map

-     *   HashMap params = new HashMap();
+     *   Hashfinal ImagingParameters params = new HashMap();
      *   params.put(TiffConstants.PARAM_KEY_SUBIMAGE_X, new Integer(x));
      *   params.put(TiffConstants.PARAM_KEY_SUBIMAGE_Y, new Integer(y));
      *   params.put(TiffConstants.PARAM_KEY_SUBIMAGE_WIDTH, new Integer(width));
@@ -452,7 +452,7 @@ public List collectRawImageData(final ByteSource byteSource, final Map params)
+    public BufferedImage getBufferedImage(final ByteSource byteSource, final ImagingParameters params)
             throws ImageReadException, IOException {
         final FormatCompliance formatCompliance = FormatCompliance.getDefault();
         final TiffReader reader = new TiffReader(isStrict(params));
@@ -485,40 +485,45 @@ public List getAllBufferedImages(final ByteSource byteSource)
         }
         return results;
     }
-
-    private Integer getIntegerParameter(
-            final String key, final Mapparams)
-            throws ImageReadException
-    {
-        if (params == null) {
-            return null;
-        }
-
-        if (!params.containsKey(key)) {
-            return null;
-        }
-
-        final Object obj = params.get(key);
-
-        if (obj instanceof Integer) {
-            return (Integer) obj;
-        }
-        throw new ImageReadException("Non-Integer parameter " + key);
-    }
     
-    private Rectangle checkForSubImage(
-            final Map params)
-            throws ImageReadException
-    {
-        Integer ix0 = getIntegerParameter(TiffConstants.PARAM_KEY_SUBIMAGE_X, params);
-        Integer iy0 = getIntegerParameter(TiffConstants.PARAM_KEY_SUBIMAGE_Y, params);
-        Integer iwidth = getIntegerParameter(TiffConstants.PARAM_KEY_SUBIMAGE_WIDTH, params);
-        Integer iheight = getIntegerParameter(TiffConstants.PARAM_KEY_SUBIMAGE_HEIGHT, params);
+    private Rectangle checkForSubImage(final ImagingParameters params) throws ImageReadException {
+        Integer ix0 = null;
+        Integer iy0 = null;
+        Integer iwidth = null;
+        Integer iheight = null;
+        
+        // we got parameters
+        if (params != null) {
+            // we got even TIFF specific parameters
+            if (params instanceof ImagingParametersTiff) {
+                final ImagingParametersTiff parametersTiff = (ImagingParametersTiff) params;
+                
+                if (parametersTiff.isSubImageX_Present()) {
+                    ix0 = parametersTiff.getSubImageX();
+                }
+                
+                if (parametersTiff.isSubImageY_Present()) {
+                    iy0 = parametersTiff.getSubImageY();
+                }
+                
+                if (parametersTiff.isSubImageWidth_Present()) {
+                    iwidth = parametersTiff.getSubImageWidth();
+                }
+                
+                if (parametersTiff.isSubImageHeight_Present()) {
+                    iheight = parametersTiff.getSubImageHeight();
+                }
+            }
+        }
         
+        // we either got no parameters, got parameters but these are not TIFF specific
+        // or if neither x, y, width nor height was set
         if (ix0 == null && iy0 == null && iwidth == null && iheight == null) {
             return null;
         }
-
+        
+        // if we got at lease one of theseparameters: x, y, width or height
+        // at least one of these is missing
         final StringBuilder sb = new StringBuilder(32);
         if (ix0 == null) {
             sb.append(" x0,");
@@ -541,7 +546,7 @@ private Rectangle checkForSubImage(
     }
     
     protected BufferedImage getBufferedImage(final TiffDirectory directory,
-            final ByteOrder byteOrder, final Map params) 
+            final ByteOrder byteOrder, final ImagingParameters params) 
             throws ImageReadException, IOException
     {
         final List entries = directory.entries;
@@ -640,7 +645,7 @@ protected BufferedImage getBufferedImage(final TiffDirectory directory,
                 photometricInterpreter, bitsPerPixel, bitsPerSample, predictor,
                 samplesPerPixel, width, height, compression, byteOrder);
 
-        BufferedImage result = null;
+        BufferedImage result;
         if (subImage != null) {
             result = dataReader.readImageData(subImage);
         } else {
@@ -729,7 +734,7 @@ private PhotometricInterpreter getPhotometricInterpreter(
     }
 
     @Override
-    public void writeImage(final BufferedImage src, final OutputStream os, final Map params)
+    public void writeImage(final BufferedImage src, final OutputStream os, final ImagingParameters params)
             throws ImageWriteException, IOException {
         new TiffImageWriterLossy().writeImage(src, os, params);
     }
diff --git a/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java b/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java
index 3d8c348a4..521fcf209 100644
--- a/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java
+++ b/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java
@@ -21,11 +21,11 @@
 import java.nio.ByteOrder;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.commons.imaging.FormatCompliance;
 import org.apache.commons.imaging.ImageReadException;
-import org.apache.commons.imaging.ImagingConstants;
+import org.apache.commons.imaging.ImagingParameters;
+import org.apache.commons.imaging.ImagingParametersTiff;
 import org.apache.commons.imaging.common.BinaryFileParser;
 import org.apache.commons.imaging.common.ByteConversions;
 import org.apache.commons.imaging.common.bytesource.ByteSource;
@@ -309,11 +309,13 @@ public Collector() {
             this(null);
         }
 
-        public Collector(final Map params) {
+        public Collector(final ImagingParameters params) {
             boolean tmpReadThumbnails = true;
-            if (params != null && params.containsKey(ImagingConstants.PARAM_KEY_READ_THUMBNAILS)) {
-                tmpReadThumbnails = Boolean.TRUE.equals(params
-                        .get(ImagingConstants.PARAM_KEY_READ_THUMBNAILS));
+            if (params != null) {
+                if (params instanceof ImagingParametersTiff) {
+                    final ImagingParametersTiff paramsTiff = (ImagingParametersTiff) params;
+                    tmpReadThumbnails = paramsTiff.getReadThumbnails();
+                }
             }
             this.readThumbnails = tmpReadThumbnails;
         }
@@ -385,7 +387,7 @@ public boolean readImageData() {
 //        }
 //    }
 
-    public TiffContents readFirstDirectory(final ByteSource byteSource, final Map params,
+    public TiffContents readFirstDirectory(final ByteSource byteSource, final ImagingParameters params,
             final boolean readImageData, final FormatCompliance formatCompliance)
             throws ImageReadException, IOException {
         final Collector collector = new FirstDirectoryCollector(readImageData);
@@ -411,7 +413,7 @@ public TiffContents readDirectories(final ByteSource byteSource,
         return contents;
     }
 
-    public TiffContents readContents(final ByteSource byteSource, final Map params,
+    public TiffContents readContents(final ByteSource byteSource, final ImagingParameters params,
             final FormatCompliance formatCompliance) throws ImageReadException,
             IOException {
 
@@ -420,7 +422,7 @@ public TiffContents readContents(final ByteSource byteSource, final Map params,
+    public void read(final ByteSource byteSource, final ImagingParameters params,
             final FormatCompliance formatCompliance, final Listener listener)
             throws ImageReadException, IOException {
         // TiffContents contents =
diff --git a/src/main/java/org/apache/commons/imaging/formats/tiff/constants/TiffConstants.java b/src/main/java/org/apache/commons/imaging/formats/tiff/constants/TiffConstants.java
index c12a66b8b..dbdf7c6cf 100644
--- a/src/main/java/org/apache/commons/imaging/formats/tiff/constants/TiffConstants.java
+++ b/src/main/java/org/apache/commons/imaging/formats/tiff/constants/TiffConstants.java
@@ -18,8 +18,6 @@
 
 import java.nio.ByteOrder;
 
-import org.apache.commons.imaging.ImagingConstants;
-
 public final class TiffConstants {
 
     public static final ByteOrder DEFAULT_TIFF_BYTE_ORDER = ByteOrder.LITTLE_ENDIAN;
@@ -40,43 +38,10 @@ public final class TiffConstants {
     public static final int TIFF_COMPRESSION_UNCOMPRESSED_2 = 32771;
     public static final int TIFF_COMPRESSION_PACKBITS = 32773;
 
-    /**
-     * Parameter key. Used in write operations to indicate the desired
-     * T.4 options to use when using TIFF_COMPRESSION_CCITT_GROUP_3.
-     * 

- * Valid values: any Integer containing a mixture of the - * TIFF_FLAG_T4_OPTIONS_2D, TIFF_FLAG_T4_OPTIONS_UNCOMPRESSED_MODE, - * and TIFF_FLAG_T4_OPTIONS_FILL flags. - */ - public static final String PARAM_KEY_T4_OPTIONS = "T4_OPTIONS"; - - /** - * Parameter key. Used in write operations to indicate the desired - * T.6 options to use when using TIFF_COMPRESSION_CCITT_GROUP_4. - *

- * Valid values: any Integer containing either zero or - * TIFF_FLAG_T6_OPTIONS_UNCOMPRESSED_MODE. - */ - public static final String PARAM_KEY_T6_OPTIONS = "T6_OPTIONS"; - public static final int TIFF_FLAG_T4_OPTIONS_2D = 1; public static final int TIFF_FLAG_T4_OPTIONS_UNCOMPRESSED_MODE = 2; public static final int TIFF_FLAG_T4_OPTIONS_FILL = 4; public static final int TIFF_FLAG_T6_OPTIONS_UNCOMPRESSED_MODE = 2; - - - public static final String PARAM_KEY_SUBIMAGE_X = "SUBIMAGE_X"; - public static final String PARAM_KEY_SUBIMAGE_Y = "SUBIMAGE_Y"; - public static final String PARAM_KEY_SUBIMAGE_WIDTH = "SUBIMAGE_WIDTH"; - public static final String PARAM_KEY_SUBIMAGE_HEIGHT = "SUBIMAGE_HEIGHT"; - - /** - * 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. - */ - public static final String PARAM_KEY_LZW_COMPRESSION_BLOCK_SIZE = - "PARAM_KEY_LZW_COMPRESSION_BLOCK_SIZE"; /** * Specifies a larger strip-size to be used for compression. This setting 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 b1a4c6a04..c5ccee368 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 @@ -28,7 +28,8 @@ import java.util.Map; import org.apache.commons.imaging.ImageWriteException; -import org.apache.commons.imaging.ImagingConstants; +import org.apache.commons.imaging.ImagingParameters; +import org.apache.commons.imaging.ImagingParametersTiff; import org.apache.commons.imaging.PixelDensity; import org.apache.commons.imaging.common.BinaryOutputStream; import org.apache.commons.imaging.common.PackBits; @@ -243,74 +244,67 @@ protected TiffOutputSummary validateDirectories(final TiffOutputSet outputSet) // Debug.debug(); } - public void writeImage(final BufferedImage src, final OutputStream os, Map params) + public void writeImage(final BufferedImage src, final OutputStream os, final ImagingParameters params) throws ImageWriteException, IOException { - // make copy of params; we'll clear keys as we consume them. - params = new HashMap(params); - - // clear format key. - if (params.containsKey(ImagingConstants.PARAM_KEY_FORMAT)) { - params.remove(ImagingConstants.PARAM_KEY_FORMAT); - } - - TiffOutputSet userExif = null; - if (params.containsKey(ImagingConstants.PARAM_KEY_EXIF)) { - userExif = (TiffOutputSet) params.remove(ImagingConstants.PARAM_KEY_EXIF); - } - + + // ensure that the parameter object is not null + final ImagingParameters parameters = (params == null) ? new ImagingParameters() : params; + + // get generic options String xmpXml = null; - if (params.containsKey(ImagingConstants.PARAM_KEY_XMP_XML)) { - xmpXml = (String) params.get(ImagingConstants.PARAM_KEY_XMP_XML); - params.remove(ImagingConstants.PARAM_KEY_XMP_XML); + if (parameters.isXmpXmlAsStringPresent()) { + xmpXml = parameters.getXmpXmlAsString(); } - PixelDensity pixelDensity = (PixelDensity) params - .remove(ImagingConstants.PARAM_KEY_PIXEL_DENSITY); - if (pixelDensity == null) { + PixelDensity pixelDensity; + if (parameters.isPixelDensityPresent()) { + pixelDensity = parameters.getPixelDensity(); + } + else { pixelDensity = PixelDensity.createFromPixelsPerInch(72, 72); } - - final int width = src.getWidth(); - final int height = src.getHeight(); - + + // get TIFF specific options + TiffOutputSet userExif = null; int compression = TIFF_COMPRESSION_LZW; // LZW is default int stripSizeInBits = 64000; // the default from legacy implementation - if (params.containsKey(ImagingConstants.PARAM_KEY_COMPRESSION)) { - final Object value = params.get(ImagingConstants.PARAM_KEY_COMPRESSION); - if (value != null) { - if (!(value instanceof Number)) { - throw new ImageWriteException( - "Invalid compression parameter, must be numeric: " - + value); - } - compression = ((Number) value).intValue(); + // t4 and t6 options are only used for some kinds of compression + // we try to get them in case they are set regardless of the kind of compression + // just because we get all other TIFF specific parameters here + // so we have everything in one place + Integer t4Parameter = null; + Integer t6Parameter = null; + + if (parameters instanceof ImagingParametersTiff) { + final ImagingParametersTiff parametersTiff = (ImagingParametersTiff) parameters; + + if (parametersTiff.isOutputSetPresent()) { + userExif = parametersTiff.getOutputSet(); } - params.remove(ImagingConstants.PARAM_KEY_COMPRESSION); - if (params.containsKey(PARAM_KEY_LZW_COMPRESSION_BLOCK_SIZE)) { - final Object bValue = - params.get(PARAM_KEY_LZW_COMPRESSION_BLOCK_SIZE); - if (!(bValue instanceof Number)) { - throw new ImageWriteException( - "Invalid compression block-size parameter: " + value); - } - final int stripSizeInBytes = ((Number) bValue).intValue(); - if (stripSizeInBytes < 8000) { - throw new ImageWriteException( - "Block size parameter " + stripSizeInBytes - + " is less than 8000 minimum"); + + if (parametersTiff.isCompressionLevelPresent()) { + compression = parametersTiff.getCompressionLevel(); + + if (parametersTiff.isCompressionBlockSizePresent()) { + final int stripSizeInBytes = parametersTiff.getCompressionBlockSize(); + if (stripSizeInBytes < 8000) { + throw new ImageWriteException( + "Block size parameter " + stripSizeInBytes + + " is less than 8000 minimum"); + } + stripSizeInBits = stripSizeInBytes*8; } - stripSizeInBits = stripSizeInBytes*8; - params.remove(PARAM_KEY_LZW_COMPRESSION_BLOCK_SIZE); + } + + if (parametersTiff.isT4optionsPresent()) { + t4Parameter = parametersTiff.getT4options(); + } + + if (parametersTiff.isT6optionsPresent()) { + t6Parameter = parametersTiff.getT6options(); } } - final HashMap rawParams = new HashMap(params); - params.remove(PARAM_KEY_T4_OPTIONS); - params.remove(PARAM_KEY_T6_OPTIONS); - if (!params.isEmpty()) { - final Object firstKey = params.keySet().iterator().next(); - throw new ImageWriteException("Unknown parameter: " + firstKey); - } - + int samplesPerPixel; int bitsPerSample; int photometricInterpretation; @@ -325,6 +319,9 @@ public void writeImage(final BufferedImage src, final OutputStream os, Map analyzeOldTiff(final Map fro IOException { try { final ByteSource byteSource = new ByteSourceArray(exifBytes); - final Map params = null; + final ImagingParameters params = null; final FormatCompliance formatCompliance = FormatCompliance.getDefault(); final TiffContents contents = new TiffReader(false).readContents( byteSource, params, formatCompliance); diff --git a/src/main/java/org/apache/commons/imaging/formats/wbmp/WbmpImageParser.java b/src/main/java/org/apache/commons/imaging/formats/wbmp/WbmpImageParser.java index 8709e77a8..9c9cb9b6a 100644 --- a/src/main/java/org/apache/commons/imaging/formats/wbmp/WbmpImageParser.java +++ b/src/main/java/org/apache/commons/imaging/formats/wbmp/WbmpImageParser.java @@ -10,7 +10,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * under the License. */ package org.apache.commons.imaging.formats.wbmp; @@ -27,8 +26,6 @@ import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; import java.util.Properties; import org.apache.commons.imaging.ImageFormat; @@ -37,11 +34,11 @@ import org.apache.commons.imaging.ImageParser; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.common.bytesource.ByteSource; import org.apache.commons.imaging.util.IoUtils; -import static org.apache.commons.imaging.ImagingConstants.*; import static org.apache.commons.imaging.common.BinaryFunctions.*; public class WbmpImageParser extends ImageParser { @@ -70,13 +67,13 @@ protected ImageFormat[] getAcceptedTypes() { } @Override - public ImageMetadata getMetadata(final ByteSource byteSource, final Map params) + public ImageMetadata getMetadata(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } @Override - public ImageInfo getImageInfo(final ByteSource byteSource, final Map params) + public ImageInfo getImageInfo(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final WbmpHeader wbmpHeader = readWbmpHeader(byteSource); return new ImageInfo("WBMP", 1, new ArrayList(), @@ -88,14 +85,14 @@ public ImageInfo getImageInfo(final ByteSource byteSource, final Map params) + public Dimension getImageSize(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final WbmpHeader wbmpHeader = readWbmpHeader(byteSource); return new Dimension(wbmpHeader.width, wbmpHeader.height); } @Override - public byte[] getICCProfileBytes(final ByteSource byteSource, final Map params) + public byte[] getICCProfileBytes(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } @@ -216,7 +213,7 @@ private BufferedImage readImage(final WbmpHeader wbmpHeader, final InputStream i @Override public final BufferedImage getBufferedImage(final ByteSource byteSource, - final Map params) throws ImageReadException, IOException { + final ImagingParameters params) throws ImageReadException, IOException { InputStream is = null; boolean canThrow = false; try { @@ -231,21 +228,9 @@ public final BufferedImage getBufferedImage(final ByteSource byteSource, } @Override - public void writeImage(final BufferedImage src, final OutputStream os, Map params) + public void writeImage(final BufferedImage src, final OutputStream os, final ImagingParameters params) throws ImageWriteException, IOException { - // make copy of params; we'll clear keys as we consume them. - params = (params == null) ? new HashMap() : new HashMap(params); - - // clear format key. - if (params.containsKey(PARAM_KEY_FORMAT)) { - params.remove(PARAM_KEY_FORMAT); - } - - if (!params.isEmpty()) { - final Object firstKey = params.keySet().iterator().next(); - throw new ImageWriteException("Unknown parameter: " + firstKey); - } - + writeMultiByteInteger(os, 0); // typeField os.write(0); // fixHeaderField writeMultiByteInteger(os, src.getWidth()); @@ -285,9 +270,11 @@ public void writeImage(final BufferedImage src, final OutputStream os, Map params) + public String getXmpXml(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } diff --git a/src/main/java/org/apache/commons/imaging/formats/xbm/XbmImageParser.java b/src/main/java/org/apache/commons/imaging/formats/xbm/XbmImageParser.java index 39a7229d6..b145462d1 100644 --- a/src/main/java/org/apache/commons/imaging/formats/xbm/XbmImageParser.java +++ b/src/main/java/org/apache/commons/imaging/formats/xbm/XbmImageParser.java @@ -10,7 +10,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * under the License. */ package org.apache.commons.imaging.formats.xbm; @@ -42,12 +41,12 @@ import org.apache.commons.imaging.ImageParser; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.BasicCParser; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.common.bytesource.ByteSource; import org.apache.commons.imaging.util.IoUtils; -import static org.apache.commons.imaging.ImagingConstants.*; public class XbmImageParser extends ImageParser { private static final String DEFAULT_EXTENSION = ".xbm"; @@ -75,13 +74,13 @@ protected ImageFormat[] getAcceptedTypes() { } @Override - public ImageMetadata getMetadata(final ByteSource byteSource, final Map params) + public ImageMetadata getMetadata(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } @Override - public ImageInfo getImageInfo(final ByteSource byteSource, final Map params) + public ImageInfo getImageInfo(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final XbmHeader xbmHeader = readXbmHeader(byteSource); return new ImageInfo("XBM", 1, new ArrayList(), @@ -92,14 +91,14 @@ public ImageInfo getImageInfo(final ByteSource byteSource, final Map params) + public Dimension getImageSize(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final XbmHeader xbmHeader = readXbmHeader(byteSource); return new Dimension(xbmHeader.width, xbmHeader.height); } @Override - public byte[] getICCProfileBytes(final ByteSource byteSource, final Map params) + public byte[] getICCProfileBytes(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } @@ -292,7 +291,7 @@ public boolean dumpImageFile(final PrintWriter pw, final ByteSource byteSource) @Override public final BufferedImage getBufferedImage(final ByteSource byteSource, - final Map params) throws ImageReadException, IOException { + final ImagingParameters params) throws ImageReadException, IOException { final XbmParseResult result = parseXbmHeader(byteSource); return readXbmImage(result.xbmHeader, result.cParser); } @@ -323,20 +322,8 @@ private String toPrettyHex(final int value) { } @Override - public void writeImage(final BufferedImage src, final OutputStream os, Map params) + public void writeImage(final BufferedImage src, final OutputStream os, final ImagingParameters params) throws ImageWriteException, IOException { - // make copy of params; we'll clear keys as we consume them. - params = (params == null) ? new HashMap() : new HashMap(params); - - // clear format key. - if (params.containsKey(PARAM_KEY_FORMAT)) { - params.remove(PARAM_KEY_FORMAT); - } - - if (!params.isEmpty()) { - final Object firstKey = params.keySet().iterator().next(); - throw new ImageWriteException("Unknown parameter: " + firstKey); - } final String name = randomName(); @@ -404,9 +391,11 @@ public void writeImage(final BufferedImage src, final OutputStream os, Map params) + public String getXmpXml(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } diff --git a/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java b/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java index 820167134..92a593746 100644 --- a/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java +++ b/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java @@ -10,7 +10,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * under the License. */ package org.apache.commons.imaging.formats.xpm; @@ -45,6 +44,7 @@ import org.apache.commons.imaging.ImageParser; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.BasicCParser; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.common.bytesource.ByteSource; @@ -52,7 +52,6 @@ import org.apache.commons.imaging.palette.SimplePalette; import org.apache.commons.imaging.util.IoUtils; -import static org.apache.commons.imaging.ImagingConstants.*; public class XpmImageParser extends ImageParser { private static final String DEFAULT_EXTENSION = ".xpm"; @@ -134,13 +133,13 @@ protected ImageFormat[] getAcceptedTypes() { } @Override - public ImageMetadata getMetadata(final ByteSource byteSource, final Map params) + public ImageMetadata getMetadata(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } @Override - public ImageInfo getImageInfo(final ByteSource byteSource, final Map params) + public ImageInfo getImageInfo(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final XpmHeader xpmHeader = readXpmHeader(byteSource); boolean transparent = false; @@ -166,14 +165,14 @@ public ImageInfo getImageInfo(final ByteSource byteSource, final Map params) + public Dimension getImageSize(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { final XpmHeader xpmHeader = readXpmHeader(byteSource); return new Dimension(xpmHeader.width, xpmHeader.height); } @Override - public byte[] getICCProfileBytes(final ByteSource byteSource, final Map params) + public byte[] getICCProfileBytes(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } @@ -605,7 +604,7 @@ public boolean dumpImageFile(final PrintWriter pw, final ByteSource byteSource) @Override public final BufferedImage getBufferedImage(final ByteSource byteSource, - final Map params) throws ImageReadException, IOException { + final ImagingParameters params) throws ImageReadException, IOException { final XpmParseResult result = parseXpmHeader(byteSource); return readXpmImage(result.xpmHeader, result.cParser); } @@ -651,20 +650,8 @@ private String toColor(final int color) { } @Override - public void writeImage(final BufferedImage src, final OutputStream os, Map params) + public void writeImage(final BufferedImage src, final OutputStream os, final ImagingParameters params) throws ImageWriteException, IOException { - // make copy of params; we'll clear keys as we consume them. - params = (params == null) ? new HashMap() : new HashMap(params); - - // clear format key. - if (params.containsKey(PARAM_KEY_FORMAT)) { - params.remove(PARAM_KEY_FORMAT); - } - - if (!params.isEmpty()) { - final Object firstKey = params.keySet().iterator().next(); - throw new ImageWriteException("Unknown parameter: " + firstKey); - } final PaletteFactory paletteFactory = new PaletteFactory(); boolean hasTransparency = false; @@ -741,9 +728,11 @@ public void writeImage(final BufferedImage src, final OutputStream os, Map params) + public String getXmpXml(final ByteSource byteSource, final ImagingParameters params) throws ImageReadException, IOException { return null; } diff --git a/src/test/java/org/apache/commons/imaging/ImagingParametersTest.java b/src/test/java/org/apache/commons/imaging/ImagingParametersTest.java new file mode 100644 index 000000000..3ee9e971b --- /dev/null +++ b/src/test/java/org/apache/commons/imaging/ImagingParametersTest.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.imaging; + +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * Tests for ImagingParameters. + */ +public final class ImagingParametersTest { + /** + * Asserts that an exception is thrown if the provided value is null. + */ + @Test(expected=IllegalArgumentException.class) + public void testCheckIfValueIsNull01() { + ImagingParameters ip = new ImagingParameters(); + ip.setFileNameHint(null); + } + + /** + * Test if the exception thrown if the provided value is null + * provides the parameter name. + */ + @Test + public void testCheckIfValueIsNull02() { + ImagingParameters ip = new ImagingParameters(); + try { + ip.setFileNameHint(null); + } + catch (IllegalArgumentException ex) { + assertEquals("The value for the parameter fileNameHint must not null.", ex.getLocalizedMessage()); + } + } + + /** + * Asserts that no exception is thrown if the provided value is not null. + */ + @Test + public void testCheckIfValueIsNull03() { + ImagingParameters ip = new ImagingParameters(); + ip.setFileNameHint("Teststring"); + assertEquals("Teststring", ip.getFileNameHint()); + } + + /** + * Asserts that an exception is thrown if the parameter is accessed before a value was provided. + */ + @Test(expected=IllegalStateException.class) + public void testCheckIfParameterIsPresent01() { + ImagingParameters ip = new ImagingParameters(); + ip.getFileNameHint(); + } + + /** + * Asserts that no exception is thrown if the parameter is accessed after a value was provided. + */ + @Test + public void testCheckIfParameterIsPresent02() { + ImagingParameters ip = new ImagingParameters(); + ip.setFileNameHint("Teststring"); + assertEquals("Teststring", ip.getFileNameHint()); + } +} \ No newline at end of file diff --git a/src/test/java/org/apache/commons/imaging/common/bytesource/ByteSourceImageTest.java b/src/test/java/org/apache/commons/imaging/common/bytesource/ByteSourceImageTest.java index eb7c2eede..7d4d867d4 100644 --- a/src/test/java/org/apache/commons/imaging/common/bytesource/ByteSourceImageTest.java +++ b/src/test/java/org/apache/commons/imaging/common/bytesource/ByteSourceImageTest.java @@ -29,15 +29,15 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Collection; -import java.util.HashMap; -import java.util.Map; import org.apache.commons.imaging.ImageFormat; import org.apache.commons.imaging.ImageFormats; import org.apache.commons.imaging.ImageInfo; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.Imaging; -import org.apache.commons.imaging.ImagingConstants; +import org.apache.commons.imaging.ImagingParameters; +import org.apache.commons.imaging.ImagingParametersJpeg; +import org.apache.commons.imaging.ImagingParametersTiff; import org.apache.commons.imaging.util.Debug; import org.apache.commons.io.FileUtils; import org.junit.Test; @@ -169,12 +169,22 @@ public void checkGetICCProfileBytes(final File imageFile, final byte[] imageFile public void checkGetImageInfo(final File imageFile, final byte[] imageFileBytes) throws IOException, ImageReadException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { - final Map params = new HashMap(); + + final ImagingParameters params; final boolean ignoreImageData = isPhilHarveyTestImage(imageFile); final ImageFormat imageFormat = Imaging.guessFormat(imageFile); - if (imageFormat.equals(ImageFormats.TIFF) - || imageFormat.equals(ImageFormats.JPEG)) { - params.put(ImagingConstants.PARAM_KEY_READ_THUMBNAILS, new Boolean(!ignoreImageData)); + if (imageFormat.equals(ImageFormats.TIFF)) { + final ImagingParametersTiff paramsTiff = new ImagingParametersTiff(); + if (ignoreImageData == false) paramsTiff.setReadThumbnails(true); + params = paramsTiff; + } + else if (imageFormat.equals(ImageFormats.JPEG)) { + final ImagingParametersJpeg paramsJpeg = new ImagingParametersJpeg(); + if (ignoreImageData == false) paramsJpeg.setReadThumbnails(true); + params = paramsJpeg; + } + else { + params = new ImagingParameters(); } final ImageInfo imageInfoFile = Imaging.getImageInfo(imageFile, params); diff --git a/src/test/java/org/apache/commons/imaging/examples/ApacheImagingSpeedAndMemoryTest.java b/src/test/java/org/apache/commons/imaging/examples/ApacheImagingSpeedAndMemoryTest.java index c1234fd0f..ce7424cfa 100644 --- a/src/test/java/org/apache/commons/imaging/examples/ApacheImagingSpeedAndMemoryTest.java +++ b/src/test/java/org/apache/commons/imaging/examples/ApacheImagingSpeedAndMemoryTest.java @@ -159,9 +159,9 @@ import java.io.File; import java.io.IOException; import java.util.Formatter; -import java.util.HashMap; import org.apache.commons.imaging.ImageReadException; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.bytesource.ByteSourceFile; import org.apache.commons.imaging.formats.tiff.TiffImageParser; @@ -213,7 +213,7 @@ private void performTest(final String name) { // ready the parser (you may modify this code block // to use your parser of choice) - HashMap params = new HashMap(); + ImagingParameters params = new ImagingParameters(); TiffImageParser tiffImageParser = new TiffImageParser(); // load the file and record time needed to do so diff --git a/src/test/java/org/apache/commons/imaging/examples/ImageReadExample.java b/src/test/java/org/apache/commons/imaging/examples/ImageReadExample.java index 37bb74d9d..d8c432dad 100644 --- a/src/test/java/org/apache/commons/imaging/examples/ImageReadExample.java +++ b/src/test/java/org/apache/commons/imaging/examples/ImageReadExample.java @@ -20,24 +20,21 @@ import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.Imaging; -import org.apache.commons.imaging.ImagingConstants; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.BufferedImageFactory; public class ImageReadExample { public static BufferedImage imageReadExample(final File file) throws ImageReadException, IOException { - final Map params = new HashMap(); + final ImagingParameters params = new ImagingParameters(); // set optional parameters if you like - params.put(ImagingConstants.BUFFERED_IMAGE_FACTORY, - new ManagedImageBufferedImageFactory()); + params.setBufferedImageFactory(new ManagedImageBufferedImageFactory()); - // params.put(ImagingConstants.PARAM_KEY_VERBOSE, Boolean.TRUE); + // params.setVerbose(); // read image final BufferedImage image = Imaging.getBufferedImage(file, params); diff --git a/src/test/java/org/apache/commons/imaging/examples/ImageWriteExample.java b/src/test/java/org/apache/commons/imaging/examples/ImageWriteExample.java index 0093983df..92f8b68d6 100644 --- a/src/test/java/org/apache/commons/imaging/examples/ImageWriteExample.java +++ b/src/test/java/org/apache/commons/imaging/examples/ImageWriteExample.java @@ -19,15 +19,13 @@ import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; import org.apache.commons.imaging.ImageFormat; import org.apache.commons.imaging.ImageFormats; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; import org.apache.commons.imaging.Imaging; -import org.apache.commons.imaging.ImagingConstants; +import org.apache.commons.imaging.ImagingParametersTiff; import org.apache.commons.imaging.formats.tiff.constants.TiffConstants; public class ImageWriteExample { @@ -37,11 +35,10 @@ public static byte[] imageWriteExample(final File file) final BufferedImage image = Imaging.getBufferedImage(file); final ImageFormat format = ImageFormats.TIFF; - final Map params = new HashMap(); + final ImagingParametersTiff params = new ImagingParametersTiff(); // set optional parameters if you like - params.put(ImagingConstants.PARAM_KEY_COMPRESSION, new Integer( - TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED)); + params.setCompressionLevel(TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED); final byte[] bytes = Imaging.writeImageToBytes(image, format, params); diff --git a/src/test/java/org/apache/commons/imaging/examples/SampleUsage.java b/src/test/java/org/apache/commons/imaging/examples/SampleUsage.java index 4bb0d2093..4beb69023 100644 --- a/src/test/java/org/apache/commons/imaging/examples/SampleUsage.java +++ b/src/test/java/org/apache/commons/imaging/examples/SampleUsage.java @@ -22,14 +22,13 @@ import java.io.File; import java.io.InputStream; import java.io.OutputStream; -import java.util.HashMap; -import java.util.Map; import org.apache.commons.imaging.FormatCompliance; import org.apache.commons.imaging.ImageFormat; import org.apache.commons.imaging.ImageFormats; import org.apache.commons.imaging.ImageInfo; import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.ImageMetadata; public class SampleUsage { @@ -67,7 +66,7 @@ public SampleUsage() { final BufferedImage image = someImage; final File dst = someFile; final ImageFormat format = ImageFormats.PNG; - final Map optionalParams = new HashMap(); + final ImagingParameters optionalParams = new ImagingParameters(); Imaging.writeImage(image, dst, format, optionalParams); final OutputStream os = someOutputStream; diff --git a/src/test/java/org/apache/commons/imaging/formats/bmp/BmpReadTest.java b/src/test/java/org/apache/commons/imaging/formats/bmp/BmpReadTest.java index d17e3af25..8c1d39b0b 100644 --- a/src/test/java/org/apache/commons/imaging/formats/bmp/BmpReadTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/bmp/BmpReadTest.java @@ -23,12 +23,11 @@ import java.io.File; import java.io.IOException; import java.util.Collection; -import java.util.Collections; -import java.util.Map; import org.apache.commons.imaging.ImageInfo; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.ImagingParameters; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -37,7 +36,7 @@ @RunWith(Parameterized.class) public class BmpReadTest extends BmpBaseTest { - private File imageFile; + private final File imageFile; @Parameterized.Parameters public static Collection data() throws Exception { @@ -50,7 +49,7 @@ public BmpReadTest(File imageFile) { @Test public void testImageInfo() throws ImageReadException, IOException { - final Map params = Collections.emptyMap(); + final ImagingParameters params = new ImagingParameters(); final ImageInfo imageInfo = Imaging.getImageInfo(imageFile, params); assertNotNull(imageInfo); // TODO assert more diff --git a/src/test/java/org/apache/commons/imaging/formats/bmp/BmpRoundtripTest.java b/src/test/java/org/apache/commons/imaging/formats/bmp/BmpRoundtripTest.java index 6921402c3..3c1e40742 100644 --- a/src/test/java/org/apache/commons/imaging/formats/bmp/BmpRoundtripTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/bmp/BmpRoundtripTest.java @@ -23,14 +23,13 @@ import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; import java.util.Random; import org.apache.commons.imaging.ImageFormats; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.util.Debug; import org.apache.commons.io.FileUtils; import org.junit.Test; @@ -140,7 +139,7 @@ private void writeAndReadImageData(final int[][] rawData) throws IOException, ImageReadException, ImageWriteException { final BufferedImage srcImage = imageDataToBufferedImage(rawData); - final Map writeParams = new HashMap(); + final ImagingParameters writeParams = new ImagingParameters(); // writeParams.put(ImagingConstants.PARAM_KEY_FORMAT, // ImageFormat.IMAGE_FORMAT_BMP); // writeParams.put(PngConstants.PARAM_KEY_BMP_FORCE_TRUE_COLOR, diff --git a/src/test/java/org/apache/commons/imaging/formats/dcx/DcxReadTest.java b/src/test/java/org/apache/commons/imaging/formats/dcx/DcxReadTest.java index bcddec686..86b85fcba 100644 --- a/src/test/java/org/apache/commons/imaging/formats/dcx/DcxReadTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/dcx/DcxReadTest.java @@ -25,6 +25,7 @@ import java.util.Collections; import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.ImagingParameters; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -33,7 +34,7 @@ @RunWith(Parameterized.class) public class DcxReadTest extends DcxBaseTest { - private File imageFile; + private final File imageFile; @Parameterized.Parameters public static Collection data() throws Exception { @@ -53,7 +54,7 @@ public void testImageMetadata() throws Exception { @Ignore(value = "RoundtripTest has to be fixed befor implementation can throw UnsupportedOperationException") @Test(expected = UnsupportedOperationException.class) public void testImageInfo() throws Exception { - Imaging.getImageInfo(imageFile, Collections. emptyMap()); + Imaging.getImageInfo(imageFile, new ImagingParameters()); } @Test 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 9c13dfd92..01c5e3ae4 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 @@ -22,13 +22,10 @@ import java.awt.image.BufferedImage; import java.io.File; import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import org.apache.commons.imaging.ImageInfo; import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.util.Debug; import org.junit.Assert; @@ -59,7 +56,7 @@ public void testImageMetadata() throws Exception { @Test public void testImageInfo() throws Exception { - final ImageInfo imageInfo = Imaging.getImageInfo(imageFile, Collections. emptyMap()); + final ImageInfo imageInfo = Imaging.getImageInfo(imageFile, new ImagingParameters()); assertNotNull(imageInfo); } diff --git a/src/test/java/org/apache/commons/imaging/formats/ico/IcoReadTest.java b/src/test/java/org/apache/commons/imaging/formats/ico/IcoReadTest.java index 41e1ffb33..f9cd3d5f3 100644 --- a/src/test/java/org/apache/commons/imaging/formats/ico/IcoReadTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/ico/IcoReadTest.java @@ -22,13 +22,10 @@ import java.awt.image.BufferedImage; import java.io.File; import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import org.apache.commons.imaging.ImageInfo; import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.util.Debug; import org.junit.Assert; @@ -40,7 +37,7 @@ @RunWith(Parameterized.class) public class IcoReadTest extends IcoBaseTest { - private File imageFile; + private final File imageFile; @Parameterized.Parameters public static Collection data() throws Exception { @@ -60,7 +57,7 @@ public void testMetadata() throws Exception { @Ignore(value = "RoundtripTest has to be fixed befor implementation can throw UnsupportedOperationException") @Test(expected = UnsupportedOperationException.class) public void testImageInfo() throws Exception { - Imaging.getImageInfo(imageFile, Collections. emptyMap()); + Imaging.getImageInfo(imageFile, new ImagingParameters()); } @Test diff --git a/src/test/java/org/apache/commons/imaging/formats/jpeg/JpegReadTest.java b/src/test/java/org/apache/commons/imaging/formats/jpeg/JpegReadTest.java index 314d7c3e6..30eabb5fa 100644 --- a/src/test/java/org/apache/commons/imaging/formats/jpeg/JpegReadTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/jpeg/JpegReadTest.java @@ -23,13 +23,11 @@ import java.awt.image.BufferedImage; import java.io.File; import java.util.Collection; -import java.util.HashMap; -import java.util.Map; import org.apache.commons.imaging.ImageInfo; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.Imaging; -import org.apache.commons.imaging.ImagingConstants; +import org.apache.commons.imaging.ImagingParametersJpeg; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.util.Debug; import org.junit.Test; @@ -39,7 +37,7 @@ @RunWith(Parameterized.class) public class JpegReadTest extends JpegBaseTest { - private File imageFile; + private final File imageFile; @Parameterized.Parameters public static Collection data() throws Exception{ @@ -52,9 +50,9 @@ public JpegReadTest(File imageFile) { @Test public void test() throws Exception { - final Map params = new HashMap(); + final ImagingParametersJpeg params = new ImagingParametersJpeg(); final boolean ignoreImageData = isPhilHarveyTestImage(imageFile); - params.put(ImagingConstants.PARAM_KEY_READ_THUMBNAILS, new Boolean(!ignoreImageData)); + if (ignoreImageData == false) params.setReadThumbnails(true); final ImageMetadata metadata = Imaging.getMetadata(imageFile, params); // TODO only run this tests with images that have metadata... diff --git a/src/test/java/org/apache/commons/imaging/formats/jpeg/JpegWithJpegThumbnailTest.java b/src/test/java/org/apache/commons/imaging/formats/jpeg/JpegWithJpegThumbnailTest.java index 8b8706808..8de959903 100644 --- a/src/test/java/org/apache/commons/imaging/formats/jpeg/JpegWithJpegThumbnailTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/jpeg/JpegWithJpegThumbnailTest.java @@ -21,10 +21,9 @@ import java.awt.image.BufferedImage; import java.io.File; -import java.util.HashMap; -import java.util.Map; import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.ImagingTest; import org.apache.commons.imaging.common.ImageMetadata; import org.junit.Test; @@ -35,7 +34,7 @@ public class JpegWithJpegThumbnailTest extends ImagingTest { public void testSingleImage() throws Exception { final File imageFile = getTestImageByName("img_F028c_small.jpg"); - final Map params = new HashMap(); + final ImagingParameters params = new ImagingParameters(); final ImageMetadata metadata = Imaging.getMetadata(imageFile, params); assertNotNull(metadata); final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; diff --git a/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/AsciiFieldTest.java b/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/AsciiFieldTest.java index e2c028a3d..2147ac03f 100644 --- a/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/AsciiFieldTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/AsciiFieldTest.java @@ -27,6 +27,7 @@ import java.util.Map; import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; import org.apache.commons.imaging.formats.tiff.TiffField; @@ -40,7 +41,7 @@ public class AsciiFieldTest extends ExifBaseTest { public void testSingleImage() throws Exception { final File imageFile = getTestImageByName("Canon Powershot SD750 - 2007.12.26.n.IMG_3704.JPG"); - final Map params = new HashMap(); + final ImagingParameters params = new ImagingParameters(); final ImageMetadata metadata = Imaging.getMetadata(imageFile, params); assertNotNull(metadata); diff --git a/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/ExifDumpTest.java b/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/ExifDumpTest.java index 1357a1c48..89a5c19e8 100644 --- a/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/ExifDumpTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/ExifDumpTest.java @@ -21,12 +21,9 @@ import java.io.File; import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import org.apache.commons.imaging.Imaging; -import org.apache.commons.imaging.ImagingConstants; +import org.apache.commons.imaging.ImagingParametersJpeg; import org.apache.commons.imaging.common.bytesource.ByteSource; import org.apache.commons.imaging.common.bytesource.ByteSourceFile; import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; @@ -39,7 +36,7 @@ @RunWith(Parameterized.class) public class ExifDumpTest extends ExifBaseTest { - private File imageFile; + private final File imageFile; @Parameterized.Parameters public static Collection data() throws Exception { @@ -60,10 +57,10 @@ public void testDumpJFIF() throws Exception { @Test public void testMetadata() throws Exception { - final Map params = new HashMap(); + final ImagingParametersJpeg params = new ImagingParametersJpeg(); final boolean ignoreImageData = isPhilHarveyTestImage(imageFile); - params.put(ImagingConstants.PARAM_KEY_READ_THUMBNAILS, Boolean.valueOf(!ignoreImageData)); - + if (ignoreImageData == false) params.setReadThumbnails(true); + final JpegImageMetadata metadata = (JpegImageMetadata) Imaging.getMetadata(imageFile, params); assertNotNull(metadata); // TODO assert more diff --git a/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/GpsTest.java b/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/GpsTest.java index e060c7f1a..c563c5db3 100644 --- a/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/GpsTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/GpsTest.java @@ -19,12 +19,9 @@ import java.io.File; import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import org.apache.commons.imaging.Imaging; -import org.apache.commons.imaging.ImagingConstants; +import org.apache.commons.imaging.ImagingParametersJpeg; import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; import org.apache.commons.imaging.util.Debug; @@ -35,7 +32,7 @@ @RunWith(Parameterized.class) public class GpsTest extends ExifBaseTest { - private File imageFile; + private final File imageFile; @Parameterized.Parameters public static Collection data() throws Exception { @@ -53,9 +50,9 @@ public void test() throws Exception { return; } - final Map params = new HashMap(); + final ImagingParametersJpeg params = new ImagingParametersJpeg(); final boolean ignoreImageData = isPhilHarveyTestImage(imageFile); - params.put(ImagingConstants.PARAM_KEY_READ_THUMBNAILS, Boolean.valueOf(!ignoreImageData)); + if (ignoreImageData == false) params.setReadThumbnails(true); final JpegImageMetadata metadata = (JpegImageMetadata) Imaging .getMetadata(imageFile, params); diff --git a/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/MicrosoftTagTest.java b/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/MicrosoftTagTest.java index 4c3dd7b0d..a191e172a 100644 --- a/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/MicrosoftTagTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/MicrosoftTagTest.java @@ -21,17 +21,14 @@ import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.File; -import java.util.Map; -import java.util.TreeMap; import org.apache.commons.imaging.ImageFormats; import org.apache.commons.imaging.Imaging; -import org.apache.commons.imaging.ImagingConstants; +import org.apache.commons.imaging.ImagingParametersTiff; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; import org.apache.commons.imaging.formats.tiff.constants.MicrosoftTagConstants; -import org.apache.commons.imaging.formats.tiff.constants.TiffConstants; import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory; import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; import org.junit.Test; @@ -51,8 +48,10 @@ public void testWrite() throws Exception { exif.add(MicrosoftTagConstants.EXIF_TAG_XPCOMMENT, COMMENT); exif.add(MicrosoftTagConstants.EXIF_TAG_XPSUBJECT, SUBJECT); exif.add(MicrosoftTagConstants.EXIF_TAG_XPTITLE, TITLE); - final Map params = new TreeMap(); - params.put(ImagingConstants.PARAM_KEY_EXIF, exifSet); + + final ImagingParametersTiff params = new ImagingParametersTiff(); + params.setOutputSet(exifSet); + final byte[] bytes = Imaging.writeImageToBytes(image, ImageFormats.TIFF, params); checkFields(bytes); } diff --git a/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/SpecificExifTagTest.java b/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/SpecificExifTagTest.java index 270e710cb..b90242d67 100644 --- a/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/SpecificExifTagTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/SpecificExifTagTest.java @@ -20,14 +20,12 @@ import java.io.File; import java.io.IOException; import java.util.Collection; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; import org.apache.commons.imaging.Imaging; -import org.apache.commons.imaging.ImagingConstants; +import org.apache.commons.imaging.ImagingParametersJpeg; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; import org.apache.commons.imaging.formats.tiff.TiffField; @@ -39,7 +37,7 @@ @RunWith(Parameterized.class) public abstract class SpecificExifTagTest extends ExifBaseTest { - private File imageFile; + private final File imageFile; @Parameterized.Parameters public static Collection data() throws Exception { @@ -66,9 +64,9 @@ private void checkImage(final File imageFile) throws IOException, ImageReadException, ImageWriteException { // Debug.debug("imageFile", imageFile.getAbsoluteFile()); - final Map params = new HashMap(); + final ImagingParametersJpeg params = new ImagingParametersJpeg(); final boolean ignoreImageData = isPhilHarveyTestImage(imageFile); - params.put(ImagingConstants.PARAM_KEY_READ_THUMBNAILS, Boolean.valueOf(!ignoreImageData)); + if (ignoreImageData == false) params.setReadThumbnails(true); // note that metadata might be null if no metadata is found. final ImageMetadata metadata = Imaging.getMetadata(imageFile, params); diff --git a/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcAddTest.java b/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcAddTest.java index 5b69aef10..39f728768 100644 --- a/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcAddTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcAddTest.java @@ -26,11 +26,8 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.List; -import java.util.Map; - -import org.apache.commons.imaging.ImagingConstants; +import org.apache.commons.imaging.ImagingParametersJpeg; import org.apache.commons.imaging.common.bytesource.ByteSource; import org.apache.commons.imaging.common.bytesource.ByteSourceFile; import org.apache.commons.imaging.formats.jpeg.JpegImageParser; @@ -43,7 +40,7 @@ @RunWith(Parameterized.class) public class IptcAddTest extends IptcBaseTest { - private File imageFile; + private final File imageFile; @Parameterized.Parameters public static Collection data() throws Exception { @@ -62,9 +59,9 @@ public IptcAddTest(File imageFile) { public void testAddIptcData() throws Exception { final ByteSource byteSource = new ByteSourceFile(imageFile); - final Map params = new HashMap(); + final ImagingParametersJpeg params = new ImagingParametersJpeg(); final boolean ignoreImageData = isPhilHarveyTestImage(imageFile); - params.put(ImagingConstants.PARAM_KEY_READ_THUMBNAILS, Boolean.valueOf(!ignoreImageData)); + if (ignoreImageData == false) params.setReadThumbnails(true); final JpegPhotoshopMetadata metadata = new JpegImageParser().getPhotoshopMetadata(byteSource, params); if (metadata == null) { diff --git a/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcDumpTest.java b/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcDumpTest.java index d886b5194..110670a13 100644 --- a/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcDumpTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcDumpTest.java @@ -21,12 +21,10 @@ import java.io.File; import java.util.Collection; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.Imaging; -import org.apache.commons.imaging.ImagingConstants; +import org.apache.commons.imaging.ImagingParametersJpeg; import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; import org.apache.commons.imaging.formats.jpeg.JpegPhotoshopMetadata; import org.apache.commons.imaging.util.Debug; @@ -37,7 +35,7 @@ @RunWith(Parameterized.class) public class IptcDumpTest extends IptcBaseTest { - private File imageFile; + private final File imageFile; @Parameterized.Parameters public static Collection data() throws Exception { @@ -50,9 +48,9 @@ public IptcDumpTest(File imageFile) { @Test public void test() throws Exception { - final Map params = new HashMap(); + final ImagingParametersJpeg params = new ImagingParametersJpeg(); final boolean ignoreImageData = isPhilHarveyTestImage(imageFile); - params.put(ImagingConstants.PARAM_KEY_READ_THUMBNAILS, Boolean.valueOf(!ignoreImageData)); + if (ignoreImageData == false) params.setReadThumbnails(true); final JpegImageMetadata metadata = (JpegImageMetadata) Imaging.getMetadata(imageFile, params); assertNotNull(metadata); diff --git a/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcUpdateTest.java b/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcUpdateTest.java index 639c88cf7..eef9b44c6 100644 --- a/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcUpdateTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcUpdateTest.java @@ -27,14 +27,11 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; -import org.apache.commons.imaging.Imaging; -import org.apache.commons.imaging.ImagingConstants; +import org.apache.commons.imaging.ImagingParametersJpeg; import org.apache.commons.imaging.common.bytesource.ByteSource; import org.apache.commons.imaging.common.bytesource.ByteSourceFile; import org.apache.commons.imaging.formats.jpeg.JpegImageParser; @@ -46,7 +43,7 @@ @RunWith(Parameterized.class) public class IptcUpdateTest extends IptcBaseTest { - private File imageFile; + private final File imageFile; @Parameterized.Parameters public static Collection data() throws Exception { @@ -64,9 +61,9 @@ public IptcUpdateTest(File imageFile) { public void testRemove() throws Exception { final ByteSource byteSource = new ByteSourceFile(imageFile); - final Map params = new HashMap(); + final ImagingParametersJpeg params = new ImagingParametersJpeg(); final boolean ignoreImageData = isPhilHarveyTestImage(imageFile); - params.put(ImagingConstants.PARAM_KEY_READ_THUMBNAILS, Boolean.valueOf(!ignoreImageData)); + if (ignoreImageData == false) params.setReadThumbnails(true); final JpegPhotoshopMetadata metadata = new JpegImageParser() .getPhotoshopMetadata(byteSource, params); @@ -97,9 +94,9 @@ public File removeIptc(ByteSource byteSource) throws Exception { public void testInsert() throws Exception { final ByteSource byteSource = new ByteSourceFile(imageFile); - final Map params = new HashMap(); + final ImagingParametersJpeg params = new ImagingParametersJpeg(); final boolean ignoreImageData = isPhilHarveyTestImage(imageFile); - params.put(ImagingConstants.PARAM_KEY_READ_THUMBNAILS, Boolean.valueOf(!ignoreImageData)); + if (ignoreImageData == false) params.setReadThumbnails(true); final JpegPhotoshopMetadata metadata = new JpegImageParser().getPhotoshopMetadata(byteSource, params); assertNotNull(metadata); @@ -142,9 +139,9 @@ public void testInsert() throws Exception { public void testUpdate() throws Exception { final ByteSource byteSource = new ByteSourceFile(imageFile); - final Map params = new HashMap(); + final ImagingParametersJpeg params = new ImagingParametersJpeg(); final boolean ignoreImageData = isPhilHarveyTestImage(imageFile); - params.put(ImagingConstants.PARAM_KEY_READ_THUMBNAILS, Boolean.valueOf(!ignoreImageData)); + if (ignoreImageData == false) params.setReadThumbnails(true); final JpegPhotoshopMetadata metadata = new JpegImageParser().getPhotoshopMetadata(byteSource, params); assertNotNull(metadata); @@ -189,9 +186,9 @@ public File writeIptc(ByteSource byteSource, PhotoshopApp13Data newData) throws public void testNoChangeUpdate() throws Exception { final ByteSource byteSource = new ByteSourceFile(imageFile); - final Map params = new HashMap(); + final ImagingParametersJpeg params = new ImagingParametersJpeg(); final boolean ignoreImageData = isPhilHarveyTestImage(imageFile); - params.put(ImagingConstants.PARAM_KEY_READ_THUMBNAILS, Boolean.valueOf(!ignoreImageData)); + if (ignoreImageData == false) params.setReadThumbnails(true); final JpegPhotoshopMetadata metadata = new JpegImageParser().getPhotoshopMetadata(byteSource, params); assertNotNull(metadata); diff --git a/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpDumpTest.java b/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpDumpTest.java index 9395c5613..f1e1b9750 100644 --- a/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpDumpTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpDumpTest.java @@ -21,8 +21,7 @@ import java.io.File; import java.util.Collection; -import java.util.HashMap; -import java.util.Map; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.bytesource.ByteSource; import org.apache.commons.imaging.common.bytesource.ByteSourceFile; @@ -34,7 +33,7 @@ @RunWith(Parameterized.class) public class JpegXmpDumpTest extends JpegXmpBaseTest { - private File imageFile; + private final File imageFile; @Parameterized.Parameters public static Collection data() throws Exception { @@ -48,7 +47,7 @@ public JpegXmpDumpTest(File imageFile) { @Test public void test() throws Exception { final ByteSource byteSource = new ByteSourceFile(imageFile); - final Map params = new HashMap(); + final ImagingParameters params = new ImagingParameters(); final String xmpXml = new JpegImageParser().getXmpXml(byteSource, params); // TODO assert more diff --git a/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpRewriteTest.java b/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpRewriteTest.java index 306b46004..9093f4780 100644 --- a/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpRewriteTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpRewriteTest.java @@ -26,8 +26,7 @@ import java.io.FileOutputStream; import java.io.OutputStream; import java.util.Collection; -import java.util.HashMap; -import java.util.Map; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.bytesource.ByteSource; import org.apache.commons.imaging.common.bytesource.ByteSourceFile; @@ -40,7 +39,7 @@ @RunWith(Parameterized.class) public class JpegXmpRewriteTest extends JpegXmpBaseTest { - private File imageFile; + private final File imageFile; @Parameterized.Parameters public static Collection data() throws Exception { @@ -54,7 +53,7 @@ public JpegXmpRewriteTest(File imageFile) { @Test public void testRemoveInsertUpdate() throws Exception { final ByteSource byteSource = new ByteSourceFile(imageFile); - final Map params = new HashMap(); + final ImagingParameters params = new ImagingParameters(); final String xmpXml = new JpegImageParser().getXmpXml(byteSource, params); assertNotNull(xmpXml); diff --git a/src/test/java/org/apache/commons/imaging/formats/pam/PamReadTest.java b/src/test/java/org/apache/commons/imaging/formats/pam/PamReadTest.java index 872afe6fb..655a610fd 100644 --- a/src/test/java/org/apache/commons/imaging/formats/pam/PamReadTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/pam/PamReadTest.java @@ -21,12 +21,11 @@ import java.awt.image.BufferedImage; import java.io.File; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.ImageInfo; import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.util.Debug; import org.junit.Assert; @@ -47,7 +46,7 @@ public void test() throws Exception { final ImageMetadata metadata = Imaging.getMetadata(imageFile); Assert.assertFalse(metadata instanceof File); // Dummy check to avoid unused warning (it may be null) - final Map params = new HashMap(); + final ImagingParameters params = new ImagingParameters(); final ImageInfo imageInfo = Imaging.getImageInfo(imageFile, params); assertNotNull(imageInfo); diff --git a/src/test/java/org/apache/commons/imaging/formats/pcx/PcxReadTest.java b/src/test/java/org/apache/commons/imaging/formats/pcx/PcxReadTest.java index 6fc56dabc..454c3b175 100644 --- a/src/test/java/org/apache/commons/imaging/formats/pcx/PcxReadTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/pcx/PcxReadTest.java @@ -21,12 +21,11 @@ import java.awt.image.BufferedImage; import java.io.File; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.ImageInfo; import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.util.Debug; import org.junit.Assert; @@ -47,7 +46,7 @@ public void test() throws Exception { final ImageMetadata metadata = Imaging.getMetadata(imageFile); Assert.assertFalse(metadata instanceof File); // Dummy check to avoid unused warning (it may be null) - final Map params = new HashMap(); + final ImagingParameters params = new ImagingParameters(); final ImageInfo imageInfo = Imaging.getImageInfo(imageFile, params); assertNotNull(imageInfo); diff --git a/src/test/java/org/apache/commons/imaging/formats/png/ConvertPngToGifTest.java b/src/test/java/org/apache/commons/imaging/formats/png/ConvertPngToGifTest.java index 18e84a90f..3dab77597 100644 --- a/src/test/java/org/apache/commons/imaging/formats/png/ConvertPngToGifTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/png/ConvertPngToGifTest.java @@ -21,12 +21,11 @@ import java.awt.image.BufferedImage; import java.io.File; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.ImageFormats; import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.util.Debug; import org.junit.Test; @@ -46,8 +45,8 @@ public void test() throws Exception { // Debug.debug(); } - final Map params = new HashMap(); - // params.put(ImagingConstants.PARAM_KEY_VERBOSE, Boolean.TRUE); + final ImagingParameters params = new ImagingParameters(); + // params.setVerbose(); final BufferedImage image = Imaging.getBufferedImage(imageFile, params); assertNotNull(image); diff --git a/src/test/java/org/apache/commons/imaging/formats/png/PngMultipleRoundtripTest.java b/src/test/java/org/apache/commons/imaging/formats/png/PngMultipleRoundtripTest.java index 46541d10c..c2d4b07bd 100644 --- a/src/test/java/org/apache/commons/imaging/formats/png/PngMultipleRoundtripTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/png/PngMultipleRoundtripTest.java @@ -22,11 +22,10 @@ import java.awt.image.BufferedImage; import java.io.File; -import java.util.HashMap; -import java.util.Map; import org.apache.commons.imaging.ImageFormats; import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.util.Debug; import org.apache.commons.io.FilenameUtils; import org.junit.Test; @@ -55,20 +54,18 @@ public void test() throws Exception { File lastFile = imageFile; for (int j = 0; j < 10; j++) { - final Map readParams = new HashMap(); - // readParams.put(ImagingConstants.BUFFERED_IMAGE_FACTORY, - // new RgbBufferedImageFactory()); - final BufferedImage image = Imaging.getBufferedImage(lastFile, - readParams); + final ImagingParameters readParams = new ImagingParameters(); + // readParams.setBufferedImageFactory(new RgbBufferedImageFactory()); + + final BufferedImage image = Imaging.getBufferedImage(lastFile, readParams); assertNotNull(image); final File tempFile = createTempFile(imageFile.getName() + "." + j + ".", ".png"); Debug.debug("tempFile", tempFile); - - final Map writeParams = new HashMap(); - Imaging.writeImage(image, tempFile, - ImageFormats.PNG, writeParams); + + final ImagingParameters writeParams = new ImagingParameters(); + Imaging.writeImage(image, tempFile, ImageFormats.PNG, writeParams); lastFile = tempFile; } diff --git a/src/test/java/org/apache/commons/imaging/formats/png/PngTextTest.java b/src/test/java/org/apache/commons/imaging/formats/png/PngTextTest.java index 0c4e93208..d23941146 100644 --- a/src/test/java/org/apache/commons/imaging/formats/png/PngTextTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/png/PngTextTest.java @@ -25,12 +25,11 @@ import java.awt.image.BufferedImage; import java.io.File; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.ImageFormats; import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.ImagingParametersPng; import org.apache.commons.io.FileUtils; import org.junit.Test; @@ -40,11 +39,10 @@ public class PngTextTest extends PngBaseTest { public void test() throws Exception { final int width = 1; final int height = 1; - final BufferedImage srcImage = new BufferedImage(width, height, - BufferedImage.TYPE_INT_ARGB); + final BufferedImage srcImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); srcImage.setRGB(0, 0, Color.red.getRGB()); - final Map writeParams = new HashMap(); + final ImagingParametersPng writeParams = new ImagingParametersPng(); final List writeTexts = new ArrayList(); { @@ -65,11 +63,10 @@ public void test() throws Exception { writeTexts.add(new PngText.Itxt(keyword, text, languageTag, translatedKeyword)); } - - writeParams.put(PngConstants.PARAM_KEY_PNG_TEXT_CHUNKS, writeTexts); - - final byte[] bytes = Imaging.writeImageToBytes(srcImage, - ImageFormats.PNG, writeParams); + + writeParams.setTextChunks(writeTexts); + + final byte[] bytes = Imaging.writeImageToBytes(srcImage, ImageFormats.PNG, writeParams); final File tempFile = createTempFile("temp", ".png"); FileUtils.writeByteArrayToFile(tempFile, bytes); diff --git a/src/test/java/org/apache/commons/imaging/formats/png/PngWriteForceTrueColorText.java b/src/test/java/org/apache/commons/imaging/formats/png/PngWriteForceTrueColorText.java index fa1176c1a..95b9daef5 100644 --- a/src/test/java/org/apache/commons/imaging/formats/png/PngWriteForceTrueColorText.java +++ b/src/test/java/org/apache/commons/imaging/formats/png/PngWriteForceTrueColorText.java @@ -21,12 +21,12 @@ import java.awt.image.BufferedImage; import java.io.File; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.ImageFormats; import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.ImagingParameters; +import org.apache.commons.imaging.ImagingParametersPng; import org.apache.commons.imaging.util.Debug; import org.junit.Test; @@ -49,21 +49,17 @@ public void test() throws Exception { // params.put(ImagingConstants.PARAM_KEY_VERBOSE, // Boolean.TRUE); - final BufferedImage image = Imaging.getBufferedImage(imageFile, - new HashMap()); + final BufferedImage image = Imaging.getBufferedImage(imageFile, new ImagingParameters()); assertNotNull(image); final File outFile = createTempFile(imageFile.getName() + ".", ".gif"); // Debug.debug("outFile", outFile); - final Map params = new HashMap(); - params.put(PngConstants.PARAM_KEY_PNG_FORCE_TRUE_COLOR, - Boolean.TRUE); - Imaging.writeImage(image, outFile, - ImageFormats.PNG, params); + final ImagingParametersPng params = new ImagingParametersPng(); + params.setForceTrueColor(true); + Imaging.writeImage(image, outFile, ImageFormats.PNG, params); - final BufferedImage image2 = Imaging.getBufferedImage(outFile, - new HashMap()); + final BufferedImage image2 = Imaging.getBufferedImage(outFile, new ImagingParameters()); assertNotNull(image2); } catch (final Exception e) { Debug.debug("imageFile", imageFile); diff --git a/src/test/java/org/apache/commons/imaging/formats/png/PngWriteReadTest.java b/src/test/java/org/apache/commons/imaging/formats/png/PngWriteReadTest.java index aed494ae2..f30ecda27 100644 --- a/src/test/java/org/apache/commons/imaging/formats/png/PngWriteReadTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/png/PngWriteReadTest.java @@ -24,14 +24,13 @@ import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; import java.util.Random; import org.apache.commons.imaging.ImageFormats; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.ImagingParametersPng; import org.apache.commons.imaging.ImagingTest; import org.apache.commons.io.FileUtils; import org.junit.Test; @@ -137,11 +136,9 @@ private void writeAndReadImageData(final int[][] rawData) throws IOException, ImageReadException, ImageWriteException { final BufferedImage srcImage = imageDataToBufferedImage(rawData); - final Map writeParams = new HashMap(); - // writeParams.put(ImagingConstants.PARAM_KEY_FORMAT, - // ImageFormat.IMAGE_FORMAT_PNG); - // writeParams.put(PngConstants.PARAM_KEY_PNG_FORCE_TRUE_COLOR, - // Boolean.TRUE); + final ImagingParametersPng writeParams = new ImagingParametersPng(); + // writeParams.setImageFormat(ImageFormats.PNG); + // writeParams.setForceTrueColor(); final byte[] bytes = Imaging.writeImageToBytes(srcImage, ImageFormats.PNG, writeParams); diff --git a/src/test/java/org/apache/commons/imaging/formats/psd/PsdReadTest.java b/src/test/java/org/apache/commons/imaging/formats/psd/PsdReadTest.java index a1a085192..3fc5d7baa 100644 --- a/src/test/java/org/apache/commons/imaging/formats/psd/PsdReadTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/psd/PsdReadTest.java @@ -20,12 +20,11 @@ import java.awt.image.BufferedImage; import java.io.File; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.ImageInfo; import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.util.Debug; import org.junit.Assert; @@ -45,7 +44,7 @@ public void test() throws Exception { final ImageMetadata metadata = Imaging.getMetadata(imageFile); Assert.assertFalse(metadata instanceof File); // Dummy check to avoid unused warning (it may be null) - final Map params = new HashMap(); + final ImagingParameters params = new ImagingParameters(); final ImageInfo imageInfo = Imaging.getImageInfo(imageFile, params); assertNotNull(imageInfo); diff --git a/src/test/java/org/apache/commons/imaging/formats/tiff/TiffCcittTest.java b/src/test/java/org/apache/commons/imaging/formats/tiff/TiffCcittTest.java index 7eaa3bcbf..12ed166d6 100644 --- a/src/test/java/org/apache/commons/imaging/formats/tiff/TiffCcittTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/tiff/TiffCcittTest.java @@ -22,13 +22,12 @@ import java.awt.image.BufferedImage; import java.io.IOException; -import java.util.HashMap; import org.apache.commons.imaging.ImageFormats; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; import org.apache.commons.imaging.Imaging; -import org.apache.commons.imaging.ImagingConstants; +import org.apache.commons.imaging.ImagingParametersTiff; import org.apache.commons.imaging.common.itu_t4.T4AndT6Compression; import org.apache.commons.imaging.formats.tiff.constants.TiffConstants; import org.apache.commons.imaging.util.Debug; @@ -178,9 +177,9 @@ public void testAll5x2Images() { } try { - final HashMap params = new HashMap(); - params.put(ImagingConstants.PARAM_KEY_COMPRESSION, - TiffConstants.TIFF_COMPRESSION_CCITT_1D); + final ImagingParametersTiff params = new ImagingParametersTiff(); + params.setCompressionLevel(TiffConstants.TIFF_COMPRESSION_CCITT_1D); + final byte[] compressed = Imaging.writeImageToBytes(image, ImageFormats.TIFF, params); final BufferedImage result = Imaging.getBufferedImage(compressed); @@ -197,10 +196,10 @@ public void testAll5x2Images() { } try { - final HashMap params = new HashMap(); - params.put(ImagingConstants.PARAM_KEY_COMPRESSION, - TiffConstants.TIFF_COMPRESSION_CCITT_GROUP_3); - params.put(TiffConstants.PARAM_KEY_T4_OPTIONS, 0); + final ImagingParametersTiff params = new ImagingParametersTiff(); + params.setCompressionLevel(TiffConstants.TIFF_COMPRESSION_CCITT_GROUP_3); + params.setT4options(0); + final byte[] compressed = Imaging.writeImageToBytes(image, ImageFormats.TIFF, params); final BufferedImage result = Imaging.getBufferedImage(compressed); @@ -217,10 +216,10 @@ public void testAll5x2Images() { } try { - final HashMap params = new HashMap(); - params.put(ImagingConstants.PARAM_KEY_COMPRESSION, - TiffConstants.TIFF_COMPRESSION_CCITT_GROUP_3); - params.put(TiffConstants.PARAM_KEY_T4_OPTIONS, 4); + final ImagingParametersTiff params = new ImagingParametersTiff(); + params.setCompressionLevel(TiffConstants.TIFF_COMPRESSION_CCITT_GROUP_3); + params.setT4options(4); + final byte[] compressed = Imaging.writeImageToBytes(image, ImageFormats.TIFF, params); final BufferedImage result = Imaging.getBufferedImage(compressed); @@ -237,10 +236,10 @@ public void testAll5x2Images() { } try { - final HashMap params = new HashMap(); - params.put(ImagingConstants.PARAM_KEY_COMPRESSION, - TiffConstants.TIFF_COMPRESSION_CCITT_GROUP_3); - params.put(TiffConstants.PARAM_KEY_T4_OPTIONS, 1); + final ImagingParametersTiff params = new ImagingParametersTiff(); + params.setCompressionLevel(TiffConstants.TIFF_COMPRESSION_CCITT_GROUP_3); + params.setT4options(1); + final byte[] compressed = Imaging.writeImageToBytes(image, ImageFormats.TIFF, params); final BufferedImage result = Imaging.getBufferedImage(compressed); @@ -257,10 +256,10 @@ public void testAll5x2Images() { } try { - final HashMap params = new HashMap(); - params.put(ImagingConstants.PARAM_KEY_COMPRESSION, - TiffConstants.TIFF_COMPRESSION_CCITT_GROUP_3); - params.put(TiffConstants.PARAM_KEY_T4_OPTIONS, 5); + final ImagingParametersTiff params = new ImagingParametersTiff(); + params.setCompressionLevel(TiffConstants.TIFF_COMPRESSION_CCITT_GROUP_3); + params.setT4options(5); + final byte[] compressed = Imaging.writeImageToBytes(image, ImageFormats.TIFF, params); final BufferedImage result = Imaging.getBufferedImage(compressed); @@ -277,9 +276,9 @@ public void testAll5x2Images() { } try { - final HashMap params = new HashMap(); - params.put(ImagingConstants.PARAM_KEY_COMPRESSION, - TiffConstants.TIFF_COMPRESSION_CCITT_GROUP_4); + final ImagingParametersTiff params = new ImagingParametersTiff(); + params.setCompressionLevel(TiffConstants.TIFF_COMPRESSION_CCITT_GROUP_4); + final byte[] compressed = Imaging.writeImageToBytes(image, ImageFormats.TIFF, params); final BufferedImage result = Imaging.getBufferedImage(compressed); diff --git a/src/test/java/org/apache/commons/imaging/formats/tiff/TiffLzwTest.java b/src/test/java/org/apache/commons/imaging/formats/tiff/TiffLzwTest.java index bd87bb382..822dd1be5 100644 --- a/src/test/java/org/apache/commons/imaging/formats/tiff/TiffLzwTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/tiff/TiffLzwTest.java @@ -25,11 +25,11 @@ import java.io.InputStream; import java.nio.ByteOrder; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.bytesource.ByteSource; import org.apache.commons.imaging.common.bytesource.ByteSourceFile; import org.apache.commons.imaging.common.mylzw.MyLzwCompressor; @@ -69,8 +69,7 @@ public void testTiffImageData() throws IOException, ImageReadException, Debug.debug("imageFile", image); ByteSource byteSource = new ByteSourceFile(image); - List data = new TiffImageParser().collectRawImageData(byteSource, - Collections.emptyMap()); + List data = new TiffImageParser().collectRawImageData(byteSource, new ImagingParameters()); for (byte[] bytes : data) { decompressRoundtripAndValidate(bytes); diff --git a/src/test/java/org/apache/commons/imaging/formats/tiff/TiffReadWriteTagsTest.java b/src/test/java/org/apache/commons/imaging/formats/tiff/TiffReadWriteTagsTest.java index 1c85bd8c0..e74bddd60 100644 --- a/src/test/java/org/apache/commons/imaging/formats/tiff/TiffReadWriteTagsTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/tiff/TiffReadWriteTagsTest.java @@ -26,6 +26,7 @@ import org.apache.commons.imaging.FormatCompliance; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.RationalNumber; import org.apache.commons.imaging.common.bytesource.ByteSourceArray; import org.apache.commons.imaging.formats.tiff.constants.GeoTiffTagConstants; @@ -68,7 +69,7 @@ public void testReadWriteTags() throws ImageWriteException, ImageReadException, writer.write(tiff, set); TiffReader reader = new TiffReader(true); - Map params = new TreeMap(); + final ImagingParameters params = new ImagingParameters(); FormatCompliance formatCompliance = new FormatCompliance(""); TiffContents contents = reader.readFirstDirectory(new ByteSourceArray(tiff.toByteArray()), params, true, formatCompliance); TiffDirectory rootDir = contents.directories.get(0); diff --git a/src/test/java/org/apache/commons/imaging/formats/tiff/TiffRoundtripTest.java b/src/test/java/org/apache/commons/imaging/formats/tiff/TiffRoundtripTest.java index afe8824a7..5d35fa26f 100644 --- a/src/test/java/org/apache/commons/imaging/formats/tiff/TiffRoundtripTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/tiff/TiffRoundtripTest.java @@ -21,14 +21,12 @@ import java.awt.image.BufferedImage; import java.io.File; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.ImageFormats; import org.apache.commons.imaging.ImageInfo; import org.apache.commons.imaging.Imaging; -import org.apache.commons.imaging.ImagingConstants; +import org.apache.commons.imaging.ImagingParametersTiff; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.formats.tiff.constants.TiffConstants; import org.apache.commons.imaging.util.Debug; @@ -59,8 +57,10 @@ public void test() throws Exception { }; for (final int compression : compressions) { final File tempFile = createTempFile(imageFile.getName() + "-" + compression + ".", ".tif"); - final Map params = new HashMap(); - params.put(ImagingConstants.PARAM_KEY_COMPRESSION, compression); + + final ImagingParametersTiff params = new ImagingParametersTiff(); + params.setCompressionLevel(compression); + Imaging.writeImage(image, tempFile, ImageFormats.TIFF, params); final BufferedImage image2 = Imaging.getBufferedImage(tempFile); diff --git a/src/test/java/org/apache/commons/imaging/formats/tiff/TiffSubImageTest.java b/src/test/java/org/apache/commons/imaging/formats/tiff/TiffSubImageTest.java index bef9ccc85..3b29fe0e4 100644 --- a/src/test/java/org/apache/commons/imaging/formats/tiff/TiffSubImageTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/tiff/TiffSubImageTest.java @@ -20,14 +20,12 @@ import java.awt.image.BufferedImage; import java.io.IOException; -import java.util.Map; -import java.util.TreeMap; import org.apache.commons.imaging.ImageFormats; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; import org.apache.commons.imaging.Imaging; -import org.apache.commons.imaging.formats.tiff.constants.TiffConstants; +import org.apache.commons.imaging.ImagingParametersTiff; import org.junit.Test; public class TiffSubImageTest extends TiffBaseTest { @@ -37,11 +35,11 @@ public void testSubImage() throws ImageReadException, ImageWriteException, IOExc BufferedImage src = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); byte[] imageBytes = Imaging.writeImageToBytes(src, ImageFormats.TIFF, null); - Map params = new TreeMap(); - params.put(TiffConstants.PARAM_KEY_SUBIMAGE_X, 0); - params.put(TiffConstants.PARAM_KEY_SUBIMAGE_Y, 0); - params.put(TiffConstants.PARAM_KEY_SUBIMAGE_WIDTH, 2); - params.put(TiffConstants.PARAM_KEY_SUBIMAGE_HEIGHT, 3); + final ImagingParametersTiff params = new ImagingParametersTiff(); + params.setSubImageX(0); + params.setSubImageY(0); + params.setSubImageWidth(2); + params.setSubImageHeight(3); BufferedImage image = Imaging.getBufferedImage(imageBytes, params); assertEquals(image.getWidth(), 2); assertEquals(image.getHeight(), 3); diff --git a/src/test/java/org/apache/commons/imaging/formats/wbmp/WbmpReadTest.java b/src/test/java/org/apache/commons/imaging/formats/wbmp/WbmpReadTest.java index bf2ddb7c7..50ff878e1 100644 --- a/src/test/java/org/apache/commons/imaging/formats/wbmp/WbmpReadTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/wbmp/WbmpReadTest.java @@ -10,7 +10,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * under the License. */ package org.apache.commons.imaging.formats.wbmp; @@ -19,12 +18,11 @@ import java.awt.image.BufferedImage; import java.io.File; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.ImageInfo; import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.util.Debug; import org.junit.Assert; @@ -44,7 +42,7 @@ public void test() throws Exception { final ImageMetadata metadata = Imaging.getMetadata(imageFile); Assert.assertFalse(metadata instanceof File); // Dummy check to avoid unused warning (it may be null) - final Map params = new HashMap(); + final ImagingParameters params = new ImagingParameters(); final ImageInfo imageInfo = Imaging.getImageInfo(imageFile, params); assertNotNull(imageInfo); diff --git a/src/test/java/org/apache/commons/imaging/formats/xbm/XbmReadTest.java b/src/test/java/org/apache/commons/imaging/formats/xbm/XbmReadTest.java index 3bd6504da..2fa9b2c1f 100644 --- a/src/test/java/org/apache/commons/imaging/formats/xbm/XbmReadTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/xbm/XbmReadTest.java @@ -10,7 +10,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * under the License. */ package org.apache.commons.imaging.formats.xbm; @@ -25,6 +24,7 @@ import org.apache.commons.imaging.ImageInfo; import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.util.Debug; import org.junit.Assert; @@ -44,7 +44,7 @@ public void test() throws Exception { final ImageMetadata metadata = Imaging.getMetadata(imageFile); Assert.assertFalse(metadata instanceof File); // Dummy check to avoid unused warning (it may be null) - final Map params = new HashMap(); + final ImagingParameters params = new ImagingParameters(); final ImageInfo imageInfo = Imaging.getImageInfo(imageFile, params); assertNotNull(imageInfo); diff --git a/src/test/java/org/apache/commons/imaging/formats/xmp/XmpUpdateTest.java b/src/test/java/org/apache/commons/imaging/formats/xmp/XmpUpdateTest.java index 84d8ca8b3..30a99ce3d 100644 --- a/src/test/java/org/apache/commons/imaging/formats/xmp/XmpUpdateTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/xmp/XmpUpdateTest.java @@ -22,14 +22,12 @@ import java.awt.image.BufferedImage; import java.io.File; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.ImageFormat; import org.apache.commons.imaging.ImageFormats; import org.apache.commons.imaging.Imaging; -import org.apache.commons.imaging.ImagingConstants; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.ImagingTest; import org.apache.commons.imaging.util.Debug; import org.junit.Test; @@ -84,8 +82,8 @@ && isInvalidPNGTestFile(imageFile)) { // ---- - final Map params = new HashMap(); - params.put(ImagingConstants.PARAM_KEY_XMP_XML, xmpXml); + final ImagingParameters params = new ImagingParameters(); + params.setXmpXmlAsString(xmpXml); Imaging.writeImage(image, tempFile, imageFormat, params); final String xmpXmlOut = Imaging.getXmpXml(tempFile); diff --git a/src/test/java/org/apache/commons/imaging/formats/xpm/XpmReadTest.java b/src/test/java/org/apache/commons/imaging/formats/xpm/XpmReadTest.java index 515b6e211..f420e7eac 100644 --- a/src/test/java/org/apache/commons/imaging/formats/xpm/XpmReadTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/xpm/XpmReadTest.java @@ -10,7 +10,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * under the License. */ package org.apache.commons.imaging.formats.xpm; @@ -19,12 +18,11 @@ import java.awt.image.BufferedImage; import java.io.File; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.imaging.ImageInfo; import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.util.Debug; import org.junit.Assert; @@ -44,7 +42,7 @@ public void test() throws Exception { final ImageMetadata metadata = Imaging.getMetadata(imageFile); Assert.assertFalse(metadata instanceof File); // Dummy check to avoid unused warning (it may be null) - final Map params = new HashMap(); + final ImagingParameters params = new ImagingParameters(); final ImageInfo imageInfo = Imaging.getImageInfo(imageFile, params); assertNotNull(imageInfo); diff --git a/src/test/java/org/apache/commons/imaging/roundtrip/RoundtripTest.java b/src/test/java/org/apache/commons/imaging/roundtrip/RoundtripTest.java index 374d6f6e8..d8d82875c 100644 --- a/src/test/java/org/apache/commons/imaging/roundtrip/RoundtripTest.java +++ b/src/test/java/org/apache/commons/imaging/roundtrip/RoundtripTest.java @@ -24,8 +24,6 @@ import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; import org.apache.commons.imaging.ImageFormat; import org.apache.commons.imaging.ImageFormats; @@ -33,7 +31,7 @@ import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; import org.apache.commons.imaging.Imaging; -import org.apache.commons.imaging.ImagingConstants; +import org.apache.commons.imaging.ImagingParameters; import org.apache.commons.imaging.ImagingTest; import org.apache.commons.imaging.PixelDensity; import org.apache.commons.imaging.common.RgbBufferedImageFactory; @@ -416,9 +414,10 @@ public void testPixelDensityRoundtrip() throws IOException, final File temp1 = createTempFile("pixeldensity.", "." + formatInfo.format.getExtension()); - final Map params = new HashMap(); + final ImagingParameters params = new ImagingParameters(); final PixelDensity pixelDensity = PixelDensity.createFromPixelsPerInch(75, 150); - params.put(ImagingConstants.PARAM_KEY_PIXEL_DENSITY, pixelDensity); + params.setPixelDensity(pixelDensity); + Imaging.writeImage(testImage, temp1, formatInfo.format, params); final ImageInfo imageInfo = Imaging.getImageInfo(temp1); @@ -465,12 +464,11 @@ private void roundtrip(final FormatInfo formatInfo, final BufferedImage testImag + formatInfo.format.getExtension()); Debug.debug("tempFile: " + temp1.getName()); - final Map params = new HashMap(); + final ImagingParameters params = new ImagingParameters(); Imaging.writeImage(testImage, temp1, formatInfo.format, params); - final Map readParams = new HashMap(); - readParams.put(ImagingConstants.BUFFERED_IMAGE_FACTORY, - new RgbBufferedImageFactory()); + final ImagingParameters readParams = new ImagingParameters(); + readParams.setBufferedImageFactory(new RgbBufferedImageFactory()); final BufferedImage image2 = Imaging.getBufferedImage(temp1, readParams); assertNotNull(image2);