degal/exif_data.py
branchnew-exif
changeset 106 a4f605bd122c
parent 105 effae6f38749
--- a/degal/exif_data.py	Sat Jun 13 20:59:53 2009 +0300
+++ b/degal/exif_data.py	Sat Jun 13 22:22:04 2009 +0300
@@ -151,6 +151,21 @@
 
         return self.values_func(values)
 
+class IFDTag (Tag) :
+    """
+        A tag that references another IFD
+    """
+
+    def __init__ (self, name, ifd_tags=None) :
+        """
+            A tag that points to another IFD block. `ifd_tags`, if given, lists the tags for that block, otherwise,
+            the same tags as for the current block are used.
+        """
+
+        super(IFDTag, self).__init__(name)
+
+        self.ifd_tags = ifd_tags
+
 USER_COMMENT_CHARSETS = {
     'ASCII':    ('ascii',   'replace'   ),
     'JIS':      ('jis',     'error'     ),
@@ -191,6 +206,48 @@
 #   XXX: or does it?
 # SUB_IFD_MAGIC signifies that this IFD points to 
 # otherwise, the value is left as-is.
+# interoperability tags
+INTR_TAGS = {
+    0x0001: Tag('InteroperabilityIndex'),
+    0x0002: Tag('InteroperabilityVersion'),
+    0x1000: Tag('RelatedImageFileFormat'),
+    0x1001: Tag('RelatedImageWidth'),
+    0x1002: Tag('RelatedImageLength'),
+    }
+
+# GPS tags (not used yet, haven't seen camera with GPS)
+GPS_TAGS = {
+    0x0000: Tag('GPSVersionID'),
+    0x0001: Tag('GPSLatitudeRef'),
+    0x0002: Tag('GPSLatitude'),
+    0x0003: Tag('GPSLongitudeRef'),
+    0x0004: Tag('GPSLongitude'),
+    0x0005: Tag('GPSAltitudeRef'),
+    0x0006: Tag('GPSAltitude'),
+    0x0007: Tag('GPSTimeStamp'),
+    0x0008: Tag('GPSSatellites'),
+    0x0009: Tag('GPSStatus'),
+    0x000A: Tag('GPSMeasureMode'),
+    0x000B: Tag('GPSDOP'),
+    0x000C: Tag('GPSSpeedRef'),
+    0x000D: Tag('GPSSpeed'),
+    0x000E: Tag('GPSTrackRef'),
+    0x000F: Tag('GPSTrack'),
+    0x0010: Tag('GPSImgDirectionRef'),
+    0x0011: Tag('GPSImgDirection'),
+    0x0012: Tag('GPSMapDatum'),
+    0x0013: Tag('GPSDestLatitudeRef'),
+    0x0014: Tag('GPSDestLatitude'),
+    0x0015: Tag('GPSDestLongitudeRef'),
+    0x0016: Tag('GPSDestLongitude'),
+    0x0017: Tag('GPSDestBearingRef'),
+    0x0018: Tag('GPSDestBearing'),
+    0x0019: Tag('GPSDestDistanceRef'),
+    0x001A: Tag('GPSDestDistance'),
+    0x001D: Tag('GPSDate'),
+    }
+
+
 EXIF_TAGS = {
     0x0100: Tag('ImageWidth'),
     0x0101: Tag('ImageLength'),
@@ -280,7 +337,7 @@
     0x829A: Tag('ExposureTime'),
     0x829D: Tag('FNumber'),
     0x83BB: Tag('IPTC/NAA'),
-    0x8769: Tag('ExifOffset'),
+    0x8769: IFDTag('ExifOffset', None),
     0x8773: Tag('InterColorProfile'),
     0x8822: TagDict('ExposureProgram',
              {0: 'Unidentified',
@@ -293,7 +350,7 @@
               7: 'Portrait Mode',
               8: 'Landscape Mode'}),
     0x8824: Tag('SpectralSensitivity'),
-    0x8825: Tag('GPSInfo'),
+    0x8825: IFDTag('GPSInfo', GPS_TAGS),
     0x8827: Tag('ISOSpeedRatings'),
     0x8828: Tag('OECF'),
     0x9000: Tag('ExifVersion'),
@@ -376,7 +433,7 @@
               65535: 'Uncalibrated'}),
     0xA002: Tag('ExifImageWidth'),
     0xA003: Tag('ExifImageLength'),
-    0xA005: Tag('InteroperabilityOffset'),
+    0xA005: IFDTag('InteroperabilityOffset', INTR_TAGS),
     0xA20B: Tag('FlashEnergy'),               # 0x920B in TIFF/EP
     0xA20C: Tag('SpatialFrequencyResponse'),  # 0x920C
     0xA20E: Tag('FocalPlaneXResolution'),     # 0x920E
@@ -441,47 +498,6 @@
     0xEA1C:	('Padding', None),
     }
 
-# interoperability tags
-INTR_TAGS = {
-    0x0001: Tag('InteroperabilityIndex'),
-    0x0002: Tag('InteroperabilityVersion'),
-    0x1000: Tag('RelatedImageFileFormat'),
-    0x1001: Tag('RelatedImageWidth'),
-    0x1002: Tag('RelatedImageLength'),
-    }
-
-# GPS tags (not used yet, haven't seen camera with GPS)
-GPS_TAGS = {
-    0x0000: Tag('GPSVersionID'),
-    0x0001: Tag('GPSLatitudeRef'),
-    0x0002: Tag('GPSLatitude'),
-    0x0003: Tag('GPSLongitudeRef'),
-    0x0004: Tag('GPSLongitude'),
-    0x0005: Tag('GPSAltitudeRef'),
-    0x0006: Tag('GPSAltitude'),
-    0x0007: Tag('GPSTimeStamp'),
-    0x0008: Tag('GPSSatellites'),
-    0x0009: Tag('GPSStatus'),
-    0x000A: Tag('GPSMeasureMode'),
-    0x000B: Tag('GPSDOP'),
-    0x000C: Tag('GPSSpeedRef'),
-    0x000D: Tag('GPSSpeed'),
-    0x000E: Tag('GPSTrackRef'),
-    0x000F: Tag('GPSTrack'),
-    0x0010: Tag('GPSImgDirectionRef'),
-    0x0011: Tag('GPSImgDirection'),
-    0x0012: Tag('GPSMapDatum'),
-    0x0013: Tag('GPSDestLatitudeRef'),
-    0x0014: Tag('GPSDestLatitude'),
-    0x0015: Tag('GPSDestLongitudeRef'),
-    0x0016: Tag('GPSDestLongitude'),
-    0x0017: Tag('GPSDestBearingRef'),
-    0x0018: Tag('GPSDestBearing'),
-    0x0019: Tag('GPSDestDistanceRef'),
-    0x001A: Tag('GPSDestDistance'),
-    0x001D: Tag('GPSDate'),
-    }
-
 # http://tomtia.plala.jp/DigitalCamera/MakerNote/index.asp
 def nikon_ev_bias (seq) :
     """