Changes of Revision 40

_service Changed
x
 
1
@@ -115,7 +115,6 @@
2
        <param name="exclude">synfig-core/src/modules/untemplate.nsh</param>
3
        <param name="exclude">synfig-core/src/synfig/CMakeLists.txt</param>
4
        <param name="exclude">synfig-core/src/synfig/color/CMakeLists.txt</param>
5
-       <param name="exclude">synfig-core/src/synfig/color/color.hpp</param>
6
        <param name="exclude">synfig-core/src/synfig/debug/CMakeLists.txt</param>
7
        <param name="exclude">synfig-core/src/synfig/layers/CMakeLists.txt</param>
8
        <param name="exclude">synfig-core/src/synfig/rendering/CMakeLists.txt</param>
9
_service:obs_scm:synfig-1.5.3.obscpio/synfig-core/src/synfig/color/color.hpp Added
201
 
1
@@ -0,0 +1,290 @@
2
+/* === S Y N F I G ========================================================= */
3
+/*!    \file synfig/color/color.hpp
4
+** \brief Color class function implementation
5
+**
6
+** \legal
7
+** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
8
+** Copyright (c) 2007, 2008 Chris Moore
9
+** Copyright (c) 2012-2013 Carlos López
10
+** Copyright (c) 2015 Diego Barrios Romero
11
+**
12
+** This file is part of Synfig.
13
+**
14
+** Synfig is free software: you can redistribute it and/or modify
15
+** it under the terms of the GNU General Public License as published by
16
+** the Free Software Foundation, either version 2 of the License, or
17
+** (at your option) any later version.
18
+**
19
+** Synfig is distributed in the hope that it will be useful,
20
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
+** GNU General Public License for more details.
23
+**
24
+** You should have received a copy of the GNU General Public License
25
+** along with Synfig.  If not, see <https://www.gnu.org/licenses/>.
26
+** \endlegal
27
+*/
28
+/* ========================================================================= */
29
+
30
+#ifndef __SYNFIG_COLOR_COLOR_HPP
31
+#define __SYNFIG_COLOR_COLOR_HPP
32
+
33
+
34
+#include <synfig/string.h>
35
+#include <synfig/angle.h>
36
+
37
+
38
+#ifdef USING_PCH
39
+#  include "pch.h"
40
+#else
41
+#ifdef HAVE_CONFIG_H
42
+#  include <config.h>
43
+#endif
44
+
45
+#include "color.h"
46
+#endif
47
+
48
+namespace synfig {
49
+
50
+Color& Color::operator+=(const Color &rhs)
51
+{
52
+   r_+=rhs.r_;
53
+   g_+=rhs.g_;
54
+   b_+=rhs.b_;
55
+   a_+=rhs.a_;
56
+   return *this;
57
+}
58
+
59
+Color& Color::operator-=(const Color &rhs)
60
+{
61
+   r_-=rhs.r_;
62
+   g_-=rhs.g_;
63
+   b_-=rhs.b_;
64
+   a_-=rhs.a_;
65
+   return *this;
66
+}
67
+
68
+Color& Color::operator*=(const float &rhs)
69
+{
70
+   r_*=rhs;
71
+   g_*=rhs;
72
+   b_*=rhs;
73
+   a_*=rhs;
74
+   return *this;
75
+}
76
+
77
+Color& Color::operator/=(const float &rhs)
78
+{
79
+   const float temp(value_type(1)/rhs);
80
+   r_*=temp;
81
+   g_*=temp;
82
+   b_*=temp;
83
+   a_*=temp;
84
+   return *this;
85
+}
86
+
87
+Color Color::operator+(const Color &rhs) const
88
+{
89
+    return Color(*this)+=rhs;
90
+}
91
+
92
+Color Color::operator-(const Color &rhs) const
93
+{ return Color(*this)-=rhs; }
94
+
95
+Color Color::operator*(const float &rhs)const
96
+{ return Color(*this)*=rhs; }
97
+
98
+Color Color::operator/(const float &rhs)const
99
+{ return Color(*this)/=rhs; }
100
+
101
+bool Color::operator<(const Color &rhs)const
102
+{
103
+   return r_<rhs.r_ ? true  : rhs.r_<r_ ? false
104
+        : g_<rhs.g_ ? true  : rhs.g_<g_ ? false
105
+        : b_<rhs.b_ ? true  : rhs.b_<b_ ? false
106
+        : a_<rhs.a_;
107
+}
108
+
109
+bool Color::operator==(const Color &rhs)const
110
+{ return r_==rhs.r_ && g_==rhs.g_ && b_==rhs.b_ && a_==rhs.a_; }
111
+
112
+bool Color::operator!=(const Color &rhs)const
113
+{ return r_!=rhs.r_ || g_!=rhs.g_ || b_!=rhs.b_ || a_!=rhs.a_; }
114
+
115
+Color Color::operator-()const
116
+{ return Color(-r_,-g_,-b_,-a_); }
117
+
118
+//! Effectively 1.0-color
119
+Color Color::operator~()const
120
+{ return Color(1.0f-r_,1.0f-g_,1.0f-b_,a_); }
121
+
122
+bool Color::is_valid()const
123
+{ return !std::isnan(r_) && !std::isnan(g_) && !std::isnan(b_) && !std::isnan(a_); }
124
+
125
+Color Color::premult_alpha() const
126
+{
127
+   return Color (r_*a_, g_*a_, b_*a_, a_);
128
+}
129
+
130
+Color Color::demult_alpha() const
131
+{
132
+   if(a_)
133
+   {
134
+       const value_type inva = 1/a_;
135
+       return Color (r_*inva, g_*inva, b_*inva, a_);
136
+   }else return alpha();
137
+}
138
+
139
+Color::Color() :r_(0), g_(0), b_(0),a_(0) { }
140
+Color::Color(const value_type &f) :r_(f), g_(f), b_(f),a_(f) { }
141
+Color::Color(int f) :r_(f), g_(f), b_(f),a_(f) { }
142
+
143
+Color::Color(const value_type& R,
144
+             const value_type& G,
145
+             const value_type& B,
146
+             const value_type& A):
147
+   r_(R),
148
+   g_(G),
149
+   b_(B),
150
+   a_(A) { }
151
+
152
+Color::Color(const Color& c, const value_type& A):
153
+   r_(c.r_),
154
+   g_(c.g_),
155
+   b_(c.b_),
156
+   a_(A) { }
157
+
158
+const String Color::get_hex()const
159
+{
160
+    return String(real2hex(r_) + real2hex(g_) + real2hex(b_));
161
+}
162
+
163
+
164
+//! Returns color's luminance
165
+float Color::get_y() const
166
+{
167
+   return
168
+       (float)get_r()*EncodeYUV00+
169
+       (float)get_g()*EncodeYUV01+
170
+       (float)get_b()*EncodeYUV02;
171
+}
172
+
173
+
174
+//! Returns U component of chromanance
175
+float Color::get_u() const
176
+{
177
+   return
178
+       (float)get_r()*EncodeYUV10+
179
+       (float)get_g()*EncodeYUV11+
180
+       (float)get_b()*EncodeYUV12;
181
+}
182
+
183
+
184
+   //! Returns V component of chromanance
185
+float Color::get_v() const
186
+{
187
+   return
188
+       (float)get_r()*EncodeYUV20+
189
+       (float)get_g()*EncodeYUV21+
190
+       (float)get_b()*EncodeYUV22;
191
+}
192
+
193
+//! Returns the color's saturation
194
+/*!    This is is the magnitude of the U and V components.
195
+** \see set_s() */
196
+float Color::get_s() const
197
+{
198
+   const float u(get_u()), v(get_v());
199
+   return sqrt(u*u+v*v);
200
+}
201