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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user