Class: Capybara::Screenshot::Diff::Drivers::VipsDriver::VipsUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/screenshot/diff/drivers/vips_driver.rb

Class Method Summary collapse

Class Method Details

.difference_area(old_image, new_image, color_distance: 0) ⇒ Object



124
125
126
127
# 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) ⇒ Object



129
130
131
132
# 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) ⇒ Object



134
135
136
137
138
# 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) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
# 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