#ifndef FORMAT_UTILS_H
#define FORMAT_UTILS_H
+#include "formats.h"
#include "imports.h"
#include "macros.h"
+#include "util/rounding.h"
+#include "util/half_float.h"
extern const mesa_array_format RGBA32_FLOAT;
extern const mesa_array_format RGBA8_UBYTE;
else if (x > 1.0f)
return MAX_UINT(dst_bits);
else
- return F_TO_I(x * MAX_UINT(dst_bits));
+ return _mesa_i64roundevenf(x * MAX_UINT(dst_bits));
}
static inline unsigned
{
if (src_bits < dst_bits) {
return EXTEND_NORMALIZED_INT(x, src_bits, dst_bits);
- } else {
+ } else if (src_bits > dst_bits) {
unsigned src_half = (1 << (src_bits - 1)) - 1;
if (src_bits + dst_bits > sizeof(x) * 8) {
} else {
return (x * MAX_UINT(dst_bits) + src_half) / MAX_UINT(src_bits);
}
+ } else {
+ return x;
}
}
else if (x > 1.0f)
return MAX_INT(dst_bits);
else
- return F_TO_I(x * MAX_INT(dst_bits));
+ return _mesa_lroundevenf(x * MAX_INT(dst_bits));
}
static inline int
static inline int
_mesa_unsigned_to_signed(unsigned src, unsigned dst_size)
{
- return MIN2(src, MAX_INT(dst_size));
+ return MIN2(src, (unsigned)MAX_INT(dst_size));
}
static inline int