diff --git a/crates/pdf/src/export.rs b/crates/pdf/src/export.rs index 3d7d53699..5462c015a 100644 --- a/crates/pdf/src/export.rs +++ b/crates/pdf/src/export.rs @@ -203,7 +203,7 @@ impl GreyImage { return None; } let (mut grey, mut alpha) = (Vec::with_capacity(pixels), Vec::with_capacity(pixels)); - for p in img.data().chunks_exact(2) { + for p in img.data().as_chunks::<2>().0 { grey.push(p[0]); alpha.push(p[1]); } diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs index e6e5d04e8..84bb075dc 100644 --- a/crates/render/src/lib.rs +++ b/crates/render/src/lib.rs @@ -72,19 +72,18 @@ impl Rendered { } /// PNG bytes (empty, with the error logged, if the image can't be encoded). pub fn to_png(&self) -> Vec { - let mut buf = Vec::new(); let mut px = self.to_straight(); // `pixels` is public: a mismatched buffer is padded or cut to the stated size. px.resize(self.width as usize * self.height as usize * 4, 0); let Ok(img) = craft_image_codecs::Image::from_u8(self.width, self.height, craft_image_codecs::ChannelLayout::Rgba, px) else { log::error!("PNG encode: {}×{} image is too large", self.width, self.height); - return buf; + return Vec::new(); }; match craft_image_codecs::encode(&img, craft_image_codecs::Format::Png, &Default::default()) { Ok(bytes) => bytes, Err(e) => { log::error!("PNG encode: {e}"); - buf + Vec::new() } } } @@ -100,17 +99,16 @@ impl Rendered { [mix(p[0]), mix(p[1]), mix(p[2])] }) .collect(); - let mut buf = Vec::new(); let Ok(img) = craft_image_codecs::Image::from_u8(self.width, self.height, craft_image_codecs::ChannelLayout::Rgb, rgb) else { log::error!("JPEG encode: {}×{} image is too large", self.width, self.height); - return buf; + return Vec::new(); }; let options = craft_image_codecs::EncodeOptions { jpeg_quality: quality.clamp(1, 100), ..Default::default() }; match craft_image_codecs::encode(&img, craft_image_codecs::Format::Jpeg, &options) { Ok(bytes) => bytes, Err(e) => { log::error!("JPEG encode: {e}"); - buf + Vec::new() } } }