commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1245871 [5/5] - in /commons/proper/sanselan/trunk: ./ src/main/java/org/apache/commons/sanselan/common/ src/main/java/org/apache/commons/sanselan/formats/jpeg/ src/main/java/org/apache/commons/sanselan/formats/tiff/ src/main/java/org/apach...
Date Sat, 18 Feb 2012 06:43:35 GMT
Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffOutputSet.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffOutputSet.java?rev=1245871&r1=1245870&r2=1245871&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffOutputSet.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffOutputSet.java
Sat Feb 18 06:43:33 2012
@@ -20,9 +20,10 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.commons.sanselan.ImageWriteException;
+import org.apache.commons.sanselan.common.RationalNumberUtilities;
 import org.apache.commons.sanselan.formats.tiff.constants.GpsTagConstants;
-import org.apache.commons.sanselan.formats.tiff.constants.TagInfo;
 import org.apache.commons.sanselan.formats.tiff.constants.TiffConstants;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfo;
 import org.apache.commons.sanselan.util.Debug;
 
 public final class TiffOutputSet implements TiffConstants
@@ -153,21 +154,12 @@ public final class TiffOutputSet impleme
         String latitudeRef = latitude < 0 ? "S" : "N";
         latitude = Math.abs(latitude);
 
-        {
-            TiffOutputField longitudeRefField = TiffOutputField.create(
-                    GpsTagConstants.GPS_LONGITUDE_REF.tagInfo, byteOrder,
-                    longitudeRef);
-            gpsDirectory.removeField(GpsTagConstants.GPS_LONGITUDE_REF.tagInfo);
-            gpsDirectory.add(longitudeRefField);
-        }
+        gpsDirectory.removeField(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF);
+        gpsDirectory.add(GpsTagConstants.GPS_TAG_GPS_DEST_LONGITUDE_REF, longitudeRef);
+
+        gpsDirectory.removeField(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF);
+        gpsDirectory.add(GpsTagConstants.GPS_TAG_GPS_DEST_LATITUDE_REF, latitudeRef);
 
-        {
-            TiffOutputField latitudeRefField = TiffOutputField.create(
-                    GpsTagConstants.GPS_LATITUDE_REF.tagInfo, byteOrder,
-                    latitudeRef);
-            gpsDirectory.removeField(GpsTagConstants.GPS_LATITUDE_REF.tagInfo);
-            gpsDirectory.add(latitudeRefField);
-        }
 
         {
             double value = longitude;
@@ -178,15 +170,12 @@ public final class TiffOutputSet impleme
             value %= 1;
             value *= 60.0;
             double longitudeSeconds = value;
-            Double values[] = {
-                    new Double(longitudeDegrees), new Double(longitudeMinutes),
-                    new Double(longitudeSeconds),
-            };
-
-            TiffOutputField longitudeField = TiffOutputField.create(
-                    GpsTagConstants.GPS_LONGITUDE.tagInfo, byteOrder, values);
-            gpsDirectory.removeField(GpsTagConstants.GPS_LONGITUDE.tagInfo);
-            gpsDirectory.add(longitudeField);
+
+            gpsDirectory.removeField(GpsTagConstants.GPS_TAG_GPS_LONGITUDE);
+            gpsDirectory.add(GpsTagConstants.GPS_TAG_GPS_DEST_LONGITUDE,
+                    RationalNumberUtilities.getRationalNumber(longitudeDegrees),
+                    RationalNumberUtilities.getRationalNumber(longitudeMinutes),
+                    RationalNumberUtilities.getRationalNumber(longitudeSeconds));
         }
 
         {
@@ -198,15 +187,12 @@ public final class TiffOutputSet impleme
             value %= 1;
             value *= 60.0;
             double latitudeSeconds = value;
-            Double values[] = {
-                    new Double(latitudeDegrees), new Double(latitudeMinutes),
-                    new Double(latitudeSeconds),
-            };
-
-            TiffOutputField latitudeField = TiffOutputField.create(
-                    GpsTagConstants.GPS_LATITUDE.tagInfo, byteOrder, values);
-            gpsDirectory.removeField(GpsTagConstants.GPS_LATITUDE.tagInfo);
-            gpsDirectory.add(latitudeField);
+
+            gpsDirectory.removeField(GpsTagConstants.GPS_TAG_GPS_LATITUDE);
+            gpsDirectory.add(GpsTagConstants.GPS_TAG_GPS_LATITUDE,
+                    RationalNumberUtilities.getRationalNumber(latitudeDegrees),
+                    RationalNumberUtilities.getRationalNumber(latitudeMinutes),
+                    RationalNumberUtilities.getRationalNumber(latitudeSeconds));
         }
 
     }
@@ -247,7 +233,7 @@ public final class TiffOutputSet impleme
     public TiffOutputDirectory addRootDirectory() throws ImageWriteException
     {
         TiffOutputDirectory result = new TiffOutputDirectory(
-                DIRECTORY_TYPE_ROOT);
+                DIRECTORY_TYPE_ROOT, byteOrder);
         addDirectory(result);
         return result;
     }
@@ -255,14 +241,14 @@ public final class TiffOutputSet impleme
     public TiffOutputDirectory addExifDirectory() throws ImageWriteException
     {
         TiffOutputDirectory result = new TiffOutputDirectory(
-                DIRECTORY_TYPE_EXIF);
+                DIRECTORY_TYPE_EXIF, byteOrder);
         addDirectory(result);
         return result;
     }
 
     public TiffOutputDirectory addGPSDirectory() throws ImageWriteException
     {
-        TiffOutputDirectory result = new TiffOutputDirectory(DIRECTORY_TYPE_GPS);
+        TiffOutputDirectory result = new TiffOutputDirectory(DIRECTORY_TYPE_GPS, byteOrder);
         addDirectory(result);
         return result;
     }
@@ -273,7 +259,7 @@ public final class TiffOutputSet impleme
         getOrCreateExifDirectory();
 
         TiffOutputDirectory result = new TiffOutputDirectory(
-                DIRECTORY_TYPE_INTEROPERABILITY);
+                DIRECTORY_TYPE_INTEROPERABILITY, byteOrder);
         addDirectory(result);
         return result;
     }

Modified: commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/examples/MetadataExample.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/examples/MetadataExample.java?rev=1245871&r1=1245870&r2=1245871&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/examples/MetadataExample.java
(original)
+++ commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/examples/MetadataExample.java
Sat Feb 18 06:43:33 2012
@@ -29,9 +29,9 @@ import org.apache.commons.sanselan.forma
 import org.apache.commons.sanselan.formats.tiff.TiffImageMetadata;
 import org.apache.commons.sanselan.formats.tiff.constants.ExifTagConstants;
 import org.apache.commons.sanselan.formats.tiff.constants.GpsTagConstants;
-import org.apache.commons.sanselan.formats.tiff.constants.TagInfo;
 import org.apache.commons.sanselan.formats.tiff.constants.TiffConstants;
 import org.apache.commons.sanselan.formats.tiff.constants.TiffTagConstants;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfo;
 
 public class MetadataExample
 {
@@ -58,20 +58,20 @@ public class MetadataExample
             System.out.println("file: " + file.getPath());
 
             // print out various interesting EXIF tags.
-            printTagValue(jpegMetadata, TiffTagConstants.XRESOLUTION.tagInfo);
-            printTagValue(jpegMetadata, TiffTagConstants.DATE_TIME.tagInfo);
+            printTagValue(jpegMetadata, TiffTagConstants.TIFF_TAG_XRESOLUTION);
+            printTagValue(jpegMetadata, TiffTagConstants.TIFF_TAG_DATE_TIME);
             printTagValue(jpegMetadata,
-                    ExifTagConstants.DATE_TIME_ORIGINAL.tagInfo);
-            printTagValue(jpegMetadata, ExifTagConstants.CREATE_DATE.tagInfo);
-            printTagValue(jpegMetadata, ExifTagConstants.ISO.tagInfo);
+                    ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
+            printTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_CREATE_DATE);
+            printTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_ISO);
             printTagValue(jpegMetadata,
-                    ExifTagConstants.SHUTTER_SPEED_VALUE.tagInfo);
-            printTagValue(jpegMetadata, ExifTagConstants.APERTURE_VALUE.tagInfo);
-            printTagValue(jpegMetadata, ExifTagConstants.BRIGHTNESS_VALUE.tagInfo);
-            printTagValue(jpegMetadata, GpsTagConstants.GPS_LATITUDE_REF.tagInfo);
-            printTagValue(jpegMetadata, GpsTagConstants.GPS_LATITUDE.tagInfo);
-            printTagValue(jpegMetadata, GpsTagConstants.GPS_LONGITUDE_REF.tagInfo);
-            printTagValue(jpegMetadata, GpsTagConstants.GPS_LONGITUDE.tagInfo);
+                    ExifTagConstants.EXIF_TAG_SHUTTER_SPEED_VALUE);
+            printTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_APERTURE_VALUE);
+            printTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_BRIGHTNESS_VALUE);
+            printTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF);
+            printTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE);
+            printTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF);
+            printTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE);
 
             System.out.println();
 
@@ -94,13 +94,13 @@ public class MetadataExample
 
             // more specific example of how to manually access GPS values
             TiffField gpsLatitudeRefField = jpegMetadata
-                    .findEXIFValueWithExactMatch(GpsTagConstants.GPS_LATITUDE_REF.tagInfo);
+                    .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF);
             TiffField gpsLatitudeField = jpegMetadata
-                    .findEXIFValueWithExactMatch(GpsTagConstants.GPS_LATITUDE.tagInfo);
+                    .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE);
             TiffField gpsLongitudeRefField = jpegMetadata
-                    .findEXIFValueWithExactMatch(GpsTagConstants.GPS_LONGITUDE_REF.tagInfo);
+                    .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF);
             TiffField gpsLongitudeField = jpegMetadata
-                    .findEXIFValueWithExactMatch(GpsTagConstants.GPS_LONGITUDE.tagInfo);
+                    .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE);
             if (gpsLatitudeRefField != null && gpsLatitudeField != null
                     && gpsLongitudeRefField != null
                     && gpsLongitudeField != null)

Modified: commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/examples/WriteExifMetadataExample.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/examples/WriteExifMetadataExample.java?rev=1245871&r1=1245870&r2=1245871&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/examples/WriteExifMetadataExample.java
(original)
+++ commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/examples/WriteExifMetadataExample.java
Sat Feb 18 06:43:33 2012
@@ -26,6 +26,7 @@ import org.apache.commons.sanselan.Image
 import org.apache.commons.sanselan.ImageWriteException;
 import org.apache.commons.sanselan.Sanselan;
 import org.apache.commons.sanselan.common.IImageMetadata;
+import org.apache.commons.sanselan.common.RationalNumber;
 import org.apache.commons.sanselan.formats.jpeg.JpegImageMetadata;
 import org.apache.commons.sanselan.formats.jpeg.exif.ExifRewriter;
 import org.apache.commons.sanselan.formats.tiff.TiffImageMetadata;
@@ -125,16 +126,13 @@ public class WriteExifMetadataExample
                 // see
                 // org.apache.commons.sanselan.formats.tiff.constants.AllTagConstants
                 //
-                TiffOutputField aperture = TiffOutputField.create(
-                        ExifTagConstants.APERTURE_VALUE.tagInfo,
-                        outputSet.byteOrder, new Double(0.3));
                 TiffOutputDirectory exifDirectory = outputSet
                         .getOrCreateExifDirectory();
                 // make sure to remove old value if present (this method will
                 // not fail if the tag does not exist).
                 exifDirectory
-                        .removeField(ExifTagConstants.APERTURE_VALUE.tagInfo);
-                exifDirectory.add(aperture);
+                        .removeField(ExifTagConstants.EXIF_TAG_APERTURE_VALUE);
+                exifDirectory.add(ExifTagConstants.EXIF_TAG_APERTURE_VALUE, RationalNumber.factoryMethod(3,
10));
             }
 
             {
@@ -232,7 +230,7 @@ public class WriteExifMetadataExample
                 // Note that this approach is crude: Exif data is organized in
                 // directories. The same tag/field may appear in more than one
                 // directory, and have different meanings in each.
-                outputSet.removeField(ExifTagConstants.APERTURE_VALUE.tagInfo);
+                outputSet.removeField(ExifTagConstants.EXIF_TAG_APERTURE_VALUE);
 
                 // Option 2: precision
                 // We know the exact directory the tag should appear in, in this
@@ -246,7 +244,7 @@ public class WriteExifMetadataExample
                         .getExifDirectory();
                 if (null != exifDirectory)
                     exifDirectory
-                            .removeField(ExifTagConstants.APERTURE_VALUE.tagInfo);
+                            .removeField(ExifTagConstants.EXIF_TAG_APERTURE_VALUE);
             }
 
             os = new FileOutputStream(dst);

Modified: commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/formats/jpeg/exif/AsciiFieldTest.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/formats/jpeg/exif/AsciiFieldTest.java?rev=1245871&r1=1245870&r2=1245871&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/formats/jpeg/exif/AsciiFieldTest.java
(original)
+++ commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/formats/jpeg/exif/AsciiFieldTest.java
Sat Feb 18 06:43:33 2012
@@ -59,9 +59,9 @@ public class AsciiFieldTest extends Exif
         }
 
         Map expectedFieldValues = new Hashtable();
-        expectedFieldValues.put(new Integer(ExifTagConstants.MAKE.tagInfo.tag), "Canon");
-        expectedFieldValues.put(new Integer(ExifTagConstants.MODEL.tagInfo.tag), "Canon PowerShot
SD750");
-        expectedFieldValues.put(new Integer(ExifTagConstants.MODIFY_DATE.tagInfo.tag), "2007:12:25
13:34:39");
+        expectedFieldValues.put(new Integer(ExifTagConstants.EXIF_TAG_MAKE.tag), "Canon");
+        expectedFieldValues.put(new Integer(ExifTagConstants.EXIF_TAG_MODEL.tag), "Canon
PowerShot SD750");
+        expectedFieldValues.put(new Integer(ExifTagConstants.EXIF_TAG_MODIFY_DATE.tag), "2007:12:25
13:34:39");
         Iterator expectedTags = expectedFieldValues.keySet().iterator();
         while (expectedTags.hasNext()) {
             Integer tag = (Integer) expectedTags.next();

Modified: commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/formats/jpeg/exif/MakerNoteFieldTest.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/formats/jpeg/exif/MakerNoteFieldTest.java?rev=1245871&r1=1245870&r2=1245871&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/formats/jpeg/exif/MakerNoteFieldTest.java
(original)
+++ commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/formats/jpeg/exif/MakerNoteFieldTest.java
Sat Feb 18 06:43:33 2012
@@ -36,7 +36,7 @@ public class MakerNoteFieldTest extends 
     protected void checkField(File imageFile, TiffField field)
             throws IOException, ImageReadException, ImageWriteException
     {
-        if (field.tag != ExifTagConstants.MAKER_NOTE.tagInfo.tag)
+        if (field.tag != ExifTagConstants.EXIF_TAG_MAKER_NOTE.tag)
         {
             //            if (field.tag == EXIF_TAG_EXIF_OFFSET.tag)
             //                ;

Modified: commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/formats/jpeg/exif/TextFieldTest.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/formats/jpeg/exif/TextFieldTest.java?rev=1245871&r1=1245870&r2=1245871&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/formats/jpeg/exif/TextFieldTest.java
(original)
+++ commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/formats/jpeg/exif/TextFieldTest.java
Sat Feb 18 06:43:33 2012
@@ -38,12 +38,12 @@ public class TextFieldTest extends Speci
     protected void checkField(File imageFile, TiffField field)
             throws IOException, ImageReadException, ImageWriteException
     {
-        if (field.tag == ExifTagConstants.USER_COMMENT.tagInfo.tag)
+        if (field.tag == ExifTagConstants.EXIF_TAG_USER_COMMENT.tag)
         { /* do nothing */ }
-        else if (field.tag == GpsTagConstants.GPS_PROCESSING_METHOD.tagInfo.tag
+        else if (field.tag == GpsTagConstants.GPS_TAG_GPS_PROCESSING_METHOD.tag
                 && field.directoryType == TiffDirectoryType.EXIF_DIRECTORY_GPS.directoryType)
         { /* do nothing */ }
-        else if (field.tag == GpsTagConstants.GPS_AREA_INFORMATION.tagInfo.tag
+        else if (field.tag == GpsTagConstants.GPS_TAG_GPS_AREA_INFORMATION.tag
                 && field.directoryType == TiffDirectoryType.EXIF_DIRECTORY_GPS.directoryType)
         { /* do nothing */ }
         else

Added: commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/formats/tiff/TiffTagIntegrityTest.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/formats/tiff/TiffTagIntegrityTest.java?rev=1245871&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/formats/tiff/TiffTagIntegrityTest.java
(added)
+++ commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/formats/tiff/TiffTagIntegrityTest.java
Sat Feb 18 06:43:33 2012
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.sanselan.formats.tiff;
+
+import java.lang.reflect.Field;
+import java.util.List;
+
+import org.apache.commons.sanselan.SanselanTest;
+import org.apache.commons.sanselan.formats.tiff.constants.ExifTagConstants;
+import org.apache.commons.sanselan.formats.tiff.constants.GpsTagConstants;
+import org.apache.commons.sanselan.formats.tiff.constants.TiffTagConstants;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfo;
+
+public class TiffTagIntegrityTest extends SanselanTest {
+    public void testTagIntegrity() {
+        verifyFields(TiffTagConstants.class, TiffTagConstants.ALL_TIFF_TAGS);
+        verifyFields(GpsTagConstants.class, GpsTagConstants.ALL_GPS_TAGS);
+        verifyFields(ExifTagConstants.class, ExifTagConstants.ALL_EXIF_TAGS);
+    }
+    
+    private void verifyFields(Class<?> cls, List<TagInfo> tags) {
+        Field[] fields = cls.getFields();
+        int tagCount = 0;
+        int foundCount = 0;
+        for (Field field : fields) {
+            field.setAccessible(true);
+            if (!(field.getType().isInstance(TagInfo.class))) {
+                continue;
+            }
+            ++tagCount;
+            TagInfo src = null;
+            try {
+                src = (TagInfo) field.get(null);
+            } catch (IllegalAccessException illegalAccess) {
+            }
+            if (src == null) {
+                continue;
+            }
+            for (int i = 0; i < tags.size(); i++) {
+                TagInfo tagInfo = tags.get(i);
+                if (tagInfo.tag == src.tag) {
+                    ++foundCount;
+                    break;
+                }
+            }
+        }
+        assertEquals(tagCount, foundCount);
+    }
+}

Propchange: commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/formats/tiff/TiffTagIntegrityTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message