Class: Capybara::Screenshot::Diff::Drivers::VipsDriver::VipsUtil
- Inherits:
-
Object
- Object
- Capybara::Screenshot::Diff::Drivers::VipsDriver::VipsUtil
- Defined in:
- lib/capybara/screenshot/diff/drivers/vips_driver.rb
Class Method Summary collapse
- .difference(old_image, new_image, color_distance: 0) ⇒ Object
- .difference_area(old_image, new_image, color_distance: 0) ⇒ Object
- .difference_area_size_by(difference_mask) ⇒ Object
- .difference_mask(color_distance, old_image, new_image) ⇒ Object
- .difference_region_by(diff_mask) ⇒ Object
Class Method Details
.difference(old_image, new_image, color_distance: 0) ⇒ Object
160 161 162 163 |
# File 'lib/capybara/screenshot/diff/drivers/vips_driver.rb', line 160 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).to_edge_coordinates end |
.difference_area(old_image, new_image, color_distance: 0) ⇒ Object
165 166 167 168 |
# File 'lib/capybara/screenshot/diff/drivers/vips_driver.rb', line 165 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) ⇒ Object
170 171 172 173 |
# File 'lib/capybara/screenshot/diff/drivers/vips_driver.rb', line 170 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) ⇒ Object
175 176 177 |
# File 'lib/capybara/screenshot/diff/drivers/vips_driver.rb', line 175 def self.difference_mask(color_distance, old_image, new_image) (new_image - old_image).abs > color_distance end |
.difference_region_by(diff_mask) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/capybara/screenshot/diff/drivers/vips_driver.rb', line 179 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 |