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: After invocation of ImageUtilities.clip(…), verifiy that the intersection is not empty. Various documentation fixes.
Date Thu, 27 Aug 2020 17:10:12 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 3771a28  After invocation of ImageUtilities.clip(…), verifiy that the intersection
is not empty. Various documentation fixes.
3771a28 is described below

commit 3771a283ba8cf96eb8a163b4595401f03fa63c40
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Thu Aug 27 18:20:46 2020 +0200

    After invocation of ImageUtilities.clip(…), verifiy that the intersection is not empty.
    Various documentation fixes.
---
 .../org/apache/sis/gui/coverage/RenderingData.java |  5 ++--
 .../gui/referencing/PositionableProjection.java    |  8 ++++---
 .../org/apache/sis/internal/gui/Resources.java     |  2 +-
 .../apache/sis/internal/gui/Resources.properties   |  2 +-
 .../sis/internal/gui/Resources_fr.properties       |  2 +-
 .../java/org/apache/sis/image/AnnotatedImage.java  |  6 +++++
 .../apache/sis/image/BandedSampleConverter.java    | 28 ++++++++++++----------
 .../java/org/apache/sis/image/ImageCombiner.java   | 14 ++++++-----
 .../java/org/apache/sis/image/PlanarImage.java     |  6 +++--
 .../java/org/apache/sis/image/PrefetchedImage.java |  8 +++++++
 .../sis/internal/coverage/j2d/ImageUtilities.java  |  2 ++
 .../internal/coverage/j2d/WritableTiledImage.java  | 14 ++++++-----
 .../main/java/org/apache/sis/portrayal/Canvas.java |  4 ++--
 13 files changed, 64 insertions(+), 37 deletions(-)

diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/RenderingData.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/RenderingData.java
index 111a22d..000f91d 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/RenderingData.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/RenderingData.java
@@ -347,13 +347,14 @@ final class RenderingData implements Cloneable {
     final RenderedImage prefetch(final RenderedImage resampledImage, final AffineTransform
resampledToDisplay,
                                  final Envelope2D displayBounds)
     {
+        final Rectangle areaOfInterest;
         try {
-            return processor.prefetch(resampledImage, (Rectangle) AffineTransforms2D.transform(
-                        resampledToDisplay.createInverse(), displayBounds, new Rectangle()));
+            areaOfInterest = (Rectangle) AffineTransforms2D.transform(resampledToDisplay.createInverse(),
displayBounds, new Rectangle());
         } catch (NoninvertibleTransformException e) {
             recoverableException(e);
             return resampledImage;
         }
+        return processor.prefetch(resampledImage, areaOfInterest);
     }
 
     /**
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/PositionableProjection.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/PositionableProjection.java
index 24ebda5..ed4353f 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/PositionableProjection.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/PositionableProjection.java
@@ -204,15 +204,17 @@ public abstract class PositionableProjection extends CodeList<PositionableProjec
         if (!Utilities.equalsIgnoreMetadata(normalizedCRS, inherit)) {
             center = CRS.findOperation(inherit, normalizedCRS, null).getMathTransform().transform(center,
null);
         }
-        return createProjectedCRS(normalizedCRS, center.getOrdinate(0), center.getOrdinate(1));
+        return createProjectedCRS(normalizedCRS,
+                Latitude .clamp    (center.getOrdinate(0)),
+                Longitude.normalize(center.getOrdinate(1)));
     }
 
     /**
      * Creates a map projection centered on the given latitude and longitude.
      *
      * @param  baseCRS    the base CRS of the projection to create.
-     * @param  latitude   latitude of projection center.
-     * @param  longitude  longitude of projection center.
+     * @param  latitude   latitude of projection center in degrees.
+     * @param  longitude  longitude of projection center in degrees.
      * @return projection centered on the given position.
      * @throws FactoryException if an error occurred while creating the projection.
      */
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 7d22b93..f5077d7 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
@@ -206,7 +206,7 @@ public final class Resources extends IndexedResourceBundle {
         public static final short ImageStart = 36;
 
         /**
-         * {0} – inconsistency in {1}
+         * {0} – inconsistency in `{1}` property
          */
         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 ce5391a..3c48248 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
@@ -50,7 +50,7 @@ FullScreen             = Full screen
 GeospatialFiles        = Geospatial data files
 Help                   = Help
 ImageStart             = Image start
-InconsistencyIn_2      = {0} \u2013 inconsistency in {1}
+InconsistencyIn_2      = {0} \u2013 inconsistency in `{1}` property
 Loading                = Loading\u2026
 Mercator               = Mercator
 MainWindow             = Main window
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 764464f..d775028 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
@@ -55,7 +55,7 @@ FullScreen             = Plein \u00e9cran
 GeospatialFiles        = Fichiers de donn\u00e9es g\u00e9ospatiales
 Help                   = Aide
 ImageStart             = D\u00e9but de l\u2019image
-InconsistencyIn_2      = {0} \u2013 incoh\u00e9rence dans {1}
+InconsistencyIn_2      = {0} \u2013 incoh\u00e9rence dans la propri\u00e9t\u00e9 `{1}`
 Loading                = Chargement\u2026
 Mercator               = Mercator
 MainWindow             = Fen\u00eatre principale
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/AnnotatedImage.java b/core/sis-feature/src/main/java/org/apache/sis/image/AnnotatedImage.java
index 82222ef..c0430c7 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/AnnotatedImage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/AnnotatedImage.java
@@ -200,6 +200,12 @@ abstract class AnnotatedImage extends ImageAdapter {
         if (areaOfInterest != null) {
             bounds = areaOfInterest.getBounds();
             ImageUtilities.clipBounds(source, bounds);
+            if (bounds.isEmpty()) {
+                bounds.x = getMinX();
+                bounds.y = getMinY();
+                bounds.width  = 0;
+                bounds.height = 0;
+            }
             if (areaOfInterest.contains(bounds)) {
                 areaOfInterest = bounds;
             }
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 13beb7b..6639c73 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
@@ -453,19 +453,21 @@ class BandedSampleConverter extends ComputedImage {
             final Rectangle bounds = data.getBounds();
             final WritableRenderedImage target = (WritableRenderedImage) getSource();
             ImageUtilities.clipBounds(target, bounds);
-            final TileOpExecutor executor = new TileOpExecutor(target, bounds) {
-                @Override protected void writeTo(final WritableRaster target) throws TransformException
{
-                    final Rectangle aoi = target.getBounds().intersection(bounds);
-                    Transferer.create(data, target, aoi).compute(inverses);
-                }
-            };
-            executor.writeTo(target);
-            /*
-             * Request to recompute the tiles of this `BandedSampleConverter` because if
the values
-             * in the source image are integers, then converting back to floating point values
may
-             * produce slightly different results.
-             */
-            markDirtyTiles(executor.getTileIndices());
+            if (!bounds.isEmpty()) {
+                final TileOpExecutor executor = new TileOpExecutor(target, bounds) {
+                    @Override protected void writeTo(final WritableRaster target) throws
TransformException {
+                        final Rectangle aoi = target.getBounds().intersection(bounds);
+                        Transferer.create(data, target, aoi).compute(inverses);
+                    }
+                };
+                executor.writeTo(target);
+                /*
+                 * Request to recompute the tiles of this `BandedSampleConverter` because
if the values
+                 * in the source image are integers, then converting back to floating point
values may
+                 * produce slightly different results.
+                 */
+                markDirtyTiles(executor.getTileIndices());
+            }
         }
     }
 }
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/ImageCombiner.java b/core/sis-feature/src/main/java/org/apache/sis/image/ImageCombiner.java
index 3b0d49c..8a1f5d9 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/ImageCombiner.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/ImageCombiner.java
@@ -184,12 +184,14 @@ public class ImageCombiner implements Consumer<RenderedImage>
{
         final WritableRenderedImage destination = this.destination;
         final Rectangle bounds = ImageUtilities.getBounds(source);
         ImageUtilities.clipBounds(destination, bounds);
-        final TileOpExecutor executor = new TileOpExecutor(source, bounds) {
-            @Override protected void readFrom(final Raster tile) {
-                destination.setData(tile);
-            }
-        };
-        executor.readFrom(processor.prefetch(source, bounds));
+        if (!bounds.isEmpty()) {
+            final TileOpExecutor executor = new TileOpExecutor(source, bounds) {
+                @Override protected void readFrom(final Raster tile) {
+                    destination.setData(tile);
+                }
+            };
+            executor.readFrom(processor.prefetch(source, bounds));
+        }
     }
 
     /**
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 0be29e9..f32d979 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
@@ -462,7 +462,9 @@ public abstract class PlanarImage implements RenderedImage {
             aoi = getBounds();
             raster = createWritableRaster(aoi);
         }
-        copyData(aoi, raster);
+        if (!aoi.isEmpty()) {
+            copyData(aoi, raster);
+        }
         return raster;
     }
 
@@ -604,7 +606,7 @@ colors: if (cm != null) {
         }
         final String error = verify();
         if (error != null) {
-            buffer.append("; ⚠ mismatched ").append(error);
+            buffer.append("; ⚠ inconsistency in `").append(error).append("` property");
         }
         return buffer.append(']').toString();
     }
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 6b5c0c0..6436786 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
@@ -76,6 +76,14 @@ final class PrefetchedImage extends PlanarImage {
         if (areaOfInterest != null) {
             areaOfInterest = new Rectangle(areaOfInterest);
             ImageUtilities.clipBounds(source, areaOfInterest);
+            if (areaOfInterest.isEmpty()) {
+                minTileX  = 0;
+                minTileY  = 0;
+                numXTiles = 0;
+                numYTiles = 0;
+                tiles = null;
+                return;
+            }
         }
         final Worker worker = new Worker(source, areaOfInterest);
         final Rectangle ti = worker.getTileIndices();
diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/ImageUtilities.java
b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/ImageUtilities.java
index d8cda2c..d1d7eea 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/ImageUtilities.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/ImageUtilities.java
@@ -94,6 +94,8 @@ public final class ImageUtilities extends Static {
 
     /**
      * Clips the given rectangle to the bounds of the given image.
+     * Note that {@link Rectangle#width} and/or {@link Rectangle#width} results may be negative.
+     * Consequently the caller should test {@link Rectangle#isEmpty()} on the returned value.
      *
      * @param  image  the image.
      * @param  aoi    a region of interest to clip to the image bounds.
diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/WritableTiledImage.java
b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/WritableTiledImage.java
index 16b5078..494a1b4 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/WritableTiledImage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/WritableTiledImage.java
@@ -208,11 +208,13 @@ public class WritableTiledImage extends TiledImage implements WritableRenderedIm
     public void setData(final Raster data) {
         final Rectangle bounds = data.getBounds();
         ImageUtilities.clipBounds(this, bounds);
-        final TileOpExecutor op = new TileOpExecutor(this, bounds) {
-            @Override protected void writeTo(final WritableRaster target) {
-                target.setRect(data);
-            }
-        };
-        op.writeTo(this);
+        if (!bounds.isEmpty()) {
+            final TileOpExecutor op = new TileOpExecutor(this, bounds) {
+                @Override protected void writeTo(final WritableRaster target) {
+                    target.setRect(data);
+                }
+            };
+            op.writeTo(this);
+        }
     }
 }
diff --git a/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/Canvas.java b/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/Canvas.java
index ecfa8da..1df30d3 100644
--- a/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/Canvas.java
+++ b/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/Canvas.java
@@ -536,7 +536,7 @@ public class Canvas extends Observable implements Localized {
                     final DirectPosition poiInNew = poiToNew.transform(pointOfInterest, allocatePosition());
                     /*
                      * We need anchor in new CRS. If no anchor was specified, `poiInNew`
is already what we need.
-                     * Otherwise convert the anchor to coordinates in the new CRS. There
is good change that the
+                     * Otherwise convert the anchor to coordinates in the new CRS. There
is good chances that the
                      * anchor CRS is the objective CRS, so we can reuse `poiToNew`.
                      */
                     if (anchor == null) {
@@ -557,7 +557,7 @@ public class Canvas extends Observable implements Localized {
                      * and the Jacobian matrix around POI to be approximately the same. Conceptually,
this is as if we
                      * wanted to convert from new CRS to old CRS before to apply the old
`objectiveToCRS` transform.
                      * We get this effect by pre-concatenating a linear approximation of
"new to old CRS" transform
-                     * before `objectiveToCRS`. That approximation contain only uniform scale,
rotation or axis flips
+                     * before `objectiveToCRS`. That approximation contains only uniform
scale, rotation or axis flips
                      * in order to preserve pixel ratios (otherwise the map projection would
appear deformed).
                      */
                     oldObjectiveToDisplay = getObjectiveToDisplay();


Mime
View raw message