Class: FormatParser::TIFFParser
- Inherits:
-
Object
- Object
- FormatParser::TIFFParser
show all
- Includes:
- EXIFParser, IOUtils
- Defined in:
- lib/parsers/tiff_parser.rb
Constant Summary
collapse
- MAGIC_LE =
[0x49, 0x49, 0x2A, 0x0].pack('C4')
- MAGIC_BE =
[0x4D, 0x4D, 0x0, 0x2A].pack('C4')
Constants included
from EXIFParser
EXIFParser::ORIENTATIONS, EXIFParser::ROTATED_ORIENTATIONS
Instance Method Summary
collapse
Methods included from EXIFParser
#exif_from_tiff_io
Methods included from IOUtils
#safe_read, #safe_skip
Instance Method Details
#call(io) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/parsers/tiff_parser.rb', line 8
def call(io)
io = FormatParser::IOConstraint.new(io)
return unless [MAGIC_LE, MAGIC_BE].include?(safe_read(io, 4))
io.seek(io.pos + 2) return if cr2?(io)
exif_data = exif_from_tiff_io(io)
return unless exif_data
w = exif_data.image_width
h = exif_data.image_length
FormatParser::Image.new(
format: :tif,
width_px: w,
height_px: h,
display_width_px: exif_data.rotated? ? h : w,
display_height_px: exif_data.rotated? ? w : h,
orientation: exif_data.orientation,
intrinsics: {exif: exif_data},
)
rescue EXIFR::MalformedTIFF
nil
end
|
#cr2?(io) ⇒ Boolean
37
38
39
40
|
# File 'lib/parsers/tiff_parser.rb', line 37
def cr2?(io)
io.seek(8)
safe_read(io, 2) == 'CR'
end
|