Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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 }
00072 }
00073
00074
00078 claw::graphic::rgb_pixel::rgb_pixel()
00079 {
00080
00081 }
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 }
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 }
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 }
00121
00122
00127 bool claw::graphic::rgb_pixel::operator==(const rgba_pixel& that) const
00128 {
00129 return *this == rgb_pixel(that);
00130 }
00131
00132
00137 bool claw::graphic::rgb_pixel::operator!=(const rgb_pixel& that) const
00138 {
00139 return !(*this == that);
00140 }
00141
00142
00147 bool claw::graphic::rgb_pixel::operator!=(const rgba_pixel& that) const
00148 {
00149 return !(*this == that);
00150 }
00151
00152
00153
00154
00155
00159 claw::graphic::rgba_pixel::rgba_pixel()
00160 {
00161
00162 }
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 }
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 }
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 }
00211
00212
00217 bool claw::graphic::rgba_pixel::operator==( const rgba_pixel& that ) const
00218 {
00219 return pixel == that.pixel;
00220 }
00221
00222
00227 bool claw::graphic::rgba_pixel::operator!=( const rgba_pixel& that ) const
00228 {
00229 return pixel != that.pixel;
00230 }
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 }