• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014 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 #ifndef SkHalf_DEFINED
9 #define SkHalf_DEFINED
10 
11 #include "src/base/SkVx.h"
12 
13 // 16-bit floating point value
14 // format is 1 bit sign, 5 bits exponent, 10 bits mantissa
15 // only used for storage
16 typedef uint16_t SkHalf;
17 
18 static constexpr uint16_t SK_HalfMin     = 0x0400; // 2^-14  (minimum positive normal value)
19 static constexpr uint16_t SK_HalfMax     = 0x7bff; // 65504
20 static constexpr uint16_t SK_HalfEpsilon = 0x1400; // 2^-10
21 static constexpr uint16_t SK_Half1       = 0x3C00; // 1
22 
23 // convert between half and single precision floating point
24 float SkHalfToFloat(SkHalf h);
25 SkHalf SkFloatToHalf(float f);
26 
27 // Convert between half and single precision floating point,
28 // assuming inputs and outputs are both finite, and may
29 // flush values which would be denormal half floats to zero.
SkHalfToFloat_finite_ftz(uint64_t rgba)30 static inline skvx::float4 SkHalfToFloat_finite_ftz(uint64_t rgba) {
31     return skvx::from_half(skvx::half4::Load(&rgba));
32 }
SkFloatToHalf_finite_ftz(const skvx::float4 & c)33 static inline skvx::half4 SkFloatToHalf_finite_ftz(const skvx::float4& c) {
34     return skvx::to_half(c);
35 }
36 
37 #endif
38