Class: FormatParser::CR3Parser

Inherits:
Object
  • Object
show all
Includes:
IOUtils
Defined in:
lib/parsers/cr3_parser.rb

Defined Under Namespace

Classes: Decoder

Constant Summary collapse

CR3_MIME_TYPE =
'image/x-canon-cr3'
MAGIC_BYTES =
'ftypcrx '

Constants included from IOUtils

IOUtils::INTEGER_DIRECTIVES

Instance Method Summary collapse

Methods included from IOUtils

#read_bytes, #read_fixed_point, #read_int, #safe_read, #safe_skip, #skip_bytes

Instance Method Details

#call(io) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/parsers/cr3_parser.rb', line 12

def call(io)
  @buf = FormatParser::IOConstraint.new(io)

  return unless matches_cr3_definition?

  box_tree = Measurometer.instrument('format_parser.cr3_parser.decoder.build_box_tree') do
    Decoder.new.build_box_tree(0xffffffff, @buf)
  end
  moov_box = box_tree.find { |box| box.type == 'moov' }
  cmt1_box = moov_box&.first_descendent('CMT1')
  return unless cmt1_box

  width = cmt1_box.fields[:image_width]
  height = cmt1_box.fields[:image_length]
  rotated = cmt1_box.fields[:rotated]
  orientation = cmt1_box.fields[:orientation_sym]
  FormatParser::Image.new(
    format: :cr3,
    content_type: CR3_MIME_TYPE,
    width_px: width,
    height_px: height,
    orientation: orientation,
    display_width_px: rotated ? height : width,
    display_height_px: rotated ? width : height,
    intrinsics: {
      box_tree: box_tree,
      exif: cmt1_box.fields,
    },
  )
end

#likely_match?(filename) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/parsers/cr3_parser.rb', line 8

def likely_match?(filename)
  filename =~ /\.cr3$/i
end