Class: JXL::Bit::Writer
- Inherits:
-
Object
- Object
- JXL::Bit::Writer
- Defined in:
- lib/jxl/bit/writer.rb
Instance Attribute Summary collapse
-
#bits_written ⇒ Object
readonly
Returns the value of attribute bits_written.
Instance Method Summary collapse
- #align ⇒ Object
- #bytes ⇒ Object
-
#initialize ⇒ Writer
constructor
A new instance of Writer.
- #write(count, value) ⇒ Object
Constructor Details
#initialize ⇒ Writer
Returns a new instance of Writer.
8 9 10 11 12 13 |
# File 'lib/jxl/bit/writer.rb', line 8 def initialize @bytes = +"".b @buffer = 0 @count = 0 @bits_written = 0 end |
Instance Attribute Details
#bits_written ⇒ Object (readonly)
Returns the value of attribute bits_written.
6 7 8 |
# File 'lib/jxl/bit/writer.rb', line 6 def bits_written @bits_written end |
Instance Method Details
#align ⇒ Object
26 27 28 |
# File 'lib/jxl/bit/writer.rb', line 26 def align write((-@count) & 7, 0) end |
#bytes ⇒ Object
30 31 32 33 |
# File 'lib/jxl/bit/writer.rb', line 30 def bytes align @bytes.dup end |
#write(count, value) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/jxl/bit/writer.rb', line 15 def write(count, value) raise ArgumentError, "invalid bit count" unless count.between?(0, 64) raise ArgumentError, "value does not fit" if value.negative? || value.bit_length > count @buffer |= value << @count @count += count @bits_written += count flush_bytes self end |