sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Add methods in `PixelIterator` for getting and setting data elements (not necessarily the same than pixel values).
Date Thu, 14 May 2020 10:11:25 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux 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 c6a7fb1  Add methods in `PixelIterator` for getting and setting data elements (not
necessarily the same than pixel values).
c6a7fb1 is described below

commit c6a7fb19bfb908ab957509bb47d019080f3f2e89
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Thu May 14 12:08:27 2020 +0200

    Add methods in `PixelIterator` for getting and setting data elements (not necessarily
the same than pixel values).
---
 .../java/org/apache/sis/image/DefaultIterator.java | 34 +++++++++++++++++-----
 .../java/org/apache/sis/image/PixelIterator.java   | 24 +++++++++++++++
 .../apache/sis/image/WritablePixelIterator.java    | 17 ++++++++++-
 3 files changed, 66 insertions(+), 9 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/DefaultIterator.java b/core/sis-feature/src/main/java/org/apache/sis/image/DefaultIterator.java
index ef39c72..e5daa80 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/DefaultIterator.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/DefaultIterator.java
@@ -367,8 +367,17 @@ class DefaultIterator extends WritablePixelIterator {
      * This method assumes that {@link #next()} or {@link #moveTo(int,int)} has been invoked.
      */
     @Override
-    public double[] getPixel​(double[] dest) {
-        return currentRaster.getPixel(x, y, dest);
+    public double[] getPixel​(double[] values) {
+        return currentRaster.getPixel(x, y, values);
+    }
+
+    /**
+     * Returns the data elements of current pixel.
+     * This method assumes that {@link #next()} or {@link #moveTo(int,int)} has been invoked.
+     */
+    @Override
+    public Object getDataElements​(Object values) {
+        return currentRaster.getDataElements​(x, y, values);
     }
 
     /**
@@ -376,8 +385,8 @@ class DefaultIterator extends WritablePixelIterator {
      * This method assumes that {@link #next()} or {@link #moveTo(int,int)} has been invoked.
      */
     @Override
-    public void setPixel​(int[] dest) {
-        destRaster.setPixel(x, y, dest);
+    public void setPixel​(int[] values) {
+        destRaster.setPixel(x, y, values);
     }
 
     /**
@@ -385,8 +394,8 @@ class DefaultIterator extends WritablePixelIterator {
      * This method assumes that {@link #next()} or {@link #moveTo(int,int)} has been invoked.
      */
     @Override
-    public void setPixel​(float[] dest) {
-        destRaster.setPixel(x, y, dest);
+    public void setPixel​(float[] values) {
+        destRaster.setPixel(x, y, values);
     }
 
     /**
@@ -394,8 +403,17 @@ class DefaultIterator extends WritablePixelIterator {
      * This method assumes that {@link #next()} or {@link #moveTo(int,int)} has been invoked.
      */
     @Override
-    public void setPixel​(double[] dest) {
-        destRaster.setPixel(x, y, dest);
+    public void setPixel​(double[] values) {
+        destRaster.setPixel(x, y, values);
+    }
+
+    /**
+     * Sets the data elements of current pixel.
+     * This method assumes that {@link #next()} or {@link #moveTo(int,int)} has been invoked.
+     */
+    @Override
+    public void setDataElements(Object values) {
+        destRaster.setDataElements(x, y, values);
     }
 
     /**
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/PixelIterator.java b/core/sis-feature/src/main/java/org/apache/sis/image/PixelIterator.java
index beb5065..cbc7d48 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/PixelIterator.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/PixelIterator.java
@@ -663,6 +663,30 @@ public abstract class PixelIterator {
     public abstract double[] getPixel​(double[] dest);
 
     /**
+     * Returns the data elements (not necessarily band values) of current pixel.
+     * The {@code Object} argument and return value is a relatively opaque format (it may
be {@code int[]},
+     * {@code byte[]}, <i>etc.</i>): it is used for transferring values in a
packed format between compatible
+     * Java2D sample or color models. That {@code Object} should generally not be used directly
by the caller.
+     *
+     * <div class="note"><b>Example:</b>
+     * if an image has Red, Green, Blue and Alpha bands, then the {@link #getPixel(int[])}
methods will return
+     * arrays of length 4 containing the individual values for each band, no matter how those
bands are stored
+     * in the image. By contrast this {@code getDataElements​(…)} method may return an
array of length 1 with
+     * all sample values packed as a single ARGB value.</div>
+     *
+     * Data elements are useful for copying efficiently values in another image using the
same sample model,
+     * or for getting colors with a call to {@link java.awt.image.ColorModel#getRGB(Object)}.
+     *
+     * @param  dest  a pre-allocated array where to store the data elements, or {@code null}
if none.
+     * @return the data elements for current pixel.
+     *
+     * @see Raster#getDataElements​(int, int, Object)
+     *
+     * @since 1.1
+     */
+    public abstract Object getDataElements(Object dest);
+
+    /**
      * Returns a moving window over the sample values in a rectangular region starting at
iterator position.
      * The <cite>window size</cite> must have been specified at {@code PixelIterator} construction
time.
      * The current iterator position is the window corner having the smallest <var>x</var>
and <var>y</var> coordinates.
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/WritablePixelIterator.java
b/core/sis-feature/src/main/java/org/apache/sis/image/WritablePixelIterator.java
index 19b42dd..420a8d1 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/WritablePixelIterator.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/WritablePixelIterator.java
@@ -51,7 +51,7 @@ import org.apache.sis.internal.feature.Resources;
  *
  * @author  Rémi Maréchal (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @version 1.1
  * @since   1.0
  * @module
  */
@@ -237,6 +237,21 @@ public abstract class WritablePixelIterator extends PixelIterator implements
Clo
     public abstract void setPixel​(double[] values);
 
     /**
+     * Sets the data elements (not necessarily band values) of current pixel.
+     * The {@code Object} argument is a relatively opaque format (it may be {@code int[]},
{@code byte[]}, <i>etc.</i>).
+     * It should be the value provided by a call to {@link #getDataElements(Object)} on an
image using
+     * a compatible sample model.
+     *
+     * @param  values  the new the data elements.
+     *
+     * @see WritableRaster#setDataElements​(int, int, Object)
+     * @see #getDataElements(Object)
+     *
+     * @since 1.1
+     */
+    public abstract void setDataElements(Object values);
+
+    /**
      * Releases any resources hold by this iterator.
      * Invoking this method may flush some tiles content to disk.
      */


Mime
View raw message