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 bec9e147958ce2c141f94629165ab955edc52a57 Author: Martin Desruisseaux <[email protected]> AuthorDate: Tue Nov 21 15:34:25 2023 +0100 Calculation of mask derived from `java.awt.Shape` needs to be done in pixel coordinates rather grid cell coordinates. --- .../org/apache/sis/coverage/CoverageCombiner.java | 8 ++++---- .../sis/coverage/grid/GridCoverageProcessor.java | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/CoverageCombiner.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/CoverageCombiner.java index b879f5a0d3..ada3f8aaf0 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/CoverageCombiner.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/CoverageCombiner.java @@ -164,9 +164,9 @@ public class CoverageCombiner { * @param image the image from which to get the conversion. * @param coverage the coverage to use as a fallback if the information is not provided with the image. * @param slice identification of the slice to read in the coverage. - * @return information about conversion from pixel to "real world" coordinates. + * @return information about conversion from pixel coordinates to "real world" coordinates. */ - private static GridGeometry getGridGeometry(final RenderedImage image, + private static GridGeometry getImageGeometry(final RenderedImage image, final GridCoverage coverage, final GridExtent slice) { final Object value = image.getProperty(PlanarImage.GRID_GEOMETRY_KEY); @@ -340,8 +340,8 @@ next: for (;;) { sourceSlice = processor.convert(sourceSlice, sourceRanges[j], converters, combiner.getBandType()); } MathTransform toSource = - getGridGeometry(targetSlice, destination, targetSliceExtent).createTransformTo( - getGridGeometry(sourceSlice, source, sourceSliceExtent), PixelInCell.CELL_CENTER); + getImageGeometry(targetSlice, destination, targetSliceExtent).createTransformTo( + getImageGeometry(sourceSlice, source, sourceSliceExtent), PixelInCell.CELL_CENTER); combiner.resample(sourceSlice, null, toSource); } } else { diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCoverageProcessor.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCoverageProcessor.java index 7f4451c1ea..1fe3f23034 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCoverageProcessor.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCoverageProcessor.java @@ -39,6 +39,7 @@ import org.apache.sis.coverage.SampleDimension; import org.apache.sis.coverage.SubspaceNotSpecifiedException; import org.apache.sis.image.DataType; import org.apache.sis.image.Colorizer; +import org.apache.sis.image.PlanarImage; import org.apache.sis.image.ImageProcessor; import org.apache.sis.image.Interpolation; import org.apache.sis.coverage.internal.SampleDimensions; @@ -76,7 +77,7 @@ import org.apache.sis.measure.NumberRange; * * @author Martin Desruisseaux (Geomatys) * @author Alexis Manin (Geomatys) - * @version 1.4 + * @version 1.5 * * @see org.apache.sis.image.ImageProcessor * @@ -326,6 +327,22 @@ public class GridCoverageProcessor implements Cloneable { optimizations.addAll(enabled); } + /** + * Returns information about conversion from pixel coordinates to "real world" coordinates. + * This is taken from {@link PlanarImage#GRID_GEOMETRY_KEY} if available, or computed otherwise. + * + * @param image the image from which to get the conversion. + * @param coverage the coverage to use as a fallback if the information is not provided with the image. + * @return information about conversion from pixel coordinates to "real world" coordinates. + */ + private static GridGeometry getImageGeometry(final RenderedImage image, final GridCoverage coverage) { + final Object value = image.getProperty(PlanarImage.GRID_GEOMETRY_KEY); + if (value instanceof GridGeometry) { + return (GridGeometry) value; + } + return new ImageRenderer(coverage, null).getImageGeometry(GridCoverage2D.BIDIMENSIONAL); + } + /** * Applies a mask defined by a region of interest (ROI). If {@code maskInside} is {@code true}, * then all pixels inside the given ROI are set to the {@linkplain #getFillValues() fill values}. @@ -353,8 +370,8 @@ public class GridCoverageProcessor implements Cloneable { { ArgumentChecks.ensureNonNull("source", source); ArgumentChecks.ensureNonNull("mask", mask); - final Shape roi = mask.toShape2D(source.getGridGeometry()); RenderedImage data = source.render(null); + final Shape roi = mask.toShape2D(getImageGeometry(data, source)); data = imageProcessor.mask(data, roi, maskInside); return new GridCoverage2D(source, data); }
