Class: ZIMG::JPEG::DHT

Inherits:
Chunk show all
Defined in:
lib/zimg/jpeg/chunks.rb

Overview

Define Huffman Table

Instance Attribute Summary collapse

Attributes inherited from Chunk

#data, #marker, #size

Instance Method Summary collapse

Methods inherited from Chunk

#crc, #export, #type

Methods inherited from Chunk

#cli_color

Constructor Details

#initialize(marker, io) ⇒ DHT

Returns a new instance of DHT.



179
180
181
182
183
184
185
186
187
188
# File 'lib/zimg/jpeg/chunks.rb', line 179

def initialize(marker, io)
  super
  @tables = {}
  sio = StringIO.new(@data)
  until sio.eof?
    id, *lengths = sio.read(17).unpack("C*")
    values = sio.read(lengths.inject(:+)).unpack("C*")
    @tables[id] = [lengths, values]
  end
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



177
178
179
# File 'lib/zimg/jpeg/chunks.rb', line 177

def id
  @id
end

#tablesObject

Returns the value of attribute tables.



177
178
179
# File 'lib/zimg/jpeg/chunks.rb', line 177

def tables
  @tables
end

Instance Method Details

#inspect(verbose = 0) ⇒ Object



190
191
192
193
194
# File 'lib/zimg/jpeg/chunks.rb', line 190

def inspect(verbose = 0)
  r = super.chop + format("ids=%s >", tables.keys.inspect)
  r = r.chop + format("tables=%s >", tables.values.inspect) if verbose > 0
  r
end