OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "Test.h" | 8 #include "Test.h" |
9 #include "SkColor.h" | 9 #include "SkColor.h" |
10 #include "SkHalf.h" | 10 #include "SkHalf.h" |
| 11 #include "SkOpts.h" |
11 #include "SkPixmap.h" | 12 #include "SkPixmap.h" |
12 | 13 |
13 static bool eq_within_half_float(float a, float b) { | 14 static bool eq_within_half_float(float a, float b) { |
14 const float kTolerance = 1.0f / (1 << (8 + 10)); | 15 const float kTolerance = 1.0f / (1 << (8 + 10)); |
15 | 16 |
16 SkHalf ha = SkFloatToHalf(a); | 17 SkHalf ha = SkFloatToHalf(a); |
17 SkHalf hb = SkFloatToHalf(b); | 18 SkHalf hb = SkFloatToHalf(b); |
18 float a2 = SkHalfToFloat(ha); | 19 float a2 = SkHalfToFloat(ha); |
19 float b2 = SkHalfToFloat(hb); | 20 float b2 = SkHalfToFloat(hb); |
20 return fabsf(a2 - b2) <= kTolerance; | 21 return fabsf(a2 - b2) <= kTolerance; |
(...skipping 22 matching lines...) Expand all Loading... |
43 pm.erase(c4); | 44 pm.erase(c4); |
44 | 45 |
45 SkPM4f origpm4 = c4.premul(); | 46 SkPM4f origpm4 = c4.premul(); |
46 for (int y = 0; y < pm.height(); ++y) { | 47 for (int y = 0; y < pm.height(); ++y) { |
47 for (int x = 0; x < pm.width(); ++x) { | 48 for (int x = 0; x < pm.width(); ++x) { |
48 SkPM4f pm4 = SkPM4f::FromF16(pm.addrF16(x, y)); | 49 SkPM4f pm4 = SkPM4f::FromF16(pm.addrF16(x, y)); |
49 REPORTER_ASSERT(reporter, eq_within_half_float(origpm4, pm4)); | 50 REPORTER_ASSERT(reporter, eq_within_half_float(origpm4, pm4)); |
50 } | 51 } |
51 } | 52 } |
52 } | 53 } |
| 54 |
| 55 DEF_TEST(float_to_half, reporter) { |
| 56 const float fs[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7
.0 }; |
| 57 const uint16_t hs[] = { 0x3c00, 0x4000, 0x4200, 0x4400, 0x4500, 0x4600, 0x47
00 }; |
| 58 |
| 59 uint16_t hscratch[7]; |
| 60 SkOpts::float_to_half(hscratch, fs, 7); |
| 61 REPORTER_ASSERT(reporter, 0 == memcmp(hscratch, hs, sizeof(hs))); |
| 62 |
| 63 float fscratch[7]; |
| 64 SkOpts::half_to_float(fscratch, hs, 7); |
| 65 REPORTER_ASSERT(reporter, 0 == memcmp(fscratch, fs, sizeof(fs))); |
| 66 } |
OLD | NEW |