This is an automated email from the ASF dual-hosted git repository. amanin pushed a commit to branch fix/mask-image-is-back in repository https://gitbox.apache.org/repos/asf/sis.git
commit 2d2f7ef21d9d5e3712cc96294f5a21932c8e5bd7 Author: Alexis Manin <alexis.ma...@geomatys.com> AuthorDate: Wed Nov 10 17:34:42 2021 +0100 chore(Core): add a new test case for mask images ensure working on image subsets works --- .../java/org/apache/sis/image/MaskedImageTest.java | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/core/sis-feature/src/test/java/org/apache/sis/image/MaskedImageTest.java b/core/sis-feature/src/test/java/org/apache/sis/image/MaskedImageTest.java index 7be55e7..b01ec40 100644 --- a/core/sis-feature/src/test/java/org/apache/sis/image/MaskedImageTest.java +++ b/core/sis-feature/src/test/java/org/apache/sis/image/MaskedImageTest.java @@ -31,6 +31,7 @@ import java.awt.image.Raster; import java.awt.image.RenderedImage; import java.awt.image.WritableRaster; import org.apache.sis.internal.coverage.j2d.TiledImage; +import org.apache.sis.test.FeatureAssert; import org.apache.sis.test.TestCase; import org.apache.sis.util.Debug; import org.junit.Test; @@ -152,6 +153,36 @@ public final strictfp class MaskedImageTest extends TestCase { } /** + * Ensure that performing a mask on a {@link BufferedImage#getSubimage(int, int, int, int) subset of a buffered image} + * will return a tile correctly sized. + */ + @Test + public void maskSubRegion() { + final BufferedImage source = monoTile(); + final BufferedImage sourceSubset = source.getSubimage(0, 0, 4, 4); + final ImageProcessor processor = new ImageProcessor(); + processor.setFillValues(4); + final RenderedImage mask = processor.mask(sourceSubset, new Rectangle(0, 0, 2, 2), true); + + final Raster tile = mask.getTile(0, 0); + assertEquals("Tile width", mask.getTileWidth(), tile.getWidth()); + assertEquals("Tile height", mask.getTileHeight(), tile.getHeight()); + + // Note: put 5 on pixels that should not be tested, so the test will fail if we do not test the right area + final RenderedImage expected = monoTile(new int[] { + 4, 4, 0, 0, 5, 5, 5, 5, + 4, 4, 0, 0, 5, 5, 5, 5, + 0, 0, 0, 0, 5, 5, 5, 5, + 0, 0, 0, 0, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5 + }); + FeatureAssert.assertPixelsEqual(expected, new Rectangle(4, 4), mask, null); + } + + /** * Tests masking pixels inside a rectangle on the given image. * This method is invoked twice, for untiled image and for tiled image. */