OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "Test.h" |
| 9 #include "SkColor.h" |
| 10 #include "SkHalf.h" |
| 11 #include "SkPixmap.h" |
| 12 |
| 13 static bool eq_within_half_float(float a, float b) { |
| 14 const float kTolerance = 1.0f / (1 << (8 + 10)); |
| 15 |
| 16 SkHalf ha = SkFloatToHalf(a); |
| 17 SkHalf hb = SkFloatToHalf(b); |
| 18 float a2 = SkHalfToFloat(ha); |
| 19 float b2 = SkHalfToFloat(hb); |
| 20 return fabsf(a2 - b2) <= kTolerance; |
| 21 } |
| 22 |
| 23 static bool eq_within_half_float(const SkPM4f& a, const SkPM4f& b) { |
| 24 for (int i = 0; i < 4; ++i) { |
| 25 if (!eq_within_half_float(a.fVec[i], b.fVec[i])) { |
| 26 return false; |
| 27 } |
| 28 } |
| 29 return true; |
| 30 } |
| 31 |
| 32 DEF_TEST(color_half_float, reporter) { |
| 33 const int w = 100; |
| 34 const int h = 100; |
| 35 |
| 36 SkImageInfo info = SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_Sk
AlphaType); |
| 37 |
| 38 SkAutoPixmapStorage pm; |
| 39 pm.alloc(info); |
| 40 REPORTER_ASSERT(reporter, pm.getSafeSize() == SkToSizeT(w * h * sizeof(uint6
4_t))); |
| 41 |
| 42 SkColor4f c4 { 0.5f, 1, 0.5f, 0.25f }; |
| 43 pm.erase(c4); |
| 44 |
| 45 SkPM4f origpm4 = c4.premul(); |
| 46 for (int y = 0; y < pm.height(); ++y) { |
| 47 for (int x = 0; x < pm.width(); ++x) { |
| 48 SkPM4f pm4 = SkPM4f::FromF16(pm.addrF16(x, y)); |
| 49 REPORTER_ASSERT(reporter, eq_within_half_float(origpm4, pm4)); |
| 50 } |
| 51 } |
| 52 } |
OLD | NEW |