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 63079aa8ea5f9735d4ba1dbbcdbb263519ab37ba Author: Martin Desruisseaux <[email protected]> AuthorDate: Tue Dec 2 14:42:30 2025 +0100 Revert the use of `fillValues` in `Transferer` while keeping the clip. Add an explanation about why the fill values was not necessary. --- .../apache/sis/image/BandedSampleConverter.java | 34 +++++----------------- .../main/org/apache/sis/image/ImageProcessor.java | 8 ++--- .../main/org/apache/sis/image/Transferer.java | 15 ++++------ .../main/org/apache/sis/image/Visualization.java | 2 +- .../sis/image/BandedSampleConverterTest.java | 2 +- 5 files changed, 18 insertions(+), 43 deletions(-) diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/BandedSampleConverter.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/BandedSampleConverter.java index e85f4c51a5..1e24e62d2d 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/BandedSampleConverter.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/BandedSampleConverter.java @@ -36,7 +36,6 @@ import org.apache.sis.coverage.internal.shared.SampleDimensions; import org.apache.sis.image.internal.shared.ImageUtilities; import org.apache.sis.image.internal.shared.TileOpExecutor; import org.apache.sis.image.internal.shared.ColorScaleBuilder; -import org.apache.sis.image.internal.shared.FillValues; import org.apache.sis.util.Numbers; import org.apache.sis.util.Disposable; import org.apache.sis.util.logging.Logging; @@ -105,12 +104,6 @@ class BandedSampleConverter extends WritableComputedImage { */ private final double[] sampleResolutions; - /** - * Values to assign to the pixels outside source image. - * Can be {@code null} if the target image is fully contained inside the source image. - */ - private final FillValues fillValues; - /** * Creates a new image which will compute values using the given converters. * @@ -121,29 +114,19 @@ class BandedSampleConverter extends WritableComputedImage { * @param converters the transfer functions to apply on each band of the source image. * If this array was a user-provided parameter, should be cloned by caller. * @param sampleDimensions description of conversion result, or {@code null} if unknown. - * @param fillValues values to assign to pixels outside source image, or {@code null} for default values. */ private BandedSampleConverter(final RenderedImage source, final BandedSampleModel sampleModel, final ColorModel colorModel, final NumberRange<?>[] ranges, final MathTransform1D[] converters, - final List<SampleDimension> sampleDimensions, - final Number[] fillValues) + final List<SampleDimension> sampleDimensions) { super(sampleModel, source); this.colorModel = colorModel; this.converters = converters; this.sampleDimensions = sampleDimensions; ensureCompatible(sampleModel, colorModel); - FillValues fill = null; - if (!ImageUtilities.getBounds(source).contains(super.getBounds())) { - fill = new FillValues(sampleModel, fillValues, true); - if (fill.isFullyZero) { - fill = null; - } - } - this.fillValues = fill; /* * Get an estimation of the resolution, arbitrarily looking in the middle of the range of values. * If the converters are linear (which is the most common case), the middle value does not matter @@ -216,7 +199,6 @@ class BandedSampleConverter extends WritableComputedImage { * @param converters the transfer functions to apply on each band of the source image. * @param targetType the type of this image resulting from conversion of given image. * @param colorizer provider of color model for the expected range of values, or {@code null}. - * @param fillValues values to assign to pixels outside source image, or {@code null} for default values. * @return the image which compute converted values from the given source. * * @see ImageProcessor#convert(RenderedImage, NumberRange[], MathTransform1D[], DataType) @@ -226,8 +208,7 @@ class BandedSampleConverter extends WritableComputedImage { final NumberRange<?>[] sourceRanges, final MathTransform1D[] converters, final DataType targetType, - final Colorizer colorizer, - final Number[] fillValues) + final Colorizer colorizer) { /* * Since this operation applies its own ColorModel anyway, skip operation that was doing nothing else @@ -275,11 +256,11 @@ class BandedSampleConverter extends WritableComputedImage { inverses[i] = converters[i].inverse(); } return new Writable((WritableRenderedImage) source, sampleModel, colorModel, - sourceRanges, converters, inverses, sampleDimensions, fillValues); + sourceRanges, converters, inverses, sampleDimensions); } catch (NoninvertibleTransformException e) { Logging.recoverableException(LOGGER, ImageProcessor.class, "convert", e); } - return new BandedSampleConverter(source, sampleModel, colorModel, sourceRanges, converters, sampleDimensions, fillValues); + return new BandedSampleConverter(source, sampleModel, colorModel, sourceRanges, converters, sampleDimensions); } /** @@ -416,7 +397,7 @@ class BandedSampleConverter extends WritableComputedImage { if (target == null) { target = createTile(tileX, tileY); } - Transferer.create(getSource(), target, fillValues).compute(converters); + Transferer.create(getSource(), target).compute(converters); return target; } @@ -455,10 +436,9 @@ class BandedSampleConverter extends WritableComputedImage { final NumberRange<?>[] ranges, final MathTransform1D[] converters, final MathTransform1D[] inverses, - final List<SampleDimension> sampleDimensions, - final Number[] fillValues) + final List<SampleDimension> sampleDimensions) { - super(source, sampleModel, colorModel, ranges, converters, sampleDimensions, fillValues); + super(source, sampleModel, colorModel, ranges, converters, sampleDimensions); this.inverses = inverses; } diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/ImageProcessor.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/ImageProcessor.java index 3202254ded..a5e8c35960 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/ImageProcessor.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/ImageProcessor.java @@ -1116,14 +1116,12 @@ public class ImageProcessor implements Cloneable { } final ImageLayout layout; final Colorizer colorizer; - final Number[] fillValues; synchronized (this) { - layout = this.layout; - colorizer = this.colorizer; - fillValues = this.fillValues; + layout = this.layout; + colorizer = this.colorizer; } // No need to clone `sourceRanges` because it is not stored by `BandedSampleConverter`. - return unique(BandedSampleConverter.create(source, layout, sourceRanges, converters, targetType, colorizer, fillValues)); + return unique(BandedSampleConverter.create(source, layout, sourceRanges, converters, targetType, colorizer)); } /** diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/Transferer.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/Transferer.java index c86e539bdc..3197fb1ef4 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/Transferer.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/Transferer.java @@ -29,7 +29,6 @@ import java.awt.image.RasterFormatException; import org.opengis.referencing.operation.MathTransform1D; import org.opengis.referencing.operation.TransformException; import org.apache.sis.image.internal.shared.ImageUtilities; -import org.apache.sis.image.internal.shared.FillValues; import org.apache.sis.system.Configuration; import org.apache.sis.feature.internal.Resources; import org.apache.sis.util.internal.shared.Numerics; @@ -543,19 +542,17 @@ abstract class Transferer { * That later condition is met if the target tile matrix was computed by {@link ImageLayout}. * However, the target tile may be larger in the last row and last column of the tile matrix * if {@link ImageLayout#isImageBoundsAdjustmentAllowed} was {@code true}. This method clips - * the area of interest for that reason.</p> + * the area of interest for that reason. Note that there is no need to write fill values in + * the area outside the clip, because this method is invoked in contexts where area outside + * the clip should be area outside the bounds of the target image.</p> * - * @param source image from which to read sample values. - * @param target image tile where to write sample values after processing. - * @param fillValues the fill values, or {@code null} if none. + * @param source image from which to read sample values. + * @param target image tile where to write sample values after processing. * @return object to use for applying the operation. */ - static Transferer create(final RenderedImage source, final WritableRaster target, final FillValues fillValues) { + static Transferer create(final RenderedImage source, final WritableRaster target) { final Rectangle aoi = target.getBounds(); ImageUtilities.clipBounds(source, aoi); - if (fillValues != null && (aoi.width != target.getWidth() || aoi.height != target.getHeight())) { - fillValues.fill(target); - } int tileX = ImageUtilities.pixelToTileX(source, target.getMinX()); int tileY = ImageUtilities.pixelToTileY(source, target.getMinY()); return create(source.getTile(tileX, tileY), target, aoi); diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/Visualization.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/Visualization.java index 002563ee75..6a7b97239c 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/Visualization.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/Visualization.java @@ -529,7 +529,7 @@ final class Visualization extends ResampledImage { tile = createTile(tileX, tileY); } // Conversion only, when no resampling is needed. - Transferer.create(getSource(), tile, null).compute(converters); + Transferer.create(getSource(), tile).compute(converters); return tile; } diff --git a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/BandedSampleConverterTest.java b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/BandedSampleConverterTest.java index 38ffe78401..cca05744ac 100644 --- a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/BandedSampleConverterTest.java +++ b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/BandedSampleConverterTest.java @@ -71,7 +71,7 @@ public final class BandedSampleConverterTest extends ImageTestCase { source.initializeAllTiles(0); image = BandedSampleConverter.create(source, ImageLayout.DEFAULT, null, new MathTransform1D[] {(MathTransform1D) MathTransforms.linear(scale, 0)}, - targetType, null, null); + targetType, null); } /**
