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 a7888b6e692ce95fb214315864fa9acab7335d3d Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Wed Jan 22 11:13:18 2025 +0100 Javadoc and minor cleaning. --- .../main/org/apache/sis/image/PlanarImage.java | 9 +++++---- .../apache/sis/image/privy/TilePlaceholder.java | 5 ++--- .../apache/sis/storage/GridCoverageResource.java | 2 +- .../sis/storage/base/GridResourceWrapper.java | 1 + .../org/apache/sis/storage/gdal/TiledCoverage.java | 22 +++++++++++++++++++--- .../org/apache/sis/storage/gdal/TiledResource.java | 5 +++-- 6 files changed, 31 insertions(+), 13 deletions(-) diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/PlanarImage.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/PlanarImage.java index c30a8fefdf..19c776b1cd 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/PlanarImage.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/PlanarImage.java @@ -677,11 +677,12 @@ public abstract class PlanarImage implements RenderedImage { */ @Override public String toString() { - final StringBuilder buffer = new StringBuilder(100).append(Classes.getShortClassName(this)) - .append("[(").append(getWidth()).append(" × ").append(getHeight()).append(") pixels"); + final var buffer = new StringBuilder(100).append(Classes.getShortClassName(this)) + .append("[(").append(getWidth()).append(" × ").append(getHeight()).append(") pixels starting at ") + .append('(').append(getMinX()).append(", ").append(getMinY()).append(')'); final SampleModel sm = getSampleModel(); if (sm != null) { - buffer.append(" × ").append(sm.getNumBands()).append(" bands"); + buffer.append(" in ").append(sm.getNumBands()).append(" bands"); final String type = ImageUtilities.getDataTypeName(sm); if (type != null) { buffer.append(" of type ").append(type); @@ -694,7 +695,7 @@ public abstract class PlanarImage implements RenderedImage { */ final ColorModel cm = getColorModel(); colors: if (cm != null) { - buffer.append("; "); + buffer.append(". Colors: "); if (cm instanceof IndexColorModel) { buffer.append(((IndexColorModel) cm).getMapSize()).append(" indexed colors"); } else { diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/privy/TilePlaceholder.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/privy/TilePlaceholder.java index 65b4963e1f..1a6498e70b 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/privy/TilePlaceholder.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/privy/TilePlaceholder.java @@ -49,9 +49,8 @@ public class TilePlaceholder { * Identifies workaround for two JDK bugs. * * <p><a href="https://bugs.openjdk.java.net/browse/JDK-8166038">JDK-8166038</a>: - * If {@link BufferedImage} cannot be used, fallback on {@link org.apache.sis.coverage.grid.ReshapedImage} - * at the cost of an image larger than necessary. In such case, the tests need to specify the sub-region - * of pixels to verify.</p> + * If {@link BufferedImage} cannot be used, fallback on {@link ReshapedImage} at the cost of an image + * larger than necessary. In such case, the tests need to specify the sub-region of pixels to verify.</p> * * <p><a href="https://bugs.openjdk.java.net/browse/JDK-8275345">JDK-8275345</a>: * call to {@code Graphics2D.drawRenderedImage(…)} fails if the image contains more than one tile diff --git a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/GridCoverageResource.java b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/GridCoverageResource.java index 71da17224c..6c10e81d73 100644 --- a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/GridCoverageResource.java +++ b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/GridCoverageResource.java @@ -143,7 +143,7 @@ public interface GridCoverageResource extends DataSet { * are <em>not</em> constrained to the resolutions returned by this method. Those resolutions are only hints * about resolution values where read operations are likely to be more efficient.</p> * - * @return preferred resolutions for read operations in this data store, or an empty array if none. + * @return preferred resolutions for read operations in this data store, or an empty list if none. * @throws DataStoreException if an error occurred while reading definitions from the underlying data store. * * @see GridGeometry#getResolution(boolean) diff --git a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/GridResourceWrapper.java b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/GridResourceWrapper.java index bface76118..8780fb42e5 100644 --- a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/GridResourceWrapper.java +++ b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/GridResourceWrapper.java @@ -213,6 +213,7 @@ public abstract class GridResourceWrapper implements GridCoverageResource { */ @Override public <T extends StoreEvent> void addListener(Class<T> eventType, StoreListener<? super T> listener) { + @SuppressWarnings("LocalVariableHidesMemberVariable") final GridCoverageResource source; try { source = source(); diff --git a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/TiledCoverage.java b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/TiledCoverage.java index 560eafbaa4..3fa33fb638 100644 --- a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/TiledCoverage.java +++ b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/TiledCoverage.java @@ -99,6 +99,11 @@ final class TiledCoverage extends TiledGridCoverage { if (!band.adviseRead(gdal, resourceBounds, imageBounds, rasterType)) break; } } + /* + * Immediate reading of all tiles that intersect the requested region. + * Pixel values are copied twice: GDAL ⟶ `transferBuffer` ⟶ tiles. + * The transfer buffer is reused for each tile. + */ final var result = new WritableRaster[iterator.tileCountInQuery]; try (Arena arena = Arena.ofConfined()) { final MemorySegment transferBuffer = arena.allocate(getTileLength()); @@ -109,11 +114,22 @@ final class TiledCoverage extends TiledGridCoverage { rasterBounds.translate(tile.getMinX(), tile.getMinY()); assert (imageBounds == null) || imageBounds.contains(rasterBounds) : AssertionMessages.notContained(imageBounds, rasterBounds); - + /* + * The coordinates to give to GDAL are derived from the AOI coordinates in the most + * straightforward way (`tight` = false) because GDAL will compute subsampling with + * the ratio between `resourceBounds` and `rasterBounds`. A consequence is that the + * bounding box may be larger than the image bounds, which is why a clip is needed. + * The clip would be unneeded if we used `tight` = true, but the ratio would have + * slight rounding errors compared to the desired subsampling and we are not sure + * how GDAL would handle that. + */ resourceBounds = iterator.imageToResource(rasterBounds, false); owner.clipReadRegion(resourceBounds); - - // Conversion from uncropped coordinates to cropped coordinates before reading. + /* + * Conversion from uncropped coordinates to cropped coordinates before reading. + * The crop is needed only when reading from a single large tile. It is a no-op + * when reading a tiled image. + */ iterator.getUncroppedTileLocation().ifPresent((p) -> rasterBounds.translate(p.x, p.y)); if (!Band.transfer(gdal, OpenFlag.READ, bands, owner.dataType, resourceBounds, tile, rasterBounds, transferBuffer)) { break; // Exception will be thrown by `throwOnFailure(…)` diff --git a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/TiledResource.java b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/TiledResource.java index 23cbe6ffa6..3f72b176de 100644 --- a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/TiledResource.java +++ b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/TiledResource.java @@ -604,8 +604,9 @@ final class TiledResource extends TiledGridResource { /** * Ensures that the region to read is inside the bounds of the resource. - * The upper values of the region may be out of bounds when the subsampling is not a divisor of the image size. - * the lower values should always be okay and are not checked by this method. + * The upper values of the region may be out of bounds when the subsampling is not a divisor of the image size, + * because the <var>r</var> bounds intentionally contains trailing pixels that will be skipped by subsampling. + * The lower values should always be okay and are not checked by this method. */ final void clipReadRegion(final Rectangle r) { long max;