Skip to content

Profile-based Color Management for Preview and PDF export #3143

Open

Description

@tilman-schieber

Description

1. Features

The typst compiler should

  1. allow to specify an output ICC color profile (e.g. command line option --icc-profile ).
  2. convert the colors to the specified output profile when writing the pdf. If none is specified default to the sRGB profile currently used.
  3. use a "proofing" transform (see details) to RGB so we get a better preview of CMYK colors.
  4. include a few commonly used ICC profiles to improve usability. The most commonly used color profile for offset print ist ISOcoatedv2.

2. Details

One of the most popular color management C libraries is Little-CMS, which is used by Scribus, Imagemagick, GIMP, Inkscape and many more. It is open source (MIT License).
For improving the preview of documents with CMYK-colors, it offers a function cmsCreateProofingTransform that allows a transformation to RGB that tries to get the colors to look on the screen as it would when printed with the destination profile. (see the docs,p.25)

Use Case

CMYK colors are supported in typst. However most printers require an embedded CMYK color profile in the pdf file.

Additionally, improving the preview of cmyk colors in the Web App so it is consistent with common pdf viewers (that use proper color management) would be helpful.
To illustrate this issue: create a CMYK color that mixes Cyan and Magenta, e.g.
cmyk(80%,80%,0,0). Observe how it is blue in the webapp but violet in the downloaded pdf.

Activity

  1. LaurenzV commented on Jan 6, 2024

    @LaurenzV
    Collaborator

    allow to specify an output ICC color profile (e.g. command line option --icc-profile )

    I think maybe it would even be better to allow specifying icc profiles within a Typst document via some setting, this way it would be reproducible across different platforms.

    One of the most popular color management C libraries is Little-CMS, which is used by Scribus, Imagemagick, GIMP, Inkscape and many more. It is open source (MIT License).

    Afaik we can only use Rust dependencies, because there are linking issues between C and Rust when compiling to WASM.

  2. tilman-schieber commented on Jan 6, 2024

    @tilman-schieber
    Author

    I think maybe it would even be better to allow specifying icc profiles within a Typst document via some setting, this way it would be reproducible across different platforms.

    Yes that would be better.

    Afaik we can only use Rust dependencies, because there are linking issues between C and Rust when compiling to WASM.

    I just found out that Firefox used to use Little-CMS but they redid it in Rust (!) https://github.com/FirefoxGraphics/qcms/

  3. reknih commented on Jan 7, 2024

    @reknih
    Member

    The qcms repo unfortunately does not have a license and has its issue tracker closed. I dmmed a maintainer on Discord about this but received no answer. Does anyone know a collaborator there? Otherwise, we could fork the project (however not without a license)

  4. tilman-schieber commented on Jan 7, 2024

    @tilman-schieber
    Author

    yes the repo is not the best maintained.
    However there is a license in the comments of the source files, here for example

    //  qcms
    //  Copyright (C) 2009 Mozilla Foundation
    //  Copyright (C) 1998-2007 Marti Maria
    //
    // 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, 
    ...
    

    The Marti Maria mentioned here is the original author of LIttleCMS. So while this repo does not make it perfectly clear i assume that the c to rust translation they did is from the original source code of lcms.

    If this goes nowhere however, the next best starting point would be the charmingly old fashioned website of the ICC
    Under resources, there are reference implementations for working with ICC profiles.

  5. Enivex commented on Jan 7, 2024

    @Enivex
    Collaborator

    I think maybe it would even be better to allow specifying icc profiles within a Typst document via some setting, this way it would be reproducible across different platforms.

    Yes that would be better.

    Afaik we can only use Rust dependencies, because there are linking issues between C and Rust when compiling to WASM.

    I just found out that Firefox used to use Little-CMS but they redid it in Rust (!) https://github.com/FirefoxGraphics/qcms/

    It still says 2.8% c++ and 2.6% c

  6. tilman-schieber commented on Jan 7, 2024

    @tilman-schieber
    Author

    I think maybe it would even be better to allow specifying icc profiles within a Typst document via some setting, this way it would be reproducible across different platforms.

    Yes that would be better.

    Afaik we can only use Rust dependencies, because there are linking issues between C and Rust when compiling to WASM.

    I just found out that Firefox used to use Little-CMS but they redid it in Rust (!) https://github.com/FirefoxGraphics/qcms/

    It still says 2.8% c++ and 2.6% c

    yes but these are just the three header files in the root directory. As far as I understand this is only there so the library can be called from C code. If you look in the rust code all functionality for converting ICC profiles is in rust.
    Some rust functions are declared extern "C" so they are probably meant to be used by some parts of Mozillas gfx library that is still in C.

  7. added
    pdf
    png
    visualize
    on Jan 8, 2024
  8. reknih commented on Jan 9, 2024

    @reknih
    Member

    I have successfully reached out to the Firefox Graphics team on Matrix (#gfx:mozilla.org). qcms will bump on Cargo and add a license and CONTRIBUTING.md file (https://phabricator.services.mozilla.com/D197955). Prior to our adoption, CMYK support would need to be added (see https://bugzilla.mozilla.org/show_bug.cgi?id=1474560). Is anyone interested in taking this up? If not, we can do it, but it will take some time.

  9. added
    help wanted
    on Jan 9, 2024
  10. tilman-schieber commented on Jan 9, 2024

    @tilman-schieber
    Author

    So whats missing is a function that reads the CMYK=>PCS (CIEXYZ) translation table from the icc file. right?
    What ICC spec should this be based on? It looks like PDF/X still recommends ICCv2 and not the newest major version 4.

  11. reknih commented on Jan 9, 2024

    @reknih
    Member

    For our intents and purposes ICCv2 would be fine, but best to discuss this on the #gfx:mozilla.org as well! Maybe they aim for compatibility with both formats.

  12. tilman-schieber commented on Jan 9, 2024

    @tilman-schieber
    Author

    Lo and behold:
    qcms added CMYK support in the commit FirefoxGraphics/qcms@7f4e64c

    see also the comments of qcms's author: FirefoxGraphics/qcms#35
    the cmyk update will be published as a crate soon.

  13. jrmuizel commented on Jan 9, 2024

    @jrmuizel

    It's worth noting that the qcms's CMYK support currently only supports going from CMYK to RGB. If you need to go in the other direction support will need to be added.

  14. jrmuizel commented on Jan 9, 2024

    @jrmuizel

    v0.3.0 has now been published. Let me know if there's anything else that you need.

  15. tilman-schieber commented on Jan 9, 2024

    @tilman-schieber
    Author

    Jeff, thank you so much for chiming in here, a better rendition of CMYK colors on screen already solves half our problems and I"ll look into the to-CMYK transform but the ICC spec is not that easy to understand. I'll look into it as soon as I find the time.

  16. terefang commented on Sep 6, 2025

    @terefang

    hello, for the late call.

    will this also allow spot color support in some way ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requesthelp wantedpdfpngvisualize

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions