@@ -42,12 +42,12 @@ def flatten_animation(image)
4242 end
4343end
4444
45- def mepp ( image_a , image_b )
45+ def psnr ( image_a , image_b )
4646 coalesce_a = flatten_animation ( image_a )
4747 coalesce_b = flatten_animation ( image_b )
4848 output = ImageOptim ::Cmd . capture ( ( IMAGEMAGICK_PREFIX + %W[
4949 compare
50- -metric MEPP
50+ -metric PSNR
5151 -alpha Background
5252 #{ coalesce_a . to_s . shellescape }
5353 #{ coalesce_b . to_s . shellescape }
@@ -59,21 +59,21 @@ def mepp(image_a, image_b)
5959 end
6060
6161 num_r = '\d+(?:\.\d+(?:[eE][-+]?\d+)?)?'
62- output [ /\( (#{ num_r } ), #{ num_r } \) / , 1 ] . to_f
62+ num = output [ /\A (#{ num_r } )/ , 1 ] . to_f
63+ num == 0 ? Float ::INFINITY : num
6364end
6465
6566RSpec ::Matchers . define :be_smaller_than do |expected |
6667 match { |actual | actual . size < expected . size }
6768end
6869
69- RSpec ::Matchers . define :be_similar_to do |expected , max_difference |
70+ RSpec ::Matchers . define :be_similar_to do |expected , psnr_min |
7071 match do |actual |
71- @diff = mepp ( actual , expected )
72- @diff <= max_difference
72+ @diff = psnr ( actual , expected )
73+ @diff >= psnr_min
7374 end
7475 failure_message do |actual |
75- "expected #{ actual } to have at most #{ max_difference } difference from " \
76- "#{ expected } , got mean error per pixel of #{ @diff } "
76+ "expected peaks signal to noise ratio between #{ actual } and #{ expected } to be #{ psnr_min } , got #{ @diff } "
7777 end
7878end
7979
0 commit comments