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:
Romain Vimont
2022-08-03 13:04:15 +02:00
parent 1ab6c19486
commit 1f138aef41
4 changed files with 68 additions and 0 deletions

View File

@@ -24,4 +24,15 @@ public final class Binary {
// 0x1p16f is 2^16 as float
return unsignedShort == 0xffff ? 1f : (unsignedShort / 0x1p16f);
}
/**
* Convert signed 16-bit fixed-point to a float between -1 and 1
*
* @param value encoded value
* @return Float value between -1 and 1
*/
public static float i16FixedPointToFloat(short value) {
// 0x1p15f is 2^15 as float
return value == 0x7fff ? 1f : (value / 0x1p15f);
}
}