use crate::color::{AlphaColor, Srgb};
use crate::filter::gaussian_blur::{MAX_KERNEL_SIZE, plan_decimated_blur, transform_blur_params};
use crate::filter::transform_offset_params;
use crate::filter_effects::EdgeMode;
use crate::kurbo::Affine;
#[derive(Debug)]
pub struct DropShadow {
pub dx: f32,
pub dy: f32,
pub color: AlphaColor<Srgb>,
pub std_deviation: f32,
pub edge_mode: EdgeMode,
pub composite_original: bool,
pub n_decimations: usize,
pub kernel: [f32; MAX_KERNEL_SIZE],
pub kernel_size: u8,
}
impl DropShadow {
pub fn new(
dx: f32,
dy: f32,
std_deviation: f32,
edge_mode: EdgeMode,
color: AlphaColor<Srgb>,
) -> Self {
Self::new_impl(dx, dy, std_deviation, edge_mode, color, true)
}
pub fn new_shadow_only(
dx: f32,
dy: f32,
std_deviation: f32,
edge_mode: EdgeMode,
color: AlphaColor<Srgb>,
) -> Self {
Self::new_impl(dx, dy, std_deviation, edge_mode, color, false)
}
fn new_impl(
dx: f32,
dy: f32,
std_deviation: f32,
edge_mode: EdgeMode,
color: AlphaColor<Srgb>,
composite_original: bool,
) -> Self {
let (n_decimations, kernel, kernel_size) = plan_decimated_blur(std_deviation);
Self {
dx,
dy,
color,
std_deviation,
edge_mode,
composite_original,
n_decimations,
kernel,
kernel_size,
}
}
}
pub(crate) fn transform_shadow_params(
dx: f32,
dy: f32,
std_deviation: f32,
transform: &Affine,
) -> (f32, f32, f32) {
let (scaled_dx, scaled_dy) = transform_offset_params(dx, dy, transform);
let scaled_std_dev = transform_blur_params(std_deviation, transform);
(scaled_dx, scaled_dy, scaled_std_dev)
}