| 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" | 8 #include "Sk4px.h" |
| 9 #include "SkNx.h" | 9 #include "SkNx.h" |
| 10 #include "SkRandom.h" | 10 #include "SkRandom.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 | 170 |
| 171 DEF_TEST(Sk4px_muldiv255round, r) { | 171 DEF_TEST(Sk4px_muldiv255round, r) { |
| 172 for (int a = 0; a < (1<<8); a++) { | 172 for (int a = 0; a < (1<<8); a++) { |
| 173 for (int b = 0; b < (1<<8); b++) { | 173 for (int b = 0; b < (1<<8); b++) { |
| 174 int exact = (a*b+127)/255; | 174 int exact = (a*b+127)/255; |
| 175 | 175 |
| 176 // Duplicate a and b 16x each. | 176 // Duplicate a and b 16x each. |
| 177 Sk4px av((SkAlpha)a), | 177 auto av = Sk4px::DupAlpha(a), |
| 178 bv((SkAlpha)b); | 178 bv = Sk4px::DupAlpha(b); |
| 179 | 179 |
| 180 // This way should always be exactly correct. | 180 // This way should always be exactly correct. |
| 181 int correct = av.mulWiden(bv).div255RoundNarrow().kth<0>(); | 181 int correct = (av * bv).div255().kth<0>(); |
| 182 REPORTER_ASSERT(r, correct == exact); | 182 REPORTER_ASSERT(r, correct == exact); |
| 183 | 183 |
| 184 // We're a bit more flexible on this method: correct for 0 or 255, other
wise off by <=1. | 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>(); | 185 int fast = av.approxMulDiv255(bv).kth<0>(); |
| 186 REPORTER_ASSERT(r, fast-exact >= -1 && fast-exact <= 1); | 186 REPORTER_ASSERT(r, fast-exact >= -1 && fast-exact <= 1); |
| 187 if (a == 0 || a == 255 || b == 0 || b == 255) { | 187 if (a == 0 || a == 255 || b == 0 || b == 255) { |
| 188 REPORTER_ASSERT(r, fast == exact); | 188 REPORTER_ASSERT(r, fast == exact); |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 } | 191 } |
| 192 } | 192 } |
| OLD | NEW |