mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-04-27 16:09:58 -07:00
add config and read files from binary
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use image::{io::Reader as ImageReader, AnimationDecoder, imageops::FilterType, codecs::gif::GifDecoder, DynamicImage};
|
||||
use std::{io::BufReader, fs::File, time::Duration};
|
||||
use image::{codecs::gif::GifDecoder, imageops::FilterType, AnimationDecoder, DynamicImage};
|
||||
use std::{io::Cursor, time::Duration};
|
||||
use include_dir::{include_dir, Dir};
|
||||
|
||||
const FB_PATH:&str = "/dev/fb0";
|
||||
@@ -30,9 +30,18 @@ impl Framebuffer<'_>{
|
||||
|
||||
fn write(&mut self, img: DynamicImage) {
|
||||
|
||||
let resized_img = img.resize( self.dimensions.width, self.dimensions.height, FilterType::CatmullRom);
|
||||
let width = self.dimensions.width.min(resized_img.width());
|
||||
let height = self.dimensions.height.min(resized_img.height());
|
||||
let mut width = img.width();
|
||||
let mut height = img.height();
|
||||
let resized_img: DynamicImage;
|
||||
if height > self.dimensions.height ||
|
||||
width > self.dimensions.width {
|
||||
resized_img = img.resize( self.dimensions.width, self.dimensions.height, FilterType::CatmullRom);
|
||||
width = self.dimensions.width.min(resized_img.width());
|
||||
height = self.dimensions.height.min(resized_img.height());
|
||||
|
||||
} else {
|
||||
resized_img = img;
|
||||
}
|
||||
let img_rgba8 = resized_img.as_rgba8().unwrap();
|
||||
let mut buf = Vec::new();
|
||||
for y in 0..height {
|
||||
@@ -49,12 +58,11 @@ impl Framebuffer<'_>{
|
||||
|
||||
|
||||
pub fn draw_img(&mut self, img_name: &str) {
|
||||
//let img_path = IMAGE_DIR.get_file(img_name).unwrap().path();
|
||||
let img_path = img_name;
|
||||
if img_path.ends_with(".gif") {
|
||||
let img = IMAGE_DIR.get_file(img_name).unwrap();
|
||||
if img_name.ends_with(".gif") {
|
||||
// this is dumb and i'm sure there's a better way to loop this
|
||||
let stream = BufReader::new(File::open(&img_path).unwrap());
|
||||
let decoder = GifDecoder::new(stream).unwrap();
|
||||
let cursor = Cursor::new(img.contents());
|
||||
let decoder = GifDecoder::new(cursor).unwrap();
|
||||
for maybe_frame in decoder.into_frames() {
|
||||
let frame = maybe_frame.unwrap();
|
||||
let (numerator, _) = frame.delay().numer_denom_ms();
|
||||
@@ -63,8 +71,7 @@ impl Framebuffer<'_>{
|
||||
std::thread::sleep(Duration::from_millis(numerator as u64));
|
||||
}
|
||||
} else {
|
||||
let img_reader = ImageReader::open(img_path).unwrap();
|
||||
let img = img_reader.decode().unwrap();
|
||||
let img = image::load_from_memory(img.contents()).unwrap();
|
||||
self.write(img);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user