Blargh
This commit is contained in:
14
src/main.rs
14
src/main.rs
@ -70,7 +70,7 @@ fn load_wallpaper(path: &Path) -> eyre::Result<GrayAlphaImage> {
|
|||||||
|
|
||||||
match image_dimensions {
|
match image_dimensions {
|
||||||
(SCREEN_W, SCREEN_H) => {}
|
(SCREEN_W, SCREEN_H) => {}
|
||||||
(SCREEN_H, SCREEN_W) => image = image.rotate270(),
|
(SCREEN_H, SCREEN_W) => image = image.rotate90(),
|
||||||
_ => bail!("Image must be {SCREEN_W}x{SCREEN_H}"),
|
_ => bail!("Image must be {SCREEN_W}x{SCREEN_H}"),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,12 +114,20 @@ fn image_to_offimage_buffer(image: GrayAlphaImage) -> eyre::Result<Box<[u8; IOCT
|
|||||||
let image = image.into_vec();
|
let image = image.into_vec();
|
||||||
|
|
||||||
ensure!(
|
ensure!(
|
||||||
image.len() / 2 + 1 == IOCTL_BUFFER_SIZE,
|
image.len() / 2 == SCREEN_W * SCREEN_H,
|
||||||
"Invalid size of image backing buffer. Bug?",
|
"Invalid size of image backing buffer. Bug?",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// iterate over pixel coordinates
|
||||||
|
let xs = 0..SCREEN_W;
|
||||||
|
let ys = 0..SCREEN_H;
|
||||||
|
let ys = ys.rev(); // flip `y`, it's reversed in the ioctl buffer.
|
||||||
|
let coords = ys.flat_map(|y| xs.clone().map(move |x| (x, y)));
|
||||||
|
// coordinates to indices
|
||||||
|
let indices = coords.map(|(x, y)| y * SCREEN_W + x);
|
||||||
|
|
||||||
// Iterate over pixels and copy them into `buf`.
|
// Iterate over pixels and copy them into `buf`.
|
||||||
for (i, pixel) in (0..buf.len() - 1).rev().zip(image.chunks_exact(2)) {
|
for (i, pixel) in indices.zip(image.chunks_exact(2)) {
|
||||||
let &[gray, alpha] = pixel else {
|
let &[gray, alpha] = pixel else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user