OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Sk4px.h" | |
9 #include "SkNx.h" | 8 #include "SkNx.h" |
10 #include "SkRandom.h" | 9 #include "SkRandom.h" |
11 #include "Test.h" | 10 #include "Test.h" |
12 | 11 |
13 template <int N, typename T> | 12 template <int N, typename T> |
14 static void test_Nf(skiatest::Reporter* r) { | 13 static void test_Nf(skiatest::Reporter* r) { |
15 | 14 |
16 auto assert_nearly_eq = [&](double eps, const SkNf<N,T>& v, T a, T b, T c, T
d) { | 15 auto assert_nearly_eq = [&](double eps, const SkNf<N,T>& v, T a, T b, T c, T
d) { |
17 auto close = [=](T a, T b) { return fabs(a-b) <= eps; }; | 16 auto close = [=](T a, T b) { return fabs(a-b) <= eps; }; |
18 T vals[4]; | 17 T vals[4]; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 b = rand.nextU() >> 16; | 147 b = rand.nextU() >> 16; |
149 REPORTER_ASSERT(r, Sk8h::Min(Sk8h(a), Sk8h(b)).kth<0>() == SkTMin(a, b))
; | 148 REPORTER_ASSERT(r, Sk8h::Min(Sk8h(a), Sk8h(b)).kth<0>() == SkTMin(a, b))
; |
150 } | 149 } |
151 #else | 150 #else |
152 for (int a = 0; a < (1<<16); a++) { | 151 for (int a = 0; a < (1<<16); a++) { |
153 for (int b = 0; b < (1<<16); b++) { | 152 for (int b = 0; b < (1<<16); b++) { |
154 REPORTER_ASSERT(r, Sk8h::Min(Sk8h(a), Sk8h(b)).kth<0>() == SkTMin(a, b))
; | 153 REPORTER_ASSERT(r, Sk8h::Min(Sk8h(a), Sk8h(b)).kth<0>() == SkTMin(a, b))
; |
155 }} | 154 }} |
156 #endif | 155 #endif |
157 } | 156 } |
158 | |
159 DEF_TEST(SkNi_saturatedAdd, r) { | |
160 for (int a = 0; a < (1<<8); a++) { | |
161 for (int b = 0; b < (1<<8); b++) { | |
162 int exact = a+b; | |
163 if (exact > 255) { exact = 255; } | |
164 if (exact < 0) { exact = 0; } | |
165 | |
166 REPORTER_ASSERT(r, Sk16b(a).saturatedAdd(Sk16b(b)).kth<0>() == exact); | |
167 } | |
168 } | |
169 } | |
170 | |
171 DEF_TEST(Sk4px_muldiv255round, r) { | |
172 for (int a = 0; a < (1<<8); a++) { | |
173 for (int b = 0; b < (1<<8); b++) { | |
174 int exact = (a*b+127)/255; | |
175 | |
176 // Duplicate a and b 16x each. | |
177 Sk4px av((SkAlpha)a), | |
178 bv((SkAlpha)b); | |
179 | |
180 // This way should always be exactly correct. | |
181 int correct = av.mulWiden(bv).div255RoundNarrow().kth<0>(); | |
182 REPORTER_ASSERT(r, correct == exact); | |
183 | |
184 // We're a bit more flexible on this method: correct for 0 or 255, other
wise off by <=1. | |
185 int fast = av.fastMulDiv255Round(bv).kth<0>(); | |
186 REPORTER_ASSERT(r, fast-exact >= -1 && fast-exact <= 1); | |
187 if (a == 0 || a == 255 || b == 0 || b == 255) { | |
188 REPORTER_ASSERT(r, fast == exact); | |
189 } | |
190 } | |
191 } | |
192 } | |
OLD | NEW |