mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-07-28 11:49:10 +00:00
Extract conversion from fixed-point u16 to float
So that it can be reused for other fields. PR #3369 <https://github.com/Genymobile/scrcpy/pull/3369>
This commit is contained in:
parent
db8c1ce8e1
commit
72ff957e9a
1 changed files with 7 additions and 4 deletions
|
@ -139,10 +139,7 @@ public class ControlMessageReader {
|
|||
int action = toUnsigned(buffer.get());
|
||||
long pointerId = buffer.getLong();
|
||||
Position position = readPosition(buffer);
|
||||
// 16 bits fixed-point
|
||||
int pressureInt = toUnsigned(buffer.getShort());
|
||||
// convert it to a float between 0 and 1 (0x1p16f is 2^16 as float)
|
||||
float pressure = pressureInt == 0xffff ? 1f : (pressureInt / 0x1p16f);
|
||||
float pressure = fixedPointToFloat(buffer.getShort());
|
||||
int buttons = buffer.getInt();
|
||||
return ControlMessage.createInjectTouchEvent(action, pointerId, position, pressure, buttons);
|
||||
}
|
||||
|
@ -210,4 +207,10 @@ public class ControlMessageReader {
|
|||
private static int toUnsigned(byte value) {
|
||||
return value & 0xff;
|
||||
}
|
||||
|
||||
private static float fixedPointToFloat(short value) {
|
||||
int unsignedShort = toUnsigned(value);
|
||||
// convert 16 bits fixed-point to a float between 0 and 1 (0x1p16f is 2^16 as float)
|
||||
return unsignedShort == 0xffff ? 1f : (unsignedShort / 0x1p16f);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue