#![warn(missing_docs)]
use kurbo::Affine;
use oxframe_2d::SceneGraph;
use oxframe_core::Color;
#[cfg(feature = "cpu")]
mod blur;
#[cfg(feature = "cpu")]
mod cpu;
#[cfg(feature = "cpu")]
pub use cpu::CpuRenderer;
#[cfg(feature = "gpu")]
mod gpu;
#[cfg(feature = "gpu")]
pub use gpu::{GpuError, GpuRenderer};
#[derive(Clone, PartialEq, Eq)]
pub struct Image {
pub width: u32,
pub height: u32,
pub data: Vec<u8>,
}
impl std::fmt::Debug for Image {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Image({}x{})", self.width, self.height)
}
}
#[derive(Debug, Clone, Copy)]
pub struct RenderOptions {
pub width: u32,
pub height: u32,
pub background: Color,
}
pub trait Renderer {
fn render(&mut self, graph: &SceneGraph, options: &RenderOptions) -> Image;
}
pub fn scene_to_pixels(scene: (u32, u32), out: (u32, u32)) -> Affine {
let (sw, sh) = (f64::from(scene.0), f64::from(scene.1));
let (ow, oh) = (f64::from(out.0), f64::from(out.1));
let k = (ow / sw).min(oh / sh);
Affine::translate((ow / 2.0, oh / 2.0)) * Affine::scale(k)
}