OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkColorPriv.h" | 8 #include "SkColorPriv.h" |
9 #include "SkEndian.h" | 9 #include "SkEndian.h" |
10 #include "SkFloatBits.h" | 10 #include "SkFloatBits.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 return (float)(x + big) - big; | 45 return (float)(x + big) - big; |
46 } | 46 } |
47 | 47 |
48 static float std_floor(float x) { | 48 static float std_floor(float x) { |
49 return sk_float_floor(x); | 49 return sk_float_floor(x); |
50 } | 50 } |
51 | 51 |
52 static void test_floor_value(skiatest::Reporter* reporter, float value) { | 52 static void test_floor_value(skiatest::Reporter* reporter, float value) { |
53 float fast = fast_floor(value); | 53 float fast = fast_floor(value); |
54 float std = std_floor(value); | 54 float std = std_floor(value); |
55 REPORTER_ASSERT(reporter, std == fast); | 55 if (std != fast) { |
56 // SkDebugf("value[%1.9f] std[%g] fast[%g] equal[%d]\n", | 56 ERRORF(reporter, "fast_floor(%.9g) == %.9g != %.9g == std_floor(%.9g)", |
57 // value, std, fast, std == fast); | 57 value, fast, std, value); |
| 58 } |
58 } | 59 } |
59 | 60 |
60 static void test_floor(skiatest::Reporter* reporter) { | 61 static void test_floor(skiatest::Reporter* reporter) { |
61 static const float gVals[] = { | 62 static const float gVals[] = { |
62 0, 1, 1.1f, 1.01f, 1.001f, 1.0001f, 1.00001f, 1.000001f, 1.0000001f | 63 0, 1, 1.1f, 1.01f, 1.001f, 1.0001f, 1.00001f, 1.000001f, 1.0000001f |
63 }; | 64 }; |
64 | 65 |
65 for (size_t i = 0; i < SK_ARRAY_COUNT(gVals); ++i) { | 66 for (size_t i = 0; i < SK_ARRAY_COUNT(gVals); ++i) { |
66 test_floor_value(reporter, gVals[i]); | 67 test_floor_value(reporter, gVals[i]); |
67 // test_floor_value(reporter, -gVals[i]); | 68 // test_floor_value(reporter, -gVals[i]); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 // int r0 = blend31_round(src, dst, a); | 144 // int r0 = blend31_round(src, dst, a); |
144 // int r0 = blend31_old(src, dst, a); | 145 // int r0 = blend31_old(src, dst, a); |
145 int r0 = blend31_slow(src, dst, a); | 146 int r0 = blend31_slow(src, dst, a); |
146 | 147 |
147 float f = float_blend(src, dst, a / 31.f); | 148 float f = float_blend(src, dst, a / 31.f); |
148 int r1 = (int)f; | 149 int r1 = (int)f; |
149 int r2 = SkScalarRoundToInt(f); | 150 int r2 = SkScalarRoundToInt(f); |
150 | 151 |
151 if (r0 != r1 && r0 != r2) { | 152 if (r0 != r1 && r0 != r2) { |
152 SkDebugf("src:%d dst:%d a:%d result:%d float:%g\n", | 153 SkDebugf("src:%d dst:%d a:%d result:%d float:%g\n", |
153 src, dst, a, r0, f); | 154 src, dst, a, r0, f); |
154 failed += 1; | 155 failed += 1; |
155 } | 156 } |
156 if (r0 > 255) { | 157 if (r0 > 255) { |
157 death += 1; | 158 death += 1; |
158 SkDebugf("death src:%d dst:%d a:%d result:%d float:%g\n", | 159 SkDebugf("death src:%d dst:%d a:%d result:%d float:%g\n", |
159 src, dst, a, r0, f); | 160 src, dst, a, r0, f); |
160 } | 161 } |
161 } | 162 } |
162 } | 163 } |
163 } | 164 } |
164 SkDebugf("---- failed %d death %d\n", failed, death); | 165 SkDebugf("---- failed %d death %d\n", failed, death); |
165 } | 166 } |
166 | 167 |
167 static void test_blend(skiatest::Reporter* reporter) { | 168 static void test_blend(skiatest::Reporter* reporter) { |
168 for (int src = 0; src <= 255; src++) { | 169 for (int src = 0; src <= 255; src++) { |
169 for (int dst = 0; dst <= 255; dst++) { | 170 for (int dst = 0; dst <= 255; dst++) { |
170 for (int a = 0; a <= 255; a++) { | 171 for (int a = 0; a <= 255; a++) { |
171 int r0 = SkAlphaBlend255(src, dst, a); | 172 int r0 = SkAlphaBlend255(src, dst, a); |
172 float f1 = float_blend(src, dst, a / 255.f); | 173 float f1 = float_blend(src, dst, a / 255.f); |
173 int r1 = SkScalarRoundToInt(f1); | 174 int r1 = SkScalarRoundToInt(f1); |
174 | 175 |
175 if (r0 != r1) { | 176 if (r0 != r1) { |
176 float diff = sk_float_abs(f1 - r1); | 177 float diff = sk_float_abs(f1 - r1); |
177 diff = sk_float_abs(diff - 0.5f); | 178 diff = sk_float_abs(diff - 0.5f); |
178 if (diff > (1 / 255.f)) { | 179 if (diff > (1 / 255.f)) { |
179 #ifdef SK_DEBUG | 180 ERRORF(reporter, "src:%d dst:%d a:%d " |
180 SkDebugf("src:%d dst:%d a:%d result:%d float:%g\n", | 181 "result:%d float:%g\n", src, dst, a, r0, f1); |
181 src, dst, a, r0, f1); | |
182 #endif | |
183 REPORTER_ASSERT(reporter, false); | |
184 } | 182 } |
185 } | 183 } |
186 } | 184 } |
187 } | 185 } |
188 } | 186 } |
189 } | 187 } |
190 | 188 |
191 static void check_length(skiatest::Reporter* reporter, | 189 static void check_length(skiatest::Reporter* reporter, |
192 const SkPoint& p, SkScalar targetLen) { | 190 const SkPoint& p, SkScalar targetLen) { |
193 float x = SkScalarToFloat(p.fX); | 191 float x = SkScalarToFloat(p.fX); |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 test_divmod<int16_t>(r); | 689 test_divmod<int16_t>(r); |
692 } | 690 } |
693 | 691 |
694 DEF_TEST(divmod_s32, r) { | 692 DEF_TEST(divmod_s32, r) { |
695 test_divmod<int32_t>(r); | 693 test_divmod<int32_t>(r); |
696 } | 694 } |
697 | 695 |
698 DEF_TEST(divmod_s64, r) { | 696 DEF_TEST(divmod_s64, r) { |
699 test_divmod<int64_t>(r); | 697 test_divmod<int64_t>(r); |
700 } | 698 } |
OLD | NEW |