Class: RPDiff
- Inherits:
-
Object
- Object
- RPDiff
- Defined in:
- lib/rpdiff.rb
Instance Attribute Summary collapse
-
#fov ⇒ Object
readonly
Returns the value of attribute fov.
-
#gamma ⇒ Object
readonly
Returns the value of attribute gamma.
-
#identical ⇒ Object
readonly
Returns the value of attribute identical.
-
#img1 ⇒ Object
readonly
Returns the value of attribute img1.
-
#img2 ⇒ Object
readonly
Returns the value of attribute img2.
-
#indistinguishable ⇒ Object
readonly
Returns the value of attribute indistinguishable.
-
#luminance ⇒ Object
readonly
Returns the value of attribute luminance.
-
#match_percentage ⇒ Object
readonly
Returns the value of attribute match_percentage.
-
#pixel_difference ⇒ Object
readonly
Returns the value of attribute pixel_difference.
-
#threshold ⇒ Object
readonly
Returns the value of attribute threshold.
-
#visibly_different ⇒ Object
readonly
Returns the value of attribute visibly_different.
Instance Method Summary collapse
-
#calculate_match_percentage ⇒ Object
Optional gem requirement to get a % value out of image similarity.
- #diff ⇒ Object
-
#initialize(img1, img2, options = {}) ⇒ RPDiff
constructor
A new instance of RPDiff.
Constructor Details
#initialize(img1, img2, options = {}) ⇒ RPDiff
Returns a new instance of RPDiff.
9 10 11 |
# File 'lib/rpdiff.rb', line 9 def initialize(img1, img2, ={}) @img1, @img2, @options = img1, img2, end |
Instance Attribute Details
#fov ⇒ Object (readonly)
Returns the value of attribute fov.
6 7 8 |
# File 'lib/rpdiff.rb', line 6 def fov @fov end |
#gamma ⇒ Object (readonly)
Returns the value of attribute gamma.
6 7 8 |
# File 'lib/rpdiff.rb', line 6 def gamma @gamma end |
#identical ⇒ Object (readonly)
Returns the value of attribute identical.
6 7 8 |
# File 'lib/rpdiff.rb', line 6 def identical @identical end |
#img1 ⇒ Object (readonly)
Returns the value of attribute img1.
6 7 8 |
# File 'lib/rpdiff.rb', line 6 def img1 @img1 end |
#img2 ⇒ Object (readonly)
Returns the value of attribute img2.
6 7 8 |
# File 'lib/rpdiff.rb', line 6 def img2 @img2 end |
#indistinguishable ⇒ Object (readonly)
Returns the value of attribute indistinguishable.
6 7 8 |
# File 'lib/rpdiff.rb', line 6 def indistinguishable @indistinguishable end |
#luminance ⇒ Object (readonly)
Returns the value of attribute luminance.
6 7 8 |
# File 'lib/rpdiff.rb', line 6 def luminance @luminance end |
#match_percentage ⇒ Object (readonly)
Returns the value of attribute match_percentage.
6 7 8 |
# File 'lib/rpdiff.rb', line 6 def match_percentage @match_percentage end |
#pixel_difference ⇒ Object (readonly)
Returns the value of attribute pixel_difference.
6 7 8 |
# File 'lib/rpdiff.rb', line 6 def pixel_difference @pixel_difference end |
#threshold ⇒ Object (readonly)
Returns the value of attribute threshold.
6 7 8 |
# File 'lib/rpdiff.rb', line 6 def threshold @threshold end |
#visibly_different ⇒ Object (readonly)
Returns the value of attribute visibly_different.
6 7 8 |
# File 'lib/rpdiff.rb', line 6 def visibly_different @visibly_different end |
Instance Method Details
#calculate_match_percentage ⇒ Object
Optional gem requirement to get a % value out of image similarity.
37 38 39 40 41 |
# File 'lib/rpdiff.rb', line 37 def calculate_match_percentage return 0 if @incomparable @image_sizes = FastImage.size(@img1) @match_percentage = 100 - (@pixel_difference.to_f * 100 / (@image_sizes.first * @image_sizes.last).to_f) end |
#diff ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rpdiff.rb', line 13 def diff @indistinguishable = @visibly_different = @identical = false @pixel_difference = 0 opts = "#{@img1} #{@img2} " @options.each {|k, v| opts << "-#{k} #{v} "} io = `perceptualdiff #{opts}` io.split(/\n/).each do |line| @fov = $1 if line =~ /Field of view is (\d+\.\d+) degrees/ @threshold = $1 if line =~ /Threshold pixels is (\d+) pixels/ @gamma = $1 if line =~ /The Gamma is (\d+\.\d+)/ @luminance = $1 if line =~ /The Display's luminance is (\d+\.\d+) candela per meter squared/ @pixel_difference = $1 if line =~ /(\d+) pixels are different/ @visibly_different = true if line =~ /FAIL: Images are visibly different/ @identical = true if line =~ /PASS: Images are binary identical/ @indistinguishable = true if line =~ /PASS: Images are perceptually indistinguishable/ @incomparable = true if line =~ /FAIL: Images dimensions do not match/ end puts io end |