From 77e4f855ae4f5dc3d04cad8defe23442005c35fc Mon Sep 17 00:00:00 2001 From: Jaby Date: Mon, 19 Sep 2022 20:20:43 +0200 Subject: [PATCH] Prepare reading in files --- src/Tools/jaby_engine_fconv/Cargo.toml | 1 + .../jaby_engine_fconv/src/images/reduced_tim/mod.rs | 6 +++++- src/Tools/tool_helper/src/lib.rs | 10 ++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Tools/jaby_engine_fconv/Cargo.toml b/src/Tools/jaby_engine_fconv/Cargo.toml index b3e4fd76..61ed5822 100644 --- a/src/Tools/jaby_engine_fconv/Cargo.toml +++ b/src/Tools/jaby_engine_fconv/Cargo.toml @@ -7,4 +7,5 @@ edition = "2021" [dependencies] clap = {version = "*", features = ["derive"]} +image = "*" tool_helper = {path = "../tool_helper"} \ No newline at end of file diff --git a/src/Tools/jaby_engine_fconv/src/images/reduced_tim/mod.rs b/src/Tools/jaby_engine_fconv/src/images/reduced_tim/mod.rs index a886f2f8..dbed16cc 100644 --- a/src/Tools/jaby_engine_fconv/src/images/reduced_tim/mod.rs +++ b/src/Tools/jaby_engine_fconv/src/images/reduced_tim/mod.rs @@ -1,4 +1,6 @@ use clap::{Args, ValueEnum}; +use image::io::Reader as ImageReader; +use std::io::Cursor; use tool_helper::{Error, Input, Output}; #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)] @@ -14,6 +16,8 @@ pub struct Arguments { color_depth: ColorDepth } -pub fn convert(_args: Arguments, _input: Input, _output: Output) -> Result<(), Error> { +pub fn convert(_args: Arguments, input: Input, _output: Output) -> Result<(), Error> { + ImageReader::new(Cursor::new(tool_helper::input_to_vec(input)?)); + Err(Error::new("Convert not implemented yet".to_owned(), Some(-2))) } \ No newline at end of file diff --git a/src/Tools/tool_helper/src/lib.rs b/src/Tools/tool_helper/src/lib.rs index fcbee1c5..8678bfe6 100644 --- a/src/Tools/tool_helper/src/lib.rs +++ b/src/Tools/tool_helper/src/lib.rs @@ -53,4 +53,14 @@ pub fn os_str_to_string(input: &std::ffi::OsStr, name: &str) -> Result { pub fn get_file_name_from_path_buf(input: &PathBuf, name: &str) -> Result { os_str_to_string(Error::ok_or_new(input.file_name(), ||format!("No {} file name found", name), None)?, name) +} + +pub fn input_to_vec(input: Input) -> Result> { + let mut data = Vec::new(); + + for byte in input.bytes() { + data.push(Error::try_or_new(byte, None)?); + } + + Ok(data) } \ No newline at end of file