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 294f605850e0e49068533a024192afba5d0ab76b Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Thu Sep 12 12:55:53 2024 +0200 Base class changes in support for GDAL binding: * Relax the maximum number of bits for banded color model. * `TiledGridResource.getTileSize()` can throw `DataStoreException`. * `TiledGridResource.getAtomSize(boolean)` argument replaced by `int`. * `TiledGridCoverage.getPositionInSource()` renamed as `getTileCoordinatesInSource()` * `RasterFactory.createBuffer(DataBuffer, int)` renamed as `wrapAsBuffer(…)`. --- .../sis/coverage/privy/ColorModelFactory.java | 6 +++--- .../apache/sis/coverage/privy/RangeArgument.java | 4 ++-- .../apache/sis/coverage/privy/RasterFactory.java | 2 +- .../apache/sis/image/BandAggregateImageTest.java | 2 +- .../apache/sis/storage/base/TiledGridCoverage.java | 2 +- .../apache/sis/storage/base/TiledGridResource.java | 23 +++++++++++----------- .../main/org/apache/sis/storage/gdal/Band.java | 2 +- .../storage/gimi/internal/MatrixGridRessource.java | 10 +++------- 8 files changed, 24 insertions(+), 27 deletions(-) diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/privy/ColorModelFactory.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/privy/ColorModelFactory.java index 80a7c53bdb..e1a22790e1 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/privy/ColorModelFactory.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/privy/ColorModelFactory.java @@ -617,7 +617,7 @@ public final class ColorModelFactory { * {@code true} for color model used with {@link java.awt.image.SinglePixelPackedSampleModel}, and * {@code false} for color model used with {@link java.awt.image.BandedSampleModel}. * - * @param bitsPerSample number of bits per sample, between 1 and 8 inclusive. + * @param bitsPerSample number of bits per sample, between 1 and 8 (packed) or 32 (banded) inclusive. * @param packed whether sample values are packed in a single element. * @param hasAlpha whether the color model should have an alpha channel. * @return the color model. @@ -626,10 +626,10 @@ public final class ColorModelFactory { if ((hasAlpha & packed) && bitsPerSample == Byte.SIZE) { return ColorModel.getRGBdefault(); } - ArgumentChecks.ensureBetween("bitsPerSample", 1, Byte.SIZE, bitsPerSample); - final int mask = (1 << bitsPerSample) - 1; + ArgumentChecks.ensureBetween("bitsPerSample", 1, packed ? Byte.SIZE : Integer.SIZE, bitsPerSample); final ColorModel cm; if (packed) { + final int mask = (1 << bitsPerSample) - 1; cm = new DirectColorModel((hasAlpha ? 4 : 3) * bitsPerSample, mask << (bitsPerSample * 2), // Red mask << bitsPerSample, // Green diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/privy/RangeArgument.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/privy/RangeArgument.java index cb9211453e..3fdd7ba79b 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/privy/RangeArgument.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/privy/RangeArgument.java @@ -316,7 +316,7 @@ public final class RangeArgument { * @return bands selected by user, in user-specified order. */ public SampleDimension[] select(final List<? extends SampleDimension> sourceBands) { - final SampleDimension[] bands = new SampleDimension[getNumBands()]; + final var bands = new SampleDimension[getNumBands()]; for (int i=0; i<bands.length; i++) { bands[getTargetIndex(i)] = sourceBands.get(getSourceIndex(i)); } @@ -357,7 +357,7 @@ public final class RangeArgument { if (view) { return model.createSubsetSampleModel(bands); } else { - final SampleModelFactory factory = new SampleModelFactory(model); + final var factory = new SampleModelFactory(model); factory.subsetAndCompress(bands); return factory.build(); } diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/privy/RasterFactory.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/privy/RasterFactory.java index 880d7f993d..7d3ceeac3e 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/privy/RasterFactory.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/privy/RasterFactory.java @@ -230,7 +230,7 @@ public final class RasterFactory extends Static { * @param bank bank index of the data array to wrap. * @return buffer wrapping the data array of the specified bank. */ - public static Buffer createBuffer(final DataBuffer data, final int bank) { + public static Buffer wrapAsBuffer(final DataBuffer data, final int bank) { Buffer buffer; switch (data.getDataType()) { case DataBuffer.TYPE_BYTE: buffer = ByteBuffer .wrap(((DataBufferByte) data).getData(bank)); break; diff --git a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/BandAggregateImageTest.java b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/BandAggregateImageTest.java index b0fea47c1f..c7f6fa1de0 100644 --- a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/BandAggregateImageTest.java +++ b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/BandAggregateImageTest.java @@ -520,7 +520,7 @@ public final class BandAggregateImageTest extends TestCase { final int tileY = source.getMinTileY() + y; final DataBuffer buffer = source.getTile(tileX, tileY).getDataBuffer(); for (int band = buffer.getNumBanks(); --band >= 0;) { - action.accept(RasterFactory.createBuffer(buffer, band).array(), band); + action.accept(RasterFactory.wrapAsBuffer(buffer, band).array(), band); } } } diff --git a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/TiledGridCoverage.java b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/TiledGridCoverage.java index 75f6e2d55c..ffe450ff15 100644 --- a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/TiledGridCoverage.java +++ b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/TiledGridCoverage.java @@ -599,7 +599,7 @@ public abstract class TiledGridCoverage extends GridCoverage { * * @return current iterator tile position in original coverage resource. */ - public final long[] getPositionInSource() { + public final long[] getTileCoordinatesInSource() { final long[] coordinate = new long[tmcOfFirstTile.length]; for (int i = 0; i < coordinate.length; i++) { coordinate[i] = Math.addExact(tmcOfFirstTile[i], tmcInSubset[i]); diff --git a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/TiledGridResource.java b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/TiledGridResource.java index ca1c0a6af9..74128e6099 100644 --- a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/TiledGridResource.java +++ b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/TiledGridResource.java @@ -144,28 +144,29 @@ public abstract class TiledGridResource extends AbstractGridCoverageResource { * The length of the returned array is the number of dimensions. * * @return the size of tiles (in pixels) in this resource. + * @throws DataStoreException if an error occurred while fetching the tile size. */ - protected abstract int[] getTileSize(); + protected abstract int[] getTileSize() throws DataStoreException; /** * Returns the number of sample values in an indivisible element of a tile. * An element is a primitive type such as {@code byte}, {@code int} or {@code float}. - * This value is usually 1 because each sample value is usually stored in a separated element. + * This value is usually 1 when each sample value is stored in a separated element. * However, in multi-pixels packed sample model (e.g. bilevel image with 8 pixels per byte), * it is difficult to start reading an image at <var>x</var> location other than a byte boundary. - * By declaring an "atom" size of 8 sample values in dimension X, the {@link Subset} constructor - * will ensure that the sub-region to read starts at a byte boundary when reading a bilevel image. + * By declaring an "atom" size of 8 sample values in dimension 0 (<var>x</var>), the {@link Subset} + * constructor will ensure that the sub-region to read starts at a byte boundary when reading a bilevel image. * * <p>The default implementation returns the {@linkplain TiledGridCoverage#getPixelsPerElement() - * number of pixels per data element} for dimension X and returns 1 for all other dimensions.</p> + * number of pixels per data element} for dimension 0 and returns 1 for all other dimensions.</p> * - * @param xdim {@code true} for the size on <var>x</var> dimension, {@code false} for any other dimension. + * @param dim the dimension: 0 for <var>x</var>, 1 for <var>y</var>, <i>etc.</i> * @return indivisible number of sample values to read in the specified dimension. Must be ≥ 1. * This is in units of sample values (may be bits, bytes, floats, <i>etc</i>). * @throws DataStoreException if an error occurred while fetching the sample model. */ - protected int getAtomSize(final boolean xdim) throws DataStoreException { - return xdim ? TiledGridCoverage.getPixelsPerElement(getSampleModel()) : 1; + protected int getAtomSize(final int dim) throws DataStoreException { + return (dim == 0) ? TiledGridCoverage.getPixelsPerElement(getSampleModel()) : 1; } /** @@ -359,8 +360,8 @@ public abstract class TiledGridResource extends AbstractGridCoverageResource { * Note that it is possible to disable this restriction in a single dimension, typically the X one * when reading a TIFF image using strips instead of tiles. */ - final int atomSizeX = getAtomSize(true); - final int atomSizeY = getAtomSize(false); + final int atomSizeX = getAtomSize(0); + final int atomSizeY = getAtomSize(1); int tileWidth = tileSize[X_DIMENSION]; int tileHeight = tileSize[Y_DIMENSION]; if (tileWidth >= sourceExtent.getSize(X_DIMENSION)) {tileWidth = atomSizeX; sharedCache = false;} @@ -516,7 +517,7 @@ public abstract class TiledGridResource extends AbstractGridCoverageResource { * Current implementation does not support immediate loading if the data cube has more than 2 dimensions. * Non-immediate loading allows users to specify two-dimensional slices. */ - private boolean supportImmediateLoading() { + private boolean supportImmediateLoading() throws DataStoreException { return getTileSize().length == TiledGridCoverage.BIDIMENSIONAL; } diff --git a/incubator/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/Band.java b/incubator/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/Band.java index 0d21b8ac63..f71907f4ea 100644 --- a/incubator/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/Band.java +++ b/incubator/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/Band.java @@ -265,7 +265,7 @@ final class Band { final var model = (ComponentSampleModel) raster.getSampleModel(); // See prerequisites in Javadoc. final var data = raster.getDataBuffer(); final int dataSize = DataBuffer.getDataTypeSize(data.getDataType()) / Byte.SIZE; - final var buffer = RasterFactory.createBuffer(data, model.getBankIndices()[band]); + final var buffer = RasterFactory.wrapAsBuffer(data, model.getBankIndices()[band]); buffer.position(model.getOffset(raster.getMinX() - raster.getSampleModelTranslateX(), raster.getMinY() - raster.getSampleModelTranslateY(), band)); final int err; diff --git a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/internal/MatrixGridRessource.java b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/internal/MatrixGridRessource.java index 5d7587087d..d65b4b0eaf 100644 --- a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/internal/MatrixGridRessource.java +++ b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/internal/MatrixGridRessource.java @@ -61,12 +61,8 @@ public abstract class MatrixGridRessource extends TiledGridResource { } @Override - protected int[] getTileSize() { - try { - initialize(); - } catch (DataStoreException ex) { - throw new RuntimeException(ex); - } + protected int[] getTileSize() throws DataStoreException { + initialize(); return tileSize.clone(); } @@ -124,7 +120,7 @@ public abstract class MatrixGridRessource extends TiledGridResource { if (tile != null) { result[iterator.getIndexInResultArray()] = tile; } else { - long[] tileCoord = iterator.getPositionInSource(); + long[] tileCoord = iterator.getTileCoordinatesInSource(); final RenderedImage image = getTileImage(tileCoord); result[iterator.getIndexInResultArray()] = image instanceof BufferedImage ? ((BufferedImage)image).getRaster() : image.getData(); }