From 3ec3d3498751bfcbb373988df6ae35f277191080 Mon Sep 17 00:00:00 2001 From: Ivan Smirnov Date: Thu, 2 Dec 2021 15:57:57 +0000 Subject: [PATCH] Add Header::new() and with_colorspace() --- src/header.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/header.rs b/src/header.rs index b22a14f..443634b 100644 --- a/src/header.rs +++ b/src/header.rs @@ -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) -> Self { + self.colorspace = colorspace.into(); + self + } + #[inline] pub const fn encoded_size() -> usize { QOI_HEADER_SIZE