[latex3-commits] [git/LaTeX3-latex3-latex3] master: Add color conversion for DeviceN spaces (9ead403bd)
Joseph Wright
joseph.wright at morningstar2.co.uk
Thu Sep 24 10:02:32 CEST 2020
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/9ead403bde335204e1ee529a0d5da3ada3ea866f
>---------------------------------------------------------------
commit 9ead403bde335204e1ee529a0d5da3ada3ea866f
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Thu Sep 24 07:58:03 2020 +0100
Add color conversion for DeviceN spaces
>---------------------------------------------------------------
9ead403bde335204e1ee529a0d5da3ada3ea866f
l3experimental/l3color/l3color.dtx | 150 +++++++++++++++++++++
.../l3color/testfiles/m3color003.ptex.tlg | 6 +
l3experimental/l3color/testfiles/m3color003.tlg | 6 +
.../l3color/testfiles/m3color003.uptex.tlg | 6 +
.../l3color/testfiles/m3color003.xetex.tlg | 6 +
5 files changed, 174 insertions(+)
diff --git a/l3experimental/l3color/l3color.dtx b/l3experimental/l3color/l3color.dtx
index c8de1d88a..dddef1148 100644
--- a/l3experimental/l3color/l3color.dtx
+++ b/l3experimental/l3color/l3color.dtx
@@ -1888,6 +1888,23 @@
% }
% \begin{macro}{\@@_model_devicen_tranform:nnn}
% \begin{macro}[EXP]{\@@_model_devicen_colorant:n}
+% \begin{macro}{\@@_model_devicen_convert:nnnn}
+% \begin{macro}[EXP]{\@@_model_devicen_convert:n}
+% \begin{macro}
+% {
+% \@@_model_devicen_convert_cmyk:n ,
+% \@@_model_devicen_convert_gray:n ,
+% \@@_model_devicen_convert_rgb:n
+% }
+% \begin{macro}[EXP]{\@@_convert_devicen_cmyk:nnnnw}
+% \begin{macro}[EXP]{\@@_convert_devicen_cmyk:nnnnnnnnn}
+% \begin{macro}[EXP]{\@@_convert_devicen_cmyk_aux:nnnnw}
+% \begin{macro}[EXP]{\@@_convert_devicen_gray:nw}
+% \begin{macro}[EXP]{\@@_convert_devicen_gray:nnn}
+% \begin{macro}[EXP]{\@@_convert_devicen_gray_aux:nw}
+% \begin{macro}[EXP]{\@@_convert_devicen_rgb:nnnw}
+% \begin{macro}[EXP]{\@@_convert_devicen_rgb:nnnnnnn}
+% \begin{macro}[EXP]{\@@_convert_devicen_rgb_aux:nnnw}
% We require a list of component names here: one might call them colorants,
% but it's convenient to use \TeX{} names instead so we slightly adjust the
% terminology.
@@ -1986,6 +2003,7 @@
}
\use:c { @@_model_ #4 _white: }
\@@_model_devicen_init:nnn {#1} {#2} {#3}
+ \@@_model_devicen_convert:nnnn {#4} {#2} {#1} {#3}
}
% \end{macrocode}
% For short lists of DeviceN colors, wee can use hand-tuned parsing. This
@@ -2194,6 +2212,138 @@
/ \prop_item:Nn \g_@@_colorants_prop {#1} ~
}
% \end{macrocode}
+% Here we need to set up conversion from the DeviceN space to the alternative
+% at the \TeX{} level. This also means supplying methods for inter-converting
+% to other parameter-based spaces. Essentially the approach is exactly the same
+% as the PostScript, just expressed in \TeX{} terms.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_model_devicen_convert:nnnn #1#2#3#4
+ {
+ \cs_new:cpx { @@_convert_ #1 _ #2 :w } ##1 \s_@@_stop
+ {
+ \exp_not:c { @@_convert_devicen_ #2 : \prg_replicate:nn {#3} { n } w }
+ \prg_replicate:nn {#3} { { 1 } }
+ ##1 \exp_not:N \s_@@_mark
+ \clist_map_function:nN {#4} \@@_model_devicen_convert:n
+ \exp_not:N \s_@@_stop
+ }
+ \use:c { @@_model_devicen_convert_ #2 :n } {#1}
+ }
+\cs_new:Npn \@@_model_devicen_convert:n #1
+ {
+ { \prop_item:Nn \g_@@_alternative_values_prop {#1} }
+ }
+\cs_new_protected:Npn \@@_model_devicen_convert_cmyk:n #1
+ {
+ \@@_model_convert:nnn {#1} { cmyk } { gray }
+ \@@_model_convert:nnn {#1} { cmyk } { rgb }
+ }
+\cs_new_protected:Npn \@@_model_devicen_convert_gray:n #1
+ {
+ \@@_model_convert:nnn {#1} { gray } { cmyk }
+ \@@_model_convert:nnn {#1} { gray } { rgb }
+ }
+\cs_new_protected:Npn \@@_model_devicen_convert_rgb:n #1
+ {
+ \@@_model_convert:nnn {#1} { rgb } { cmyk }
+ \@@_model_convert:nnn {#1} { rgb } { gray }
+ }
+\cs_new:Npn \@@_convert_devicen_cmyk:nnnnw
+ #1#2#3#4#5 ~ #6 \s_@@_mark #7#8 \s_@@_stop
+ {
+ \@@_convert_devicen_cmyk:nnnnnnnnn {#5} {#1} {#2} {#3} {#4} #7
+ #6 \s_@@_mark #8 \s_@@_stop
+ }
+\cs_new:Npn \@@_convert_devicen_cmyk:nnnnnnnnn #1#2#3#4#5#6#7#8#9
+ {
+ \use:e
+ {
+ \exp_not:N \@@_convert_devicen_cmyk_aux:nnnnw
+ { \fp_eval:n { #2 * (1 - (#1 * #6)) } }
+ { \fp_eval:n { #3 * (1 - (#1 * #7)) } }
+ { \fp_eval:n { #4 * (1 - (#1 * #8)) } }
+ { \fp_eval:n { #5 * (1 - (#1 * #9)) } }
+ }
+ }
+\cs_new:Npn \@@_convert_devicen_cmyk_aux:nnnnw
+ #1#2#3#4 #5 \s_@@_mark #6 \s_@@_stop
+ {
+ \tl_if_blank:nTF {#5}
+ {
+ \fp_eval:n { 1 - #1 } ~
+ \fp_eval:n { 1 - #2 } ~
+ \fp_eval:n { 1 - #3 } ~
+ \fp_eval:n { 1 - #4 }
+ }
+ {
+ \@@_convert_devicen_cmyk:nnnnw {#1} {#2} {#3} {#4}
+ #5 \s_@@_mark #6 \s_@@_stop
+ }
+ }
+\cs_new:Npn \@@_convert_devicen_gray:nw
+ #1#2 ~ #3 \s_@@_mark #4#5 \s_@@_stop
+ {
+ \@@_convert_devicen_gray:nnn {#2} {#1} #4
+ #3 \s_@@_mark #5 \s_@@_stop
+ }
+\cs_new:Npn \@@_convert_devicen_gray:nnn #1#2#3
+ {
+ \exp_arsgs:Ne \@@_convert_devicen_gray_aux:nw
+ { \fp_eval:n { #2 * (1 - (#1 * #3)) } }
+ }
+\cs_new:Npn \@@_convert_devicen_gray_aux:nw
+ #1 #2 \s_@@_mark #3 \s_@@_stop
+ {
+ \tl_if_blank:nTF {#2}
+ { \fp_eval:n { 1 - #1 } }
+ {
+ \@@_convert_devicen_gray:nw {#1}
+ #2 \s_@@_mark #3 \s_@@_stop
+ }
+ }
+\cs_new:Npn \@@_convert_devicen_rgb:nnnw
+ #1#2#3#4 ~ #5 \s_@@_mark #6#7 \s_@@_stop
+ {
+ \@@_convert_devicen_cmyk:nnnnnn {#4} {#1} {#2} {#3} #6
+ #5 \s_@@_mark #7 \s_@@_stop
+ }
+\cs_new:Npn \@@_convert_devicen_rgb:nnnnnnn #1#2#3#4#5#6#7
+ {
+ \use:e
+ {
+ \exp_not:N \@@_convert_devicen_rgb_aux:nnnw
+ { \fp_eval:n { #2 * (1 - (#1 * #5)) } }
+ { \fp_eval:n { #3 * (1 - (#1 * #6)) } }
+ { \fp_eval:n { #4 * (1 - (#1 * #7)) } }
+ }
+ }
+\cs_new:Npn \@@_convert_devicen_rgb_aux:nnnw
+ #1#2#3 #4 \s_@@_mark #5 \s_@@_stop
+ {
+ \tl_if_blank:nTF {#4}
+ {
+ \fp_eval:n { 1 - #1 } ~
+ \fp_eval:n { 1 - #2 } ~
+ \fp_eval:n { 1 - #3 }
+ }
+ {
+ \@@_convert_devicen_rgb:nnnw {#1} {#2} {#3}
+ #4 \s_@@_mark #5 \s_@@_stop
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
diff --git a/l3experimental/l3color/testfiles/m3color003.ptex.tlg b/l3experimental/l3color/testfiles/m3color003.ptex.tlg
index c247665ec..95104c57a 100644
--- a/l3experimental/l3color/testfiles/m3color003.ptex.tlg
+++ b/l3experimental/l3color/testfiles/m3color003.ptex.tlg
@@ -423,6 +423,9 @@ Defining \__color_backend_fill_TwoUp:n on line ...
Defining \__color_backend_stroke_TwoUp:n on line ...
Defining \__color_backend_select_TwoUp:n on line ...
Defining \__color_model_TwoUp_white: on line ...
+Defining \__color_convert_TwoUp_cmyk:w on line ...
+Defining \__color_convert_TwoUp_gray:w on line ...
+Defining \__color_convert_TwoUp_rgb:w on line ...
Defining \l__color_named_twoup_tl on line ...
Defining \l__color_named_twoup_prop on line ...
The color foo has the properties:
@@ -442,6 +445,9 @@ Defining \__color_backend_fill_AllIn:n on line ...
Defining \__color_backend_stroke_AllIn:n on line ...
Defining \__color_backend_select_AllIn:n on line ...
Defining \__color_model_AllIn_white: on line ...
+Defining \__color_convert_AllIn_cmyk:w on line ...
+Defining \__color_convert_AllIn_gray:w on line ...
+Defining \__color_convert_AllIn_rgb:w on line ...
Defining \l__color_named_allin_tl on line ...
Defining \l__color_named_allin_prop on line ...
The color foo has the properties:
diff --git a/l3experimental/l3color/testfiles/m3color003.tlg b/l3experimental/l3color/testfiles/m3color003.tlg
index 9fe613738..1657e087f 100644
--- a/l3experimental/l3color/testfiles/m3color003.tlg
+++ b/l3experimental/l3color/testfiles/m3color003.tlg
@@ -413,6 +413,9 @@ Defining \__color_backend_fill_TwoUp:n on line ...
Defining \__color_backend_stroke_TwoUp:n on line ...
Defining \__color_backend_select_TwoUp:n on line ...
Defining \__color_model_TwoUp_white: on line ...
+Defining \__color_convert_TwoUp_cmyk:w on line ...
+Defining \__color_convert_TwoUp_gray:w on line ...
+Defining \__color_convert_TwoUp_rgb:w on line ...
Defining \l__color_named_twoup_tl on line ...
Defining \l__color_named_twoup_prop on line ...
The color foo has the properties:
@@ -432,6 +435,9 @@ Defining \__color_backend_fill_AllIn:n on line ...
Defining \__color_backend_stroke_AllIn:n on line ...
Defining \__color_backend_select_AllIn:n on line ...
Defining \__color_model_AllIn_white: on line ...
+Defining \__color_convert_AllIn_cmyk:w on line ...
+Defining \__color_convert_AllIn_gray:w on line ...
+Defining \__color_convert_AllIn_rgb:w on line ...
Defining \l__color_named_allin_tl on line ...
Defining \l__color_named_allin_prop on line ...
The color foo has the properties:
diff --git a/l3experimental/l3color/testfiles/m3color003.uptex.tlg b/l3experimental/l3color/testfiles/m3color003.uptex.tlg
index c247665ec..95104c57a 100644
--- a/l3experimental/l3color/testfiles/m3color003.uptex.tlg
+++ b/l3experimental/l3color/testfiles/m3color003.uptex.tlg
@@ -423,6 +423,9 @@ Defining \__color_backend_fill_TwoUp:n on line ...
Defining \__color_backend_stroke_TwoUp:n on line ...
Defining \__color_backend_select_TwoUp:n on line ...
Defining \__color_model_TwoUp_white: on line ...
+Defining \__color_convert_TwoUp_cmyk:w on line ...
+Defining \__color_convert_TwoUp_gray:w on line ...
+Defining \__color_convert_TwoUp_rgb:w on line ...
Defining \l__color_named_twoup_tl on line ...
Defining \l__color_named_twoup_prop on line ...
The color foo has the properties:
@@ -442,6 +445,9 @@ Defining \__color_backend_fill_AllIn:n on line ...
Defining \__color_backend_stroke_AllIn:n on line ...
Defining \__color_backend_select_AllIn:n on line ...
Defining \__color_model_AllIn_white: on line ...
+Defining \__color_convert_AllIn_cmyk:w on line ...
+Defining \__color_convert_AllIn_gray:w on line ...
+Defining \__color_convert_AllIn_rgb:w on line ...
Defining \l__color_named_allin_tl on line ...
Defining \l__color_named_allin_prop on line ...
The color foo has the properties:
diff --git a/l3experimental/l3color/testfiles/m3color003.xetex.tlg b/l3experimental/l3color/testfiles/m3color003.xetex.tlg
index 225713522..d822ef959 100644
--- a/l3experimental/l3color/testfiles/m3color003.xetex.tlg
+++ b/l3experimental/l3color/testfiles/m3color003.xetex.tlg
@@ -413,6 +413,9 @@ Defining \__color_backend_fill_TwoUp:n on line ...
Defining \__color_backend_stroke_TwoUp:n on line ...
Defining \__color_backend_select_TwoUp:n on line ...
Defining \__color_model_TwoUp_white: on line ...
+Defining \__color_convert_TwoUp_cmyk:w on line ...
+Defining \__color_convert_TwoUp_gray:w on line ...
+Defining \__color_convert_TwoUp_rgb:w on line ...
Defining \l__color_named_twoup_tl on line ...
Defining \l__color_named_twoup_prop on line ...
The color foo has the properties:
@@ -432,6 +435,9 @@ Defining \__color_backend_fill_AllIn:n on line ...
Defining \__color_backend_stroke_AllIn:n on line ...
Defining \__color_backend_select_AllIn:n on line ...
Defining \__color_model_AllIn_white: on line ...
+Defining \__color_convert_AllIn_cmyk:w on line ...
+Defining \__color_convert_AllIn_gray:w on line ...
+Defining \__color_convert_AllIn_rgb:w on line ...
Defining \l__color_named_allin_tl on line ...
Defining \l__color_named_allin_prop on line ...
The color foo has the properties:
More information about the latex3-commits
mailing list.