Class: Pura::Webp::Encoder::BitWriter
- Inherits:
-
Object
- Object
- Pura::Webp::Encoder::BitWriter
- Defined in:
- lib/pura/webp/encoder.rb
Overview
Bit writer (LSB-first, VP8L format)
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize ⇒ BitWriter
constructor
A new instance of BitWriter.
- #write_bits(value, num_bits) ⇒ Object
Constructor Details
#initialize ⇒ BitWriter
Returns a new instance of BitWriter.
406 407 408 409 410 |
# File 'lib/pura/webp/encoder.rb', line 406 def initialize @data = String.new(encoding: Encoding::BINARY) @current = 0 @bits = 0 end |
Instance Method Details
#finish ⇒ Object
420 421 422 423 |
# File 'lib/pura/webp/encoder.rb', line 420 def finish @data << (@current & 0xFF).chr if @bits.positive? @data end |
#write_bits(value, num_bits) ⇒ Object
412 413 414 415 416 417 418 |
# File 'lib/pura/webp/encoder.rb', line 412 def write_bits(value, num_bits) num_bits.times do |i| @current |= ((value >> i) & 1) << @bits @bits += 1 flush_byte if @bits == 8 end end |