summaryrefslogtreecommitdiff
path: root/macros/optex/base/colors.opm
diff options
context:
space:
mode:
Diffstat (limited to 'macros/optex/base/colors.opm')
-rw-r--r--macros/optex/base/colors.opm30
1 files changed, 24 insertions, 6 deletions
diff --git a/macros/optex/base/colors.opm b/macros/optex/base/colors.opm
index bbda496761..23ec22dd9f 100644
--- a/macros/optex/base/colors.opm
+++ b/macros/optex/base/colors.opm
@@ -1,6 +1,6 @@
%% This is part of the OpTeX project, see http://petr.olsak.net/optex
-\_codedecl \colordef {Colors <2020-03-18>} % loaded in format
+\_codedecl \colordef {Colors <2021-05-28>} % preloaded in format
\_doc -----------------------------
We declare internal boolean value \`\_iflocalcolor` ad do
@@ -129,9 +129,12 @@
to they are in $[0,1]$ interval. The `\colordefFin` expands to the values
accumulated in Lua code `color_C`, `color_M`, `color_Y` and `color_K`.
The `\_douseK` applies \^`\useK` to CMYK components.
+ \nl
+ The `\_tocmyk:<rgb>` or `\_torgb:<cmyk>` control sequences (given by
+ \^`\rgbcmykmap`) have precedence.
\_cod -----------------------------
-\_def\_rgbtocmyk #1 #2 #3 ;{%
+\_def\_rgbtocmyk #1 #2 #3 ;{\_trycs{_tocmyk:#1 #2 #3}{%
\_ea \_stripzeros \_detokenize \_ea{\_directlua{
local kr = math.max(#1,#2,#3)
if (kr==0) then
@@ -140,13 +143,13 @@
tex.print(string.format('\_pcent.3f \_pcent.3f \_pcent.3f \_pcent.3f ;',
(kr-#1)/kr, (kr-#2)/kr, (kr-#3)/kr, 1-kr))
end
-}}}
-\_def\_cmyktorgb #1 #2 #3 #4 ;{%
+}}}}
+\_def\_cmyktorgb #1 #2 #3 #4 ;{\_trycs{_torgb:#1 #2 #3 #4}{%
\_ea \_stripzeros \_detokenize \_ea{\_directlua{
local kr = 1-#4
tex.print(string.format('\_pcent.3f \_pcent.3f \_pcent.3f ;',
(1-#1)*kr, (1-#2)*kr, (1-#3)*kr))
-}}}
+}}}}
\_def\_colorcrop{\_directlua{
local m=math.max(color_C, color_M, color_Y, color_K)
if (m>1) then
@@ -181,6 +184,19 @@
\_def\_stripzeroC #1 #2:{#1}
\_doc -----------------------------
+ \`\rgbcmykmap` `{<R> <G> <B>}`\,`{<C> <M> <Y> <K>}` declares mapping from
+ RGB to CMYK and from CMYK to RGB for given color. It has precedence
+ before general formulae used in the \^`\_rgbtocmyk` and \^`\_cmyktorgb`
+ macros. Note, that the values <R> <G> <B> <C> <M> <Y> <K> must be given
+ exacly in the same format as in \^`\setcmykcolor` and \^`\setrgbcolor`
+ parameters. For example, `0.5` or `.5` or `.50` are different values from
+ point of view of this mapping.
+ \_cod -----------------------------
+
+\_def\_rgbcmykmap#1#2{\_sxdef{_torgb:#2}{#1}\_sxdef{_tocmyk:#1}{#2}}
+\_public \rgbcmykmap ;
+
+ \_doc -----------------------------
The \`\rgbcolordef` and \`\cmykcolordef` use common macro
\`\_commoncolordef` with different first four parameters.
The `\_commoncolordef <selector><K><R><G><what-define>{<data>}` does the
@@ -373,7 +389,8 @@ The \^`\rgbcolordef` can be used to mix colors in additive color model RGB.
If \^`\onlyrgb` is declared, then \^`\colordef` works as \^`\rgbcolordef`.
If a CMYK to RGB or RGB to CMYK conversion is needed then
-the following simple formulae are used
+direct conversion of given color is used (if declared using
+\^`\rgbcmykmap``{<rgb>}{<cmyk>}`) or the following simple formulae are used
(ICC profiles are not supported):
$$
\displaylines{
@@ -390,5 +407,6 @@ and it is used in \^`\rgbcolordef` or if it is printed when \^`\onlyrgb` is decl
\_endinput
+2021-05-28 \rgbcmykmap introduced
2020-04-22 \replstring\tmpb{+ }{+}, {- }{-} added in \colordef, bug fixed
2020-03-18 introduced