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:
@@ -139,10 +139,7 @@ public class ControlMessageReader {
|
|||||||
int action = toUnsigned(buffer.get());
|
int action = toUnsigned(buffer.get());
|
||||||
long pointerId = buffer.getLong();
|
long pointerId = buffer.getLong();
|
||||||
Position position = readPosition(buffer);
|
Position position = readPosition(buffer);
|
||||||
// 16 bits fixed-point
|
float pressure = fixedPointToFloat(buffer.getShort());
|
||||||
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);
|
|
||||||
int buttons = buffer.getInt();
|
int buttons = buffer.getInt();
|
||||||
return ControlMessage.createInjectTouchEvent(action, pointerId, position, pressure, buttons);
|
return ControlMessage.createInjectTouchEvent(action, pointerId, position, pressure, buttons);
|
||||||
}
|
}
|
||||||
@@ -210,4 +207,10 @@ public class ControlMessageReader {
|
|||||||
private static int toUnsigned(byte value) {
|
private static int toUnsigned(byte value) {
|
||||||
return value & 0xff;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user