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

Public Class Methods

difference(old_image, new_image, color_distance: 0) click to toggle source
# File lib/capybara/screenshot/diff/drivers/vips_driver.rb, line 146
def self.difference(old_image, new_image, color_distance: 0)
  diff_mask = difference_mask(color_distance, new_image, old_image)
  difference_region_by(diff_mask)
end
difference_area(old_image, new_image, color_distance: 0) click to toggle source
# File lib/capybara/screenshot/diff/drivers/vips_driver.rb, line 151
def self.difference_area(old_image, new_image, color_distance: 0)
  difference_mask = difference_mask(color_distance, new_image, old_image)
  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 156
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(color_distance, old_image, new_image) click to toggle source
# File lib/capybara/screenshot/diff/drivers/vips_driver.rb, line 161
def self.difference_mask(color_distance, old_image, new_image)
  (new_image - old_image).abs > color_distance
end
difference_region_by(diff_mask) click to toggle source
# File lib/capybara/screenshot/diff/drivers/vips_driver.rb, line 165
def self.difference_region_by(diff_mask)
  columns, rows = diff_mask.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

  [left, top, right, bottom]
end