Class: Noyes::GolombRiceDecoder

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_impl/compression.rb

Instance Method Summary collapse

Constructor Details

#initialize(m = 8) ⇒ GolombRiceDecoder


176
177
178
179
# File 'lib/ruby_impl/compression.rb', line 176

def initialize m = 8
  @M = m
  @b = Math.log2(m).to_i
end

Instance Method Details

#<<(data) ⇒ Object


180
181
182
183
184
185
186
187
# File 'lib/ruby_impl/compression.rb', line 180

def << data
  data.map do |exp_sign_combo, significand|
    exp_sign_combo = deinterleave exp_sign_combo
    sign = exp_sign_combo & 0x00000001
    exp =  exp_sign_combo >> 1
    [sign, exp, significand]
  end
end

#decode(bits) ⇒ Object


192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/ruby_impl/compression.rb', line 192

def decode bits
  int_array = []
  while !bits.empty?
    q = 0
    nr = 0
    q+=1 while bits.shift == 1
    (@b-1).downto(0) do |a|
      break if bits.empty?
      nr += (1 << a) if bits.shift == 1
    end
    nr += q * @M
    int_array.push nr
  end
  int_array
end

#deinterleave(x) ⇒ Object


188
189
190
# File 'lib/ruby_impl/compression.rb', line 188

def deinterleave x
  x.odd? ? (x + 1)/-2 : x/2
end