sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ama...@apache.org
Subject [sis] branch geoapi-4.0 updated: fix(Core): fix bad size computing on GridCoverage2D render (crop) operation
Date Thu, 04 Jun 2020 10:15:41 GMT
This is an automated email from the ASF dual-hosted git repository.

amanin 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 4ba19c7  fix(Core): fix bad size computing on GridCoverage2D render (crop) operation
4ba19c7 is described below

commit 4ba19c7a9d32155af2153c39e514605cf8c492a3
Author: Alexis Manin <amanin@apache.org>
AuthorDate: Thu Jun 4 12:15:00 2020 +0200

    fix(Core): fix bad size computing on GridCoverage2D render (crop) operation
---
 .../apache/sis/coverage/grid/GridCoverage2D.java   |  5 ++-
 .../sis/coverage/grid/GridCoverage2DTest.java      | 47 ++++++++++++++++++++++
 2 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage2D.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage2D.java
index 47c71e7..5da66ab 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage2D.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage2D.java
@@ -578,12 +578,13 @@ public class GridCoverage2D extends GridCoverage {
              * upper-left point is inside the image.
              */
             if (data instanceof BufferedImage) {
+                // BufferedImage origin should be (0, 0), but for consistency over image
API, we consider it variable
                 final long ix = data.getMinX();
                 final long iy = data.getMinY();
                 if (xmin >= ix && ymin >= iy) {
                     return ((BufferedImage) data).getSubimage(toIntExact(xmin), toIntExact(ymin),
-                            toIntExact(min(xmax + 1, ix + data.getWidth()  - 1) - xmin),
-                            toIntExact(min(ymax + 1, iy + data.getHeight() - 1) - ymin));
+                            toIntExact(min(xmax + 1, ix + data.getWidth() ) - xmin),
+                            toIntExact(min(ymax + 1, iy + data.getHeight()) - ymin));
                 }
             }
             /*
diff --git a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridCoverage2DTest.java
b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridCoverage2DTest.java
index a0be3dd..b2ef925 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridCoverage2DTest.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridCoverage2DTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.coverage.grid;
 
+import java.awt.image.RenderedImage;
 import java.util.List;
 import java.util.Collections;
 import java.awt.image.BufferedImage;
@@ -194,6 +195,52 @@ public strictfp class GridCoverage2DTest extends TestCase {
     }
 
     /**
+     * Ensure that calling {@link GridCoverage#render(GridExtent)} with a sub-extent (crop
operation)
+     * returns precisely the requested area, not a smaller or bigger one.
+     */
+    @Test
+    public void render_of_subextent() {
+        final GridCoverage coverage = createTestCoverage();
+        final Raster completeRendering = coverage.render(null).getTile(0, 0);
+
+        final GridExtent singleRow = new GridExtent(2, 1).translate(0, 1);
+        RenderedImage subset = coverage.render(singleRow);
+        assertEquals("Rendering width", 2, subset.getWidth());
+        assertEquals("Rendering height", 1, subset.getHeight());
+        Raster subsetTile = subset.getTile(0, 0);
+        assertArrayEquals(
+                "Row extraction, pixel source(0, 1) -> output(0, 0)",
+                completeRendering.getPixel(0, 1, (double[])null),
+                subsetTile.getPixel(0, 0, (double[])null),
+                1e-1
+        );
+        assertArrayEquals(
+                "Row extraction, pixel source(1, 1) -> output(1, 0)",
+                completeRendering.getPixel(1, 1, (double[])null),
+                subsetTile.getPixel(1, 0, (double[])null),
+                1e-1
+        );
+
+        final GridExtent singleCol = new GridExtent(1, 2).translate(1, 0);
+        subset = coverage.render(singleCol);
+        assertEquals("Rendering width", 1, subset.getWidth());
+        assertEquals("Rendering height", 2, subset.getHeight());
+        subsetTile = subset.getTile(0, 0);
+        assertArrayEquals(
+                "Column extraction, pixel source(1, 0) -> output(0, 0)",
+                completeRendering.getPixel(1, 0, (double[])null),
+                subsetTile.getPixel(0, 0, (double[])null),
+                1e-1
+        );
+        assertArrayEquals(
+                "Column extraction, pixel source(1, 1) -> output(0, 1)",
+                completeRendering.getPixel(1, 1, (double[])null),
+                subsetTile.getPixel(0, 1, (double[])null),
+                1e-1
+        );
+    }
+
+    /**
      * Asserts that the sample values in the given coverage are equal to the expected values.
      *
      * @param  coverage  the coverage containing the sample values to check.


Mime
View raw message