mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-21 20:39:29 +00:00
M6: restore full JPEG export chroma (#2521)
* M6: restore full JPEG export chroma * M6: check the JPEG matte away from the painted edge * docs: keep the parity header's change level and describe the JPG chroma fix Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: FredApps <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
FredApps
parent
48ebd1b58b
commit
f7acb637f0
@@ -146,7 +146,8 @@ fn export_file_names_take_the_suffix_and_slashes_make_folders() {
|
||||
#[test]
|
||||
fn export_formats_and_what_each_keeps() {
|
||||
let mut s = Session::new();
|
||||
let e = id(&ex(&mut s, "shape.ellipse", json!({"x": 0, "y": 0, "width": 40, "height": 40})));
|
||||
let side = 128;
|
||||
let e = id(&ex(&mut s, "shape.ellipse", json!({"x": 0, "y": 0, "width": side, "height": side})));
|
||||
set(&mut s, &[e], json!({"fills": ["#FF0000"]}));
|
||||
let png = export(&mut s, json!({"ids": [e], "format": "png"}));
|
||||
let jpg = export(&mut s, json!({"ids": [e], "format": "jpg"}));
|
||||
@@ -162,10 +163,17 @@ fn export_formats_and_what_each_keeps() {
|
||||
for (bytes, sig, why) in rows {
|
||||
assert!(bytes.starts_with(sig), "{why}");
|
||||
}
|
||||
assert_eq!(pixels(&png).get_pixel(0, 0)[3], 0, "PNG keeps transparency outside the circle");
|
||||
let corner = *pixels(&jpg).get_pixel(0, 0);
|
||||
assert!(corner[0] > 245 && corner[1] > 245 && corner[2] > 245, "JPG has no transparency: transparent areas are white");
|
||||
let mid = *pixels(&jpg).get_pixel(20, 20);
|
||||
let png = pixels(&png);
|
||||
let jpg = pixels(&jpg);
|
||||
// Keep the corner block clear of the ellipse so JPEG ringing at the edge does not affect the matte check.
|
||||
for y in 0..8 {
|
||||
for x in 0..8 {
|
||||
assert_eq!(png.get_pixel(x, y)[3], 0, "PNG keeps transparency outside the circle at ({x}, {y})");
|
||||
let corner = jpg.get_pixel(x, y);
|
||||
assert!(corner.0[..3].iter().all(|&channel| channel > 245), "JPG composites onto white at ({x}, {y}): {corner:?}");
|
||||
}
|
||||
}
|
||||
let mid = *jpg.get_pixel(side / 2, side / 2);
|
||||
assert!(mid[0] > 240 && mid[1] < 16 && mid[2] < 16, "docs silent: JPG quality is fixed and high (flat colours come back within a few levels)");
|
||||
}
|
||||
|
||||
|
||||
@@ -536,7 +536,13 @@ fn jpeg_with(p: &Pixmap, background: Color, quality: u8, icc: Option<Vec<u8>>) -
|
||||
}
|
||||
let embed_icc = icc.is_some();
|
||||
let img = codec_image(p, craft_image_codecs::ChannelLayout::Rgb, rgb, icc, None)?;
|
||||
let opts = craft_image_codecs::EncodeOptions { jpeg_quality: quality.clamp(1, 100), embed_icc, embed_metadata: false, ..Default::default() };
|
||||
let opts = craft_image_codecs::EncodeOptions {
|
||||
jpeg_quality: quality.clamp(1, 100),
|
||||
jpeg_chroma_subsampling: false, // Preserve full chroma resolution from before the shared codec cutover.
|
||||
embed_icc,
|
||||
embed_metadata: false,
|
||||
..Default::default()
|
||||
};
|
||||
encode_with_codec(&img, craft_image_codecs::Format::Jpeg, &opts)
|
||||
}
|
||||
|
||||
|
||||
@@ -586,6 +586,18 @@ fn rect_clip_frame_matches_same_rect_fill_on_fractional_edges() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn jpeg_export_keeps_full_chroma() {
|
||||
let mut pix = Pixmap::new(8, 8).unwrap();
|
||||
pix.fill(tiny_skia::Color::from_rgba8(160, 64, 192, 255));
|
||||
let jpeg = encode_export_with(&pix, ExportFormat::Jpg, ColorProfile::Srgb, 90).unwrap();
|
||||
|
||||
// SOF0 for the generated 8-bit, three-component baseline JPEG.
|
||||
let header = [0xff, 0xc0, 0, 17, 8, 0, 8, 0, 8, 3];
|
||||
let frame = jpeg.windows(19).find(|segment| segment.starts_with(&header)).expect("RGB JPEG frame");
|
||||
assert_eq!([frame[11], frame[14], frame[17]], [0x11; 3], "JPEG component sampling factors");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn export_output_and_icc_parity() {
|
||||
use figcraft_color::ColorProfile;
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user