Extract conversion from u16 fixed-point to float
PR #3369 <https://github.com/Genymobile/scrcpy/pull/3369>
This commit is contained in:
parent
5b8e9aa0e9
commit
3848ce86f1
2 changed files with 13 additions and 4 deletions
|
@ -12,4 +12,16 @@ public final class Binary {
|
||||||
public static int toUnsigned(byte value) {
|
public static int toUnsigned(byte value) {
|
||||||
return value & 0xff;
|
return value & 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert unsigned 16-bit fixed-point to a float between 0 and 1
|
||||||
|
*
|
||||||
|
* @param value encoded value
|
||||||
|
* @return Float value between 0 and 1
|
||||||
|
*/
|
||||||
|
public static float u16FixedPointToFloat(short value) {
|
||||||
|
int unsignedShort = Binary.toUnsigned(value);
|
||||||
|
// 0x1p16f is 2^16 as float
|
||||||
|
return unsignedShort == 0xffff ? 1f : (unsignedShort / 0x1p16f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,10 +139,7 @@ public class ControlMessageReader {
|
||||||
int action = Binary.toUnsigned(buffer.get());
|
int action = Binary.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 = Binary.u16FixedPointToFloat(buffer.getShort());
|
||||||
int pressureInt = Binary.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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue