feat: add image display mode

This commit is contained in:
Xiretza 2022-06-17 21:06:04 +02:00
parent 8ab9cd7010
commit e383197483

View file

@ -5,6 +5,7 @@ use std::{
io::stdout,
net::{Ipv4Addr, SocketAddr, UdpSocket},
num::ParseIntError,
path::PathBuf,
str::FromStr,
thread::sleep,
time::Duration,
@ -12,7 +13,7 @@ use std::{
use bracket_color::prelude::{HSV, RGB};
use clap::{Parser, Subcommand};
use image::{Pixel, Rgb, RgbImage};
use image::{imageops::FilterType, io::Reader as ImageReader, Pixel, Rgb, RgbImage};
use rand::Rng;
use splink_client::{send_frame, Layout};
@ -81,6 +82,7 @@ impl From<Color> for Rgb<u8> {
enum Action {
Rainbow,
Solid { color: Color },
Image { path: PathBuf },
Clear,
}
@ -190,6 +192,14 @@ fn main() -> anyhow::Result<()> {
let frame_num: u32 = rand::thread_rng().gen();
send_frame(&socket, layout, frame_num, &image)?;
}
Action::Image { path } => {
let image = ImageReader::open(path)?
.decode()?
.resize_to_fill(layout.width_px(), layout.height_px(), FilterType::Gaussian)
.into_rgb8();
let frame_num: u32 = rand::thread_rng().gen();
send_frame(&socket, layout, frame_num, &image)?;
}
Action::Rainbow => {
print!("{}", termion::clear::All);