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

Side by Side Diff: tests/Float16Test.cpp

Issue 1686543003: skeleton for float <-> half optimized procs (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: bench Created 4 years, 10 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/core/SkOpts.cpp ('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 "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
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 }
OLDNEW
« no previous file with comments | « src/core/SkOpts.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698