[latex3-commits] [git/LaTeX3-latex3-latex3] icc: Add support for ICC-based color profiles (9a3c0c715)
Marcel Fabian Krüger
tex at 2krueger.de
Thu Oct 14 14:35:46 CEST 2021
Repository : https://github.com/latex3/latex3
On branch : icc
Link : https://github.com/latex3/latex3/commit/9a3c0c715cd08969a6baa4ab011a2ec308f889da
>---------------------------------------------------------------
commit 9a3c0c715cd08969a6baa4ab011a2ec308f889da
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Sun Feb 21 17:18:57 2021 +0000
Add support for ICC-based color profiles
>---------------------------------------------------------------
9a3c0c715cd08969a6baa4ab011a2ec308f889da
l3backend/l3backend-color.dtx | 52 +++++++++++++++++++++--
l3kernel/CHANGELOG.md | 3 ++
l3kernel/l3color.dtx | 95 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 147 insertions(+), 3 deletions(-)
diff --git a/l3backend/l3backend-color.dtx b/l3backend/l3backend-color.dtx
index 72254382f..dc132abf2 100644
--- a/l3backend/l3backend-color.dtx
+++ b/l3backend/l3backend-color.dtx
@@ -497,6 +497,13 @@
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}{\@@_backend_select_iccbased:nn}
+% No support.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_select_iccbased:nn #1#2 { }
+% \end{macrocode}
+% \end{macro}
+%
% \begin{macro}
% {
% \@@_backend_separation_init:nnnnn,
@@ -756,11 +763,17 @@
%<*dvisvgm>
% \end{macrocode}
%
-% \begin{macro}{\@@_backend_select_separation:nn, \@@_backend_select_devicen:nn}
+% \begin{macro}
+% {
+% \@@_backend_select_separation:nn,
+% \@@_backend_select_devicen:nn ,
+% \@@_backend_select_iccbased:nn
+% }
% No support at present.
% \begin{macrocode}
\cs_new_protected:Npn \@@_backend_select_separation:nn #1#2 { }
-\cs_new_protected:Npn \@@_backend_select_devicen:nn #1#2 { }
+\cs_new_eq:NN \@@_backend_select_devicen:nn \@@_backend_select_separation:nn
+\cs_new_eq:NN \@@_backend_select_iccbased:nn \@@_backend_select_separation:nn
% \end{macrocode}
% \end{macro}
%
@@ -781,7 +794,12 @@
%<*dvipdfmx|luatex|pdftex|xetex>
% \end{macrocode}
%
-% \begin{macro}{\@@_backend_select_separation:nn, \@@_backend_select_devicen:nn}
+% \begin{macro}
+% {
+% \@@_backend_select_separation:nn,
+% \@@_backend_select_devicen:nn ,
+% \@@_backend_select_iccbased:nn
+% }
% Although \texttt{(x)dvipdfmx} has a built-in approach to color spaces, that
% can't be used with the generic color stacks. So we take an approach in which
% we share the same code as for \pdfTeX{}.
@@ -789,6 +807,7 @@
\cs_new_protected:Npn \@@_backend_select_separation:nn #1#2
{ \@@_backend_select:nn { /#1 ~ cs ~ #2 ~ scn } { /#1 ~ CS ~ #2 ~ SCN } }
\cs_new_eq:NN \@@_backend_select_devicen:nn \@@_backend_select_separation:nn
+\cs_new_eq:NN \@@_backend_select_iccbased:nn \@@_backend_select_separation:nn
% \end{macrocode}
% \end{macro}
%
@@ -925,6 +944,33 @@
% \end{macro}
% \end{macro}
% \end{macro}
+%
+% \begin{macro}{\@@_backend_iccbased_init:nnn}
+% Lots of data to save here: we only want to do that once per file,
+% so track it by name.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_iccbased_init:nnn #1#2#3
+ {
+ \pdf_object_if_exist:nF { @@_icc_ #1 }
+ {
+ \pdf_object_new:nn { @@_icc_ #1 } { fstream }
+ \pdf_object_write:nn { @@_icc_ #1 }
+ {
+ { /N ~ #2 }
+ {#1}
+ }
+ }
+ \pdf_object_unnamed_write:nx { array }
+ { /ICCBased~ \pdf_object_ref:n { @@_icc_ #1 } }
+ \cs_if_exist:NT \pdfmanagement_add:nnn
+ {
+ \pdfmanagement_add:nnx { Page / Resources / ColorSpace }
+ {#3} { ~ \pdf_object_ref_last: }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+
%
% \begin{macrocode}
%</dvipdfmx|luatex|pdftex|xetex>
diff --git a/l3kernel/CHANGELOG.md b/l3kernel/CHANGELOG.md
index 55e9db4bb..f06fdc78f 100644
--- a/l3kernel/CHANGELOG.md
+++ b/l3kernel/CHANGELOG.md
@@ -7,6 +7,9 @@ this project uses date-based 'snapshot' version identifiers.
## [Unreleased]
+### Added
+- Support for ICC-based color profiles
+
## [2021-10-12]
### Fixed
diff --git a/l3kernel/l3color.dtx b/l3kernel/l3color.dtx
index 36fa14876..9efe41536 100644
--- a/l3kernel/l3color.dtx
+++ b/l3kernel/l3color.dtx
@@ -393,6 +393,7 @@
% The latter should be one of
% \begin{itemize}
% \item \texttt{DeviceN}
+% \item \texttt{ICCBased}
% \item \texttt{Separation}
% \end{itemize}
% (The \meta{family} may be given in mixed case as-in the PDF reference:
@@ -436,6 +437,13 @@
% a process color name (\texttt{cyan}, etc.) or the special name \texttt{none}.
% \end{itemize}
%
+% For a \texttt{ICCBased} space, there are two \emph{compulsory} key.
+% \begin{itemize}
+% \item \texttt{file} The name of the file containing the profile.
+% \item \texttt{components} The number of components the profile requires:
+% must be one of $1$, $3$ or $4$.
+% \end{itemize}
+%
% \end{documentation}
%
% \begin{implementation}
@@ -2513,6 +2521,69 @@
% \end{macro}
% \end{macro}
%
+% \begin{macro}{\@@_model_iccbased:n}
+% \begin{macro}{\@@_model_iccbased:nn}
+% \begin{macro}{\@@_model_iccbased:nnn, \@@_model_iccbased_aux:nnn}
+% For an ICC profile, we need a file name and a number of components. The
+% file name is processed here so the backend can treat it as a string.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_model_iccbased:n #1
+ {
+ \prop_get:NnNTF \l_@@_internal_prop { file }
+ \l_@@_internal_tl
+ {
+ \exp_args:NV \@@_model_iccbased:nn
+ \l_@@_internal_tl {#1}
+ }
+ {
+ \msg_error:nnn { color }
+ { ICCBased-requires-file } {#1}
+ }
+ }
+\cs_new_protected:Npn \@@_model_iccbased:nn #1#2
+ {
+ \prop_get:NnNTF \l_@@_internal_prop { components }
+ \l_@@_internal_tl
+ {
+ \exp_args:NV \@@_model_iccbased:nnn
+ \l_@@_internal_tl {#2} {#1}
+ }
+ {
+ \msg_error:nnn { color }
+ { ICCBased-requires-components } {#2}
+ }
+ }
+\cs_new_protected:Npn \@@_model_iccbased:nnn #1#2#3
+ {
+ \bool_lazy_any:nTF
+ {
+ { \int_compare_p:nNn {#1} = 1 }
+ { \int_compare_p:nNn {#1} = 3 }
+ { \int_compare_p:nNn {#1} = 4 }
+ }
+ { \@@_model_iccbased_aux:nnn {#1} {#2} {#3} }
+ {
+ \msg_error:nnn { color }
+ { ICCBased-component-number } {#2}
+ }
+ }
+% \end{macrocode}
+% Here, we can use the same internals as for DeviceN approach as we know the
+% number of components. No conversion is possible, so there is no need
+% to worry about that at all.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_model_iccbased_aux:nnn #1#2#3
+ {
+ \@@_model_init:nnn {#2} {#1} { iccbased }
+ \use:c { @@_model_devicen_parse_ #1 :nn } {#2} {#1}
+ \exp_args:Nx \@@_backend_devicen_init:nnn
+ { \file_full_name:n {#3} } {#1} {#2}
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
% \subsection{Diagnostics}
%
% \begin{macro}{\color_show:n, \color_log:n, \@@_show:Nn}
@@ -2589,6 +2660,30 @@
\\ \\
key~was~given~with~the~correct~information.
}
+\msg_new:nnnn { color } { ICCBased-component-number }
+ { Too~many~components~for~ICCBased~color~space~'#1'. }
+ {
+ LaTeX~has~been~asked~to~create~an~ICCBased~color~space~with~#1~components,~
+ but~only~1,~3~or~4~components~are~allowed.
+ }
+\msg_new:nnnn { color } { ICCBased-requires-components }
+ { ICCBased~color~space~'#1'~require~a~number~of~components. }
+ {
+ LaTeX~has~been~asked~to~create~an~ICCBased~color~space,~but~no~\\ \\
+ \iow_indent:n { compontents~=~<number> }
+ \\ \\
+ key~was~given~with~the~correct~information.~LaTeX~will~use~ignore~this~
+ request.
+ }
+\msg_new:nnnn { color } { ICCBased-requires-file }
+ { ICCBased~color~space~'#1'~require~an~file. }
+ {
+ LaTeX~has~been~asked~to~create~an~ICCBased~color~space,~but~no~\\ \\
+ \iow_indent:n { file~=~<name> }
+ \\ \\
+ key~was~given~with~the~correct~information.~LaTeX~will~use~ignore~this~
+ request.
+ }
\msg_new:nnnn { color } { model-already-defined }
{ Color~model~'#1'~already~defined. }
{
More information about the latex3-commits
mailing list.