Class: Kracker::Zooka::Analyzer
- Inherits:
-
Object
- Object
- Kracker::Zooka::Analyzer
- Defined in:
- lib/kracker/zooka/analyzer.rb
Instance Attribute Summary collapse
-
#ignore_antialiasing ⇒ Object
Returns the value of attribute ignore_antialiasing.
-
#ignore_colors ⇒ Object
Returns the value of attribute ignore_colors.
-
#image_1 ⇒ Object
Returns the value of attribute image_1.
-
#image_2 ⇒ Object
Returns the value of attribute image_2.
-
#noncompliant_pixels ⇒ Object
readonly
Returns the value of attribute noncompliant_pixels.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#tolerance ⇒ Object
Returns the value of attribute tolerance.
Instance Method Summary collapse
- #analyze ⇒ Object
-
#initialize(options = {}) ⇒ Analyzer
constructor
A new instance of Analyzer.
- #same? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Analyzer
Returns a new instance of Analyzer.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/kracker/zooka/analyzer.rb', line 9 def initialize( = {}) @tolerance = Tolerance.new @ignore_antialiasing = false @ignore_colors = false @noncompliant_pixels = [] if .has_key?(:image_1) @image_1 = [:image_1] elsif .has_key?(:filename_1) @image_1 = ChunkyPNG::Image.from_file([:filename_1]) else @image_1 = nil end if .has_key?(:image_2) @image_2 = [:image_2] elsif .has_key?(:filename_2) @image_2 = ChunkyPNG::Image.from_file([:filename_2]) else @image_2 = nil end end |
Instance Attribute Details
#ignore_antialiasing ⇒ Object
Returns the value of attribute ignore_antialiasing.
4 5 6 |
# File 'lib/kracker/zooka/analyzer.rb', line 4 def ignore_antialiasing @ignore_antialiasing end |
#ignore_colors ⇒ Object
Returns the value of attribute ignore_colors.
4 5 6 |
# File 'lib/kracker/zooka/analyzer.rb', line 4 def ignore_colors @ignore_colors end |
#image_1 ⇒ Object
Returns the value of attribute image_1.
5 6 7 |
# File 'lib/kracker/zooka/analyzer.rb', line 5 def image_1 @image_1 end |
#image_2 ⇒ Object
Returns the value of attribute image_2.
5 6 7 |
# File 'lib/kracker/zooka/analyzer.rb', line 5 def image_2 @image_2 end |
#noncompliant_pixels ⇒ Object (readonly)
Returns the value of attribute noncompliant_pixels.
7 8 9 |
# File 'lib/kracker/zooka/analyzer.rb', line 7 def noncompliant_pixels @noncompliant_pixels end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
6 7 8 |
# File 'lib/kracker/zooka/analyzer.rb', line 6 def result @result end |
#tolerance ⇒ Object
Returns the value of attribute tolerance.
4 5 6 |
# File 'lib/kracker/zooka/analyzer.rb', line 4 def tolerance @tolerance end |
Instance Method Details
#analyze ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/kracker/zooka/analyzer.rb', line 32 def analyze @noncompliant_pixels = [] @result = ChunkyPNG::Image.new(@image_1.width, @image_1.height, ChunkyPNG::Color::TRANSPARENT) @image_1.width.times do |x| @image_1.height.times do |y| pix_1 = Pixel.new(@image_1[x, y]) pix_2 = Pixel.new(@image_2[x, y]) if @ignore_colors if brightness_similar?(pix_1, pix_2) @result[x, y] = ChunkyPNG::Color::rgba(pix_1.red, pix_1.green, pix_1.blue, pix_1.alpha / 10) else @result[x, y] = ChunkyPNG::Color::rgba(255, 0, 0, 100) @noncompliant_pixels << { x: x, y: y } end else if rgb_similar?(pix_1, pix_2) @result[x, y] = ChunkyPNG::Color::rgba(pix_1.red, pix_1.green, pix_1.blue, pix_1.alpha / 10) elsif @ignore_antialiasing && (antialiased?(@image_1, x, y) || antialiased?(@image_2, x, y)) if brightness_similar?(pix_1, pix_2) @result[x, y] = ChunkyPNG::Color::rgba(pix_1.red, pix_1.green, pix_1.blue, pix_1.alpha / 10) else @result[x, y] = ChunkyPNG::Color::rgba(255, 0, 0, 100) @noncompliant_pixels << { x: x, y: y } end else @result[x, y] = ChunkyPNG::Color::rgba(255, 0, 0, 100) @noncompliant_pixels << { x: x, y: y } end end end end end |
#same? ⇒ Boolean
67 68 69 |
# File 'lib/kracker/zooka/analyzer.rb', line 67 def same? @noncompliant_pixels.count == 0 end |