sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 09/10: Consolidation in the mechanism for inheriting properties.
Date Wed, 29 Jul 2020 16:19:02 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

commit d78b6deb197d8389582f9db6b13a74ec3be9f26a
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Jul 29 16:03:24 2020 +0200

    Consolidation in the mechanism for inheriting properties.
---
 .../java/org/apache/sis/image/BandSelectImage.java |  2 +-
 .../apache/sis/image/BandedSampleConverter.java    | 26 +++++++++++++-------
 .../main/java/org/apache/sis/image/MaskImage.java  | 15 ++----------
 .../sis/image/PositionalConsistencyImage.java      |  2 +-
 .../java/org/apache/sis/image/PrefetchedImage.java |  2 +-
 .../org/apache/sis/image/SourceAlignedImage.java   | 28 +++++++++++++++++-----
 .../sis/internal/coverage/j2d/ImageLayout.java     | 11 ++++++++-
 7 files changed, 55 insertions(+), 31 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/BandSelectImage.java b/core/sis-feature/src/main/java/org/apache/sis/image/BandSelectImage.java
index 8234fd9..f209b49 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/BandSelectImage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/BandSelectImage.java
@@ -111,7 +111,7 @@ final class BandSelectImage extends SourceAlignedImage {
      */
     @Override
     public String[] getPropertyNames() {
-        return getPropertyNames(INHERITED_PROPERTIES, null);
+        return filterPropertyNames(getSource().getPropertyNames(), INHERITED_PROPERTIES,
null);
     }
 
     /**
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/BandedSampleConverter.java
b/core/sis-feature/src/main/java/org/apache/sis/image/BandedSampleConverter.java
index 2584a6b..bc01848 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/BandedSampleConverter.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/BandedSampleConverter.java
@@ -71,6 +71,14 @@ class BandedSampleConverter extends ComputedImage {
      */
 
     /**
+     * Properties potentially added by this image, no matter if present in source image or
not. Must be consistent
+     * with the <cite>switch case</cite> statement doing its own calculation
in {@link #getProperty(String)}.
+     *
+     * @see #getPropertyNames()
+     */
+    private static final String[] ADDED_PROPERTIES = {SAMPLE_RESOLUTIONS_KEY};
+
+    /**
      * The transfer functions to apply on each band of the source image.
      */
     private final MathTransform1D[] converters;
@@ -206,8 +214,14 @@ class BandedSampleConverter extends ComputedImage {
      */
     @Override
     public Object getProperty(final String key) {
-        if (SAMPLE_RESOLUTIONS_KEY.equals(key) && sampleResolutions != null) {
-            return sampleResolutions.clone();
+        if (SourceAlignedImage.POSITIONAL_PROPERTIES.contains(key)) {
+            if (SAMPLE_RESOLUTIONS_KEY.equals(key)) {
+                if (sampleResolutions != null) {
+                    return sampleResolutions.clone();
+                }
+            } else {
+                return getSource().getProperty(key);
+            }
         }
         return super.getProperty(key);
     }
@@ -217,12 +231,8 @@ class BandedSampleConverter extends ComputedImage {
      */
     @Override
     public String[] getPropertyNames() {
-        if (sampleResolutions != null) {
-            return new String[] {
-                SAMPLE_RESOLUTIONS_KEY
-            };
-        }
-        return super.getPropertyNames();
+        return SourceAlignedImage.filterPropertyNames(getSource().getPropertyNames(),
+                SourceAlignedImage.POSITIONAL_PROPERTIES, (sampleResolutions != null) ? ADDED_PROPERTIES
: null);
     }
 
     /**
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/MaskImage.java b/core/sis-feature/src/main/java/org/apache/sis/image/MaskImage.java
index f3c92b9..28e8e3b 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/MaskImage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/MaskImage.java
@@ -16,13 +16,11 @@
  */
 package org.apache.sis.image;
 
-import java.util.Set;
 import java.awt.image.Raster;
 import java.awt.image.WritableRaster;
 import org.opengis.referencing.operation.TransformException;
 import org.apache.sis.internal.coverage.j2d.ColorModelFactory;
 import org.apache.sis.internal.coverage.j2d.ImageUtilities;
-import org.apache.sis.internal.jdk9.JDK9;
 
 
 /**
@@ -36,15 +34,6 @@ import org.apache.sis.internal.jdk9.JDK9;
  */
 final class MaskImage extends SourceAlignedImage {
     /**
-     * Properties inherited from the source image. Must be consistent with the <cite>switch
case</cite>
-     * statement delegating to the source image in {@link #getProperty(String)}.
-     *
-     * @see #getPropertyNames()
-     */
-    private static final Set<String> INHERITED_PROPERTIES = JDK9.setOf(
-            GRID_GEOMETRY_KEY, POSITIONAL_ACCURACY_KEY, ResampledImage.POSITIONAL_CONSISTENCY_KEY);
-
-    /**
      * Creates a new instance for the given image.
      */
     MaskImage(final ResampledImage image) {
@@ -57,7 +46,7 @@ final class MaskImage extends SourceAlignedImage {
      */
     @Override
     public Object getProperty(final String key) {
-        return INHERITED_PROPERTIES.contains(key) ? getSource().getProperty(key) : super.getProperty(key);
+        return POSITIONAL_PROPERTIES.contains(key) ? getSource().getProperty(key) : super.getProperty(key);
     }
 
     /**
@@ -67,7 +56,7 @@ final class MaskImage extends SourceAlignedImage {
      */
     @Override
     public String[] getPropertyNames() {
-        return getPropertyNames(INHERITED_PROPERTIES, null);
+        return filterPropertyNames(getSource().getPropertyNames(), POSITIONAL_PROPERTIES,
null);
     }
 
     /**
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/PositionalConsistencyImage.java
b/core/sis-feature/src/main/java/org/apache/sis/image/PositionalConsistencyImage.java
index 77f2596..370cb2f 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/PositionalConsistencyImage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/PositionalConsistencyImage.java
@@ -103,7 +103,7 @@ final class PositionalConsistencyImage extends SourceAlignedImage {
      */
     @Override
     public String[] getPropertyNames() {
-        return getPropertyNames(INHERITED_PROPERTIES, ADDED_PROPERTIES);
+        return filterPropertyNames(getSource().getPropertyNames(), INHERITED_PROPERTIES,
ADDED_PROPERTIES);
     }
 
     /**
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/PrefetchedImage.java b/core/sis-feature/src/main/java/org/apache/sis/image/PrefetchedImage.java
index 9d7e47e..6b5c0c0 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/PrefetchedImage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/PrefetchedImage.java
@@ -107,7 +107,7 @@ final class PrefetchedImage extends PlanarImage {
             tileGridYOffset = source.getTileGridYOffset();
         }
 
-        /** Invoked in a when a tile have been computed, possibly in a background thread.
*/
+        /** Invoked when a tile has been computed, possibly in a background thread. */
         @Override protected void readFrom(final Raster source) {
             final long tx = Math.floorDiv(source.getMinX() - tileGridXOffset, tileWidth)
 - minTileX;
             final long ty = Math.floorDiv(source.getMinY() - tileGridYOffset, tileHeight)
- minTileY;
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/SourceAlignedImage.java b/core/sis-feature/src/main/java/org/apache/sis/image/SourceAlignedImage.java
index 05209fe..49795ad 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/SourceAlignedImage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/SourceAlignedImage.java
@@ -22,6 +22,7 @@ import java.awt.image.SampleModel;
 import java.awt.image.RenderedImage;
 import org.apache.sis.util.ArraysExt;
 import org.apache.sis.util.Workaround;
+import org.apache.sis.internal.jdk9.JDK9;
 
 
 /**
@@ -29,6 +30,11 @@ import org.apache.sis.util.Workaround;
  * In addition of pixel coordinate system, images share also the same tile indices.
  * Tiles in this image have the same size than tiles in the source image.
  *
+ * <div class="note"><b>Relationship with other classes</b><br>
+ * This class is similar to {@link ImageAdapter} except that it extends {@link ComputedImage}
+ * and does not forward {@link #getTile(int, int)}, {@link #getData()} and other data methods
+ * to the source image.</div>
+ *
  * @author  Martin Desruisseaux (Geomatys)
  * @version 1.1
  * @since   1.1
@@ -36,6 +42,14 @@ import org.apache.sis.util.Workaround;
  */
 abstract class SourceAlignedImage extends ComputedImage {
     /**
+     * Convenience collection for subclasses that inherit all properties related to positioning.
+     * May be used as the {@code inherit} argument in {@link #filterPropertyNames(String[],
Set, String[])}.
+     * Inheriting those properties make sense for operations that do not change pixel coordinates.
+     */
+    static final Set<String> POSITIONAL_PROPERTIES = JDK9.setOf(GRID_GEOMETRY_KEY,
+            POSITIONAL_ACCURACY_KEY, ResampledImage.POSITIONAL_CONSISTENCY_KEY);
+
+    /**
      * The color model for this image.
      */
     private final ColorModel colorModel;
@@ -88,16 +102,18 @@ abstract class SourceAlignedImage extends ComputedImage {
      * Returns the names of properties as a merge between source properties (after filtering)
and properties added
      * by the subclass. This is a helper method for {@link #getPropertyNames()} implementations
in subclasses.
      *
+     * <p>The {@code names} argument should be the result of invoking {@link RenderedImage#getPropertyNames()}
+     * on the source image. This method modifies directly that array returned by {@code getPropertyNames()}
on
+     * the assumption that the array is already a copy. This assumption is okay when the
source is known to be
+     * an Apache SIS implementation.</p>
+     *
+     * @param  names    names of properties to filter, or {@code null} if none.
+     *                  If non-null, this array will be modified in-place.
      * @param  inherit  properties to inherit from the source.
      * @param  append   properties to append, or {@code null} if none.
      * @return properties recognized by this image, or {@code null} if none.
      */
-    final String[] getPropertyNames(final Set<String> inherit, final String[] append)
{
-        /*
-         * This method modifies directly the array returned by `getPropertyNames()` on the
assumption that the array
-         * is already a copy. This assumption is okay when the source is known to be an Apache
SIS implementation.
-         */
-        String[] names = getSource().getPropertyNames();
+    static String[] filterPropertyNames(String[] names, final Set<String> inherit,
final String[] append) {
         if (names == null) {
             return (append != null) ? append.clone() : null;
         }
diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/ImageLayout.java
b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/ImageLayout.java
index d1fff0c..10e8cd8 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/ImageLayout.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/ImageLayout.java
@@ -79,6 +79,15 @@ public class ImageLayout {
     }
 
     /**
+     * Returns the preferred tile size. This is the dimension values specified at construction
time.
+     *
+     * @return the preferred tile size.
+     */
+    public final Dimension getPreferredTileSize() {
+        return new Dimension(preferredTileWidth, preferredTileHeight);
+    }
+
+    /**
      * Suggests a tile size close to {@code tileSize} for the specified {@code imageSize}.
      * First, this method tries to return a tile size which is a divisor of the image size.
      * If no such divisor is found and {@code allowPartialTiles} is {@code true}, then this
@@ -213,7 +222,7 @@ public class ImageLayout {
             width  = singleXTile ? image.getWidth()  : image.getTileWidth();
             height = singleYTile ? image.getHeight() : image.getTileHeight();
         } else {
-            return new Dimension(preferredTileWidth, preferredTileHeight);
+            return getPreferredTileSize();
         }
         final Dimension tileSize = new Dimension(
                 toTileSize(width,  preferredTileWidth,  allowPartialTiles & singleXTile),


Mime
View raw message