\DocumentMetadata{}
\errorcontextlines=100
\documentclass{article}
\usepackage[a4paper,tmargin=1cm,bmargin=1cm,lmargin=1.5cm,rmargin=1cm,
  includeheadfoot]{geometry}
\usepackage{libertinus}
\usepackage[Scale=MatchLowercase,FakeStretch=0.8]{juliamono}
\usepackage{biblatex}
\addbibresource{\jobname.bib}
\addbibresource[location=remote]{https://mirror.ctan.org/biblio/ctan-bibdata/ctan.bib}

\usepackage{array,booktabs,libertinus,minted-code}
\usepackage{pst-plot}
\usepackage{pst-spectrum}
\usepackage{hvindex,xindex}
\makeindex
\usepackage[colorlinks]{hyperref}
\newcommand*\param[1]{\textcolor{blue}{\textsf{\textbf{#1}}}}

\def\Lcs#1{\texttt{\textbackslash#1}\index{#1@\texttt{\textbackslash#1}}}
\def\LPack#1{\texttt{#1}\index{#1@\texttt{#1} (package)}}
\def\Lkeyword#1{\texttt{#1}\index{#1@\texttt{#1} (keyword)}}
\def\Lkeyval#1{\texttt{#1}\index{#1@\texttt{#1} (value)}}
\def\PST{\texttt{PSTricks}}
\def\PS{\texttt{PostScript}}
\makeatletter
\def\LName#1{#1\expandafter\LName@i#1\@nil}
\def\LName@i#1 #2\@nil{\index{#2, #1}}
\makeatother

\title{Representing the Continuous Spectrum of Visible 
  Light: \texttt{pst-spectrum}}
%\date{1 mai 2016}
\author{Manuel Luque \and Herbert Voß}
\begin{document}
\maketitle

\section{Representing the Visible Spectrum of Light in Different Color Spaces}
To represent the spectrum of light decomposition, we have several 
packages at our disposal with PSTricks: \LPack{pst-spectra} 
by \LName{Arnaud Schmittbuhl}, 
\LPack{xcolor} by \LName{Uwe Kern}, and a \LPack{pstricks-add} 
command.~\cite{ctan-pst-spectra,ctan-xcolor,ctan-pstricks-add} 
All of them use the 
same source: a Fortran code by \LName{Dan Bruton} transposed into PostScript 
or \TeX.~\cite{db} I have provided a version here: extended visible spectrum. 
However, it is possible to obtain the representation of the spectrum 
directly from the data of the \Index{International Commission on Illumination}
(\Index{CIE}), 
and we have the choice between the data of (\Index{CIE 1931}) and that of 
(\Index{CIE 1964}). Then we must choose a \Index{color space}, \Index{sRGB}, 
\Index{Adobe}, etc., 
which each gives a significantly different representation. However, 
it is highly unreasonable to expect to reproduce a spectrum obtained by
an experimental method, since the various color spaces use illuminant 
\Index{D65}, which has a
nearest \Index{color temperature} of approximately 6500~K and corresponds to 
typical global solar radiation on overcast days. Experimentally, one 
would prefer to choose uncloudy weather, so another illuminant would 
need to be defined,
and according to \LName{Robert Sève}: »\Index{Temperature}s lower than 6500 K will 
be chosen to account for greater direct \Index{solar radiation} [\ldots].« 
One 
can also attempt to model the values of R, G, and B from the chosen 
working space; this is certainly what \LName{Dan Bruton} did, and we will see 
this in the second part.~\cite{db}


\section{Representations obtained with the pst-spectrum package}

Theoretically, the spectrum can be represented for all \Index{wavelength}s 
between 360~nm and 830~nm.

The \Lcs{psCIEspectrum} command has the following options taken from the 
\LPack{pst-spectra} package written by \LName{Arnaud Schmittbuhl}.~\cite{ctan-pst-spectra}

\begin{codeblockA}[title=The two macros]
\psCIEspectrum[options](x0,y0)(x1,y1)
\psCIEspectrumDB[options](x0,y0)(x1,y1)
\end{codeblockA}
 The coordinates  are optional and preset to \verb|(-6,-1)(6,1)|

\begin{exampleM}{Default image with default coordinates}
\psCIEspectrum[invers=false]  

\psCIEspectrumDB[invers=false]
\end{exampleM}


\begin{center}
\begin{tabular}{>{\bfseries\sffamily\color{blue}}l c c m{7cm}}\toprule
  Option & Type & Default & Description      \\\toprule
  \Lkeyword{begin}      &value   &360& Initial wavelength, in nm\\
  \Lkeyword{end}        &value   &830& Final \Index{wavelength}, in nm\\
  \Lkeyword{gamma}      &value   &2.2& \Index{Color correction} \\
 \Lkeyword{ColorSpace}        &name  &\Lkeyval{sRGB}& Color space  \\
 \Lkeyword{datas}        &name  &\Lkeyval{CIE1931}&  CIE data\\
 \Lkeyword{invers}      &bool& true & black backgound\\
 \Lkeyword{values}      & bool& true & print wavelength\\
 \bottomrule
\end{tabular}
\end{center}




The available color spaces are: \Lkeyval{Adobe}, \Lkeyval{CIE}, 
\Lkeyval{ColorMatch}, \Lkeyval{NTSC}, 
\Lkeyval{Pal-Secam}, \Lkeyval{ProPhoto}, \Lkeyval{SMPTE}, and \Lkeyval{sRGB}.
The available tabulated values are those of \Index{CIE XYZ 1931} and 
\Index{CIE XYZ 1964}.

The coordinate pair following the command determines the frame of 
the spectrum plot. By default, if the \Index{coordinates} are omitted, the 
output is: \Lcs{psCIEspectrum}\texttt{(-5,0)(5,1)}. \LName{Dan Bruton}'s model is drawn 
using the command \Lcs{psspectrumDB}. Here are some examples; note the 
differences depending on whether \Index{CIE 1931} or \Index{CIE 1964} 
data is used.

\begin{exampleM}{Default image with invers background}
\psCIEspectrum[gamma=1,begin=360,end=750](-7.6,-1)(8,1)
\end{exampleM}

\begin{exampleM}{Default image with white background}
\psCIEspectrum[gamma=1,begin=360,end=750,invers=false](-7.5,-1)(7.5,1)
\end{exampleM}

\begin{exampleM}{Default image without values}
\psCIEspectrum[gamma=1,begin=360,end=750,values=false](-7.5,-1)(7.5,1)
\end{exampleM}


\begin{exampleM}{{datas=CIE1964}}
\psCIEspectrum[gamma=1,begin=360,end=750,datas=CIE1964](-7.5,-1)(7.5,1)
\end{exampleM}

\begin{exampleM}{{datas=CIE1964, ColorSpace=sRGB}}
\psCIEspectrum[gamma=1,begin=360,end=750,datas=CIE1964](-7.5,-1)(7.5,1)
\end{exampleM}

\begin{exampleM}{{other begin/end values}}
\psCIEspectrum[gamma=1,begin=360,end=750,datas=CIE1964](-7.5,-1)(7.5,1)
\end{exampleM}

\begin{exampleM}{{ColorSpace=sRGB}}
\psCIEspectrum[gamma=1,begin=400,end=700,ColorSpace=sRGB](-7.5,-1)(7.5,1)
\end{exampleM}

\begin{exampleM}{{gamma=0.8}}
\psCIEspectrum[gamma=0.8,begin=400,end=700](-7.5,-1)(7.5,1)
\end{exampleM}


\begin{exampleM}{{ColorSpace=Adobe}}
\psCIEspectrum[gamma=2.2,begin=400,end=700,ColorSpace=Adobe](-7.5,-1)(7.5,1)
\end{exampleM}



\begin{exampleM}{{ColorSpace=ColorMatch}}
\psCIEspectrum[gamma=1.8,begin=400,end=700,ColorSpace=ColorMatch](-7.5,-1)(7.5,1)
\end{exampleM}


\begin{exampleM}{{ColorSpace=CIE}}
\psCIEspectrum[begin=400,end=700,ColorSpace=CIE](-7.5,-1)(7.5,1)
\end{exampleM}



\begin{exampleM}{{ColorSpace=SMPTE,datas=CIE1931}}
\psCIEspectrum[begin=400,end=700,ColorSpace=SMPTE,datas=CIE1931](-7.5,-1)(7.5,1)
\end{exampleM}

\begin{exampleM}{{ColorSpace=SMPTE,datas=CIE1964}}
\psCIEspectrum[begin=400,end=700,ColorSpace=SMPTE,datas=CIE1964](-7.5,-1)(7.5,1)
\end{exampleM}

\clearpage

\section{Comparison of the proportions of R, G, and B}
This is done 
according to Dan Bruton's models
and obtained directly from CIE data.~\cite{db}

\begin{center}
\begin{pspicture}(0,-1)(10,10)
\psgrid[subgriddiv=0,gridcolor=lightgray,griddots=10,gridlabels=0pt]
\pstVerb{
/GAM 1 2.2 div def
spectrumdict begin
/TAB CIE1931 def
/SYTEM {(Adobe) cvx exec} def
/WLRGB [
 0 1 TAB length 1 sub {/K exch def
          /WL 360 K add def
          /X TAB K get 0 get def %
          /Y TAB K get 1 get def %
          /Z TAB K get 2 get def %
XYZ_to_RGB /B exch def /G exch def /R exch def
 WL R GAM exp G GAM exp B GAM exp
} for
 ] def
/WLR [
0 4 WLRGB length 4 sub {/i exch def
  WLRGB i get 360 sub
  WLRGB i 1 add get} for
] def
/WLG [
0 4 WLRGB length 4 sub {/i exch def
  WLRGB i get 360 sub
  WLRGB i 2 add get} for
] def
/WLB [
0 4 WLRGB length 4 sub {/i exch def
  WLRGB i get 360 sub
  WLRGB i 3 add get} for
] def
WLR WLG WLB
end
/WLB exch def /WLG exch def /WLR exch def
}%
\listplot[xunit=0.02,yunit=10,linecolor=red]{WLR aload pop}
\listplot[xunit=0.02,yunit=10,linecolor=green]{WLG aload pop}
\listplot[xunit=0.02,yunit=10,linecolor=blue]{WLB aload pop}
\multido{\i=0+1,\iL=360+50}{11}{%
    \psline(\i,0)(\i,-0.2)
    \uput[d](\i,-0.2){\iL}}
\multido{\n=0.1+0.1,\i=1+1}{10}{
\psline(0,\i)(-0.1,\i)
\uput[l](-0.1,\i){\n}}
\end{pspicture}

Model \Index{CIE1931} by \Index{Adobe}.
\end{center}
\begin{center}
\begin{pspicture}(-1,-1)(10,10)
\psgrid[subgriddiv=0,gridcolor=lightgray,griddots=10,gridlabels=0pt]
\pstVerb{
/GAM 0.8 def
spectrumdict begin
/WLRGB [
360 1 830 {/lambda exch def
calculateRGB
lambda Red Green Blue
} for
] def
/WLR [
0 4 WLRGB length 4 sub {/i exch def
  WLRGB i get 360 sub
  WLRGB i 1 add get} for
] def
/WLG [
0 4 WLRGB length 4 sub {/i exch def
  WLRGB i get 360 sub
  WLRGB i 2 add get} for
] def
/WLB [
0 4 WLRGB length 4 sub {/i exch def
  WLRGB i get 360 sub
  WLRGB i 3 add get} for
] def
WLR WLG WLB
end
/WLB exch def /WLG exch def /WLR exch def
}%
\listplot[xunit=0.02,yunit=10,linecolor=red]{WLR aload pop}
\listplot[xunit=0.02,yunit=10,linecolor=green]{WLG aload pop}
\listplot[xunit=0.02,yunit=10,linecolor=blue]{WLB aload pop}
\multido{\i=0+1,\iL=360+50}{11}{%
    \psline(\i,0)(\i,-0.2)
    \uput[d](\i,-0.2){\iL}}
\multido{\n=0.1+0.1,\i=1+1}{10}{
\psline(0,\i)(-0.1,\i)
\uput[l](-0.1,\i){\n}}
\end{pspicture}

Model by \LName{Dan Bruton}
\end{center}

%\nocite{*}
\printbibliography
\printindex


\end{document}
