This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits 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 98c2112e62 Fix the computation of tile index in "tili" image scheme of
GeoHEIF. Less distracting exception thrown when an error occurred during
decompression.
98c2112e62 is described below
commit 98c2112e62e9bf7255d0a5b0db64040f3ce9fee2
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Fri Jun 19 00:14:36 2026 +0200
Fix the computation of tile index in "tili" image scheme of GeoHEIF.
Less distracting exception thrown when an error occurred during
decompression.
---
.../io/stream/inflater/CompressionException.java | 42 ++++++++++++++++++++++
.../org/apache/sis/io/stream/inflater/Deflate.java | 2 +-
.../sis/storage/AbstractGridCoverageResource.java | 8 +++++
.../sis/storage/geoheif/CoverageBuilder.java | 23 ++++++------
.../org/apache/sis/storage/geoheif/TiledImage.java | 4 +--
5 files changed, 63 insertions(+), 16 deletions(-)
diff --git
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/io/stream/inflater/CompressionException.java
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/io/stream/inflater/CompressionException.java
new file mode 100644
index 0000000000..bbd7626981
--- /dev/null
+++
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/io/stream/inflater/CompressionException.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.io.stream.inflater;
+
+import java.io.IOException;
+
+
+/**
+ * Thrown when an error occurred during decompression.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ */
+public class CompressionException extends IOException {
+ /**
+ * For cross-version compatibility.
+ */
+ private static final long serialVersionUID = -5493223452276185518L;
+
+ /**
+ * Constructs a new exception with the specified detail message and cause.
+ *
+ * @param message the detail message, or {@code null} if none.
+ * @param cause the cause, or {@code null} if none.
+ */
+ public CompressionException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/io/stream/inflater/Deflate.java
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/io/stream/inflater/Deflate.java
index b804bd218b..1db05bd9dd 100644
---
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/io/stream/inflater/Deflate.java
+++
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/io/stream/inflater/Deflate.java
@@ -104,7 +104,7 @@ public final class Deflate extends InflaterChannel {
}
}
} catch (DataFormatException e) {
- throw new IOException(e);
+ throw new CompressionException(e.getMessage(), e);
}
return target.position() - start;
}
diff --git
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/AbstractGridCoverageResource.java
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/AbstractGridCoverageResource.java
index 722d0c9d3f..bdb2f045ae 100644
---
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/AbstractGridCoverageResource.java
+++
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/AbstractGridCoverageResource.java
@@ -17,6 +17,7 @@
package org.apache.sis.storage;
import java.util.Locale;
+import java.util.Objects;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -46,6 +47,7 @@ import org.apache.sis.measure.Latitude;
import org.apache.sis.measure.Longitude;
import org.apache.sis.measure.AngleFormat;
import org.apache.sis.io.stream.IOUtilities;
+import org.apache.sis.io.stream.inflater.CompressionException;
import org.apache.sis.util.logging.PerformanceLevel;
import org.apache.sis.util.internal.shared.Constants;
@@ -231,6 +233,12 @@ public abstract class AbstractGridCoverageResource extends
AbstractResource impl
}
} else if (isReferencing(cause)) {
type = REFERENCING;
+ } else if (cause instanceof CompressionException) {
+ type = CONTENT;
+ Throwable c = cause.getCause();
+ if (c != null && Objects.equals(c.getMessage(),
cause.getMessage())) {
+ cause = c;
+ }
}
final String message = createExceptionMessage(filename, bounds);
switch (type) {
diff --git
a/incubator/src/org.apache.sis.storage.geoheif/main/org/apache/sis/storage/geoheif/CoverageBuilder.java
b/incubator/src/org.apache.sis.storage.geoheif/main/org/apache/sis/storage/geoheif/CoverageBuilder.java
index 16690e47a9..3b0f6ff1fb 100644
---
a/incubator/src/org.apache.sis.storage.geoheif/main/org/apache/sis/storage/geoheif/CoverageBuilder.java
+++
b/incubator/src/org.apache.sis.storage.geoheif/main/org/apache/sis/storage/geoheif/CoverageBuilder.java
@@ -505,24 +505,23 @@ final class CoverageBuilder implements Emptiable {
* @throws DataStoreException if the reading failed for another reason.
*/
public final int numTiles(final int dimension) throws DataStoreException {
- if (model != null) {
+ if (tiling != null && !isEmpty()) {
+ // Must have precedence over `model` because `model.numTile*` are
1.
+ switch (dimension) {
+ case 0: return JDK18.ceilDiv(width, tiling.tileWidth);
+ case 1: return JDK18.ceilDiv(height, tiling.tileHeight);
+ }
+ } else if (model != null) {
switch (dimension) {
case 0: return model.numTileCols;
case 1: return model.numTileRows;
}
} else if (!isEmpty()) {
- if (tiling != null) {
+ final SampleModel sampleModel = imageModel().sampleModel;
+ if (sampleModel != null) {
switch (dimension) {
- case 0: return JDK18.ceilDiv(width, tiling.tileWidth);
- case 1: return JDK18.ceilDiv(height, tiling.tileHeight);
- }
- } else {
- final SampleModel sampleModel = imageModel().sampleModel;
- if (sampleModel != null) {
- switch (dimension) {
- case 0: return JDK18.ceilDiv(width,
sampleModel.getWidth());
- case 1: return JDK18.ceilDiv(height,
sampleModel.getHeight());
- }
+ case 0: return JDK18.ceilDiv(width,
sampleModel.getWidth());
+ case 1: return JDK18.ceilDiv(height,
sampleModel.getHeight());
}
}
}
diff --git
a/incubator/src/org.apache.sis.storage.geoheif/main/org/apache/sis/storage/geoheif/TiledImage.java
b/incubator/src/org.apache.sis.storage.geoheif/main/org/apache/sis/storage/geoheif/TiledImage.java
index 1128ead27d..85cedd8354 100644
---
a/incubator/src/org.apache.sis.storage.geoheif/main/org/apache/sis/storage/geoheif/TiledImage.java
+++
b/incubator/src/org.apache.sis.storage.geoheif/main/org/apache/sis/storage/geoheif/TiledImage.java
@@ -59,9 +59,7 @@ final class TiledImage extends UncompressedImage {
throws DataStoreException, IOException
{
super(builder, locator, name);
- final int numTileCols = builder.numTiles(0);
- final int numTileRows = builder.numTiles(1);
- final int numTiles = Math.multiplyExact(numTileCols, numTileRows);
+ final int numTiles = Math.multiplyExact(numXTiles, numYTiles);
final TiledImageConfiguration tiling = builder.tiling();
final int offsetFieldLength = tiling.offsetFieldLength();
final int sizeFieldLength = tiling.sizeFieldLength();