sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jso...@apache.org
Subject [sis] branch geoapi-4.0 updated: Coverage : add PixelIterator getNumBands and getSampleRange methods
Date Thu, 14 Mar 2019 11:23:03 GMT
This is an automated email from the ASF dual-hosted git repository.

jsorel pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 0515946  Coverage : add PixelIterator getNumBands and getSampleRange methods
0515946 is described below

commit 05159464ae47e7b570b16398e57efd0ec78c126c
Author: jsorel <johann.sorel@geomatys.com>
AuthorDate: Thu Mar 14 13:22:41 2019 +0100

    Coverage : add PixelIterator getNumBands and getSampleRange methods
---
 .../java/org/apache/sis/image/PixelIterator.java   | 37 ++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/core/sis-raster/src/main/java/org/apache/sis/image/PixelIterator.java b/core/sis-raster/src/main/java/org/apache/sis/image/PixelIterator.java
index 8423205..ec36654 100644
--- a/core/sis-raster/src/main/java/org/apache/sis/image/PixelIterator.java
+++ b/core/sis-raster/src/main/java/org/apache/sis/image/PixelIterator.java
@@ -20,6 +20,7 @@ import java.nio.Buffer;
 import java.awt.Point;
 import java.awt.Dimension;
 import java.awt.Rectangle;
+import java.awt.image.DataBuffer;
 import java.awt.image.Raster;
 import java.awt.image.RenderedImage;
 import java.awt.image.WritableRaster;
@@ -31,6 +32,7 @@ import org.apache.sis.util.ArgumentChecks;
 
 import static java.lang.Math.floorDiv;
 import static org.apache.sis.internal.util.Numerics.ceilDiv;
+import org.apache.sis.measure.NumberRange;
 
 
 /**
@@ -80,6 +82,11 @@ public abstract class PixelIterator {
     final int numBands;
 
     /**
+     * Value range supported by storage.
+     */
+    final NumberRange sampleRange;
+
+    /**
      * The domain, in pixel coordinates, of the region traversed by this pixel iterator.
      * This may be smaller than the image or raster bounds, but not greater.
      * The lower values are inclusive and the upper values exclusive.
@@ -124,6 +131,7 @@ public abstract class PixelIterator {
         image           = null;
         currentRaster   = data;
         numBands        = data.getNumBands();
+        sampleRange     = rangeForDataType(data.getSampleModel().getDataType());
         tileWidth       = data.getWidth();
         tileHeight      = data.getHeight();
         tileGridXOffset = data.getMinX();
@@ -153,6 +161,7 @@ public abstract class PixelIterator {
         final Rectangle bounds;
         image           = data;
         numBands        = data.getSampleModel().getNumBands();
+        sampleRange     = rangeForDataType(data.getSampleModel().getDataType());
         tileWidth       = data.getTileWidth();
         tileHeight      = data.getTileHeight();
         tileGridXOffset = data.getTileGridXOffset();
@@ -170,6 +179,16 @@ public abstract class PixelIterator {
         windowHeight    = (window != null) ? window.height : 0;
     }
 
+    private static NumberRange<?> rangeForDataType(int dataType) {
+        switch (dataType) {
+            case DataBuffer.TYPE_BYTE : return NumberRange.create(0, true, 255, true);
+            case DataBuffer.TYPE_SHORT : return NumberRange.create(Short.MIN_VALUE, true,
Short.MAX_VALUE, true);
+            case DataBuffer.TYPE_USHORT : return NumberRange.create(0, true, 65535, true);
+            case DataBuffer.TYPE_INT : return NumberRange.create(Integer.MIN_VALUE, true,
Integer.MAX_VALUE, true);
+            default : return NumberRange.create(Double.NEGATIVE_INFINITY, true, Double.POSITIVE_INFINITY,
true);
+        }
+    }
+
     /**
      * Computes the intersection between the given bounds and and {@code subArea} if {@code
subArea} is non-null.
      * If the result is empty, then the width and/or height are set to zero (not negative).
@@ -420,6 +439,24 @@ public abstract class PixelIterator {
     }
 
     /**
+     * Returns the number of bands (samples per pixel) from Image or Raster within this Iterator.
+     *
+     * @return number of bands.
+     */
+    public int getNumBands() {
+        return numBands;
+    }
+
+    /**
+     * Returns the numeric range supported by datas from Image or Raster within this Iterator.
+     *
+     * @return primitive samples range.
+     */
+    public NumberRange<?> getSampleRange() {
+        return sampleRange;
+    }
+
+    /**
      * Returns the column (x) and row (y) indices of the current pixel.
      * The {@link #next()} or {@link #moveTo(int,int)} method must have been invoked before
this method.
      * Indices of the first pixel are not necessarily zero; they can even be negative.


Mime
View raw message