Skip to content

Commit

Permalink
fixes after image crate bump
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Fenoll <[email protected]>
  • Loading branch information
fenollp committed Jul 27, 2024
1 parent 9f01dee commit d9efab8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
7 changes: 4 additions & 3 deletions examples/live.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use image::{
use image::codecs::{
bmp::BmpEncoder, gif::GifEncoder, jpeg::JpegEncoder, png::PngEncoder, tga::TgaEncoder,
ColorType::Rgb8, ImageFormat,
};
use image::ImageEncoder;
use image::{ExtendedColorType::Rgb8, ImageFormat};
use libremarkable::framebuffer;
use libremarkable::framebuffer::common::{DISPLAYHEIGHT, DISPLAYWIDTH};
use libremarkable::framebuffer::core::Framebuffer;
Expand Down Expand Up @@ -76,7 +77,7 @@ fn encode(img_buf: &[u8], format: ImageFormat) -> Vec<u8> {
ImageFormat::Bmp => BmpEncoder::new(&mut writer).encode(img_buf, width, height, Rgb8),
ImageFormat::Gif => GifEncoder::new(&mut writer).encode(img_buf, width, height, Rgb8),
ImageFormat::Jpeg => JpegEncoder::new(&mut writer).encode(img_buf, width, height, Rgb8),
ImageFormat::Png => PngEncoder::new(&mut writer).encode(img_buf, width, height, Rgb8),
ImageFormat::Png => PngEncoder::new(&mut writer).write_image(img_buf, width, height, Rgb8),
ImageFormat::Tga => TgaEncoder::new(&mut writer).encode(img_buf, width, height, Rgb8),
_ => unimplemented!(),
}
Expand Down
34 changes: 13 additions & 21 deletions examples/screenshot.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use image::{DynamicImage, ImageOutputFormat};
use image::{DynamicImage, ImageFormat};

use libremarkable::framebuffer::common::*;
use libremarkable::framebuffer::core::*;
Expand Down Expand Up @@ -27,25 +27,17 @@ fn main() {
let image =
RgbImage::from_raw(width, height, contents).expect("unable to construct the rgb image");

let args = std::env::args().collect::<Vec<_>>();
let Some(path) = std::env::args().nth(1) else {
panic!("First argument must be the path to the PNG we will be writing")
};

match args.get(1) {
Some(path) => {
let mut output_file = OpenOptions::new()
.write(true)
.create(true)
.truncate(false)
.open(path)
.expect("Invalid path provided as argument!");
DynamicImage::ImageRgb8(image)
.write_to(&mut output_file, ImageOutputFormat::Png)
.expect("failed while writing to output file");
}
None => {
let mut stdout = std::io::stdout();
DynamicImage::ImageRgb8(image)
.write_to(&mut stdout, ImageOutputFormat::Png)
.expect("failed while writing to stdout");
}
}
let mut output_file = OpenOptions::new()
.write(true)
.create(true)
.truncate(false)
.open(path)
.expect("Invalid path provided as argument!");
DynamicImage::ImageRgb8(image)
.write_to(&mut output_file, ImageFormat::Png)
.expect("failed while writing to output file");
}

0 comments on commit d9efab8

Please sign in to comment.