mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge current main; retain strict SVG depth boundary regression
This commit is contained in:
commit
fa8228698b
20 files changed
+111
-88
No files matched your search
Generated
+3
-5
@@ -5416,7 +5416,9 @@ dependencies = [
|
||||
"craft-cms",
|
||||
"craft-flags",
|
||||
"craft-image-codecs",
|
||||
"craft-svg",
|
||||
"craft-update",
|
||||
"craft-xml",
|
||||
"dispatch2",
|
||||
"eframe",
|
||||
"egui",
|
||||
@@ -5440,10 +5442,8 @@ dependencies = [
|
||||
"photocraft-tablet",
|
||||
"photocraft-ui-egui",
|
||||
"plist",
|
||||
"resvg 0.45.1",
|
||||
"rfd",
|
||||
"ron",
|
||||
"roxmltree 0.21.2",
|
||||
"rustix 1.1.5",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -5706,10 +5706,8 @@ dependencies = [
|
||||
"photocraft-text",
|
||||
"photocraft-vector",
|
||||
"proptest",
|
||||
"roxmltree 0.21.2",
|
||||
"serde_json",
|
||||
"thiserror 2.0.21",
|
||||
"tiff",
|
||||
"ttf-parser",
|
||||
"zune-core",
|
||||
"zune-jpegxl",
|
||||
@@ -5776,11 +5774,11 @@ dependencies = [
|
||||
name = "photocraft-raw"
|
||||
version = "0.23.1"
|
||||
dependencies = [
|
||||
"craft-image-codecs",
|
||||
"craft-raw",
|
||||
"flate2",
|
||||
"image",
|
||||
"photocraft-raw",
|
||||
"png 0.18.1",
|
||||
"rayon",
|
||||
"zune-core",
|
||||
"zune-jpegxl",
|
||||
|
||||
+1
-2
@@ -82,9 +82,8 @@ bytemuck = { version = "1", features = ["derive"] }
|
||||
flate2 = { version = "1.1.10", default-features = false, features = ["zlib-rs", "runtime_detection"] }
|
||||
encoding_rs = { version = "0.8", default-features = false, features = ["alloc"] }
|
||||
image = { version = "0.25", default-features = false }
|
||||
# Baseline-JPEG decode of lossy DNG tiles (compression 34892), shared with zune-jpeg.
|
||||
# Baseline-JPEG decode of lossy DNG tiles (compression 34892).
|
||||
zune-core = "0.5"
|
||||
zune-jpeg = "0.5"
|
||||
proptest = "1"
|
||||
eframe = { version = "0.37", default-features = false }
|
||||
# Without `default_fonts`, which embeds egui's fonts uncompressed: ui-egui ships them deflated
|
||||
|
||||
@@ -42,7 +42,7 @@ thiserror = { workspace = true }
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
tempfile = "=3.27.0"
|
||||
roxmltree = "0.21"
|
||||
craft-xml = { workspace = true }
|
||||
craft-update = { workspace = true }
|
||||
rfd = { workspace = true }
|
||||
arboard = { version = "3.7", features = ["wayland-data-control"] }
|
||||
@@ -94,8 +94,8 @@ wl-clipboard-rs = { version = "=0.9.4", default-features = false }
|
||||
# Wayland desktop color selection through the existing XDG portal transport.
|
||||
zbus = "=5.19.0"
|
||||
# Caption button glyphs from the desktop's icon theme (`caption_style.rs`): SVG paths only, no
|
||||
# text or images. Already in Cargo.lock (photocraft-io); pinned exactly.
|
||||
resvg = { version = "=0.45.1", default-features = false }
|
||||
# text or images. Already in Cargo.lock (photocraft-io).
|
||||
craft-svg = { workspace = true }
|
||||
# Already used by the portal stack; bounded waits let cancelling close the OS request.
|
||||
futures-lite = "=2.6.1"
|
||||
async-io = "=2.6.0"
|
||||
|
||||
@@ -200,7 +200,7 @@ impl IconTheme {
|
||||
/// An SVG's coverage (alpha) as a `px` × `px` mask, the drawing fitted and centred. `None` for an
|
||||
/// unreadable SVG or an absurd size.
|
||||
pub fn rasterize_mask(svg: &[u8], px: u32) -> Option<Vec<u8>> {
|
||||
use resvg::{tiny_skia, usvg};
|
||||
use craft_svg::tree::{draw, draw::tiny_skia, usvg};
|
||||
// usvg inflates gzip (`.svgz`) input without a decoded-size limit, and icons are plain `.svg`.
|
||||
if !(1..=256).contains(&px) || svg.starts_with(&[0x1f, 0x8b]) {
|
||||
return None;
|
||||
@@ -221,8 +221,7 @@ pub fn rasterize_mask(svg: &[u8], px: u32) -> Option<Vec<u8>> {
|
||||
}
|
||||
let s = px as f32 / side;
|
||||
let (dx, dy) = ((px as f32 - size.width() * s) / 2.0, (px as f32 - size.height() * s) / 2.0);
|
||||
let mut pixmap = tiny_skia::Pixmap::new(px, px)?;
|
||||
resvg::render(&tree, tiny_skia::Transform::from_scale(s, s).post_translate(dx, dy), &mut pixmap.as_mut());
|
||||
let pixmap = draw::render(&tree, tiny_skia::Transform::from_scale(s, s).post_translate(dx, dy), px, px, 0, 64 * 1024 * 1024).ok()?;
|
||||
Some(pixmap.data().as_chunks::<4>().0.iter().map(|[_, _, _, a]| *a).collect())
|
||||
}))
|
||||
.ok()
|
||||
|
||||
@@ -147,9 +147,9 @@ fn export_commands(input: &Path, output: &Path, format: &str) -> Result<[(u8, &'
|
||||
fn source_svg(bytes: &[u8], size: Option<(f64, f64)>) -> Result<Vec<u8>, String> {
|
||||
let text = std::str::from_utf8(bytes).map_err(|_| "Converted SVG is not UTF-8")?;
|
||||
photocraft_io::svg::import_svg_bounded_with_work("Artwork.svg", bytes, 96_000_000).map_err(|e| format!("Converted SVG is unsupported: {e}"))?;
|
||||
let doc = roxmltree::Document::parse(text).map_err(|e| format!("Invalid converted SVG: {e}"))?;
|
||||
let root = doc.root_element();
|
||||
if root.tag_name().name() != "svg" {
|
||||
let root = craft_xml::parse(text.as_bytes()).map_err(|e| format!("Invalid converted SVG: {e}"))?;
|
||||
let local_name = root.name.rsplit_once(':').map_or(root.name.as_str(), |(_, l)| l);
|
||||
if local_name != "svg" {
|
||||
return Err("VectorCraft did not return SVG".into());
|
||||
}
|
||||
let Some((w, h)) = size else {
|
||||
@@ -161,12 +161,12 @@ fn source_svg(bytes: &[u8], size: Option<(f64, f64)>) -> Result<Vec<u8>, String>
|
||||
// The nested root keeps its own width/height, so the outer viewBox must use the same CSS
|
||||
// pixels: `612pt` is 816 user units at SVG's 96 dpi. Other units are rejected below.
|
||||
let dimension = |key| {
|
||||
let value = root.attribute(key)?;
|
||||
let value = root.attr(key)?;
|
||||
let (number, scale) = value.strip_suffix("pt").map_or((value, 1.0), |number| (number, 4.0 / 3.0));
|
||||
number.parse::<f64>().ok().map(|v| v * scale).filter(|v| v.is_finite() && *v > 0.0)
|
||||
};
|
||||
let (iw, ih) = dimension("width").zip(dimension("height")).ok_or("Converted SVG has no finite dimensions")?;
|
||||
let inner = text.get(root.range()).ok_or("Invalid SVG root range")?;
|
||||
let inner = root.to_xml();
|
||||
let result =
|
||||
format!(r#"<svg xmlns="http://www.w3.org/2000/svg" width="{w}" height="{h}" viewBox="0 0 {iw} {ih}" preserveAspectRatio="none">{inner}</svg>"#)
|
||||
.into_bytes();
|
||||
|
||||
@@ -40,8 +40,10 @@ MCP or control client
|
||||
The current token proves possession of a secret but does not provide general method authorization.
|
||||
Filesystem handles and a defensive command-path policy are implemented; explicit non-filesystem
|
||||
capabilities, session-memory/command-duration budgets, and audit events remain. Preview and
|
||||
reply ceilings do not bound all document operations or desktop screenshot capture. Private token handling, process
|
||||
isolation, and least-privileged execution are still practical containment measures.
|
||||
reply ceilings do not bound all document operations; desktop screenshots are admission-bounded
|
||||
per image and in aggregate, though that admission is far above the reply ceiling. Private token
|
||||
handling, process isolation, and least-privileged execution are still practical containment
|
||||
measures.
|
||||
|
||||
## Windows UNC write roots
|
||||
|
||||
|
||||
@@ -67,8 +67,10 @@ Automation is a privilege boundary because requests can cause filesystem access,
|
||||
or command-duration/cancellation budget;
|
||||
- one thread per accepted TCP connection;
|
||||
- no structured security audit event stream;
|
||||
- desktop screenshot capture/encoding and document import/export have no automation-specific
|
||||
operation budgets; the desktop transport limits replies after their creation;
|
||||
- desktop screenshots are admission-bounded (4 outstanding requests, 128 MiB per image, 256 MiB
|
||||
aggregate, 8 s deadline), which is far above the 8 MiB JSON reply cap; document import/export
|
||||
have no automation-specific operation budgets, and the desktop transport limits replies after
|
||||
their creation;
|
||||
- expensive engine commands are not charged to a session budget.
|
||||
|
||||
Reply rejection can happen after a command has changed state. Such errors report that the
|
||||
|
||||
@@ -10,8 +10,9 @@ PhotoCraft processes complex attacker-controlled files and exposes automation th
|
||||
| Raster codecs | Default dimension/pixel/allocation limits; decoder-specific budgets; malformed/property tests; fuzz targets | Continuous fuzzing and more format-specific semantic cases |
|
||||
| `.pcraft` | Manifest/blob/total-byte limits; bounded decompression; CRC/hash and version checks; fuzz target | Tighter complexity/entry limits and directory-bundle path-race analysis |
|
||||
| Engine commands | Error-return contract, focused bad-parameter tests, adversarial `panic_hunt` test | Continue eliminating input-derived panic and exhaustion paths |
|
||||
| Automation filesystem | Separate read roots and one write root held as directory capabilities; traversal and symlink escapes refused; writes are atomic replacements | A hardlink inside a root still reads the inode it names outside the root; writing over it replaces only the link, leaving the outside name unchanged |
|
||||
| Control TCP | Loopback binding; bearer-token authentication; rooted read/write authority; 1 MiB request lines; 8 MiB replies; 16 active connections; I/O timeouts | No general method capabilities, encryption, client identity, explicit JSON-depth policy, aggregate session-memory/command-duration budgets, or audit trail |
|
||||
| MCP | Stdio; typed tools; authenticated and bounded bridge; rooted read/write authority; 256-step batches with aggregate reply budgets; headless preview/output ceilings | No general tool authorization scopes, aggregate session-memory accounting, or command cancellation; transport reply caps do not bound desktop screenshot capture |
|
||||
| MCP | Stdio; typed tools; authenticated and bounded bridge; rooted read/write authority; 256-step batches with aggregate reply budgets; headless preview/output ceilings | No general tool authorization scopes, aggregate session-memory accounting, or command cancellation; desktop screenshot capture is admission-bounded (4 outstanding requests, 128 MiB per image, 256 MiB aggregate, 8 s deadline) but that admission is far above the 8 MiB reply cap |
|
||||
| Dependencies | Cargo lockfile and normal CI build/test/clippy | No `cargo-audit` or `cargo-deny` job/configuration confirmed in current tree |
|
||||
| Releases | Checksums and platform signing/notarization paths when secrets are configured | Signing can be absent; no SBOM generation confirmed in current tree |
|
||||
|
||||
@@ -22,7 +23,8 @@ The table is a snapshot of the current repository, not a guarantee about deploye
|
||||
1. Add capability-scoped automation sessions on top of the authenticated transport.
|
||||
2. Maintain the implemented workspace-handle boundary as file-bearing commands evolve.
|
||||
3. Extend the preview/reply budgets to JSON complexity, aggregate document/session memory,
|
||||
desktop capture/import/export, and command duration/cancellation.
|
||||
desktop import/export, command duration/cancellation, and the gap between screenshot
|
||||
admission and the reply ceiling.
|
||||
4. Expand PSD/PSB, codec, and `.pcraft` fuzzing with regression corpora.
|
||||
5. Add dependency advisories/license policy checks and release SBOMs.
|
||||
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
e02939ef009218e81c44e8ec001fbb7603461de4
|
||||
e56d26244bbac099bfd42e23fb12f78a4be418a7
|
||||
@@ -1499,6 +1499,22 @@ fn same_root_leaf_link_save_replaces_the_link_without_writing_its_target() {
|
||||
assert!(!std::fs::symlink_metadata(inside.join("link.png")).unwrap().file_type().is_symlink());
|
||||
}
|
||||
|
||||
/// A hardlink inside a root names the outside inode, so it reads that content. Writing over it is
|
||||
/// an atomic replace of the directory entry: the other name and its inode keep their bytes.
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn hardlink_inside_a_root_reads_the_target_but_write_over_replaces_the_link() {
|
||||
let (inside, outside, workspace) = roots("hardlink");
|
||||
let target = outside.join("target.png");
|
||||
std::fs::write(&target, b"outside").unwrap();
|
||||
std::fs::hard_link(&target, inside.join("linked.png")).unwrap();
|
||||
|
||||
assert_eq!(workspace.read("linked.png").unwrap(), b"outside");
|
||||
workspace.write("linked.png", b"replacement").unwrap();
|
||||
assert_eq!(std::fs::read(&target).unwrap(), b"outside", "the outside inode is not modified");
|
||||
assert_eq!(std::fs::read(inside.join("linked.png")).unwrap(), b"replacement");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn directory_pcraft_uses_ordered_roots_without_falling_back_after_selection() {
|
||||
let (library, work, _) = roots("pcraft-ordered");
|
||||
|
||||
@@ -68,7 +68,7 @@ photocraft-io = { workspace = true, features = ["testgen"] }
|
||||
# Synthetic camera raw files for the open tests.
|
||||
photocraft-raw = { workspace = true, features = ["testgen"] }
|
||||
photocraft-testkit = { workspace = true }
|
||||
exr = { version = "1.73", default-features = false }
|
||||
# WebAssembly text -> binary for plug-in test modules (Apache-2.0 WITH LLVM-exception).
|
||||
wat = "1.228"
|
||||
# Synthetic multi-part EXR fixtures for the parts-commands tests.
|
||||
exr = { version = "1.73", default-features = false }
|
||||
@@ -64,8 +64,6 @@ kurbo = { version = "0.13", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
lopdf = { version = "0.38", default-features = false }
|
||||
# PDF XMP serialization assertions parse output XML in tests.
|
||||
roxmltree = "0.21"
|
||||
miniz_oxide = "0.9"
|
||||
crc32fast = "1.5"
|
||||
craft-affinity = { workspace = true, features = ["synth"] }
|
||||
@@ -77,4 +75,3 @@ proptest = { workspace = true }
|
||||
# Lossless JPEG XL encoder for the JPEG XL DNG preview test (tests only), as in photocraft-raw.
|
||||
zune-jpegxl = { version = "=0.5.2", default-features = false, features = ["std"] }
|
||||
zune-core = { workspace = true }
|
||||
tiff = { version = "0.11", default-features = false, features = ["deflate", "lzw"] }
|
||||
@@ -442,15 +442,24 @@ fn the_plate_description_joins_the_rdf_element_however_the_packet_spells_it() {
|
||||
d.channels.push(spot("Varnish", photocraft_color::Color::rgb(0.9, 0.9, 0.6), &[1.0; 8]));
|
||||
// The packet must parse as namespaced XML with the plates a description inside its RDF element.
|
||||
let plates_in_rdf = |xmp: &str| {
|
||||
let tree = roxmltree::Document::parse(xmp.trim_start_matches('\u{feff}')).unwrap_or_else(|e| panic!("{e}: {xmp}"));
|
||||
let plates = tree
|
||||
.descendants()
|
||||
.find(|n| n.tag_name().namespace() == Some(crate::pdf::SPOT_PLATES_NS) && n.tag_name().name() == "plates")
|
||||
.unwrap_or_else(|| panic!("no pcsp:plates: {xmp}"));
|
||||
let description = plates.parent_element().unwrap();
|
||||
assert_eq!((description.tag_name().namespace(), description.tag_name().name()), (Some(RDF), "Description"), "{xmp}");
|
||||
let rdf = description.parent_element().unwrap();
|
||||
assert_eq!((rdf.tag_name().namespace(), rdf.tag_name().name()), (Some(RDF), "RDF"), "{xmp}");
|
||||
let canon = craft_xml::Canonical::new(&[("rdf", RDF), ("pcsp", crate::pdf::SPOT_PLATES_NS)]);
|
||||
let tree = craft_xml::Options::canonical(&canon).parse(xmp.trim_start_matches('\u{feff}').as_bytes()).unwrap_or_else(|e| panic!("{e}: {xmp}"));
|
||||
fn child_els(el: &craft_xml::El) -> impl Iterator<Item = &craft_xml::El> {
|
||||
el.children.iter().filter_map(|n| match n {
|
||||
craft_xml::Node::El(e) => Some(e),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
let mut stack = vec![&tree];
|
||||
let mut found = false;
|
||||
while let Some(el) = stack.pop() {
|
||||
if el.name == "rdf:RDF" && child_els(el).any(|d| d.name == "rdf:Description" && child_els(d).any(|p| p.name == "pcsp:plates")) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
stack.extend(child_els(el));
|
||||
}
|
||||
assert!(found, "no rdf:RDF/rdf:Description/pcsp:plates: {xmp}");
|
||||
assert_eq!(xmp.matches("<?xpacket begin").count(), 1, "one packet, not two: {xmp}");
|
||||
};
|
||||
let head = "<?xpacket begin=\"\u{feff}\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>\n<x:xmpmeta xmlns:x=\"adobe:ns:meta/\">\n";
|
||||
|
||||
@@ -1045,8 +1045,18 @@ fn the_deepest_chain_of_embedded_svg_images_fits_a_small_stack() {
|
||||
let mut accepted = 0;
|
||||
for levels in 1..=MAX_EMBEDDED_SVG_DEPTH + 1 {
|
||||
match rasterize_bounded(chain(levels).as_bytes(), 1.0, MAX_RASTER_PIXELS) {
|
||||
Ok(buf) if buf.px[4 * 8 + 4][3] > 0.99 => accepted = levels,
|
||||
Ok(_) | Err(_) => assert!(accepted > 0, "a one-level chain renders"),
|
||||
Ok(buf) => {
|
||||
let drawn = buf.px[4 * 8 + 4][3] > 0.99;
|
||||
if levels > MAX_EMBEDDED_SVG_DEPTH {
|
||||
// A chain past the limit is left out rather than rejected; it must not
|
||||
// still draw its innermost image through the exhausted depth budget.
|
||||
assert!(!drawn, "{levels} levels: the too-deep image is left out");
|
||||
break;
|
||||
}
|
||||
assert!(drawn, "{levels} levels: the innermost rect draws through every level");
|
||||
accepted = levels;
|
||||
}
|
||||
Err(_) => assert!(accepted > 0, "a one-level chain renders"),
|
||||
}
|
||||
}
|
||||
assert!((20..=MAX_EMBEDDED_SVG_DEPTH).contains(&accepted), "deepest accepted chain: {accepted}");
|
||||
|
||||
@@ -412,44 +412,27 @@ fn damaged_layer_data_opens_flattened_part(part: u64) {
|
||||
/// the file is retagged MinIsBlack first. The result is then a multiband image of every sample,
|
||||
/// which is what libtiff's `TIFFReadScanline` returns and what a RIP walks.
|
||||
fn independent_samples(bytes: &[u8]) -> (u16, Vec<u16>, Vec<u16>, u32, Vec<u8>) {
|
||||
let mut tags = tiff::decoder::Decoder::new(std::io::Cursor::new(bytes)).expect("tiff tags");
|
||||
let spp: u16 = tags.get_tag_unsigned(tiff::tags::Tag::SamplesPerPixel).expect("spp");
|
||||
let bps = tags.get_tag_u16_vec(tiff::tags::Tag::BitsPerSample).expect("bps");
|
||||
let extra = tags.get_tag_u16_vec(tiff::tags::Tag::ExtraSamples).unwrap_or_default();
|
||||
let rows = tags.find_tag_unsigned::<u32>(tiff::tags::Tag::RowsPerStrip).ok().flatten().unwrap_or(0);
|
||||
let patched = photometric_min_is_black(bytes);
|
||||
let mut dec = tiff::decoder::Decoder::new(std::io::Cursor::new(patched.as_slice())).expect("tiff decode");
|
||||
let tiff::decoder::DecodingResult::U8(samples) = dec.read_image().expect("read image") else {
|
||||
panic!("expected 8-bit samples");
|
||||
};
|
||||
(spp, bps, extra, rows, samples)
|
||||
}
|
||||
|
||||
/// Classic-TIFF photometric tag 262 → 1 (MinIsBlack), value stored inline in the IFD entry.
|
||||
fn photometric_min_is_black(src: &[u8]) -> Vec<u8> {
|
||||
let mut bytes = src.to_vec();
|
||||
let le = bytes.first().copied() == Some(b'I');
|
||||
let ru16 = |b: &[u8], i: usize| -> Option<u16> {
|
||||
let s = b.get(i..i + 2)?;
|
||||
Some(if le { u16::from_le_bytes([s[0], s[1]]) } else { u16::from_be_bytes([s[0], s[1]]) })
|
||||
};
|
||||
let ru32 = |b: &[u8], i: usize| -> Option<u32> {
|
||||
let s = b.get(i..i + 4)?;
|
||||
Some(if le { u32::from_le_bytes(s.try_into().ok()?) } else { u32::from_be_bytes(s.try_into().ok()?) })
|
||||
};
|
||||
let Some(ifd) = ru32(&bytes, 4) else { return bytes };
|
||||
let Some(n) = ru16(&bytes, ifd as usize) else { return bytes };
|
||||
for e in 0..n as usize {
|
||||
let at = ifd as usize + 2 + e * 12;
|
||||
if ru16(&bytes, at) == Some(262) {
|
||||
let value = if le { 1u16.to_le_bytes() } else { 1u16.to_be_bytes() };
|
||||
if let Some(slot) = bytes.get_mut(at + 8..at + 10) {
|
||||
slot.copy_from_slice(&value);
|
||||
use std::io::Read;
|
||||
let tiff = craft_tiff::Tiff::parse(bytes).expect("tiff tags");
|
||||
let ifd = tiff.ifds.first().expect("ifd0");
|
||||
let spp = ifd.u16(craft_tiff::tags::SAMPLES_PER_PIXEL).expect("spp");
|
||||
let bps: Vec<u16> = ifd.value(craft_tiff::tags::BITS_PER_SAMPLE).expect("bps").to_u64_vec().into_iter().map(|v| v as u16).collect();
|
||||
let extra: Vec<u16> = ifd.value(craft_tiff::tags::EXTRA_SAMPLES).map(|v| v.to_u64_vec().into_iter().map(|x| x as u16).collect()).unwrap_or_default();
|
||||
let rows = ifd.u32(craft_tiff::tags::ROWS_PER_STRIP).unwrap_or(0);
|
||||
let info = craft_tiff::image::ImageInfo::from_ifd(ifd).expect("tiff info");
|
||||
let comp = ifd.u16(craft_tiff::tags::COMPRESSION).unwrap_or(1);
|
||||
let mut samples = Vec::new();
|
||||
for chunk in info.chunks(bytes.len() as u64) {
|
||||
let raw = craft_tiff::image::chunk_bytes(bytes, &chunk).expect("chunk bytes");
|
||||
match comp {
|
||||
1 => samples.extend_from_slice(raw),
|
||||
8 | 32946 => {
|
||||
flate2::read::ZlibDecoder::new(raw).read_to_end(&mut samples).expect("deflate");
|
||||
}
|
||||
break;
|
||||
other => panic!("unexpected compression {other} in tiff_layers test"),
|
||||
}
|
||||
}
|
||||
bytes
|
||||
(spp, bps, extra, rows, samples)
|
||||
}
|
||||
|
||||
fn assert_plane(samples: &[u8], spp: usize, plane: usize, expected: &[u8]) {
|
||||
@@ -616,8 +599,8 @@ fn transparent_tiff_without_channels_keeps_image_alpha() {
|
||||
let img = photocraft_codecs::decode(&r.bytes).unwrap();
|
||||
assert!(img.layout().has_alpha(), "{layers}");
|
||||
assert!(img.meta.extra_samples.is_empty(), "{layers}");
|
||||
let mut dec = tiff::decoder::Decoder::new(std::io::Cursor::new(r.bytes.as_slice())).unwrap();
|
||||
let extra = dec.get_tag_u16_vec(tiff::tags::Tag::ExtraSamples).unwrap();
|
||||
let parsed = craft_tiff::Tiff::parse(&r.bytes).unwrap();
|
||||
let extra: Vec<u16> = parsed.ifds[0].value(craft_tiff::tags::EXTRA_SAMPLES).unwrap().to_u64_vec().into_iter().map(|x| x as u16).collect();
|
||||
assert_eq!(extra, vec![2], "{layers}");
|
||||
assert!(!r.warnings.iter().any(|w| w.contains("Save Transparency")), "{layers}: {:?}", r.warnings);
|
||||
if layers {
|
||||
|
||||
@@ -33,8 +33,12 @@ fn save(doc: &Document, layers: bool, transparency: Option<bool>) -> ExportResul
|
||||
}
|
||||
|
||||
fn extra_samples_tag(bytes: &[u8]) -> Vec<u16> {
|
||||
let mut dec = tiff::decoder::Decoder::new(std::io::Cursor::new(bytes)).unwrap();
|
||||
dec.get_tag_u16_vec(tiff::tags::Tag::ExtraSamples).unwrap_or_default()
|
||||
let tiff = craft_tiff::Tiff::parse(bytes).unwrap();
|
||||
tiff.ifds
|
||||
.first()
|
||||
.and_then(|ifd| ifd.value(craft_tiff::tags::EXTRA_SAMPLES))
|
||||
.map(|v| v.to_u64_vec().into_iter().map(|x| x as u16).collect())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// A TIFF's channel resources: the names in 1006, and the byte lengths of DisplayInfo (1077)
|
||||
|
||||
@@ -27,7 +27,7 @@ rayon = { workspace = true }
|
||||
[dev-dependencies]
|
||||
photocraft-raw = { path = ".", features = ["testgen"] }
|
||||
# Writes sRGB PNG previews in the `rawinfo` example.
|
||||
png = "0.18"
|
||||
photocraft-codecs = { workspace = true }
|
||||
# JPEG XL encoder used by legacy test fixtures only.
|
||||
zune-jpegxl = { version = "=0.5.2", default-features = false, features = ["std"] }
|
||||
zune-core = "0.5"
|
||||
|
||||
@@ -236,11 +236,13 @@ fn write_png(path: &str, dev: &photocraft_raw::Developed) {
|
||||
}
|
||||
}
|
||||
}
|
||||
let Ok(f) = std::fs::File::create(path) else { return eprintln!("{path}: cannot create") };
|
||||
let mut enc = png::Encoder::new(std::io::BufWriter::new(f), ow as u32, oh as u32);
|
||||
enc.set_color(png::ColorType::Rgb);
|
||||
enc.set_depth(png::BitDepth::Eight);
|
||||
if let Err(e) = enc.write_header().and_then(|mut w| w.write_image_data(&out)) {
|
||||
eprintln!("{path}: {e}");
|
||||
let img = photocraft_codecs::Image::from_u8(ow as u32, oh as u32, photocraft_codecs::ChannelLayout::Rgb, out).unwrap();
|
||||
match photocraft_codecs::encode(&img, photocraft_codecs::Format::Png, &Default::default()) {
|
||||
Ok(png) => {
|
||||
if let Err(e) = std::fs::write(path, png) {
|
||||
eprintln!("{path}: {e}");
|
||||
}
|
||||
}
|
||||
Err(e) => eprintln!("{path}: {e}"),
|
||||
}
|
||||
}
|
||||
@@ -118,5 +118,5 @@ modules:
|
||||
path: stage
|
||||
- type: git
|
||||
url: https://github.com/storytold/craft-i18n
|
||||
commit: e02939ef009218e81c44e8ec001fbb7603461de4
|
||||
commit: e56d26244bbac099bfd42e23fb12f78a4be418a7
|
||||
dest: craft-i18n
|
||||
@@ -132,5 +132,5 @@ modules:
|
||||
# The interface translations at the commit in craft-i18n.rev (a test keeps the two equal).
|
||||
- type: git
|
||||
url: https://github.com/storytold/craft-i18n
|
||||
commit: e02939ef009218e81c44e8ec001fbb7603461de4
|
||||
commit: e56d26244bbac099bfd42e23fb12f78a4be418a7
|
||||
dest: craft-i18n
|
||||
Reference in new issue
Block a user