mirror of
https://github.com/Genymobile/scrcpy.git
synced 2026-04-21 01:33:36 +00:00
Add conversion from float to fixed-point i16
To encode float values between -1 and 1. PR #3369 <https://github.com/Genymobile/scrcpy/pull/3369>
This commit is contained in:
parent
1ab6c19486
commit
1f138aef41
4 changed files with 68 additions and 0 deletions
|
|
@ -58,4 +58,19 @@ sc_float_to_u16fp(float f) {
|
|||
return (uint16_t) u;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a float between -1 and 1 to a signed 16-bit fixed-point value
|
||||
*/
|
||||
static inline int16_t
|
||||
sc_float_to_i16fp(float f) {
|
||||
assert(f >= -1.0f && f <= 1.0f);
|
||||
int32_t i = f * 0x1p15f; // 2^15
|
||||
assert(i >= -0x8000);
|
||||
if (i >= 0x7fff) {
|
||||
assert(i == 0x8000); // for f == 1.0f
|
||||
i = 0x7fff;
|
||||
}
|
||||
return (int16_t) i;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue