Sha256: ae4b4c6d7f2dca5328a56de073041048296b0028ec745b16be3ec24725b2ae9b

Contents?: true

Size: 983 Bytes

Versions: 22

Compression:

Stored size: 983 Bytes

Contents

#!/usr/bin/env ruby

#--
# Copyright 2004 by Duncan Robertson (duncan@whomwah.com).
# All rights reserved.

# Permission is granted for use, copying, modification, distribution,
# and distribution of modified versions of this work as long as the
# above copyright notice is included.
#++

module RQRCode

  class QRBitBuffer
    attr_reader :buffer

    def initialize
      @buffer = []
      @length = 0
    end


    def get( index )
      buf_index = (index / 8).floor
      (( (@buffer[buf_index]).rszf(7 - index % 8)) & 1) == 1
    end


    def put( num, length )
      ( 0...length ).each do |i|
        put_bit((((num).rszf(length - i - 1)) & 1) == 1)
      end
    end


    def get_length_in_bits
      @length
    end


    def put_bit( bit )
      buf_index = ( @length / 8 ).floor
      if @buffer.size <= buf_index
        @buffer << 0
      end

      if bit
        @buffer[buf_index] |= ((0x80).rszf(@length % 8))
      end

      @length += 1
    end 

  end

end

Version data entries

22 entries across 22 versions & 4 rubygems

Version Path
arena_barby-0.3.2 vendor/rqrcode/lib/rqrcode/qrcode/qr_bit_buffer.rb
barby-chunky_png-0.3.4 vendor/rqrcode/lib/rqrcode/qrcode/qr_bit_buffer.rb
rqrcode-0.4.2 lib/rqrcode/qrcode/qr_bit_buffer.rb
rqrcode-0.4.1 lib/rqrcode/qrcode/qr_bit_buffer.rb
rqrcode-0.4.0 lib/rqrcode/qrcode/qr_bit_buffer.rb
rqrcode-0.3.4 lib/rqrcode/qrcode/qr_bit_buffer.rb
barby-0.4.3 vendor/rqrcode/lib/rqrcode/qrcode/qr_bit_buffer.rb
rqrcode-0.3.3 lib/rqrcode/qrcode/qr_bit_buffer.rb
barby-0.4.2 vendor/rqrcode/lib/rqrcode/qrcode/qr_bit_buffer.rb
barby-0.4.1 vendor/rqrcode/lib/rqrcode/qrcode/qr_bit_buffer.rb
barby-0.4.0 vendor/rqrcode/lib/rqrcode/qrcode/qr_bit_buffer.rb
barby-chunky_png-0.3.3 vendor/rqrcode/lib/rqrcode/qrcode/qr_bit_buffer.rb
barby-0.3.2 vendor/rqrcode/lib/rqrcode/qrcode/qr_bit_buffer.rb
barby-0.3.1 vendor/rqrcode/lib/rqrcode/qrcode/qr_bit_buffer.rb
barby-0.2.1 vendor/rqrcode/lib/rqrcode/qrcode/qr_bit_buffer.rb
barby-0.2.0 vendor/rqrcode/lib/rqrcode/qrcode/qr_bit_buffer.rb
barby-0.3.0 vendor/rqrcode/lib/rqrcode/qrcode/qr_bit_buffer.rb
rqrcode-0.2.0 lib/rqrcode/qrcode/qr_bit_buffer.rb
rqrcode-0.3.1 lib/rqrcode/qrcode/qr_bit_buffer.rb
rqrcode-0.3.2 lib/rqrcode/qrcode/qr_bit_buffer.rb