uitl: Add R1_UNORM to the list of noaccess (no pack/unpack) formats.
[mesa.git] / src / util / format_r11g11b10f.h
index 218822b16e6bd05834c99af37e4b262798e11105..ec5abf96119353c355bbe48167897e5ccb4ba7e6 100644 (file)
  * below.
  */
 
+#ifndef FORMAT_R11G11B10F_H
+#define FORMAT_R11G11B10F_H
+
+#include <stdint.h>
+
 #define UF11(e, m)           ((e << 6) | (m))
 #define UF11_EXPONENT_BIAS   15
 #define UF11_EXPONENT_BITS   0x1F
@@ -45,7 +50,7 @@
 
 #define F32_INFINITY         0x7f800000
 
-static inline unsigned f32_to_uf11(float val)
+static inline uint32_t f32_to_uf11(float val)
 {
    union {
       float f;
@@ -84,8 +89,7 @@ static inline unsigned f32_to_uf11(float val)
        *      converted to 65024."
        */
       uf11 = UF11(30, 63);
-   }
-   else if (exponent > -15) { /* Representable value */
+   } else if (exponent > -15) { /* Representable value */
       exponent += UF11_EXPONENT_BIAS;
       mantissa >>= UF11_MANTISSA_SHIFT;
       uf11 = exponent << UF11_EXPONENT_SHIFT | mantissa;
@@ -111,17 +115,14 @@ static inline float uf11_to_f32(uint16_t val)
          const float scale = 1.0 / (1 << 20);
          f32.f = scale * mantissa;
       }
-   }
-   else if (exponent == 31) {
+   } else if (exponent == 31) {
       f32.ui = F32_INFINITY | mantissa;
-   }
-   else {
+   } else {
       float scale, decimal;
       exponent -= 15;
       if (exponent < 0) {
          scale = 1.0f / (1 << -exponent);
-      }
-      else {
+      } else {
          scale = (float) (1 << exponent);
       }
       decimal = 1.0f + (float) mantissa / 64;
@@ -131,7 +132,7 @@ static inline float uf11_to_f32(uint16_t val)
    return f32.f;
 }
 
-static inline unsigned f32_to_uf10(float val)
+static inline uint32_t f32_to_uf10(float val)
 {
    union {
       float f;
@@ -170,8 +171,7 @@ static inline unsigned f32_to_uf10(float val)
        *      converted to 64512."
        */
       uf10 = UF10(30, 31);
-   }
-   else if (exponent > -15) { /* Representable value */
+   } else if (exponent > -15) { /* Representable value */
       exponent += UF10_EXPONENT_BIAS;
       mantissa >>= UF10_MANTISSA_SHIFT;
       uf10 = exponent << UF10_EXPONENT_SHIFT | mantissa;
@@ -194,14 +194,12 @@ static inline float uf10_to_f32(uint16_t val)
 
    if (exponent == 0) {
       if (mantissa != 0) {
-         const float scale = 1.0 / (1 << 20);
+         const float scale = 1.0 / (1 << 19);
          f32.f = scale * mantissa;
       }
-   }
-   else if (exponent == 31) {
+   } else if (exponent == 31) {
       f32.ui = F32_INFINITY | mantissa;
-   }
-   else {
+   } else {
       float scale, decimal;
       exponent -= 15;
       if (exponent < 0) {
@@ -217,16 +215,18 @@ static inline float uf10_to_f32(uint16_t val)
    return f32.f;
 }
 
-static inline unsigned float3_to_r11g11b10f(const float rgb[3])
+static inline uint32_t float3_to_r11g11b10f(const float rgb[3])
 {
    return ( f32_to_uf11(rgb[0]) & 0x7ff) |
           ((f32_to_uf11(rgb[1]) & 0x7ff) << 11) |
           ((f32_to_uf10(rgb[2]) & 0x3ff) << 22);
 }
 
-static inline void r11g11b10f_to_float3(unsigned rgb, float retval[3])
+static inline void r11g11b10f_to_float3(uint32_t rgb, float retval[3])
 {
    retval[0] = uf11_to_f32( rgb        & 0x7ff);
    retval[1] = uf11_to_f32((rgb >> 11) & 0x7ff);
    retval[2] = uf10_to_f32((rgb >> 22) & 0x3ff);
 }
+
+#endif /* FORMAT_R11G11B10F_H */