/* Copyright 2004, 2005 Nicholas Bishop * * This file is part of SharpConstruct. * * SharpConstruct 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. * * SharpConstruct 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 SharpConstruct; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "Color.h" using namespace SharpConstruct; Color::Color() : Red( 1 ), Green( 1 ), Blue( 1 ) {} Color::Color( float r, float g, float b ) : Red( r ), Green( g ), Blue( b ) {} Color::~Color() {} bool Color::IsGrey() const { return Red == Green && Green == Blue; } void Color::SetToBlack() { Red = 0; Green = 0; Blue = 0; } Color Color::operator+( const Color& c ) const { return Color( Red + c.Red, Green + c.Green, Blue + c.Blue ); } Color Color::operator+( const float c ) const { return Color( Red + c, Green + c, Blue + c ); } Color Color::operator-( const Color& c ) const { return Color( Red - c.Red, Green - c.Green, Blue - c.Blue ); } Color Color::operator-( const float c ) const { return Color( Red - c, Green - c, Blue - c ); } Color Color::operator*( const float c ) const { return Color( Red * c, Green * c, Blue * c ); } void Color::operator+=( const Color& c ) { Red += c.Red; Green += c.Green; Blue += c.Blue; } void Color::operator/=( const int d ) { Red /= d; Green /= d; Blue /= d; } Color SharpConstruct::MixColors( const Color& c1, const Color& c2 ) { Color r; r.Red = ( c1.Red + c2.Red ) / 2; r.Green = ( c1.Green + c2.Green ) / 2; r.Blue = ( c1.Blue + c2.Blue ) / 2; return r; } Color SharpConstruct::MixColors( const Color& c1, const Color& c2, const Color& c3 ) { Color r; r.Red = ( c1.Red + c2.Red + c3.Red ) / 3; r.Green = ( c1.Green + c2.Green + c3.Green ) / 3; r.Blue = ( c1.Blue + c2.Blue + c3.Blue ) / 3; return r; } Color SharpConstruct::MixColors( const Color& c1, const Color& c2, const Color& c3, const Color& c4 ) { Color r; r.Red = ( c1.Red + c2.Red + c3.Red + c4.Red ) / 4; r.Green = ( c1.Green + c2.Green + c3.Green + c4.Green ) / 4; r.Blue = ( c1.Blue + c2.Blue + c3.Blue + c4.Blue ) / 4; return r; }