00001 #include "SdlArs.h"
00002
00003 namespace Ars
00004 {
00005 RGBColor::RGBColor(const Uint32* pColorValue, const SDL_PixelFormat* pFormat)
00006 {
00007 red = static_cast<unsigned char>((pFormat->Rmask & *pColorValue) >> pFormat->Rshift);
00008 green = static_cast<unsigned char>((pFormat->Gmask & *pColorValue) >> pFormat->Gshift);
00009 blue = static_cast<unsigned char>((pFormat->Bmask & *pColorValue) >> pFormat->Bshift);
00010 alpha = static_cast<unsigned char>((pFormat->Amask & *pColorValue) >> pFormat->Ashift);
00011 }
00012
00013
00014 RGBColor& RGBColor::operator=(const RGBColor& c)
00015 {
00016 red = c.red;
00017 green = c.green;
00018 blue = c.blue;
00019 alpha = c.alpha;
00020 return *this;
00021 }
00022
00023
00024 RGBColor RGBColor::operator+(const RGBColor& c) const
00025 {
00026 double fg_ratio = static_cast<double>(c.alpha) / 0xFF;
00027 double bg_ratio = static_cast<double>(0xFF - c.alpha) / 0xFF;
00028 unsigned char new_red = static_cast<unsigned char>(red * bg_ratio + c.red * fg_ratio);
00029 unsigned char new_green = static_cast<unsigned char>(green * bg_ratio + c.green * fg_ratio);
00030 unsigned char new_blue = static_cast<unsigned char>(blue * bg_ratio + c.blue * fg_ratio);
00031 return RGBColor(new_red, new_green, new_blue, alpha);
00032 }
00033
00034
00035 RGBColor RGBColor::operator|(const RGBColor& c) const
00036 {
00037 return RGBColor(red | c.red, green | c.green, blue | c.blue, alpha | c.alpha);
00038 }
00039
00040
00041 RGBColor RGBColor::operator&(const RGBColor& c) const
00042 {
00043 return RGBColor(red & c.red, green & c.green, blue & c.blue, alpha & c.alpha);
00044 }
00045
00046
00047 RGBColor RGBColor::operator^(const RGBColor& c) const
00048 {
00049 return RGBColor(red ^ c.red, green ^ c.green, blue ^ c.blue, alpha ^ c.alpha);
00050 }
00051
00052 RGBColor RGBColor::FadeColor( const int factor ) const
00053 {
00054 return RGBColor( max( 0 , min( 0xff , red + factor ) ) , max( 0 , min( 0xff , green + factor ) ) , max( 0 , min( 0xff , blue + factor ) ) );
00055 }
00056
00057 }
00058