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 61589faccb Rename `MultiSourceLayout` and `BandAggregateLayout` for making clear that this is about band aggregate only rather than all multi-source image. 61589faccb is described below commit 61589faccbda84edd3ff45b733e91a753beb4d9f Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Sat Dec 14 20:11:12 2024 +0100 Rename `MultiSourceLayout` and `BandAggregateLayout` for making clear that this is about band aggregate only rather than all multi-source image. --- .../coverage/grid/BandAggregateGridCoverage.java | 6 +++--- .../sis/coverage/grid/GridCoverageProcessor.java | 4 ++-- ...rceArgument.java => BandAggregateArgument.java} | 6 +++--- .../org/apache/sis/coverage/privy/ImageLayout.java | 12 +++++++----- .../org/apache/sis/image/BandAggregateImage.java | 22 +++++++++++++++------- ...iSourceLayout.java => BandAggregateLayout.java} | 22 +++++++++++----------- .../org/apache/sis/image/MultiSourceImage.java | 2 +- .../aggregate/BandAggregateGridResource.java | 10 +++++----- 8 files changed, 47 insertions(+), 37 deletions(-) diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/BandAggregateGridCoverage.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/BandAggregateGridCoverage.java index 2f3d391420..695876c2c8 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/BandAggregateGridCoverage.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/BandAggregateGridCoverage.java @@ -24,7 +24,7 @@ import org.opengis.referencing.operation.TransformException; import org.apache.sis.image.DataType; import org.apache.sis.image.ImageProcessor; import org.apache.sis.feature.internal.Resources; -import org.apache.sis.coverage.privy.MultiSourceArgument; +import org.apache.sis.coverage.privy.BandAggregateArgument; import org.apache.sis.util.privy.CollectionsExt; @@ -93,7 +93,7 @@ final class BandAggregateGridCoverage extends GridCoverage { * @throws IllegalArgumentException if there is an incompatibility between some source coverages * or if some band indices are duplicated or outside their range of validity. */ - BandAggregateGridCoverage(final MultiSourceArgument<GridCoverage> aggregate, final ImageProcessor processor) { + BandAggregateGridCoverage(final BandAggregateArgument<GridCoverage> aggregate, final ImageProcessor processor) { super(aggregate.domain(GridCoverage::getGridGeometry), aggregate.ranges()); this.sources = aggregate.sources(); this.bandsPerSource = aggregate.bandsPerSource(true); @@ -118,7 +118,7 @@ final class BandAggregateGridCoverage extends GridCoverage { * * @param unwrapper a handler where to supply the result of an aggregate decomposition. */ - static void unwrap(final MultiSourceArgument<GridCoverage>.Unwrapper unwrapper) { + static void unwrap(final BandAggregateArgument<GridCoverage>.Unwrapper unwrapper) { if (unwrapper.source instanceof BandAggregateGridCoverage) { final var aggregate = (BandAggregateGridCoverage) unwrapper.source; unwrapper.applySubset(aggregate.sources, aggregate.bandsPerSource, GridCoverage::getSampleDimensions); 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 3128803050..69fcbc0b47 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 @@ -46,7 +46,7 @@ import org.apache.sis.image.PlanarImage; import org.apache.sis.image.ImageProcessor; import org.apache.sis.image.Interpolation; import org.apache.sis.coverage.privy.SampleDimensions; -import org.apache.sis.coverage.privy.MultiSourceArgument; +import org.apache.sis.coverage.privy.BandAggregateArgument; import org.apache.sis.referencing.CommonCRS; import org.apache.sis.referencing.crs.DefaultTemporalCRS; import org.apache.sis.referencing.operation.transform.MathTransforms; @@ -886,7 +886,7 @@ public class GridCoverageProcessor implements Cloneable { * @since 1.4 */ public GridCoverage aggregateRanges(GridCoverage[] sources, int[][] bandsPerSource) { - final var aggregate = new MultiSourceArgument<>(sources, bandsPerSource); + final var aggregate = new BandAggregateArgument<>(sources, bandsPerSource); aggregate.unwrap(BandAggregateGridCoverage::unwrap); aggregate.completeAndValidate(GridCoverage::getSampleDimensions); aggregate.mergeConsecutiveSources(); diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/privy/MultiSourceArgument.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/privy/BandAggregateArgument.java similarity index 99% rename from endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/privy/MultiSourceArgument.java rename to endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/privy/BandAggregateArgument.java index b7f0c965ea..a4c9737149 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/privy/MultiSourceArgument.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/privy/BandAggregateArgument.java @@ -56,7 +56,7 @@ import org.apache.sis.util.resources.Errors; * @param <S> type of objects that are the source of sample dimensions. */ @SuppressWarnings("ReturnOfCollectionOrArrayField") // See class Javadoc. -public final class MultiSourceArgument<S> { +public final class BandAggregateArgument<S> { /** * The user-specified sources, usually grid coverages or rendered images. * This is initially a copy of the array specified at construction time. @@ -142,7 +142,7 @@ public final class MultiSourceArgument<S> { * @param sources the sources from which to get the sample dimensions. * @param bandsPerSource sample dimensions for each source. May contain {@code null} elements. */ - public MultiSourceArgument(S[] sources, int[][] bandsPerSource) { + public BandAggregateArgument(S[] sources, int[][] bandsPerSource) { /* * Ensure that both arrays are non-null and have the same length. * Copy those arrays because their content will be overwritten. @@ -287,7 +287,7 @@ public final class MultiSourceArgument<S> { } /** - * Notifies the enclosing {@code MultiSourceArgument} that the {@linkplain #source} + * Notifies the enclosing {@code BandAggregateArgument} that the {@linkplain #source} * shall be replaced by deeper sources. The {@code componentBands} array specifies * the bands to use for each source and shall take in account the {@link #bands} subset. * diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/privy/ImageLayout.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/privy/ImageLayout.java index 719e6ed9de..50e0bfa8cb 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/privy/ImageLayout.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/privy/ImageLayout.java @@ -382,12 +382,13 @@ public class ImageLayout { * * <p>This method constructs the simplest possible banded sample model: * All {@linkplain BandedSampleModel#getBandOffsets() band offsets} are zero and - * all {@linkplain BandedSampleModel#getBankIndices() bank indices} are identity mapping.</p> + * all {@linkplain BandedSampleModel#getBankIndices() bank indices} are identity mapping. + * This simplicity is needed by current implementation of {@link org.apache.sis.image.BandAggregateImage}.</p> * - * @param dataType desired data type as a {@link java.awt.image.DataBuffer} constant. - * @param numBands desired number of bands. - * @param image the image which will be the source of the image for which a sample model is created. - * @param bounds the bounds of the image to create, or {@code null} if same as {@code image}. + * @param dataType desired data type as a {@link java.awt.image.DataBuffer} constant. + * @param numBands desired number of bands. + * @param image the image which will be the source of the image for which a sample model is created. + * @param bounds the bounds of the image to create, or {@code null} if same as {@code image}. * @param scanlineStride the line stride of the of the image data, or ≤ 0 for automatic. * @return a banded sample model of the given type with the given number of bands. */ @@ -398,6 +399,7 @@ public class ImageLayout { if (scanlineStride <= 0) { scanlineStride = tileSize.width; } + // Pixel stride, bank indices and band offsets intentionally non-configurable. See Javadoc. return RasterFactory.unique(new BandedSampleModel(dataType, tileSize.width, tileSize.height, scanlineStride, ArraysExt.range(0, numBands), new int[numBands])); } diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/BandAggregateImage.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/BandAggregateImage.java index 3403b1abdc..47b8bdc130 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/BandAggregateImage.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/BandAggregateImage.java @@ -25,7 +25,7 @@ import java.awt.image.WritableRaster; import java.awt.image.WritableRenderedImage; import org.apache.sis.util.ArraysExt; import org.apache.sis.coverage.privy.ImageUtilities; -import org.apache.sis.coverage.privy.MultiSourceArgument; +import org.apache.sis.coverage.privy.BandAggregateArgument; /** @@ -61,7 +61,7 @@ class BandAggregateImage extends MultiSourceImage { * * @param unwrapper a handler where to supply the result of an aggregate decomposition. */ - static void unwrap(final MultiSourceArgument<RenderedImage>.Unwrapper unwrapper) { + static void unwrap(final BandAggregateArgument<RenderedImage>.Unwrapper unwrapper) { RenderedImage source = unwrapper.source; int[] bands = unwrapper.bands; while (source instanceof ImageAdapter) { @@ -93,7 +93,7 @@ class BandAggregateImage extends MultiSourceImage { * @return an image with a subset of the bands of this image, or {@code null} if {@code unwrapper} was non-null. */ final RenderedImage subset(final int[] bands, final ColorModel colors, - final MultiSourceArgument<RenderedImage>.Unwrapper unwrapper) + final BandAggregateArgument<RenderedImage>.Unwrapper unwrapper) { final RenderedImage[] sources = new RenderedImage[bands.length]; final int[][] bandsPerSource = new int[bands.length][]; @@ -140,7 +140,7 @@ class BandAggregateImage extends MultiSourceImage { static RenderedImage create(final RenderedImage[] sources, final int[][] bandsPerSource, final Colorizer colorizer, final boolean forceColors, final boolean allowSharing, final boolean parallel) { - final var layout = MultiSourceLayout.create(sources, bandsPerSource, allowSharing); + final var layout = BandAggregateLayout.create(sources, bandsPerSource, allowSharing); final BandAggregateImage image; if (layout.isWritable()) { image = new Writable(layout, colorizer, allowSharing, parallel); @@ -169,7 +169,7 @@ class BandAggregateImage extends MultiSourceImage { * @param layout pixel and tile coordinate spaces of this image, together with sample model. * @param colorizer provider of color model to use for this image, or {@code null} for automatic. */ - private BandAggregateImage(final MultiSourceLayout layout, final Colorizer colorizer, + private BandAggregateImage(final BandAggregateLayout layout, final Colorizer colorizer, final boolean allowSharing, final boolean parallel) { super(layout, colorizer, parallel); @@ -191,7 +191,7 @@ class BandAggregateImage extends MultiSourceImage { /* * If we are allowed to share the data arrays, try that first. * The cast to `BandedSampleModel` is safe because this is the - * type given by `MultiSourceLayout` in the constructor. + * type given by `BandAggregateLayout` in the constructor. */ BandSharedRaster shared = null; if (allowSharing) { @@ -237,7 +237,7 @@ class BandAggregateImage extends MultiSourceImage { * @param layout pixel and tile coordinate spaces of this image, together with sample model. * @param colorizer provider of color model to use for this image, or {@code null} for automatic. */ - Writable(final MultiSourceLayout layout, final Colorizer colorizer, + Writable(final BandAggregateLayout layout, final Colorizer colorizer, final boolean allowSharing, final boolean parallel) { super(layout, colorizer, allowSharing, parallel); @@ -332,4 +332,12 @@ class BandAggregateImage extends MultiSourceImage { public boolean equals(final Object object) { return super.equals(object) && ((BandAggregateImage) object).allowSharing == allowSharing; } + + /** + * Returns a hash code value for this image. + */ + @Override + public int hashCode() { + return super.hashCode() ^ Boolean.hashCode(allowSharing); + } } diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/MultiSourceLayout.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/BandAggregateLayout.java similarity index 95% rename from endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/MultiSourceLayout.java rename to endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/BandAggregateLayout.java index 884e620780..744c9d84df 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/MultiSourceLayout.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/BandAggregateLayout.java @@ -34,13 +34,12 @@ import org.apache.sis.coverage.grid.DisjointExtentException; import org.apache.sis.coverage.privy.ImageLayout; import org.apache.sis.coverage.privy.ImageUtilities; import org.apache.sis.coverage.privy.ColorModelFactory; -import org.apache.sis.coverage.privy.MultiSourceArgument; +import org.apache.sis.coverage.privy.BandAggregateArgument; import org.apache.sis.coverage.privy.CommonDomainFinder; /** - * Computes the bounds of a destination image which will combine many source images. - * A combination may be an aggregation or an overlay of bands, depending on the image class. + * Computes the bounds of a destination image which will combine the bands of many source images. * All images are assumed to use the same pixel coordinate space: (<var>x</var>, <var>y</var>) * expressed in pixel coordinates should map to the same geospatial location in all images. * @@ -52,7 +51,7 @@ import org.apache.sis.coverage.privy.CommonDomainFinder; * @see ImageCombiner * @see BandAggregateImage */ -final class MultiSourceLayout extends ImageLayout { +final class BandAggregateLayout extends ImageLayout { /** * The source images. This is a copy of the user-specified array, * except that images associated to an empty set of bands are discarded. @@ -66,7 +65,7 @@ final class MultiSourceLayout extends ImageLayout { final RenderedImage[] filteredSources; /** - * Ordered (not necessarily sorted) indices of bands to select in each source image. + * Indices of bands to select in each source image, in the order of target image bands. * The length of this array is always equal to the length of the {@link #sources} array. * A {@code null} element means that all bands of the corresponding image should be used. * All non-null elements are non-empty and without duplicated values. @@ -75,6 +74,7 @@ final class MultiSourceLayout extends ImageLayout { /** * Final band select operation to apply on the aggregated result. + * This is needed if the final band order implies interleaving bands of different images. */ final int[] bandSelect; @@ -112,7 +112,7 @@ final class MultiSourceLayout extends ImageLayout { private final boolean exactTileSize; /** - * Computes the layout of an image combining all the specified source images. + * Computes the layout of an image combining the bands of all the specified source images. * The optional {@code bandsPerSource} argument specifies the bands to select in each source images. * That array can be {@code null} for selecting all bands in all source images, * or may contain {@code null} elements for selecting all bands of the corresponding image. @@ -128,8 +128,8 @@ final class MultiSourceLayout extends ImageLayout { * or if some band indices are duplicated or outside their range of validity. */ @Workaround(library="JDK", version="1.8") - static MultiSourceLayout create(RenderedImage[] sources, int[][] bandsPerSource, boolean allowSharing) { - final var aggregate = new MultiSourceArgument<RenderedImage>(sources, bandsPerSource); + static BandAggregateLayout create(RenderedImage[] sources, int[][] bandsPerSource, boolean allowSharing) { + final var aggregate = new BandAggregateArgument<RenderedImage>(sources, bandsPerSource); aggregate.unwrap(BandAggregateImage::unwrap); aggregate.validate(ImageUtilities::getNumBands); @@ -151,7 +151,7 @@ final class MultiSourceLayout extends ImageLayout { */ final SampleModel sm = source.getSampleModel(); if (allowSharing && (allowSharing = (sm instanceof ComponentSampleModel))) { - final ComponentSampleModel csm = (ComponentSampleModel) sm; + final var csm = (ComponentSampleModel) sm; if (allowSharing = (csm.getPixelStride() == 1)) { allowSharing &= scanlineStride == (scanlineStride = csm.getScanlineStride()); allowSharing &= tileWidth == (tileWidth = source.getTileWidth()); @@ -211,7 +211,7 @@ final class MultiSourceLayout extends ImageLayout { final var preferredTileSize = new Dimension((int) cx, (int) cy); final boolean exactTileSize = ((cx | cy) >>> Integer.SIZE) == 0; allowSharing &= exactTileSize; - return new MultiSourceLayout(sources, bandsPerSource, bandSelect, domain, preferredTileSize, exactTileSize, + return new BandAggregateLayout(sources, bandsPerSource, bandSelect, domain, preferredTileSize, exactTileSize, chooseMinTile(tileGridXOffset, domain.x, preferredTileSize.width), chooseMinTile(tileGridYOffset, domain.y, preferredTileSize.height), commonDataType, aggregate.numBands(), allowSharing ? scanlineStride : 0); @@ -229,7 +229,7 @@ final class MultiSourceLayout extends ImageLayout { * @param scanlineStride common scanline stride if data buffers will be shared, or 0 if no sharing. * @param numBands number of bands of the image to create. */ - private MultiSourceLayout(final RenderedImage[] sources, final int[][] bandsPerSource, final int[] bandSelect, + private BandAggregateLayout(final RenderedImage[] sources, final int[][] bandsPerSource, final int[] bandSelect, final Rectangle domain, final Dimension preferredTileSize, final boolean exactTileSize, final int minTileX, final int minTileY, final int commonDataType, final int numBands, final int scanlineStride) diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/MultiSourceImage.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/MultiSourceImage.java index 2bf062c5d0..1cb416dd13 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/MultiSourceImage.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/MultiSourceImage.java @@ -70,7 +70,7 @@ abstract class MultiSourceImage extends WritableComputedImage { * @param colorizer provider of color model to use for this image, or {@code null} for automatic. * @param parallel whether parallel computation is allowed. */ - MultiSourceImage(final MultiSourceLayout layout, final Colorizer colorizer, final boolean parallel) { + MultiSourceImage(final BandAggregateLayout layout, final Colorizer colorizer, final boolean parallel) { super(layout.sampleModel, layout.filteredSources); final Rectangle r = layout.domain; minX = r.x; diff --git a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/aggregate/BandAggregateGridResource.java b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/aggregate/BandAggregateGridResource.java index 7839cb582d..420e57e20c 100644 --- a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/aggregate/BandAggregateGridResource.java +++ b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/aggregate/BandAggregateGridResource.java @@ -26,7 +26,7 @@ import org.apache.sis.coverage.grid.GridCoverage; import org.apache.sis.coverage.grid.GridGeometry; import org.apache.sis.coverage.grid.GridCoverageProcessor; import org.apache.sis.coverage.grid.IllegalGridGeometryException; -import org.apache.sis.coverage.privy.MultiSourceArgument; +import org.apache.sis.coverage.privy.BandAggregateArgument; import org.apache.sis.coverage.privy.RangeArgument; import org.apache.sis.storage.Resource; import org.apache.sis.storage.GridCoverageResource; @@ -127,7 +127,7 @@ final class BandAggregateGridResource extends AbstractGridCoverageResource imple * @throws IllegalArgumentException if some band indices are duplicated or outside their range of validity. */ private BandAggregateGridResource(final StoreListeners parentListeners, - final MultiSourceArgument<GridCoverageResource> aggregate, + final BandAggregateArgument<GridCoverageResource> aggregate, final GridCoverageProcessor processor) { super(parentListeners, false); @@ -208,11 +208,11 @@ final class BandAggregateGridResource extends AbstractGridCoverageResource imple } } /* - * If the same source appears two or more times consecutively, `MultiSourceArgument` will merge them + * If the same source appears two or more times consecutively, `BandAggregateArgument` will merge them * in a single reference to that source. Consequently the arrays of sources may become shorter. */ try { - final var aggregate = new MultiSourceArgument<GridCoverageResource>(sources, bandsPerSource); + final var aggregate = new BandAggregateArgument<GridCoverageResource>(sources, bandsPerSource); aggregate.unwrap(BandAggregateGridResource::unwrap); aggregate.completeAndValidate(BandAggregateGridResource::range); aggregate.mergeConsecutiveSources(); @@ -256,7 +256,7 @@ final class BandAggregateGridResource extends AbstractGridCoverageResource imple * * @param unwrapper a handler where to supply the result of an aggregate decomposition. */ - private static void unwrap(final MultiSourceArgument<GridCoverageResource>.Unwrapper unwrapper) { + private static void unwrap(final BandAggregateArgument<GridCoverageResource>.Unwrapper unwrapper) { if (unwrapper.source instanceof BandAggregateGridResource) { final var aggregate = (BandAggregateGridResource) unwrapper.source; unwrapper.applySubset(aggregate.sources, aggregate.bandsPerSource, BandAggregateGridResource::range);