Back to index

plone3  3.1.7
Classes | Functions | Variables
exif Namespace Reference

Classes

class  Ratio
class  IFD_Tag
class  EXIF_header

Functions

def olympus_special_mode
def s2n_motorola
def s2n_intel
def gcd
def process_file

Variables

tuple LOG = logging.getLogger('exif')
tuple FIELD_TYPES
dictionary EXIF_TAGS
dictionary INTR_TAGS
dictionary GPS_TAGS
dictionary MAKERNOTE_NIKON_NEWER_TAGS
dictionary MAKERNOTE_NIKON_OLDER_TAGS
tuple start_time = time.clock()
tuple start = len(gc.get_objects())
tuple file = open(filename, 'rb')
tuple data = process_file(file)
tuple x = data.keys()
tuple end_time = time.clock()
 duration = end_time-start_time
tuple end = len(gc.get_objects())

Class Documentation

class exif::Ratio

Definition at line 95 of file exif.py.

class exif::IFD_Tag

Definition at line 97 of file exif.py.


Function Documentation

def exif.gcd (   a,
  b 
)

Definition at line 724 of file exif.py.

00724 
00725 def gcd(a, b):
00726    if b == 0:
00727       return a
00728    else:
00729       return gcd(b, a % b)
00730 
# class that handles an EXIF header

Here is the caller graph for this function:

Definition at line 404 of file exif.py.

00404 
00405 def olympus_special_mode(v):
00406     a={
00407         0: 'Normal',
00408         1: 'Unknown',
00409         2: 'Fast',
00410         3: 'Panorama'}
00411     b={
00412         0: 'Non-panoramic',
00413         1: 'Left to right',
00414         2: 'Right to left',
00415         3: 'Bottom to top',
00416         4: 'Top to bottom'}
00417     return '%s - sequence %d - %s' % (a[v[0]], v[1], b[v[2]])
00418 
00419 MAKERNOTE_OLYMPUS_TAGS={
00420     # ah HAH! those sneeeeeaky bastids! this is how they get past the fact
00421     # that a JPEG thumbnail is not allowed in an uncompressed TIFF file
00422     0x0100: ('JPEGThumbnail', ),
00423     0x0200: ('SpecialMode', olympus_special_mode),
00424     0x0201: ('JPEGQual',
00425              {1: 'SQ',
00426               2: 'HQ',
00427               3: 'SHQ'}),
00428     0x0202: ('Macro',
00429              {0: 'Normal',
00430               1: 'Macro'}),
00431     0x0204: ('DigitalZoom', ),
00432     0x0207: ('SoftwareRelease',  ),
00433     0x0208: ('PictureInfo',  ),
00434     # print as string
00435     0x0209: ('CameraID', lambda x: ''.join(map(chr, x))),
00436     0x0F00: ('DataDump',  )
00437     }
00438 
00439 MAKERNOTE_CASIO_TAGS={
00440     0x0001: ('RecordingMode',
00441              {1: 'Single Shutter',
00442               2: 'Panorama',
00443               3: 'Night Scene',
00444               4: 'Portrait',
00445               5: 'Landscape'}),
00446     0x0002: ('Quality',
00447              {1: 'Economy',
00448               2: 'Normal',
00449               3: 'Fine'}),
00450     0x0003: ('FocusingMode',
00451              {2: 'Macro',
00452               3: 'Auto Focus',
00453               4: 'Manual Focus',
00454               5: 'Infinity'}),
00455     0x0004: ('FlashMode',
00456              {1: 'Auto',
00457               2: 'On',
00458               3: 'Off',
00459               4: 'Red Eye Reduction'}),
00460     0x0005: ('FlashIntensity',
00461              {11: 'Weak',
00462               13: 'Normal',
00463               15: 'Strong'}),
00464     0x0006: ('Object Distance', ),
00465     0x0007: ('WhiteBalance',
00466              {1:   'Auto',
00467               2:   'Tungsten',
00468               3:   'Daylight',
00469               4:   'Fluorescent',
00470               5:   'Shade',
00471               129: 'Manual'}),
00472     0x000B: ('Sharpness',
00473              {0: 'Normal',
00474               1: 'Soft',
00475               2: 'Hard'}),
00476     0x000C: ('Contrast',
00477              {0: 'Normal',
00478               1: 'Low',
00479               2: 'High'}),
00480     0x000D: ('Saturation',
00481              {0: 'Normal',
00482               1: 'Low',
00483               2: 'High'}),
00484     0x0014: ('CCDSpeed',
00485              {64:  'Normal',
00486               80:  'Normal',
00487               100: 'High',
00488               125: '+1.0',
00489               244: '+3.0',
00490               250: '+2.0',})
00491     }
00492 
00493 MAKERNOTE_FUJIFILM_TAGS={
00494     0x0000: ('NoteVersion', lambda x: ''.join(map(chr, x))),
00495     0x1000: ('Quality', ),
00496     0x1001: ('Sharpness',
00497              {1: 'Soft',
00498               2: 'Soft',
00499               3: 'Normal',
00500               4: 'Hard',
00501               5: 'Hard'}),
00502     0x1002: ('WhiteBalance',
00503              {0:    'Auto',
00504               256:  'Daylight',
00505               512:  'Cloudy',
00506               768:  'DaylightColor-Fluorescent',
00507               769:  'DaywhiteColor-Fluorescent',
00508               770:  'White-Fluorescent',
00509               1024: 'Incandescent',
00510               3840: 'Custom'}),
00511     0x1003: ('Color',
00512              {0:   'Normal',
00513               256: 'High',
00514               512: 'Low'}),
00515     0x1004: ('Tone',
00516              {0:   'Normal',
00517               256: 'High',
00518               512: 'Low'}),
00519     0x1010: ('FlashMode',
00520              {0: 'Auto',
00521               1: 'On',
00522               2: 'Off',
00523               3: 'Red Eye Reduction'}),
00524     0x1011: ('FlashStrength', ),
00525     0x1020: ('Macro',
00526              {0: 'Off',
00527               1: 'On'}),
00528     0x1021: ('FocusMode',
00529              {0: 'Auto',
00530               1: 'Manual'}),
00531     0x1030: ('SlowSync',
00532              {0: 'Off',
00533               1: 'On'}),
00534     0x1031: ('PictureMode',
00535              {0:   'Auto',
00536               1:   'Portrait',
00537               2:   'Landscape',
00538               4:   'Sports',
00539               5:   'Night',
00540               6:   'Program AE',
00541               256: 'Aperture Priority AE',
00542               512: 'Shutter Priority AE',
00543               768: 'Manual Exposure'}),
00544     0x1100: ('MotorOrBracket',
00545              {0: 'Off',
00546               1: 'On'}),
00547     0x1300: ('BlurWarning',
00548              {0: 'Off',
00549               1: 'On'}),
00550     0x1301: ('FocusWarning',
00551              {0: 'Off',
00552               1: 'On'}),
00553     0x1302: ('AEWarning',
00554              {0: 'Off',
00555               1: 'On'})
00556     }
00557 
00558 MAKERNOTE_CANON_TAGS={
00559     0x0006: ('ImageType', ),
00560     0x0007: ('FirmwareVersion', ),
00561     0x0008: ('ImageNumber', ),
00562     0x0009: ('OwnerName', )
00563     }
00564 
00565 # see http://www.burren.cx/david/canon.html by David Burren
00566 # this is in element offset, name, optional value dictionary format
00567 MAKERNOTE_CANON_TAG_0x001={
00568     1: ('Macromode',
00569         {1: 'Macro',
00570          2: 'Normal'}),
00571     2: ('SelfTimer', ),
00572     3: ('Quality',
00573         {2: 'Normal',
00574          3: 'Fine',
00575          5: 'Superfine'}),
00576     4: ('FlashMode',
00577         {0: 'Flash Not Fired',
00578          1: 'Auto',
00579          2: 'On',
00580          3: 'Red-Eye Reduction',
00581          4: 'Slow Synchro',
00582          5: 'Auto + Red-Eye Reduction',
00583          6: 'On + Red-Eye Reduction',
00584          16: 'external flash'}),
00585     5: ('ContinuousDriveMode',
00586         {0: 'Single Or Timer',
00587          1: 'Continuous'}),
00588     7: ('FocusMode',
00589         {0: 'One-Shot',
00590          1: 'AI Servo',
00591          2: 'AI Focus',
00592          3: 'MF',
00593          4: 'Single',
00594          5: 'Continuous',
00595          6: 'MF'}),
00596     10: ('ImageSize',
00597          {0: 'Large',
00598           1: 'Medium',
00599           2: 'Small'}),
00600     11: ('EasyShootingMode',
00601          {0: 'Full Auto',
00602           1: 'Manual',
00603           2: 'Landscape',
00604           3: 'Fast Shutter',
00605           4: 'Slow Shutter',
00606           5: 'Night',
00607           6: 'B&W',
00608           7: 'Sepia',
00609           8: 'Portrait',
00610           9: 'Sports',
00611           10: 'Macro/Close-Up',
00612           11: 'Pan Focus'}),
00613     12: ('DigitalZoom',
00614          {0: 'None',
00615           1: '2x',
00616           2: '4x'}),
00617     13: ('Contrast',
00618          {0xFFFF: 'Low',
00619           0: 'Normal',
00620           1: 'High'}),
00621     14: ('Saturation',
00622          {0xFFFF: 'Low',
00623           0: 'Normal',
00624           1: 'High'}),
00625     15: ('Sharpness',
00626          {0xFFFF: 'Low',
00627           0: 'Normal',
00628           1: 'High'}),
00629     16: ('ISO',
00630          {0: 'See ISOSpeedRatings Tag',
00631           15: 'Auto',
00632           16: '50',
00633           17: '100',
00634           18: '200',
00635           19: '400'}),
00636     17: ('MeteringMode',
00637          {3: 'Evaluative',
00638           4: 'Partial',
00639           5: 'Center-weighted'}),
00640     18: ('FocusType',
00641          {0: 'Manual',
00642           1: 'Auto',
00643           3: 'Close-Up (Macro)',
00644           8: 'Locked (Pan Mode)'}),
00645     19: ('AFPointSelected',
00646          {0x3000: 'None (MF)',
00647           0x3001: 'Auto-Selected',
00648           0x3002: 'Right',
00649           0x3003: 'Center',
00650           0x3004: 'Left'}),
00651     20: ('ExposureMode',
00652          {0: 'Easy Shooting',
00653           1: 'Program',
00654           2: 'Tv-priority',
00655           3: 'Av-priority',
00656           4: 'Manual',
00657           5: 'A-DEP'}),
00658     23: ('LongFocalLengthOfLensInFocalUnits', ),
00659     24: ('ShortFocalLengthOfLensInFocalUnits', ),
00660     25: ('FocalUnitsPerMM', ),
00661     28: ('FlashActivity',
00662          {0: 'Did Not Fire',
00663           1: 'Fired'}),
00664     29: ('FlashDetails',
00665          {14: 'External E-TTL',
00666           13: 'Internal Flash',
00667           11: 'FP Sync Used',
00668           7: '2nd("Rear")-Curtain Sync Used',
00669           4: 'FP Sync Enabled'}),
00670     32: ('FocusMode',
00671          {0: 'Single',
00672           1: 'Continuous'})
00673     }
00674 
00675 MAKERNOTE_CANON_TAG_0x004={
00676     7: ('WhiteBalance',
00677         {0: 'Auto',
00678          1: 'Sunny',
00679          2: 'Cloudy',
00680          3: 'Tungsten',
00681          4: 'Fluorescent',
00682          5: 'Flash',
00683          6: 'Custom'}),
00684     9: ('SequenceNumber', ),
00685     14: ('AFPointUsed', ),
00686     15: ('FlashBias',
00687         {0XFFC0: '-2 EV',
00688          0XFFCC: '-1.67 EV',
00689          0XFFD0: '-1.50 EV',
00690          0XFFD4: '-1.33 EV',
00691          0XFFE0: '-1 EV',
00692          0XFFEC: '-0.67 EV',
00693          0XFFF0: '-0.50 EV',
00694          0XFFF4: '-0.33 EV',
00695          0X0000: '0 EV',
00696          0X000C: '0.33 EV',
00697          0X0010: '0.50 EV',
00698          0X0014: '0.67 EV',
00699          0X0020: '1 EV',
00700          0X002C: '1.33 EV',
00701          0X0030: '1.50 EV',
00702          0X0034: '1.67 EV',
00703          0X0040: '2 EV'}),
00704     19: ('SubjectDistance', )
00705     }
00706 
# extract multibyte integer in Motorola format (little endian)
def exif.process_file (   file,
  debug = 0 
)

Definition at line 983 of file exif.py.

00983 
00984 def process_file(file, debug=0):
00985     data=file.read(12)
00986     if data[0:4] in ['II*\x00', 'MM\x00*']:
00987         # it's a TIFF file
00988         file.seek(0)
00989         endian=file.read(1)
00990         file.read(1)
00991         offset=0
00992         fake_exif=0
00993     elif data[0:2] == '\xFF\xD8':
00994         # it's a JPEG file
00995         # skip JFIF style header(s)
00996         fake_exif=0
00997         while data[2] == '\xFF' and data[6:10] in ('JFIF', 'JFXX', 'OLYM'):
00998             length=ord(data[4])*256+ord(data[5])
00999             file.read(length-8)
01000             # fake an EXIF beginning of file
01001             data='\xFF\x00'+file.read(10)
01002             fake_exif=1
01003         if data[2] == '\xFF' and data[6:10] == 'Exif':
01004             # detected EXIF header
01005             offset=file.tell()
01006             endian=file.read(1)
01007         else:
01008             # no EXIF information
01009             return {}
01010     else:
01011         # file format not recognized
01012         return {}
01013 
01014     # deal with the EXIF info we found
01015     if debug:
01016         print {'I': 'Intel', 'M': 'Motorola'}[endian], 'format'
01017     hdr=EXIF_header(file, endian, offset, fake_exif, debug)
01018     ifd_list=hdr.list_IFDs()
01019     ctr=0
01020     for i in ifd_list:
01021         if ctr == 0:
01022             IFD_name='Image'
01023         elif ctr == 1:
01024             IFD_name='Thumbnail'
01025             thumb_ifd=i
01026         else:
01027             IFD_name='IFD %d' % ctr
01028         if debug:
01029             print ' IFD %d (%s) at offset %d:' % (ctr, IFD_name, i)
01030         hdr.dump_IFD(i, IFD_name)
01031         # EXIF IFD
01032         exif_off=hdr.tags.get(IFD_name+' ExifOffset')
01033         if exif_off:
01034             if debug:
01035                 print ' EXIF SubIFD at offset %d:' % exif_off.values[0]
01036             hdr.dump_IFD(exif_off[0], 'EXIF')
01037             # Interoperability IFD contained in EXIF IFD
01038             intr_off=hdr.tags.get('EXIF SubIFD InteroperabilityOffset')
01039             if intr_off:
01040                 if debug:
01041                     print ' EXIF Interoperability SubSubIFD at offset %d:' \
01042                           % intr_off.values[0]
01043                 hdr.dump_IFD(intr_off.values[0], 'EXIF Interoperability',
01044                              dict=INTR_TAGS)
01045         # GPS IFD
01046         gps_off=hdr.tags.get(IFD_name+' GPSInfo')
01047         if gps_off:
01048             if debug:
01049                 print ' GPS SubIFD at offset %d:' % gps_off.values[0]
01050             hdr.dump_IFD(gps_off.values[0], 'GPS', dict=GPS_TAGS)
01051         ctr+=1
01052 
01053     if hdr.tags.has_key('EXIF MakerNote'):
01054         try:
01055             hdr.decode_maker_note()
01056         except:
01057             pass
01058         del hdr.tags['EXIF MakerNote']
01059     dict = {}
01060     tags = hdr.tags.keys()
01061     tags.sort()
01062     for tag in tags:
01063         hdr.tags[tag] = hdr.tags[tag][1]
01064     return hdr.tags
01065 
# library test/debug function (dump given files)

Here is the caller graph for this function:

def exif.s2n_intel (   str)

Definition at line 714 of file exif.py.

00714 
00715 def s2n_intel(str):
00716     x=0
00717     y=0L
00718     for c in str:
00719         x=x | (ord(c) << y)
00720         y=y+8
00721     return x
00722 
00723 # ratio object that eventually will be able to reduce itself to lowest
# common denominator for printing

Here is the caller graph for this function:

def exif.s2n_motorola (   str)

Definition at line 707 of file exif.py.

00707 
00708 def s2n_motorola(str):
00709     x=0
00710     for c in str:
00711         x=(x << 8) | ord(c)
00712     return x
00713 
# extract multibyte integer in Intel format (big endian)

Here is the caller graph for this function:


Variable Documentation

Definition at line 1088 of file exif.py.

Definition at line 1098 of file exif.py.

tuple exif.end = len(gc.get_objects())

Definition at line 1099 of file exif.py.

tuple exif.end_time = time.clock()

Definition at line 1097 of file exif.py.

dictionary exif.EXIF_TAGS

Definition at line 121 of file exif.py.

Initial value:
00001 (
00002     (0, 'X',  'Proprietary'), # no such type
00003     (1, 'B',  'Byte'),
00004     (1, 'A',  'ASCII'),
00005     (2, 'S',  'Short'),
00006     (4, 'L',  'Long'),
00007     (8, 'R',  'Ratio'),
00008     (1, 'SB', 'Signed Byte'),
00009     (1, 'U',  'Undefined'),
00010     (2, 'SS', 'Signed Short'),
00011     (4, 'SL', 'Signed Long'),
00012     (8, 'SR', 'Signed Ratio')
00013     )

Definition at line 104 of file exif.py.

tuple exif.file = open(filename, 'rb')

Definition at line 1081 of file exif.py.

dictionary exif.GPS_TAGS
Initial value:
00001 {
00002     0x0000: ('GPSVersionID', ),
00003     0x0001: ('GPSLatitudeRef', ),
00004     0x0002: ('GPSLatitude', ),
00005     0x0003: ('GPSLongitudeRef', ),
00006     0x0004: ('GPSLongitude', ),
00007     0x0005: ('GPSAltitudeRef', ),
00008     0x0006: ('GPSAltitude', ),
00009     0x0007: ('GPSTimeStamp', ),
00010     0x0008: ('GPSSatellites', ),
00011     0x0009: ('GPSStatus', ),
00012     0x000A: ('GPSMeasureMode', ),
00013     0x000B: ('GPSDOP', ),
00014     0x000C: ('GPSSpeedRef', ),
00015     0x000D: ('GPSSpeed', ),
00016     0x000E: ('GPSTrackRef', ),
00017     0x000F: ('GPSTrack', ),
00018     0x0010: ('GPSImgDirectionRef', ),
00019     0x0011: ('GPSImgDirection', ),
00020     0x0012: ('GPSMapDatum', ),
00021     0x0013: ('GPSDestLatitudeRef', ),
00022     0x0014: ('GPSDestLatitude', ),
00023     0x0015: ('GPSDestLongitudeRef', ),
00024     0x0016: ('GPSDestLongitude', ),
00025     0x0017: ('GPSDestBearingRef', ),
00026     0x0018: ('GPSDestBearing', ),
00027     0x0019: ('GPSDestDistanceRef', ),
00028     0x001A: ('GPSDestDistance', )
00029     }

Definition at line 280 of file exif.py.

dictionary exif.INTR_TAGS
Initial value:
00001 {
00002     0x0001: ('InteroperabilityIndex', ),
00003     0x0002: ('InteroperabilityVersion', ),
00004     0x1000: ('RelatedImageFileFormat', ),
00005     0x1001: ('RelatedImageWidth', ),
00006     0x1002: ('RelatedImageLength', ),
00007     }

Definition at line 271 of file exif.py.

tuple exif.LOG = logging.getLogger('exif')

Definition at line 101 of file exif.py.

Definition at line 312 of file exif.py.

Definition at line 371 of file exif.py.

tuple exif.start = len(gc.get_objects())

Definition at line 1072 of file exif.py.

tuple exif.start_time = time.clock()

Definition at line 1071 of file exif.py.

tuple exif.x = data.keys()

Definition at line 1093 of file exif.py.