sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1769015 - in /sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff: GeoTiffStore.java ImageFileDirectory.java Type.java
Date Wed, 09 Nov 2016 21:29:49 GMT
Author: desruisseaux
Date: Wed Nov  9 21:29:49 2016
New Revision: 1769015

URL: http://svn.apache.org/viewvc?rev=1769015&view=rev
Log:
Set default character encoding to US-ASCII as specified in GeoTIFF specification.
Change tile size type from long to int. The size of 'long' type seems excessive for a tile
and can not fit in java.awt.image.Raster anyway.

Modified:
    sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java
    sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
    sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Type.java

Modified: sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java?rev=1769015&r1=1769014&r2=1769015&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java
[UTF-8] Wed Nov  9 21:29:49 2016
@@ -20,6 +20,7 @@ import java.util.Locale;
 import java.io.IOException;
 import java.nio.charset.Charset;
 import java.util.logging.LogRecord;
+import java.nio.charset.StandardCharsets;
 import org.opengis.metadata.Metadata;
 import org.apache.sis.setup.OptionKey;
 import org.apache.sis.storage.DataStore;
@@ -66,13 +67,13 @@ public class GeoTiffStore extends DataSt
      * This constructor invokes {@link StorageConnector#closeAllExcept(Object)},
      * keeping open only the needed resource.
      *
-     * @param  storage information about the storage (URL, stream, <i>etc</i>).
+     * @param  storage  information about the storage (URL, stream, <i>etc</i>).
      * @throws DataStoreException if an error occurred while opening the GeoTIFF file.
      */
     public GeoTiffStore(final StorageConnector storage) throws DataStoreException {
         ArgumentChecks.ensureNonNull("storage", storage);
-        final Charset option         = storage.getOption(OptionKey.ENCODING);
-        encoding                     = (option != null) ? option : Charset.defaultCharset();
//-- TODO : ce n'est pas la bonne solution (maybe)
+        final Charset encoding = storage.getOption(OptionKey.ENCODING);
+        this.encoding = (encoding != null) ? encoding : StandardCharsets.US_ASCII;
         final ChannelDataInput input = storage.getStorageAs(ChannelDataInput.class);
         if (input == null) {
             throw new DataStoreException(Errors.format(Errors.Keys.IllegalInputTypeForReader_2,
@@ -103,16 +104,13 @@ public class GeoTiffStore extends DataSt
             while ((dir = reader.getImageFileDirectory(n++)) != null) {
                 dir.completeMetadata(reader.metadata, locale);
             }
-
-            //-- add geotiff CRS
+            // Add Coordinate Reference System built from GeoTIFF tags.
             reader.metadata.add(reader.crsBuilder.build());
             metadata = reader.metadata.build(true);
         } catch (IOException e) {
             throw new DataStoreException(reader.errors().getString(Errors.Keys.CanNotRead_1,
reader.input.filename), e);
-        } catch (ArithmeticException e) {
+        } catch (FactoryException | ArithmeticException e) {
             throw new DataStoreContentException(reader.canNotDecode(), e);
-        } catch (FactoryException e) {
-            throw new DataStoreContentException(e);
         }
         return metadata;
     }
@@ -145,18 +143,21 @@ public class GeoTiffStore extends DataSt
     }
 
     /**
-     * Reports a warning represented by the given {@link LogRecord}.
-     *
-     * <p>Moreover, {@linkplain LogRecord#setSourceClassName(java.lang.String) Class
name}
-     * and {@linkplain LogRecord#setSourceMethodName(java.lang.String) method name}
-     * are added into the given LogRecord.</p>
-     *
-     * @param logRecord the warning as a logrecord.
-     */
-    final void warning(final LogRecord logRecord) {
-        ArgumentChecks.ensureNonNull("logRecord", logRecord);
-        logRecord.setSourceClassName(GeoTiffStore.class.getName());
-        logRecord.setSourceMethodName("read");
-        listeners.warning(logRecord);
+     * Reports a warning contained in the given {@link LogRecord}.
+     * Note that the given record will not necessarily be sent to the logging framework;
+     * if the user as registered at least one listener, then the record will be sent to the
listeners instead.
+     *
+     * <p>This method sets the {@linkplain LogRecord#setSourceClassName(String) source
class name} and
+     * {@linkplain LogRecord#setSourceMethodName(String) source method name} to hard-coded
values.
+     * Those values assume that the warnings occurred indirectly from a call to {@link #getMetadata()}
+     * in this class. We do not report private classes or methods as the source of warnings.</p>
+     *
+     * @param  record  the warning to report.
+     */
+    final void warning(final LogRecord record) {
+        // Logger name will be set by listeners.warning(record).
+        record.setSourceClassName(GeoTiffStore.class.getName());
+        record.setSourceMethodName("getMetadata");
+        listeners.warning(record);
     }
 }

Modified: sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java?rev=1769015&r1=1769014&r2=1769015&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
[UTF-8] Wed Nov  9 21:29:49 2016
@@ -63,59 +63,38 @@ final class ImageFileDirectory {
     private long imageWidth = -1, imageHeight = -1;
 
     /**
-     * The width of each tile, or -1 if the information has not be found.
-     * This is the number of columns in each tile.
-     * Tiles should be small enough for fitting in memory.
-     *
-     * Assuming integer arithmetic, three computed values that are useful in the following
field descriptions are:
-     * {@preformat math
-     * TilesAcross = (ImageWidth + TileWidth - 1) / TileWidth
-     * TilesDown = (ImageLength + TileLength - 1) / TileLength
-     * TilesPerImage = TilesAcross * TilesDown
-     * }
-     * These computed values are not TIFF fields; they are simply values determined by
-     * the ImageWidth, TileWidth, ImageLength, and TileLength fields.
-     * TileWidth must be a multiple of 16. This restriction improves performance
-     * in some graphics environments and enhances compatibility with compression schemes
such as JPEG.
-     * Tiles need not be square.
-     * Note that ImageWidth can be less than TileWidth, although this means that the tiles
-     * are too large or that you are using tiling on really small images, neither of which
is recommended.
-     * The same observation holds for ImageLength and TileLength.
-     */
-    private long tileWidth = -1;
-
-    /**
      * The size of each tile, or -1 if the information has not be found.
-     * This is the number of rows in each tile.
-     * Tiles should be small enough for fitting in memory.
+     * Tiles shall be small enough for fitting in memory, typically in a {@link java.awt.image.Raster}
object.
+     * The TIFF specification requires that tile width and height must be a multiple of 16,
but the SIS reader
+     * implementation works for any size. Tiles need not be square.
+     *
+     * <p>Assuming integer arithmetic, the number of tiles in an image can be computed
as below
+     * (these computed values are not TIFF fields):</p>
      *
-     * Assuming integer arithmetic, three computed values that are useful in the following
field descriptions are:
      * {@preformat math
-     *   TilesAcross = (ImageWidth + TileWidth - 1) / TileWidth
-     *     TilesDown = (ImageLength + TileLength - 1) / TileLength
-     * TilesPerImage = TilesAcross * TilesDown
+     *   tilesAcross   = (imageWidth  + tileWidth  - 1) / tileWidth
+     *   tilesDown     = (imageHeight + tileHeight - 1) / tileHeight
+     *   tilesPerImage = tilesAcross * tilesDown
      * }
-     * These computed values are not TIFF fields; they are simply values determined by
-     * the ImageWidth, TileWidth, ImageLength, and TileLength fields.
-     * TileLength must be a multiple of 16. This restriction improves performance
-     * in some graphics environments and enhances compatibility with compression schemes
such as JPEG.
-     * Tiles need not be square
+     *
+     * Note that {@link #imageWidth} can be less than {@code tileWidth} and/or {@link #imageHeight}
can be less
+     * than {@code tileHeight}. Such case means that the tiles are too large or that the
tiled image is too small,
+     * neither of which is recommended.
      *
      * <p><b>Note:</b>
      * the {@link #tileHeight} attribute is named {@code TileLength} in TIFF specification.</p>
      */
-    private long tileHeight = -1;
+    private int tileWidth = -1, tileHeight = -1;
 
     /**
      * For each tile, the byte offset of that tile, as compressed and stored on disk.
-     *
      * The offset is specified with respect to the beginning of the TIFF file.
+     * Each tile has a location independent of the locations of other tiles
      *
-     * <p><b>Note</b> that this implies that each tile has a location independent
of the locations of other tiles.</p>
-     *
-     * Offsets are ordered left-to-right and top-to-bottom. For PlanarConfiguration = 2,
-     * the offsets for the first component plane are stored first,
-     * followed by all the offsets for the second component plane, and so on.
+     * <p>Offsets are ordered left-to-right and top-to-bottom. if {@link #isPlanar}
is {@code true}
+     * (i.e. components are stored in separate “component planes”), then the offsets
for the first
+     * component plane are stored first, followed by all the offsets for the second component
plane,
+     * and so on.</p>
      */
     private Vector tileOffsets;
 
@@ -436,18 +415,16 @@ final class ImageFileDirectory {
              * The tile width in pixels. This is the number of columns in each tile.
              */
             case Tags.TileWidth: {
-                tileWidth = type.readUnsignedLong(reader.input, count);
+                tileWidth = type.readInt(reader.input, count);
                 break;
             }
-
             /*
              * The tile length (height) in pixels. This is the number of rows in each tile.
              */
             case Tags.TileLength: {
-                tileHeight = type.readUnsignedLong(reader.input, count);
+                tileHeight = type.readInt(reader.input, count);
                 break;
             }
-
             /*
              * The tile length (height) in pixels. This is the number of rows in each tile.
              */
@@ -455,7 +432,6 @@ final class ImageFileDirectory {
                 tileOffsets = type.readVector(reader.input, count);
                 break;
             }
-
             /*
              * The tile width in pixels. This is the number of columns in each tile.
              */

Modified: sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Type.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Type.java?rev=1769015&r1=1769014&r2=1769015&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Type.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Type.java
[UTF-8] Wed Nov  9 21:29:49 2016
@@ -459,6 +459,27 @@ enum Type {
     }
 
     /**
+     * Reads a single value and returns it as a signed {@code int} type, performing conversion
if needed.
+     * This method should be invoked when the caller expects a single value.
+     *
+     * @param  input  the input from where to read the value.
+     * @param  count  the amount of values (normally exactly 1).
+     * @return the value as an {@code int}.
+     * @throws IOException if an error occurred while reading the stream.
+     * @throws NumberFormatException if the value was stored in ASCII and can not be parsed.
+     * @throws ArithmeticException if the value can not be represented in the Java signed
{@code int} type.
+     * @throws IllegalArgumentException if the value is not a singleton.
+     * @throws UnsupportedOperationException if this type is {@link #UNDEFINED}.
+     */
+    final int readInt(final ChannelDataInput input, final long count) throws IOException
{
+        final long value = readLong(input, count);
+        if (value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE) {
+            return (int) value;
+        }
+        throw new ArithmeticException(canNotConvert(Long.toString(value)));
+    }
+
+    /**
      * Reads a single value which is expected to be positive. A negative value may be an
encoding error in the
      * big TIFF file, or if it was really the intended value then something greater than
what we can support.
      *



Mime
View raw message