crates/format/image/src/lib.rs 1.3 KiB 41 lines Raw
1 //! inf3r-image — FORMAT: Frame, PixelFormat, colour, tiles, png.2 //!3 //! The engine needs a frame, a strip of tiles, and a png encoder that a plugin4 //! can answer a job with. It needs no colour management, no decoder zoo, and no5 //! resize engine, so none are here.6 7 use std::fmt;8 9 pub mod pixel;10 pub mod png;11 pub mod tile;12 13 pub use pixel::{Format, Frame, Tile};14 pub use png::{encode, one_pixel};15 pub use tile::split;16 17 /// The reason an image operation failed.18 #[derive(Clone, PartialEq, Eq, Debug)]19 pub enum ImageError {20     /// A frame cannot have a zero side. A png with one is not an image.21     Empty,22     /// The pixel count overflows or does not match the bytes.23     Size,24     /// A side is beyond the u32 that png allows (2^31 - 1).25     TooLarge,26     /// A field of the png would be wrong.27     Text(&'static str),28 }29 30 impl fmt::Display for ImageError {31     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {32         match self {33             ImageError::Empty => write!(f, "the image has a zero side"),34             ImageError::Size => write!(f, "the pixels do not match the size"),35             ImageError::TooLarge => write!(f, "a side is beyond 2147483647"),36             ImageError::Text(why) => write!(f, "{why}"),37         }38     }39 }40 41 impl std::error::Error for ImageError {}