Extract conversion from float to u16 fixed-point
PR #3369 <https://github.com/Genymobile/scrcpy/pull/3369>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -43,4 +44,18 @@ sc_read64be(const uint8_t *buf) {
|
||||
return ((uint64_t) msb << 32) | lsb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a float between 0 and 1 to an unsigned 16-bit fixed-point value
|
||||
*/
|
||||
static inline uint16_t
|
||||
sc_float_to_u16fp(float f) {
|
||||
assert(f >= 0.0f && f <= 1.0f);
|
||||
uint32_t u = f * 0x1p16f; // 2^16
|
||||
if (u >= 0xffff) {
|
||||
assert(u == 0x10000); // for f == 1.0f
|
||||
u = 0xffff;
|
||||
}
|
||||
return (uint16_t) u;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user