[latex3-commits] [git/LaTeX3-latex3-latex3] icc: Auto detect component count from ICC (e3c8f6815)
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/e3c8f681527b5064dc49983754095ae28ca7732f
>---------------------------------------------------------------
commit e3c8f681527b5064dc49983754095ae28ca7732f
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date: Wed Mar 3 18:57:58 2021 +0100
Auto detect component count from ICC
>---------------------------------------------------------------
e3c8f681527b5064dc49983754095ae28ca7732f
l3backend/l3backend-color.dtx | 11 ++--
l3kernel/l3color.dtx | 94 ++++++++++++++++++---------------
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 ++---
7 files changed, 86 insertions(+), 73 deletions(-)
diff --git a/l3backend/l3backend-color.dtx b/l3backend/l3backend-color.dtx
index 0d50bbe99..ba0d79824 100644
--- a/l3backend/l3backend-color.dtx
+++ b/l3backend/l3backend-color.dtx
@@ -758,7 +758,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}
%
@@ -952,18 +952,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 60b0de13c..4cb4c09ea 100644
--- a/l3kernel/l3color.dtx
+++ b/l3kernel/l3color.dtx
@@ -437,11 +437,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}
@@ -1789,11 +1787,10 @@
% A shared auxiliary to do the basics of setting up a new model: reserve a
% number, create a fallback and white-equivalent, 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
@@ -1805,12 +1802,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}
%
@@ -2521,6 +2530,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}
@@ -2542,29 +2569,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}
- }
- {
- \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} }
{
\msg_error:nnn { color }
- { ICCBased-component-number } {#2}
+ { ICCBased-unsupported-colorspace } {#2}
}
}
% \end{macrocode}
@@ -2572,12 +2585,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}
@@ -2660,20 +2673,13 @@
\\ \\
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. }
+\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.
}
\msg_new:nnnn { color } { ICCBased-requires-file }
{ ICCBased~color~space~'#1'~require~an~file. }
diff --git a/l3kernel/testfiles/m3color003.lvt b/l3kernel/testfiles/m3color003.lvt
index 1ff4d3318..f76ef442a 100644
--- a/l3kernel/testfiles/m3color003.lvt
+++ b/l3kernel/testfiles/m3color003.lvt
@@ -286,7 +286,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 a125e6cc5..3f4ebe310 100644
--- a/l3kernel/testfiles/m3color003.ptex.tlg
+++ b/l3kernel/testfiles/m3color003.ptex.tlg
@@ -497,7 +497,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. ... }
============================================================
@@ -511,12 +511,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 d25eee7e0..63d24f4b2 100644
--- a/l3kernel/testfiles/m3color003.tlg
+++ b/l3kernel/testfiles/m3color003.tlg
@@ -495,7 +495,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. ... }
============================================================
@@ -509,12 +509,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 a125e6cc5..3f4ebe310 100644
--- a/l3kernel/testfiles/m3color003.uptex.tlg
+++ b/l3kernel/testfiles/m3color003.uptex.tlg
@@ -497,7 +497,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. ... }
============================================================
@@ -511,12 +511,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 f3d79e5c4..509d07d12 100644
--- a/l3kernel/testfiles/m3color003.xetex.tlg
+++ b/l3kernel/testfiles/m3color003.xetex.tlg
@@ -494,7 +494,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. ... }
============================================================
@@ -508,12 +508,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.