pub mod commands;
use std::{collections::HashMap, path::PathBuf};
pub mod gifmeta_structs;
pub mod utils;
pub fn get_metadata(
path: &PathBuf,
show_frames: bool,
) -> Result<gifmeta_structs::GifMetadata, String> {
match commands::info::get_metadata(path, show_frames) {
Ok(meta) => Ok(meta),
Err(e) => Err(e),
}
}
pub fn mod_gif(
input: &PathBuf,
output: Option<PathBuf>,
loop_count: Option<u16>,
delay_all: Option<u16>,
delays: Option<HashMap<usize, u16>>,
) -> Result<(), String> {
if loop_count.is_none() && delay_all.is_none() && delays.as_ref().map_or(true, |m| m.is_empty())
{
eprintln!("⚠️ No modifications specified.");
eprintln!(" Use at least one of: --loop, --delay, or --delays");
return Err("No modification parameters provided.".into());
}
match commands::modify::apply_modifications(input, loop_count, delay_all, delays, output) {
Ok(_) => {
println!("File modified.");
Ok(())
}
Err(e) => {
eprintln!("Failed to extract loop count: {}", e);
Err(e)
}
}
}
pub fn get_loop_count(path: &PathBuf) -> Result<u16, String> {
match utils::loop_count::extract_loop_count(path) {
Ok(count) => {
println!("Loop count: {}", count);
Ok(count)
}
Err(e) => {
eprintln!("Failed to extract loop count: {}", e);
Err(e)
}
}
}
pub fn set_frame_delay(path: &PathBuf, delay: u16, output: Option<PathBuf>) -> Result<u16, String> {
let output_clone = output.clone();
println!(
"(stub) Setting delay {} for: {:?} → {:?}",
delay, path, output
);
match utils::set_frame_delay::set_frame_delay(path, delay, output) {
Ok(_) => {
println!("New delay: {} saved to: {:?}", delay, output_clone);
Ok(delay)
}
Err(e) => {
eprintln!("Failed to set delay: {}", e);
Err(e)
}
}
}
pub fn set_loop_count(path: &PathBuf, count: u16, output: Option<PathBuf>) -> Result<u16, String> {
let output_clone = output.clone();
match utils::loop_count::set_loop_count(path, count, output) {
Ok(_) => {
println!("New loop count: {} saved to: {:?}", count, output_clone);
Ok(count)
}
Err(e) => {
eprintln!("Failed to extract loop count: {}", e);
Err(e)
}
}
}
pub fn show_frame_delays(path: &PathBuf) {
println!("show_frame_delays {:?}", path);
}
pub fn set_selected_frame_delays(
input: &PathBuf,
frame_numbers: Vec<usize>,
delay_values: Vec<u16>,
output: Option<PathBuf>,
) {
println!(
"set_selected_frame_delays {:?} with: {:?}, {:?} → {:?}",
input, frame_numbers, delay_values, output
);
}
pub fn get_frame_image(path: String, frame: usize) -> Result<Vec<u8>, String> {
utils::extract_frame_as_png::extract_frame_as_png(&path, frame)
}