This is an automated email from the ASF dual-hosted git repository.

alexismanin pushed a commit to branch fix/image-tile-matrix-get-tile
in repository https://gitbox.apache.org/repos/asf/sis.git

commit c99b7c431e042b472a9384d5f38b5600da21d64e
Author: Alexis Manin <[email protected]>
AuthorDate: Mon May 18 17:09:41 2026 +0200

    fix(Image): fix ReshapedImage.singleTile to strictly return the designated 
tile, and only this tile.
---
 .../sis/image/internal/shared/ReshapedImage.java   | 10 ++++++++-
 .../image/internal/shared/ReshapedImageTest.java   | 24 ++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/internal/shared/ReshapedImage.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/internal/shared/ReshapedImage.java
index 7db4d35660..17bebfaab5 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/internal/shared/ReshapedImage.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/internal/shared/ReshapedImage.java
@@ -128,7 +128,7 @@ public final class ReshapedImage extends PlanarImage {
                 0, 0,
                 tileWidth,
                 tileHeight,
-                0, 0);
+                tileX, tileY);
         return image.isIdentity() ? image.source : image;
     }
 
@@ -298,6 +298,14 @@ public final class ReshapedImage extends PlanarImage {
      */
     @Override
     public Raster getTile(final int tileX, final int tileY) {
+        // Ensure reshaped image strictly respect its boundaries and does not 
access source tiles outside its domain.
+        if (!(
+                getMinTileX() <= tileX && tileX < getMinTileX() + 
getNumXTiles()
+                &&
+                getMinTileY() <= tileY && tileY < getMinTileY() + 
getNumYTiles()
+        )) {
+            throw new IllegalArgumentException("Requested tile is outside 
Image domain");
+        }
         return offset(source.getTile(tileX, tileY));
     }
 
diff --git 
a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/internal/shared/ReshapedImageTest.java
 
b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/internal/shared/ReshapedImageTest.java
index 35973b6908..10884f8d3b 100644
--- 
a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/internal/shared/ReshapedImageTest.java
+++ 
b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/internal/shared/ReshapedImageTest.java
@@ -198,4 +198,28 @@ public final class ReshapedImageTest extends TestCase {
             {1210, 1211, 1212  ,  1310, 1311, 1312  ,  1410, 1411, 1412}
         });
     }
+
+    /**
+     * Verify a reshaped image created to expose a single tile from a source 
tiled image only serves the requested tile.
+     */
+    @Test
+    public void testExposeSingleTileFromTiledImage() {
+        var source  = new TiledImageMock(DataBuffer.TYPE_USHORT, 1, 0, 0, 4, 
4, 2, 2, 0, 0, false);
+        source.validate();
+        source.initializeAllTiles(0);
+
+        var lastTile = ReshapedImage.singleTile(source, 1, 1);
+        try {
+            lastTile.getTile(0, 0);
+            fail("Tile (0, 0) should not be available");
+        } catch (IllegalArgumentException e) {
+            // Expected
+        }
+
+        final var exposedTile = lastTile.getTile(1, 1);
+        assertValuesEqual(exposedTile, 0, new int[][] {
+                { 400, 401 },
+                { 410, 411 }
+        });
+    }
 }

Reply via email to