Class: ZIMG::JPEG::DQT

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

Overview

can store multiple tables

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) ⇒ DQT

Returns a new instance of DQT.



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/zimg/jpeg/chunks.rb', line 201

def initialize(marker, io)
  super
  @tables = {}
  sio = StringIO.new(@data)
  until sio.eof?
    id = sio.read(1).unpack1("C")
    values =
      case (id >> 4)
      when 0
        # 8 bit values
        sio.read(64).unpack("C*")
      when 1
        # 16 bit values
        sio.read(128).unpack("n*")
      else
        raise "DQT: invalid table spec #{id}"
      end

    id &= 0x0f
    table = [0] * 64
    values.each_with_index { |value, idx| table[DCT_ZIGZAG[idx]] = value }

    @tables[id] = table
  end
end

Instance Attribute Details

#tablesObject

Returns the value of attribute tables.



199
200
201
# File 'lib/zimg/jpeg/chunks.rb', line 199

def tables
  @tables
end

Instance Method Details

#inspect(verbose = 0) ⇒ Object



227
228
229
230
231
# File 'lib/zimg/jpeg/chunks.rb', line 227

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