| 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 "SkAutoPixmapStorage.h" | 9 #include "SkAutoPixmapStorage.h" |
| 10 #include "SkColor.h" | 10 #include "SkColor.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 static uint32_t u(float f) { | 58 static uint32_t u(float f) { |
| 59 uint32_t x; | 59 uint32_t x; |
| 60 memcpy(&x, &f, 4); | 60 memcpy(&x, &f, 4); |
| 61 return x; | 61 return x; |
| 62 } | 62 } |
| 63 | 63 |
| 64 DEF_TEST(HalfToFloat_finite, r) { | 64 DEF_TEST(HalfToFloat_01, r) { |
| 65 for (uint32_t h = 0; h <= 0xffff; h++) { | 65 for (uint16_t h = 0; h < 0x8000; h++) { |
| 66 float f = SkHalfToFloat(h); | 66 float f = SkHalfToFloat(h); |
| 67 if (isfinite(f)) { | 67 if (f >= 0 && f <= 1) { |
| 68 float got = SkHalfToFloat_finite(h)[0]; | 68 float got = SkHalfToFloat_01(h)[0]; |
| 69 if (got != f) { | 69 if (got != f) { |
| 70 SkDebugf("0x%04x -> 0x%08x (%g), want 0x%08x (%g)\n", | 70 SkDebugf("0x%04x -> 0x%08x (%g), want 0x%08x (%g)\n", |
| 71 h, | 71 h, |
| 72 u(got), got, | 72 u(got), got, |
| 73 u(f), f); | 73 u(f), f); |
| 74 } | 74 } |
| 75 REPORTER_ASSERT(r, SkHalfToFloat_finite(h)[0] == f); | 75 REPORTER_ASSERT(r, SkHalfToFloat_01(h)[0] == f); |
| 76 REPORTER_ASSERT(r, SkFloatToHalf_finite(SkHalfToFloat_finite(h)) ==
h); | 76 REPORTER_ASSERT(r, SkFloatToHalf_01(SkHalfToFloat_01(h)) == h); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 | 80 |
| 81 DEF_TEST(FloatToHalf_finite, r) { | 81 DEF_TEST(FloatToHalf_01, r) { |
| 82 #if 0 | 82 #if 0 |
| 83 for (uint64_t bits = 0; bits <= 0xffffffff; bits++) { | 83 for (uint32_t bits = 0; bits < 0x80000000; bits++) { |
| 84 #else | 84 #else |
| 85 SkRandom rand; | 85 SkRandom rand; |
| 86 for (int i = 0; i < 1000000; i++) { | 86 for (int i = 0; i < 1000000; i++) { |
| 87 uint32_t bits = rand.nextU(); | 87 uint32_t bits = rand.nextU(); |
| 88 #endif | 88 #endif |
| 89 float f; | 89 float f; |
| 90 memcpy(&f, &bits, 4); | 90 memcpy(&f, &bits, 4); |
| 91 if (isfinite(f) && isfinite(SkHalfToFloat(SkFloatToHalf(f)))) { | 91 if (f >= 0 && f <= 1) { |
| 92 uint16_t h1 = (uint16_t)SkFloatToHalf_finite(Sk4f(f,0,0,0)), | 92 uint16_t h1 = (uint16_t)SkFloatToHalf_01(Sk4f(f,0,0,0)), |
| 93 h2 = SkFloatToHalf(f); | 93 h2 = SkFloatToHalf(f); |
| 94 bool ok = (h1 == h2 || h1 == h2-1); | 94 bool ok = (h1 == h2 || h1 == h2-1); |
| 95 REPORTER_ASSERT(r, ok); | 95 REPORTER_ASSERT(r, ok); |
| 96 if (!ok) { | 96 if (!ok) { |
| 97 SkDebugf("%08x (%g) -> %04x, want %04x (%g)\n", | 97 SkDebugf("%08x (%d) -> %04x (%d), want %04x (%d)\n", |
| 98 bits, f, h1, h2, SkHalfToFloat(h2)); | 98 bits, bits>>23, h1, h1>>10, h2, h2>>10); |
| 99 break; | 99 break; |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 } | 103 } |
| OLD | NEW |