Add Header::new() and with_colorspace()

This commit is contained in:
Ivan Smirnov 2021-12-02 15:57:57 +00:00
parent 02734e4eca
commit 3ec3d34987

View file

@ -41,6 +41,17 @@ const fn u32_from_be(v: &[u8]) -> u32 {
}
impl Header {
#[inline]
pub const fn new(width: u32, height: u32, channels: u8) -> Self {
Self { magic: QOI_MAGIC, width, height, channels, colorspace: ColorSpace::from_u8(0) }
}
#[inline]
pub fn with_colorspace(mut self, colorspace: impl Into<ColorSpace>) -> Self {
self.colorspace = colorspace.into();
self
}
#[inline]
pub const fn encoded_size() -> usize {
QOI_HEADER_SIZE