-
Notifications
You must be signed in to change notification settings - Fork 198
Proposal for a patch for Imaging-159 using a POJO #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from 163 commits
16372b8
217abfa
ddd2052
584c46b
1edd229
b215e4b
13a14d3
b8b1aef
07f98aa
6957d07
56e9fd1
90377ff
b7d5ce1
e4ca402
ff70685
a5da7bd
9f54d06
4189850
cc6ac0f
39b9e67
386c381
38f4b82
cff75ed
4712719
2c3d9ca
8ff6d0d
ba7b7be
f3605d3
95f01b6
9bf64f3
ab48433
259ae2b
f5db3ba
4454b82
cede4fc
a6ac9ea
b97e9ca
996abd1
bfc72c3
4a12446
8db737c
81d32db
3a8e609
f8b45e3
03ff8c7
3b8392b
c51a6e6
a32f119
0c6a0c1
e082094
4a1bf67
13442b7
8122d35
83998e4
3c58f66
b203d5a
8e26d53
7bd251a
479fee8
7eb3b21
e2c8d09
e4e151d
5f063ee
61b96ea
c1a6979
2d0d773
eb3ddfb
bf067ac
9722ce1
fc9bb64
3f43350
50601ae
a1d01d4
51a7b3c
5de82ae
3697cd9
93085b5
8d8c816
0562178
748f64f
8e1b272
ec03c5a
05d111d
60bb733
342ddf5
ede24e3
44d89fe
3f30ef9
9911252
92607ad
215afc8
a818a94
ee1f1a3
331e3f2
016fdfd
2c96cf5
53168a6
52a0c2b
d8d628e
13a1684
ce0e256
bf29c05
2b6c1a2
ddac350
1aa72c4
49b3b0a
9352398
1841900
4eb2a80
7ce092b
c42bcc9
2904fbe
d9f198c
37d7054
223fbbf
7a5b3a9
dd32969
183e7a0
bc349a0
ffe3da4
3ac6708
fa250a1
24315f9
e33f8d2
8f86045
f1dfdce
e67a700
11e23ec
fdd1249
43ee3f1
cffd5ec
55faed2
8ec13e8
58a3155
d90b702
eb20439
15c16ae
be94d28
d3f735d
6ad55c8
bbb966b
9497a46
9086d93
eaeddf5
fc7bc8e
34e69d0
4d6ee12
94402c4
59cf880
39037ef
5c55338
5a45484
0a24438
c976b8a
749cbb2
54ed80d
819fee5
6bc6883
b8a0266
fb80d9f
462a943
4b79c82
afce5be
f197352
2cbee0d
43e4431
8639f88
832402a
5d03d43
9521624
405eab0
a1eaf9c
99bc27e
ef43d0a
c27bc68
3817976
862469e
42cc793
d36b30d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,8 @@ | |
| * 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. | ||
| * | ||
| * Changed 2015 by Michael Gross, [email protected] | ||
| */ | ||
| package org.apache.commons.imaging; | ||
|
|
||
|
|
@@ -26,7 +28,6 @@ | |
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Locale; | ||
| import java.util.Map; | ||
|
|
||
| import org.apache.commons.imaging.common.BinaryFileParser; | ||
| import org.apache.commons.imaging.common.BufferedImageFactory; | ||
|
|
@@ -76,24 +77,6 @@ | |
| * the intentions of the original. Therefore, you should not assume | ||
| * that the documentation is perfect, especially in the more obscure | ||
| * and specialized areas of implementation. | ||
| * | ||
| * <h4>The "Map params" argument</h4> | ||
| * | ||
| * Many of the methods specified by this class accept an argument of | ||
| * type Map giving a list of parameters to be used when processing an | ||
| * image. For example, some of the output formats permit the specification | ||
| * of different kinds of image compression or color models. Some of the | ||
| * reading methods permit the calling application to require strict | ||
| * format compliance. In many cases, however, an application will not | ||
| * require the use of this argument. While some of the ImageParser | ||
| * implementations check for (and ignore) null arguments for this parameter, | ||
| * not all of them do (at least not at the time these notes were written). | ||
| * Therefore, a prudent programmer will always supply an valid, though | ||
| * empty instance of a Map implementation when calling such methods. | ||
| * Generally, the java HashMap class is useful for this purpose. | ||
| * | ||
| * <p>Additionally, developers creating or enhancing classes derived | ||
| * from ImageParser are encouraged to include such checks in their code. | ||
| */ | ||
| public abstract class ImageParser extends BinaryFileParser { | ||
|
|
||
|
|
@@ -169,7 +152,7 @@ public final ImageMetadata getMetadata(final ByteSource byteSource) throws Image | |
| * implementation. | ||
| * @throws IOException In the event of unsuccessful data read operation. | ||
| */ | ||
| public abstract ImageMetadata getMetadata(ByteSource byteSource, Map<String, Object> params) | ||
| public abstract ImageMetadata getMetadata(ByteSource byteSource, final ImagingParameters params) | ||
| throws ImageReadException, IOException; | ||
|
|
||
| /** | ||
|
|
@@ -215,7 +198,7 @@ public final ImageMetadata getMetadata(final byte[] bytes) throws ImageReadExcep | |
| * parser implementation. | ||
| * @throws IOException In the event of unsuccessful data read operation. | ||
| */ | ||
| public final ImageMetadata getMetadata(final byte[] bytes, final Map<String, Object> params) | ||
| public final ImageMetadata getMetadata(final byte[] bytes, final ImagingParameters params) | ||
| throws ImageReadException, IOException { | ||
| return getMetadata(new ByteSourceArray(bytes), params); | ||
| } | ||
|
|
@@ -264,7 +247,7 @@ public final ImageMetadata getMetadata(final File file) throws ImageReadExceptio | |
| * @throws IOException In the event of unsuccessful file read or | ||
| * access operation. | ||
| */ | ||
| public final ImageMetadata getMetadata(final File file, final Map<String, Object> params) | ||
| public final ImageMetadata getMetadata(final File file, final ImagingParameters params) | ||
| throws ImageReadException, IOException { | ||
| if (getDebug()) { | ||
| System.out.println(getName() + ".getMetadata" + ": " | ||
|
|
@@ -302,7 +285,7 @@ public final ImageMetadata getMetadata(final File file, final Map<String, Object | |
| * parser implementation. | ||
| * @throws IOException In the event of unsuccessful data access operation. | ||
| */ | ||
| public abstract ImageInfo getImageInfo(ByteSource byteSource, Map<String, Object> params) | ||
| public abstract ImageInfo getImageInfo(ByteSource byteSource, final ImagingParameters params) | ||
| throws ImageReadException, IOException; | ||
|
|
||
| /** | ||
|
|
@@ -348,7 +331,7 @@ public final ImageInfo getImageInfo(final ByteSource byteSource) throws ImageRea | |
| * @throws IOException In the event of unsuccessful data | ||
| * access operation. | ||
| */ | ||
| public final ImageInfo getImageInfo(final byte[] bytes, final Map<String, Object> params) | ||
| public final ImageInfo getImageInfo(final byte[] bytes, final ImagingParameters params) | ||
| throws ImageReadException, IOException { | ||
| return getImageInfo(new ByteSourceArray(bytes), params); | ||
| } | ||
|
|
@@ -377,7 +360,7 @@ public final ImageInfo getImageInfo(final byte[] bytes, final Map<String, Object | |
| * @throws IOException In the event of unsuccessful file read or | ||
| * access operation. | ||
| */ | ||
| public final ImageInfo getImageInfo(final File file, final Map<String, Object> params) | ||
| public final ImageInfo getImageInfo(final File file, final ImagingParameters params) | ||
| throws ImageReadException, IOException { | ||
| if (!canAcceptExtension(file)) { | ||
| return null; | ||
|
|
@@ -505,7 +488,7 @@ public final List<BufferedImage> getAllBufferedImages(final File file) throws Im | |
| * parser implementation. | ||
| * @throws IOException In the event of unsuccessful read or access operation. | ||
| */ | ||
| public abstract BufferedImage getBufferedImage(ByteSource byteSource, Map<String, Object> params) | ||
| public abstract BufferedImage getBufferedImage(ByteSource byteSource, final ImagingParameters params) | ||
| throws ImageReadException, IOException; | ||
|
|
||
| /** | ||
|
|
@@ -523,7 +506,7 @@ public abstract BufferedImage getBufferedImage(ByteSource byteSource, Map<String | |
| * parser implementation. | ||
| * @throws IOException In the event of unsuccessful read or access operation. | ||
| */ | ||
| public final BufferedImage getBufferedImage(final byte[] bytes, final Map<String, Object> params) | ||
| public final BufferedImage getBufferedImage(final byte[] bytes, final ImagingParameters params) | ||
| throws ImageReadException, IOException { | ||
| return getBufferedImage(new ByteSourceArray(bytes), params); | ||
| } | ||
|
|
@@ -543,7 +526,7 @@ public final BufferedImage getBufferedImage(final byte[] bytes, final Map<String | |
| * parser implementation. | ||
| * @throws IOException In the event of unsuccessful read or access operation. | ||
| */ | ||
| public final BufferedImage getBufferedImage(final File file, final Map<String, Object> params) | ||
| public final BufferedImage getBufferedImage(final File file, final ImagingParameters params) | ||
| throws ImageReadException, IOException { | ||
| if (!canAcceptExtension(file)) { | ||
| return null; | ||
|
|
@@ -575,7 +558,7 @@ public final BufferedImage getBufferedImage(final File file, final Map<String, O | |
| * @throws IOException In the event of an write error from | ||
| * the output stream. | ||
| */ | ||
| public void writeImage(final BufferedImage src, final OutputStream os, final Map<String, Object> params) | ||
| public void writeImage(final BufferedImage src, final OutputStream os, final ImagingParameters params) | ||
| throws ImageWriteException, IOException { | ||
| os.close(); // we are obligated to close stream. | ||
|
|
||
|
|
@@ -609,7 +592,7 @@ public final Dimension getImageSize(final byte[] bytes) throws ImageReadExceptio | |
| * parser implementation. | ||
| * @throws IOException In the event of unsuccessful read or access operation. | ||
| */ | ||
| public final Dimension getImageSize(final byte[] bytes, final Map<String, Object> params) | ||
| public final Dimension getImageSize(final byte[] bytes, final ImagingParameters params) | ||
| throws ImageReadException, IOException { | ||
| return getImageSize(new ByteSourceArray(bytes), params); | ||
| } | ||
|
|
@@ -640,7 +623,7 @@ public final Dimension getImageSize(final File file) throws ImageReadException, | |
| * parser implementation. | ||
| * @throws IOException In the event of unsuccessful read or access operation. | ||
| */ | ||
| public final Dimension getImageSize(final File file, final Map<String, Object> params) | ||
| public final Dimension getImageSize(final File file, final ImagingParameters params) | ||
| throws ImageReadException, IOException { | ||
|
|
||
| if (!canAcceptExtension(file)) { | ||
|
|
@@ -662,7 +645,7 @@ public final Dimension getImageSize(final File file, final Map<String, Object> p | |
| * parser implementation. | ||
| * @throws IOException In the event of unsuccessful read or access operation. | ||
| */ | ||
| public abstract Dimension getImageSize(ByteSource byteSource, Map<String, Object> params) | ||
| public abstract Dimension getImageSize(ByteSource byteSource, final ImagingParameters params) | ||
| throws ImageReadException, IOException; | ||
|
|
||
| /** | ||
|
|
@@ -682,7 +665,7 @@ public abstract Dimension getImageSize(ByteSource byteSource, Map<String, Object | |
| * parser implementation. | ||
| * @throws IOException In the event of unsuccessful read or access operation. | ||
| */ | ||
| public abstract String getXmpXml(ByteSource byteSource, Map<String, Object> params) | ||
| public abstract String getXmpXml(ByteSource byteSource, final ImagingParameters params) | ||
| throws ImageReadException, IOException; | ||
|
|
||
| /** | ||
|
|
@@ -715,7 +698,7 @@ public final byte[] getICCProfileBytes(final byte[] bytes) throws ImageReadExcep | |
| * parser implementation. | ||
| * @throws IOException In the event of unsuccessful read or access operation. | ||
| */ | ||
| public final byte[] getICCProfileBytes(final byte[] bytes, final Map<String, Object> params) | ||
| public final byte[] getICCProfileBytes(final byte[] bytes, final ImagingParameters params) | ||
| throws ImageReadException, IOException { | ||
| return getICCProfileBytes(new ByteSourceArray(bytes), params); | ||
| } | ||
|
|
@@ -750,7 +733,7 @@ public final byte[] getICCProfileBytes(final File file) throws ImageReadExceptio | |
| * parser implementation. | ||
| * @throws IOException In the event of unsuccessful read or access operation. | ||
| */ | ||
| public final byte[] getICCProfileBytes(final File file, final Map<String, Object> params) | ||
| public final byte[] getICCProfileBytes(final File file, final ImagingParameters params) | ||
| throws ImageReadException, IOException { | ||
| if (!canAcceptExtension(file)) { | ||
| return null; | ||
|
|
@@ -777,7 +760,7 @@ public final byte[] getICCProfileBytes(final File file, final Map<String, Object | |
| * parser implementation. | ||
| * @throws IOException In the event of unsuccessful read or access operation. | ||
| */ | ||
| public abstract byte[] getICCProfileBytes(ByteSource byteSource, Map<String, Object> params) | ||
| public abstract byte[] getICCProfileBytes(ByteSource byteSource, final ImagingParameters params) | ||
| throws ImageReadException, IOException; | ||
|
|
||
| /** | ||
|
|
@@ -846,6 +829,7 @@ public final String dumpImageFile(final ByteSource byteSource) | |
| * Write the ImageInfo and format-specific information for the image | ||
| * content of the specified byte source to a PrintWriter | ||
| * | ||
| * @param pw | ||
| * @param byteSource A valid byte source. | ||
| * @return A valid PrintWriter. | ||
| * @throws ImageReadException In the event that the the specified content | ||
|
|
@@ -954,13 +938,12 @@ protected final boolean canAcceptExtension(final String filename) { | |
| * @param params A valid Map object, or a null. | ||
| * @return A valid instance of an implementation of a IBufferedImageFactory. | ||
| */ | ||
| protected BufferedImageFactory getBufferedImageFactory(final Map<String, Object> params) { | ||
| if (params == null) { | ||
| protected BufferedImageFactory getBufferedImageFactory(final ImagingParameters params) { | ||
| if (params == null || params.isBufferedImageFactoryPresent() == false) { | ||
| return new SimpleBufferedImageFactory(); | ||
| } | ||
|
|
||
| final BufferedImageFactory result = (BufferedImageFactory) params | ||
| .get(ImagingConstants.BUFFERED_IMAGE_FACTORY); | ||
| final BufferedImageFactory result = params.getBufferedImageFactory(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As noted in JIRA, to me it feels strange to pass a BufferedImageFactory via a parameters object. But since this has been the case before this PR, I think we should first concentrate on getting the ImagingParameters in place and refactor the BufferedImageFactory later (if that is possible)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uh, really strange. Perhaps if it were the class only, not the instance, then I think it'd be fine. |
||
|
|
||
| if (null != result) { | ||
| return result; | ||
|
|
@@ -970,19 +953,18 @@ protected BufferedImageFactory getBufferedImageFactory(final Map<String, Object> | |
| } | ||
|
|
||
| /** | ||
| * A utility method to search a params specification and determine | ||
| * whether it contains the ImagingConstants.PARAM_KEY_STRICT | ||
| * specification. Intended | ||
| * for internal use by ImageParser implementations. | ||
| * A utility method to whether we have a parameter object and if the STRICT | ||
| * flag is set or not. | ||
| * Intended for internal use by ImageParser implementations. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe some re-wording here "Return whether to use a strict mode or not when reading or writing images." or similar? |
||
| * | ||
| * @param params A valid Map object (or a null). | ||
| * @param params A valid parameter object (or a null). | ||
| * @return If the params specify strict format compliance, true; | ||
| * otherwise, false. | ||
| */ | ||
| public static boolean isStrict(final Map<String, Object> params) { | ||
| if (params == null || !params.containsKey(ImagingConstants.PARAM_KEY_STRICT)) { | ||
| public static boolean isStrict(final ImagingParameters params) { | ||
| if (params == null) { | ||
| return false; | ||
| } | ||
| return ((Boolean) params.get(ImagingConstants.PARAM_KEY_STRICT)).booleanValue(); | ||
| return params.isStrictEnabled(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has to be removed from all files. Please file an ICLA.