sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1804115 - in /sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/image: PixelIterator.java WritablePixelIterator.java
Date Fri, 04 Aug 2017 12:43:52 GMT
Author: desruisseaux
Date: Fri Aug  4 12:43:52 2017
New Revision: 1804115

URL: http://svn.apache.org/viewvc?rev=1804115&view=rev
Log:
Add factory methods for WritablePixelIterator.

Modified:
    sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/image/PixelIterator.java
    sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/image/WritablePixelIterator.java

Modified: sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/image/PixelIterator.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/image/PixelIterator.java?rev=1804115&r1=1804114&r2=1804115&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/image/PixelIterator.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/image/PixelIterator.java
[UTF-8] Fri Aug  4 12:43:52 2017
@@ -259,8 +259,8 @@ public abstract class PixelIterator {
      * Any other {@code order} value will cause an {@link IllegalArgumentException} to be
thrown.
      * More iteration orders may be supported in future Apache SIS versions.
      *
-     * @param  data     the raster which contains the sample values on which to iterate.
-     * @param  subArea  the raster region where to perform the iteration, or {@code null}
+     * @param  data     the image which contains the sample values on which to iterate.
+     * @param  subArea  the image region where to perform the iteration, or {@code null}
      *                  for iterating over all the image domain.
      * @param  window   size of the window to use in {@link #createWindow(TransferType)}
method, or {@code null} if none.
      * @param  order    the desired iteration order, or {@code null} for a default order.

Modified: sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/image/WritablePixelIterator.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/image/WritablePixelIterator.java?rev=1804115&r1=1804114&r2=1804115&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/image/WritablePixelIterator.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/image/WritablePixelIterator.java
[UTF-8] Fri Aug  4 12:43:52 2017
@@ -20,11 +20,13 @@ import java.io.Closeable;
 import java.awt.Dimension;
 import java.awt.Rectangle;
 import java.awt.image.Raster;
-import java.awt.image.RasterFormatException;
 import java.awt.image.RenderedImage;
 import java.awt.image.WritableRaster;
 import java.awt.image.WritableRenderedImage;
+import org.opengis.coverage.grid.SequenceType;
 import org.apache.sis.internal.raster.Resources;
+import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.ArgumentChecks;
 
 
 /**
@@ -98,43 +100,116 @@ public abstract class WritablePixelItera
     }
 
     /**
-     * Ensures that the given output raster has the same grid geometry than the input raster.
+     * Creates an iterator for all pixels in the given raster.
+     *
+     * @param  data  the raster which contains the sample values on which to iterate.
+     * @return a new iterator traversing all pixels in the given raster, in arbitrary order.
+     */
+    public static WritablePixelIterator create(WritableRaster data) {
+        return create(data, null, null, null, null);
+    }
+
+    /**
+     * Creates an iterator for all pixels in the given image.
+     *
+     * @param  data  the image which contains the sample values on which to iterate.
+     * @return a new iterator traversing all pixels in the given image, in arbitrary order.
      */
-    private static void checkCompatibility(final Raster input, final WritableRaster output)
{
-        final short message;
+    public static WritablePixelIterator create(WritableRenderedImage data) {
+        return create(data, null, null, null, null);
+    }
+
+    /**
+     * Creates an iterator for the given region in the given rasters.
+     * The {@code order} argument can have the following values:
+     *
+     * <table class="sis">
+     *   <caption>Supported iteration order</caption>
+     *   <tr><th>Value</th>                         <th>Iteration
order</th></tr>
+     *   <tr><td>{@code null}</td>                  <td>Most efficient
iteration order.</td></tr>
+     *   <tr><td>{@link SequenceType#LINEAR}</td>   <td>From left
to right, then from top to bottom.</td></tr>
+     * </table>
+     *
+     * Any other {@code order} value will cause an {@link IllegalArgumentException} to be
thrown.
+     * More iteration orders may be supported in future Apache SIS versions.
+     *
+     * @param  input    the raster which contains the sample values to read.
+     * @param  output   the raster where to write the sample values. Can be the same than
{@code input}.
+     * @param  subArea  the raster region where to perform the iteration, or {@code null}
+     *                  for iterating over all the raster domain.
+     * @param  window   size of the window to use in {@link #createWindow(TransferType)}
method, or {@code null} if none.
+     * @param  order    the desired iteration order, or {@code null} for a default order.
+     * @return a new writable iterator.
+     */
+    public static WritablePixelIterator create(Raster input, WritableRaster output,
+            Rectangle subArea, Dimension window, SequenceType order)
+    {
+        ArgumentChecks.ensureNonNull("input",  input);
+        ArgumentChecks.ensureNonNull("output", output);
         if (!input.getSampleModel().equals(output.getSampleModel())) {
-            message = Resources.Keys.MismatchedSampleModel;
+            throw new IllegalArgumentException(Resources.format(Resources.Keys.MismatchedSampleModel));
         } else if (!input.getBounds().equals(output.getBounds())) {
-            message = Resources.Keys.MismatchedImageLocation;
+            throw new IllegalArgumentException(Resources.format(Resources.Keys.MismatchedImageLocation));
+        }
+
+        // TODO: check here for cases that we can optimize (after we ported corresponding
implementations).
+
+        if (order == null || order.equals(SequenceType.LINEAR)) {
+            return new DefaultIterator(input, output, subArea, window);
         } else {
-            return;
+            throw new IllegalArgumentException(Errors.format(Errors.Keys.UnsupportedType_1,
order));
         }
-        throw new RasterFormatException(Resources.format(message));
     }
 
     /**
-     * Ensures that the given output image has the same grid geometry than the input image.
+     * Creates an iterator for the given region in the given image.
+     * The {@code order} argument can have the following values:
+     *
+     * <table class="sis">
+     *   <caption>Supported iteration order</caption>
+     *   <tr><th>Value</th>                         <th>Iteration
order</th></tr>
+     *   <tr><td>{@code null}</td>                  <td>Most efficient
iteration order.</td></tr>
+     * </table>
+     *
+     * Any other {@code order} value will cause an {@link IllegalArgumentException} to be
thrown.
+     * More iteration orders may be supported in future Apache SIS versions.
+     *
+     * @param  input    the image which contains the sample values to read.
+     * @param  output   the image where to write the sample values. Can be the same than
{@code input}.
+     * @param  subArea  the image region where to perform the iteration, or {@code null}
+     *                  for iterating over all the image domain.
+     * @param  window   size of the window to use in {@link #createWindow(TransferType)}
method, or {@code null} if none.
+     * @param  order    the desired iteration order, or {@code null} for a default order.
+     * @return a new iterator.
      */
-    private static void checkCompatibility(final RenderedImage input, final WritableRenderedImage
output) {
-        final short message;
+    public static WritablePixelIterator create(RenderedImage input, WritableRenderedImage
output,
+            Rectangle subArea, Dimension window, SequenceType order)
+    {
+        ArgumentChecks.ensureNonNull("input",  input);
+        ArgumentChecks.ensureNonNull("output", output);
         if (!input.getSampleModel().equals(output.getSampleModel())) {
-            message = Resources.Keys.MismatchedSampleModel;
+            throw new IllegalArgumentException(Resources.format(Resources.Keys.MismatchedSampleModel));
         } else if (input.getMinX()   != output.getMinX()  ||
                    input.getMinY()   != output.getMinY()  ||
                    input.getWidth()  != output.getWidth() ||
                    input.getHeight() != output.getHeight())
         {
-            message = Resources.Keys.MismatchedImageLocation;
+            throw new IllegalArgumentException(Resources.format(Resources.Keys.MismatchedImageLocation));
         } else if (input.getMinTileX()   != output.getMinTileX()  ||
                    input.getMinTileY()   != output.getMinTileY()  ||
                    input.getTileWidth()  != output.getTileWidth() ||
                    input.getTileHeight() != output.getTileHeight())
         {
-            message = Resources.Keys.MismatchedTileGrid;
+            throw new IllegalArgumentException(Resources.format(Resources.Keys.MismatchedTileGrid));
+        }
+
+        // TODO: check here for cases that we can optimize (after we ported corresponding
implementations).
+
+        if (order == null) {
+            return new DefaultIterator(input, output, subArea, window);
         } else {
-            return;
+            throw new IllegalArgumentException(Errors.format(Errors.Keys.UnsupportedType_1,
order));
         }
-        throw new RasterFormatException(Resources.format(message));
     }
 
     /**



Mime
View raw message