Class: ZXing::FFI::Reader
- Inherits:
-
Object
- Object
- ZXing::FFI::Reader
- Includes:
- Reader
- Defined in:
- lib/zxing/ffi/reader.rb
Direct Known Subclasses
Aztec::AztecReader, DataMatrix::DataMatrixReader, MultiFormatReader, OneD::Code39Reader
Instance Attribute Summary
Attributes included from Reader
Instance Method Summary collapse
- #decode(bitmap, hints = nil) ⇒ Object
-
#initialize(ptr) ⇒ Reader
constructor
A new instance of Reader.
Constructor Details
#initialize(ptr) ⇒ Reader
Returns a new instance of Reader.
6 7 8 |
# File 'lib/zxing/ffi/reader.rb', line 6 def initialize ptr super ZXing::FFI::Library::ReaderPointer.new ptr end |
Instance Method Details
#decode(bitmap, hints = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/zxing/ffi/reader.rb', line 10 def decode bitmap, hints = nil hints ||= {} th = hints[:try_harder] hints.delete :try_harder native_hints = nil if hints.empty? native_hints = ZXing::FFI::Library::DecodeHintsPointer.new(ZXing::FFI::Library.DecodeHints_default) else native_hints = ZXing::FFI::Library::DecodeHintsPointer.new(ZXing::FFI::Library.DecodeHints_new(0)) hints.each do |k, v| case k when :possible_formats v.each do |format| case format when :DATA_MATRIX ZXing::FFI::Library. DecodeHints_setDataMatrix native_hints, true else raise "implement hint for #{format}" end end else raise "implement #{k} #{v}" end end end if th ZXing::FFI::Library.DecodeHints_setTryHarder native_hints, th end # p @native, bitmap.native, native_hints ptr = ZXing::FFI::Library.Reader_decode @native, bitmap.native, native_hints # p ptr if (ptr.address & 1) != 0 ptr = FFI::Pointer.new(ptr.address & ~1) ptrs = ptr.read_array_of_pointer 2 className = ptrs[0].read_string.sub(%r{^zxing},"ZXing") what = ptrs[1].read_string ZXing::FFI::Library.free ptrs[1] ZXing::FFI::Library.free ptr cls = className.split("::").inject(Object) { |parent, child| parent.const_get(child) } raise cls.new what end ZXing::Result.new ZXing::FFI::Library::ResultPointer.new ptr end |