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 #include <stdlib.h> | |
10 | |
11 // This really is just an example Fuzz*.cpp file. | |
12 // It tests that two different ways of calculating the Paeth predictor function
are equivalent. | |
13 | |
14 static uint8_t paeth_std(uint8_t a, uint8_t b, uint8_t c) { | |
15 int p = a+b-c; | |
16 | |
17 int pa = abs(p-a), | |
18 pb = abs(p-b), | |
19 pc = abs(p-c); | |
20 | |
21 if (pb < pa) { pa = pb; a = b; } | |
22 if (pc < pa) { a = c; } | |
23 return a; | |
24 } | |
25 | |
26 static uint8_t paeth_alt(uint8_t a, uint8_t b, uint8_t c) { | |
27 int min = SkTMin(a,b), | |
28 max = SkTMax(a,b); | |
29 int delta = (max-min)/3; | |
30 | |
31 if (c <= min+delta) return max; | |
32 if (c >= max-delta) return min; | |
33 return c; | |
34 } | |
35 | |
36 DEF_FUZZ(Paeth, fuzz) { | |
37 auto a = fuzz->nextB(), | |
38 b = fuzz->nextB(), | |
39 c = fuzz->nextB(); | |
40 SkDebugf("Paeth(%d,%d,%d)\n", a,b,c); | |
41 | |
42 if (a == b && b == c) { | |
43 fuzz->signalBoring(); // Not really boring, just demoing signalBoring()
. | |
44 } | |
45 | |
46 if (paeth_alt(a,b,c) != paeth_std(a,b,c)) { | |
47 fuzz->signalBug(); | |
48 } | |
49 } | |
OLD | NEW |