OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "Fuzz.h" |
| 9 |
| 10 // This really is just an example Fuzz*.cpp file. |
| 11 // It tests that two different ways of calculating the Paeth predictor function
are equivalent. |
| 12 |
| 13 static uint8_t paeth_std(uint8_t a, uint8_t b, uint8_t c) { |
| 14 int p = a+b-c; |
| 15 |
| 16 int pa = abs(p-a), |
| 17 pb = abs(p-b), |
| 18 pc = abs(p-c); |
| 19 |
| 20 if (pb < pa) { pa = pb; a = b; } |
| 21 if (pc < pa) { a = c; } |
| 22 return a; |
| 23 } |
| 24 |
| 25 static uint8_t paeth_alt(uint8_t a, uint8_t b, uint8_t c) { |
| 26 int min = SkTMin(a,b), |
| 27 max = SkTMax(a,b); |
| 28 int delta = (max-min)/3; |
| 29 |
| 30 if (c <= min+delta) return max; |
| 31 if (c >= max-delta) return min; |
| 32 return c; |
| 33 } |
| 34 |
| 35 DEF_FUZZ(Paeth, fuzz) { |
| 36 int a = fuzz->nextU(), |
| 37 b = fuzz->nextU(), |
| 38 c = fuzz->nextU(); |
| 39 ASSERT(paeth_alt(a,b,c) == paeth_std(a,b,c)); |
| 40 } |
OLD | NEW |