[latex3-commits] [git/LaTeX3-latex3-latex3] icc-auto-comp: Auto detect component count from ICC (74c7fbd55)

Marcel Fabian Krüger tex at 2krueger.de
Wed Mar 3 18:57:58 CET 2021


Repository : https://github.com/latex3/latex3
On branch  : icc-auto-comp
Link       : https://github.com/latex3/latex3/commit/74c7fbd558ed17b660471bde8b7a22ed7a9585f8

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

commit 74c7fbd558ed17b660471bde8b7a22ed7a9585f8
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Wed Mar 3 18:57:58 2021 +0100

    Auto detect component count from ICC


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

74c7fbd558ed17b660471bde8b7a22ed7a9585f8
 l3backend/l3backend-color.dtx            | 11 ++--
 l3kernel/l3color.dtx                     | 94 +++++++++++++++++---------------
 l3kernel/testfiles/m3color003.luatex.tlg | 13 +++--
 l3kernel/testfiles/m3color003.lvt        |  2 +-
 l3kernel/testfiles/m3color003.ptex.tlg   | 13 +++--
 l3kernel/testfiles/m3color003.tlg        | 13 +++--
 l3kernel/testfiles/m3color003.uptex.tlg  | 13 +++--
 l3kernel/testfiles/m3color003.xetex.tlg  | 13 +++--
 8 files changed, 93 insertions(+), 79 deletions(-)

diff --git a/l3backend/l3backend-color.dtx b/l3backend/l3backend-color.dtx
index ee812671e..223ec2187 100644
--- a/l3backend/l3backend-color.dtx
+++ b/l3backend/l3backend-color.dtx
@@ -744,7 +744,7 @@
 % \begin{macro}{\@@_backend_iccbased_init:nnn}
 %   No support at present.
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_backend_iccbased_init:nn #1#2 { }
+\cs_new_protected:Npn \@@_backend_iccbased_init:nnn #1#2#3 { }
 %    \end{macrocode}
 % \end{macro}
 %
@@ -939,18 +939,21 @@
 % \end{macro}
 % \end{macro}
 %
-% \begin{macro}{\@@_backend_iccbased_init:nn}
+% \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:nn #1#2
+\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 }
+            {
+              /N ~ #2 ~
+              \tl_if_empty:nF { #3 } { /Range~[ #3 ] }
+            }
             {#1}
           }
       }
diff --git a/l3kernel/l3color.dtx b/l3kernel/l3color.dtx
index dbb55a136..9f08638bd 100644
--- a/l3kernel/l3color.dtx
+++ b/l3kernel/l3color.dtx
@@ -432,11 +432,9 @@
 %   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.
+% For a \texttt{ICCBased} space, there is one \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}
@@ -1762,11 +1760,10 @@
 %   A shared auxiliary to do the basics of setting up a new model: reserve a
 %   number, create a fallback and white-eqivalent, set up links to the backend.
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_model_init:nnn #1#2#3
+\cs_new_protected:Npn \@@_model_init:nnnnn #1#2#3#4#5
   {
     \int_gincr:N \g_@@_model_int
-    \tl_const:cx { c_@@_fallback_ #1 _tl }
-      { 1 \prg_replicate:nn { #2 - 1 } { ~ 1 } }
+    \tl_const:cn { c_@@_fallback_ #1 _tl } { #4 }
     \clist_map_inline:nn { fill , stroke , select }
       {
         \cs_new_protected:cpx { @@_backend_ ##1 _ #1 :n } ####1
@@ -1778,12 +1775,24 @@
     \cs_new_protected:cpx { @@_model_ #1 _white: }
       {
         \prop_put:Nnn \exp_not:N \l_@@_named_white_prop {#1}
-          { 0 \prg_replicate:nn { #2 - 1 } { ~ 0 } }
+        { \exp_not:n {#5} }
         \exp_not:N \int_compare:nNnF { \tex_currentgrouplevel:D } = 0
           { \group_insert_after:N \exp_not:c { @@_model_ #1 _ white: } }
       }
     \use:c { @@_model_ #1 _white: }
   }
+\cs_generate_variant:Nn \@@_model_init:nnnnn { nnnxx }
+
+\cs_new_protected:Npn \@@_model_init:nnn #1#2#3
+  {
+    \@@_model_init:nnnxx { #1 } { #2 } { #3 }
+      {
+        1 \prg_replicate:nn { #2 - 1 } { ~ 1 }
+      }
+      {
+        0 \prg_replicate:nn { #2 - 1 } { ~ 0 }
+      }
+  }
 %    \end{macrocode}
 % \end{macro}
 %
@@ -2493,6 +2502,24 @@
 % \end{macro}
 % \end{macro}
 %
+% \begin{variable}{\c_@@_icc_colorspace_signatures_prop}
+%   The signatures in the ICC file header indicating the underlying
+%   colorspace.  We map it to three values: The number of components,
+%   the values corresponding to white, and the range.
+%    \begin{macrocode}
+\prop_const_from_keyval:Nn \c_@@_icc_colorspace_signatures_prop
+  {
+% Gray
+    47524159 = {1} {1} {0} {},
+% RGB
+    52474220 = {3} {0~0~0} {1~1~1} {},
+% CMYK
+    434D594B = {4} {0~0~0~1} {0~0~0~0} {},
+% Lab
+    4C616220 = {3} {0~0~0} {100~0~0} {0~100~-128~127~-128~127}
+  }
+%    \end{macrocode}
+% \end{variable}
 % \begin{macro}{\@@_model_iccbased:n}
 % \begin{macro}{\@@_model_iccbased:nn}
 % \begin{macro}{\@@_model_iccbased:nnn, \@@_model_iccbased_aux:nnn}
@@ -2514,29 +2541,15 @@
   }
 \cs_new_protected:Npn \@@_model_iccbased:nn #1#2
   {
-    \prop_get:NnNTF \l_@@_internal_prop { components }
-      \l_@@_internal_tl
+    \exp_args:NNx \prop_get:NnNTF \c_@@_icc_colorspace_signatures_prop
+      { \file_hex_dump:nnn { #1 } { 17 } { 20 } } \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 }
+        \exp_last_unbraced:NV \@@_model_iccbased_aux:nnnnnn
+          \l_@@_internal_tl { #2 } { #1 }
       }
-      { \@@_model_iccbased_aux:nnn {#1} {#2} {#3} }
       {
         \__kernel_msg_error:nnn { color }
-          { ICCBased-component-number } {#2}
+        { ICCBased-unsupported-colorspace } {#2}
       }
   }
 %    \end{macrocode}
@@ -2544,12 +2557,12 @@
 %   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
+\cs_new_protected:Npn \@@_model_iccbased_aux:nnnnnn #1#2#3#4#5#6
   {
-    \@@_model_init:nnn {#2} {#1} { iccbased }
-    \use:c { @@_model_devicen_parse_ #1 :nn } {#2} {#1}
-    \exp_args:Nx \@@_backend_iccbased_init:nn
-      { \file_full_name:n {#3} } {#1}
+    \@@_model_init:nnnnn {#5} {#1} { iccbased } {#2} {#3}
+    \use:c { @@_model_devicen_parse_ #1 :nn } {#5} {#1}
+    \exp_args:Nx \@@_backend_iccbased_init:nnn
+      { \file_full_name:n {#6} } {#1} {#4}
   }
 %    \end{macrocode}
 % \end{macro}
@@ -2628,20 +2641,13 @@
     \\ \\
     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. }
+\__kernel_msg_new:nnnn { color } { ICCBased-unsupported-colorspace }
+  { ICCBased~color~space~'#1'~uses~an~unsupported~data~color~space. }
   {
-    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~ignore~this~
-    request.
+    LaTeX~has~been~asked~to~create~a~ICCBased~colorspace,~but~the~
+    used~data~colorspace~is~not~supported.~ICC~profiles~used~for~
+    defining~a~ICCBased~colorspace~should~use~a~Lab,~RGB,~or~
+    CMYK~data~colorspace.~LaTeX~will~ignore~this~request.
   }
 \__kernel_msg_new:nnnn { color } { ICCBased-requires-file }
   { ICCBased~color~space~'#1'~require~an~file. }
diff --git a/l3kernel/testfiles/m3color003.luatex.tlg b/l3kernel/testfiles/m3color003.luatex.tlg
index 4323d715b..fd60a2206 100644
--- a/l3kernel/testfiles/m3color003.luatex.tlg
+++ b/l3kernel/testfiles/m3color003.luatex.tlg
@@ -483,7 +483,7 @@ The color foo has the properties:
 l. ...  }
 The color foo has the properties:
 >  model  =>  ICC
->  ICC  =>  0.375 0.125 0.0625.
+>  ICC  =>  0.875 0.625 0.5625.
 <recently read> }
 l. ...  }
 ============================================================
@@ -497,12 +497,13 @@ l. ...  }
 LaTeX has been asked to create an ICCBased color space, but no 
     file = <name>
 key was given with the correct information. LaTeX will ignore this request.
-! LaTeX3 Error: ICCBased color space 'ICCmixed' require a number of
-(LaTeX3)        components.
+! LaTeX3 Error: ICCBased color space 'ICCmixed' uses an unsupported data color
+(LaTeX3)        space.
 For immediate help type H <return>.
  ...                                              
 l. ...  }
-LaTeX has been asked to create an ICCBased color space, but no 
-    compontents = <number>
-key was given with the correct information. LaTeX will ignore this request.
+LaTeX has been asked to create a ICCBased colorspace, but the used data
+colorspace is not supported. ICC profiles used for defining a ICCBased
+colorspace should use a Lab, RGB, or CMYK data colorspace. LaTeX will ignore
+this request.
 ============================================================
diff --git a/l3kernel/testfiles/m3color003.lvt b/l3kernel/testfiles/m3color003.lvt
index a6fe71f14..83de33832 100644
--- a/l3kernel/testfiles/m3color003.lvt
+++ b/l3kernel/testfiles/m3color003.lvt
@@ -279,7 +279,7 @@
   {
     \color_model_new:nnn { ICC } { ICCBased }
       {
-        file = sRGB_v4_ICC_preference.icc , components = 3
+        file = sRGB_v4_ICC_preference.icc
       }
     \color_set:nnn { ICC3 } { ICC } { 0.75 , 0.25 , 0.125 }
     \color_set:nn { foo } { ICC3 }
diff --git a/l3kernel/testfiles/m3color003.ptex.tlg b/l3kernel/testfiles/m3color003.ptex.tlg
index 90810651c..24a0e8c4b 100644
--- a/l3kernel/testfiles/m3color003.ptex.tlg
+++ b/l3kernel/testfiles/m3color003.ptex.tlg
@@ -485,7 +485,7 @@ The color foo has the properties:
 l. ...  }
 The color foo has the properties:
 >  model  =>  ICC
->  ICC  =>  0.375 0.125 0.0625.
+>  ICC  =>  0.875 0.625 0.5625.
 <recently read> }
 l. ...  }
 ============================================================
@@ -499,12 +499,13 @@ l. ...  }
 LaTeX has been asked to create an ICCBased color space, but no 
     file = <name>
 key was given with the correct information. LaTeX will ignore this request.
-! LaTeX3 Error: ICCBased color space 'ICCmixed' require a number of
-(LaTeX3)        components.
+! LaTeX3 Error: ICCBased color space 'ICCmixed' uses an unsupported data color
+(LaTeX3)        space.
 For immediate help type H <return>.
  ...                                              
 l. ...  }
-LaTeX has been asked to create an ICCBased color space, but no 
-    compontents = <number>
-key was given with the correct information. LaTeX will ignore this request.
+LaTeX has been asked to create a ICCBased colorspace, but the used data
+colorspace is not supported. ICC profiles used for defining a ICCBased
+colorspace should use a Lab, RGB, or CMYK data colorspace. LaTeX will ignore
+this request.
 ============================================================
diff --git a/l3kernel/testfiles/m3color003.tlg b/l3kernel/testfiles/m3color003.tlg
index c64996c1a..d116809aa 100644
--- a/l3kernel/testfiles/m3color003.tlg
+++ b/l3kernel/testfiles/m3color003.tlg
@@ -483,7 +483,7 @@ The color foo has the properties:
 l. ...  }
 The color foo has the properties:
 >  model  =>  ICC
->  ICC  =>  0.375 0.125 0.0625.
+>  ICC  =>  0.875 0.625 0.5625.
 <recently read> }
 l. ...  }
 ============================================================
@@ -497,12 +497,13 @@ l. ...  }
 LaTeX has been asked to create an ICCBased color space, but no 
     file = <name>
 key was given with the correct information. LaTeX will ignore this request.
-! LaTeX3 Error: ICCBased color space 'ICCmixed' require a number of
-(LaTeX3)        components.
+! LaTeX3 Error: ICCBased color space 'ICCmixed' uses an unsupported data color
+(LaTeX3)        space.
 For immediate help type H <return>.
  ...                                              
 l. ...  }
-LaTeX has been asked to create an ICCBased color space, but no 
-    compontents = <number>
-key was given with the correct information. LaTeX will ignore this request.
+LaTeX has been asked to create a ICCBased colorspace, but the used data
+colorspace is not supported. ICC profiles used for defining a ICCBased
+colorspace should use a Lab, RGB, or CMYK data colorspace. LaTeX will ignore
+this request.
 ============================================================
diff --git a/l3kernel/testfiles/m3color003.uptex.tlg b/l3kernel/testfiles/m3color003.uptex.tlg
index 90810651c..24a0e8c4b 100644
--- a/l3kernel/testfiles/m3color003.uptex.tlg
+++ b/l3kernel/testfiles/m3color003.uptex.tlg
@@ -485,7 +485,7 @@ The color foo has the properties:
 l. ...  }
 The color foo has the properties:
 >  model  =>  ICC
->  ICC  =>  0.375 0.125 0.0625.
+>  ICC  =>  0.875 0.625 0.5625.
 <recently read> }
 l. ...  }
 ============================================================
@@ -499,12 +499,13 @@ l. ...  }
 LaTeX has been asked to create an ICCBased color space, but no 
     file = <name>
 key was given with the correct information. LaTeX will ignore this request.
-! LaTeX3 Error: ICCBased color space 'ICCmixed' require a number of
-(LaTeX3)        components.
+! LaTeX3 Error: ICCBased color space 'ICCmixed' uses an unsupported data color
+(LaTeX3)        space.
 For immediate help type H <return>.
  ...                                              
 l. ...  }
-LaTeX has been asked to create an ICCBased color space, but no 
-    compontents = <number>
-key was given with the correct information. LaTeX will ignore this request.
+LaTeX has been asked to create a ICCBased colorspace, but the used data
+colorspace is not supported. ICC profiles used for defining a ICCBased
+colorspace should use a Lab, RGB, or CMYK data colorspace. LaTeX will ignore
+this request.
 ============================================================
diff --git a/l3kernel/testfiles/m3color003.xetex.tlg b/l3kernel/testfiles/m3color003.xetex.tlg
index 52b0da8a7..1f4b235e2 100644
--- a/l3kernel/testfiles/m3color003.xetex.tlg
+++ b/l3kernel/testfiles/m3color003.xetex.tlg
@@ -482,7 +482,7 @@ The color foo has the properties:
 l. ...  }
 The color foo has the properties:
 >  model  =>  ICC
->  ICC  =>  0.375 0.125 0.0625.
+>  ICC  =>  0.875 0.625 0.5625.
 <recently read> }
 l. ...  }
 ============================================================
@@ -496,12 +496,13 @@ l. ...  }
 LaTeX has been asked to create an ICCBased color space, but no 
     file = <name>
 key was given with the correct information. LaTeX will ignore this request.
-! LaTeX3 Error: ICCBased color space 'ICCmixed' require a number of
-(LaTeX3)        components.
+! LaTeX3 Error: ICCBased color space 'ICCmixed' uses an unsupported data color
+(LaTeX3)        space.
 For immediate help type H <return>.
  ...                                              
 l. ...  }
-LaTeX has been asked to create an ICCBased color space, but no 
-    compontents = <number>
-key was given with the correct information. LaTeX will ignore this request.
+LaTeX has been asked to create a ICCBased colorspace, but the used data
+colorspace is not supported. ICC profiles used for defining a ICCBased
+colorspace should use a Lab, RGB, or CMYK data colorspace. LaTeX will ignore
+this request.
 ============================================================





More information about the latex3-commits mailing list.