sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1754275 - in /sis/branches/JDK8/storage: sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ sis-storage/src/main/java/org/apache/sis/internal/storage/
Date Wed, 27 Jul 2016 14:04:57 GMT
Author: desruisseaux
Date: Wed Jul 27 14:04:57 2016
New Revision: 1754275

URL: http://svn.apache.org/viewvc?rev=1754275&view=rev
Log:
Finish declaration of baseline GeoTIFF tags. However most of them are not yet implemented.

Modified:
    sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTIFF.java
    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/Reader.java
    sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Tags.java
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java

Modified: sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTIFF.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTIFF.java?rev=1754275&r1=1754274&r2=1754275&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTIFF.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTIFF.java
[UTF-8] Wed Jul 27 14:04:57 2016
@@ -16,13 +16,18 @@
  */
 package org.apache.sis.storage.geotiff;
 
+import java.util.Locale;
+import java.util.TimeZone;
 import java.io.Closeable;
-import org.apache.sis.util.Localized;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 import org.apache.sis.util.resources.Errors;
 
 
 /**
  * Base class of GeoTIFF image reader and writer.
+ * Those readers and writers are <strong>not</strong> thread safe.
+ * The {@link GeoTiffStore} class is responsible for synchronization if needed.
  *
  * @author  Rémi Marechal (Geomatys)
  * @author  Alexis Manin (Geomatys)
@@ -34,14 +39,25 @@ import org.apache.sis.util.resources.Err
  */
 abstract class GeoTIFF implements Closeable {
     /**
-     * The locale for formatting error messages.
+     * The timezone specified at construction time, or {@code null} for the default.
+     * This is not yet configurable, but may become in a future version.
      */
-    private final Localized owner;
+    private static final TimeZone TIMEZONE = null;
+
+    /**
+     * The store which created this reader or writer.
+     */
+    final GeoTiffStore owner;
+
+    /**
+     * The object to use for parsing and formatting dates. Created when first needed.
+     */
+    private transient DateFormat dateFormat;
 
     /**
      * For subclass constructors.
      */
-    GeoTIFF(final Localized owner) {
+    GeoTIFF(final GeoTiffStore owner) {
         this.owner = owner;
     }
 
@@ -51,4 +67,17 @@ abstract class GeoTIFF implements Closea
     final Errors errors() {
         return Errors.getResources(owner.getLocale());
     }
+
+    /**
+     * Returns the object to use for parsing and formatting dates.
+     */
+    final DateFormat getDateFormat() {
+        if (dateFormat == null) {
+            dateFormat = new SimpleDateFormat("yyy:MM:dd HH:mm:ss", Locale.US);
+            if (TIMEZONE != null) {
+                dateFormat.setTimeZone(TIMEZONE);
+            }
+        }
+        return dateFormat;
+    }
 }

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=1754275&r1=1754274&r2=1754275&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 Jul 27 14:04:57 2016
@@ -17,6 +17,7 @@
 package org.apache.sis.storage.geotiff;
 
 import java.io.IOException;
+import java.nio.charset.Charset;
 import org.opengis.metadata.Metadata;
 import org.apache.sis.setup.OptionKey;
 import org.apache.sis.storage.DataStore;
@@ -39,6 +40,12 @@ import org.apache.sis.util.Classes;
  */
 public class GeoTiffStore extends DataStore {
     /**
+     * The encoding of strings in the metadata. The string specification said that is shall
be US-ASCII,
+     * but Apache SIS nevertheless let the user specifies an alternative encoding if needed.
+     */
+    final Charset encoding;
+
+    /**
      * The GeoTIFF reader implementation, or {@code null} if none.
      */
     private Reader reader;
@@ -53,6 +60,7 @@ public class GeoTiffStore extends DataSt
      */
     public GeoTiffStore(final StorageConnector storage) throws DataStoreException {
         ArgumentChecks.ensureNonNull("storage", storage);
+        encoding = storage.getOption(OptionKey.ENCODING);
         final ChannelDataInput input = storage.getStorageAs(ChannelDataInput.class);
         if (input == null) {
             throw new DataStoreException(Errors.format(Errors.Keys.IllegalInputTypeForReader_2,
@@ -60,7 +68,7 @@ public class GeoTiffStore extends DataSt
         }
         storage.closeAllExcept(input);
         try {
-            reader = new Reader(input, storage.getOption(OptionKey.ENCODING), this);
+            reader = new Reader(this, input);
         } catch (IOException e) {
             throw new DataStoreException(e);
         }
@@ -75,7 +83,7 @@ public class GeoTiffStore extends DataSt
      * @throws DataStoreException if an error occurred while reading the data.
      */
     @Override
-    public Metadata getMetadata() throws DataStoreException {
+    public synchronized Metadata getMetadata() throws DataStoreException {
         return null;
     }
 
@@ -94,4 +102,15 @@ public class GeoTiffStore extends DataSt
             throw new DataStoreException(e);
         }
     }
+
+    /**
+     * Reports a warning represented by the given message and exception.
+     * At least one of {@code message} and {@code exception} shall be non-null.
+     *
+     * @param message    the message to log, or {@code null} if none.
+     * @param exception  the exception to log, or {@code null} if none.
+     */
+    final void warning(final String message, final Exception exception) {
+        listeners.warning(message, exception);
+    }
 }

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=1754275&r1=1754274&r2=1754275&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 Jul 27 14:04:57 2016
@@ -17,6 +17,8 @@
 package org.apache.sis.storage.geotiff;
 
 import java.io.IOException;
+import java.text.ParseException;
+import org.opengis.metadata.citation.DateType;
 
 
 /**
@@ -29,6 +31,8 @@ import java.io.IOException;
  * @since   0.8
  * @version 0.8
  * @module
+ *
+ * @see <a href="http://www.awaresystems.be/imaging/tiff/tifftags.html">TIFF Tag Reference</a>
  */
 final class ImageFileDirectory {
     /**
@@ -82,24 +86,91 @@ final class ImageFileDirectory {
      * @param  count    the number of values to read.
      * @return {@code true} on success, or {@code false} for unrecognized value.
      * @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 ParseException if the value need to be parsed as date and the parsing failed.
+     * @throws NumberFormatException if the value need to be parsed as number and the parsing
failed.
      * @throws ArithmeticException if the value can not be represented in the expected Java
type.
      * @throws IllegalArgumentException if a value which was expected to be a singleton is
not.
      * @throws UnsupportedOperationException if the given type is {@link Type#UNDEFINED}.
      */
-    boolean addEntry(final Reader reader, final int tag, final Type type, final long count)
throws IOException {
+    boolean addEntry(final Reader reader, final int tag, final Type type, final long count)
throws IOException, ParseException {
         switch (tag) {
+
+            ////////////////////////////////////////////////////////////////////////////////////////////////
+            ////                                                                        
               ////
+            ////    Essential information for being able to read the image at least as grayscale.
      ////
+            ////    In Java2D, following information are needed for building the SampleModel.
          ////
+            ////                                                                        
               ////
+            ////////////////////////////////////////////////////////////////////////////////////////////////
+
             /*
-             * Person who created the image. Some older TIFF files used this tag for storing
-             * Copyright information, but Apache SIS does not support this legacy practice.
+             * How the components of each pixel are stored.
+             * 1 = Chunky format. The component values for each pixel are stored contiguously
(for example RGBRGBRGB).
+             * 2 = Planar format. For example one plane of Red components, one plane of Green
and one plane if Blue.
              */
-            case Tags.Artist: {
-                for (final String value : type.readString(reader.input, count, reader.encoding))
{
-                    reader.metadata.addAuthorName(value);
+            case Tags.PlanarConfiguration: {
+                final long value = type.readLong(reader.input, count);
+                if (value < 1 || value > 2) {
+                    return false;
+                }
+                isPlanar = (value == 2);
+                break;
+            }
+            /*
+             * The number of columns in the image, i.e., the number of pixels per row.
+             */
+            case Tags.ImageWidth: {
+                imageWidth = type.readUnsignedLong(reader.input, count);
+                break;
+            }
+            /*
+             * The number of rows of pixels in the image.
+             */
+            case Tags.ImageLength: {
+                imageHeight = type.readUnsignedLong(reader.input, count);
+                break;
+            }
+            /*
+             * The number of rows per strip. RowsPerStrip and ImageLength together tell us
the number of strips
+             * in the entire image: StripsPerImage = floor((ImageLength + RowsPerStrip -
1) / RowsPerStrip).
+             */
+            case Tags.RowsPerStrip: {
+                // TODO
+                break;
+            }
+            /*
+             * For each strip, the number of bytes in the strip after compression.
+             */
+            case Tags.StripByteCounts: {
+                // TODO
+                break;
+            }
+            /*
+             * For each strip, the byte offset of that strip relative to the beginning of
the TIFF file.
+             */
+            case Tags.StripOffsets: {
+                // TODO
+                break;
+            }
+            /*
+             * Compression scheme used on the image data.
+             */
+            case Tags.Compression: {
+                final long value = type.readLong(reader.input, count);
+                compression = Compression.valueOf(value);
+                if (compression == null) {
+                    return false;
                 }
                 break;
             }
             /*
+             * The logical order of bits within a byte. If this value is 2, then bits order
shall be reversed in every
+             * bytes before decompression.
+             */
+            case Tags.FillOrder: {
+                // TODO
+                break;
+            }
+            /*
              * Number of bits per component. The array length should be the number of components
in a
              * pixel (e.g. 3 for RGB values). Typically, all components have the same number
of bits.
              * But the TIFF specification allows different values.
@@ -109,18 +180,40 @@ final class ImageFileDirectory {
                 break;
             }
             /*
-             * The height of the dithering or halftoning matrix used to create a dithered
or halftoned
-             * bilevel file. Meaningful only if Threshholding = 2.
+             * The number of components per pixel. Ssually 1 for bilevel, grayscale, and
palette-color images,
+             * and 3 for RGB images. Default value is 1.
              */
-            case Tags.CellLength: {
+            case Tags.SamplesPerPixel: {
                 // TODO
                 break;
             }
             /*
-             * The width of the dithering or halftoning matrix used to create a dithered
or halftoned
-             * bilevel file. Meaningful only if Threshholding = 2.
+             * Specifies that each pixel has N extra components. When this field is used,
the SamplesPerPixel field
+             * has a value greater than the PhotometricInterpretation field suggests. For
example, a full-color RGB
+             * image normally has SamplesPerPixel=3. If SamplesPerPixel is greater than 3,
then the ExtraSamples field
+             * describes the meaning of the extra samples. It may be an alpha channel, but
not necessarily.
              */
-            case Tags.CellWidth: {
+            case Tags.ExtraSamples: {
+                // TODO
+                break;
+            }
+
+            ////////////////////////////////////////////////////////////////////////////////////////////////
+            ////                                                                        
               ////
+            ////    Information related to the color palette or the meaning of sample values.
          ////
+            ////    In Java2D, following information are needed for building the ColorModel.
           ////
+            ////                                                                        
               ////
+            ////////////////////////////////////////////////////////////////////////////////////////////////
+
+            /*
+             * The color space of the image data.
+             * 0 = WhiteIsZero. For bilevel and grayscale images: 0 is imaged as white.
+             * 1 = BlackIsZero. For bilevel and grayscale images: 0 is imaged as black.
+             * 2 = RGB. RGB value of (0,0,0) represents black, and (255,255,255) represents
white.
+             * 3 = Palette color. The value of the component is used as an index into the
RGB valuesthe ColorMap.
+             * 4 = Transparency Mask the defines an irregularly shaped region of another
image in the same TIFF file.
+             */
+            case Tags.PhotometricInterpretation: {
                 // TODO
                 break;
             }
@@ -137,44 +230,212 @@ final class ImageFileDirectory {
                 break;
             }
             /*
-             * Compression scheme used on the image data.
+             * The minimum component value used. Default is 0.
              */
-            case Tags.Compression: {
-                final long value = type.readLong(reader.input, count);
-                compression = Compression.valueOf(value);
-                if (compression == null) {
-                    return false;
+            case Tags.MinSampleValue: {
+                // TODO
+                break;
+            }
+            /*
+             * The maximum component value used. Default is {@code (1 << BitsPerSample)
- 1}.
+             * This field is for statistical purposes and should not to be used to affect
the
+             * visual appearance of an image, unless a map styling is applied.
+             */
+            case Tags.MaxSampleValue: {
+                // TODO
+                break;
+            }
+
+            ////////////////////////////////////////////////////////////////////////////////////////////////
+            ////                                                                        
               ////
+            ////    Information useful for defining the image role in a multi-images context.
          ////
+            ////                                                                        
               ////
+            ////////////////////////////////////////////////////////////////////////////////////////////////
+
+            /*
+             * A general indication of the kind of data contained in this subfile, mainly
useful when there
+             * are multiple subfiles in a single TIFF file. This field is made up of a set
of 32 flag bits.
+             *
+             * Bit 0 is 1 if the image is a reduced-resolution version of another image in
this TIFF file.
+             * Bit 1 is 1 if the image is a single page of a multi-page image (see PageNumber).
+             * Bit 2 is 1 if the image defines a transparency mask for another image in this
TIFF file (see PhotometricInterpretation).
+             * Bit 4 indicates MRC imaging model as described in ITU-T recommendation T.44
[T.44] (See ImageLayer tag) - RFC 2301.
+             */
+            case Tags.NewSubfileType: {
+                // TODO
+                break;
+            }
+            /*
+             * Old version (now deprecated) of above NewSubfileType.
+             * 1 = full-resolution image data
+             * 2 = reduced-resolution image data
+             * 3 = a single page of a multi-page image (see PageNumber).
+             */
+            case Tags.SubfileType: {
+                // TODO
+                break;
+            }
+
+            ////////////////////////////////////////////////////////////////////////////////////////////////
+            ////                                                                        
               ////
+            ////    Information related to the Coordinate Reference System and the bounding
box.        ////
+            ////                                                                        
               ////
+            ////////////////////////////////////////////////////////////////////////////////////////////////
+
+            /*
+             * The orientation of the image with respect to the rows and columns.
+             * This is an integer numeroted from 1 to 7 inclusive (see TIFF specification
for meaning).
+             */
+            case Tags.Orientation: {
+                // TODO
+                break;
+            }
+
+
+            ////////////////////////////////////////////////////////////////////////////////////////////////
+            ////                                                                        
               ////
+            ////    Metadata for discovery purposes, conditions of use, etc.            
               ////
+            ////    Those metadata are not "critical" information for reading the image.
               ////
+            ////                                                                        
               ////
+            ////////////////////////////////////////////////////////////////////////////////////////////////
+
+            /*
+             * A string that describes the subject of the image.
+             * For example, a user may wish to attach a comment such as "1988 company picnic"
to an image.
+             */
+            case Tags.ImageDescription: {
+                for (final String value : type.readString(reader.input, count, reader.owner.encoding))
{
+                    reader.metadata.addTitle(value);
+                }
+                break;
+            }
+            /*
+             * Person who created the image. Some older TIFF files used this tag for storing
+             * Copyright information, but Apache SIS does not support this legacy practice.
+             */
+            case Tags.Artist: {
+                for (final String value : type.readString(reader.input, count, reader.owner.encoding))
{
+                    reader.metadata.addAuthor(value);
                 }
                 break;
             }
             /*
              * Copyright notice of the person or organization that claims the copyright to
the image.
+             * Example: “Copyright, John Smith, 1992. All rights reserved.”
              */
             case Tags.Copyright: {
-                for (final String value : type.readString(reader.input, count, reader.encoding))
{
+                for (final String value : type.readString(reader.input, count, reader.owner.encoding))
{
                     reader.metadata.parseLegalNotice(value);
                 }
                 break;
             }
-            case Tags.PlanarConfiguration: {
-                final long value = type.readLong(reader.input, count);
-                if (value < 1 || value > 2) {
-                    return false;
+            /*
+             * Date and time of image creation. The format is: "YYYY:MM:DD HH:MM:SS" with
24-hour clock.
+             */
+            case Tags.DateTime: {
+                for (final String value : type.readString(reader.input, count, reader.owner.encoding))
{
+                    reader.metadata.add(reader.getDateFormat().parse(value), DateType.CREATION);
                 }
-                isPlanar = (value == 2);
                 break;
             }
-            case Tags.PhotometricInterpretation: {
-                final boolean blackIsZero = (type.readLong(reader.input, count) != 0);
+            /*
+             * The computer and/or operating system in use at the time of image creation.
+             */
+            case Tags.HostComputer: {
                 // TODO
                 break;
             }
-            case Tags.ImageLength: {
-                imageHeight = type.readUnsignedLong(reader.input, count);
+            /*
+             * Name and version number of the software package(s) used to create the image.
+             */
+            case Tags.Software: {
+                // TODO
                 break;
             }
-            case Tags.ImageWidth: {
-                imageWidth = type.readUnsignedLong(reader.input, count);
+            /*
+             * Manufacturer of the scanner, video digitizer, or other type of equipment used
to generate the image.
+             * Synthetic images should not include this field.
+             */
+            case Tags.Make: {
+                // TODO
+                break;
+            }
+            /*
+             * The model name or number of the scanner, video digitizer, or other type of
equipment used to
+             * generate the image.
+             */
+            case Tags.Model: {
+                // TODO
+                break;
+            }
+            /*
+             * The number of pixels per ResolutionUnit in the ImageWidth direction.
+             */
+            case Tags.XResolution: {
+                // TODO
+                break;
+            }
+            /*
+             * The number of pixels per ResolutionUnit in the ImageLength direction.
+             */
+            case Tags.YResolution: {
+                // TODO
+                break;
+            }
+            /*
+             * The unit of measurement for XResolution and YResolution.
+             * 1 = None, 2 = Inch, 3 = Centimeter.
+             */
+            case Tags.ResolutionUnit: {
+                // TODO
+                break;
+            }
+            /*
+             * The technique used to convert from gray to black and white pixels (if applicable):
+             * 1 = No dithering or halftoning has been applied to the image data.
+             * 2 = An ordered dither or halftone technique has been applied to the image
data.
+             * 3 = A randomized process such as error diffusion has been applied to the image
data.
+             */
+            case Tags.Threshholding: {
+                // TODO
+                break;
+            }
+            /*
+             * The width of the dithering or halftoning matrix used to create a dithered
or halftoned
+             * bilevel file. Meaningful only if Threshholding = 2.
+             */
+            case Tags.CellWidth: {
+                // TODO
+                break;
+            }
+            /*
+             * The height of the dithering or halftoning matrix used to create a dithered
or halftoned
+             * bilevel file. Meaningful only if Threshholding = 2.
+             */
+            case Tags.CellLength: {
+                // TODO
+                break;
+            }
+
+            ////////////////////////////////////////////////////////////////////////////////////////////////
+            ////                                                                        
               ////
+            ////    Defined by TIFF specification but currently ignored.                
               ////
+            ////                                                                        
               ////
+            ////////////////////////////////////////////////////////////////////////////////////////////////
+
+            /*
+             * For each string of contiguous unused bytes in a TIFF file, the number of bytes
and the byte offset
+             * in the string. Those tags are deprecated and do not need to be supported.
+             */
+            case Tags.FreeByteCounts:
+            case Tags.FreeOffsets:
+            /*
+             * For grayscale data, the optical density of each possible pixel value, plus
the precision of that
+             * information. This is ignored by most TIFF readers.
+             */
+            case Tags.GrayResponseCurve:
+            case Tags.GrayResponseUnit: {
+                // TODO: log a warning saying that this tag is ignored.
                 break;
             }
         }

Modified: sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Reader.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Reader.java?rev=1754275&r1=1754274&r2=1754275&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Reader.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Reader.java
[UTF-8] Wed Jul 27 14:04:57 2016
@@ -20,13 +20,11 @@ import java.util.List;
 import java.util.ArrayList;
 import java.io.IOException;
 import java.nio.ByteOrder;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
+import java.text.ParseException;
 import org.apache.sis.internal.storage.ChannelDataInput;
 import org.apache.sis.internal.storage.MetadataBuilder;
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.util.resources.Errors;
-import org.apache.sis.util.Localized;
 
 
 /**
@@ -55,12 +53,6 @@ final class Reader extends GeoTIFF {
     final ChannelDataInput input;
 
     /**
-     * The encoding of strings in the metadata. The string specification said that is shall
be US-ASCII,
-     * but Apache SIS nevertheless let the user specifies an alternative encoding if needed.
-     */
-    final Charset encoding;
-
-    /**
      * Stream position of the first byte of the GeoTIFF file. This is usually zero.
      */
     private final long origin;
@@ -99,14 +91,11 @@ final class Reader extends GeoTIFF {
      * @throws IOException if an error occurred while reading bytes from the stream.
      * @throws DataStoreException if the file is not encoded in the TIFF or BigTIFF format.
      */
-    Reader(final ChannelDataInput input, final Charset encoding, final Localized owner)
-            throws IOException, DataStoreException
-    {
+    Reader(final GeoTiffStore owner, final ChannelDataInput input) throws IOException, DataStoreException
{
         super(owner);
-        this.input = input;
-        origin = input.getStreamPosition();
-        metadata = new MetadataBuilder();
-        this.encoding = (encoding != null) ? encoding : StandardCharsets.US_ASCII;
+        this.input    = input;
+        this.origin   = input.getStreamPosition();
+        this.metadata = new MetadataBuilder();
         /*
          * A TIFF file begins with either "II" (0x4949) or "MM" (0x4D4D) characters.
          * Those characters identify the byte order. Note we we do not need to care
@@ -227,26 +216,30 @@ final class Reader extends GeoTIFF {
             final int   tag   = input.readUnsignedShort();
             final Type  type  = Type.valueOf(input.readShort());        // May be null.
             final long  count = readUnsignedInt();
-            final long  size  = (type != null) ? Math.multiplyExact(type.size, count) : 0;
-            if (size <= offsetSize) {
-                /*
-                 * If the value can fit inside the number of bytes given by 'offsetSize',
then the value is
-                 * stored directly at that location. This is the most common way TIFF tag
values are stored.
-                 */
-                final long position = input.getStreamPosition();
-                if (size != 0) {
+            try {
+                final long  size  = (type != null) ? Math.multiplyExact(type.size, count)
: 0;
+                if (size <= offsetSize) {
                     /*
-                     * A size of zero means that we have an unknown type, in which case the
TIFF specification
-                     * recommends to ignore it (for allowing them to add new types in the
future), or an entry
-                     * without value (count = 0) - in principle illegal but we make this
reader tolerant.
+                     * If the value can fit inside the number of bytes given by 'offsetSize',
then the value is
+                     * stored directly at that location. This is the most common way TIFF
tag values are stored.
                      */
-                    dir.addEntry(this, tag, type, count);
+                    final long position = input.getStreamPosition();
+                    if (size != 0) {
+                        /*
+                         * A size of zero means that we have an unknown type, in which case
the TIFF specification
+                         * recommends to ignore it (for allowing them to add new types in
the future), or an entry
+                         * without value (count = 0) - in principle illegal but we make this
reader tolerant.
+                         */
+                        dir.addEntry(this, tag, type, count);
+                    }
+                    input.seek(position + offsetSize);
+                } else {
+                    // offset from beginning of file where the values are stored.
+                    final long value = readUnsignedInt();
+                    // TODO
                 }
-                input.seek(position + offsetSize);
-            } else {
-                // offset from beginning of file where the values are stored.
-                final long value = readUnsignedInt();
-                // TODO
+            } catch (IOException | ParseException | RuntimeException e) {
+                owner.warning(errors().getString(Errors.Keys.CanNotSetPropertyValue_1, Tags.name(tag)),
e);
             }
         }
         return imageFileDirectories.add(dir);

Modified: sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Tags.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Tags.java?rev=1754275&r1=1754274&r2=1754275&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Tags.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Tags.java
[UTF-8] Wed Jul 27 14:04:57 2016
@@ -16,6 +16,8 @@
  */
 package org.apache.sis.storage.geotiff;
 
+import java.lang.reflect.Field;
+
 
 /**
  * Numerical values of GeoTIFF tags. In this class, field names are identical to TIFF tag
names.
@@ -35,82 +37,82 @@ final class Tags {
     //                  BASELINE TIFF TAGS                  //
     //////////////////////////////////////////////////////////
 
-    static final int NewSubfileType              = 0x00FE;
-    static final int SubfileType                 = 0x00FF;
-    static final int ImageWidth                  = 0x0100;
-    static final int ImageLength                 = 0x0101;
-    static final int BitsPerSample               = 0x0102;
-    static final int Compression                 = 0x0103;
-    static final int PhotometricInterpretation   = 0x0106;
-    static final int Threshholding               = 0x0107;
-    static final int CellWidth                   = 0x0108;
-    static final int CellLength                  = 0x0109;
-    static final int FillOrder                   = 0x010A;
-    static final int DocumentName                = 0x010D;
-    static final int ImageDescription            = 0x010E;
-    static final int Make                        = 0x010F;
-    static final int Model                       = 0x0110;
-    static final int StripOffsets                = 0x0111;
-    static final int Orientation                 = 0x0112;
-    static final int SamplesPerPixel             = 0x0115;
-    static final int RowsPerStrip                = 0x0116;
-    static final int StripByteCounts             = 0x0117;
-    static final int MinSampleValue              = 0x0118;
-    static final int MaxSampleValue              = 0x0119;
-    static final int XResolution                 = 0x011A;
-    static final int YResolution                 = 0x011B;
-    static final int PlanarConfiguration         = 0x011C;
-    static final int PageName                    = 0x011D;
-    static final int XPosition                   = 0x011E;
-    static final int YPosition                   = 0x011F;
-    static final int FreeOffsets                 = 0x0120;
-    static final int FreeByteCounts              = 0x0121;
-    static final int GrayResponseUnit            = 0x0122;
-    static final int GrayResponseCurve           = 0x0123;
-    static final int T4Options                   = 0x0124;
-    static final int T6Options                   = 0x0125;
-    static final int ResolutionUnit              = 0x0128;
-    static final int PageNumber                  = 0x0129;
-    static final int TransferFunction            = 0x012D;
-    static final int Software                    = 0x0131;
-    static final int DateTime                    = 0x0132;
-    static final int DateTimeOriginal            = 0x9003;
-    static final int DateTimeDigitized           = 0x9004;
-    static final int Artist                      = 0x013B;
-    static final int HostComputer                = 0x013C;
-    static final int Predictor                   = 0x013D;
-    static final int WhitePoint                  = 0x013E;
-    static final int PrimaryChromaticities       = 0x013F;
-    static final int ColorMap                    = 0x0140;
-    static final int HalftoneHints               = 0x0141;
-    static final int TileWidth                   = 0x0142;
-    static final int TileLength                  = 0x0143;
-    static final int TileOffsets                 = 0x0144;
-    static final int TileByteCounts              = 0x0145;
-    static final int InkSet                      = 0x014C;
-    static final int InkNames                    = 0x014D;
-    static final int NumberOfInks                = 0x014E;
-    static final int DotRange                    = 0x0150;
-    static final int TargetPrinter               = 0x0151;
-    static final int ExtraSamples                = 0x0152;
-    static final int SampleFormat                = 0x0153;
-    static final int SMinSampleValue             = 0x0154;
-    static final int SMaxSampleValue             = 0x0155;
-    static final int TransferRange               = 0x0156;
-    static final int JPEGProc                    = 0x0200;
-    static final int JPEGInterchangeFormat       = 0x0201;
-    static final int JPEGInterchangeFormatLength = 0x0202;
-    static final int JPEGRestartInterval         = 0x0203;
-    static final int JPEGLosslessPredictors      = 0x0205;
-    static final int JPEGPointTransforms         = 0x0206;
-    static final int JPEGQTables                 = 0x0207;
-    static final int JPEGDCTables                = 0x0208;
-    static final int JPEGACTables                = 0x0209;
-    static final int YCbCrCoefficients           = 0x0211;
-    static final int YCbCrSubSampling            = 0x0212;
-    static final int YCbCrPositioning            = 0x0213;
-    static final int ReferenceBlackWhite         = 0x0214;
-    static final int Copyright                   = 0x8298;
+    public static final int NewSubfileType              = 0x00FE;
+    public static final int SubfileType                 = 0x00FF;
+    public static final int ImageWidth                  = 0x0100;
+    public static final int ImageLength                 = 0x0101;
+    public static final int BitsPerSample               = 0x0102;
+    public static final int Compression                 = 0x0103;
+    public static final int PhotometricInterpretation   = 0x0106;
+    public static final int Threshholding               = 0x0107;
+    public static final int CellWidth                   = 0x0108;
+    public static final int CellLength                  = 0x0109;
+    public static final int FillOrder                   = 0x010A;
+    public static final int DocumentName                = 0x010D;
+    public static final int ImageDescription            = 0x010E;
+    public static final int Make                        = 0x010F;
+    public static final int Model                       = 0x0110;
+    public static final int StripOffsets                = 0x0111;
+    public static final int Orientation                 = 0x0112;
+    public static final int SamplesPerPixel             = 0x0115;
+    public static final int RowsPerStrip                = 0x0116;
+    public static final int StripByteCounts             = 0x0117;
+    public static final int MinSampleValue              = 0x0118;
+    public static final int MaxSampleValue              = 0x0119;
+    public static final int XResolution                 = 0x011A;
+    public static final int YResolution                 = 0x011B;
+    public static final int PlanarConfiguration         = 0x011C;
+    public static final int PageName                    = 0x011D;
+    public static final int XPosition                   = 0x011E;
+    public static final int YPosition                   = 0x011F;
+    public static final int FreeOffsets                 = 0x0120;
+    public static final int FreeByteCounts              = 0x0121;
+    public static final int GrayResponseUnit            = 0x0122;
+    public static final int GrayResponseCurve           = 0x0123;
+    public static final int T4Options                   = 0x0124;
+    public static final int T6Options                   = 0x0125;
+    public static final int ResolutionUnit              = 0x0128;
+    public static final int PageNumber                  = 0x0129;
+    public static final int TransferFunction            = 0x012D;
+    public static final int Software                    = 0x0131;
+    public static final int DateTime                    = 0x0132;
+    public static final int DateTimeOriginal            = 0x9003;
+    public static final int DateTimeDigitized           = 0x9004;
+    public static final int Artist                      = 0x013B;
+    public static final int HostComputer                = 0x013C;
+    public static final int Predictor                   = 0x013D;
+    public static final int WhitePoint                  = 0x013E;
+    public static final int PrimaryChromaticities       = 0x013F;
+    public static final int ColorMap                    = 0x0140;
+    public static final int HalftoneHints               = 0x0141;
+    public static final int TileWidth                   = 0x0142;
+    public static final int TileLength                  = 0x0143;
+    public static final int TileOffsets                 = 0x0144;
+    public static final int TileByteCounts              = 0x0145;
+    public static final int InkSet                      = 0x014C;
+    public static final int InkNames                    = 0x014D;
+    public static final int NumberOfInks                = 0x014E;
+    public static final int DotRange                    = 0x0150;
+    public static final int TargetPrinter               = 0x0151;
+    public static final int ExtraSamples                = 0x0152;
+    public static final int SampleFormat                = 0x0153;
+    public static final int SMinSampleValue             = 0x0154;
+    public static final int SMaxSampleValue             = 0x0155;
+    public static final int TransferRange               = 0x0156;
+    public static final int JPEGProc                    = 0x0200;
+    public static final int JPEGInterchangeFormat       = 0x0201;
+    public static final int JPEGInterchangeFormatLength = 0x0202;
+    public static final int JPEGRestartInterval         = 0x0203;
+    public static final int JPEGLosslessPredictors      = 0x0205;
+    public static final int JPEGPointTransforms         = 0x0206;
+    public static final int JPEGQTables                 = 0x0207;
+    public static final int JPEGDCTables                = 0x0208;
+    public static final int JPEGACTables                = 0x0209;
+    public static final int YCbCrCoefficients           = 0x0211;
+    public static final int YCbCrSubSampling            = 0x0212;
+    public static final int YCbCrPositioning            = 0x0213;
+    public static final int ReferenceBlackWhite         = 0x0214;
+    public static final int Copyright                   = 0x8298;
 
 
 
@@ -118,12 +120,31 @@ final class Tags {
     //                 GDAL EXTENSION TAGS                 //
     /////////////////////////////////////////////////////////
 
-    static final int GDAL_METADATA = 42112;  // http://www.awaresystems.be/imaging/tiff/tifftags/gdal_metadata.html
-    static final int GDAL_NODATA   = 42113;  // http://www.awaresystems.be/imaging/tiff/tifftags/gdal_nodata.html
+    public static final int GDAL_METADATA = 42112;  // http://www.awaresystems.be/imaging/tiff/tifftags/gdal_metadata.html
+    public static final int GDAL_NODATA   = 42113;  // http://www.awaresystems.be/imaging/tiff/tifftags/gdal_nodata.html
 
     /**
      * Do not allow instantiation of this class.
      */
     private Tags() {
     }
+
+    /**
+     * Returns the name of the given tag. Implementation of this method is inefficient,
+     * but it should rarely be invoked (mostly for formatting error messages).
+     */
+    static String name(final int tag) {
+        try {
+            for (final Field field : Tags.class.getFields()) {
+                if (field.getType() == Integer.TYPE) {
+                    if (field.getInt(null) == tag) {
+                        return field.getName();
+                    }
+                }
+            }
+        } catch (IllegalAccessException e) {
+            throw new AssertionError(e);        // Should never happen because we asked only
for public fields.
+        }
+        return Integer.toHexString(tag);
+    }
 }

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java?rev=1754275&r1=1754274&r2=1754275&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
[UTF-8] Wed Jul 27 14:04:57 2016
@@ -20,6 +20,7 @@ import java.util.Date;
 import java.util.Collection;
 import java.util.Collections;
 import java.nio.charset.Charset;
+import org.opengis.util.InternationalString;
 import org.opengis.metadata.citation.Role;
 import org.opengis.metadata.citation.DateType;
 import org.opengis.metadata.constraint.Restriction;
@@ -275,17 +276,90 @@ public class MetadataBuilder {
     }
 
     /**
+     * Adds a date of the given type.
+     *
+     * @param date  the date to add, or {@code null}.
+     * @param type  the type of the date to add, or {@code null}.
+     */
+    public final void add(final Date date, final DateType type) {
+        if (date != null) {
+            citation().getDates().add(new DefaultCitationDate(date, type));
+        }
+    }
+
+    /**
+     * Returns the given character sequence as a non-empty character string with leading
and trailing spaces removed.
+     * If the given character sequence is null, empty or blank, then this method returns
{@code null}.
+     */
+    private static InternationalString trim(CharSequence string) {
+        string = CharSequences.trimWhitespaces(string);
+        if (string != null && string.length() != 0) {
+            return Types.toInternationalString(string);
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * Returns the concatenation of the given string. The previous string may be {@code null}.
+     * This method does nothing if the previous string already contains the one to append.
+     */
+    private static InternationalString append(final InternationalString previous, final InternationalString
toAdd) {
+        if (previous == null) {
+            return toAdd;
+        }
+        final String p = previous.toString();
+        final String a = toAdd.toString();
+        if (p.contains(a)) {
+            return previous;
+        }
+        return Types.toInternationalString(p + System.lineSeparator() + a);
+    }
+
+    /**
+     * Adds a title of the resource.
+     *
+     * @param title  the resource title, or {@code null} if none.
+     */
+    public final void addTitle(final CharSequence title) {
+        final InternationalString i18n = trim(title);
+        if (i18n != null) {
+            final DefaultCitation citation = citation();
+            if (citation.getTitle() == null) {
+                citation.setTitle(i18n);
+            } else {
+                citation.getAlternateTitles().add(i18n);
+            }
+        }
+    }
+
+    /**
+     * Adds a brief narrative summary of the resource(s).
+     * If a summary already existed, the new one will be appended after a new line.
+     *
+     * @param description  the summary of resource(s), or {@code null} if none.
+     */
+    public final void addAbstract(final CharSequence description) {
+        final InternationalString i18n = trim(description);
+        if (i18n != null) {
+            final DefaultDataIdentification identification = identification();
+            identification.setAbstract(append(identification.getAbstract(), i18n));
+        }
+    }
+
+    /**
      * Adds an author name.
      *
      * @param  author  the name of the author or publisher, or {@code null} if none.
      */
-    public final void addAuthorName(final CharSequence author) {
-        if (author != null) {
+    public final void addAuthor(final CharSequence author) {
+        final InternationalString i18n = trim(author);
+        if (i18n != null) {
             if (party != null) {
-                responsibility().getParties().add(party);
+                responsibility().getParties().add(party);       // Save the previous party
before to create a new one.
                 party = null;
             }
-            party().setName(Types.toInternationalString(author));
+            party().setName(i18n);
         }
     }
 




Mime
View raw message