Class: Tesseract::API::Image
- Inherits:
-
Object
- Object
- Tesseract::API::Image
- Defined in:
- lib/tesseract/api/image.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Class Method Summary collapse
Instance Method Summary collapse
- #height ⇒ Object
-
#initialize(pointer, x = 0, y = 0) ⇒ Image
constructor
A new instance of Image.
- #to_blob(format = :default) ⇒ Object
- #to_ffi ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(pointer, x = 0, y = 0) ⇒ Image
Returns a new instance of Image.
50 51 52 53 54 |
# File 'lib/tesseract/api/image.rb', line 50 def initialize (pointer, x = 0, y = 0) @internal = FFI::AutoPointer.new(pointer, self.class.method(:finalize)) @x = x @y = y end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
48 49 50 |
# File 'lib/tesseract/api/image.rb', line 48 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
48 49 50 |
# File 'lib/tesseract/api/image.rb', line 48 def y @y end |
Class Method Details
.finalize(pointer) ⇒ Object
56 57 58 |
# File 'lib/tesseract/api/image.rb', line 56 def self.finalize (pointer) C::Leptonica.pix_destroy(pointer) end |
.new(image, x = 0, y = 0) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tesseract/api/image.rb', line 28 def self.new (image, x = 0, y = 0) image = if image.is_a?(String) && (File.exists?(File.(image)) rescue nil) C::Leptonica.pix_read(File.(image)) elsif image.is_a?(String) C::Leptonica.pix_read_mem(image, image.bytesize) elsif image.is_a?(IO) C::Leptonica.pix_read_stream(image.to_i) elsif image.respond_to? :to_blob image = image.to_blob C::Leptonica.pix_read_mem(image, image.bytesize) else image end raise ArgumentError, 'invalid image' if image.nil? || image.null? super(image, x, y) end |
Instance Method Details
#height ⇒ Object
64 65 66 |
# File 'lib/tesseract/api/image.rb', line 64 def height C::Leptonica.pix_get_height(to_ffi) end |
#to_blob(format = :default) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/tesseract/api/image.rb', line 68 def to_blob (format = :default) data = FFI::MemoryPointer.new(:pointer) size = FFI::MemoryPointer.new(:size_t) C::Leptonica.pix_write_mem(to_ffi, data, size, C.for_enum(format)) result = data.typecast(:pointer).read_string(size.typecast(:size_t)) C.free(data.typecast(:pointer)) result end |
#to_ffi ⇒ Object
79 80 81 |
# File 'lib/tesseract/api/image.rb', line 79 def to_ffi @internal end |