You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2021/11/28 13:08:08 UTC

[sis] 03/03: In `PlanarImage.verify()`, an unexpected value for "width" and "height" properties may be normal. So those "anomalies" should be reported only if everything else is okay.

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 9edee116e148b738097cfeecc40cff1f75982300
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Sun Nov 28 13:37:53 2021 +0100

    In `PlanarImage.verify()`, an unexpected value for "width" and "height" properties may be normal.
    So those "anomalies" should be reported only if everything else is okay.
---
 .../sis/gui/coverage/ImagePropertyExplorer.java    |  8 +++--
 .../org/apache/sis/internal/gui/Resources.java     |  2 +-
 .../apache/sis/internal/gui/Resources.properties   |  2 +-
 .../sis/internal/gui/Resources_fr.properties       |  2 +-
 .../apache/sis/coverage/grid/ReshapedImage.java    | 16 ++++-----
 .../java/org/apache/sis/image/PlanarImage.java     | 39 ++++++++++++++--------
 .../java/org/apache/sis/image/ResampledImage.java  | 10 +++---
 .../sis/internal/coverage/j2d/TiledImage.java      |  7 ++--
 8 files changed, 51 insertions(+), 35 deletions(-)

diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/ImagePropertyExplorer.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/ImagePropertyExplorer.java
index eb1208d..4de7c8b 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/ImagePropertyExplorer.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/ImagePropertyExplorer.java
@@ -630,7 +630,9 @@ public class ImagePropertyExplorer extends Widget {
 
         /**
          * Invoked when a new image is shown in this cell node. This method also tests image consistency.
-         * If an inconsistency is found, the line is shown in read with a warning message.
+         * If an inconsistency is found, the line is shown in red (except for "width" and "height") with
+         * a warning message. We do not use a red color for "width" and "height" because the mismatch may
+         * be normal.
          */
         @Override protected void updateItem(final RenderedImage image, final boolean empty) {
             super.updateItem(image, empty);
@@ -642,7 +644,9 @@ public class ImagePropertyExplorer extends Widget {
                     final String check = ((PlanarImage) image).verify();
                     if (check != null) {
                         text = Resources.format(Resources.Keys.InconsistencyIn_2, text, check);
-                        fill = Styles.ERROR_TEXT;
+                        if (!(check.equals("width") || check.equals("height"))) {
+                            fill = Styles.ERROR_TEXT;
+                        }
                     }
                 }
             }
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java
index e9e4b79..b693899 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java
@@ -257,7 +257,7 @@ public final class Resources extends IndexedResourceBundle {
         public static final short ImageStart = 36;
 
         /**
-         * {0} – inconsistency in `{1}` property
+         * {0} – `{1}` has an unexpected value.
          */
         public static final short InconsistencyIn_2 = 39;
 
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties
index 5fdf198..cbaefa2 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties
@@ -60,7 +60,7 @@ GeodeticDataset_1      = {0} geodetic dataset
 GeospatialFiles        = Geospatial data files
 Help                   = Help
 ImageStart             = Image start
-InconsistencyIn_2      = {0} \u2013 inconsistency in `{1}` property
+InconsistencyIn_2      = {0} \u2013 `{1}` has an unexpected value.
 IsolinesInRange        = Generate isolines at constant interval\nstarting from given minimum.
 LicenseAgreement       = Do you accept the license shown below?
 Loading                = Loading\u2026
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties
index c2bf0d5..06e8ac6 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties
@@ -65,7 +65,7 @@ GeodeticDataset_1      = Base de donn\u00e9es g\u00e9od\u00e9siques {0}
 GeospatialFiles        = Fichiers de donn\u00e9es g\u00e9ospatiales
 Help                   = Aide
 ImageStart             = D\u00e9but de l\u2019image
-InconsistencyIn_2      = {0} \u2013 incoh\u00e9rence dans la propri\u00e9t\u00e9 `{1}`
+InconsistencyIn_2      = {0} \u2013 `{1}` a une valeur inattendue.
 IsolinesInRange        = G\u00e9n\u00e8re des isolignes \u00e0 intervalle constant en\ncommen\u00e7ant \u00e0 la valeur minimale sp\u00e9cifi\u00e9e.
 LicenseAgreement       = Acceptez-vous la licence ci-dessous?
 Loading                = Chargement\u2026
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/ReshapedImage.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/ReshapedImage.java
index ca98c7f..c0efa44 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/ReshapedImage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/ReshapedImage.java
@@ -288,16 +288,16 @@ final class ReshapedImage extends PlanarImage {
 
     /**
      * Verifies whether image layout information are consistent.
+     * This method first checks the properties modified by this class.
+     * If okay, then this method completes the check with all verifications
+     * {@linkplain ComputedImage#verify() documented in parent class}
      */
     @Override
     public String verify() {
-        final String error = super.verify();
-        if (error == null) {
-            if (getMinX() != image.getMinX() + (minTileX - image.getMinTileX()) * getTileWidth()  + offsetX) return "minX";
-            if (getMinY() != image.getMinY() + (minTileY - image.getMinTileY()) * getTileHeight() + offsetY) return "minY";
-            if (getTileGridXOffset() != super.getTileGridXOffset()) return "tileGridXOffset";
-            if (getTileGridYOffset() != super.getTileGridYOffset()) return "tileGridYOffset";
-        }
-        return error;
+        if (getMinX() != image.getMinX() + (minTileX - image.getMinTileX()) * getTileWidth()  + offsetX) return "minX";
+        if (getMinY() != image.getMinY() + (minTileY - image.getMinTileY()) * getTileHeight() + offsetY) return "minY";
+        if (getTileGridXOffset() != super.getTileGridXOffset()) return "tileGridXOffset";
+        if (getTileGridYOffset() != super.getTileGridYOffset()) return "tileGridYOffset";
+        return super.verify();      // "width" and "height" properties should be checked last.
     }
 }
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/PlanarImage.java b/core/sis-feature/src/main/java/org/apache/sis/image/PlanarImage.java
index 56046c1..ff230d7 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/PlanarImage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/PlanarImage.java
@@ -102,7 +102,7 @@ import org.apache.sis.coverage.grid.GridGeometry;       // For javadoc
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.1
+ * @version 1.2
  * @since   1.1
  * @module
  */
@@ -517,20 +517,31 @@ public abstract class PlanarImage implements RenderedImage {
      *
      * <p>The default implementation may return the following identifiers, in that order
      * (i.e. this method returns the identifier of the first test that fail):</p>
-     * <ul>
-     *   <li>{@code "SampleModel"} — Sample model is incompatible with color model.</li>
-     *   <li>{@code "tileWidth"}   — tile width is greater than sample model width.</li>
-     *   <li>{@code "tileHeight"}  — tile height is greater than sample model height.</li>
-     *   <li>{@code "numXTiles"}   — number of tiles on the X axis is inconsistent with image width.</li>
-     *   <li>{@code "width"}       — image width is not an integer multiple of tile width.</li>
-     *   <li>{@code "numYTiles"}   — number of tiles on the Y axis is inconsistent with image height.</li>
-     *   <li>{@code "height"}      — image height is not an integer multiple of tile height.</li>
-     *   <li>{@code "tileX"}       — {@code minTileX} and/or {@code tileGridXOffset} is inconsistent.</li>
-     *   <li>{@code "tileY"}       — {@code minTileY} and/or {@code tileGridYOffset} is inconsistent.</li>
-     * </ul>
      *
-     * Subclasses may perform additional checks. For example some subclasses also check specifically
-     * for {@code "minX"}, {@code "minY"}, {@code "tileGridXOffset"} and {@code "tileGridYOffset"}.
+     * <table class="sis">
+     *   <caption>Identifiers of inconsistent values</caption>
+     *   <tr><th>Identifier</th>            <th>Meaning</th></tr>
+     *   <tr><td>{@code "SampleModel"}</td> <td>Sample model is incompatible with color model.</td></tr>
+     *   <tr><td>{@code "tileWidth"}</td>   <td>Tile width is greater than sample model width.</td></tr>
+     *   <tr><td>{@code "tileHeight"}</td>  <td>Tile height is greater than sample model height.</td></tr>
+     *   <tr><td>{@code "numXTiles"}</td>   <td>Number of tiles on the X axis is inconsistent with image width.</td></tr>
+     *   <tr><td>{@code "numYTiles"}</td>   <td>Number of tiles on the Y axis is inconsistent with image height.</td></tr>
+     *   <tr><td>{@code "tileX"}</td>       <td>{@code minTileX} and/or {@code tileGridXOffset} is inconsistent.</td></tr>
+     *   <tr><td>{@code "tileY"}</td>       <td>{@code minTileY} and/or {@code tileGridYOffset} is inconsistent.</td></tr>
+     *   <tr><td>{@code "width"}</td>       <td>image width is not an integer multiple of tile width.</td></tr>
+     *   <tr><td>{@code "height"}</td>      <td>Image height is not an integer multiple of tile height.</td></tr>
+     * </table>
+     *
+     * Subclasses may perform additional checks. For example some subclasses have specialized checks
+     * for {@code "minX"}, {@code "minY"}, {@code "tileGridXOffset"} and {@code "tileGridYOffset"}
+     * values before to fallback on the more generic {@code "tileX"} and {@code "tileY"} above checks.
+     *
+     * <h4>Ignorable inconsistency</h4>
+     * Inconsistency in {@code "width"} and {@code "height"} values may be acceptable
+     * if all other verifications pass (in particular the {@code "numXTiles"} and {@code "numYTiles"} checks).
+     * It happens when tiles in the last row or last column have some unused space compared to the image size.
+     * This is legal in TIFF format for example. For this reason, the {@code "width"} and {@code "height"}
+     * values should be checked last, after all other values have been verified consistent.
      *
      * @return {@code null} if image layout information are consistent,
      *         or the name of inconsistent attribute if a problem is found.
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/ResampledImage.java b/core/sis-feature/src/main/java/org/apache/sis/image/ResampledImage.java
index 54974f1..f348c61 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/ResampledImage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/ResampledImage.java
@@ -438,19 +438,19 @@ public class ResampledImage extends ComputedImage {
     }
 
     /**
-     * Verifies whether image layout information are consistent. This method performs all verifications
-     * {@linkplain ComputedImage#verify() documented in parent class}, then verifies that source coordinates
+     * Verifies whether image layout information are consistent. This method verifies that source coordinates
      * required by this image (computed by converting {@linkplain #getBounds() this image bounds} using the
      * {@link #toSource} transform) intersects the bounds of the source image. If this is not the case, then
      * this method returns {@code "toSource"} for signaling that the transform may have a problem.
+     * Otherwise this method completes the check with all verifications
+     * {@linkplain ComputedImage#verify() documented in parent class}
      *
      * @return {@code null} if image layout information are consistent,
      *         or the name of inconsistent attribute if a problem is found.
      */
     @Override
     public String verify() {
-        String error = super.verify();
-        if (error == null && toSource instanceof MathTransform2D) try {
+        if (toSource instanceof MathTransform2D) try {
             final Rectangle bounds = getBounds();
             final Rectangle2D tb = Shapes2D.transform((MathTransform2D) toSource, bounds, bounds);
             if (!ImageUtilities.getBounds(getSource()).intersects(tb)) {
@@ -460,7 +460,7 @@ public class ResampledImage extends ComputedImage {
             recoverableException("verify", e);
             return "toSource";
         }
-        return error;
+        return super.verify();      // "width" and "height" properties should be checked last.
     }
 
     /**
diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/TiledImage.java b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/TiledImage.java
index abecce8..19976bf 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/TiledImage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/TiledImage.java
@@ -100,8 +100,9 @@ public class TiledImage extends PlanarImage {
 
     /**
      * Verifies whether image layout information and tile coordinates are consistent.
-     * This method verifies the size and minimum pixel coordinates of all tiles,
-     * in addition to the verifications documented in the super-class.
+     * This method verifies the size and minimum pixel coordinates of all tiles.
+     * If okay, then this method completes the check with all verifications
+     * {@linkplain ComputedImage#verify() documented in parent class}
      *
      * @return {@code null} if image layout information are consistent,
      *         or the name of inconsistent attribute if a problem is found.
@@ -122,7 +123,7 @@ public class TiledImage extends PlanarImage {
             if (tile.getMinX()   != tileWidth  * tx + minX) return property(tx, ty, "x");
             if (tile.getMinY()   != tileHeight * ty + minY) return property(tx, ty, "y");
         }
-        return super.verify();
+        return super.verify();      // "width" and "height" properties should be checked last.
     }
 
     /**