30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
# File 'lib/exifparser/scan.rb', line 30
def scan
tic = Time.now if $DEBUG
@fin.pos = 0
unless get_soi == 0xFFD8
raise RuntimeError, 'not JPEG format'
end
begin
marker = get_marker
break if (marker == 0xFFE1)
size = get_marker_datasize
@fin.seek(size - 2, IO::SEEK_CUR)
end while (!@fin.eof?)
if marker != 0xFFE1
raise RuntimeError, 'not EXIF format'
end
@result[:app1DataSize] = get_marker_datasize()
curpos = @fin.pos
@result[:app1Data] = fin_read_n(@result[:app1DataSize])
@fin.pos = curpos
if (h = exif_identifier()) !~ /\AExif\000/
raise RuntimeError, "Invalid EXIF header: #{h}"
end
@tiffHeader0, = ()
case [0,2]
when "MM"
@byteOrder_module = Utils::Decode::Motorola
when "II"
@byteOrder_module = Utils::Decode::Intel
else
raise RuntimeError, "Unknown byte order"
end
self.extend @byteOrder_module
@result[:offset_IFD0] = decode_ulong([4..-1])
@fin.pos = @tiffHeader0 + @result[:offset_IFD0]
@result[:IFD0] = []
scan_IFD(Tag::IFD0Table, Tag::IFD0Table.name) do |tag|
@result[:IFD0].push tag
end
@result[:IFD1] = []
next_ifd = decode_ulong(fin_read_n(4))
if next_ifd > 0
@fin.pos = @tiffHeader0 + next_ifd
scan_IFD(Tag::IFD1Table, Tag::IFD1Table.name) do |tag|
@result[:IFD1].push tag
end
end
@result[:GPS] = []
found = @result[:IFD0].find{ |e|
e.class == Tag::GPSIFDPointer
}
if found
@result[:offset_GPS] = found.processData
@fin.pos = @tiffHeader0 + @result[:offset_GPS]
scan_IFD(Tag::GPSIFDTable, Tag::GPSIFDTable.name) do |tag|
@result[:GPS].push tag
end
end
@result[:Exif] = []
found = @result[:IFD0].find{ |e|
e.class == Tag::ExifIFDPointer
}
if found
@result[:offset_Exif] = found.processData
@fin.pos = @tiffHeader0 + @result[:offset_Exif]
scan_IFD(Tag::ExifIFDTable, Tag::ExifIFDTable.name) do |tag|
@result[:Exif].push tag
end
end
@result[:Interoperability] = []
found = @result[:Exif].find {|e|
e.class == Tag::InteroperabilityIFDPointer
}
if found
@result[:offset_InteroperabilityIFD] = found.processData
@fin.pos = @tiffHeader0 + @result[:offset_InteroperabilityIFD]
scan_IFD(Tag::InteroperabilityIFDTable, Tag::InteroperabilityIFDTable.name) do |tag|
@result[:Interoperability].push tag
end
end
@result[:MakerNote]=[]
found = @result[:Exif].find {|e| e.class == Tag::Exif::MakerNote }
if (found)
begin
make = @result[:IFD0].find {|e| e.class == Tag::TIFF::Make}
model = @result[:IFD0].find {|e| e.class == Tag::TIFF::Model}
makernote_class = Exif::MakerNote.prove(found.data, make, model)
@fin.pos = found.pos
makernote = makernote_class.new(@fin, @tiffHeader0, found.dataPos, @byteOrder_module)
makernote.scan_IFD do |tag|
@result[:MakerNote].push tag
end
rescue MakerNote::NotSupportedError
rescue Exception if $DEBUG
raise $!
end
end
end
if !@result[:IFD1].empty?
format = @result[:IFD1].find do |e|
e.class == Tag::TIFF::Compression
end.value
unless format == 6
raise NotImplementedError, "Sorry, thumbnail of other than JPEG format is not supported."
end
thumbStart = @result[:IFD1].find do |e|
e.class == Exif::Tag::TIFF::JpegInterchangeFormat
end.value
thumbLen = @result[:IFD1].find do |e|
e.class == Exif::Tag::TIFF::JpegInterchangeFormatLength
end.value
@fin.pos = @tiffHeader0 + thumbStart
if get_soi != 0xFFD8
raise RuntimeError, 'not JPEG format'
end
@fin.pos = @fin.pos - 2
@result[:Thumbnail] = @fin.read(thumbLen)
end
toc = Time.now if $DEBUG
puts(sprintf("scan time: %1.4f sec.", toc-tic)) if $DEBUG
end
|