Change PixelsAreSimilar() to handle black pixels correctly.

if src_{r,g,b} = 0, any value of src_a or dst_a such that
   abs(src_a - dst_a) <= max_allowed_diff
was making the test pass, despite being very different-looking pixels.

The fix is to require same values for src_a and dst_a before attempting
an r/g/b comparison.

Change-Id: If3a55a229eab3904ed454f20065e49e35c39f25c
This commit is contained in:
Pascal Massimino 2016-08-25 07:33:18 +02:00
parent c0a27fd2af
commit 6585075f8a

View File

@ -378,10 +378,10 @@ static WEBP_INLINE int PixelsAreSimilar(uint32_t src, uint32_t dst,
const int dst_g = (dst >> 8) & 0xff; const int dst_g = (dst >> 8) & 0xff;
const int dst_b = (dst >> 0) & 0xff; const int dst_b = (dst >> 0) & 0xff;
return (abs(src_r * src_a - dst_r * dst_a) <= (max_allowed_diff * 255)) && return (src_a == dst_a) &&
(abs(src_g * src_a - dst_g * dst_a) <= (max_allowed_diff * 255)) && (abs(src_r - dst_r) * dst_a <= (max_allowed_diff * 255)) &&
(abs(src_b * src_a - dst_b * dst_a) <= (max_allowed_diff * 255)) && (abs(src_g - dst_g) * dst_a <= (max_allowed_diff * 255)) &&
(abs(src_a - dst_a) <= max_allowed_diff); (abs(src_b - dst_b) * dst_a <= (max_allowed_diff * 255));
} }
// Returns true if 'length' number of pixels in 'src' and 'dst' are within an // Returns true if 'length' number of pixels in 'src' and 'dst' are within an