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-2008 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 #ifndef __CLAW_PIXEL_HPP_ 00031 #define __CLAW_PIXEL_HPP_ 00032 00033 namespace claw 00034 { 00035 namespace graphic 00036 { 00040 struct pixel24 00041 { 00042 typedef unsigned char component_type; 00043 00045 struct 00046 { 00048 component_type red; 00049 00051 component_type green; 00052 00054 component_type blue; 00055 00056 } components; 00057 00058 public: 00060 pixel24() {} 00061 00068 pixel24( component_type r, component_type g, component_type b ) 00069 { 00070 components.red = r; 00071 components.green = g; 00072 components.blue = b; 00073 } // pixel24() 00074 00075 }; // struct pixel24 00076 00080 union pixel32 00081 { 00082 typedef unsigned char component_type; 00083 00085 unsigned int pixel; 00086 00088 struct 00089 { 00091 component_type red; 00092 00094 component_type green; 00095 00097 component_type blue; 00098 00100 component_type alpha; 00101 00102 } components; 00103 00104 public: 00106 pixel32() {} 00107 00115 pixel32( component_type r, component_type g, component_type b, 00116 component_type a ) 00117 { 00118 components.red = r; 00119 components.green = g; 00120 components.blue = b; 00121 components.alpha = a; 00122 } // pixel32() 00123 00129 pixel32& operator=( const pixel24& that ) 00130 { 00131 components.red = that.components.red; 00132 components.green = that.components.green; 00133 components.blue = that.components.blue; 00134 components.alpha = 255; 00135 00136 return *this; 00137 } // operator=() 00138 00143 bool operator==( const pixel32& that ) const 00144 { 00145 return pixel == that.pixel; 00146 } // operator==() 00147 00152 bool operator!=( const pixel32& that ) const 00153 { 00154 return pixel != that.pixel; 00155 } // operator!=() 00156 00166 component_type luminosity() const 00167 { 00168 return ((unsigned int)components.red * 183 00169 + (unsigned int)components.green * 54 00170 + (unsigned int)components.blue * 18 00171 ) / 256; 00172 } // luminosity() 00173 00174 }; 00175 } // namespace graphic 00176 } // namespace claw 00177 00178 #endif // __CLAW_PIXEL_HPP__