Merge remote-tracking branch 'origin/main' into integration-batch-12

# Conflicts:
#	docs/file-format-parity.md
This commit is contained in:
David Mann committed 2026-11-02 20:15:23 +01:00
commit 673bfb4d9c
28 files changed
+742 -176

No files matched your search

Generated
+23
View File
@@ -1388,6 +1388,16 @@ dependencies = [
"thiserror 2.0.21",
]
[[package]]
name = "craft-pcraft-format"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=b8f7d93b00dfb8f172938f3d2d796ae62dcfe123#b8f7d93b00dfb8f172938f3d2d796ae62dcfe123"
dependencies = [
"serde",
"serde_json",
"thiserror 2.0.21",
]
[[package]]
name = "craft-print"
version = "0.1.0"
@@ -5199,6 +5209,7 @@ name = "photocraft-format"
version = "0.19.0"
dependencies = [
"blake3",
"craft-pcraft-format",
"crc32fast",
"exacl",
"flate2",
@@ -6651,6 +6662,17 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "sctk-adwaita"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6277f0217056f77f1d8f49f2950ac6c278c0d607c45f5ee99328d792ede24ec"
dependencies = [
"log",
"smithay-client-toolkit 0.19.2",
"tiny-skia",
]
[[package]]
name = "security-framework"
version = "3.7.0"
@@ -8920,6 +8942,7 @@ dependencies = [
"raw-window-handle",
"redox_syscall 0.4.1",
"rustix 0.38.44",
"sctk-adwaita",
"smithay-client-toolkit 0.19.2",
"smol_str",
"tracing",
+1
View File
@@ -42,6 +42,7 @@ photocraft-ipp = { path = "crates/ipp" }
craft-print = { git = "https://github.com/storytold/craft-libs", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7" }
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7" }
craft-jpeg = { git = "https://github.com/storytold/craft-libs", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7" }
craft-pcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "b8f7d93b00dfb8f172938f3d2d796ae62dcfe123" }
# craft-update: app-specific pretend versions apply to startup and manual checks.
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7", features = ["egui"] }
thiserror = "2"
+31
View File
@@ -23,6 +23,37 @@ https://github.com/storytold/craft-fonts/blob/main/ATTRIBUTION.md (today BIZ UDP
BIZ UDMincho; not the web build), under the SIL Open Font License 1.1. Their licence texts
ship with the package as OFL-<family>.txt.
Linux Wayland window decorations
-------------------------------
sctk-adwaita 0.10.1 (https://github.com/PolyMeilex/sctk-adwaita,
commit d5f343c45c04d4a026db57f76760819b7325db00) is used by winit on Linux
for vector window controls. Its title-font features are disabled: no Cantarell
font is embedded by this dependency and no font file is added to this repo.
sctk-adwaita's MIT licence:
MIT License
Copyright (c) 2022 Bartłomiej Maryńczak
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
The egui-icons font subset is embedded from epaint_default_fonts by crates/ui-egui/build.rs
and registered in the native and web fallback stacks by crates/ui-egui/src/egui_fonts.rs.
It is a subset of emoji-icon-font by John Slegers; the same upstream MIT license applies.
+1
View File
@@ -122,6 +122,7 @@ Detail and the next releases: [docs/roadmap.md](docs/roadmap.md).
| Date | Entry |
|---|---|
| 2026-10-21 | Linux can use font-free Adwaita controls when System Title Bar is selected, while the integrated CSD title bar remains the default (as in #4439). Saved preferences are respected; startup and preference-dialog regressions cover both choices (#6266). |
| 2026-10-17 | Object Finder classifies background by boundary coverage, retaining large enclosed foregrounds and rejecting surrounding backdrop (#6548); learned segmentation remains open (#2788) |
| 2026-10-10 | Full re-measure against Photoshop 2026 27.11.0 (installed bundle inspected): breadth ~76%, ready ~45%, alpha. Progress docs reorganized (`parity.md` → `parity-checklist.md`, `parity-estimate.md` merged into `target-app-parity.md`). 0.6.0 released. |
| 2026-10-09 | Remove tool, Rotate View, crop rotation; OpenRaster and Paint.NET; 39 Affinity documents in the corpus |
+1 -1
View File
@@ -100,7 +100,7 @@ futures-lite = "=2.6.1"
async-io = "=2.6.0"
# Open the window through Xwayland for a pen on Wayland (`tablet.rs`, #639): eframe doesn't
# re-export winit's `EventLoopBuilderExtX11`. Already in Cargo.lock (eframe); pinned exactly.
winit = { version = "=0.30.13", default-features = false, features = ["x11"] }
winit = { version = "=0.30.13", default-features = false, features = ["wayland-csd-adwaita-notitle", "x11"] }
# Safe Win32 wrappers on Windows: the pointer position for file drops (`cursor.rs`,
# GetCursorPos) and the window frame for the custom title bar (`window_frame.rs`, window styles),
+8 -5
View File
@@ -80,9 +80,9 @@ use photocraft_ui_egui::PhotocraftApp;
use photocraft_ui_egui::os_window::APP_ID;
/// Windows and Linux: no OS title bar; the app's top bar is the title bar, with its own caption
/// buttons and edge resizing (`photocraft_ui_egui::titlebar`), as Photoshop does on Windows. macOS
/// keeps its traffic lights over the integrated title strip.
/// Windows and Linux can use the app's title bar, with its own caption buttons and edge resizing
/// (`photocraft_ui_egui::titlebar`); the preference below selects the mode. macOS always keeps its
/// system traffic lights over the integrated title strip.
const CUSTOM_TITLEBAR: bool = !cfg!(target_os = "macos");
/// Whether this start draws its own title bar: Windows and Linux do, unless Preferences ›
@@ -946,9 +946,12 @@ mod tests {
let dir = std::env::temp_dir().join(format!("pc-titlebar-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
let file = dir.join("prefs.json");
assert_eq!(super::custom_titlebar(None), super::CUSTOM_TITLEBAR, "no preferences file: the default");
let default_custom = super::CUSTOM_TITLEBAR;
assert_eq!(super::custom_titlebar(None), default_custom, "no preferences file: the platform default");
std::fs::write(&file, "not json").unwrap();
assert_eq!(super::custom_titlebar(Some(&file)), super::CUSTOM_TITLEBAR, "an unreadable file: the default");
assert_eq!(super::custom_titlebar(Some(&file)), default_custom, "an unreadable file: the platform default");
std::fs::write(&file, r#"{"interface":{}}"#).unwrap();
assert_eq!(super::custom_titlebar(Some(&file)), default_custom, "an older preference file: the platform default");
std::fs::write(&file, r#"{"interface":{"systemTitleBar":true}}"#).unwrap();
assert!(!super::custom_titlebar(Some(&file)));
assert_eq!(super::native_options(false).viewport.decorations, Some(true));
+4
View File
@@ -291,6 +291,10 @@ sync_github_name = true
[people.dylanmtaylor]
sync_github_name = true
[people.Yuki-init]
display_name = "DC@yuki.himejima"
sync_github_name = false
[people.sn-o-w]
real_name = "Cristian Silaghi"
sync_github_name = false
+4 -2
View File
@@ -254,8 +254,10 @@ embedded table (and a PNG's transparent entry) so `photocraft-io` can open them
ms in release). Image data cut off by the end of the file decodes with
`DecodeWarning::Truncated`; a file far too small for its declared size (more than any
compression could expand) is refused before allocating.
* YCbCr, CIE Lab, signed integers and compressions that the `tiff` crate lacks (CCITT,
JPEG-in-TIFF) return `Unsupported`.
* YCbCr with three 8- or 16-bit samples decodes to RGB. YCbCr with other sample counts or
bit depths returns `Unsupported`. JPEG-compressed YCbCr uses the full-range JFIF conversion.
* 8/16-bit CIELab and ICCLab decode to the Lab channel layout.
* Signed integer samples and unsupported compression methods return `Unsupported`.
* **TIFF encode** writes classic TIFF, or BigTIFF when `EncodeOptions::tiff_bigtiff` is set or
the file could pass 4 GiB. `Metadata::extra_samples` (up to 16) are written after the colour
and alpha samples, with their `kind` in the ExtraSamples tag (a reserved `kind` above 2 is
+1
View File
@@ -168,6 +168,7 @@ mod bands;
mod decode;
mod encode;
mod tags;
mod ycbcr;
pub use decode::TiffBands;
pub(crate) use decode::{decode, decode_page, orientation};
+33 -5
View File
@@ -2,6 +2,7 @@ use std::borrow::Cow;
use super::bands::{Tally, convert_ab, decode_bands, extra_sample_indices, refill_zeroed, split_extra_samples, zeroed};
use super::tags::{F, TAG_IMAGE_SOURCE_DATA, TAG_PHOTOSHOP, TAG_XMP, TEXT_TAGS, photoshop_tags};
use super::ycbcr::YCbCr;
use super::{
ChannelLayout, ChunkType, CodecError, DecodeWarning, Decoder, ExifDirs, File, Ifd, Image, Limits, Metadata, Read, SampleType, Seek, SeekFrom, Tag,
camera_raw, err, ifd, io, map_err, tiff_exif,
@@ -185,6 +186,9 @@ impl<'a> TiffBands<'a> {
// Missing chunks leave their rows as they are: they must start empty in every group.
buf = refill_zeroed(buf, len)?;
tally = tally + decode_bands(p, self.b, &mut buf, band, first, &mut [], 0)?;
if let Some(c) = p.ycbcr {
c.convert(&mut buf, p.lay.out_channels(), p.lay.out);
}
if let Some(signed) = p.lab {
convert_ab(&mut buf, p.lay.out_channels(), p.lay.out, signed, false);
}
@@ -520,6 +524,20 @@ fn header_patches(
Ok(patches)
}
/// Lab and YCbCr are converted after decoding, from 8 or 16-bit samples only: Lab needs at least
/// its three colour samples, YCbCr exactly three.
fn check_converted_model(photometric: u64, spp: u64, bits: u64, src: Src) -> Result<(), CodecError> {
let (name, samples_ok) = match photometric {
8 | 9 => ("Lab", spp >= 3),
6 => ("YCbCr", spp == 3),
_ => return Ok(()),
};
if samples_ok && matches!(src, Src::U8 | Src::U16) {
return Ok(());
}
Err(CodecError::unsupported(F, format!("{name} image with {spp} samples of {bits} bits")))
}
/// A directory checked and laid out for decoding, before any pixel is read.
pub(super) struct Prepared {
w: u32,
@@ -531,6 +549,8 @@ pub(super) struct Prepared {
tl: tiff::decoder::Limits,
/// Lab samples: `Some(true)` for CIELab (a* and b* stored signed), `Some(false)` for ICCLab.
lab: Option<bool>,
/// YCbCr samples: the conversion to RGB (#10316).
ycbcr: Option<YCbCr>,
/// The colour samples of a pixel in the file's colour model.
color: usize,
/// The ExtraSamples tag (0 unspecified, 1 associated alpha, 2 unassociated alpha).
@@ -567,6 +587,9 @@ fn decode_ifd(f: &File<'_>, dir: &Ifd, limits: &Limits) -> Result<Image, CodecEr
if tally.decoded == 0 && tally.missing > 0 {
return Err(err("the image data is missing (cut off or past the end of the file)"));
}
if let Some(c) = p.ycbcr {
c.convert(&mut data, p.lay.out_channels(), p.lay.out);
}
if let Some(signed) = p.lab {
convert_ab(&mut data, p.lay.out_channels(), p.lay.out, signed, false);
}
@@ -642,15 +665,17 @@ fn prepare(f: &File<'_>, dir: &Ifd, limits: &Limits, whole: bool) -> Result<Prep
// `tiff` crate as RGB, then labelled Lab with a* and b* in PhotoCraft's encoding
// (`convert_ab`).
let lab = matches!(photometric, 8 | 9);
if lab && (spp < 3 || !matches!(src, Src::U8 | Src::U16)) {
return Err(CodecError::unsupported(F, format!("Lab image with {spp} samples of {bits} bits")));
}
// YCbCr (6), as scanners and cameras write it (usually JPEG-compressed with subsampled
// chroma): the `tiff` crate decodes and upsamples the samples, and they are turned into RGB
// after decoding (#10316).
let ycbcr = photometric == 6;
check_converted_model(photometric, spp, bits, src)?;
// TIFF 6.0 lets any extra sample be the alpha (#1349). For RGB and CMYK the `tiff` crate
// returns the alpha only when it is the first extra sample: otherwise it is asked for every
// sample (as multiband gray) and the colour and alpha samples are picked here. An alpha
// position past the samples the file has is ignored.
let color: usize = match photometric {
2 | 8 | 9 => 3,
2 | 6 | 8 | 9 => 3,
5 => 4,
_ => 1,
};
@@ -686,6 +711,7 @@ fn prepare(f: &File<'_>, dir: &Ifd, limits: &Limits, whole: bool) -> Result<Prep
(if gray_alpha { ChannelLayout::GrayA } else { ChannelLayout::Gray }, usize::from(num_samples))
}
tiff::ColorType::RGB(_) => (ChannelLayout::Rgb, 3),
tiff::ColorType::YCbCr(_) if ycbcr => (ChannelLayout::Rgb, 3),
tiff::ColorType::RGBA(_) => (ChannelLayout::Rgba, 4),
tiff::ColorType::CMYK(_) => (ChannelLayout::Cmyk, 4),
tiff::ColorType::CMYKA(_) => (ChannelLayout::CmykA, 5),
@@ -729,8 +755,9 @@ fn prepare(f: &File<'_>, dir: &Ifd, limits: &Limits, whole: bool) -> Result<Prep
// strip or tile tables point at inside the file count (and never more than the file), so
// padding the file while pointing the chunks past its end does not raise the bound: the
// banded decoder has no whole-image `max_alloc` to fall back on.
let compression = f.tag_uint(dir, ifd::TAG_COMPRESSION).unwrap_or(1);
let stored = u64::from(w).saturating_mul(u64::from(h)).saturating_mul(spp).saturating_mul(bits).div_ceil(8);
let ratio: u64 = match f.tag_uint(dir, ifd::TAG_COMPRESSION).unwrap_or(1) {
let ratio: u64 = match compression {
1 => 4,
32773 => 130,
4 => cw.clamp(4096, 65_535),
@@ -814,6 +841,7 @@ fn prepare(f: &File<'_>, dir: &Ifd, limits: &Limits, whole: bool) -> Result<Prep
patches,
tl,
lab: lab.then_some(photometric == 8),
ycbcr: ycbcr.then(|| YCbCr::of(f, dir, compression, if out == SampleType::U16 { 65535.0 } else { 255.0 })),
color,
extra_kinds: extra,
extras_over_limit,
+222
View File
@@ -0,0 +1,222 @@
//! YCbCr (PhotometricInterpretation 6) to RGB, after the `tiff` crate has decoded the samples.
//!
//! The crate decompresses JPEG data and upsamples subsampled chroma, but hands back the stored
//! Y, Cb and Cr values. This module turns them into RGB in place: ReferenceBlackWhite scales the
//! codes and YCbCrCoefficients gives the luma weights. JPEG-compressed data (compression 7) uses
//! the JPEG (JFIF) conversion, full range with the BT.601 weights, and ignores both tags, as
//! libtiff does when it asks the JPEG library for RGB.
//!
//! # Sources
//!
//! - TIFF Revision 6.0 (Final, June 3, 1992), Section 21 "YCbCr Images", pp. 89–92; the
//! YCbCrCoefficients field and its inverse equations are on pp. 90–91:
//! `R = Cr·(2 - 2·LumaRed) + Y`, `B = Cb·(2 - 2·LumaBlue) + Y`,
//! `G = (Y - LumaBlue·B - LumaRed·R) / LumaGreen`.
//! <https://www.itu.int/itudoc/itu-t/com16/tiff-fx/docs/tiff6.pdf>
//! - libtiff, `libtiff/tif_color.c`: `TIFFYCbCrToRGBInit` (tables) and `TIFFYCbCrtoRGB` (per pixel).
//! <https://gitlab.com/libtiff/libtiff/-/blob/master/libtiff/tif_color.c>
//!
//! # Green: a compatibility choice
//!
//! Red and blue follow the spec. Green follows libtiff, which rewrites the spec's equation as
//! `G = Y - (LumaRed·(2 - 2·LumaRed) / LumaGreen)·Cr - (LumaBlue·(2 - 2·LumaBlue) / LumaGreen)·Cb`,
//! adding Y unscaled. The two agree only when the weights sum to 1. Every standard set does
//! (the spec's own examples, BT.601 and BT.709), but the spec only calls the weights "the
//! proportions of red, green, and blue respectively in luminance" and does not require the sum.
//! For other weights the spec's equation scales Y in green by `(1 - LumaRed - LumaBlue) / LumaGreen`,
//! which tints neutral grays.
//!
//! PhotoCraft deliberately follows libtiff here (decided in PR #10319, for issue #10316), so such
//! files open as they do in libtiff-based tools (ImageMagick, GIMP) and grays stay neutral. This is
//! a contributor choice, not a requirement of the spec; the test
//! `weights_that_do_not_sum_to_one_keep_grays_neutral` in `tests/it/tiff_ycbcr.rs` pins it.
use super::{File, Ifd, SampleType};
const TAG_YCBCR_COEFFICIENTS: u16 = 529;
const TAG_REFERENCE_BLACK_WHITE: u16 = 532;
/// BT.601 luma weights: the TIFF default for YCbCrCoefficients.
const BT601: [f64; 3] = [0.299, 0.587, 0.114];
/// How one file's YCbCr codes map to RGB.
#[derive(Clone, Copy, Debug, PartialEq)]
pub(super) struct YCbCr {
/// Luma weights of red, green and blue.
luma: [f64; 3],
/// Black and white codes of Y, Cb and Cr.
ref_bw: [f64; 6],
}
impl YCbCr {
/// The conversion for directory `dir`, whose samples have `max` as their largest code
/// (255 or 65535). Missing or unusable tags fall back to the TIFF defaults.
pub(super) fn of(f: &File<'_>, dir: &Ifd, compression: u64, max: f64) -> Self {
let defaults = Self::defaults(max);
if compression == 7 {
return defaults;
}
let luma = f
.tag_f64s(dir, TAG_YCBCR_COEFFICIENTS, 3)
.and_then(|v| <[f64; 3]>::try_from(v).ok())
.filter(|l| l.iter().all(|c| c.is_finite() && *c > 0.0 && *c < 1.0))
.unwrap_or(defaults.luma);
let ref_bw = f
.tag_f64s(dir, TAG_REFERENCE_BLACK_WHITE, 6)
.and_then(|v| <[f64; 6]>::try_from(v).ok())
.filter(|r| r.iter().all(|v| v.is_finite()) && r.as_chunks::<2>().0.iter().all(|[black, white]| (white - black).abs() > f64::EPSILON))
.unwrap_or(defaults.ref_bw);
YCbCr { luma, ref_bw }
}
/// TIFF's defaults: BT.601 weights, full-range luma, chroma centred on the middle code.
fn defaults(max: f64) -> Self {
let mid = (max + 1.0) / 2.0;
YCbCr { luma: BT601, ref_bw: [0.0, max, mid, max, mid, max] }
}
/// Converts interleaved Y, Cb, Cr pixels of `channels` samples (the first three are the
/// colour) to R, G, B in place. Other sample types are left as they are.
pub(super) fn convert(self, data: &mut [u8], channels: usize, sample: SampleType) {
match sample {
SampleType::U8 => {
let t = Tables::new(&self, 255);
for_each_pixel(data, channels, |px| {
if let [y, cb, cr, ..] = px {
let [r, g, b] = t.rgb(usize::from(*y), usize::from(*cb), usize::from(*cr));
(*y, *cb, *cr) = (r as u8, g as u8, b as u8);
}
});
}
SampleType::U16 => {
let t = Tables::new(&self, 65535);
for_each_pixel(data, channels * 2, |px| {
if let [y0, y1, b0, b1, r0, r1, ..] = px {
let get = |a: u8, b: u8| usize::from(u16::from_ne_bytes([a, b]));
let [r, g, b] = t.rgb(get(*y0, *y1), get(*b0, *b1), get(*r0, *r1));
[*y0, *y1] = (r as u16).to_ne_bytes();
[*b0, *b1] = (g as u16).to_ne_bytes();
[*r0, *r1] = (b as u16).to_ne_bytes();
}
});
}
_ => {}
}
}
}
/// Runs `f` on every `stride`-byte pixel, in parallel on native targets.
fn for_each_pixel(data: &mut [u8], stride: usize, f: impl Fn(&mut [u8]) + Sync + Send) {
if stride == 0 {
return;
}
#[cfg(not(target_arch = "wasm32"))]
{
use rayon::prelude::*;
// Bands of whole pixels, so each task has a useful amount of work.
let band = stride.saturating_mul(1 << 14);
data.par_chunks_mut(band).for_each(|b| b.chunks_exact_mut(stride).for_each(&f));
}
#[cfg(target_arch = "wasm32")]
data.chunks_exact_mut(stride).for_each(f);
}
/// Per-code contributions, so a pixel costs a few additions.
struct Tables {
max: f64,
/// Scaled luma of each Y code.
y: Vec<f64>,
/// Red and green contributions of each Cr code.
cr_r: Vec<f64>,
cr_g: Vec<f64>,
/// Green and blue contributions of each Cb code.
cb_g: Vec<f64>,
cb_b: Vec<f64>,
}
impl Tables {
fn new(c: &YCbCr, max: u32) -> Self {
let m = f64::from(max);
let [lr, lg, lb] = c.luma;
let [y_black, y_white, cb_black, cb_white, cr_black, cr_white] = c.ref_bw;
// TIFF 6.0: chroma codes span ±(max + 1) / 2 - 1 around the black code; with the
// default ReferenceBlackWhite that is the code minus the middle code.
let half = (m + 1.0) / 2.0 - 1.0;
let codes = || (0..=max).map(f64::from);
let y = codes().map(|v| (v - y_black) * m / (y_white - y_black)).collect();
let cb: Vec<f64> = codes().map(|v| (v - cb_black) * half / (cb_white - cb_black)).collect();
let cr: Vec<f64> = codes().map(|v| (v - cr_black) * half / (cr_white - cr_black)).collect();
// R = Y + (2 - 2·Lr)·Cr and B = Y + (2 - 2·Lb)·Cb (TIFF 6.0 p. 91); green as libtiff:
// G = Y - (Lr·(2 - 2·Lr) / Lg)·Cr - (Lb·(2 - 2·Lb) / Lg)·Cb (see the module notes).
let (kr, kb) = (2.0 - 2.0 * lr, 2.0 - 2.0 * lb);
Tables {
max: m,
y,
cr_r: cr.iter().map(|v| kr * v).collect(),
cr_g: cr.iter().map(|v| -lr * kr * v / lg).collect(),
cb_g: cb.iter().map(|v| -lb * kb * v / lg).collect(),
cb_b: cb.iter().map(|v| kb * v).collect(),
}
}
/// R, G and B of one pixel, rounded and clamped to the code range.
fn rgb(&self, y: usize, cb: usize, cr: usize) -> [u32; 3] {
let at = |t: &[f64], i: usize| t.get(i).copied().unwrap_or(0.0);
let yv = at(&self.y, y);
// Green adds Y unscaled, as libtiff does (see "Green: a compatibility choice" above).
let r = yv + at(&self.cr_r, cr);
let g = yv + at(&self.cr_g, cr) + at(&self.cb_g, cb);
let b = yv + at(&self.cb_b, cb);
[r, g, b].map(|v| v.round().clamp(0.0, self.max) as u32)
}
}
#[cfg(test)]
mod tests {
use super::*;
fn convert(c: &YCbCr, px: [u8; 3]) -> [u8; 3] {
let mut d = px.to_vec();
c.convert(&mut d, 3, SampleType::U8);
[d[0], d[1], d[2]]
}
#[test]
fn jfif_conversion_matches_known_colours() {
let c = YCbCr::defaults(255.0);
assert_eq!(convert(&c, [0, 128, 128]), [0, 0, 0]);
assert_eq!(convert(&c, [255, 128, 128]), [255, 255, 255]);
assert_eq!(convert(&c, [128, 128, 128]), [128, 128, 128]);
// Pure red, green and blue as JFIF encodes them.
assert_eq!(convert(&c, [76, 85, 255]), [254, 0, 0]);
assert_eq!(convert(&c, [150, 44, 21]), [0, 255, 1]);
assert_eq!(convert(&c, [29, 255, 107]), [0, 0, 254]);
}
#[test]
fn sixteen_bit_and_extra_samples() {
let c = YCbCr::defaults(65535.0);
let mut d: Vec<u8> = [65535u16, 32768, 32768, 1234].iter().flat_map(|v| v.to_ne_bytes()).collect();
c.convert(&mut d, 4, SampleType::U16);
let v: Vec<u16> = d.as_chunks::<2>().0.iter().map(|b| u16::from_ne_bytes(*b)).collect();
assert_eq!(v, [65535, 65535, 65535, 1234]);
}
#[test]
fn studio_range_reference_black_white() {
// Y 16–235, chroma 128 ± 112 (ITU-R BT.601 studio range).
let c = YCbCr { luma: BT601, ref_bw: [16.0, 235.0, 128.0, 240.0, 128.0, 240.0] };
assert_eq!(convert(&c, [16, 128, 128]), [0, 0, 0]);
assert_eq!(convert(&c, [235, 128, 128]), [255, 255, 255]);
}
#[test]
fn odd_buffers_do_not_panic() {
let c = YCbCr::defaults(255.0);
let mut d = vec![1u8, 2];
c.convert(&mut d, 3, SampleType::U8);
c.convert(&mut d, 0, SampleType::U8);
c.convert(&mut d, 0, SampleType::U16);
assert_eq!(d, [1, 2]);
}
}
+20 -5
View File
@@ -236,18 +236,33 @@ impl<'a> File<'a> {
/// The first value of a numeric tag as a float: RATIONAL, FLOAT, DOUBLE or an integer.
pub fn tag_f64(&self, ifd: &Ifd, tag: u16) -> Option<f64> {
self.float(ifd.get(tag)?, 0)
}
/// The values of a numeric tag as floats, when it holds exactly `n` (`None` for any other
/// count or an unreadable value).
pub fn tag_f64s(&self, ifd: &Ifd, tag: u16, n: u64) -> Option<Vec<f64>> {
let e = ifd.get(tag)?;
if e.count == 0 {
if e.count != n {
return None;
}
(0..n).map(|i| self.float(e, i)).collect()
}
/// Value `i` of a numeric entry as a float: RATIONAL, FLOAT, DOUBLE or an integer.
fn float(&self, e: &Entry, i: u64) -> Option<f64> {
if i >= e.count {
return None;
}
let at = e.value_at.checked_add(i.checked_mul(type_size(e.ty)?)?)?;
match e.ty {
5 => {
let (n, d) = (self.u32_at(e.value_at)?, self.u32_at(e.value_at.checked_add(4)?)?);
let (n, d) = (self.u32_at(at)?, self.u32_at(at.checked_add(4)?)?);
(d != 0).then(|| f64::from(n) / f64::from(d))
}
11 => Some(f64::from(f32::from_bits(self.u32_at(e.value_at)?))),
12 => Some(f64::from_bits(self.u64_at(e.value_at)?)),
_ => self.uint(e, 0).map(|v| v as f64),
11 => Some(f64::from(f32::from_bits(self.u32_at(at)?))),
12 => Some(f64::from_bits(self.u64_at(at)?)),
_ => self.uint(e, i).map(|v| v as f64),
}
}
+1
View File
@@ -31,6 +31,7 @@ mod tiff_lab;
mod tiff_pages;
mod tiff_photoshop;
mod tiff_regressions;
mod tiff_ycbcr;
mod webp_frames;
mod webp_lossy;
mod xpm;
+259
View File
@@ -0,0 +1,259 @@
//! YCbCr TIFFs (PhotometricInterpretation 6), as scanners write them: JPEG-compressed with 2×2
//! chroma subsampling, and uncompressed with ReferenceBlackWhite and YCbCrCoefficients (#10316).
//! Every file here is hand-built by `common::tiffgen`.
use crate::common::sample_icc;
use crate::common::tiffgen::*;
use photocraft_codecs::*;
const COMPRESSION: u16 = 259;
const SUBSAMPLING: u16 = 530;
const YCBCR_COEFFICIENTS: u16 = 529;
const REFERENCE_BLACK_WHITE: u16 = 532;
const ICC_PROFILE: u16 = 34675;
/// A directory whose Compression is `c`.
fn compressed(mut d: Dir, c: u64) -> Dir {
d.entries.retain(|e| e.0 != COMPRESSION);
d.tag(COMPRESSION, SHORT, &[c])
}
/// A little-endian RATIONAL value for `tiffgen`.
fn rational(num: u32, den: u32) -> u64 {
u64::from(num) | (u64::from(den) << 32)
}
/// The image's pixels as RGB bytes.
fn rgb(img: &Image) -> Vec<u8> {
img.to_rgba8().as_chunks::<4>().0.iter().flat_map(|[r, g, b, _]| [*r, *g, *b]).collect()
}
/// A smooth colour test card, `w`×`h` RGB.
fn card(w: u32, h: u32) -> Vec<u8> {
let mut v = Vec::new();
for y in 0..h {
for x in 0..w {
v.extend([(x * 255 / (w - 1)) as u8, (y * 255 / (h - 1)) as u8, (255 - x * 255 / (w - 1)) as u8]);
}
}
v
}
/// A 4:2:0 baseline JPEG stream of `rgb`.
fn jpeg(rgb: &[u8], w: u32, h: u32) -> Vec<u8> {
let img = Image::from_raw(w, h, ChannelLayout::Rgb, SampleType::U8, rgb.to_vec()).unwrap();
encode(&img, Format::Jpeg, &EncodeOptions { jpeg_chroma_subsampling: true, ..Default::default() }).unwrap()
}
#[test]
fn jpeg_compressed_ycbcr_with_subsampled_chroma_reads_as_rgb() {
let (w, h) = (32, 24);
let stream = jpeg(&card(w, h), w, h);
// The stream really is subsampled: the luma component samples 2×2 in the frame header.
let sof = stream.windows(2).position(|m| m == [0xFF, 0xC0]).expect("baseline frame header");
assert_eq!(stream[sof + 11], 0x22, "luma sampling factors");
let dir = compressed(strips(w, h, 8, 3, 6, h, &stream), 7).tag(SUBSAMPLING, SHORT, &[2, 2]);
let file = build(true, false, &[dir], &[0]).bytes;
let img = decode(&file).unwrap();
assert_eq!((img.width(), img.height(), img.layout(), img.sample_type()), (w, h, ChannelLayout::Rgb, SampleType::U8));
// The oracle: the same JPEG stream decoded to RGB by an independent decoder.
let want = image::load_from_memory_with_format(&stream, image::ImageFormat::Jpeg).unwrap().to_rgb8().into_raw();
let worst = rgb(&img).iter().zip(&want).map(|(g, o)| g.abs_diff(*o)).max().unwrap();
assert!(worst <= 2, "largest difference from the oracle: {worst}");
}
#[test]
fn uncompressed_ycbcr_uses_the_default_conversion() {
// Black, white, mid gray and JFIF's pure red, without subsampling.
let px = [0, 128, 128, 255, 128, 128, 128, 128, 128, 76, 85, 255];
let dir = strips(4, 1, 8, 3, 6, 1, &px).tag(SUBSAMPLING, SHORT, &[1, 1]);
let img = decode(&build(true, false, &[dir], &[0]).bytes).unwrap();
assert_eq!(img.layout(), ChannelLayout::Rgb);
assert_eq!(rgb(&img), [0, 0, 0, 255, 255, 255, 128, 128, 128, 254, 0, 0]);
}
#[test]
fn reference_black_white_sets_the_code_range() {
// Studio range: Y 16–235, chroma 128 ± 112.
let rbw = [rational(16, 1), rational(235, 1), rational(128, 1), rational(240, 1), rational(128, 1), rational(240, 1)];
let dir = strips(2, 1, 8, 3, 6, 1, &[16, 128, 128, 235, 128, 128]).tag(SUBSAMPLING, SHORT, &[1, 1]).tag(REFERENCE_BLACK_WHITE, RATIONAL, &rbw);
let img = decode(&build(true, false, &[dir], &[0]).bytes).unwrap();
assert_eq!(rgb(&img), [0, 0, 0, 255, 255, 255]);
}
#[test]
fn weights_that_do_not_sum_to_one_keep_grays_neutral() {
// 0.25 each (sum 0.75): TIFF 6.0's full inverse would scale green's Y by (1 − Lr − Lb) / Lg
// = 2 and give mid gray G 255 (clamped). Like libtiff, green keeps Y, so gray stays gray, and
// the weights still set the chroma terms: R = Y + 1.5·Cr, B = Y + 1.5·Cb.
let weights = [rational(1, 4), rational(1, 4), rational(1, 4)];
let dir = strips(2, 1, 8, 3, 6, 1, &[128, 128, 128, 128, 64, 192]).tag(SUBSAMPLING, SHORT, &[1, 1]).tag(YCBCR_COEFFICIENTS, RATIONAL, &weights);
let img = decode(&build(true, false, &[dir], &[0]).bytes).unwrap();
// Green for the second pixel: 128 − (Lb·1.5/Lg)·Cb − (Lr·1.5/Lg)·Cr = 128 + 96 − 96.
assert_eq!(rgb(&img), [128, 128, 128, 224, 128, 32]);
}
#[test]
fn ycbcr_coefficients_set_the_luma_weights() {
// Weights 0.25, 0.5, 0.25 with Cb −64 and Cr +64: R = Y + 1.5·Cr, B = Y + 1.5·Cb, and G keeps Y
// (BT.601 would give R 218 and B 15).
let weights = [rational(1, 4), rational(1, 2), rational(1, 4)];
let dir = strips(1, 1, 8, 3, 6, 1, &[128, 64, 192]).tag(SUBSAMPLING, SHORT, &[1, 1]).tag(YCBCR_COEFFICIENTS, RATIONAL, &weights);
let img = decode(&build(true, false, &[dir], &[0]).bytes).unwrap();
assert_eq!(rgb(&img), [224, 128, 32]);
}
#[test]
fn ycbcr_tags_with_the_wrong_count_use_the_defaults() {
// Four weights and seven black/white codes: both tags are malformed, so BT.601 and full range
// apply (the weights alone would give 224, 128, 32).
let weights = [rational(1, 4), rational(1, 2), rational(1, 4), rational(1, 4)];
let rbw = [rational(16, 1), rational(235, 1), rational(128, 1), rational(240, 1), rational(128, 1), rational(240, 1), rational(0, 1)];
let dir = strips(1, 1, 8, 3, 6, 1, &[128, 64, 192]).tag(SUBSAMPLING, SHORT, &[1, 1]).tag(YCBCR_COEFFICIENTS, RATIONAL, &weights).tag(
REFERENCE_BLACK_WHITE,
RATIONAL,
&rbw,
);
let img = decode(&build(true, false, &[dir], &[0]).bytes).unwrap();
assert_eq!(rgb(&img), [218, 104, 15]);
}
#[test]
fn sixteen_bit_ycbcr_reads_as_rgb() {
let px: Vec<u8> = [65535u16, 32768, 32768, 0, 32768, 32768].iter().flat_map(|v| v.to_le_bytes()).collect();
let dir = strips(2, 1, 16, 3, 6, 1, &px).tag(SUBSAMPLING, SHORT, &[1, 1]);
let img = decode(&build(true, false, &[dir], &[0]).bytes).unwrap();
assert_eq!((img.layout(), img.sample_type()), (ChannelLayout::Rgb, SampleType::U16));
let n = img.to_normalized();
assert!(n[..3].iter().all(|&v| v == 1.0) && n[3..].iter().all(|&v| v == 0.0), "{n:?}");
}
#[test]
#[cfg(target_pointer_width = "64")]
fn sixteen_bit_ycbcr_bands_match_whole_decode_with_a_missing_last_strip() {
// On 32-bit targets max_alloc also bounds the whole image, so a small allocation cap
// cannot force these tiny strips into separate output groups there.
let (w, h, rows) = (4u32, 5u32, 2u32);
let pixels = [[0u16, 32768, 32768], [65535, 32768, 32768], [19595, 21710, 65535], [32768, 40960, 24576]];
let samples: Vec<u16> = (0..w * h).flat_map(|i| pixels[i as usize % pixels.len()]).collect();
let weights = [rational(1, 4), rational(1, 2), rational(1, 4)];
let icc = sample_icc(512);
for little in [true, false] {
for missing in [false, true] {
let dir = strips(w, h, 16, 3, 6, rows, &u16s(&samples, little)).tag(SUBSAMPLING, SHORT, &[1, 1]).tag(YCBCR_COEFFICIENTS, RATIONAL, &weights).bytes(
ICC_PROFILE,
UNDEFINED,
&icc,
);
let mut file = build(little, false, &[dir], &[0]);
if missing {
let past = file.bytes.len() as u64 + 4096;
patch_value(&mut file, little, false, 0, 273, 2, past);
}
let want = decode_with(&file.bytes, &DecodeOptions { keep_orientation: true, ..Default::default() }).unwrap();
let limits = Limits { max_alloc: u64::from(w * rows * 3 * 2), ..Limits::banded() };
let mut bands = TiffBands::open(&file.bytes, None, &limits).unwrap();
assert_eq!((bands.dimensions(), bands.layout(), bands.sample_type()), ((w, h), ChannelLayout::Rgb, SampleType::U16));
let mut got = Image::new(w, h, bands.layout(), bands.sample_type()).unwrap();
let mut positions = Vec::new();
bands
.decode(|x, y, group: &Image| -> Result<(), CodecError> {
positions.push((x, y, group.height()));
assert_eq!((x, group.width(), group.layout(), group.sample_type()), (0, w, ChannelLayout::Rgb, SampleType::U16));
let at = y as usize * w as usize * 3 * 2;
got.data_mut()[at..at + group.data().len()].copy_from_slice(group.data());
Ok(())
})
.unwrap();
assert_eq!(positions, [(0, 0, 2), (0, 2, 2), (0, 4, 1)], "one output group per strip, including the short last strip");
assert_eq!(got.data(), want.data(), "little endian: {little}, missing last strip: {missing}");
assert_eq!(bands.icc, want.icc);
assert_eq!(bands.meta, want.meta);
assert_eq!(bands.warnings, want.warnings);
assert_eq!(bands.warnings.iter().any(|w| matches!(w, DecodeWarning::Truncated { .. })), missing);
}
}
}
#[test]
fn unsupported_ycbcr_files_fail_cleanly() {
// Four samples (an extra sample next to YCbCr).
let four = strips(1, 1, 8, 4, 6, 1, &[128, 128, 128, 255]).tag(SUBSAMPLING, SHORT, &[1, 1]);
assert!(decode(&build(true, false, &[four], &[0]).bytes).is_err());
// Subsampled chroma without JPEG compression (the default subsampling is 2×2).
let sub = strips(2, 2, 8, 3, 6, 2, &[128; 12]);
assert!(decode(&build(true, false, &[sub], &[0]).bytes).is_err());
// A JPEG strip that is not JPEG data.
let junk = compressed(strips(16, 16, 8, 3, 6, 16, &[0x5A; 64]), 7).tag(SUBSAMPLING, SHORT, &[2, 2]);
assert!(decode(&build(true, false, &[junk], &[0]).bytes).is_err());
// Coefficients and ReferenceBlackWhite that would divide by zero fall back to the defaults.
let bad = strips(1, 1, 8, 3, 6, 1, &[255, 128, 128])
.tag(SUBSAMPLING, SHORT, &[1, 1])
.tag(YCBCR_COEFFICIENTS, RATIONAL, &[rational(0, 1), rational(0, 0), rational(5, 1)])
.tag(REFERENCE_BLACK_WHITE, RATIONAL, &[rational(7, 1); 6]);
let img = decode(&build(true, false, &[bad], &[0]).bytes).unwrap();
assert_eq!(&img.to_rgba8()[..3], &[255, 255, 255]);
}
#[test]
fn tiled_jpeg_ycbcr_keeps_its_icc_profile() {
// Two 16×16 tiles, each its own 4:2:0 JPEG stream, and an embedded profile, like a scanner's
// tiled output.
let (w, h, t) = (32u32, 16u32, 16u32);
let px = card(w, h);
let tile = |tx: u32| -> Vec<u8> {
(0..t)
.flat_map(|y| {
let at = ((y * w + tx * t) * 3) as usize;
px[at..at + (t * 3) as usize].to_vec()
})
.collect()
};
let streams = [jpeg(&tile(0), t, t), jpeg(&tile(1), t, t)];
let icc = sample_icc(512);
let dir = Dir { entries: base(w, h, 8, 3, 6), chunks: streams.to_vec(), tiled: true };
let dir = compressed(dir, 7).tag(322, SHORT, &[u64::from(t)]).tag(323, SHORT, &[u64::from(t)]).tag(SUBSAMPLING, SHORT, &[2, 2]).bytes(
ICC_PROFILE,
UNDEFINED,
&icc,
);
let img = decode(&build(true, false, &[dir], &[0]).bytes).unwrap();
assert_eq!((img.width(), img.height(), img.layout()), (w, h, ChannelLayout::Rgb));
assert_eq!(img.icc.as_deref(), Some(icc.as_slice()), "the embedded profile is kept");
// The oracle: each tile's stream decoded by an independent decoder, placed side by side.
let tiles: Vec<Vec<u8>> = streams.iter().map(|s| image::load_from_memory_with_format(s, image::ImageFormat::Jpeg).unwrap().to_rgb8().into_raw()).collect();
let row = (t * 3) as usize;
let want: Vec<u8> = (0..t as usize).flat_map(|y| [&tiles[0][y * row..(y + 1) * row], &tiles[1][y * row..(y + 1) * row]].concat()).collect();
let worst = rgb(&img).iter().zip(&want).map(|(g, o)| g.abs_diff(*o)).max().unwrap();
assert!(worst <= 2, "largest difference from the oracle: {worst}");
}
#[test]
fn big_endian_sixteen_bit_ycbcr_reads_as_rgb() {
// White, black, and red as full-range 16-bit YCbCr (Y 0.299·65535, Cb 32768 − 0.1687·65535, Cr max).
let px = [65535u16, 32768, 32768, 0, 32768, 32768, 19595, 21710, 65535];
let dir = strips(3, 1, 16, 3, 6, 1, &u16s(&px, false)).tag(SUBSAMPLING, SHORT, &[1, 1]);
let file = build(false, false, &[dir], &[0]).bytes;
assert_eq!(&file[..2], b"MM");
let img = decode(&file).unwrap();
assert_eq!((img.layout(), img.sample_type()), (ChannelLayout::Rgb, SampleType::U16));
let n = img.to_normalized();
let want = [1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0];
assert!(n.iter().zip(want).all(|(g, w)| (g - w).abs() < 2.0 / 255.0), "{n:?}");
}
#[test]
fn planar_ycbcr_reads_as_rgb_in_both_byte_orders() {
// The pixels of the default-conversion test, one plane per component.
let px = [0u8, 128, 128, 255, 128, 128, 128, 128, 128, 76, 85, 255];
for little in [true, false] {
let dir = Dir { entries: base(4, 1, 8, 3, 6), chunks: planar_strips(&px, 4, 1, 3, 1, 1), tiled: false }.tag(278, LONG, &[1]).tag(284, SHORT, &[2]).tag(
SUBSAMPLING,
SHORT,
&[1, 1],
);
let img = decode(&build(little, false, &[dir], &[0]).bytes).unwrap();
assert_eq!(rgb(&img), [0, 0, 0, 255, 255, 255, 128, 128, 128, 254, 0, 0], "little endian: {little}");
}
}
+2 -1
View File
@@ -295,7 +295,8 @@ pub struct Interface {
pub show_bounding_box_when_dragging_layer: bool,
/// Windows and Linux: use the system's title bar and window buttons instead of PhotoCraft's
/// own one-row title bar (tiling window managers, desktops that draw their own decorations;
/// #1271, #1316). Read when the app starts. macOS always uses the system's.
/// #1271, #1316). The integrated title bar remains the default on Linux and Windows;
/// the system frame is opt-in. Read when the app starts. macOS always uses the system's.
pub system_title_bar: bool,
/// Show the active document's file name in the title bar and the OS window title. The tabs
/// already name the file, so this can be turned off for a plain "PhotoCraft" title (#5037).
+16
View File
@@ -1,5 +1,21 @@
use super::*;
#[test]
fn system_title_bar_defaults_to_integrated_and_preserves_saved_choices() {
let default = false;
assert_eq!(Interface::default().system_title_bar, default);
for saved in [json!({}), json!({"interface": {}})] {
let prefs: Preferences = serde_json::from_value(saved).unwrap();
assert_eq!(prefs.interface.system_title_bar, default);
}
for saved in [false, true] {
let prefs: Preferences = serde_json::from_value(json!({"interface": {"systemTitleBar": saved}})).unwrap();
assert_eq!(prefs.interface.system_title_bar, saved);
let restored: Preferences = serde_json::from_value(prefs.to_json()).unwrap();
assert_eq!(restored.interface.system_title_bar, saved);
}
}
fn session() -> Session {
let mut s = Session::new();
s.execute("file.new", json!({"width": 32, "height": 32})).unwrap();
+1
View File
@@ -15,6 +15,7 @@ photocraft-color = { workspace = true }
photocraft-raster = { workspace = true }
photocraft-doc = { workspace = true }
photocraft-codecs = { workspace = true }
craft-pcraft-format = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true, features = ["unbounded_depth", "float_roundtrip"] }
thiserror = { workspace = true }
+1 -1
View File
@@ -451,7 +451,7 @@ fn sweep_orphans(recovery_dir: &Path, min_age: std::time::Duration) {
}
// Anything at the sidecar's path (even a broken one) keeps the bundle.
let has_sidecar = std::fs::symlink_metadata(recovery_dir.join(format!("{key}.json"))).is_ok();
let parts = [path.clone(), path.join("tiles"), path.join("blobs")];
let parts = [path.clone(), path.join(craft_pcraft_format::TILES_DIR), path.join(craft_pcraft_format::BLOBS_DIR)];
// A committed bundle is recoverable work: keep exactly what `list_recovery` lists.
if !has_sidecar && sidecarless_entry(recovery_dir, &path).is_none() && parts.iter().all(|p| untouched_for(p, min_age, true)) {
let _ = std::fs::remove_dir_all(&path);
+2 -4
View File
@@ -81,9 +81,7 @@ fn key4(s: &str) -> Result<[u8; 4]> {
unhex(s)?.try_into().map_err(|_| FormatError::corrupt(format!("bad 4-byte key `{s}`")))
}
pub(crate) fn is_valid_hash(h: &str) -> bool {
h.len() == 64 && h.bytes().all(|b| b.is_ascii_digit() || (b'a'..=b'f').contains(&b))
}
pub(crate) use craft_pcraft_format::is_valid_hash;
/// Convert native-endian sample bytes to little-endian in place (and back:
/// the swap is an involution).
@@ -110,7 +108,7 @@ fn surface_m(s: &Surface, sink: &mut dyn Sink) -> SurfaceM {
let mut dp = vec![0u8; f.bytes_per_pixel()];
encode_pixel(&f, &s.default_pixel(), &mut dp);
swap_to_le(&mut dp, f.sample);
SurfaceM { format: f, default: hex(&dp), tiles: s.tiles().map(|(c, t)| TileRef { tx: c.tx, ty: c.ty, hash: sink.tile(f, t) }).collect() }
SurfaceM { format: f, default: hex(&dp), tiles: s.tiles().map(|(c, t)| TileRef::new(c.tx, c.ty, sink.tile(f, t))).collect() }
}
fn opt_blob(b: &Option<Arc<Vec<u8>>>, sink: &mut dyn Sink) -> Option<Hash> {
+19 -4
View File
@@ -50,7 +50,7 @@ pub use read::read_file;
pub use store::{ByteSource, DEFAULT_REVERIFY_BUDGET, PcraftWriter, SaveStats, read_entry};
/// File extension of the native format.
pub const EXTENSION: &str = "pcraft";
pub use craft_pcraft_format::EXTENSION;
#[derive(Debug, thiserror::Error)]
pub enum FormatError {
@@ -76,6 +76,20 @@ impl FormatError {
}
}
impl From<craft_pcraft_format::Error> for FormatError {
fn from(e: craft_pcraft_format::Error) -> Self {
use craft_pcraft_format::Error;
match e {
Error::Corrupt(m) => FormatError::Corrupt(m),
Error::Unsupported(m) => FormatError::Unsupported(m),
Error::TooNew { found, supported, .. } => FormatError::TooNew { found, supported },
Error::LimitExceeded(m) => FormatError::LimitExceeded(m),
Error::Json(e) => FormatError::Json(e),
other => FormatError::Corrupt(other.to_string()),
}
}
}
pub type Result<T> = std::result::Result<T, FormatError>;
/// Previews to embed. The format crate cannot render (it sits beside the
@@ -119,10 +133,11 @@ pub const MAX_CANVAS_PIXELS: u64 = MAX_CANVAS_SIDE as u64 * MAX_CANVAS_SIDE as u
impl Default for LoadOptions {
fn default() -> Self {
let limits = craft_pcraft_format::Limits::default();
LoadOptions {
max_manifest_bytes: 256 << 20,
max_blob_bytes: 1 << 30,
max_total_bytes: 16 << 30,
max_manifest_bytes: limits.max_manifest_bytes,
max_blob_bytes: limits.max_blob_bytes,
max_total_bytes: limits.max_total_bytes,
preserve_ids: true,
max_canvas_side: MAX_CANVAS_SIDE,
max_canvas_pixels: MAX_CANVAS_PIXELS,
+4 -24
View File
@@ -14,24 +14,11 @@ use photocraft_doc::{
use photocraft_geom::{Affine, Size};
use serde::{Deserialize, Serialize};
/// Current manifest version written by this build.
pub const FORMAT_VERSION: u32 = 1;
pub use craft_pcraft_format::{FORMAT_VERSION, Hash, TileRef};
/// Hex-encoded BLAKE3 hash (64 chars).
pub type Hash = String;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Manifest {
pub format_version: u32,
/// Free-form writer identification, e.g. `photocraft-format 0.1.0`.
pub generator: String,
pub document: DocM,
/// Optional previews present in the bundle.
#[serde(default)]
pub thumbnail: Option<String>,
#[serde(default)]
pub composite: Option<String>,
}
/// The manifest: craft-pcraft-format's envelope (`format_version`, `generator`, the optional
/// `thumbnail` and `composite` previews) around the document [`DocM`].
pub type Manifest = craft_pcraft_format::Manifest<DocM>;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct DocM {
@@ -154,13 +141,6 @@ pub struct NamedPathM {
pub psd_raw: Option<Hash>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TileRef {
pub tx: i32,
pub ty: i32,
pub hash: Hash,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SurfaceM {
pub format: PixelFormat,
+15 -29
View File
@@ -1,43 +1,29 @@
//! Manifest migrations. Each step upgrades the raw JSON from version `n` to
//! `n + 1`, so old bundles keep loading as the schema evolves.
use serde_json::Value;
use crate::FormatError;
use crate::manifest::FORMAT_VERSION;
use crate::{FormatError, Result};
pub(crate) type Step = fn(&mut Value) -> Result<()>;
pub(crate) type Step = craft_pcraft_format::Step<FormatError>;
/// `STEPS[i]` upgrades version `i + 1` to `i + 2`. Empty while version 1 is
/// the only version.
/// the only version. `craft_pcraft_format::read_manifest_with` runs them on load.
pub(crate) const STEPS: &[Step] = &[];
/// Upgrade `v` in place to `target` using `steps`.
pub(crate) fn migrate_with(v: &mut Value, steps: &[Step], target: u32) -> Result<u32> {
let found = v.get("format_version").and_then(Value::as_u64).ok_or_else(|| FormatError::corrupt("manifest has no format_version"))?;
let found = u32::try_from(found).map_err(|_| FormatError::corrupt("format_version out of range"))?;
if found == 0 {
return Err(FormatError::corrupt("format_version 0 is invalid"));
}
if found > target {
return Err(FormatError::TooNew { found, supported: target });
}
for ver in found..target {
let step = steps.get(ver as usize - 1).ok_or_else(|| FormatError::Unsupported(format!("no migration from format {ver}")))?;
step(v)?;
v["format_version"] = Value::from(ver + 1);
}
Ok(found)
}
pub(crate) fn migrate(v: &mut Value) -> Result<u32> {
migrate_with(v, STEPS, FORMAT_VERSION)
}
#[cfg(test)]
mod tests {
use super::*;
use serde_json::json;
use crate::Result;
use crate::manifest::FORMAT_VERSION;
use serde_json::{Value, json};
/// Upgrade `v` in place to `target` using `steps`, with craft-pcraft-format's runner.
fn migrate_with(v: &mut Value, steps: &[Step], target: u32) -> Result<u32> {
craft_pcraft_format::migrate(v, steps, target)
}
fn migrate(v: &mut Value) -> Result<u32> {
migrate_with(v, STEPS, FORMAT_VERSION)
}
fn rename_title(v: &mut Value) -> Result<()> {
let t = v["document"]["title"].take();
+42 -92
View File
@@ -15,21 +15,12 @@ use crate::manifest::{ContentM, FORMAT_VERSION, Hash, LayerM, Manifest};
use crate::zip::{ZipReader, ZipWriter};
use crate::{FormatError, LoadOptions, Result, SaveOptions};
pub(crate) const MANIFEST: &str = "manifest.json";
pub(crate) const THUMB: &str = "thumb.png";
pub(crate) const COMPOSITE: &str = "composite/preview.png";
/// The file a directory save holds an exclusive lock on for its whole transaction (#4957).
pub(crate) const SAVE_LOCK: &str = "save.lock";
use craft_pcraft_format::{BLOBS_DIR, COMPOSITE_DIR, TILES_DIR, blob_path, tile_path};
// `SAVE_LOCK` is the file a directory save holds an exclusive lock on for its whole transaction (#4957).
pub(crate) use craft_pcraft_format::{COMPOSITE, MANIFEST, SAVE_LOCK, THUMB};
/// How long a directory save waits for another save of the same bundle to finish.
const SAVE_LOCK_WAIT: std::time::Duration = std::time::Duration::from_secs(10);
fn tile_path(h: &str) -> String {
format!("tiles/{h}.zst")
}
fn blob_path(h: &str) -> String {
format!("blobs/{h}.zst")
}
/// The bytes an [`Object`] stores, owned by (or shared with) the compressor's source so one
/// [`Compressor`] can be reused for objects of any lifetime.
enum Source {
@@ -228,64 +219,27 @@ pub fn read_entry(file: &mut impl std::io::Read, len: u64, max: usize, path: &st
// Loading
// ---------------------------------------------------------------------------
/// Deepest JSON nesting a manifest may have: each group level adds three (the layer object, its
/// content object and the `children` array), with headroom for the document and leaf layer fields.
/// The saver checks the same bound, so every bundle it writes loads again.
const MAX_MANIFEST_DEPTH: usize = 3 * (convert::MAX_GROUP_DEPTH + 1) + 64;
/// Most JSON items (arrays and objects opened, plus elements and members after a comma) a
/// manifest may hold. Parsing builds a `serde_json::Value` tree of tens of bytes per item, so
/// `[0,0,…]` costs about 16× its size in memory; a typical manifest spends 20 bytes or more per
/// item, so this still admits manifests of about 80 MiB.
const MAX_MANIFEST_ITEMS: usize = 4 << 20;
/// Rejects JSON nested deeper than [`MAX_MANIFEST_DEPTH`] or holding more than
/// [`MAX_MANIFEST_ITEMS`] items with a linear scan (no recursion), so parsing with serde_json's
/// recursion limit disabled can't exhaust the stack, nor tiny values the memory, on hostile input.
fn check_manifest_depth(json: &[u8]) -> Result<()> {
let (mut depth, mut items, mut in_str, mut escaped) = (0usize, 0usize, false, false);
for &b in json {
if in_str {
match b {
_ if escaped => escaped = false,
b'\\' => escaped = true,
b'"' => in_str = false,
_ => {}
}
continue;
}
match b {
b'"' => in_str = true,
b'[' | b'{' => {
depth += 1;
if depth > MAX_MANIFEST_DEPTH {
return Err(FormatError::LimitExceeded(format!("manifest JSON nested deeper than {MAX_MANIFEST_DEPTH} levels")));
}
}
b']' | b'}' => depth = depth.saturating_sub(1),
_ => {}
}
if matches!(b, b'[' | b'{' | b',') {
items += 1;
if items > MAX_MANIFEST_ITEMS {
return Err(FormatError::LimitExceeded(format!("manifest JSON holds more than {MAX_MANIFEST_ITEMS} values")));
}
}
}
Ok(())
/// The limits a manifest is checked against: craft-pcraft-format's item limit, the JSON nesting
/// of [`convert::MAX_GROUP_DEPTH`] nested groups ([`craft_pcraft_format::manifest_depth`]) and at
/// most `max_manifest_bytes` bytes. The saver checks the same nesting and items, so every bundle
/// it writes loads again.
fn manifest_limits(max_manifest_bytes: usize) -> craft_pcraft_format::Limits {
let mut limits = craft_pcraft_format::Limits::default();
limits.max_manifest_bytes = max_manifest_bytes;
limits.max_depth = craft_pcraft_format::manifest_depth(convert::MAX_GROUP_DEPTH);
limits
}
pub(crate) fn read_manifest(src: &dyn ByteSource, opts: &LoadOptions) -> Result<Manifest> {
let raw = src.get(MANIFEST, opts.max_manifest_bytes)?;
// serde_json stops at 128 levels (about 40 nested groups); the bounded check replaces that limit.
check_manifest_depth(&raw)?;
let mut de = serde_json::Deserializer::from_slice(&raw);
de.disable_recursion_limit();
let mut v = <serde_json::Value as serde::Deserialize>::deserialize(&mut de)?;
de.end()?;
crate::migrate::migrate(&mut v)?;
let layers = take_array(&mut v, "/document/layers");
let mut m: Manifest = serde_json::from_value(v)?;
// serde_json stops at 128 levels (about 40 nested groups); `read_manifest_with` checks the
// nesting and the items in one pass, then parses without that limit.
let limits = manifest_limits(opts.max_manifest_bytes);
let mut layers = Vec::new();
let mut m: Manifest = craft_pcraft_format::read_manifest_with(&raw, &limits, crate::migrate::STEPS, FORMAT_VERSION, |mut document| {
layers = take_array(&mut document, "/layers");
Ok::<_, FormatError>(serde_json::from_value(document)?)
})?;
m.document.layers = layers_from_json(layers)?;
// A number past f32's range decodes as infinity, which no save could write back (#6862).
if let Err(crate::finite::Problem::NonFinite { path }) = crate::finite::check(&m) {
@@ -342,11 +296,10 @@ impl LoadFetch<'_> {
impl Fetch for LoadFetch<'_> {
fn tile(&mut self, hash: &str, len: usize) -> Result<Vec<u8>> {
if !is_valid_hash(hash) {
let Some(path) = tile_path(hash) else {
return Err(FormatError::corrupt(format!("invalid tile hash `{hash}`")));
}
};
self.account(len)?;
let path = tile_path(hash);
let z = self.src.get(&path, len + len / 8 + 4096)?;
let data = decompress(&z, len, &path)?;
if hash_bytes(&data) != hash {
@@ -367,10 +320,9 @@ impl Fetch for LoadFetch<'_> {
if let Some(b) = self.blobs.get(hash) {
return if b.len() <= limit { Ok(b.clone()) } else { Err(FormatError::LimitExceeded("optional preview blob exceeds its limit".into())) };
}
if !is_valid_hash(hash) {
let Some(path) = blob_path(hash) else {
return Err(FormatError::corrupt(format!("invalid blob hash `{hash}`")));
}
let path = blob_path(hash);
};
// The stored zstd frame of incompressible data is a little larger than the data, so a
// blob right at `limit` must still be read; `decompress_bounded` enforces `limit`.
let z = self.src.get(&path, limit.saturating_add(limit / 8).saturating_add(4096))?;
@@ -686,7 +638,7 @@ fn bundle_root(dir: &Path) -> Result<PathBuf> {
std::fs::create_dir_all(&dir)?;
let root = std::fs::canonicalize(&dir)?;
plain_directory_or_missing(&root)?;
for sub in ["tiles", "blobs", "composite"] {
for sub in [TILES_DIR, BLOBS_DIR, COMPOSITE_DIR] {
let path = root.join(sub);
plain_directory_or_missing(&path)?;
if !path.exists() {
@@ -706,7 +658,7 @@ fn bundle_root(dir: &Path) -> Result<PathBuf> {
fn validate_bundle_file(root: &Path, path: &Path) -> Result<()> {
let parent = path.parent().ok_or_else(|| unsafe_bundle_entry(path))?;
if parent != root && parent != root.join("tiles") && parent != root.join("blobs") && parent != root.join("composite") {
if parent != root && parent != root.join(TILES_DIR) && parent != root.join(BLOBS_DIR) && parent != root.join(COMPOSITE_DIR) {
return Err(unsafe_bundle_entry(path));
}
plain_directory_or_missing(parent)?;
@@ -863,9 +815,9 @@ impl BundleGc {
let flags = gc_directory_flags();
let root = open(root, flags, Mode::empty()).map_err(std::io::Error::from)?;
let tiles = openat(&root, "tiles", flags, Mode::empty()).map_err(std::io::Error::from)?;
let blobs = openat(&root, "blobs", flags, Mode::empty()).map_err(std::io::Error::from)?;
let composite = openat(&root, "composite", flags, Mode::empty()).map_err(std::io::Error::from)?;
let tiles = openat(&root, TILES_DIR, flags, Mode::empty()).map_err(std::io::Error::from)?;
let blobs = openat(&root, BLOBS_DIR, flags, Mode::empty()).map_err(std::io::Error::from)?;
let composite = openat(&root, COMPOSITE_DIR, flags, Mode::empty()).map_err(std::io::Error::from)?;
Ok(Self { root, tiles, blobs, composite })
}
@@ -875,8 +827,8 @@ impl BundleGc {
THUMB => (&self.root, THUMB),
COMPOSITE => (&self.composite, "preview.png"),
_ => match relative.split_once('/') {
Some(("tiles", name)) if name.strip_suffix(".zst").is_some_and(is_valid_hash) => (&self.tiles, name),
Some(("blobs", name)) if name.strip_suffix(".zst").is_some_and(is_valid_hash) => (&self.blobs, name),
Some((TILES_DIR, name)) if name.strip_suffix(craft_pcraft_format::OBJECT_SUFFIX).is_some_and(is_valid_hash) => (&self.tiles, name),
Some((BLOBS_DIR, name)) if name.strip_suffix(craft_pcraft_format::OBJECT_SUFFIX).is_some_and(is_valid_hash) => (&self.blobs, name),
_ => return Err(FormatError::Unsupported(format!("invalid bundle cleanup target: {relative}"))),
},
};
@@ -1000,13 +952,9 @@ impl PcraftWriter {
convert::check_nesting(&doc.layers)?;
let mut c = Collect { hash_cache: Some(&mut self.hash_cache), blob_hash_cache: Some(&mut self.blob_hash_cache), ..Default::default() };
let document = convert::doc_m(doc, &mut c);
let manifest = Manifest {
format_version: FORMAT_VERSION,
generator: format!("photocraft-format {}", env!("CARGO_PKG_VERSION")),
document,
thumbnail: opts.thumbnail.as_ref().map(|_| THUMB.to_owned()),
composite: opts.composite.as_ref().map(|_| COMPOSITE.to_owned()),
};
let mut manifest = Manifest::new(format!("photocraft-format {}", env!("CARGO_PKG_VERSION")), document);
manifest.thumbnail = opts.thumbnail.as_ref().map(|_| THUMB.to_owned());
manifest.composite = opts.composite.as_ref().map(|_| COMPOSITE.to_owned());
// serde_json writes NaN and the infinities as `null`, which the manifest's float fields
// refuse on load (issue #1101): refuse the save instead, naming the value.
crate::finite::check(&manifest).map_err(|e| match e {
@@ -1014,14 +962,16 @@ impl PcraftWriter {
crate::finite::Problem::Other(m) => FormatError::Unsupported(format!("manifest: {m}")),
})?;
let manifest = serde_json::to_vec_pretty(&manifest)?;
check_manifest_depth(&manifest)?;
// The nesting and the items only: a save checks no manifest size.
craft_pcraft_format::check_manifest(&manifest, &manifest_limits(usize::MAX))?;
let stats = SaveStats { tiles_total: c.tiles.len(), blobs_total: c.blobs.len(), manifest_bytes: manifest.len(), ..Default::default() };
let invalid = |h: &str| FormatError::corrupt(format!("invalid object hash `{h}`"));
let mut objects = BTreeMap::new();
for (h, (t, s)) in c.tiles {
objects.insert(tile_path(&h), Object::Tile(t, s));
objects.insert(tile_path(&h).ok_or_else(|| invalid(&h))?, Object::Tile(t, s));
}
for (h, b) in c.blobs {
objects.insert(blob_path(&h), Object::Blob(b));
objects.insert(blob_path(&h).ok_or_else(|| invalid(&h))?, Object::Blob(b));
}
Ok(Prepared { manifest, objects, stats })
}
@@ -1178,12 +1128,12 @@ impl PcraftWriter {
// flush. The retry can reuse those valid bytes (including cached ones), so flush
// both object directories again before publishing a manifest that references them.
// This also persists the fixed subdirectories of a newly created bundle.
for sub in ["tiles", "blobs"] {
for sub in [TILES_DIR, BLOBS_DIR] {
fs.sync_dir(&dir.join(sub)).map_err(|e| crate::atomic::publication_error(e, &dir.join(sub)))?;
}
}
#[cfg(not(windows))]
for sub in ["tiles", "blobs"] {
for sub in [TILES_DIR, BLOBS_DIR] {
let folder = dir.join(sub);
if folder.is_dir() {
confirm_flushed(&folder, &folder)?;
@@ -1560,7 +1510,7 @@ fn an_incompressible_blob_at_its_limit_still_loads() {
let z = Compressor::new().object(&Object::Blob(Arc::new(data.clone())));
assert!(z.len() > data.len(), "the fixture must not compress");
let hash = hash_bytes(&data);
let src = One(blob_path(&hash), z);
let src = One(blob_path(&hash).unwrap(), z);
let mut fetch = LoadFetch { src: &src, opts: crate::LoadOptions::default(), total: 0, blobs: HashMap::new() };
assert_eq!(fetch.blob_bounded(&hash, data.len()).unwrap().as_slice(), data.as_slice());
assert!(LoadFetch { src: &src, opts: crate::LoadOptions::default(), total: 0, blobs: HashMap::new() }.blob_bounded(&hash, data.len() - 1).is_err());
+23
View File
@@ -216,6 +216,13 @@ fn nesting_beyond_the_load_limit_is_refused_at_save() {
assert!(matches!(e, FormatError::LimitExceeded(_)), "{e}");
}
/// craft-pcraft-format's default manifest nesting limit is computed from its own copy of the
/// group depth, so the two must stay equal.
#[test]
fn group_depth_matches_craft_pcraft_format() {
assert_eq!(MAX_GROUP_DEPTH, craft_pcraft_format::MAX_GROUP_DEPTH);
}
#[test]
fn empty_document_roundtrips() {
let doc = Document::new("empty", photocraft_doc::Size::new(1, 1), ColorMode::Rgb, SampleType::U8);
@@ -524,6 +531,22 @@ fn save_is_deterministic() {
assert_eq!(a, b);
}
/// A bundle that is read and saved again gives the same bytes, previews included.
#[test]
fn save_load_save_gives_the_same_bytes() {
let mut preview = Rgba8Image::new(4, 3);
preview.pixels.iter_mut().enumerate().for_each(|(i, p)| *p = i as u8);
for opts in [SaveOptions::default(), SaveOptions { thumbnail: Some(preview.clone()), composite: Some(preview.clone()) }] {
for mode in MODES {
for depth in SampleType::ALL {
let first = save_to_bytes(&rich_doc(mode, depth), &opts).unwrap();
let again = save_to_bytes(&load_from_bytes(&first).unwrap(), &opts).unwrap();
assert!(first == again, "{mode:?} {depth:?}: the second save differs");
}
}
}
}
#[test]
fn not_pcraft() {
assert!(!is_pcraft(b""));
+1 -1
View File
@@ -145,7 +145,7 @@ mod title_tests {
#[test]
fn without_the_preference_the_mark_stays() {
// The default (e.g. the web build or the snapshot example): no custom bar, no preference.
// The default (e.g. the web build or snapshot example): the integrated title bar.
let app = crate::PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
assert!(!system_title_bar(&app));
}
+2
View File
@@ -36,6 +36,8 @@ building locally; the downloaded app is still subject to Windows application-con
## Build and run
On Linux, PhotoCraft keeps its integrated client-side decorated title bar by default (#4439), including desktop-matched buttons. Enabling **System Title Bar** in Preferences switches to the system frame at the next launch: on GNOME/Wayland, winit provides font-free Adwaita controls; on X11, the window manager supplies the frame. Explicit saved choices are respected and Windows/macOS defaults are unchanged.
```sh
cargo run --release -p photocraft -- path/to/image.psd # desktop app
cargo run --release -p photocraft -- --control 7878 --control-token-file .private/control.token \
+3 -2
View File
@@ -1,6 +1,6 @@
# File-format parity
> **Last reviewed:** 2026-10-12 · **Last updated:** 2026-10-31 · **Change:** minor (`.atn`: 144 supported events after Actions batch 12 (Groups A–I, command options, version 12 files, reference forms); the supported table and measured reference are in [atn.md](atn.md); TIFFs up to 300,000 px a side open, decoded a group of rows at a time into the layer, #8169; embedded AI/PDF/EPS save-back retains native format with a source-bound SVG display preview; PSD Filter Gallery: Halftone Pattern dot/circle/line settings survive PSD/PSB saves (#8940); Save for Web writes WebP, lossy or lossless, #6391; Photoshop's `MTrn` merged-transparency marker, from a layered TIFF saved with Save Transparency, marks the merged transparency, #8877; layered TIFF writes the TySh text version and descriptor in PSD big-endian order while the header, matrix, warp and bounds keep container order, #9098; layered TIFF writes Photoshop's 14-byte global layer mask, so Photoshop opens the layers instead of only the composite, #9095; legacy PSD point text placed from the layout ink box after font resolution, #6094; `.atn`: a recorded Save As imports with its format and file (`file.saveAs`, `file.saveACopy` for As a Copy) instead of as a plain Save that wrote over the played file, #7102; folder destinations stop playback until #5430; `.asl` layer style libraries read and written, #1051; JPEG Options on File › Save, Save As and Save a Copy, FILE-215-19 partial (no Matte, progressive Scans or size preview); 32-bit Hue/Saturation unclipped and Colorize as Photoshop does them, Photoshop-oracle floor 190/258, #5781; JPEG Options on Save As and Save a Copy, FILE-215-19; TIFF compression for scripted saves, `tiffCompression`, #5301; the Nikon D4 white level follows the sample depth (12 and 14 bit), #5978; Apply Layer Comp action mapping, #7101; Cineon write: 10-bit gray/RGB; animated WebP frames load into video layers, #1198; Photoshop mixed-order TIFF type geometry, #4758; DDS textures save: uncompressed or BC1–BC3, optional mip chain, DDS Options in Save As (#1327); PSD smart filters: 53 filters (39 more: Pinch, Polar Coordinates, Ripple, Spherize, Twirl, Wave, ZigZag, Invert, Blur, Surface Blur, Smart Sharpen, Diffuse, Wind, Offset, Mezzotint, Clouds, Difference Clouds, Fibers, Lens Flare and others) plus Hue/Saturation and Perspective Warp mapped both ways, #6296, #6298, #6300, #6302, #6304, #6314, #6316, #6267, #6268, FILE-215-2; large-file fixtures: a 20 MP layered PSD, a 150-layer layout, a 2 GB PSD and a 4.4 GB PSB generated at test time and round-tripped, FILE-216-2 done, #5107; earlier: smart objects keep Photoshop's Cylinder warp through re-renders and saves, #4112; PNG `sTER` stereo pairing kept on save, #6063; PDF write one flattened page via Save As / Save a Copy / CLI, #3401; CMYK Invert, Posterize and Threshold on the inks; smart filter masks on PSD open and save; Photoshop-oracle floor 188/258; lossy DNG, compression 34892, decodes with its levels and LinearizationTable applied to the stored 8-bit samples, FILE-215-11; CMYK Hue/Saturation and Color Balance keep the black ink; CMYK Posterize on the stored values, psd-tools oracle floor 242/309; CMYK adjustment layers composite on the document's inks; Photoshop-oracle floor 165/258; CMYK Brightness/Contrast on the inks, CMYK Threshold's luma; modern Brightness/Contrast's brightness curve; Photoshop-oracle floor 151/258; Lab documents composite on their stored L, a, b; Photoshop-oracle floor 152/258; Levels on whole levels at every step with Photoshop's shadow toe; Photoshop-oracle floor 146/258, psd-tools 238/309; 32-bit adjustments unclipped; Photoshop-oracle floor 149/258; mask feathers blur with their exact variance; Threshold splits on Photoshop's luminosity; a pass-through clipping base with an adjustment renders isolated; psd-tools oracle floor 240/309; 16-bit Posterize as Photoshop bins it; psd-tools oracle floor 241/309; Gradient Map luminosity; Photoshop-oracle floor 147/258; PSD: `Mt16`/`Mt32` merged transparency read; palette PNGs open in Indexed Color mode, #4804; 16-bit Lab Invert; Photoshop-oracle floor 145/258; `.atn` import maps 112 events; DDS textures open, #1327; DPX read and write, #1049; #2465 fixed: CS2 placed layers with only a `PlLd` block open their contents; Photoshop Actions `.atn` read and write; `.shc` contour files read and write; earlier the same day: indexed BMP palette mode; Save keeps a JPEG's quality and a WebP's encoding; Amiga IFF write: 24-plane ILBM, Save As `.iff`; PSD stores spot channels as Photoshop does, ink 0 = solid, and numbers them in 1053, #7415 split; TIFF writes and reads alpha and spot channels as extra samples with Photoshop's channel resources, PSD output unchanged, FILE-215-7, FILE-215-17's TIFF part, #7415; Photoshop's `MTrn` merged-transparency marker, from a layered TIFF saved with Save Transparency, marks the merged transparency) · **Target:** Adobe Photoshop 2026
> **Last reviewed:** 2026-10-12 · **Last updated:** 2026-10-31 · **Change:** minor (`.atn`: 144 supported events after Actions batch 12 (Groups A–I, command options, version 12 files, reference forms); the supported table and measured reference are in [atn.md](atn.md); TIFF: YCbCr images open as RGB, including JPEG-compressed scans with subsampled chroma, #10316; TIFFs up to 300,000 px a side open, decoded a group of rows at a time into the layer, #8169; embedded AI/PDF/EPS save-back retains native format with a source-bound SVG display preview; PSD Filter Gallery: Halftone Pattern dot/circle/line settings survive PSD/PSB saves (#8940); Save for Web writes WebP, lossy or lossless, #6391; Photoshop's `MTrn` merged-transparency marker, from a layered TIFF saved with Save Transparency, marks the merged transparency, #8877; layered TIFF writes the TySh text version and descriptor in PSD big-endian order while the header, matrix, warp and bounds keep container order, #9098; layered TIFF writes Photoshop's 14-byte global layer mask, so Photoshop opens the layers instead of only the composite, #9095; legacy PSD point text placed from the layout ink box after font resolution, #6094; `.atn`: a recorded Save As imports with its format and file (`file.saveAs`, `file.saveACopy` for As a Copy) instead of as a plain Save that wrote over the played file, #7102; folder destinations stop playback until #5430; `.asl` layer style libraries read and written, #1051; JPEG Options on File › Save, Save As and Save a Copy, FILE-215-19 partial (no Matte, progressive Scans or size preview); 32-bit Hue/Saturation unclipped and Colorize as Photoshop does them, Photoshop-oracle floor 190/258, #5781; JPEG Options on Save As and Save a Copy, FILE-215-19; TIFF compression for scripted saves, `tiffCompression`, #5301; the Nikon D4 white level follows the sample depth (12 and 14 bit), #5978; Apply Layer Comp action mapping, #7101; Cineon write: 10-bit gray/RGB; animated WebP frames load into video layers, #1198; Photoshop mixed-order TIFF type geometry, #4758; DDS textures save: uncompressed or BC1–BC3, optional mip chain, DDS Options in Save As (#1327); PSD smart filters: 53 filters (39 more: Pinch, Polar Coordinates, Ripple, Spherize, Twirl, Wave, ZigZag, Invert, Blur, Surface Blur, Smart Sharpen, Diffuse, Wind, Offset, Mezzotint, Clouds, Difference Clouds, Fibers, Lens Flare and others) plus Hue/Saturation and Perspective Warp mapped both ways, #6296, #6298, #6300, #6302, #6304, #6314, #6316, #6267, #6268, FILE-215-2; large-file fixtures: a 20 MP layered PSD, a 150-layer layout, a 2 GB PSD and a 4.4 GB PSB generated at test time and round-tripped, FILE-216-2 done, #5107; earlier: smart objects keep Photoshop's Cylinder warp through re-renders and saves, #4112; PNG `sTER` stereo pairing kept on save, #6063; PDF write one flattened page via Save As / Save a Copy / CLI, #3401; CMYK Invert, Posterize and Threshold on the inks; smart filter masks on PSD open and save; Photoshop-oracle floor 188/258; lossy DNG, compression 34892, decodes with its levels and LinearizationTable applied to the stored 8-bit samples, FILE-215-11; CMYK Hue/Saturation and Color Balance keep the black ink; CMYK Posterize on the stored values, psd-tools oracle floor 242/309; CMYK adjustment layers composite on the document's inks; Photoshop-oracle floor 165/258; CMYK Brightness/Contrast on the inks, CMYK Threshold's luma; modern Brightness/Contrast's brightness curve; Photoshop-oracle floor 151/258; Lab documents composite on their stored L, a, b; Photoshop-oracle floor 152/258; Levels on whole levels at every step with Photoshop's shadow toe; Photoshop-oracle floor 146/258, psd-tools 238/309; 32-bit adjustments unclipped; Photoshop-oracle floor 149/258; mask feathers blur with their exact variance; Threshold splits on Photoshop's luminosity; a pass-through clipping base with an adjustment renders isolated; psd-tools oracle floor 240/309; 16-bit Posterize as Photoshop bins it; psd-tools oracle floor 241/309; Gradient Map luminosity; Photoshop-oracle floor 147/258; PSD: `Mt16`/`Mt32` merged transparency read; palette PNGs open in Indexed Color mode, #4804; 16-bit Lab Invert; Photoshop-oracle floor 145/258; `.atn` import maps 112 events; DDS textures open, #1327; DPX read and write, #1049; #2465 fixed: CS2 placed layers with only a `PlLd` block open their contents; Photoshop Actions `.atn` read and write; `.shc` contour files read and write; earlier the same day: indexed BMP palette mode; Save keeps a JPEG's quality and a WebP's encoding; Amiga IFF write: 24-plane ILBM, Save As `.iff`; PSD stores spot channels as Photoshop does, ink 0 = solid, and numbers them in 1053, #7415 split; TIFF writes and reads alpha and spot channels as extra samples with Photoshop's channel resources, PSD output unchanged, FILE-215-7, FILE-215-17's TIFF part, #7415; Photoshop's `MTrn` merged-transparency marker, from a layered TIFF saved with Save Transparency, marks the merged transpaLine truncated
**PSD Filter Gallery (#8940, 2026-10-23):** Halftone Pattern maps its size, contrast and dot/circle/line pattern as editable settings on import and export, with the reference application's descriptor keys (`HlSz`, `Cntr`, `ScrT`: `ScrD`/`ScrC`/`ScrL`). PSD/PSB round trips pass at 8/16/32 bits. This does not claim pixel equivalence for the existing renderer. Unknown or malformed settings remain verbatim on import.
@@ -26,7 +26,7 @@ XL are missing (gap G10). Remaining: 300–500 h including PSD fidelity.
| PSD | R/W | yes | yes | 1/8/16/32-bit; Bitmap, Gray, Indexed, RGB, CMYK, Multichannel, Lab, Duotone; layers, groups, masks, vector masks, adjustment and fill layers, effects, text, shapes, smart objects (SoLd/lnk2 with their warp: the bend presets, a custom mesh and, since #4112, Cylinder; CS2 PlLd/lnkD read with their warp, kept as is or re-saved as SoLd once edited), smart filters (53 mapped, among them Invert, the Distort filters but Shear, Clouds, Difference Clouds, Fibers and Lens Flare, plus Hue/Saturation, Perspective Warp, Filter Gallery with Chrome and a Camera Raw subset, rest verbatim), slices, comps, Advanced Blending, each layer's XMP packet (`layer.xmpMetadata`); alpha and spot channels as Photoshop stores them (spot ink 0 = solid, channel identifiers in 1053), and PSDs with spot channels from PhotoCraft 0.1.0–0.16.0, which stored the ink the other way round, keep their ink. Oracle floors: Photoshop-authored 190/258, io 148/170, psd-tools 249/309; round trip ≥ 169/170, 308/309, 258/258. Known failures: #1281, #2469 (#2374, text layers, closed 2026-10-10; #2465, CS2 `PlLd`-only smart objects, fixed 2026-10-12) |
| PSB | R/W | yes | yes | Auto-switches above 2 GB (REL-212-2); generated 20 MP, 150-layer, 2 GB PSD and 4.4 GB PSB fixtures opened, saved and re-opened by io tests/it/large_files.rs (FILE-216-2, 2026-10-13; the 4.4 GB PSB opens on Windows); > 4 GB from the app's File › Open on Windows: #375 |
| Cloud PSD (.psdc) | R/W | no | no | Out of scope (Adobe cloud) |
| TIFF | R/W | yes | yes | 8/16/32f, Gray/RGB/CMYK, BigTIFF, every IFD, banded parallel decode; flat pages up to 300,000 px a side open a group of rows at a time into the layer, with no full-size copy, and are refused with an error when the machine lacks the memory (Linux: free RAM and swap, cgroup limits; #8169); layered TIFF both byte orders, including Photoshop mixed-order type blocks on read (#4758/#4771) and TySh text descriptors written in PSD order (#9098) and Photoshop's 14-byte `LMsk` block (#9095); LZW/ZIP for scripted saves by `tiffCompression`; undecodable type keeps saved pixels (FILE-215-7); alpha and spot channels as extra samples (at most 16) with Photoshop's names, ink colours and solidity, spot ink stored 0 = solid (#7415); no Save Transparency choice yet (channels are written as Photoshop does with it off) |
| TIFF | R/W | yes | yes | 8/16/32f, Gray/RGB/CMYK, YCbCr read as RGB (JPEG-compressed with subsampled chroma, or uncompressed without subsampling; #10316), BigTIFF, every IFD, banded parallel decode; flat pages up to 300,000 px a side open a group of rows at a time into the layer, with no full-size copy, and are refused with an error when the machine lacks the memory (Linux: free RAM and swap, cgroup limits; #8169); layered TIFF both byte orders, including Photoshop mixed-order type blocks on read (#4758/#4771) and TySh text descriptors written in PSD order (#9098) and Photoshop's 14-byte `LMsk` block (#9095); LZW/ZIP for scripted saves by `tiffCompression`; undecodable type keeps saved pixels (FILE-215-7); alpha and spot channels as extra samples (at most 16) with Photoshop's names, ink colours and solidity, spot ink stored 0 = solid (#7415); no Save Transparency choice yet (channels are written as Photoshop does with it off) |
| JPEG | R/W | yes | yes | 8-bit Gray/RGB/CMYK, ICC/EXIF/XMP; Save keeps the opened file's quality (estimated from its quantisation tables, #2399); File › Save, Save As and Save a Copy ask JPEG Options: Quality 0–12, starting at the opened file's quality or else the Export preference, and Baseline ("Standard") / Baseline Optimized / Progressive; scripts pass `quality`/`jpegFormat`, the CLI `--jpeg-format` (FILE-215-19). Baseline Optimized fits the Huffman tables only at 4:4:4 (Gray, CMYK) or progressive: RGB is written 4:2:0, which zune-jpeg 0.5.15 decodes wrongly with fitted tables, as in Save for Web. No Matte, progressive Scans (3–5) or size preview |
| PNG | R/W | yes | yes | 8/16-bit, ICC/text; APNG first frame only; alpha channels on open (#2225); palette PNGs open in Indexed Color mode with their transparent entry (#4804); Save keeps a stereo PNG's `sTER` pairing (#6063) |
| GIF | R/W | yes | yes | File › Open keeps the first frame; New Video Layer from File and Video Frames to Layers take every frame, with the timeline rate from the delays (#572). Per-frame delays and keeping the frames in `.pcraft` are not done |
@@ -163,6 +163,7 @@ The original reference entry retains its source date and historical totals; curr
| 2026-10-31 | minor | `.atn` Group D: twelve Stylize/Pixelate events load, play and save; 128 supported and 89 unmapped. Supported-table columns corrected against the event registry; the original 117/101 reference entry remains historical. |
| 2026-10-31 | minor | `.atn`: Split Channels (`SplC`, its recorded `documentIDs` not replayed or written), Merge Spot Channel (`MSpt`), Trap (`Trap`, `Wdth` clamped to 32767 px) and Match Color without a source (`matchColor`, `noReference`) map to `channel.split`, `channel.mergeSpot`, `image.trap` and `image.adjustments.matchColor`; a Match Color step that matches another image stays a Photoshop step (#10609) |
| 2026-10-31 | minor | `.atn`: Filter Gallery (`GEfc` with the effect in `GEfk`, or the effect's own event) maps all 47 effects to `filter.gallery.<effect>` with every key in recorded order, out-of-range values clamped and missing keys given Photoshop's defaults (was Spatter only); Glass maps the Frosted and Canvas textures (#10592) |
| 2026-10-30 | patch | TIFF: YCbCr (PhotometricInterpretation 6) opens as RGB instead of failing with "colour type YCbCr(8)": JPEG-compressed with subsampled chroma (as scanners write it) through the JPEG conversion, uncompressed with ReferenceBlackWhite and YCbCrCoefficients; 8 and 16-bit. Uncompressed subsampled YCbCr and YCbCr with extra samples still fail with a clear error (#10316) |
| 2026-10-26 | minor | Embedded AI/PDF/EPS save-back retains native format and a separate source-bound display preview; original sources remain undoable. Native Adobe interoperability and standalone EPS/DCS remain unverified; no corpus floor or percentage changed. |
| 2026-10-22 | minor | Embedded PSD vectors gain explicit bounded SVG editor/save-back; standalone EPS/DCS and native-format fidelity remain open. |
| 2026-10-22 | minor | TIFF: flat pages up to 300,000 px a side open (was 2^30 px, about 32,768²): `codecs::TiffBands` decodes a group of rows at a time into the layer's tiles. The 117,504 × 22,464 px banner from #8456 opens in 3.3 s at 11.45 GB peak for a 10.56 GB layer; 30,000² 6.8 s / 6.43 GB → 1.1 s / 3.86 GB; 36 MP 220 → 52 ms. Layered TIFFs still decode whole (#8169) |
+2
View File
@@ -137,6 +137,8 @@ fi
if has appimage; then
APPDIR="$WORK/PhotoCraft.AppDir"
cp -R "$STAGE" "$APPDIR"
# Preserve the sctk-adwaita MIT notice in the packaged AppImage.
install -Dm644 "$ROOT/NOTICE" "$APPDIR/usr/share/doc/photocraft/NOTICE"
# AppRun is a script, not a symlink: it installs the .desktop entry and icons into
# $XDG_DATA_HOME before launching, so Wayland compositors can resolve the window's
# app_id to our icon instead of the generic Wayland logo (#593; opt-out env in the