{-
Copyright (c) 2008
Russell O'Connor
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-}-- |Colour operations defined by the International Commission on -- Illumination (CIE).moduleData.Colour.CIE(Colour,cieXYZ,toCIEXYZ,luminance,Chromaticity,mkChromaticity,chromaCoords,chromaX,chromaY,chromaZ,chromaConvert,chromaColour--,lightness, cieLab, cieLuv)whereimportData.ListimportData.ColourimportData.Colour.RGBimportData.Colour.SRGB.LinearimportData.Colour.CIE.ChromaticityimportData.Colour.Matrix-- |Construct a 'Colour' from XYZ coordinates for the 2&#176; standard-- (colourimetric) observer.cieXYZ::(Fractionala)=>a->a->a->ColouracieXYZxyz=rgbrgbwhere[r,g,b]=multmatrix[x,y,z]matrix=map(mapfromRational)xyz2rgb709-- |Return the XYZ colour coordinates for the 2&#176; standard-- (colourimetric) observer.toCIEXYZ::(Fractionala)=>Coloura->(a,a,a)toCIEXYZc=(x,y,z)whereRGBrgb=toRGBc[x,y,z]=multmatrix[r,g,b]matrix=map(mapfromRational)rgb7092xyz{- CIE luminance -}-- |Returns the Y colour coordinate (luminance) for the 2&#176; standard-- (colourimetric) observer.luminance::(Fractionala)=>Coloura->aluminancec=ywhere(x,y,z)=toCIEXYZcinstanceAffineSpaceChromaticitywhereaffineCombolz=foldl1'chromaAdd[chromaScalewa|(w,a)<-(1-total,z):l]wheretotal=sum$mapfstl(Chromax0y0)`chromaAdd`(Chromax1y1)=Chroma(x0+x1)(y0+y1)s`chromaScale`(Chromaxy)=Chroma(s*x)(s*y)-- |Constructs a colour from the given 'Chromaticity' and 'luminance'.chromaColour::(Fractionala)=>Chromaticitya->a-- ^ 'luminance'->ColourachromaColourchy=cieXYZ(s*ch_x)y(s*ch_z)where(ch_x,ch_y,ch_z)=chromaCoordschs=y/ch_y-- |Returns the lightness of a colour, which is a perceptually uniform-- measure.lightness::(Orda,Floatinga)=>Coloura->alightnessc|(6/29)^3<y=116*y**(1/3)-16|otherwise=(29/3)^3*ywherey=luminancec-- |Returns the CIELAB coordinates of a colour, which is a-- perceptually uniform colour space.-- If you don't know what white point to use, use-- 'Data.Colour.CIE.Illuminant.d65'.cieLab::(Orda,Floatinga)=>Chromaticitya-- ^White point->Coloura->(a,a,a)cieLabwhite_chc=(lightnessc,a,b)wherewhite=chromaColourwhite_ch1.0(x,y,z)=toCIEXYZc(xn,yn,zn)=toCIEXYZwhitea=500*((x/xn)**(1/3)-(y/yn)**(1/3))b=200*((y/yn)**(1/3)-(z/zn)**(1/3))-- |Returns the CIELUV coordinates of a colour, which is a-- perceptually uniform colour space.-- If you don't know what white point to use, use-- 'Data.Colour.CIE.Illuminant.d65'.cieLuv::(Orda,Floatinga)=>Chromaticitya-- ^White point->Coloura->(a,a,a)cieLuvwhite_chc=(l,13*l*(u'-un'),13*l*(v'-vn'))wherewhite=chromaColourwhite_ch1.0(u',v')=u'v'c(un',vn')=u'v'whitel=lightnessc--------------------------------------------------------------------------{- not for export -}u'v'::(Orda,Floatinga)=>Coloura->(a,a)u'v'c=(4*x/(x+15*y+3*z),9*y/(x+15*y+3*z))where(x,y,z)=toCIEXYZcrgb7092xyz=(rgb2xyzsRGBGamut)xyz2rgb709=inversergb7092xyz