Skip to content

Image.DecodeCmyk, and the canvas without the experimental marker - #21

Merged
alftore merged 2 commits into
mainfrom
cmyk-planes
Nov 14, 2026
Merged

alftore merged 2 commits into
mainfrom
cmyk-planes

Conversation

@alftore

@alftore alftore commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Two changes for Zorg.Pdf, ahead of 0.5.0.

Image.DecodeCmyk. It decodes a CMYK JPEG (YCCK included) or a separated TIFF as its inks instead of converting to sRGB. The result is a CmykImage: four L8 planes running from 0 (no ink) to 255 (full ink), plus the file's CMYK profile. It's for print work, such as keeping a PDF image as DeviceCMYK.

  • Map applies one operation (Fit, Crop, Rotate, ...) to every plane alike.
  • ToInterleaved returns C, M, Y, K per pixel.
  • ToSrgb converts for the screen and gives the same pixels as Decode.
  • It returns null for files that aren't CMYK, decided from the header without decoding.
  • Shrink-on-load and orientation work as for Decode.
  • Speed: a 4000 × 3000 CMYK JPEG takes 103 ms against Decode's 99 ms. Plain RGB JPEG decoding is unchanged at 31 ms.
  • See docs/cmyk.md.

The canvas is no longer experimental. Canvas, Shape and FillRule drop [Experimental("ZORGDRAW")], so using them no longer needs a NoWarn. Removing the attribute doesn't break callers: projects that suppressed the diagnostic keep building. The shipped API lines lose their [ZORGDRAW] prefix.

Tests:

  • Windows: 2,642, none failing.
  • Linux gate: the 18 CMYK tests pass with none skipped, including an ImageMagick oracle where the inks match magick ... cmyk:- within one level.

A four-component JPEG (YCCK included) or a separated TIFF decodes to a CmykImage: C, M, Y and K as L8 planes in LinearSrgb, 0 no ink to 255 full, with the file's CMYK profile. Map runs an operation on every plane, ToInterleaved gives the bytes a PDF DeviceCMYK image holds, ToSrgb converts as Decode does. Shrink-on-load and orientation reuse the decoders' own paths; no operation or encoder changes. Checked against ImageMagick's raw CMYK in the gate. A 4000 x 3000 file: 103 ms, against 99 ms to sRGB.
The canvas, Shape and FillRule no longer carry [Experimental(ZORGDRAW)],
so callers don't need to suppress a diagnostic to use them. The shipped
API lines lose their [ZORGDRAW] prefix; the NoWarns go from the projects
and the docs.
@alftore
alftore merged commit 21f0371 into main Nov 14, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant