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 d5601f3 Merge the "clip" and "mask" methods in a single "mask" method with boolean argument. d5601f3 is described below commit d5601f3eca46f519d5f8ef14b7832237f0066f98 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Sat Oct 23 18:24:57 2021 +0200 Merge the "clip" and "mask" methods in a single "mask" method with boolean argument. --- .../sis/coverage/grid/GridCoverageProcessor.java | 37 +++++++--------------- .../java/org/apache/sis/image/ImageProcessor.java | 37 ++++++---------------- 2 files changed, 21 insertions(+), 53 deletions(-) diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageProcessor.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageProcessor.java index d79cea9..c631458 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageProcessor.java +++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageProcessor.java @@ -163,42 +163,27 @@ public class GridCoverageProcessor implements Cloneable { } /** - * Applies a clip defined by a region of interest (ROI). - * All pixels <em>outside</em> the given ROI are set to the {@linkplain #getFillValues() fill values}. + * 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}. + * If {@code maskInside} is {@code false}, then the mask is reversed: + * the pixels set to fill values are the ones outside the ROI. * - * @param source the coverage on which to apply a clip. - * @param clip region (in arbitrary CRS) of pixels to keep. - * @return a coverage with clip applied. - * @throws TransformException if ROI coordinates can not be transformed to grid coordinates. - * - * @since 1.2 - */ - public GridCoverage clip(final GridCoverage source, final RegionOfInterest clip) throws TransformException { - ArgumentChecks.ensureNonNull("source", source); - ArgumentChecks.ensureNonNull("clip", clip); - final Shape roi = clip.toShape2D(source.getGridGeometry()); - RenderedImage data = source.render(null); - data = imageProcessor.clip(data, roi); - return new GridCoverage2D(source, data); - } - - /** - * Applies a mask defined by a region of interest (ROI). - * All pixels <em>inside</em> the given ROI are set to the {@linkplain #getFillValues() fill values}. - * - * @param source the coverage on which to apply a mask. - * @param mask region (in arbitrary CRS) of pixels to mask. + * @param source the coverage on which to apply a mask. + * @param mask region (in arbitrary CRS) of the mask. + * @param maskInside {@code true} for masking pixels inside the shape, or {@code false} for masking outside. * @return a coverage with mask applied. * @throws TransformException if ROI coordinates can not be transformed to grid coordinates. * * @since 1.2 */ - public GridCoverage mask(final GridCoverage source, final RegionOfInterest mask) throws TransformException { + public GridCoverage mask(final GridCoverage source, final RegionOfInterest mask, final boolean maskInside) + throws TransformException + { ArgumentChecks.ensureNonNull("source", source); ArgumentChecks.ensureNonNull("mask", mask); final Shape roi = mask.toShape2D(source.getGridGeometry()); RenderedImage data = source.render(null); - data = imageProcessor.mask(data, roi); + data = imageProcessor.mask(data, roi, maskInside); return new GridCoverage2D(source, data); } diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/ImageProcessor.java b/core/sis-feature/src/main/java/org/apache/sis/image/ImageProcessor.java index ab99ab8..08866cb 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/image/ImageProcessor.java +++ b/core/sis-feature/src/main/java/org/apache/sis/image/ImageProcessor.java @@ -744,43 +744,26 @@ public class ImageProcessor implements Cloneable { } /** - * Applies a clip defined by a geometric shape. - * All pixels <em>outside</em> the given shape are set to the {@linkplain #getFillValues() fill values}. - * - * @param source the image on which to apply a clip. - * @param clip geometric area (in pixel coordinates) of pixels to keep. - * @return an image with clip applied. - * - * @since 1.2 - */ - public RenderedImage clip(final RenderedImage source, final Shape clip) { - ArgumentChecks.ensureNonNull("source", source); - ArgumentChecks.ensureNonNull("clip", clip); - final Number[] fillValues; - synchronized (this) { - fillValues = this.fillValues; - } - return unique(new MaskedImage(source, clip, false, fillValues)); - } - - /** - * Applies a mask defined by a geometric shape. - * All pixels <em>inside</em> the given shape are set to the {@linkplain #getFillValues() fill values}. - * - * @param source the image on which to apply a mask. - * @param mask geometric area (in pixel coordinates) of pixels to mask. + * Applies a mask defined by a geometric shape. If {@code maskInside} is {@code true}, + * then all pixels inside the given shape are set to the {@linkplain #getFillValues() fill values}. + * If {@code maskInside} is {@code false}, then the mask is reversed: + * the pixels set to fill values are the ones outside the shape. + * + * @param source the image on which to apply a mask. + * @param mask geometric area (in pixel coordinates) of the mask. + * @param maskInside {@code true} for masking pixels inside the shape, or {@code false} for masking outside. * @return an image with mask applied. * * @since 1.2 */ - public RenderedImage mask(final RenderedImage source, final Shape mask) { + public RenderedImage mask(final RenderedImage source, final Shape mask, final boolean maskInside) { ArgumentChecks.ensureNonNull("source", source); ArgumentChecks.ensureNonNull("mask", mask); final Number[] fillValues; synchronized (this) { fillValues = this.fillValues; } - return unique(new MaskedImage(source, mask, true, fillValues)); + return unique(new MaskedImage(source, mask, maskInside, fillValues)); } /**