Class: OnlyofficePdfParser::BmpImage
- Inherits:
-
Object
- Object
- OnlyofficePdfParser::BmpImage
- Defined in:
- lib/onlyoffice_pdf_parser/bmp_image.rb
Overview
class for storing bmp image pixels data
Instance Attribute Summary collapse
-
#data ⇒ String
readonly
Binary dat of file.
-
#height ⇒ Object
Returns the value of attribute height.
-
#path_to_image ⇒ Object
Returns the value of attribute path_to_image.
-
#pixels ⇒ Object
Returns the value of attribute pixels.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
-
#==(other) ⇒ True, False
Compare object with other.
-
#get_sub_image(start_point = CursorPoint.new(0, 0), width = 0, height = 0) ⇒ BmpImage
Get sub image from coordinates.
-
#get_sub_image_array(path_to_sub_image) ⇒ Array<CursorPoint>
Get sub image from file pattern coordinates.
-
#initialize(param = nil, width: nil, height: nil) ⇒ BmpImage
constructor
A new instance of BmpImage.
-
#to_s ⇒ String
Convert object to string.
Constructor Details
#initialize(param = nil, width: nil, height: nil) ⇒ BmpImage
Returns a new instance of BmpImage.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/onlyoffice_pdf_parser/bmp_image.rb', line 15 def initialize(param = nil, width: nil, height: nil) @width = width @height = height return unless param init_data(param) image_size = ImageSize.new(data).size @width = image_size.first @height = image_size.last fetch_pixels end |
Instance Attribute Details
#data ⇒ String (readonly)
Returns binary dat of file.
13 14 15 |
# File 'lib/onlyoffice_pdf_parser/bmp_image.rb', line 13 def data @data end |
#height ⇒ Object
Returns the value of attribute height.
11 12 13 |
# File 'lib/onlyoffice_pdf_parser/bmp_image.rb', line 11 def height @height end |
#path_to_image ⇒ Object
Returns the value of attribute path_to_image.
11 12 13 |
# File 'lib/onlyoffice_pdf_parser/bmp_image.rb', line 11 def path_to_image @path_to_image end |
#pixels ⇒ Object
Returns the value of attribute pixels.
11 12 13 |
# File 'lib/onlyoffice_pdf_parser/bmp_image.rb', line 11 def pixels @pixels end |
#width ⇒ Object
Returns the value of attribute width.
11 12 13 |
# File 'lib/onlyoffice_pdf_parser/bmp_image.rb', line 11 def width @width end |
Instance Method Details
#==(other) ⇒ True, False
Compare object with other
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/onlyoffice_pdf_parser/bmp_image.rb', line 36 def ==(other) return false unless other.width == width && other.height == height pixels.each_with_index do |row, row_index| row.each_with_index do |pixel, pixel_index| other_pixel = other.pixels[row_index][pixel_index] result = (pixel == other_pixel) return false unless result end end true end |
#get_sub_image(start_point = CursorPoint.new(0, 0), width = 0, height = 0) ⇒ BmpImage
Get sub image from coordinates
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/onlyoffice_pdf_parser/bmp_image.rb', line 54 def get_sub_image(start_point = CursorPoint.new(0, 0), width = 0, height = 0) sub_image = BmpImage.new(nil, width: width, height: height) pixels_array = [] height.times do |current_height| line_array = [] width.times do |current_width| pixel_line = pixels[start_point.top + current_height] # If pixels match to near to the edge of right border of image, then end return nil unless pixel_line line_array << pixel_line[start_point.left + current_width] end pixels_array << line_array end sub_image.pixels = pixels_array sub_image end |
#get_sub_image_array(path_to_sub_image) ⇒ Array<CursorPoint>
Get sub image from file pattern coordinates
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/onlyoffice_pdf_parser/bmp_image.rb', line 75 def get_sub_image_array(path_to_sub_image) coordinates_array = [] sub_image = BmpImage.new(path_to_sub_image) first_sub_image_line = sub_image.pixels.first pixels.each_with_index do |current_line, image_line_index| included_indexes = ArrayHelper.get_array_inclusion_indexes(current_line, first_sub_image_line) included_indexes.each do |current_included_index| coordinates = image_location_start_find(current_included_index, image_line_index) got_sub_image = get_sub_image(coordinates, sub_image.width, sub_image.height) coordinates_array << coordinates if got_sub_image == sub_image end end coordinates_array end |
#to_s ⇒ String
Returns convert object to string.
29 30 31 |
# File 'lib/onlyoffice_pdf_parser/bmp_image.rb', line 29 def to_s path_to_image end |