Class: ZIMG::JPEG::Frame

Inherits:
Object
  • Object
show all
Defined in:
lib/zimg/jpeg/decoder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sof, qtables) ⇒ Frame

Returns a new instance of Frame.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/zimg/jpeg/decoder.rb', line 9

def initialize(sof, qtables)
  @width       = sof.width
  @height      = sof.height
  @progressive = sof.progressive?
  @components  = sof.components

  # According to the JPEG standard, the sampling factor must be between 1 and 4
  # See https://github.com/libjpeg-turbo/libjpeg-turbo/blob/9abeff46d87bd201a952e276f3e4339556a403a3/libjpeg.txt#L1138-L1146
  @max_h = components.map(&:h).max
  @max_v = components.map(&:v).max
  @mcus_per_line = (width / 8.0 / max_h).ceil
  @mcus_per_column = (height / 8.0 / max_v).ceil

  components.each do |c|
    c.prepare(self, qtables)
  end
end

Instance Attribute Details

#componentsObject

Returns the value of attribute components.



6
7
8
# File 'lib/zimg/jpeg/decoder.rb', line 6

def components
  @components
end

#heightObject

Returns the value of attribute height.



6
7
8
# File 'lib/zimg/jpeg/decoder.rb', line 6

def height
  @height
end

#max_hObject (readonly)

Returns the value of attribute max_h.



7
8
9
# File 'lib/zimg/jpeg/decoder.rb', line 7

def max_h
  @max_h
end

#max_vObject (readonly)

Returns the value of attribute max_v.



7
8
9
# File 'lib/zimg/jpeg/decoder.rb', line 7

def max_v
  @max_v
end

#mcus_per_columnObject (readonly)

Returns the value of attribute mcus_per_column.



7
8
9
# File 'lib/zimg/jpeg/decoder.rb', line 7

def mcus_per_column
  @mcus_per_column
end

#mcus_per_lineObject (readonly)

Returns the value of attribute mcus_per_line.



7
8
9
# File 'lib/zimg/jpeg/decoder.rb', line 7

def mcus_per_line
  @mcus_per_line
end

#progressiveObject

Returns the value of attribute progressive.



6
7
8
# File 'lib/zimg/jpeg/decoder.rb', line 6

def progressive
  @progressive
end

#widthObject

Returns the value of attribute width.



6
7
8
# File 'lib/zimg/jpeg/decoder.rb', line 6

def width
  @width
end