Revision: 6564
          http://sourceforge.net/p/jump-pilot/code/6564
Author:   edso
Date:     2020-10-02 12:23:18 +0000 (Fri, 02 Oct 2020)
Log Message:
-----------
implement Elevation floating point data rendering according to commons-imaging 
examples from
http://commons.apache.org/proper/commons-imaging/xref-test/org/apache/commons/imaging/examples/tiff/
and
https://issues.apache.org/jira/browse/IMAGING-267

Modified Paths:
--------------
    
core/trunk/src/com/vividsolutions/jump/workbench/imagery/graphic/AbstractGraphicImage.java
    
core/trunk/src/com/vividsolutions/jump/workbench/imagery/graphic/CommonsImageFactory.java

Added Paths:
-----------
    
core/trunk/src/com/vividsolutions/jump/workbench/imagery/graphic/CommonsTIFFImage.java

Modified: 
core/trunk/src/com/vividsolutions/jump/workbench/imagery/graphic/AbstractGraphicImage.java
===================================================================
--- 
core/trunk/src/com/vividsolutions/jump/workbench/imagery/graphic/AbstractGraphicImage.java
  2020-10-02 04:48:19 UTC (rev 6563)
+++ 
core/trunk/src/com/vividsolutions/jump/workbench/imagery/graphic/AbstractGraphicImage.java
  2020-10-02 12:23:18 UTC (rev 6564)
@@ -244,7 +244,7 @@
       image_h += (topOffset + botOffset);
 
       RenderingHints rh = new RenderingHints(RenderingHints.KEY_INTERPOLATION,
-          RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+          RenderingHints.VALUE_INTERPOLATION_BICUBIC);
       g.setRenderingHints(rh);
 
       // parameters: destination corners then source corners

Modified: 
core/trunk/src/com/vividsolutions/jump/workbench/imagery/graphic/CommonsImageFactory.java
===================================================================
--- 
core/trunk/src/com/vividsolutions/jump/workbench/imagery/graphic/CommonsImageFactory.java
   2020-10-02 04:48:19 UTC (rev 6563)
+++ 
core/trunk/src/com/vividsolutions/jump/workbench/imagery/graphic/CommonsImageFactory.java
   2020-10-02 12:23:18 UTC (rev 6564)
@@ -33,6 +33,7 @@
  */
 import org.apache.commons.imaging.ImageFormat;
 import org.apache.commons.imaging.ImageFormats;
+import org.apache.commons.io.FilenameUtils;
 
 import com.vividsolutions.jump.workbench.WorkbenchContext;
 import com.vividsolutions.jump.workbench.imagery.ReferencedImage;
@@ -43,6 +44,10 @@
   }
 
   public ReferencedImage createImage(String location) {
+    String ext = FilenameUtils.getExtension(location).toLowerCase();
+    if (ext.matches("tiff?"))
+      return new CommonsTIFFImage(location, null);
+    
     return new CommonsImage(location, null);
   }
 

Added: 
core/trunk/src/com/vividsolutions/jump/workbench/imagery/graphic/CommonsTIFFImage.java
===================================================================
--- 
core/trunk/src/com/vividsolutions/jump/workbench/imagery/graphic/CommonsTIFFImage.java
                              (rev 0)
+++ 
core/trunk/src/com/vividsolutions/jump/workbench/imagery/graphic/CommonsTIFFImage.java
      2020-10-02 12:23:18 UTC (rev 6564)
@@ -0,0 +1,113 @@
+package com.vividsolutions.jump.workbench.imagery.graphic;
+
+import java.awt.Color;
+import java.awt.image.BufferedImage;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.commons.imaging.FormatCompliance;
+import org.apache.commons.imaging.common.bytesource.ByteSource;
+import org.apache.commons.imaging.common.bytesource.ByteSourceInputStream;
+import org.apache.commons.imaging.formats.tiff.TiffContents;
+import org.apache.commons.imaging.formats.tiff.TiffDirectory;
+import org.apache.commons.imaging.formats.tiff.TiffField;
+import org.apache.commons.imaging.formats.tiff.TiffRasterData;
+import org.apache.commons.imaging.formats.tiff.TiffRasterStatistics;
+import org.apache.commons.imaging.formats.tiff.TiffReader;
+import org.apache.commons.imaging.formats.tiff.constants.TiffConstants;
+import org.apache.commons.imaging.formats.tiff.constants.TiffTagConstants;
+import 
org.apache.commons.imaging.formats.tiff.photometricinterpreters.floatingpoint.PaletteEntry;
+import 
org.apache.commons.imaging.formats.tiff.photometricinterpreters.floatingpoint.PaletteEntryForRange;
+import 
org.apache.commons.imaging.formats.tiff.photometricinterpreters.floatingpoint.PaletteEntryForValue;
+import 
org.apache.commons.imaging.formats.tiff.photometricinterpreters.floatingpoint.PhotometricInterpreterFloat;
+import org.openjump.util.UriUtil;
+
+import com.vividsolutions.jts.geom.Envelope;
+import com.vividsolutions.jump.io.CompressedFile;
+import com.vividsolutions.jump.workbench.imagery.ReferencedImageException;
+
+public class CommonsTIFFImage extends CommonsImage {
+
+  public CommonsTIFFImage(String location, WorldFile wf) {
+    super(location, wf);
+  }
+
+  @Override
+  protected void initImage() throws ReferencedImageException {
+    BufferedImage image = getImage();
+    if (image != null)
+      return;
+
+    String uri = getUri();
+
+    try {
+      ByteSource byteSource = new 
ByteSourceInputStream(CompressedFile.openFile(uri), UriUtil.getFileName(uri));
+      TiffReader tiffReader = new TiffReader(true);
+      TiffContents contents = tiffReader.readDirectories(byteSource, true, 
FormatCompliance.getDefault());
+      TiffDirectory directory = contents.directories.get(0);
+
+      if (!directory.hasTiffFloatingPointRasterData()) {
+        super.initImage();
+        return;
+      }
+
+//      PhotometricInterpreterFloat pi = new PhotometricInterpreterFloat(0.0f, 
1.0f);
+//      HashMap<String, Object> params = new HashMap<>();
+//      params.put(TiffConstants.PARAM_KEY_CUSTOM_PHOTOMETRIC_INTERPRETER, pi);
+//      directory.getTiffImage(params);
+//
+//      float maxValue = pi.getMaxFound();
+//      float minValue = pi.getMinFound();
+
+      HashMap<String, Object> params = new HashMap<>();
+      TiffRasterData rasterData = directory.getFloatingPointRasterData(params);
+
+      float excludedValue = Float.NaN;
+      TiffRasterStatistics simpleStats;
+      if (false) { // we can add a custom "No Data" indicator
+        simpleStats = rasterData.getSimpleStatistics(9999);
+      } else {
+        // just gather the standard statistics
+        simpleStats = rasterData.getSimpleStatistics();
+      }
+
+      float minValue = simpleStats.getMinValue();
+      float maxValue = simpleStats.getMaxValue();
+
+//      PhotometricInterpreterFloat grayScale = new 
PhotometricInterpreterFloat(minValue, maxValue);
+//      params = new HashMap<>();
+//      params.put(TiffConstants.PARAM_KEY_CUSTOM_PHOTOMETRIC_INTERPRETER, 
grayScale);
+//      BufferedImage bImage = directory.getTiffImage(params);
+
+      TiffField piField = 
directory.findField(TiffTagConstants.TIFF_TAG_PHOTOMETRIC_INTERPRETATION);
+      // default is black to white ascending
+      boolean ascendingGrayTones = (piField == null
+          || piField.getIntValue() != 
TiffTagConstants.PHOTOMETRIC_INTERPRETATION_VALUE_WHITE_IS_ZERO);
+
+      List<PaletteEntry> paletteList = new ArrayList();
+      if (!Float.isNaN(excludedValue)) {
+        // draw the excluded value in red.
+        paletteList.add(new PaletteEntryForValue(excludedValue, Color.red));
+      }
+      paletteList.add(new PaletteEntryForRange(minValue, maxValue, 
ascendingGrayTones ? Color.black : Color.white,
+          ascendingGrayTones ? Color.white : Color.black));
+//      paletteList.add(new PaletteEntryForValue(maxValue, Color.white));
+      PhotometricInterpreterFloat photometricInterpreter = new 
PhotometricInterpreterFloat(paletteList);
+
+      params.put(TiffConstants.PARAM_KEY_CUSTOM_PHOTOMETRIC_INTERPRETER, 
photometricInterpreter);
+      BufferedImage bImage = directory.getTiffImage(params);
+
+      setImage(bImage);
+
+    } catch (Exception e) {
+      throw new ReferencedImageException(e);
+    }
+  }
+
+  @Override
+  public Envelope getEnvelope() throws ReferencedImageException {
+    // TODO implement or reuse TiffDir/Tag georeferencing
+    return super.getEnvelope();
+  }
+}



_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to