Class: FastImageParsing::IsoBmff

Inherits:
Object
  • Object
show all
Defined in:
lib/fastimage/fastimage_parsing/iso_bmff.rb

Overview

HEIC/AVIF are a special case of the general ISO_BMFF format, in which all data is encapsulated in typed boxes, with a mandatory ftyp box that is used to indicate particular file types. Is composed of nested “boxes”. Each box has a header composed of

  • Size (32 bit integer)

  • Box type (4 chars)

  • Extended size: only if size === 1, the type field is followed by 64 bit integer of extended size

  • Payload: Type-dependent

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ IsoBmff

Returns a new instance of IsoBmff.



12
13
14
15
16
# File 'lib/fastimage/fastimage_parsing/iso_bmff.rb', line 12

def initialize(stream)
  @stream = stream
  @width, @height = nil
  parse_isobmff
end

Instance Attribute Details

#heightObject (readonly)

:nodoc:



10
11
12
# File 'lib/fastimage/fastimage_parsing/iso_bmff.rb', line 10

def height
  @height
end

#widthObject (readonly)

:nodoc:



10
11
12
# File 'lib/fastimage/fastimage_parsing/iso_bmff.rb', line 10

def width
  @width
end

Instance Method Details

#parse_isobmffObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fastimage/fastimage_parsing/iso_bmff.rb', line 18

def parse_isobmff
  @rotation = 0
  @max_size = nil
  @primary_box = nil
  @ipma_boxes = []
  @ispe_boxes = []
  @final_size = nil

  catch :finish do
    read_boxes!
  end

  if [90, 270].include?(@rotation)
    @final_size.reverse!
  end
  
  @width, @height = @final_size
end