Class: PureJPEG::Huffman::FrequencyCounter
- Inherits:
-
Object
- Object
- PureJPEG::Huffman::FrequencyCounter
- Defined in:
- lib/pure_jpeg/huffman/encoder.rb
Instance Attribute Summary collapse
-
#ac_frequencies ⇒ Object
readonly
Returns the value of attribute ac_frequencies.
-
#dc_frequencies ⇒ Object
readonly
Returns the value of attribute dc_frequencies.
Instance Method Summary collapse
-
#initialize ⇒ FrequencyCounter
constructor
A new instance of FrequencyCounter.
- #observe_block(zigzag, state_key) ⇒ Object
Constructor Details
#initialize ⇒ FrequencyCounter
Returns a new instance of FrequencyCounter.
102 103 104 105 106 |
# File 'lib/pure_jpeg/huffman/encoder.rb', line 102 def initialize @dc_frequencies = Array.new(256, 0) @ac_frequencies = Array.new(256, 0) @prev_dc = Hash.new(0) end |
Instance Attribute Details
#ac_frequencies ⇒ Object (readonly)
Returns the value of attribute ac_frequencies.
100 101 102 |
# File 'lib/pure_jpeg/huffman/encoder.rb', line 100 def ac_frequencies @ac_frequencies end |
#dc_frequencies ⇒ Object (readonly)
Returns the value of attribute dc_frequencies.
100 101 102 |
# File 'lib/pure_jpeg/huffman/encoder.rb', line 100 def dc_frequencies @dc_frequencies end |
Instance Method Details
#observe_block(zigzag, state_key) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/pure_jpeg/huffman/encoder.rb', line 108 def observe_block(zigzag, state_key) diff = zigzag[0] - @prev_dc[state_key] @prev_dc[state_key] = zigzag[0] cat = Encoder.category(diff) @dc_frequencies[cat] += 1 Encoder.each_ac_symbol(zigzag) do |symbol| @ac_frequencies[symbol] += 1 end end |