class Imatcher::Modes::Grayscale

Compare pixels by alpha and brightness.

Options:

(default value is 16)

Constants

DEFAULT_TOLERANCE

Attributes

tolerance[R]

Public Class Methods

new(options) click to toggle source
Calls superclass method
# File lib/imatcher/modes/grayscale.rb, line 15
def initialize(options)
  @tolerance = options.delete(:tolerance) || DEFAULT_TOLERANCE
  super(options)
end

Public Instance Methods

background(bg) click to toggle source
# File lib/imatcher/modes/grayscale.rb, line 31
def background(bg)
  bg.to_grayscale
end
color_similar?(a, b) click to toggle source
# File lib/imatcher/modes/grayscale.rb, line 43
def color_similar?(a, b)
  d = (a - b).abs
  d <= tolerance
end
create_diff_image(_bg, diff_image) click to toggle source
# File lib/imatcher/modes/grayscale.rb, line 39
def create_diff_image(_bg, diff_image)
  diff_image
end
pixels_diff(d, _a, _b, x, y) click to toggle source
# File lib/imatcher/modes/grayscale.rb, line 35
def pixels_diff(d, _a, _b, x, y)
  d[x, y] = rgb(255, 0, 0)
end
pixels_equal?(a, b) click to toggle source
# File lib/imatcher/modes/grayscale.rb, line 20
def pixels_equal?(a, b)
  alpha = color_similar?(a(a), a(b))
  brightness = color_similar?(brightness(a), brightness(b))
  brightness && alpha
end
update_result(a, b, x, y) click to toggle source
Calls superclass method
# File lib/imatcher/modes/grayscale.rb, line 26
def update_result(a, b, x, y)
  super
  @result.diff << [a, b, x, y]
end