mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-17 21:27:00 +00:00
chore(codecs): cut over remaining image/tiff/ccitt codecs to craft-libs
This commit is contained in:
@@ -459,9 +459,8 @@ fn color_mode(b: &ImageBlob) -> &'static str {
|
||||
if b.gray_source().is_some() {
|
||||
return "gray";
|
||||
}
|
||||
let readable =
|
||||
image::ImageReader::new(std::io::Cursor::new(b.bytes.as_slice())).with_guessed_format().ok().and_then(|r| r.into_dimensions().ok());
|
||||
if readable.is_some() { "rgb" } else { "unknown" }
|
||||
let readable = craft_image_codecs::probe_size(&b.bytes).is_ok() || b.header_size().is_some();
|
||||
if readable { "rgb" } else { "unknown" }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -481,8 +480,7 @@ fn rgba_pixels(b: &ImageBlob, w: u32, h: u32, max: usize, charged: &mut usize) -
|
||||
return None;
|
||||
}
|
||||
let cmyk = b.is_cmyk();
|
||||
let reader = || image::ImageReader::new(std::io::Cursor::new(b.bytes.as_slice())).with_guessed_format().ok();
|
||||
let size = if cmyk { b.header_size()? } else { reader()?.into_dimensions().ok()? };
|
||||
let size = if cmyk { b.header_size()? } else { craft_image_codecs::probe_size(&b.bytes).ok().or_else(|| b.header_size())? };
|
||||
if size != (w, h) {
|
||||
return None;
|
||||
}
|
||||
@@ -492,13 +490,11 @@ fn rgba_pixels(b: &ImageBlob, w: u32, h: u32, max: usize, charged: &mut usize) -
|
||||
if cmyk {
|
||||
return cmyk_rgba(b, w, h);
|
||||
}
|
||||
let mut r = reader()?;
|
||||
let mut limits = image::Limits::default();
|
||||
let mut opts = craft_image_codecs::DecodeOptions::default();
|
||||
// The decoder's own buffers besides the RGBA it gives.
|
||||
limits.max_alloc = Some(64 << 20);
|
||||
r.limits(limits);
|
||||
let img = r.decode().ok()?.into_rgba8();
|
||||
(img.dimensions() == (w, h)).then(|| img.into_raw())
|
||||
opts.limits.max_alloc = 64 << 20;
|
||||
let img = craft_image_codecs::decode_with(&b.bytes, &opts).ok()?;
|
||||
(img.dimensions() == (w, h)).then(|| img.to_rgba8())
|
||||
}
|
||||
|
||||
/// The inks → XYZ table of [`cmyk_rgba`] and the color settings it was built with.
|
||||
|
||||
Reference in New Issue
Block a user