Preserve Josef Mlčůch’s PSD placement work and tests while adapting resource lookup to the current shared zero-copy HeadView and ResolutionInfo. Keep current main decoding and sanity limits.
* Formats: port the craft-libs cutover follow-ups from #2734 to main (craft-libs#778)
Brings #2734's changes (made against the release branch) to main:
IDML CDATA on write and table span parsing, DOCX plain-text accepted
changes, XLSX invalid number cells shown as written, shared CMYK JPEG
polarity, exact PPTX opacity, PDF CMYK fallback wording, and the
craft-libs re-pins. Imported DOCX built-in headings keep main's and
v0.21.0's spelling ("Heading 1"), with a test. craft-pdf, craft-prepress,
craft-cms, the krilla/hayro patches and craft-xml-dtd move to the #1322
squash merge on craft-libs main (a5ac3aa0).
Co-authored-by: Dylan M. Taylor <dylan@dylanmtaylor.com>
* Point the PDF dependency check at the craft-libs main pin
Co-authored-by: Dylan M. Taylor <dylan@dylanmtaylor.com>
* Formats: address review on the cutover follow-ups
- PDF: keep main's CMYK fallback warning. The shared decoder reads planar
CMYK TIFFs and makes associated alpha straight, so neither falls back;
a test now checks both keep their inks.
- DOCX plain-text import uses craft-wordmodel's Paragraph::final_text,
which already drops tracked deletions and expands inline objects.
- IDML: a test pins numeric table spans (fractions round down, spans past
the table or past 32 bits reach its edge, anything under 1 or not a
number spans one cell).
- Cargo.lock: craft-rtf takes craft-codepage at bfea7d98 after the merge
with main.
* PDF test: expect the CMYK fallback warning's main wording
---------
Co-authored-by: Dylan M. Taylor <dylan@dylanmtaylor.com>
A 16-bit CMYKA TIFF counts its five 16-bit samples beside the 8-bit CMYKA copy and the inks and alpha split from it, 20 bytes a pixel. The tiff encoder has no 16-bit CMYKA type, so the test defines one.
* Build: restore designcraft_format::write for recovery; render decodes without naming the image crate
* Build: collapse the nested if in images tone (clippy)
* IDML export: placements in cells and footnotes embed their PDF layer choices
* Tests: Word fixtures carry the document relationships part
* PDF/X-4: untagged WebP images carry sRGB
* Images: CMYK TIFFs with other inks fall back to RGB; associated alpha keeps its inks
craft-image-codecs' TiffPage lists InkSet (storytold/craft-libs#1307), so decode_cmyk_tiff
again refuses InkSet 2 instead of reading other inks as C, M, Y and K. Associated alpha
is made straight by the decoder; the PDF tests check those inks and that alpha.
* PDF tests: CMYK fallback expects the screen's RGB; alpha images read the masked image
The RGB fallback for other inks converts through the working CMYK space, as decode_rgba
does, so the test takes its expected samples from decode_rgba. image_color_samples took the
first image stream, which for an image with alpha is its soft mask.
* Images: repin craft-image-codecs to the InkSet enum (storytold/craft-libs#1307)
* Pin craft-image-codecs to storytold/craft-libs ea1c842 (#1307)
A placed PSD took 72 ppi for its natural size, so a 300 ppi file came in
four times larger than in the reference app. `raster_resolution` (#1991)
now reads a PSD's ResolutionInfo image resource (1005, 16.16 fixed
point), so a PSD is placed at its own ppi like JPEG, PNG, TIFF, WebP and
BMP; without a usable value (missing, shorter than its 16 bytes,
damaged, not positive) it stays at 72 ppi. The image-resource walk that
found the ICC profile (1039) now finds any resource by id, and both use
it.
Documents already holding a PSD keep their placed size; only new
placements (and Data Merge / table cell images) use the new size.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The gate that limits parallel decodes counted each image at its cached
size (4 bytes a pixel and a third more for the smaller levels). A decode
holds more than that while it converts the pixels: an 8-bit image keeps
its RGBA copy beside the decoded or the premultiplied pixels, 8 bytes a
pixel. Two 5,500 pixel square images passed the gate together and could
hold more than half the cache budget at once.
- decode_sizes returns the cached size and the peak size from one size
read. The peak counts the samples as stored beside their converted
copy (designcraft_images::decode_bytes_per_pixel): 8 bytes a pixel for
8-bit color, 10 for 16-bit RGB, 12 for 16-bit CMYK TIFFs and 16-bit
RGBA, 10 for 8-bit CMYKA TIFFs, 15 for 16-bit CMYKA TIFFs, 9 for
PSDs. An EPS counts as its TIFF preview. PDF pages, SVGs and EPS
files without a preview count 8.
- warm budgets the cache with the cached size and gates decodes with
the peak size.
- Every warm call in the process shares one gate, so the canvas
worker, thumbnails and exports together stay within half the budget
while they decode. warm returns the most its own call had decoding.
- An EPS without a preview is sized at the larger of its drawn
PostScript and its placeholder. The placeholder is clamped to 4000
pixels on each side, so a 10,000 by 4,000 point EPS that is not drawn
takes 4000 by 4000 pixels, not the 4000 by 1600 counted before.
The JPEG decoder takes the smallest scale that meets either requested
side. A short side rounds up to the same size at several scales, so a
100 x 2 JPEG asked for at a half decoded at an eighth (13 x 1). The
long side alone now picks the scale, and a decode whose size differs
from the requested reduction is refused, which falls back to the full
decode.
A reduced decode now applies the full decode's size limits before it
reads any image data:
- A file whose size pixel_size cannot read is refused, so the 256 Mpx
check always has a size to compare. The JPEG decoder's own reading of
the frame size is checked against the same limit.
- A progressive JPEG keeps the coefficients of the full-size image until
its last scan, whatever the output size. When those take more than
512 MiB (each component counted at full size, each side rounded up to
32 pixels), the reduced decode is refused and the full decode, with
its own limits, applies.
A placed JPEG drawn at a fraction of its pixel size was decoded at full
size first and then halved down to the level the screen needs. For a
24 MP photo that is a 96 MB decode per image, and with several such
images on a page the decoded pixels outgrow the image cache.
A YCbCr or grayscale JPEG whose wanted level is a half, a quarter or an
eighth of its size (or smaller) is now decoded at that size straight
from its compressed blocks with jpeg-decoder's scaled IDCT, cut to the
size the halving path gives the same level, and halved from there for
smaller levels. The embedded ICC profile is applied as in a full
decode. CMYK and YCCK JPEGs, other formats and the full size still
decode in full.
The RIFF size counts the bytes after its own field, so the container ends at
offset 8 plus the size, not 12. An EXIF chunk that ran up to four bytes past
the declared container was read when trailing bytes followed it. A new test
covers an exact size with and without trailing bytes, a size declared four
bytes short, and a file cut inside the EXIF chunk.
Paste ignored a bitmap on the system clipboard: a screenshot or an image
copied in a browser had to be saved and placed. Paste now places it.
- edit.pasteImage {base64, name?, spread?, at?} embeds the image in the
selected empty frame, or in a new frame centered on `at` at its stored
resolution (72 ppi when none) and at most 60% of the page width, as
File > Place sizes it. Save and reopen and IDML export keep the pixels.
Images over 64 million pixels and names without an image extension are
refused.
- Ctrl/Cmd+V pastes the image egui delivers with no text, and Edit >
Paste reads the clipboard's bitmap, or the first image file of a copied
file list, when there is no text or the text is only an address.
- The menu read waits at most 1.5 s on its own thread, with one read in
flight at a time.
- With a native menu, objects copied here still paste as objects until
the pasteboard's change count shows a newer copy.
- ui.paste takes {image} for the control channel.
Tests read a pHYs chunk behind 100 text chunks in a PNG, ignore a pHYs
after the image data, and read an EXIF chunk stored after 100 frames of
an animated WebP.
A JPEG whose EXIF resolution is 0 ppi or outside 1 to 100,000 ppi now
takes its size from its JFIF density instead of one point per pixel.
Tests place an 11 x 17 in image (330 x 510 px at 30 ppi) with a click,
check that it comes in at 792 x 1224 pt and keeps that size through a
save and reopen, and that an image with no stored resolution comes in
at 72 ppi.
A 600px photo saved at 600dpi places 1in wide, as in InDesign, instead
of one pixel per point. Reads JFIF/EXIF (JPEG), pHYs (PNG), EXIF (WebP),
pixels-per-meter (BMP) and TIFF resolution tags; insane metadata falls
back to 72ppi.
tone() decoded a GIF to RGBA and decode_cmyk_tiff() called read_image()
without the header check decode_rgba() runs. Both now call
too_large_to_decode() first. The decoders' own limits (image 512 MiB,
tiff 256 MiB) already refused these files; the guard refuses them from
the header instead.
With compressImages on, PDF export re-encodes rasters as JPEG in
recompress, which decoded with the image crate directly. A gray PNG
that decode_rgba refuses still decoded there, was copied and encoded
as JPEG, and only then dropped: krilla refuses a JPEG wider or taller
than 16,384 px, and every raster past the budget is. Exporting the
23,000 px PNG that way took 4.2 s and 1 GB more memory, for a PDF
without the image.
recompress now asks too_large_to_decode first, the check decode_rgba
uses, so the export skips the image with the same warning at once.
decode_rgba relied on the image crate's 512 MiB limit, which bounds
only the decoder's own output. A gray or 1-bit image just under it
expanded four times to RGBA, and render made a premultiplied copy on
top: a 288 KB PNG of 23,000 x 23,000 pixels froze the first draw for
9 s and took the app to 4.5 GB. The size is now read from the header
and anything past 256 Mpx is refused before decoding. It draws as an
empty frame, and PDF export skips it with a warning.
A 300 ppi scan of an A0 sheet (about 139 Mpx) still opens.