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 386896b1c8 Bug fix: wrong scanline stride when reading an uncompressed 
image smaller than the tile size.
386896b1c8 is described below

commit 386896b1c81d56e8e849400e8ad01480843f3b87
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Tue Sep 16 11:34:43 2025 +0200

    Bug fix: wrong scanline stride when reading an uncompressed image smaller 
than the tile size.
---
 .../org/apache/sis/storage/geotiff/CompressedSubset.java  | 14 ++------------
 .../main/org/apache/sis/storage/geotiff/DataSubset.java   | 15 +++++++++++----
 2 files changed, 13 insertions(+), 16 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/CompressedSubset.java
 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/CompressedSubset.java
index c5ce241813..199bad4d4d 100644
--- 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/CompressedSubset.java
+++ 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/CompressedSubset.java
@@ -35,15 +35,6 @@ import org.apache.sis.image.privy.RasterFactory;
  * @author  Martin Desruisseaux (Geomatys)
  */
 final class CompressedSubset extends DataSubset {
-    /**
-     * Number of sample values to skip for moving to the next row of a tile in 
the <abbr>TIFF</abbr> file.
-     * This is not necessarily the same scanline stride as the one for the 
tiles created by this class.
-     *
-     * @see #sourcePixelStride
-     * @see java.awt.image.ComponentSampleModel#getScanlineStride()
-     */
-    private final long sourceScanlineStride;
-
     /**
      * Number of sample values to skip before to read the first value of the 
first pixel in a row.
      * The first pixel is at column index 0; subsampling offset is not 
included in this calculation.
@@ -110,9 +101,8 @@ final class CompressedSubset extends DataSubset {
     @SuppressWarnings("LocalVariableHidesMemberVariable")
     CompressedSubset(final DataCube source, final TiledGridResource.Subset 
subset) throws DataStoreException {
         super(source, subset);
-        sourceScanlineStride = source.getScanlineStride(sourcePixelStride);
-        long afterLastBand   = sourceScanlineStride - sourcePixelStride;
-        final int between    = Math.multiplyExact(sourcePixelStride, 
Math.toIntExact(getSubsampling(X_DIMENSION) - 1));
+        long afterLastBand = sourceScanlineStride - sourcePixelStride;
+        final int between  = Math.multiplyExact(sourcePixelStride, 
Math.toIntExact(getSubsampling(X_DIMENSION) - 1));
         if (includedBands != null && sourcePixelStride > 1) {
             final int[] skips = new int[includedBands.length];
             final int m = skips.length - 1;
diff --git 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/DataSubset.java
 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/DataSubset.java
index bc1bd2dabe..9bfe88acdd 100644
--- 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/DataSubset.java
+++ 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/DataSubset.java
@@ -113,6 +113,15 @@ class DataSubset extends TiledGridCoverage implements 
Localized {
      */
     protected final int numBanks;
 
+    /**
+     * Number of sample values to skip for moving to the next row of a tile in 
the <abbr>TIFF</abbr> file.
+     * This is not necessarily the same scanline stride as the one for the 
tiles created by this class.
+     *
+     * @see #sourcePixelStride
+     * @see java.awt.image.ComponentSampleModel#getScanlineStride()
+     */
+    protected final long sourceScanlineStride;
+
     /**
      * Number of interleaved sample values in a pixel in the <abbr>TIFF</abbr> 
file (ignoring band subset).
      * For planar images (banded sample model), this is equal to 1. For pixel 
interleaved image,
@@ -170,6 +179,7 @@ class DataSubset extends TiledGridCoverage implements 
Localized {
             sourcePixelStride = source.getNumBands();
             targetPixelStride = model .getNumBands();
         }
+        sourceScanlineStride = source.getScanlineStride(sourcePixelStride);
         final int n = tileOffsets.size();
         if (maxBank >= n / numTiles) {
             throw new 
DataStoreContentException(source.reader.errors().getString(
@@ -511,10 +521,7 @@ class DataSubset extends TiledGridCoverage implements 
Localized {
          * This length is used only for verification purpose so it does not 
need to be exact.
          */
         final long length = ceilDiv(width * height * sourcePixelStride * 
sampleSize, Byte.SIZE);
-        final long[] size = new long[] {
-            multiplyExact(getTileSize(X_DIMENSION), sourcePixelStride),
-                          getTileSize(Y_DIMENSION)
-        };
+        final long[] size = new long[] {sourceScanlineStride, 
getTileSize(Y_DIMENSION)};
         /*
          * If we use an interleaved sample model, each "element" from 
`HyperRectangleReader` perspective is actually a
          * group of `sourcePixelStride` values. Note that in such case, we 
cannot handle subsampling on the first axis.

Reply via email to