From 845e68008b0d81c5faf6cdc4b87ac928d28cfbfe Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Sun, 15 Nov 2026 15:48:44 +0100 Subject: [PATCH] test(trace): keep the image crate's JPEG encoder for the block-artifact fixture a_jpegs_blocks_are_not_traced_as_steps measures how many traced edges land on JPEG block boundaries, which depends on the encoder's artifacts. With the craft-image-codecs encoder 18 of 40 segments sit on block edges; with the original encoder and the new shared decoder the test passes unchanged, so the trace itself is unaffected. image stays a dev-dependency only. --- Cargo.lock | 1 + crates/trace/Cargo.toml | 2 ++ crates/trace/src/tests.rs | 10 ++++++---- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b58c015a5c..d80b61462e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7034,6 +7034,7 @@ name = "vectorcraft-trace" version = "0.24.1" dependencies = [ "craft-image-codecs", + "image", "kurbo 0.13.1", "serde", "serde_json", diff --git a/crates/trace/Cargo.toml b/crates/trace/Cargo.toml index 83f7425c05..ad76667886 100644 --- a/crates/trace/Cargo.toml +++ b/crates/trace/Cargo.toml @@ -17,3 +17,5 @@ thiserror = { workspace = true } [dev-dependencies] serde_json = { workspace = true } +# Test fixtures only: the JPEG-block test needs the block artifacts of the encoder it was tuned on. +image = { workspace = true } diff --git a/crates/trace/src/tests.rs b/crates/trace/src/tests.rs index 9b73fe784a..6b0f3d3b32 100644 --- a/crates/trace/src/tests.rs +++ b/crates/trace/src/tests.rs @@ -2174,12 +2174,14 @@ fn small_accents_of_other_colors_leave_a_tinted_photo_continuous_tone() { } } -/// `img` saved as a JPEG of `quality` and read back. +/// `img` saved as a JPEG of `quality` and read back. The `image` crate's encoder stays the fixture: +/// `a_jpegs_blocks_are_not_traced_as_steps` measures block artifacts, which differ by encoder. fn through_jpeg(img: &Raster, quality: u8) -> Raster { let rgb: Vec = img.rgba.chunks(4).flat_map(|p| [p[0], p[1], p[2]]).collect(); - let encoded = craft_image_codecs::Image::from_u8(img.width, img.height, craft_image_codecs::ChannelLayout::Rgb, rgb).unwrap(); - let opts = craft_image_codecs::EncodeOptions { jpeg_quality: quality, ..Default::default() }; - let bytes = craft_image_codecs::encode(&encoded, craft_image_codecs::Format::Jpeg, &opts).unwrap(); + let mut bytes = vec![]; + image::codecs::jpeg::JpegEncoder::new_with_quality(&mut bytes, quality) + .encode(&rgb, img.width, img.height, image::ExtendedColorType::Rgb8) + .unwrap(); Raster::decode(&bytes).unwrap() }