Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: tests/Float16Test.cpp

Issue 2159993003: Improve naive SkColorXform to half floats (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Prettier code Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/opts/SkNx_sse.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 float f = SkHalfToFloat(h); 66 float f = SkHalfToFloat(h);
67 if (isfinite(f)) { 67 if (isfinite(f)) {
68 float got = SkHalfToFloat_finite(h)[0]; 68 float got = SkHalfToFloat_finite(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_finite(h)[0] == f);
76 REPORTER_ASSERT(r, SkFloatToHalf_finite(SkHalfToFloat_finite(h)) == h); 76 uint64_t result;
77 SkFloatToHalf_finite(SkHalfToFloat_finite(h)).store(&result);
78 REPORTER_ASSERT(r, result == h);
77 } 79 }
78 } 80 }
79 } 81 }
80 82
81 DEF_TEST(FloatToHalf_finite, r) { 83 DEF_TEST(FloatToHalf_finite, r) {
82 #if 0 84 #if 0
83 for (uint64_t bits = 0; bits <= 0xffffffff; bits++) { 85 for (uint64_t bits = 0; bits <= 0xffffffff; bits++) {
84 #else 86 #else
85 SkRandom rand; 87 SkRandom rand;
86 for (int i = 0; i < 1000000; i++) { 88 for (int i = 0; i < 1000000; i++) {
87 uint32_t bits = rand.nextU(); 89 uint32_t bits = rand.nextU();
88 #endif 90 #endif
89 float f; 91 float f;
90 memcpy(&f, &bits, 4); 92 memcpy(&f, &bits, 4);
91 if (isfinite(f) && isfinite(SkHalfToFloat(SkFloatToHalf(f)))) { 93 if (isfinite(f) && isfinite(SkHalfToFloat(SkFloatToHalf(f)))) {
92 uint16_t h1 = (uint16_t)SkFloatToHalf_finite(Sk4f(f,0,0,0)), 94 uint16_t h1 = SkFloatToHalf_finite(Sk4f(f,0,0,0))[0],
93 h2 = SkFloatToHalf(f); 95 h2 = SkFloatToHalf(f);
94 bool ok = (h1 == h2 || h1 == h2-1); 96 bool ok = (h1 == h2 || h1 == h2-1);
95 REPORTER_ASSERT(r, ok); 97 REPORTER_ASSERT(r, ok);
96 if (!ok) { 98 if (!ok) {
97 SkDebugf("%08x (%g) -> %04x, want %04x (%g)\n", 99 SkDebugf("%08x (%g) -> %04x, want %04x (%g)\n",
98 bits, f, h1, h2, SkHalfToFloat(h2)); 100 bits, f, h1, h2, SkHalfToFloat(h2));
99 break; 101 break;
100 } 102 }
101 } 103 }
102 } 104 }
103 } 105 }
OLDNEW
« no previous file with comments | « src/opts/SkNx_sse.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698