summaryrefslogtreecommitdiff
path: root/graphics/pstricks/contrib/pst-cie/tex/pst-cie.tex
blob: 3157147c0fc88082a40cd095ac8a9f0b15c1e0cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
%%
%% This is file `pst-cie.tex',
%%
%% IMPORTANT NOTICE:
%%
%% Package `pst-cie.tex'
%%
%% Manuel Luque <Manuel.Luque27 _at_ gmail.com
%% Herbert Voss <hvoss _at_ tug.org>
%%
%% This program can be redistributed and/or modified under the terms
%% of the LaTeX Project Public License Distributed from CTAN archives
%% in directory macros/latex/base/lppl.txt.
%%
%% DESCRIPTION:
%%   `pst-cie' is a PSTricks package to draw CIE color space
%%   with a Planck' locus
%%
\csname PSTcieLoaded\endcsname
\let\PSTcieLoaded\endinput
\ifx\PSTricksLoaded\endinput\else \input pstricks.tex\fi
\ifx\PSTplotLoaded \endinput\else \input pst-plot.tex\fi
\ifx\PSTnodesLoaded\endinput\else \input pst-node \fi
%\ifx\PSTXKeyLoaded\endinput\else    \input pst-xkey \fi
%
\def\fileversion{1.06b}
\def\filedate{2021/11/04}
\message{`PST-cie' v\fileversion, \filedate\space (hv)}
%
\edef\PstAtCode{\the\catcode`\@} \catcode`\@=11\relax
\pst@addfams{pst-cie}
\pstheader{pst-cie.pro}
%
\define@key[psset]{pst-cie}{gamma}[2.2]{\def\psk@psCIE@GAM{#1 }}
\define@key[psset]{pst-cie}{contrast}[1]{\def\psk@psCIE@contrast{#1 }}
\define@key[psset]{pst-cie}{chromaticityCoordinates}[xy]{\def\psk@psCIE@chromaticityCoordinates{#1}}
\define@key[psset]{pst-cie}{bgcolor}[black]{\pst@getcolor{#1}\pst@psCIE@bgcolor}
\define@key[psset]{pst-cie}{textcolor}[white]{\pst@getcolor{#1}\pst@psCIE@textcolor}
\define@key[psset]{pst-cie}{trianglecolor}[black]{\pst@getcolor{#1}\pst@psCIE@trianglecolor}
\psset[pst-cie]{gamma=2.2,contrast=1,bgcolor=black,textcolor=white,trianglecolor=black}
\define@boolkey[psset]{pst-cie}[Pst@]{primaries}[true]{}
\define@key[psset]{pst-cie}{Tfontsize}{\pst@getlength{#1}\psk@Tfontsize}
\define@boolkey[psset]{pst-cie}[Pst@]{Planck}[true]{}
\define@boolkey[psset]{pst-cie}[Pst@]{showcontour}[true]{}
\psset[pst-cie]{primaries,Planck=false,showcontour=false,Tfontsize=4pt,chromaticityCoordinates={xy}}
% primary illuminants
% systems = Adobe, CIE, SMPTE, sRGB,Pal-Secam, NTSC
% #1=type de reservation (action, object...) associee a une liste qui
% doit forcement etre du type pst@cie@list@#1
\def\pst@cie@reservednames#1{%
  \edef\@tempa{\csname pst@cie@list@#1\endcsname}
  \@for \name:=\@tempa\do{\expandafter\def\csname pst@cie@#1@\name\endcsname{}}}
% système
\def\txCIEdictBegin{ tx@CIEdict begin }
%
\def\pst@cie@list@ColorSpace{Adobe,CIE,ColorMatch,NTSC,Pal-Secam,ProPhoto,SMPTE,sRGB}
%% Reservation de macros correspondants aux systemes
\pst@cie@reservednames{ColorSpace}
\define@key[psset]{pst-cie}{ColorSpace}{%
  \ifcsname pst@cie@ColorSpace@#1\endcsname
    \def\pst@cie@ColorSpace{#1}%
  \else
    \@pstrickserr{This color space is not authorized, sRGB is
    chosen by default}{}%
  \fi}
\psset[pst-cie]{ColorSpace=sRGB}

% datas
\def\pst@cie@list@datas{CIE1964,CIE1931}
%% Reservation de macros correspondants aux datas
\pst@cie@reservednames{datas}
\define@key[psset]{pst-cie}{datas}{%
  \ifcsname pst@cie@datas@#1\endcsname
    \def\pst@cie@datas{#1}%
  \else
    \@pstrickserr{This datas is not authorized, CIE1931 is chosen by default}{}%
  \fi}
\psset[pst-cie]{datas=CIE1931}
\def\CIEdefaultYear{CIE1931}
%
\def\psChromaticityDiagram{\def\pst@par{}\pst@object{psChromaticityDiagram}}
\def\psChromaticityDiagram@i{%
  \begin@SpecialObj
%\pstVerb{\ifPst@primaries /primaries {true} def \else /primaries {false} def \fi}%
  \addto@pscode{
    \ifPst@primaries /primaries {true} def \else /primaries {false} def \fi
    /gamma \psk@psCIE@GAM def
    /contrast \psk@psCIE@contrast def
    /ColorSpace (\pst@cie@ColorSpace) def
    /datas (\pst@cie@datas) def
    /chromaticityCoordinates (\psk@psCIE@chromaticityCoordinates) def
    /cie-bgcolor { \pst@usecolor\pst@psCIE@bgcolor } def
    /cie-textcolor { \pst@usecolor\pst@psCIE@textcolor } def
    /cie-unit \pst@number\psunit 10 mul def
    /cie-U \pst@number\psunit 28.45274 div def
    \txCIEdictBegin SCREEN {datas cvx exec}
     {ColorSpace cvx exec} gamma contrast traceGamut end
  }%
  \ifPst@Planck\gdef\ps@next{\pstPlanck}\else\gdef\ps@next{}\fi%  options are local
  \end@SpecialObj
  \ps@next
}%
%
\def\pstCIEcontour{\pst@object{pstCIEcontour}}%
\def\pstCIEcontour@i{%
 \begin@ClosedObj
  \addto@pscode{
    \ifPst@primaries /primaries {true} def \else /primaries {false} def \fi
    /gamma \psk@psCIE@GAM def
    /contrast \psk@psCIE@contrast def
    /ColorSpace (\pst@cie@ColorSpace) def
    /datas (\pst@cie@datas) def
    /chromaticityCoordinates (\psk@psCIE@chromaticityCoordinates) def
    /cie-bgcolor { \pst@usecolor\pst@psCIE@bgcolor } def
    /cie-textcolor { \pst@usecolor\pst@psCIE@textcolor } def
    /cie-trianglecolor { \pst@usecolor\pst@psCIE@trianglecolor } def
    /cie-unit \pst@number\psunit 10 mul def
    /cie-U cie-unit 28.45274 div def
    \txCIEdictBegin {datas cvx exec} /TAB exch def ColorSpace cvx exec %/system exch def
     chromaticityCoordinates (xy) ne {/Tabuv [
    0 1 TAB length 1 sub {/i exch def
     TAB i get /subarray exch def
     /X subarray 0 get def /Y subarray 1 get def /Z 1 X sub Y sub def
%     [4 X mul X 15 Y mul add 3 Z mul add div   % u
%      6 Y mul X 15 Y mul add 3 Z mul add div]  % v
     [4 X mul X 15 Y mul add 3 Z mul add div    % u'
      9 Y mul X 15 Y mul add 3 Z mul add div]   % v'
      } for
     ] def
     /TAB Tabuv def
     } if
%    system
    gsave primaries {CouleursPrimaires} if grestore
    TAB contour stroke
    contourTriangle cie-trianglecolor stroke
   end
  }%
 \end@ClosedObj
}
%    \txCIEdictBegin \ifx\pst@cie@datas\CIEdefaultYear CIEXYZ_1931_table \else CIEXYZ_1964_table \fi
%
\def\pstPlanck{\pst@object{pstPlanck}}%
\def\pstPlanck@i{%
  \begingroup
  \use@par
  \font\CMSS=cmss10 at \psk@Tfontsize pt
  \ifPst@showcontour\pstCIEcontour\fi
  % lieu des points blancs (Planckian locus)
  \parametricplot[plotpoints=3000]{1000}{500000}{
    \txCIEdictBegin t \ifx\pst@cie@datas\CIEdefaultYear CIEXYZ_1931_table \else CIEXYZ_1964_table \fi
    BLKBOD Y X X Y Z end
    add add /S ED S div 10 mul exch S div 10 mul }%
  \parametricplot[plotpoints=2,arrows=-|]{500000}{502000}{
    \txCIEdictBegin t \ifx\pst@cie@datas\CIEdefaultYear CIEXYZ_1931_table \else CIEXYZ_1964_table \fi
    BLKBOD Y X X Y Z end
    add add /S ED S div 10 mul exch S div 10 mul }%
  % point de concours des normales : R.Sève : physique de la couleur (.332,.186)
  %\psdot[linecolor=red](3.32,1.86)
  \pnode(3.320,1.858){O}%
  \psforeach{\iA}{5000,7000,8000,9000,11000,12000,13000}{%
    \pnode(!
      \txCIEdictBegin \iA\space \ifx\pst@cie@datas\CIEdefaultYear CIEXYZ_1931_table \else CIEXYZ_1964_table \fi
      BLKBOD Y X X Y Z end
      add add /S ED
      S div 10 mul exch S div 10 mul){D\iA}%
    \psRelNode(O)(D\iA){0.96}{d0}\psRelNode(O)(D\iA){1.04}{d1}%
    \psline(d0)(d1)%
  }%
  \psforeach{\iA}{1500,2000,2500,3000,4000,6000,10000}{%
    \pnode(!
      \txCIEdictBegin \iA\space
      \ifx\pst@cie@datas\CIEdefaultYear CIEXYZ_1931_table \else CIEXYZ_1964_table \fi
      BLKBOD Y X X Y Z end
      add add /S ED
      S div 10 mul exch S div 10 mul){D\iA}%
    \psRelNode(O)(D\iA){1 3.2e-5 \iA\space mul sub}{d0}\psRelNode(O)(D\iA){1 3.2e-5 \iA\space mul add}{d1}%
    \pcline(d0)(d1)\ncput[npos=1.15]{\CMSS\iA}%
  }%
  \uput[-125](!
    1e5
    \txCIEdictBegin \ifx\pst@cie@datas\CIEdefaultYear CIEXYZ_1931_table \else CIEXYZ_1964_table \fi
    BLKBOD Y X X Y Z end
    add add /S ED
    S div 10 mul exch S div 10 mul){$\scriptstyle\infty$}%
  \endgroup
}
%
\catcode`\@=\PstAtCode\relax
\endinput
%% END pst-cie.tex \def\pstCIEcontour{\pst@object{pstCIEcontour}}%