xref: /AOO41X/main/slideshow/source/inc/hslcolor.hxx (revision aaef562f9b4401da6d8a910634bb68eaaacb4ebd)
1*aaef562fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*aaef562fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*aaef562fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*aaef562fSAndrew Rist  * distributed with this work for additional information
6*aaef562fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*aaef562fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*aaef562fSAndrew Rist  * "License"); you may not use this file except in compliance
9*aaef562fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*aaef562fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*aaef562fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*aaef562fSAndrew Rist  * software distributed under the License is distributed on an
15*aaef562fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*aaef562fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*aaef562fSAndrew Rist  * specific language governing permissions and limitations
18*aaef562fSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*aaef562fSAndrew Rist  *************************************************************/
21*aaef562fSAndrew Rist 
22*aaef562fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef INCLUDED_SLIDESHOW_HSLCOLOR_HXX
25cdf0e10cSrcweir #define INCLUDED_SLIDESHOW_HSLCOLOR_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <cppcanvas/color.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir 
30cdf0e10cSrcweir /* Definition of HSLColor class */
31cdf0e10cSrcweir 
32cdf0e10cSrcweir namespace slideshow
33cdf0e10cSrcweir {
34cdf0e10cSrcweir     namespace internal
35cdf0e10cSrcweir     {
36cdf0e10cSrcweir         class RGBColor;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir         /** HSL color space class.
39cdf0e10cSrcweir          */
40cdf0e10cSrcweir         class HSLColor
41cdf0e10cSrcweir         {
42cdf0e10cSrcweir         public:
43cdf0e10cSrcweir             HSLColor();
44cdf0e10cSrcweir             explicit HSLColor( ::cppcanvas::Color::IntSRGBA nRGBColor );
45cdf0e10cSrcweir             HSLColor( double nHue, double nSaturation, double nLuminance );
46cdf0e10cSrcweir             explicit HSLColor( const RGBColor& rColor );
47cdf0e10cSrcweir 
48cdf0e10cSrcweir             /** Hue of the color.
49cdf0e10cSrcweir 
50cdf0e10cSrcweir             	@return hue, is in the range [0,360]
51cdf0e10cSrcweir              */
52cdf0e10cSrcweir             double getHue() const;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir             /** Saturation of the color.
55cdf0e10cSrcweir 
56cdf0e10cSrcweir             	@return saturation, is in the range [0,1]
57cdf0e10cSrcweir              */
58cdf0e10cSrcweir             double getSaturation() const;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir             /** Luminance of the color.
61cdf0e10cSrcweir 
62cdf0e10cSrcweir             	@return luminance, is in the range [0,1]
63cdf0e10cSrcweir              */
64cdf0e10cSrcweir             double getLuminance() const;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir             /** Get the RGB red value.
67cdf0e10cSrcweir              */
68cdf0e10cSrcweir             double getRed() const;
69cdf0e10cSrcweir 
70cdf0e10cSrcweir             /** Get the RGB green value.
71cdf0e10cSrcweir              */
72cdf0e10cSrcweir             double getGreen() const;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir             /** Get the RGB blue value.
75cdf0e10cSrcweir              */
76cdf0e10cSrcweir             double getBlue() const;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir             /** Create an RGB color object.
79cdf0e10cSrcweir              */
80cdf0e10cSrcweir             RGBColor getRGBColor() const;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir             struct HSLTriple
83cdf0e10cSrcweir             {
84cdf0e10cSrcweir                 HSLTriple();
85cdf0e10cSrcweir                 HSLTriple( double nHue, double nSaturation, double nLuminance );
86cdf0e10cSrcweir 
87cdf0e10cSrcweir                 double mnHue;
88cdf0e10cSrcweir                 double mnSaturation;
89cdf0e10cSrcweir                 double mnLuminance;
90cdf0e10cSrcweir             };
91cdf0e10cSrcweir 
92cdf0e10cSrcweir         private:
93cdf0e10cSrcweir             // default copy/assignment are okay
94cdf0e10cSrcweir             // HSLColor(const HSLColor&);
95cdf0e10cSrcweir             // HSLColor& operator=( const HSLColor& );
96cdf0e10cSrcweir 
97cdf0e10cSrcweir             HSLTriple	maHSLTriple;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir             /// Pre-calculated value, needed for conversion back to RGB
100cdf0e10cSrcweir             double 		mnMagicValue;
101cdf0e10cSrcweir         };
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         HSLColor operator+( const HSLColor& rLHS, const HSLColor& rRHS );
104cdf0e10cSrcweir         HSLColor operator*( const HSLColor& rLHS, const HSLColor& rRHS );
105cdf0e10cSrcweir         HSLColor operator*( double nFactor, const HSLColor& rRHS );
106cdf0e10cSrcweir 
107cdf0e10cSrcweir         /** HSL color linear interpolator.
108cdf0e10cSrcweir 
109cdf0e10cSrcweir             @param t
110cdf0e10cSrcweir             As usual, t must be in the [0,1] range
111cdf0e10cSrcweir 
112cdf0e10cSrcweir             @param bCCW
113cdf0e10cSrcweir             When true, hue interpolation happens counter-clockwise
114cdf0e10cSrcweir         */
115cdf0e10cSrcweir         HSLColor interpolate( const HSLColor& rFrom, const HSLColor& rTo, double t, bool bCCW=true );
116cdf0e10cSrcweir     }
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir #endif /* INCLUDED_SLIDESHOW_HSLCOLOR_HXX */
120