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

commit 23b494440e176a4da759d8c43c86372de9b105ee
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Sat Jun 13 16:31:22 2026 +0200

    Added support for the "deflate" compression method as a slight variation of 
the "zlib" method.
---
 .../sis/storage/geotiff/ImageFileDirectory.java    |  4 +--
 .../sis/storage/geotiff/inflater/Inflater.java     |  2 +-
 .../org/apache/sis/io/stream/inflater/Deflate.java |  8 +++--
 .../sis/storage/geoheif/CoverageBuilder.java       | 15 ++++++---
 .../sis/storage/geoheif/UncompressedImage.java     | 36 +++++++++++++++++++---
 .../isobmff/mpeg/CompressionConfiguration.java     |  6 ++++
 6 files changed, 57 insertions(+), 14 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/ImageFileDirectory.java
 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/ImageFileDirectory.java
index 121a9fc764..c5122cc4e5 100644
--- 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/ImageFileDirectory.java
+++ 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/ImageFileDirectory.java
@@ -2037,8 +2037,8 @@ final class ImageFileDirectory extends DataCube {
     }
 
     /**
-     * A list of Image File Directories (FID) where the first entry is the 
image at coarsest resolution
-     * and following entries are images at finer resolutions. The entry at 
finest resolution is the
+     * A list of Image File Directories (<abbr>FID</abbr>) where the first 
element is the image at the coarsest
+     * resolution and next elements are images at finer resolutions. The 
element at the finest resolution is the
      * enclosing {@link ImageFileDirectory}.
      */
     private final class Overviews implements Pyramid {
diff --git 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/Inflater.java
 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/Inflater.java
index f8d8f9117d..05b805181d 100644
--- 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/Inflater.java
+++ 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/Inflater.java
@@ -203,7 +203,7 @@ public abstract class Inflater implements Closeable {
         final InflaterChannel inflater;
         switch (compression) {
             case LZW:      inflater = new LZW     (input, listeners); break;
-            case DEFLATE:  inflater = new Deflate (input, listeners); break;
+            case DEFLATE:  inflater = new Deflate (input, listeners, false); 
break;
             case PACKBITS: inflater = new PackBits(input, listeners); break;
             case CCITTRLE: inflater = new CCITTRLE(input, listeners, 
sourceWidth); break;
             case NONE: {
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 d364d64180..b804bd218b 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
@@ -43,12 +43,16 @@ public final class Deflate extends InflaterChannel {
      * The {@link #setInputRegion(long, long)} method must be invoked after 
construction
      * before a reading process can start.
      *
+     * <p>If the {@code nowrap} is {@code true} then the ZLIB header and 
checksum fields will not be used.
+     * See {@link Inflater#Inflater(boolean)} for more information.</p>
+     *
      * @param  input      the source of data to decompress.
      * @param  listeners  object where to report warnings.
+     * @param  nowrap     if {@code true} then support GZIP compatible 
compression.
      */
-    public Deflate(final ChannelDataInput input, final StoreListeners 
listeners) {
+    public Deflate(final ChannelDataInput input, final StoreListeners 
listeners, final boolean nowrap) {
         super(input, listeners);
-        inflater = new Inflater();
+        inflater = new Inflater(nowrap);
     }
 
     /**
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 1cbabfe5f5..7b51f15fe5 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
@@ -291,6 +291,14 @@ final class CoverageBuilder implements Emptiable {
         }
     }
 
+    /**
+     * Returns the compression method, or 0 if none.
+     * The returned value should be one of the {@code 
CompressionConfiguration.COMPRESSION_*} constants.
+     */
+    final int compressionType() {
+        return (compression != null) ? compression.compressionType : 0;
+    }
+
     /**
      * Returns the compression units which contains all image data, or {@code 
null} if the image is uncompressed.
      * This method requires that the compression unit is {@link 
UnitType#IMAGE_TILE}.
@@ -299,7 +307,7 @@ final class CoverageBuilder implements Emptiable {
      * @throws UnsupportedEncodingException if the compression configuration 
is unsupported.
      * @throws DataStoreContentException if the compression cannot be decoded 
for another reason.
      */
-    final CompressedUnitsItemInfo.Unit getCompressedImageUnit() throws 
DataStoreContentException {
+    final CompressedUnitsItemInfo.Unit compressedImageUnit() throws 
DataStoreContentException {
         if (compression == null) {
             return null;
         }
@@ -309,10 +317,7 @@ final class CoverageBuilder implements Emptiable {
             }
             final CompressedUnitsItemInfo.Unit[] units = compressedUnits.units;
             if (units.length == 1) {
-                // Current implementation supports only ZLIB, we may add more 
in the future.
-                if (compression.compressionType == 
CompressionConfiguration.COMPRESSION_ZLIB) {
-                    return units[0];
-                }
+                return units[0];
             }
         }
         throw new UnsupportedEncodingException("Unsupported compression.");
diff --git 
a/incubator/src/org.apache.sis.storage.geoheif/main/org/apache/sis/storage/geoheif/UncompressedImage.java
 
b/incubator/src/org.apache.sis.storage.geoheif/main/org/apache/sis/storage/geoheif/UncompressedImage.java
index b98ac9980f..28a7dfa0bd 100644
--- 
a/incubator/src/org.apache.sis.storage.geoheif/main/org/apache/sis/storage/geoheif/UncompressedImage.java
+++ 
b/incubator/src/org.apache.sis.storage.geoheif/main/org/apache/sis/storage/geoheif/UncompressedImage.java
@@ -31,8 +31,10 @@ import org.apache.sis.io.stream.Region;
 import org.apache.sis.io.stream.inflater.ComputedByteChannel;
 import org.apache.sis.io.stream.inflater.Deflate;
 import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.storage.UnsupportedEncodingException;
 import org.apache.sis.storage.isobmff.ByteRanges;
 import org.apache.sis.storage.isobmff.mpeg.CompressedUnitsItemInfo;
+import org.apache.sis.storage.isobmff.mpeg.CompressionConfiguration;
 
 
 /**
@@ -64,6 +66,12 @@ final class UncompressedImage extends Image {
      */
     private final SampleModel sampleModel;
 
+    /**
+     * The type of compression, or 0 if none.
+     * Should be one of the {@code CompressionConfiguration.COMPRESSION_*} 
constants.
+     */
+    private final int compressionType;
+
     /**
      * The compression units which contains all image data, or {@code null} if 
the image is uncompressed.
      */
@@ -81,9 +89,29 @@ final class UncompressedImage extends Image {
             throws DataStoreException
     {
         super(builder, locator, name);
-        sampleModel = builder.sampleModel();
-        dataType    = builder.imageModel().dataType;
-        compressedImageUnit = builder.getCompressedImageUnit();
+        sampleModel         = builder.sampleModel();
+        dataType            = builder.imageModel().dataType;
+        compressionType     = builder.compressionType();
+        compressedImageUnit = builder.compressedImageUnit();
+    }
+
+    /**
+     * Returns a channel which will decompress data on-the-fly.
+     * This method shall be invoked only if {@link #compressedImageUnit} is 
non-null.
+     * Callers shall invoke {@link ComputedByteChannel#setInputRegion(long, 
long)} on the returned object.
+     *
+     * @param  input  the channel of compressed data.
+     * @return the channel of uncompressed data.
+     * @throws UnsupportedEncodingException if the compression type is not 
supported.
+     */
+    private ComputedByteChannel inflater(final ChannelDataInput input) throws 
UnsupportedEncodingException {
+        switch (compressionType) {
+            case CompressionConfiguration.COMPRESSION_ZLIB:    return new 
Deflate(input, listeners, false);
+            case CompressionConfiguration.COMPRESSION_DEFLATE: return new 
Deflate(input, listeners, true);
+            default: throw new UnsupportedEncodingException("The \"" +
+                    CompressionConfiguration.formatFourCC(compressionType) + 
"\" compression is not supported.");
+
+        }
     }
 
     /**
@@ -138,7 +166,7 @@ final class UncompressedImage extends Image {
             final ComputedByteChannel inflater;
             final CompressedUnitsItemInfo.Unit unit = compressedImageUnit;
             if (unit != null) {
-                inflater = new Deflate(input, listeners);
+                inflater = inflater(input);
                 inflater.setInputRegion(addExact(origin, unit.offset), 
unit.size);
                 input = inflater.createDataInput(context.reuseBuffer(), (int) 
sourceSize[0]);    // (int) cast okay even if inexact.
                 origin = 0;
diff --git 
a/incubator/src/org.apache.sis.storage.geoheif/main/org/apache/sis/storage/isobmff/mpeg/CompressionConfiguration.java
 
b/incubator/src/org.apache.sis.storage.geoheif/main/org/apache/sis/storage/isobmff/mpeg/CompressionConfiguration.java
index abe2a52fd1..1a050b4356 100644
--- 
a/incubator/src/org.apache.sis.storage.geoheif/main/org/apache/sis/storage/isobmff/mpeg/CompressionConfiguration.java
+++ 
b/incubator/src/org.apache.sis.storage.geoheif/main/org/apache/sis/storage/isobmff/mpeg/CompressionConfiguration.java
@@ -42,6 +42,11 @@ public final class CompressionConfiguration extends FullBox {
      */
     public static final int COMPRESSION_ZLIB = ((((('z' << 8) | 'l') << 8) | 
'i') << 8) | 'b';
 
+    /**
+     * The {@code "defl"} value for {@link #compressionType}.
+     */
+    public static final int COMPRESSION_DEFLATE = ((((('d' << 8) | 'e') << 8) 
| 'f') << 8) | 'l';
+
     /**
      * Returns the four-character type of this box.
      * This value is fixed to {@link #BOXTYPE}.
@@ -55,6 +60,7 @@ public final class CompressionConfiguration extends FullBox {
      * Identifier of the compression.
      *
      * @see #COMPRESSION_ZLIB
+     * @see #COMPRESSION_DEFLATE
      */
     @Interpretation(Type.FOURCC)
     public final int compressionType;

Reply via email to