kinow commented on a change in pull request #5: Proposal for a patch for 
Imaging-159 using a POJO
URL: https://github.com/apache/commons-imaging/pull/5#discussion_r370989848
 
 

 ##########
 File path: 
src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageParser.java
 ##########
 @@ -485,40 +485,45 @@ public BufferedImage getBufferedImage(final ByteSource 
byteSource, final Map<Str
         }
         return results;
     }
-
-    private Integer getIntegerParameter(
-            final String key, final Map<String, Object>params)
-            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<String, Object> 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
 
 Review comment:
   s/at lease/at least
   s/theseparameters/these parameters

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to