fix endianness handling for binary coordinates

This commit is contained in:
Johann150
2023-12-29 00:49:06 +01:00
parent 04f54936b9
commit 2928144bca

View File

@@ -50,21 +50,19 @@ impl Client {
/// Write a pixel to the given stream. /// Write a pixel to the given stream.
pub fn write_pixel(&mut self, x: u16, y: u16, color: Color) -> Result<(), Error> { pub fn write_pixel(&mut self, x: u16, y: u16, color: Color) -> Result<(), Error> {
if self.binary { if self.binary {
self.write_command( let mut data = [
&[ b'P', b'B',
b'P', // these values will be filled in using to_le_bytes in the next step
b'B', // to account for the machines endianness
x as u8, 0, // x LSB
(x >> 8) as u8, 0, // x MSB
y as u8, 0, // y LSB
(y >> 8) as u8, 0, // y MSB
color.r, color.r, color.g, color.b, color.a,
color.g, ];
color.b, data[2..4].copy_from_slice(&x.to_le_bytes());
color.a, data[4..6].copy_from_slice(&y.to_le_bytes());
], self.write_command(&data, false)
false,
)
} else { } else {
self.write_command( self.write_command(
format!("PX {} {} {}", x, y, color.as_hex()).as_bytes(), format!("PX {} {} {}", x, y, color.as_hex()).as_bytes(),