You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2020/11/22 22:20:24 UTC

[GitHub] [commons-imaging] kinow commented on a change in pull request #108: Issue-266 access full precision of TIFF samples

kinow commented on a change in pull request #108:
URL: https://github.com/apache/commons-imaging/pull/108#discussion_r528412185



##########
File path: src/main/java/org/apache/commons/imaging/formats/tiff/TiffDirectory.java
##########
@@ -914,4 +915,41 @@ public boolean hasTiffFloatingPointRasterData() throws ImageReadException {
         }
         return false;
     }
+
+    /**
+     * Reads the image content of the TIFF directory and uses the
+     * current photometric interpreter to store its information
+     * in an ImageBuilder instance. Note that not all TIFF directories
+     * include image content. If the current instance does not contain
+     * an image, this method will throw an exception.
+     * <p>
+     * If desired, sub-image data can be read from the file by using a Java Map
+     * instance to specify the subsection of the image that is required. The
+     * following code illustrates the approach:
+     * <pre>
+     *   int x; // coordinate (column) of corner of sub-image
+     *   int y; // coordinate (row) of corner of sub-image
+     *   int width; // width of sub-image
+     *   int height; // height of sub-image
+     *
+     *   Map&lt;String, Object&gt;params = new HashMap&lt;&gt;();
+     *   params.put(TiffConstants.PARAM_KEY_SUBIMAGE_X, x);
+     *   params.put(TiffConstants.PARAM_KEY_SUBIMAGE_Y, y);
+     *   params.put(TiffConstants.PARAM_KEY_SUBIMAGE_WIDTH, width);
+     *   params.put(TiffConstants.PARAM_KEY_SUBIMAGE_HEIGHT, height);
+     *   ImageBuilder imageBuilder = directory.getImageBuilder(params);
+     * </pre>
+     *
+     * @param params an optional parameter map instance
+     * @return a valid instance
+     * @throws ImageReadException in the event of incompatible or malformed data
+     * @throws IOException in the event of an I/O error
+     */
+    public ImageBuilder getImageBuilder(
+        final Map<String, Object> params)
+        throws ImageReadException, IOException {
+        TiffImageParser parser = new TiffImageParser();
+        return parser.getImageBuilder(this, headerByteOrder, params);
+    }
+

Review comment:
       @gwlucastrig maybe we could rethink this? It strikes me as strange/risky having the `ImageBuilder` and `TiffDirectory` so tightly tied. I think the builder creates/uses directories; and—if that relationship really exists—then it would be a circular dependency by accessing the Builder from the Directory. Will take a better look later with the IDE :+1: 

##########
File path: src/main/java/org/apache/commons/imaging/formats/tiff/photometricinterpreters/PhotometricInterpreterTranscribeSample0.java
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.formats.tiff.photometricinterpreters;
+
+import java.io.IOException;
+
+import org.apache.commons.imaging.ImageReadException;
+import org.apache.commons.imaging.common.ImageBuilder;
+import org.apache.commons.imaging.formats.tiff.constants.TiffTagConstants;
+
+/**
+ * Provides an implementation of a custom photometric interpreter that
+ * does not transform the content of a TIFF image to the RGB format
+ * but simply transcribes the first sample at each pixel location to an integer.
+ * <p>
+ * This class is meant to support applications that use TIFF files to store
+ * integer data rather than imagery. This approach is widely used in
+ * GeoTIFF image formats to store geophysical data.
+ * <p>
+ * Note that this implementation only processes the first sample for a pixel.
+ * Developers requiring access to additional samples may use this class as
+ * an example.  However, the ImageBuilder class currently has the limitation
+ * that it cannot store more than one 32 bit integer per pixel or
+ * raster cell.
+ * <p>
+ * The data stored by this class is treated as a signed integer value.
+ */
+public class PhotometricInterpreterTranscribeSample0 extends PhotometricInterpreter {

Review comment:
       Maybe we could have a different name? Instead of `PhotometricInterpreterTranscribeSample0`, would it make sense to have something like `...Basic`, `...Default`, etc? This way we avoid having future classes with names that do not match the pattern `...0`, `...1`, etc.




----------------------------------------------------------------
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:
users@infra.apache.org