mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-18 16:37:32 +00:00
Merge #7664 (fix/restore-codec-cutover-ci) into feat/cutover-remaining-codecs
Conflicts resolved in favour of main/#7664 in the 13 source files both touched (doc/cmyk.rs, metafile/dib.rs, pdf images, svg import/files.rs, render paint and encode tests, trace, engine load.rs), keeping main's newer TIFF/CMYK, DIB and PDF image fixes. vectorcraft-doc stays on main's version until its CMYK reader moves to craft-tiff. The image crate keeps its format features, and usvg, tiff, zune-jpeg, hayro-ccitt and jpeg-encoder stay for the readers not yet moved. Codec crates pinned to craft-libs d6cd7836d364177661b0ae17f48a0805e83a5f32. Also fixes the compile errors CodeRabbit flagged (jp2read DecodeOptions, filters.rs use-after-move) and the encode() arity at d6cd7836d.
This commit is contained in:
@@ -142,7 +142,7 @@ pub fn encode(px: &[u8], width: u32, height: u32, quality: u8, ppi: Option<f64>,
|
||||
}
|
||||
if o.embed_icc {
|
||||
let icc = cms::icc_bytes(&o.color_model.profile()).map_err(|e| format!("JPEG colour profile: {e}"))?;
|
||||
img.icc = Some(icc);
|
||||
img.icc = Some(icc.to_vec());
|
||||
}
|
||||
let (jpeg_format, jpeg_progressive_scans) = match o.method {
|
||||
Method::Baseline => (JpegFormat::Baseline, None),
|
||||
|
||||
@@ -124,8 +124,10 @@ fn gray_and_bilevel_images_store_gray() {
|
||||
assert_eq!(gray(&file), levels);
|
||||
let (mime, file) = img.to_bilevel(150.0).unwrap();
|
||||
assert_eq!(mime, "image/tiff");
|
||||
let mut d = ::tiff::decoder::Decoder::new(std::io::Cursor::new(&file)).unwrap();
|
||||
assert_eq!(d.colortype().unwrap(), ::tiff::ColorType::Gray(1));
|
||||
let tiff = craft_tiff::Tiff::parse(&file).unwrap();
|
||||
let ifd = &tiff.ifds[0];
|
||||
assert_eq!(ifd.u16(craft_tiff::tags::SAMPLES_PER_PIXEL), Some(1));
|
||||
assert_eq!(ifd.value(craft_tiff::tags::BITS_PER_SAMPLE).unwrap().to_u64_vec(), vec![1]);
|
||||
let bw: Vec<u8> = [0u8, 0, 255, 255, 255, 0].iter().flat_map(|&g| [g, 255]).collect();
|
||||
assert_eq!(gray(&file), bw, "from 128 up is white");
|
||||
// Half-covered white over the light grey; a clear pixel is white.
|
||||
|
||||
@@ -144,9 +144,18 @@ fn unpack(mut src: &[u8], out: &mut Vec<u8>) {
|
||||
}
|
||||
}
|
||||
|
||||
/// The composite as a reader sees it.
|
||||
/// The stored composite: RGB stays white-matted, with its original alpha.
|
||||
fn merged(f: &[u8]) -> Vec<u8> {
|
||||
craft_psd::PsdFile::from_bytes(f).expect("a PSD a reader takes").composite_rgba8().expect("composite").data
|
||||
let psd = craft_psd::PsdFile::from_bytes(f).expect("a PSD a reader takes");
|
||||
if psd.header.color_mode != craft_psd::ColorMode::Rgb {
|
||||
return psd.composite_rgba8().expect("composite").data;
|
||||
}
|
||||
assert_eq!(psd.header.depth, 8);
|
||||
let samples = psd.decode_merged().expect("stored composite planes");
|
||||
let count = psd.header.width as usize * psd.header.height as usize;
|
||||
(0..count)
|
||||
.flat_map(|i| [samples[i], samples[count + i], samples[2 * count + i], if psd.merged_has_alpha() { samples[3 * count + i] } else { 255 }])
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn pixel(px: &[u8], width: usize, x: usize, y: usize) -> [u8; 4] {
|
||||
|
||||
@@ -69,7 +69,7 @@ fn lzw_is_smaller_and_decodes_the_same() {
|
||||
assert_eq!(pixels(&lzw), px, "transparency kept as an alpha channel");
|
||||
assert_eq!(pixels(&plain), px);
|
||||
let img = craft_image_codecs::decode_as(craft_image_codecs::Format::Tiff, &lzw).unwrap();
|
||||
assert_eq!(img.data(), px.as_slice());
|
||||
assert_eq!(img.data(), px);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -108,7 +108,7 @@ fn colour_models_write_their_samples() {
|
||||
assert_eq!(d.u16(tags::PHOTOMETRIC), Some(5), "separated");
|
||||
assert_eq!(d.u16(332), Some(1), "CMYK inks");
|
||||
let cmyk_img = craft_image_codecs::decode_as(craft_image_codecs::Format::Tiff, &cmyk).unwrap();
|
||||
assert_eq!(cmyk_img.data(), inks.as_slice());
|
||||
assert_eq!(cmyk_img.data(), inks);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -118,7 +118,7 @@ fn resolution_tags_and_the_profile() {
|
||||
let file = t::encode_samples(&px, 4, 4, ppi, &opts(ColorModel::Rgb)).unwrap();
|
||||
let d = ifd0(&file);
|
||||
for tag in [tags::X_RESOLUTION, tags::Y_RESOLUTION] {
|
||||
let Some(craft_tiff::Value::Rationals(v)) = d.value(tag) else { panic!("rational") };
|
||||
let Some(craft_tiff::Value::Rational(v)) = d.value(tag) else { panic!("rational") };
|
||||
assert_eq!(v.as_slice(), &[rational]);
|
||||
}
|
||||
assert_eq!(d.u16(tags::RESOLUTION_UNIT), Some(2), "inches");
|
||||
@@ -126,7 +126,8 @@ fn resolution_tags_and_the_profile() {
|
||||
for model in ColorModel::ALL {
|
||||
let src = if model == ColorModel::Cmyk { vec![0; 64] } else { px.clone() };
|
||||
let file = t::encode_samples(&src, 4, 4, 72.0, &TiffOptions { embed_icc: true, ..opts(model) }).unwrap();
|
||||
let icc = ifd0(&file).bytes(tags::ICC_PROFILE).unwrap();
|
||||
let ifd = ifd0(&file);
|
||||
let icc = ifd.bytes(tags::ICC_PROFILE).unwrap();
|
||||
assert_eq!(&icc[36..40], b"acsp", "{model:?}: an ICC profile");
|
||||
let space: &[u8; 4] = match model {
|
||||
ColorModel::Rgb => b"RGB ",
|
||||
@@ -169,8 +170,13 @@ fn packbits_and_bilevel_images_decode() {
|
||||
assert_eq!(d.u16(tags::COMPRESSION), Some(32773));
|
||||
// The decoder turns WhiteIsZero into black-is-zero.
|
||||
let dec = craft_image_codecs::decode_as(craft_image_codecs::Format::Tiff, &file).unwrap();
|
||||
assert_eq!(dec.width, 10);
|
||||
assert_eq!(dec.height, 3);
|
||||
assert_eq!(dec.width(), 10);
|
||||
assert_eq!(dec.height(), 3);
|
||||
assert_eq!(
|
||||
dec.data(),
|
||||
[0, 255, 0, 255, 0, 255, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
|
||||
"WhiteIsZero samples are inverted and row padding is ignored"
|
||||
);
|
||||
// A buffer that doesn't match the size is refused, not written.
|
||||
let short = Image { data: &rows[..5], ..image };
|
||||
assert!(t::write(&short, &Layout { byte_order: ByteOrder::Little, compression: Compression::None, ppi: 72.0, icc: None }).is_err());
|
||||
|
||||
Reference in New Issue
Block a user