[latex3-commits] [git/LaTeX3-latex3-latex3] icc: Add support for ICC-based color profiles (1c4c17013)

Joseph Wright joseph.wright at morningstar2.co.uk
Sun Feb 21 18:18:57 CET 2021


Repository : https://github.com/latex3/latex3
On branch  : icc
Link       : https://github.com/latex3/latex3/commit/1c4c1701324825b13dd7fb519066958c08c61532

>---------------------------------------------------------------

commit 1c4c1701324825b13dd7fb519066958c08c61532
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


>---------------------------------------------------------------

1c4c1701324825b13dd7fb519066958c08c61532
 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 22917e90c..1852b5f5b 100644
--- a/l3backend/l3backend-color.dtx
+++ b/l3backend/l3backend-color.dtx
@@ -484,6 +484,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,
@@ -742,11 +749,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}
 %
@@ -767,7 +780,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{}.
@@ -775,6 +793,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}
 %
@@ -912,6 +931,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 9663dc055..dc34b68d8 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-02-18]
 
 ### Added
diff --git a/l3kernel/l3color.dtx b/l3kernel/l3color.dtx
index 812243761..8bfff099e 100644
--- a/l3kernel/l3color.dtx
+++ b/l3kernel/l3color.dtx
@@ -388,6 +388,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:
@@ -431,6 +432,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}
@@ -2485,6 +2493,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}
+      }
+      {
+        \__kernel_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}
+      }
+      {
+        \__kernel_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} }
+      {
+        \__kernel_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}
@@ -2557,6 +2628,30 @@
     \\ \\
     key~was~given~with~the~correct~information.
   }
+\__kernel_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.
+  }
+\__kernel_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.
+  }
+\__kernel_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.
+  }
 \__kernel_msg_new:nnnn { color } { model-already-defined }
   { Color~model~'#1'~already~defined. }
   {





More information about the latex3-commits mailing list.