Path: blob/master/libmupen64plus/mupen64plus-video-rice/src/IColor.h
2 views
/*1Copyright (C) 2003 Rice196423This program is free software; you can redistribute it and/or4modify it under the terms of the GNU General Public License5as published by the Free Software Foundation; either version 26of the License, or (at your option) any later version.78This program is distributed in the hope that it will be useful,9but WITHOUT ANY WARRANTY; without even the implied warranty of10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11GNU General Public License for more details.1213You should have received a copy of the GNU General Public License14along with this program; if not, write to the Free Software15Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.1617*/1819#ifndef _ICOLOR_H_20#define _ICOLOR_H_2122#ifndef min23#define min(a,b) ((a) < (b) ? (a) : (b))24#endif25#ifndef max26#define max(a,b) ((a) > (b) ? (a) : (b))27#endif2829class IColor {30public:31uint8 r;32uint8 g;33uint8 b;34uint8 a;3536IColor(COLOR rgba)37{38*((COLOR*)this) = rgba;39}4041IColor()42{43*((COLOR*)this) = 0;44}4546IColor(XCOLOR &rgba)47{48*((COLOR*)this) = (unsigned int) rgba;49}5051inline IColor operator = (const IColor &sec) const52{53*((COLOR*)this) = *((COLOR*)&sec);54return *this;55}5657inline IColor operator = (COLOR col) const58{59*((COLOR*)this) = col;60return *this;61}6263inline IColor operator + (const IColor &sec) const64{65IColor newc;66newc.r = (uint8)min((unsigned int) r + (unsigned int) sec.r, 0xFF);67newc.g = (uint8)min((unsigned int) g + (unsigned int) sec.g, 0xFF);68newc.b = (uint8)min((unsigned int) b + (unsigned int) sec.b, 0xFF);69newc.a = (uint8)min((unsigned int) a + (unsigned int) sec.a, 0xFF);7071return newc;72}7374inline IColor operator - (const IColor &sec) const75{76IColor newc;77newc.r = max(int(r)-int(sec.r),0);78newc.g = max(int(g)-int(sec.g),0);79newc.b = max(int(b)-int(sec.b),0);80newc.a = max(int(a)-int(sec.a),0);8182return newc;83}84inline IColor operator * (const IColor &sec) const85{86IColor newc;87newc.r = (uint8)min((unsigned int) r * (unsigned int) sec.r / 256,255);88newc.g = (uint8)min((unsigned int) g * (unsigned int) sec.g / 256,255);89newc.b = (uint8)min((unsigned int) b * (unsigned int) sec.b / 256,255);90newc.a = (uint8)min((unsigned int) a * (unsigned int) sec.a / 256,255);91return newc;92}9394inline IColor& operator += (const IColor &sec)95{96r = uint8(min((unsigned int) r + (unsigned int) sec.r, 255));97g = uint8(min((unsigned int) g + (unsigned int) sec.g, 255));98b = uint8(min((unsigned int) b + (unsigned int) sec.b, 255));99a = uint8(min((unsigned int) a + (unsigned int) sec.a, 255));100return *this;101}102103inline IColor& operator -= (const IColor &sec)104{105r = uint8(max(int(r)-int(sec.r),0));106g = uint8(max(int(g)-int(sec.g),0));107b = uint8(max(int(b)-int(sec.b),0));108a = uint8(max(int(a)-int(sec.a),0));109return *this;110}111112inline IColor& operator *= (const IColor &sec)113{114r = uint8(min((unsigned int) r * (unsigned int) sec.r / 256,255));115g = uint8(min((unsigned int) g * (unsigned int) sec.g / 256,255));116b = uint8(min((unsigned int) b * (unsigned int) sec.b / 256,255));117a = uint8(min((unsigned int) a * (unsigned int) sec.a / 256,255));118return *this;119}120121inline IColor& operator += (XCOLOR val)122{123IColor newc(val);124return this->operator += (newc);125}126127inline IColor& operator -= (XCOLOR val)128{129IColor newc(val);130return this->operator-=(newc);131}132133inline IColor& operator *= (XCOLOR val)134{135IColor newc(val);136return this->operator*=(newc);137}138139inline IColor operator + (XCOLOR val) const140{141IColor newc(val);142return this->operator+(newc);143}144145inline IColor operator - (XCOLOR val) const146{147IColor newc(val);148return this->operator-(newc);149}150151inline IColor operator * (XCOLOR val) const152{153IColor newc(val);154return this->operator*(newc);155}156157inline operator COLOR() const158{159return *((COLOR*)this);160}161162inline operator XCOLOR() const163{164XCOLOR rgba;165rgba.r = (float)r/256.0f;166rgba.g = (float)g/256.0f;167rgba.b = (float)b/256.0f;168rgba.a = (float)a/256.0f;169170return rgba;171}172173inline void Complement()174{175r = 0xFF-r;176g = 0xFF-g;177b = 0xFF-b;178a = 0xFF-a;179}180181inline void AlphaReplicate()182{183r=g=b=a;184}185};186187188#endif189190191192193