Skip to content

Commit

Permalink
client: Fix endianness in simple_window example
Browse files Browse the repository at this point in the history
Haven't tested on a big-endian system, but this should be correct.

It seems redundant to use bitshifts only to convert with `to_*_bytes`,
so just use an array.

Fixes #385.
  • Loading branch information
ids1024 committed Jan 16, 2024
1 parent bbcafb7 commit 2a25e81
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions wayland-client/examples/simple_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ fn draw(tmp: &mut File, (buf_x, buf_y): (u32, u32)) {
let r = min(((buf_x - x) * 0xFF) / buf_x, ((buf_y - y) * 0xFF) / buf_y);
let g = min((x * 0xFF) / buf_x, ((buf_y - y) * 0xFF) / buf_y);
let b = min(((buf_x - x) * 0xFF) / buf_x, (y * 0xFF) / buf_y);

let color = (a << 24) + (r << 16) + (g << 8) + b;
buf.write_all(&color.to_ne_bytes()).unwrap();
buf.write_all(&[b as u8, g as u8, r as u8, a as u8]).unwrap();
}
}
buf.flush().unwrap();
Expand Down

0 comments on commit 2a25e81

Please sign in to comment.