CLAW Library (a C++ Library Absolutely Wonderful) 1.5.5
|
00001 /* 00002 CLAW - a C++ Library Absolutely Wonderful 00003 00004 CLAW is a free library without any particular aim but being useful to 00005 anyone. 00006 00007 Copyright (C) 2005-2010 Julien Jorge 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00022 00023 contact: julien_jorge@yahoo.fr 00024 */ 00030 #include <claw/pixel.hpp> 00031 00032 #include <limits> 00033 00034 namespace claw 00035 { 00036 namespace graphic 00037 { 00038 rgba_pixel transparent_pixel( 0, 0, 0, 0 ); 00039 00040 rgba_pixel black_pixel 00041 ( 0, 0, 0, std::numeric_limits<rgba_pixel::component_type>::max() ); 00042 rgba_pixel white_pixel 00043 ( std::numeric_limits<rgba_pixel::component_type>::max(), 00044 std::numeric_limits<rgba_pixel::component_type>::max(), 00045 std::numeric_limits<rgba_pixel::component_type>::max(), 00046 std::numeric_limits<rgba_pixel::component_type>::max() ); 00047 00048 rgba_pixel blue_pixel 00049 ( 0, 0, std::numeric_limits<rgba_pixel::component_type>::max(), 00050 std::numeric_limits<rgba_pixel::component_type>::max() ); 00051 rgba_pixel green_pixel 00052 ( 0, std::numeric_limits<rgba_pixel::component_type>::max(), 0, 00053 std::numeric_limits<rgba_pixel::component_type>::max() ); 00054 rgba_pixel red_pixel 00055 ( std::numeric_limits<rgba_pixel::component_type>::max(), 0, 0, 00056 std::numeric_limits<rgba_pixel::component_type>::max() ); 00057 00058 rgba_pixel yellow_pixel 00059 ( std::numeric_limits<rgba_pixel::component_type>::max(), 00060 std::numeric_limits<rgba_pixel::component_type>::max(), 0, 00061 std::numeric_limits<rgba_pixel::component_type>::max() ); 00062 rgba_pixel magenta_pixel 00063 ( std::numeric_limits<rgba_pixel::component_type>::max(), 0, 00064 std::numeric_limits<rgba_pixel::component_type>::max(), 00065 std::numeric_limits<rgba_pixel::component_type>::max() ); 00066 rgba_pixel cyan_pixel 00067 ( 0, std::numeric_limits<rgba_pixel::component_type>::max(), 00068 std::numeric_limits<rgba_pixel::component_type>::max(), 00069 std::numeric_limits<rgba_pixel::component_type>::max() ); 00070 00071 } // namespace graphic 00072 } // namespace claw 00073 00074 /*----------------------------------------------------------------------------*/ 00078 claw::graphic::rgb_pixel::rgb_pixel() 00079 { 00080 00081 } // rgb_pixel::rgb_pixel() 00082 00083 /*----------------------------------------------------------------------------*/ 00090 claw::graphic::rgb_pixel::rgb_pixel 00091 ( component_type r, component_type g, component_type b ) 00092 { 00093 components.red = r; 00094 components.green = g; 00095 components.blue = b; 00096 } // rgb_pixel::rgb_pixel() 00097 00098 /*----------------------------------------------------------------------------*/ 00103 claw::graphic::rgb_pixel::rgb_pixel( const rgba_pixel& p ) 00104 { 00105 components.red = p.components.red; 00106 components.green = p.components.green; 00107 components.blue = p.components.blue; 00108 } // rgb_pixel::rgb_pixel() 00109 00110 /*----------------------------------------------------------------------------*/ 00115 bool claw::graphic::rgb_pixel::operator==(const rgb_pixel& that) const 00116 { 00117 return (components.red == that.components.red) 00118 && (components.green == that.components.green) 00119 && (components.blue == that.components.blue); 00120 } // rgb_pixel::operator==() 00121 00122 /*----------------------------------------------------------------------------*/ 00127 bool claw::graphic::rgb_pixel::operator==(const rgba_pixel& that) const 00128 { 00129 return *this == rgb_pixel(that); 00130 } // rgb_pixel::operator==() 00131 00132 /*----------------------------------------------------------------------------*/ 00137 bool claw::graphic::rgb_pixel::operator!=(const rgb_pixel& that) const 00138 { 00139 return !(*this == that); 00140 } // rgb_pixel::operator!=() 00141 00142 /*----------------------------------------------------------------------------*/ 00147 bool claw::graphic::rgb_pixel::operator!=(const rgba_pixel& that) const 00148 { 00149 return !(*this == that); 00150 } // rgb_pixel::operator!=() 00151 00152 00153 00154 00155 /*----------------------------------------------------------------------------*/ 00159 claw::graphic::rgba_pixel::rgba_pixel() 00160 { 00161 00162 } // rgba_pixel::rgba_pixel() 00163 00164 /*----------------------------------------------------------------------------*/ 00170 claw::graphic::rgba_pixel::rgba_pixel( const rgb_pixel& that ) 00171 { 00172 components.red = that.components.red; 00173 components.green = that.components.green; 00174 components.blue = that.components.blue; 00175 components.alpha = 255; 00176 } // rgba_pixel::rgba_pixel() 00177 00178 /*----------------------------------------------------------------------------*/ 00186 claw::graphic::rgba_pixel::rgba_pixel 00187 ( component_type r, component_type g, component_type b, component_type a ) 00188 { 00189 components.red = r; 00190 components.green = g; 00191 components.blue = b; 00192 components.alpha = a; 00193 } // rgba_pixel::rgba_pixel() 00194 00195 /*----------------------------------------------------------------------------*/ 00201 claw::graphic::rgba_pixel& 00202 claw::graphic::rgba_pixel::operator=( const rgb_pixel& that ) 00203 { 00204 components.red = that.components.red; 00205 components.green = that.components.green; 00206 components.blue = that.components.blue; 00207 components.alpha = 255; 00208 00209 return *this; 00210 } // rgba_pixel::operator=() 00211 00212 /*----------------------------------------------------------------------------*/ 00217 bool claw::graphic::rgba_pixel::operator==( const rgba_pixel& that ) const 00218 { 00219 return pixel == that.pixel; 00220 } // rgba_pixel::operator==() 00221 00222 /*----------------------------------------------------------------------------*/ 00227 bool claw::graphic::rgba_pixel::operator!=( const rgba_pixel& that ) const 00228 { 00229 return pixel != that.pixel; 00230 } // rgba_pixel::operator!=() 00231 00232 /*----------------------------------------------------------------------------*/ 00242 claw::graphic::rgba_pixel::component_type 00243 claw::graphic::rgba_pixel::luminosity() const 00244 { 00245 return ((unsigned int)components.red * 183 00246 + (unsigned int)components.green * 54 00247 + (unsigned int)components.blue * 18 00248 ) / 256; 00249 } // rgba_pixel::luminosity()