use serde::{Deserialize, Serialize};
use crate::spatial::Resolution;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResizeOp {
pub resolution: Resolution,
pub mode: ResizeMode,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum ResizeMode {
Exact,
Fit,
Fill,
FitWidth,
FitHeight,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CropRegion {
pub x: u32,
pub y: u32,
pub width: u32,
pub height: u32,
}
impl CropRegion {
pub fn new(x: u32, y: u32, w: u32, h: u32) -> Self {
Self {
x,
y,
width: w,
height: h,
}
}
pub fn center_aspect(source_res: Resolution, aspect_w: u32, aspect_h: u32) -> Self {
let source_ar = source_res.width as f64 / source_res.height as f64;
let target_ar = aspect_w as f64 / aspect_h as f64;
let (w, h) = if source_ar > target_ar {
let h = source_res.height;
let w = (h as f64 * target_ar) as u32;
(w, h)
} else {
let w = source_res.width;
let h = (w as f64 / target_ar) as u32;
(w, h)
};
let x = (source_res.width - w) / 2;
let y = (source_res.height - h) / 2;
Self::new(x, y, w, h)
}
pub fn center(source_res: Resolution, w: u32, h: u32) -> Self {
let x = source_res.width.saturating_sub(w) / 2;
let y = source_res.height.saturating_sub(h) / 2;
Self::new(x, y, w, h)
}
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum Rotation {
Degrees90,
Degrees180,
Degrees270,
Arbitrary(f64),
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum FlipDirection {
Horizontal,
Vertical,
Both,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PadOp {
pub width: u32,
pub height: u32,
pub color: String,
}