1 /***********************************************************************
2 created: 20th February 2010
3 author: Lukas E Meindl
4
5 purpose: Implementation of the ColourPicker colour type classes
6 *************************************************************************/
7 /***************************************************************************
8 * Copyright (C) 2004 - 2011 Paul D Turner & The CEGUI Development Team
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining
11 * a copy of this software and associated documentation files (the
12 * "Software"), to deal in the Software without restriction, including
13 * without limitation the rights to use, copy, modify, merge, publish,
14 * distribute, sublicense, and/or sell copies of the Software, and to
15 * permit persons to whom the Software is furnished to do so, subject to
16 * the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
28 ***************************************************************************/
29 #include "CEGUI/CommonDialogs/ColourPicker/Types.h"
30 #include "CEGUI/CommonDialogs/ColourPicker/Conversions.h"
31
32 using namespace CEGUI;
33
34 //----------------------------------------------------------------------------//
RGB_Colour(const Lab_Colour & colour)35 RGB_Colour::RGB_Colour(const Lab_Colour& colour)
36 {
37 *this = ColourPickerConversions::toRGB(colour);
38 }
39
40 //----------------------------------------------------------------------------//
RGB_Colour(const HSV_Colour & colour)41 RGB_Colour::RGB_Colour(const HSV_Colour& colour)
42 {
43 *this = ColourPickerConversions::toRGB(colour);
44 }
45
46 //----------------------------------------------------------------------------//
RGB_Colour(const CEGUI::Colour & colour)47 RGB_Colour::RGB_Colour(const CEGUI::Colour& colour)
48 {
49 *this = ColourPickerConversions::toRGB(colour);
50 }
51
52
53 //----------------------------------------------------------------------------//
Lab_Colour(const RGB_Colour & colour)54 Lab_Colour::Lab_Colour(const RGB_Colour& colour)
55 {
56 *this = ColourPickerConversions::toLab(colour);
57 }
58
59 //----------------------------------------------------------------------------//
Lab_Colour(const HSV_Colour & colour)60 Lab_Colour::Lab_Colour(const HSV_Colour& colour)
61 {
62 *this = ColourPickerConversions::toLab(ColourPickerConversions::toRGB(colour));
63 }
64
65
66 //----------------------------------------------------------------------------//
Lab_Colour(const CEGUI::Colour & colour)67 Lab_Colour::Lab_Colour(const CEGUI::Colour& colour)
68 {
69 *this = ColourPickerConversions::toLab(ColourPickerConversions::toRGB(colour));
70 }
71
72 //----------------------------------------------------------------------------//
HSV_Colour(const RGB_Colour & colour)73 HSV_Colour::HSV_Colour(const RGB_Colour& colour)
74 {
75 *this = ColourPickerConversions::toHSV(colour);
76 }
77
78 //----------------------------------------------------------------------------//
HSV_Colour(const Lab_Colour & colour)79 HSV_Colour::HSV_Colour(const Lab_Colour& colour)
80 {
81 *this = ColourPickerConversions::toHSV(ColourPickerConversions::toRGB(colour));
82 }
83
84 //----------------------------------------------------------------------------//
HSV_Colour(const CEGUI::Colour & colour)85 HSV_Colour::HSV_Colour(const CEGUI::Colour& colour)
86 {
87 *this = ColourPickerConversions::toHSV(ColourPickerConversions::toRGB(colour));
88 }
89
90
91
92 //----------------------------------------------------------------------------//
operator *(const float & number) const93 RGB_Colour RGB_Colour::operator*(const float& number) const
94 {
95 RGB_Colour col;
96
97 col.r = static_cast<unsigned char>(r * number);
98 col.g = static_cast<unsigned char>(g * number);
99 col.b = static_cast<unsigned char>(b * number);
100
101 return col;
102 }
103
104 //----------------------------------------------------------------------------//
operator +(const RGB_Colour & colour) const105 RGB_Colour RGB_Colour::operator+(const RGB_Colour& colour) const
106 {
107 RGB_Colour col;
108
109 col.r = static_cast<int>(r) + static_cast<int>(colour.r);
110 col.g = static_cast<int>(g) + static_cast<int>(colour.g);
111 col.b = static_cast<int>(b) + static_cast<int>(colour.b);
112
113 return col;
114 }
115
116 //----------------------------------------------------------------------------//
117
118