class WatchDoge::PixelTest

Attributes

after[R]
before[R]
diff[R]
option[R]

Public Class Methods

diff(input_image, reference_image, opacity: 0.7, mask_base_color: " click to toggle source
# File lib/watchdoge/pixel_test.rb, line 15
def self.diff input_image, reference_image, opacity: 0.7, mask_base_color: "#F163FF"
  return nil if input_image.pixels.hash == reference_image.pixels.hash

  mask_color = mask_base_color.concat (opacity * 256).to_i.to_s(16).upcase

  dup_input_image = input_image.dup

  input_image.height.times do |y|
    pixels = input_image.row(y)

    if y >= reference_image.height
      pixels.each_with_index do |pixel, x|
        dup_input_image.compose_pixel(x, y, mask_color)
      end
    else
      reference_pixels = reference_image.row(y)

      next if (pixels.hash == reference_pixels.hash)

      pixels.each_with_index do |pixel, x|
        if pixels[x] != reference_pixels[x]
          dup_input_image.compose_pixel(x, y, reference_pixels[x])
          dup_input_image.compose_pixel(x, y, mask_color)
        end
      end
    end
  end

  dup_input_image
end
new(input, reference, **kwargs) click to toggle source
# File lib/watchdoge/pixel_test.rb, line 51
def initialize input, reference, **kwargs
  @before = reference
  @after = input

  @option = kwargs

  @diff = self.class.diff input, reference
end

Public Instance Methods

diff?() click to toggle source
# File lib/watchdoge/pixel_test.rb, line 60
def diff?
  @diff
end