Class: WatchDoge::PixelTest

Inherits:
Object
  • Object
show all
Defined in:
lib/watchdoge/pixel_test.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, reference, **kwargs) ⇒ PixelTest

Returns a new instance of PixelTest.



51
52
53
54
55
56
57
58
# 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

Instance Attribute Details

#afterObject (readonly)

Returns the value of attribute after.



48
49
50
# File 'lib/watchdoge/pixel_test.rb', line 48

def after
  @after
end

#beforeObject (readonly)

Returns the value of attribute before.



47
48
49
# File 'lib/watchdoge/pixel_test.rb', line 47

def before
  @before
end

#diffObject (readonly)

Returns the value of attribute diff.



46
47
48
# File 'lib/watchdoge/pixel_test.rb', line 46

def diff
  @diff
end

#optionObject (readonly)

Returns the value of attribute option.



49
50
51
# File 'lib/watchdoge/pixel_test.rb', line 49

def option
  @option
end

Class Method Details

.diff(input_image, reference_image, opacity: 0.7, mask_base_color: "#F163FF") ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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

Instance Method Details

#diff?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/watchdoge/pixel_test.rb', line 60

def diff?
  @diff
end