1 | #if 0 |
---|
2 | # ----------------------------------------------------------------------- |
---|
3 | # $Id: tiffinfo.py,v 1.11 2004/05/20 15:56:31 dischi Exp $ |
---|
4 | # ----------------------------------------------------------------------- |
---|
5 | # $Log: tiffinfo.py,v $ |
---|
6 | # Revision 1.11 2004/05/20 15:56:31 dischi |
---|
7 | # use Python Imaging for more info and gif/bmp support |
---|
8 | # |
---|
9 | # Revision 1.10 2003/06/30 13:17:20 the_krow |
---|
10 | # o Refactored mediainfo into factory, synchronizedobject |
---|
11 | # o Parsers now register directly at mmpython not at mmpython.mediainfo |
---|
12 | # o use mmpython.Factory() instead of mmpython.mediainfo.get_singleton() |
---|
13 | # o Bugfix in PNG parser |
---|
14 | # o Renamed disc.AudioInfo into disc.AudioDiscInfo |
---|
15 | # o Renamed disc.DataInfo into disc.DataDiscInfo |
---|
16 | # |
---|
17 | # Revision 1.9 2003/06/20 19:17:22 dischi |
---|
18 | # remove filename again and use file.name |
---|
19 | # |
---|
20 | # Revision 1.8 2003/06/09 16:11:57 the_krow |
---|
21 | # TIFF parser changed to new tables structure |
---|
22 | # debug statements removed / changed to _debug |
---|
23 | # |
---|
24 | # Revision 1.7 2003/06/08 19:55:22 dischi |
---|
25 | # added bins metadata support |
---|
26 | # |
---|
27 | # Revision 1.6 2003/06/08 13:44:58 dischi |
---|
28 | # Changed all imports to use the complete mmpython path for mediainfo |
---|
29 | # |
---|
30 | # Revision 1.5 2003/06/08 13:11:51 dischi |
---|
31 | # removed print at the end and moved it into register |
---|
32 | # |
---|
33 | # Revision 1.4 2003/05/13 15:52:43 the_krow |
---|
34 | # Caption added |
---|
35 | # |
---|
36 | # Revision 1.3 2003/05/13 15:23:59 the_krow |
---|
37 | # IPTC |
---|
38 | # |
---|
39 | # Revision 1.2 2003/05/13 15:16:02 the_krow |
---|
40 | # width+height hacked |
---|
41 | # |
---|
42 | # Revision 1.1 2003/05/13 15:00:23 the_krow |
---|
43 | # Tiff parsing |
---|
44 | # |
---|
45 | # ----------------------------------------------------------------------- |
---|
46 | # |
---|
47 | # MMPython - Media Metadata for Python |
---|
48 | # Copyright (C) 2003 Thomas Schueppel |
---|
49 | # |
---|
50 | # This program is free software; you can redistribute it and/or modify |
---|
51 | # it under the terms of the GNU General Public License as published by |
---|
52 | # the Free Software Foundation; either version 2 of the License, or |
---|
53 | # (at your option) any later version. |
---|
54 | # |
---|
55 | # This program is distributed in the hope that it will be useful, but |
---|
56 | # WITHOUT ANY WARRANTY; without even the implied warranty of MER- |
---|
57 | # CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
---|
58 | # Public License for more details. |
---|
59 | # |
---|
60 | # You should have received a copy of the GNU General Public License along |
---|
61 | # with this program; if not, write to the Free Software Foundation, Inc., |
---|
62 | # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
63 | # |
---|
64 | # ----------------------------------------------------------------------- |
---|
65 | #endif |
---|
66 | |
---|
67 | from mmpython import mediainfo |
---|
68 | import mmpython |
---|
69 | import IPTC |
---|
70 | import EXIF |
---|
71 | import struct |
---|
72 | import ImageInfo |
---|
73 | |
---|
74 | MOTOROLASIGNATURE = 'MM\x00\x2a' |
---|
75 | INTELSIGNATURE = 'II\x2a\x00' |
---|
76 | |
---|
77 | # http://partners.adobe.com/asn/developer/pdfs/tn/TIFF6.pdf |
---|
78 | |
---|
79 | _debug = mediainfo._debug |
---|
80 | |
---|
81 | class TIFFInfo(mediainfo.ImageInfo): |
---|
82 | |
---|
83 | def __init__(self,file): |
---|
84 | mediainfo.ImageInfo.__init__(self) |
---|
85 | self.iptc = None |
---|
86 | self.mime = 'image/tiff' |
---|
87 | self.type = 'TIFF image' |
---|
88 | self.intel = 0 |
---|
89 | self.valid = 0 |
---|
90 | iptc = {} |
---|
91 | header = file.read(8) |
---|
92 | if header[:4] == MOTOROLASIGNATURE: |
---|
93 | self.valid = 1 |
---|
94 | self.intel = 0 |
---|
95 | (offset,) = struct.unpack(">I", header[4:8]) |
---|
96 | file.seek(offset) |
---|
97 | (len,) = struct.unpack(">H", file.read(2)) |
---|
98 | app = file.read(len*12) |
---|
99 | for i in range(len): |
---|
100 | (tag, type, length, value, offset) = struct.unpack('>HHIHH', app[i*12:i*12+12]) |
---|
101 | _debug("[%i/%i] tag: 0x%.4x, type 0x%.4x, len %d, value %d, offset %d)" % (i,len,tag,type,length,value,offset)) |
---|
102 | if tag == 0x8649: |
---|
103 | file.seek(offset,0) |
---|
104 | iptc = IPTC.flatten(IPTC.parseiptc(file.read(1000))) |
---|
105 | elif tag == 0x0100: |
---|
106 | if value != 0: |
---|
107 | self.width = value |
---|
108 | else: |
---|
109 | self.width = offset |
---|
110 | elif tag == 0x0101: |
---|
111 | if value != 0: |
---|
112 | self.height = value |
---|
113 | else: |
---|
114 | self.height = offset |
---|
115 | |
---|
116 | elif header[:4] == INTELSIGNATURE: |
---|
117 | self.valid = 1 |
---|
118 | self.intel = 1 |
---|
119 | (offset,) = struct.unpack("<I", header[4:8]) |
---|
120 | file.seek(offset,0) |
---|
121 | (len,) = struct.unpack("<H", file.read(2)) |
---|
122 | app = file.read(len*12) |
---|
123 | for i in range(len): |
---|
124 | (tag, type, length, offset, value) = struct.unpack('<HHIHH', app[i*12:i*12+12]) |
---|
125 | _debug("[%i/%i] tag: 0x%.4x, type 0x%.4x, len %d, value %d, offset %d)" % (i,len,tag,type,length,value,offset)) |
---|
126 | if tag == 0x8649: |
---|
127 | file.seek(offset) |
---|
128 | iptc = IPTC.flatten(IPTC.parseiptc(file.read(1000))) |
---|
129 | elif tag == 0x0100: |
---|
130 | if value != 0: |
---|
131 | self.width = value |
---|
132 | else: |
---|
133 | self.width = offset |
---|
134 | elif tag == 0x0101: |
---|
135 | if value != 0: |
---|
136 | self.height = value |
---|
137 | else: |
---|
138 | self.height = offset |
---|
139 | else: |
---|
140 | ImageInfo.add(file.name, self) |
---|
141 | return |
---|
142 | |
---|
143 | if iptc: |
---|
144 | self.setitem( 'title', iptc, 517 ) |
---|
145 | self.setitem( 'date' , iptc, 567 ) |
---|
146 | self.setitem( 'comment', iptc, 617 ) |
---|
147 | self.setitem( 'keywords', iptc, 537 ) |
---|
148 | self.setitem( 'artist', iptc, 592 ) |
---|
149 | self.setitem( 'country', iptc, 612 ) |
---|
150 | self.setitem( 'caption', iptc, 632 ) |
---|
151 | self.appendtable('IPTC', iptc) |
---|
152 | |
---|
153 | ImageInfo.add(file.name, self) |
---|
154 | return |
---|
155 | |
---|
156 | |
---|
157 | mmpython.registertype( 'image/tiff', ('tif','tiff'), mediainfo.TYPE_IMAGE, TIFFInfo ) |
---|