[latex3-commits] [git/LaTeX3-latex3-latex3] master: Use xcollor method for wave to rgb conversion (1376cf144)
Joseph Wright
joseph.wright at morningstar2.co.uk
Wed Aug 12 10:58:11 CEST 2020
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/1376cf144137155e15a83d5117e3e2c2b47dec2e
>---------------------------------------------------------------
commit 1376cf144137155e15a83d5117e3e2c2b47dec2e
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Wed Aug 12 09:58:11 2020 +0100
Use xcollor method for wave to rgb conversion
At the edges of the visual range, this is quite different
to the one described in the xcolor manual in rgb.
>---------------------------------------------------------------
1376cf144137155e15a83d5117e3e2c2b47dec2e
l3experimental/l3color/l3color.dtx | 83 +++++++++++++------------
l3experimental/l3color/testfiles/m3color002.tlg | 34 +++++-----
2 files changed, 60 insertions(+), 57 deletions(-)
diff --git a/l3experimental/l3color/l3color.dtx b/l3experimental/l3color/l3color.dtx
index d895d80f2..962c97dc9 100644
--- a/l3experimental/l3color/l3color.dtx
+++ b/l3experimental/l3color/l3color.dtx
@@ -881,8 +881,10 @@
% \@@_parse_model_hsb_4:nnnn ,
% \@@_parse_model_hsb_5:nnnn
% }
-% \begin{macro}[EXP]{\@@_parse_model_wave:nn}
-% \begin{macro}[EXP]{\@@_parse_model_wave:nnnn}
+% \begin{macro}[EXP]{\@@_parse_model_wave:w}
+% \begin{macro}[EXP]
+% {\@@_parse_model_wave_auxi:nn, \@@_parse_model_wave_auxii:nn}
+% \begin{macro}[EXP]{\@@_parse_model_wave_rho:n}
% \begin{macrocode}
\cs_new:Npn \@@_parse_model_Gray:w #1 , #2 \s_@@_stop
{ { gray } { \fp_eval:n { #1 / 15 } } }
@@ -963,75 +965,75 @@
}
}
% \end{macrocode}
-% Following the description in the \pkg{xcolor} manual, we use the conversion to
-% \texttt{rgb} with $\gamma = 1.0$. We do \emph{not} go via \texttt{hsb} as for
-% us that is not a core model. The first step is to calculate $f$, allowing for
-% the color being out-of-visible range and so black.
+% Following the description in the \pkg{xcolor} manual. As we always use |rgb|,
+% there is no need to find the sixth, we just pas the information straight
+% to the |hsb| auxiliary defined earlier.
% \begin{macrocode}
\cs_new:Npn \@@_parse_model_wave:w #1 , #2 \s_@@_stop
{
{ rgb }
{
- \bool_lazy_or:nnTF
- { \fp_compare_p:nNn {#1} < { 380 } }
- { \fp_compare_p:nNn {#1} > { 780 } }
- { 0 , 0 , 0 }
+ \fp_compare:nNnTF {#1} < { 420 }
+ { \@@_parse_model_wave_auxi:nn {#1} { 0.3 + 0.7 * (#1 - 380) / 40 }
+ }
{
- \exp_args:Ne \@@_parse_model_wave:nn
- {
- \fp_compare:nNnTF {#1} < { 420 }
- { \fp_eval:n { 0.3 + 0.7 * (#1 - 380) / 40 } }
- {
- \fp_compare:nNnTF {#1} > { 700 }
- { \fp_eval:n { 0.3 + 0.7 * (780 - #1) / 80 } }
- { 1 }
- }
- }
- {#1}
+ \fp_compare:nNnTF {#1} > { 700 }
+ { \@@_parse_model_wave_auxi:nn {#1} { 0.3 + 0.7 * (#1 - 780) / -80 } }
+ { \@@_parse_model_wave_auxi:nn {#1} { 1 } }
}
}
}
-\cs_new:Npn \@@_parse_model_wave:nn #1#2
+\cs_new:Npn \@@_parse_model_wave_auxi:nn #1#2
{
- \fp_compare:nNnTF {#2} < { 440 }
+ \fp_compare:nNnTF {#1} < { 440 }
{
- \@@_parse_model_wave:nnnn {#1} { ( 440 - #2 ) / 60 } { 0 } { 1 }
+ \@@_parse_model_wave_auxii:nn
+ { 4 + \@@_parse_model_wave_rho:n { (#1 - 440) / -60 } }
+ {#2}
}
{
- \fp_compare:nNnTF {#2} < { 490 }
+ \fp_compare:nNnTF {#1} < { 490 }
{
- \@@_parse_model_wave:nnnn {#1} { 0 } { ( #2 - 440 ) / 50 } { 1 }
+ \@@_parse_model_wave_auxii:nn
+ { 4 - \@@_parse_model_wave_rho:n { (#1 - 440) / 50 } }
+ {#2}
}
{
- \fp_compare:nNnTF {#2} < { 510 }
+ \fp_compare:nNnTF {#1} < { 510 }
{
- \@@_parse_model_wave:nnnn {#1} { 0 } { 1 }
- { ( 510 - #2 ) / 20 }
+ \@@_parse_model_wave_auxii:nn
+ { 2 + \@@_parse_model_wave_rho:n { (#1 - 510) / -20 } }
+ {#2}
}
{
- \fp_compare:nNnTF {#2} < { 580 }
+ \fp_compare:nNnTF {#1} < { 580 }
{
- \@@_parse_model_wave:nnnn {#1}
- { ( #2 - 510 ) / 70 } { 1 } { 0 }
+ \@@_parse_model_wave_auxii:nn
+ { 2 - \@@_parse_model_wave_rho:n { (#1 - 510) / 70 } }
+ {#2}
}
{
- \fp_compare:nNnTF {#2} < { 645 }
+ \fp_compare:nNnTF {#1} < { 645 }
{
- \@@_parse_model_wave:nnnn {#1} { 1 }
- { ( 645 - #2 ) / 65 } { 0 }
+ \@@_parse_model_wave_auxii:nn
+ { \@@_parse_model_wave_rho:n { (#1 - 645) / -65 } }
+ {#2}
}
- { \@@_parse_model_wave:nnnn {#1} { 1 } { 0 } { 0 } }
+ { \@@_parse_model_wave_auxii:nn { 0 } {#2} }
}
}
}
}
}
-\cs_new:Npn \@@_parse_model_wave:nnnn #1#2#3#4
+\cs_new:Npn \@@_parse_model_wave_auxii:nn #1#2
{
- \fp_eval:n { #1 * #2 } ,
- \fp_eval:n { #1 * #3 } ,
- \fp_eval:n { #1 * #4 }
+ \exp_args:Neee \@@_parse_model_hsb_aux:nnn
+ { \fp_eval:n {#1} }
+ { 1 }
+ { \@@_parse_model_wave_rho:n {#2} }
}
+\cs_new:Npn \@@_parse_model_wave_rho:n #1
+ { \fp_eval:n { min(1, max(0,#1) ) } }
% \end{macrocode}
% \end{macro}
% \end{macro}
@@ -1040,6 +1042,7 @@
% \end{macro}
% \end{macro}
% \end{macro}
+% \end{macro}
%
% \subsection{Selecting colors (and color models)}
%
diff --git a/l3experimental/l3color/testfiles/m3color002.tlg b/l3experimental/l3color/testfiles/m3color002.tlg
index 042cfaf8e..976be52f0 100644
--- a/l3experimental/l3color/testfiles/m3color002.tlg
+++ b/l3experimental/l3color/testfiles/m3color002.tlg
@@ -85,87 +85,87 @@ TEST 4: wave model
============================================================
The color foo1 has the properties:
> model => rgb
-> rgb => 0,0,0.
+> rgb => 0.0 0 0.
<recently read> }
l. ... }
The color foo1 has the properties:
> model => rgb
-> rgb => 0.3,0,0.3.
+> rgb => 0.3 0 0.3.
<recently read> }
l. ... }
The color foo1 has the properties:
> model => rgb
-> rgb => 0.4333333333333333,0,0.65.
+> rgb => 0.43333 0 0.65.
<recently read> }
l. ... }
The color foo1 has the properties:
> model => rgb
-> rgb => 0.4125,0,0.825.
+> rgb => 0.4125 0 0.825.
<recently read> }
l. ... }
The color foo1 has the properties:
> model => rgb
-> rgb => 0,0,1.
+> rgb => 0 0 1.0.
<recently read> }
l. ... }
The color foo1 has the properties:
> model => rgb
-> rgb => 0,0.8,1.
+> rgb => 0 0.8 1.0.
<recently read> }
l. ... }
The color foo1 has the properties:
> model => rgb
-> rgb => 0,1,1.
+> rgb => 0 1 1.0.
<recently read> }
l. ... }
The color foo1 has the properties:
> model => rgb
-> rgb => 0,1,0.5.
+> rgb => 0 1.0 0.5.
<recently read> }
l. ... }
The color foo1 has the properties:
> model => rgb
-> rgb => 0,1,0.
+> rgb => 0 1.0 0.
<recently read> }
l. ... }
The color foo1 has the properties:
> model => rgb
-> rgb => 0.4285714285714286,1,0.
+> rgb => 0.42857 1.0 0.
<recently read> }
l. ... }
The color foo1 has the properties:
> model => rgb
-> rgb => 1,1,0.
+> rgb => 1 1.0 0.
<recently read> }
l. ... }
The color foo1 has the properties:
> model => rgb
-> rgb => 1,0.6923076923076923,0.
+> rgb => 1.0 0.69231 0.
<recently read> }
l. ... }
The color foo1 has the properties:
> model => rgb
-> rgb => 1,0,0.
+> rgb => 1.0 0 0.
<recently read> }
l. ... }
The color foo1 has the properties:
> model => rgb
-> rgb => 1,0,0.
+> rgb => 1.0 0 0.
<recently read> }
l. ... }
The color foo1 has the properties:
> model => rgb
-> rgb => 0.65,0,0.
+> rgb => 0.65 0 0.
<recently read> }
l. ... }
The color foo1 has the properties:
> model => rgb
-> rgb => 0.3,0,0.
+> rgb => 0.3 0 0.
<recently read> }
l. ... }
The color foo1 has the properties:
> model => rgb
-> rgb => 0,0,0.
+> rgb => 0.125 0 0.
<recently read> }
l. ... }
============================================================
More information about the latex3-commits
mailing list.