Projects
Multimedia
synfig
Sign Up
Log In
Username
Password
We truncated the diff of some files because they were too big. If you want to see the full diff for every file,
click here
.
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 40
View file
_service
Changed
@@ -115,7 +115,6 @@ <param name="exclude">synfig-core/src/modules/untemplate.nsh</param> <param name="exclude">synfig-core/src/synfig/CMakeLists.txt</param> <param name="exclude">synfig-core/src/synfig/color/CMakeLists.txt</param> - <param name="exclude">synfig-core/src/synfig/color/color.hpp</param> <param name="exclude">synfig-core/src/synfig/debug/CMakeLists.txt</param> <param name="exclude">synfig-core/src/synfig/layers/CMakeLists.txt</param> <param name="exclude">synfig-core/src/synfig/rendering/CMakeLists.txt</param>
View file
_service:obs_scm:synfig-1.5.3.obscpio/synfig-core/src/synfig/color/color.hpp
Added
@@ -0,0 +1,290 @@ +/* === S Y N F I G ========================================================= */ +/*! \file synfig/color/color.hpp +** \brief Color class function implementation +** +** \legal +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2007, 2008 Chris Moore +** Copyright (c) 2012-2013 Carlos López +** Copyright (c) 2015 Diego Barrios Romero +** +** This file is part of Synfig. +** +** Synfig is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 2 of the License, or +** (at your option) any later version. +** +** Synfig is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Synfig. If not, see <https://www.gnu.org/licenses/>. +** \endlegal +*/ +/* ========================================================================= */ + +#ifndef __SYNFIG_COLOR_COLOR_HPP +#define __SYNFIG_COLOR_COLOR_HPP + + +#include <synfig/string.h> +#include <synfig/angle.h> + + +#ifdef USING_PCH +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include "color.h" +#endif + +namespace synfig { + +Color& Color::operator+=(const Color &rhs) +{ + r_+=rhs.r_; + g_+=rhs.g_; + b_+=rhs.b_; + a_+=rhs.a_; + return *this; +} + +Color& Color::operator-=(const Color &rhs) +{ + r_-=rhs.r_; + g_-=rhs.g_; + b_-=rhs.b_; + a_-=rhs.a_; + return *this; +} + +Color& Color::operator*=(const float &rhs) +{ + r_*=rhs; + g_*=rhs; + b_*=rhs; + a_*=rhs; + return *this; +} + +Color& Color::operator/=(const float &rhs) +{ + const float temp(value_type(1)/rhs); + r_*=temp; + g_*=temp; + b_*=temp; + a_*=temp; + return *this; +} + +Color Color::operator+(const Color &rhs) const +{ + return Color(*this)+=rhs; +} + +Color Color::operator-(const Color &rhs) const +{ return Color(*this)-=rhs; } + +Color Color::operator*(const float &rhs)const +{ return Color(*this)*=rhs; } + +Color Color::operator/(const float &rhs)const +{ return Color(*this)/=rhs; } + +bool Color::operator<(const Color &rhs)const +{ + return r_<rhs.r_ ? true : rhs.r_<r_ ? false + : g_<rhs.g_ ? true : rhs.g_<g_ ? false + : b_<rhs.b_ ? true : rhs.b_<b_ ? false + : a_<rhs.a_; +} + +bool Color::operator==(const Color &rhs)const +{ return r_==rhs.r_ && g_==rhs.g_ && b_==rhs.b_ && a_==rhs.a_; } + +bool Color::operator!=(const Color &rhs)const +{ return r_!=rhs.r_ || g_!=rhs.g_ || b_!=rhs.b_ || a_!=rhs.a_; } + +Color Color::operator-()const +{ return Color(-r_,-g_,-b_,-a_); } + +//! Effectively 1.0-color +Color Color::operator~()const +{ return Color(1.0f-r_,1.0f-g_,1.0f-b_,a_); } + +bool Color::is_valid()const +{ return !std::isnan(r_) && !std::isnan(g_) && !std::isnan(b_) && !std::isnan(a_); } + +Color Color::premult_alpha() const +{ + return Color (r_*a_, g_*a_, b_*a_, a_); +} + +Color Color::demult_alpha() const +{ + if(a_) + { + const value_type inva = 1/a_; + return Color (r_*inva, g_*inva, b_*inva, a_); + }else return alpha(); +} + +Color::Color() :r_(0), g_(0), b_(0),a_(0) { } +Color::Color(const value_type &f) :r_(f), g_(f), b_(f),a_(f) { } +Color::Color(int f) :r_(f), g_(f), b_(f),a_(f) { } + +Color::Color(const value_type& R, + const value_type& G, + const value_type& B, + const value_type& A): + r_(R), + g_(G), + b_(B), + a_(A) { } + +Color::Color(const Color& c, const value_type& A): + r_(c.r_), + g_(c.g_), + b_(c.b_), + a_(A) { } + +const String Color::get_hex()const +{ + return String(real2hex(r_) + real2hex(g_) + real2hex(b_)); +} + + +//! Returns color's luminance +float Color::get_y() const +{ + return + (float)get_r()*EncodeYUV00+ + (float)get_g()*EncodeYUV01+ + (float)get_b()*EncodeYUV02; +} + + +//! Returns U component of chromanance +float Color::get_u() const +{ + return + (float)get_r()*EncodeYUV10+ + (float)get_g()*EncodeYUV11+ + (float)get_b()*EncodeYUV12; +} + + + //! Returns V component of chromanance +float Color::get_v() const +{ + return + (float)get_r()*EncodeYUV20+ + (float)get_g()*EncodeYUV21+ + (float)get_b()*EncodeYUV22; +} + +//! Returns the color's saturation +/*! This is is the magnitude of the U and V components. +** \see set_s() */ +float Color::get_s() const +{ + const float u(get_u()), v(get_v()); + return sqrt(u*u+v*v); +}
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.