2014-11-26 21:15:59 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkHalf_DEFINED
|
|
|
|
#define SkHalf_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
2022-05-17 20:26:03 +00:00
|
|
|
#include "include/private/SkVx.h"
|
2014-11-26 21:15:59 +00:00
|
|
|
|
|
|
|
// 16-bit floating point value
|
|
|
|
// format is 1 bit sign, 5 bits exponent, 10 bits mantissa
|
|
|
|
// only used for storage
|
|
|
|
typedef uint16_t SkHalf;
|
|
|
|
|
2017-04-19 21:19:30 +00:00
|
|
|
static constexpr uint16_t SK_HalfMin = 0x0400; // 2^-14 (minimum positive normal value)
|
2016-07-19 16:07:55 +00:00
|
|
|
static constexpr uint16_t SK_HalfMax = 0x7bff; // 65504
|
|
|
|
static constexpr uint16_t SK_HalfEpsilon = 0x1400; // 2^-10
|
|
|
|
static constexpr uint16_t SK_Half1 = 0x3C00; // 1
|
2014-12-05 21:06:35 +00:00
|
|
|
|
2014-11-26 21:15:59 +00:00
|
|
|
// convert between half and single precision floating point
|
2019-01-23 01:00:22 +00:00
|
|
|
float SkHalfToFloat(SkHalf h);
|
|
|
|
SkHalf SkFloatToHalf(float f);
|
2014-11-26 21:15:59 +00:00
|
|
|
|
2016-07-15 14:00:11 +00:00
|
|
|
// Convert between half and single precision floating point,
|
2016-08-23 15:58:12 +00:00
|
|
|
// assuming inputs and outputs are both finite, and may
|
|
|
|
// flush values which would be denormal half floats to zero.
|
2022-05-17 20:26:03 +00:00
|
|
|
static inline skvx::float4 SkHalfToFloat_finite_ftz(uint64_t rgba) {
|
|
|
|
return skvx::from_half(skvx::half4::Load(&rgba));
|
2016-02-11 14:30:03 +00:00
|
|
|
}
|
2022-05-17 20:26:03 +00:00
|
|
|
static inline skvx::half4 SkFloatToHalf_finite_ftz(const skvx::float4& c) {
|
|
|
|
return skvx::to_half(c);
|
2016-02-11 14:30:03 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 21:15:59 +00:00
|
|
|
#endif
|