Class: JXL::VarDCT::BlockContextMap

Inherits:
Data
  • Object
show all
Defined in:
lib/jxl/vardct/block_context_map.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#context_mapObject (readonly)

Returns the value of attribute context_map

Returns:

  • (Object)

    the current value of context_map



15
16
17
# File 'lib/jxl/vardct/block_context_map.rb', line 15

def context_map
  @context_map
end

#dc_thresholdsObject (readonly)

Returns the value of attribute dc_thresholds

Returns:

  • (Object)

    the current value of dc_thresholds



15
16
17
# File 'lib/jxl/vardct/block_context_map.rb', line 15

def dc_thresholds
  @dc_thresholds
end

#num_contextsObject (readonly)

Returns the value of attribute num_contexts

Returns:

  • (Object)

    the current value of num_contexts



15
16
17
# File 'lib/jxl/vardct/block_context_map.rb', line 15

def num_contexts
  @num_contexts
end

#num_dc_contextsObject (readonly)

Returns the value of attribute num_dc_contexts

Returns:

  • (Object)

    the current value of num_dc_contexts



15
16
17
# File 'lib/jxl/vardct/block_context_map.rb', line 15

def num_dc_contexts
  @num_dc_contexts
end

#qf_thresholdsObject (readonly)

Returns the value of attribute qf_thresholds

Returns:

  • (Object)

    the current value of qf_thresholds



15
16
17
# File 'lib/jxl/vardct/block_context_map.rb', line 15

def qf_thresholds
  @qf_thresholds
end

Class Method Details

.defaultsObject



30
31
32
33
# File 'lib/jxl/vardct/block_context_map.rb', line 30

def self.defaults
  new(dc_thresholds: Array.new(3) { [] }, qf_thresholds: [], context_map: DEFAULT_BLOCK_CONTEXT_MAP,
      num_contexts: 15, num_dc_contexts: 1)
end

.read(reader) ⇒ Object

Raises:



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jxl/vardct/block_context_map.rb', line 17

def self.read(reader)
  return defaults if Bit::Field.read_bool(reader)

  dc = Array.new(3) do
    Array.new(reader.read(4)) { Num.unpack_signed(Bit::Field.u32(reader, *BLOCK_DC_DISTRIBUTION)) }
  end
  num_dc = dc.reduce(1) { |total, thresholds| total * (thresholds.length + 1) }
  qf = Array.new(reader.read(4)) { Bit::Field.u32(reader, *BLOCK_QF_DISTRIBUTION) + 1 }
  raise CorruptError, "block context map is too large" if num_dc * (qf.length + 1) > 64

  read_map(reader, dc, qf, num_dc)
end

Instance Method Details

#ac_context_countObject



60
# File 'lib/jxl/vardct/block_context_map.rb', line 60

def ac_context_count = num_contexts * (37 + 458)

#coefficient_context_offset(block_context) ⇒ Object



56
57
58
# File 'lib/jxl/vardct/block_context_map.rb', line 56

def coefficient_context_offset(block_context)
  (num_contexts * 37) + (458 * block_context)
end

#context(dc_index, quant, order, channel) ⇒ Object



44
45
46
47
48
# File 'lib/jxl/vardct/block_context_map.rb', line 44

def context(dc_index, quant, order, channel)
  quant_index = qf_thresholds.count { quant > _1 }
  index = ((channel < 2 ? channel ^ 1 : 2) * 13) + order
  context_map.fetch((((index * (qf_thresholds.length + 1)) + quant_index) * num_dc_contexts) + dc_index)
end

#nonzero_context(nonzeros, block_context) ⇒ Object



50
51
52
53
54
# File 'lib/jxl/vardct/block_context_map.rb', line 50

def nonzero_context(nonzeros, block_context)
  nonzeros = 64 if nonzeros >= 64
  bucket = nonzeros < 8 ? nonzeros : 4 + (nonzeros / 2)
  (bucket * num_contexts) + block_context
end