mirror of
https://github.com/storytold/designcraft.git
synced 2026-11-14 14:22:39 +00:00
Fix current Rust clippy findings
This commit is contained in:
2 files changed
+5
-7
No files matched your search
@@ -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]);
|
||||
}
|
||||
|
||||
@@ -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<u8> {
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user