();
- }
-
- 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