Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Merge #834: Images: EPS shows through its proxy at display time; simple PostScript (QR codes) is drawn

aiongg32bee3bab2f0
diff --cc crates/images/src/lib.rs
index 2aa9892f2,7ce48c0a3..fa1533ccd
--- a/crates/images/src/lib.rs
+++ b/crates/images/src/lib.rs
@@@ -237,24 -163,12 +241,29 @@@ pub fn decode_rgba(bytes: &[u8]) -> Opt
if is_psd(bytes) {
return psd::decode(bytes);
}
+ // An EPS is drawn as its proxy (preview, simple PostScript or placeholder); the document
+ // keeps the EPS itself.
+ if is_eps(bytes) {
+ return decode_rgba(&eps_proxy(bytes)?.0);
+ }
- Some(decode_to_rgba8(&image::load_from_memory(bytes).ok()?))
+ if let Some((raster, icc)) = jpeg::decode_cmyk(bytes) {
+ return to_display_rgba(Pixels::Cmyk(raster), icc.as_deref(), &DisplayColour::active());
+ }
+ if let Some(raster) = decode_cmyk_tiff(bytes) {
+ return to_display_rgba(Pixels::Cmyk(raster), embedded_icc(bytes).as_deref(), &DisplayColour::active());
+ }
+ let img = image::load_from_memory(bytes).ok()?;
+ let rgba = decode_to_rgba8(&img);
+ let Some(icc) = embedded_icc(bytes) else { return Some(rgba) };
+ let px = if img.color().has_color() { Pixels::Rgb(rgba) } else { Pixels::Gray(rgba) };
+ to_display_rgba(px, Some(&icc), &DisplayColour::active())
+}
+
+/// The ICC profile embedded in a PNG, JPEG, TIFF or WebP.
+fn embedded_icc(bytes: &[u8]) -> Option<Vec<u8>> {
+ use image::ImageDecoder;
+ let mut d = image::ImageReader::new(std::io::Cursor::new(bytes)).with_guessed_format().ok()?.into_decoder().ok()?;
+ d.icc_profile().ok().flatten()
}
/// Fresh raster decodes are sRGB in the pinned image decoder. Expanding an L8 value to