diff options
author | Jason Ekstrand <[email protected]> | 2016-08-03 09:39:00 -0700 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2016-08-05 09:06:59 -0700 |
commit | cda8d9566043a75dbe0bc3eaf75c61e37b65d792 (patch) | |
tree | 54e5709e9e35872351b0ae99b92a4c2bc5d4ec7c /src/util/format_rgb9e5.h | |
parent | f29fd7897adc920ef816840a3f4fc25dcd65228b (diff) |
util/format_rgb9e5: Get rid of the rgb9e5 union
The rgb9e5 format is a packed format defined in terms of slicing up a
single 32-bit value. The bitfields are far more confusing than simple
shifts and require that we check the endianness.
Signed-off-by: Jason Ekstrand <[email protected]>
Reviewed-by: Roland Scheidegger <[email protected]>
Diffstat (limited to 'src/util/format_rgb9e5.h')
-rw-r--r-- | src/util/format_rgb9e5.h | 38 |
1 files changed, 6 insertions, 32 deletions
diff --git a/src/util/format_rgb9e5.h b/src/util/format_rgb9e5.h index 21feba7b710..644b9d888e3 100644 --- a/src/util/format_rgb9e5.h +++ b/src/util/format_rgb9e5.h @@ -57,24 +57,6 @@ typedef union { } field; } float754; -typedef union { - unsigned int raw; - struct { -#if defined(MESA_BIG_ENDIAN) || defined(PIPE_ARCH_BIG_ENDIAN) - unsigned int biasedexponent:RGB9E5_EXPONENT_BITS; - unsigned int b:RGB9E5_MANTISSA_BITS; - unsigned int g:RGB9E5_MANTISSA_BITS; - unsigned int r:RGB9E5_MANTISSA_BITS; -#else - unsigned int r:RGB9E5_MANTISSA_BITS; - unsigned int g:RGB9E5_MANTISSA_BITS; - unsigned int b:RGB9E5_MANTISSA_BITS; - unsigned int biasedexponent:RGB9E5_EXPONENT_BITS; -#endif - } field; -} rgb9e5; - - static inline int rgb9e5_ClampRange(float x) { float754 f; @@ -91,9 +73,8 @@ static inline int rgb9e5_ClampRange(float x) return f.raw; } -static inline unsigned float3_to_rgb9e5(const float rgb[3]) +static inline unsigned int float3_to_rgb9e5(const float rgb[3]) { - rgb9e5 retval; int rm, gm, bm, exp_shared; float754 revdenom = {0}; float754 rc, bc, gc, maxrgb; @@ -135,27 +116,20 @@ static inline unsigned float3_to_rgb9e5(const float rgb[3]) assert(gm >= 0); assert(bm >= 0); - retval.field.r = rm; - retval.field.g = gm; - retval.field.b = bm; - retval.field.biasedexponent = exp_shared; - - return retval.raw; + return (exp_shared << 27) | (bm << 18) | (gm << 9) | rm; } static inline void rgb9e5_to_float3(unsigned rgb, float retval[3]) { - rgb9e5 v; int exponent; float754 scale = {0}; - v.raw = rgb; - exponent = v.field.biasedexponent - RGB9E5_EXP_BIAS - RGB9E5_MANTISSA_BITS; + exponent = (rgb >> 27) - RGB9E5_EXP_BIAS - RGB9E5_MANTISSA_BITS; scale.field.biasedexponent = exponent + 127; - retval[0] = v.field.r * scale.value; - retval[1] = v.field.g * scale.value; - retval[2] = v.field.b * scale.value; + retval[0] = ( rgb & 0x1ff) * scale.value; + retval[1] = ((rgb >> 9) & 0x1ff) * scale.value; + retval[2] = ((rgb >> 18) & 0x1ff) * scale.value; } #endif |