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 45eb43ee196e103522025e841350bd29f43db3d3 Author: Martin Desruisseaux <[email protected]> AuthorDate: Thu Jun 11 17:31:16 2026 +0200 Javadoc and class renaming for clarity. --- .../apache/sis/storage/geotiff/Compression.java | 27 +++++++---- .../org/apache/sis/storage/geotiff/DataCube.java | 8 ++-- .../sis/storage/geotiff/ImageFileDirectory.java | 12 ++--- .../apache/sis/storage/geotiff/NativeMetadata.java | 6 +-- .../{Compression.java => CompressionMethod.java} | 53 ++++++++++++++-------- .../apache/sis/storage/geotiff/base/Predictor.java | 37 ++++++++------- .../org/apache/sis/storage/geotiff/base/Tags.java | 2 +- .../sis/storage/geotiff/inflater/CCITTRLE.java | 11 +++-- .../geotiff/inflater/CompressionChannel.java | 2 +- .../storage/geotiff/inflater/CopyFromBytes.java | 4 +- .../geotiff/inflater/{ZIP.java => Deflate.java} | 8 ++-- .../geotiff/inflater/HorizontalPredictor.java | 3 +- .../sis/storage/geotiff/inflater/Inflater.java | 26 +++++------ .../apache/sis/storage/geotiff/inflater/LZW.java | 6 +-- .../storage/geotiff/inflater/PredictorChannel.java | 8 ++-- .../sis/storage/geotiff/inflater/package-info.java | 6 +-- .../sis/storage/geotiff/writer/TileMatrix.java | 18 ++------ .../sis/storage/geotiff/base/CompressionTest.java | 20 ++++++-- .../sis/storage/geotiff/inflater/CCITTRLETest.java | 3 +- 19 files changed, 142 insertions(+), 118 deletions(-) diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/Compression.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/Compression.java index 339c3d3d41..784d33ddec 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/Compression.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/Compression.java @@ -19,10 +19,12 @@ package org.apache.sis.storage.geotiff; import java.io.Serializable; import java.util.OptionalInt; import java.util.zip.Deflater; +import javax.imageio.plugins.tiff.BaselineTIFFTagSet; // For javadoc. import org.apache.sis.util.ArgumentChecks; import org.apache.sis.util.internal.shared.Strings; import org.apache.sis.storage.OptionKey; import org.apache.sis.storage.StorageConnector; +import org.apache.sis.storage.geotiff.base.CompressionMethod; import org.apache.sis.storage.geotiff.base.Predictor; import org.apache.sis.io.stream.InternalOptionKey; @@ -47,7 +49,7 @@ import org.apache.sis.io.stream.InternalOptionKey; * If no compression is explicitly specified, Apache SIS uses by default the {@link #DEFLATE} compression. * * @author Martin Desruisseaux (Geomatys) - * @version 1.5 + * @version 1.7 * @since 1.5 */ public final class Compression implements Serializable { @@ -59,9 +61,7 @@ public final class Compression implements Serializable { /** * No compression, but pack data into bytes as tightly as possible. */ - public static final Compression NONE = new Compression( - org.apache.sis.storage.geotiff.base.Compression.NONE, - 0, Predictor.NONE); + public static final Compression NONE = new Compression(CompressionMethod.NONE, 0, Predictor.NONE); /** * Deflate compression (like ZIP format) with a default compression level and a default predictor. @@ -88,8 +88,7 @@ public final class Compression implements Serializable { * @see #withPredictor(int) */ public static final Compression DEFLATE = new Compression( - org.apache.sis.storage.geotiff.base.Compression.DEFLATE, - Deflater.DEFAULT_COMPRESSION, Predictor.NONE); + CompressionMethod.DEFLATE, Deflater.DEFAULT_COMPRESSION, Predictor.NONE); /** * The key for declaring the compression at store creation time. @@ -102,7 +101,7 @@ public final class Compression implements Serializable { /** * The compression method. */ - final org.apache.sis.storage.geotiff.base.Compression method; + final CompressionMethod method; /** * The compression level from 0 to 9 inclusive, or -1 for default. @@ -121,7 +120,7 @@ public final class Compression implements Serializable { * @param level the compression level, or -1 for default. * @param predictor the predictor to apply before compression. */ - private Compression(final org.apache.sis.storage.geotiff.base.Compression method, final int level, final Predictor predictor) { + private Compression(final CompressionMethod method, final int level, final Predictor predictor) { this.method = method; this.level = level; this.predictor = predictor; @@ -180,8 +179,16 @@ public final class Compression implements Serializable { * @see BaselineTIFFTagSet#PREDICTOR_HORIZONTAL_DIFFERENCING */ public Compression withPredictor(int value) { - // `NONE` is required by `TileMatrix.writeRasters(…)` assumption that `level == 0` implies no predictor. - final Predictor p = usePredictor() ? Predictor.supported(value) : Predictor.NONE; + final Predictor p; + if (usePredictor()) { + p = Predictor.valueOf(value); + if (!p.isSupported()) { + throw new IllegalArgumentException(p.unsupported(null)); + } + } else { + // `NONE` is required by `TileMatrix.writeRasters(…)` assumption that `level == 0` implies no predictor. + p = Predictor.NONE; + } return p.equals(predictor) ? this : new Compression(method, level, p); } diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/DataCube.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/DataCube.java index e5a3c4ec95..180f0f5013 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/DataCube.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/DataCube.java @@ -29,7 +29,7 @@ import org.apache.sis.storage.event.StoreListeners; import org.apache.sis.storage.geotiff.base.Tags; import org.apache.sis.storage.geotiff.base.Resources; import org.apache.sis.storage.geotiff.base.Predictor; -import org.apache.sis.storage.geotiff.base.Compression; +import org.apache.sis.storage.geotiff.base.CompressionMethod; import org.apache.sis.storage.tiling.TiledGridCoverage; import org.apache.sis.storage.tiling.TiledGridCoverageResource; import org.apache.sis.storage.base.StoreResource; @@ -159,7 +159,7 @@ abstract class DataCube extends TiledGridCoverageResource implements StoreResour /** * Returns the compression method, or {@code null} if unspecified. */ - abstract Compression getCompression(); + abstract CompressionMethod getCompression(); /** * Returns the mathematical operator that is applied to the image data before an encoding scheme is applied. @@ -246,7 +246,7 @@ abstract class DataCube extends TiledGridCoverageResource implements StoreResour */ @Override protected final TiledGridCoverage read(final Subset subset) throws DataStoreException { - final Compression compression = getCompression(); + final CompressionMethod compression = getCompression(); if (compression == null) { throw new DataStoreContentException(reader.resources().getString( Resources.Keys.MissingValue_2, Tags.name((short) TAG_COMPRESSION))); @@ -256,7 +256,7 @@ abstract class DataCube extends TiledGridCoverageResource implements StoreResour * documented in the javadoc of its `readSlice(…)` method. If any precondition * is not met, we need to fallback on the less direct `CompressedSubset` class. */ - if (compression == Compression.NONE && getPredictor() == Predictor.NONE && canReadDirect(subset)) { + if (compression == CompressionMethod.NONE && getPredictor() == Predictor.NONE && canReadDirect(subset)) { return new DataSubset(this, subset); } else { return new CompressedSubset(this, subset); 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 2a2668ab0b..121a9fc764 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 @@ -48,7 +48,7 @@ import org.apache.sis.storage.DataStoreReferencingException; import org.apache.sis.storage.geotiff.base.Tags; import org.apache.sis.storage.geotiff.base.Resources; import org.apache.sis.storage.geotiff.base.Predictor; -import org.apache.sis.storage.geotiff.base.Compression; +import org.apache.sis.storage.geotiff.base.CompressionMethod; import org.apache.sis.storage.geotiff.reader.Type; import org.apache.sis.storage.geotiff.reader.GridGeometryBuilder; import org.apache.sis.storage.geotiff.reader.ImageMetadataBuilder; @@ -374,7 +374,7 @@ final class ImageFileDirectory extends DataCube { * * @see #getCompression() */ - private Compression compression; + private CompressionMethod compression; /** * Mathematical operator that is applied to the image data before an encoding scheme is applied. @@ -657,8 +657,8 @@ final class ImageFileDirectory extends DataCube { */ case TAG_COMPRESSION: { final int value = type.readAsInt(input(), count); - compression = Compression.valueOf(value); - if (compression == Compression.UNKNOWN) { + compression = CompressionMethod.valueOf(value); + if (compression == CompressionMethod.UNKNOWN) { return value; // Cause a warning to be reported by the caller. } break; @@ -1316,7 +1316,7 @@ final class ImageFileDirectory extends DataCube { * then we set a bit for preventing the `switch` block to perform a calculation but we let the code performs * the other checks in order to get an exception thrown with a better message. */ - int missing = !isPlanar && compression.equals(Compression.NONE) ? 0 : 0b1000; + int missing = !isPlanar && compression.equals(CompressionMethod.NONE) ? 0 : 0b1000; if (tileWidth < 0) missing |= 0b0001; if (tileHeight < 0) missing |= 0b0010; if (tileByteCounts == null) missing |= 0b0100; @@ -1933,7 +1933,7 @@ final class ImageFileDirectory extends DataCube { * Returns the compression method, or {@code null} if unspecified. */ @Override - Compression getCompression() { + CompressionMethod getCompression() { return compression; } diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/NativeMetadata.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/NativeMetadata.java index b8a0e767e3..b7ba60a978 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/NativeMetadata.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/NativeMetadata.java @@ -35,7 +35,7 @@ import org.apache.sis.util.collection.TreeTable; import org.apache.sis.util.collection.TableColumn; import org.apache.sis.util.collection.DefaultTreeTable; import org.apache.sis.io.stream.ChannelDataInput; -import org.apache.sis.storage.geotiff.base.Compression; +import org.apache.sis.storage.geotiff.base.CompressionMethod; import org.apache.sis.storage.geotiff.base.Predictor; import org.apache.sis.storage.geotiff.base.GeoKeys; import org.apache.sis.storage.geotiff.base.Tags; @@ -202,8 +202,8 @@ final class NativeMetadata extends GeoKeysLoader { * we continue to handle as integers for now. */ switch (tag) { - case TAG_COMPRESSION: value = toName(value, Compression::valueOf); break; - case TAG_PREDICTOR: value = toName(value, Predictor::valueOf); break; + case TAG_COMPRESSION: value = toName(value, CompressionMethod::valueOf); break; + case TAG_PREDICTOR: value = toName(value, Predictor::valueOf); break; case TAG_PLANAR_CONFIGURATION: { value = toString(value, (code) -> { switch (code) { diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/base/Compression.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/base/CompressionMethod.java similarity index 72% rename from endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/base/Compression.java rename to endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/base/CompressionMethod.java index bfbabadc10..61d29ba9c1 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/base/Compression.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/base/CompressionMethod.java @@ -16,28 +16,29 @@ */ package org.apache.sis.storage.geotiff.base; +import java.util.Locale; import static javax.imageio.plugins.tiff.BaselineTIFFTagSet.*; /** - * Possible values for {@code BaselineTIFFTagSet.TAG_COMPRESSION}. - * Data compression applies only to raster image data. All other TIFF fields are unaffected. - * - * <p>Except otherwise noted, field names in this class are upper-case variant of the names - * used in Web Coverage Service (WCS) as specified in the following specification:</p> + * Possible values for compression methods supported by the <abbr>TIFF</abbr> reader. + * This enumeration identifies only the algorithm. It does not contain the parameters that + * are sometime associated with the algorithm, such as the predictor or compression level. + * Except otherwise noted, field names in this class are upper-case variant of the names used + * in the Web Coverage Service (<abbr>WCS</abbr>) as specified in the following specification: * * <blockquote>OGC 12-100: GML Application Schema - Coverages - GeoTIFF Coverage Encoding Profile</blockquote> * - * The main exception is {@code CCITT}, which has different name in WCS query and response. + * The main exception is {@code CCITT}, which has different name in <abbr>WCS</abbr> query and response. * - * <p>This enumeration contains a relatively large number of compressions in order to put a name - * on the numerical codes that the reader may find. However the Apache SIS reader and writer do - * not support all those compressions. This enumeration is not put in public API for that reason.</p> + * <p>This enumeration contains a relatively large number of compressions in order to put a name on the numerical codes + * that a reader may find. However, the Apache <abbr>SIS</abbr> reader and writer do not support all those compressions. + * This enumeration is not put in public <abbr>API</abbr> for that reason.</p> * * @author Johann Sorel (Geomatys) * @author Martin Desruisseaux (Geomatys) */ -public enum Compression { +public enum CompressionMethod { /** * No compression, but pack data into bytes as tightly as possible, leaving no unused bits except * potentially at the end of rows. The component values are stored as an array of type byte. @@ -49,7 +50,7 @@ public enum Compression { NONE(COMPRESSION_NONE), /** - * CCITT Group 3, 1-Dimensional Modified Huffman run length encoding. + * <abbr>CCITT</abbr> Group 3, 1-Dimensional Modified Huffman run length encoding. * <ul> * <li>Name in WCS query: "Huffman"</li> * <li>Name in WCS response: "CCITTRLE"</li> @@ -69,7 +70,7 @@ public enum Compression { // ---- End of baseline GeoTIFF. Remaining are extensions cited by OGC standard ---- /** - * LZW compression. + * <abbr>LZW</abbr> compression. * <ul> * <li>Name in WCS query: "LZW"</li> * <li>Name in WCS response: "LZW"</li> @@ -89,7 +90,7 @@ public enum Compression { DEFLATE(COMPRESSION_ZLIB), /** - * JPEG compression. + * <abbr>JPEG</abbr> compression. * <ul> * <li>Name in WCS query: "JPEG"</li> * <li>Name in WCS response: "JPEG"</li> @@ -123,24 +124,24 @@ public enum Compression { UNKNOWN(0); /** - * The TIFF code for this compression. + * The <abbr>TIFF</abbr> code for this compression. */ public final int code; /** * Creates a new compression enumeration. */ - private Compression(final int code) { + private CompressionMethod(final int code) { this.code = code; } /** - * Returns the compression method for the given GeoTIFF code, or {@code UNKNOWN} if none. + * Returns the compression method for the given <abbr>TIFF</abbr> code, or {@link #UNKNOWN} if none. * - * @param code the TIFF code for which to get a compression enumeration value. - * @return enumeration value for the given code, or {@link #UNKNOWN} if none. + * @param code the <abbr>TIFF</abbr> code for which to get a compression enumeration value. + * @return enumeration value for the given code, or {@code UNKNOWN} if none. */ - public static Compression valueOf(final int code) { + public static CompressionMethod valueOf(final int code) { switch (code) { case COMPRESSION_DEFLATE: // Fall through case COMPRESSION_ZLIB: return DEFLATE; @@ -152,7 +153,7 @@ public enum Compression { case COMPRESSION_NONE: return NONE; default: { // Fallback for uncommon formats. - for (final Compression c : values()) { + for (final var c : values()) { if (c.code == code) return c; } break; @@ -173,8 +174,20 @@ public enum Compression { /** * Returns whether the compression can be configured with different levels. + * + * @return whether the compression can be configured with different levels. */ public final boolean supportLevels() { return this == DEFLATE; } + + /** + * Returns an error message for saying that this compression is unsupported. + * + * @param locale the locale for the error message, or {@code null} for the default locale. + * @return error message for unsupported predictor. + */ + public final String unsupported(final Locale locale) { + return Resources.forLocale(locale).getString(Resources.Keys.UnsupportedCompressionMethod_1, this); + } } diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/base/Predictor.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/base/Predictor.java index c0be9ed3fd..23a645c1b5 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/base/Predictor.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/base/Predictor.java @@ -16,17 +16,16 @@ */ package org.apache.sis.storage.geotiff.base; +import java.util.Locale; import static javax.imageio.plugins.tiff.BaselineTIFFTagSet.*; -import org.apache.sis.util.resources.Errors; /** * Possible values for {@code BaselineTIFFTagSet.TAG_PREDICTOR}. - * A predictor is a mathematical operator that is applied to the image data - * before an encoding scheme is applied. + * A predictor is a mathematical operator that is applied to the image data before an encoding scheme is applied. * - * <p>This enumeration contains more values than what the Apache SIS reader and writer can support. - * This enumeration is not put in public API for that reason.</p> + * <p>This enumeration contains more values than what the Apache <abbr>SIS</abbr> reader and writer can support. + * This enumeration is not put in public <abbr>API</abbr> for that reason.</p> * * @author Martin Desruisseaux (Geomatys) */ @@ -52,7 +51,7 @@ public enum Predictor { UNKNOWN(0); /** - * The TIFF code for this predictor. + * The <abbr>TIFF</abbr> code for this predictor. */ public final int code; @@ -66,7 +65,7 @@ public enum Predictor { /** * Returns the predictor for the given code. * - * @param code value associated to TIFF "predictor" tag. + * @param code value associated to <abbr>TIFF</abbr> "predictor" tag. * @return predictor for the given code. */ public static Predictor valueOf(final int code) { @@ -79,17 +78,21 @@ public enum Predictor { } /** - * Returns the predictor for the given code if supported. + * Returns whether this predictor is supported by the writer. * - * @param code value associated to TIFF "predictor" tag. - * @return predictor for the given code. - * @throws IllegalArgumentException if the given code is unsupported. + * @return whether this predictor is supported. */ - public static Predictor supported(final int code) { - final Predictor value = valueOf(code); - if (value.ordinal() <= HORIZONTAL_DIFFERENCING.ordinal()) { - return value; - } - throw new IllegalArgumentException(Errors.format(Errors.Keys.UnsupportedArgumentValue_1, code)); + public boolean isSupported() { + return ordinal() <= HORIZONTAL_DIFFERENCING.ordinal(); + } + + /** + * Returns an error message for saying that this predictor is unsupported. + * + * @param locale the locale for the error message, or {@code null} for the default locale. + * @return error message for unsupported predictor. + */ + public final String unsupported(final Locale locale) { + return Resources.forLocale(locale).getString(Resources.Keys.UnsupportedPredictor_1, this); } } diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/base/Tags.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/base/Tags.java index 426a5588eb..8eb12cd5dc 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/base/Tags.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/base/Tags.java @@ -71,7 +71,7 @@ public final class Tags { public static final short GDAL_NODATA = (short) 0xA481; // 42113 /** - * Supplier of TIFF tag sets, in preference order. + * Supplier of <abbr>TIFF</abbr> tag sets, in preference order. * The sets that are most likely to be used (for the kind of data handled by SIS) should be first. */ @SuppressWarnings({"unchecked", "rawtypes"}) diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/CCITTRLE.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/CCITTRLE.java index d20498886b..7e748820cd 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/CCITTRLE.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/CCITTRLE.java @@ -24,8 +24,9 @@ import org.apache.sis.io.stream.ChannelDataInput; /** * Inflater for values encoded with the CCITT Group 3, 1-Dimensional Modified Huffman run length encoding. - * This compression is described in section 10 of TIFF 6 specification. "Run length" (consecutive black or - * white pixels) are encoded with "words" having a variable number of bits. Example: + * This compression is described in section 10 of <abbr>TIFF</abbr> 6 specification. "Run length" + * (consecutive black or white pixels) are encoded with "words" having a variable number of bits. + * Example: * * <table class="sis"> * <caption>Run length encoding examples</caption> @@ -151,7 +152,7 @@ final class CCITTRLE extends CompressionChannel { * @param tree {@link #WHITE_RUNLENGTH_TREE} or {@link #BLACK_RUNLENGTH_TREE}. */ final int getRunLength(final short[] tree) throws IOException { - int runLength = 0, code; + int length = 0, code; do { int offset = 0; while ((code = tree[offset]) >= 0) { @@ -177,9 +178,9 @@ final class CCITTRLE extends CompressionChannel { offset = (input.readBit() != 0) ? code : offset + 1; } code = ~code; - runLength += code; + length += code; } while (code >= TERMINATING_LIMIT); - return runLength; + return length; } /** diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/CompressionChannel.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/CompressionChannel.java index ba3bd4e76a..e24163771d 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/CompressionChannel.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/CompressionChannel.java @@ -102,7 +102,7 @@ abstract class CompressionChannel extends PixelChannel { * for performance reasons. A well adjusted buffer size reduces calls to {@link ByteBuffer#compact()}, * which in turn reduces the number of copy operations between different regions of the buffer.</p> * - * @param channel the channel to wrap. This is {@code this} unless a {@link Predictor} is applied. + * @param channel the channel to wrap. This is {@code this} unless a predictor is applied. * @param scanlineStride the scanline stride of the image to read. Used for choosing a buffer size. * @param directBuffer whether the use of direct buffer is preferred to heap buffer. * @throws IOException if an error occurred while filling the buffer with initial data. diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/CopyFromBytes.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/CopyFromBytes.java index 1ff90bde51..384211bc7a 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/CopyFromBytes.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/CopyFromBytes.java @@ -31,8 +31,8 @@ import org.apache.sis.util.resources.Errors; /** * A pseudo-inflater which copies values from a buffer of bytes to the destination image buffer. - * When reading uncompressed TIFF images, the source buffer is the direct buffer used for I/O operations. - * When reading compressed TIFF images, the source buffer is a temporary buffer where data segments are + * When reading uncompressed images, the source buffer is the direct buffer used for I/O operations. + * When reading compressed images, the source buffer is a temporary buffer where data segments are * uncompressed before to be copied to the destination image. This is useful when handling subsampling * on-the-fly at decompression time would be too difficult: implementers can decompress everything in * a temporary buffer and let this {@code CopyFromBytes} class do the subsampling. diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/ZIP.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/Deflate.java similarity index 94% rename from endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/ZIP.java rename to endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/Deflate.java index 7acf831b11..d8fa212a5e 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/ZIP.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/Deflate.java @@ -31,7 +31,7 @@ import org.apache.sis.io.stream.ChannelDataInput; * @author Rémi Marechal (Geomatys) * @author Martin Desruisseaux (Geomatys) */ -final class ZIP extends CompressionChannel { +final class Deflate extends CompressionChannel { /** * Access to the ZLIB compression library. * Must be released by call to {@link Inflater#end()} after decompression is completed. @@ -49,7 +49,7 @@ final class ZIP extends CompressionChannel { * @param byteCount number of bytes to read from the input. * @throws IOException if the stream cannot be seek to the given start position. */ - public ZIP(final ChannelDataInput input, final StoreListeners listeners) { + public Deflate(final ChannelDataInput input, final StoreListeners listeners) { super(input, listeners); inflater = new Inflater(); } @@ -79,8 +79,7 @@ final class ZIP extends CompressionChannel { final int start = target.position(); int required = 0; try { - int n; - while ((n = inflater.inflate(target)) == 0) { + while (inflater.inflate(target) == 0) { if (inflater.needsInput()) { if (++required >= input.buffer.capacity()) { throw new BufferOverflowException(); @@ -103,6 +102,7 @@ final class ZIP extends CompressionChannel { * Releases resources used by the inflater. */ @Override + @SuppressWarnings("ConvertToTryWithResources") public void close() { inflater.end(); super.close(); diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/HorizontalPredictor.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/HorizontalPredictor.java index 57fa2ee2eb..cf7b381313 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/HorizontalPredictor.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/HorizontalPredictor.java @@ -20,11 +20,10 @@ import java.io.IOException; import java.nio.ByteBuffer; import org.apache.sis.image.DataType; import org.apache.sis.pending.jdk.JDK13; -import org.apache.sis.storage.geotiff.base.Predictor; /** - * Implementation of {@link Predictor#HORIZONTAL_DIFFERENCING}. + * Implementation of the horizontal differencing predictor. * Current implementation works only on 8, 16, 32 or 64-bits samples. * Values packed on 4, 2 or 1 bits are not yet supported. * 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 130000a7ed..a79573bc04 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 @@ -24,7 +24,7 @@ import org.apache.sis.image.DataType; import org.apache.sis.math.MathFunctions; import org.apache.sis.util.ArgumentChecks; import org.apache.sis.storage.UnsupportedEncodingException; -import org.apache.sis.storage.geotiff.base.Compression; +import org.apache.sis.storage.geotiff.base.CompressionMethod; import org.apache.sis.storage.geotiff.base.Predictor; import org.apache.sis.storage.geotiff.base.Resources; import org.apache.sis.io.stream.ChannelDataInput; @@ -183,24 +183,24 @@ public abstract class Inflater implements Closeable { * in a way that make them usable with other tiled formats than TIFF. */ @SuppressWarnings("fallthrough") - public static Inflater create(final StoreListeners listeners, - final ChannelDataInput input, - final Compression compression, - final Predictor predictor, - final int sourcePixelStride, - final int sourceWidth, - final int chunksPerRow, - final int samplesPerChunk, - final int[] skipAfterChunks, - final int pixelsPerElement, - final DataType dataType) + public static Inflater create(final StoreListeners listeners, + final ChannelDataInput input, + final CompressionMethod compression, + final Predictor predictor, + final int sourcePixelStride, + final int sourceWidth, + final int chunksPerRow, + final int samplesPerChunk, + final int[] skipAfterChunks, + final int pixelsPerElement, + final DataType dataType) throws IOException, UnsupportedEncodingException { ArgumentChecks.ensureNonNull("input", input); final CompressionChannel inflater; switch (compression) { case LZW: inflater = new LZW (input, listeners); break; - case DEFLATE: inflater = new ZIP (input, listeners); break; + case DEFLATE: inflater = new Deflate (input, listeners); 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.geotiff/main/org/apache/sis/storage/geotiff/inflater/LZW.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/LZW.java index 0db2dc0e3a..e0141af165 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/LZW.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/LZW.java @@ -26,12 +26,12 @@ import org.apache.sis.storage.event.StoreListeners; /** - * Inflater for values encoded with the LZW compression. - * This compression is described in section 13 of TIFF 6 specification, "LZW Compression". + * Inflater for values encoded with the <abbr>LZW</abbr> compression. + * This compression is described in section 13 of <abbr>TIFF</abbr> 6 specification, "<abbr>LZW</abbr> Compression". * Each code is written using at least 9 bits and at most 12 bits. * * <h2>Legal note</h2> - * Unisys's patent on the LZW algorithm expired in 2004. + * Unisys's patent on the <abbr>LZW</abbr> algorithm expired in 2004. * * @author Martin Desruisseaux (Geomatys) * @author Rémi Maréchal (Geomatys) diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/PredictorChannel.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/PredictorChannel.java index be9068ed7e..223382a214 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/PredictorChannel.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/PredictorChannel.java @@ -19,12 +19,11 @@ package org.apache.sis.storage.geotiff.inflater; import java.io.IOException; import java.nio.ByteBuffer; import org.apache.sis.util.ArraysExt; -import org.apache.sis.storage.geotiff.base.Predictor; import org.apache.sis.pending.jdk.JDK13; /** - * Implementation of a {@link Predictor} to be executed after decompression. + * Implementation of a predictor to be executed after decompression. * A predictor is a mathematical operator that is applied to the image data * before an encoding scheme is applied, in order to improve compression. * @@ -48,9 +47,8 @@ abstract class PredictorChannel extends PixelChannel { private int deferredCount; /** - * Creates a predictor. - * The {@link #setInputRegion(long, long)} method must be invoked after construction - * before a reading process can start. + * Creates a predictor. The {@link #setInputRegion(long, long)} method + * must be invoked after construction before a reading process can start. * * @param input the channel that decompress data. */ diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/package-info.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/package-info.java index 7b1add2fee..4d242b5934 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/package-info.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/package-info.java @@ -20,8 +20,8 @@ * * <STRONG>Do not use!</STRONG> * - * This package is for internal use by SIS only. Classes in this package - * may change in incompatible ways in any future version without notice. + * This package is for internal use by <abbr>SIS</abbr> only. + * Classes in this package may change in incompatible ways in any future version without notice. * This package is currently in the GeoTIFF module but we may move it to * another module in the future for sharing with other raster formats. * @@ -32,7 +32,7 @@ * For example, a pixel might have three samples storing the intensity of red, green and blue colors.</dd> * * <dt>Sample</dt> - * <dd>The value of a pixel in one band. For example if an image has three bands for red, green and blue colors, + * <dd>The value of a pixel in one band. For example, if an image has three bands for red, green and blue colors, * then the first sample value of a pixel is the intensity of the red color.</dd> * * <dt>Element</dt> diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/writer/TileMatrix.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/writer/TileMatrix.java index 18d6729d60..89e36fa683 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/writer/TileMatrix.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/writer/TileMatrix.java @@ -38,9 +38,8 @@ import org.apache.sis.io.stream.ChannelDataOutput; import org.apache.sis.io.stream.HyperRectangleWriter; import org.apache.sis.storage.DataStoreException; import org.apache.sis.storage.InternalDataStoreException; -import org.apache.sis.storage.geotiff.base.Compression; +import org.apache.sis.storage.geotiff.base.CompressionMethod; import org.apache.sis.storage.geotiff.base.Predictor; -import org.apache.sis.storage.geotiff.base.Resources; import org.apache.sis.pending.jdk.JDK18; @@ -105,7 +104,7 @@ public final class TileMatrix { /** * The compression to use for writing tiles. */ - private final Compression compression; + private final CompressionMethod compression; /** * The compression level, or -1 for default. @@ -128,7 +127,7 @@ public final class TileMatrix { * @param predictor the predictor to apply before to compress data. */ public TileMatrix(final RenderedImage image, final int numPlanes, final int[] bitsPerSample, - final Compression compression, final int compressionLevel, final Predictor predictor) + final CompressionMethod compression, final int compressionLevel, final Predictor predictor) { final int pixelSize, numArrays; this.numPlanes = numPlanes; @@ -176,13 +175,6 @@ public final class TileMatrix { } } - /** - * Creates an exception for an unsupported configuration. - */ - private static DataStoreException unsupported(final short key, final Enum<?> value) { - return new DataStoreException(Resources.forLocale(null).getString(key, value)); - } - /** * Writes the (eventually compressed) sample values of all tiles of the image. * Caller shall invoke {@link #writeOffsetsAndLengths(ChannelDataOutput)} after this method. @@ -248,10 +240,10 @@ public final class TileMatrix { final long length = Math.multiplyExact(builder.length(), type.bytes()); switch (compression) { case DEFLATE: compressor = new ZIP(output, length, compressionLevel); break; - default: throw unsupported(Resources.Keys.UnsupportedCompressionMethod_1, compression); + default: throw new DataStoreException(compression.unsupported(null)); } switch (predictor) { - default: throw unsupported(Resources.Keys.UnsupportedPredictor_1, predictor); + default: throw new DataStoreException(predictor.unsupported(null)); case NONE: break; case HORIZONTAL_DIFFERENCING: { compressor = HorizontalPredictor.create(compressor, type, builder.pixelStride(), builder.scanlineStride()); diff --git a/endorsed/src/org.apache.sis.storage.geotiff/test/org/apache/sis/storage/geotiff/base/CompressionTest.java b/endorsed/src/org.apache.sis.storage.geotiff/test/org/apache/sis/storage/geotiff/base/CompressionTest.java index b1fac853b6..14802b3f5a 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/test/org/apache/sis/storage/geotiff/base/CompressionTest.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/test/org/apache/sis/storage/geotiff/base/CompressionTest.java @@ -23,7 +23,7 @@ import org.apache.sis.test.TestCase; /** - * Tests the {@link Compression} enumeration. + * Tests the {@link CompressionMethod} and {@link Predictor} enumerations. * * @author Martin Desruisseaux (Geomatys) */ @@ -35,12 +35,22 @@ public final class CompressionTest extends TestCase { } /** - * Tests {@link Compression#valueOf(long)}. + * Tests {@link CompressionMethod#valueOf(int)}. */ @Test - public void testValueOf() { - for (final Compression c : Compression.values()) { - assertSame(c, Compression.valueOf(c.code), c.name()); + public void testMethodFromCode() { + for (final var c : CompressionMethod.values()) { + assertSame(c, CompressionMethod.valueOf(c.code), c.name()); + } + } + + /** + * Tests {@link Predictor#valueOf(int)}. + */ + @Test + public void testPreductorFromCode() { + for (final var c : Predictor.values()) { + assertSame(c, Predictor.valueOf(c.code), c.name()); } } } diff --git a/endorsed/src/org.apache.sis.storage.geotiff/test/org/apache/sis/storage/geotiff/inflater/CCITTRLETest.java b/endorsed/src/org.apache.sis.storage.geotiff/test/org/apache/sis/storage/geotiff/inflater/CCITTRLETest.java index 37faa6e8fb..1a47b5a68a 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/test/org/apache/sis/storage/geotiff/inflater/CCITTRLETest.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/test/org/apache/sis/storage/geotiff/inflater/CCITTRLETest.java @@ -31,7 +31,8 @@ import org.apache.sis.test.TestCase; /** - * Verifies the table of words for {@link CCITTRLE} implementation of TIFF Modified Huffman Compression. + * Verifies the table of words for {@link CCITTRLE} implementation + * of <abbr>TIFF</abbr> Modified Huffman Compression. * * @author Martin Desruisseaux (Geomatys) */
