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

Unified Diff: tests/Float16Test.cpp

Issue 1666343002: add kRGBA_F16_SkColorType (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add unittest 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/SkGr.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/Float16Test.cpp
diff --git a/tests/Float16Test.cpp b/tests/Float16Test.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0a2c3d5d6b62b09fc523aeb633655b4f124bb8ac
--- /dev/null
+++ b/tests/Float16Test.cpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Test.h"
+#include "SkColor.h"
+#include "SkHalf.h"
+#include "SkPixmap.h"
+
+static bool eq_within_half_float(float a, float b) {
+ const float kTolerance = 1.0f / (1 << (8 + 10));
+
+ SkHalf ha = SkFloatToHalf(a);
+ SkHalf hb = SkFloatToHalf(b);
+ float a2 = SkHalfToFloat(ha);
+ float b2 = SkHalfToFloat(hb);
+ return fabsf(a2 - b2) <= kTolerance;
+}
+
+static bool eq_within_half_float(const SkPM4f& a, const SkPM4f& b) {
+ for (int i = 0; i < 4; ++i) {
+ if (!eq_within_half_float(a.fVec[i], b.fVec[i])) {
+ return false;
+ }
+ }
+ return true;
+}
+
+DEF_TEST(color_half_float, reporter) {
+ const int w = 100;
+ const int h = 100;
+
+ SkImageInfo info = SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType);
+
+ SkAutoPixmapStorage pm;
+ pm.alloc(info);
+ REPORTER_ASSERT(reporter, pm.getSafeSize() == SkToSizeT(w * h * sizeof(uint64_t)));
+
+ SkColor4f c4 { 0.5f, 1, 0.5f, 0.25f };
+ pm.erase(c4);
+
+ SkPM4f origpm4 = c4.premul();
+ for (int y = 0; y < pm.height(); ++y) {
+ for (int x = 0; x < pm.width(); ++x) {
+ SkPM4f pm4 = SkPM4f::FromF16(pm.addrF16(x, y));
+ REPORTER_ASSERT(reporter, eq_within_half_float(origpm4, pm4));
+ }
+ }
+}
« no previous file with comments | « src/gpu/SkGr.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698