class Capybara::Screenshot::Diff::Drivers::VipsDriver::VipsUtil

Public Class Methods

difference_area(old_image, new_image, color_distance: 0) click to toggle source
# File lib/capybara/screenshot/diff/drivers/vips_driver.rb, line 124
def self.difference_area(old_image, new_image, color_distance: 0)
  difference_mask = difference_mask(new_image, old_image, color_distance)
  difference_area_size_by(difference_mask)
end
difference_area_size_by(difference_mask) click to toggle source
# File lib/capybara/screenshot/diff/drivers/vips_driver.rb, line 129
def self.difference_area_size_by(difference_mask)
  diff_mask = difference_mask == 0
  diff_mask.hist_find.to_a[0][0].max
end
difference_mask(base_image, new_image, color_distance = nil) click to toggle source
# File lib/capybara/screenshot/diff/drivers/vips_driver.rb, line 134
def self.difference_mask(base_image, new_image, color_distance = nil)
  result = (new_image - base_image).abs

  color_distance ? result > color_distance : result
end
difference_region_by(diff_mask) click to toggle source
# File lib/capybara/screenshot/diff/drivers/vips_driver.rb, line 140
def self.difference_region_by(diff_mask)
  columns, rows = diff_mask.bandor.project

  left = columns.profile[1].min
  right = columns.width - columns.flip(:horizontal).profile[1].min

  top = rows.profile[0].min
  bottom = rows.height - rows.flip(:vertical).profile[0].min

  return nil if right < left || bottom < top

  Region.from_edge_coordinates(left, top, right, bottom)
end