pixel.cpp

Go to the documentation of this file.
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 #include <claw/pixel.hpp>
00031 
00032 #include <limits>
00033 
00034 namespace claw
00035 {
00036   namespace graphic
00037   {
00038     rgba_pixel black_pixel
00039     ( 0, 0, 0, std::numeric_limits<rgba_pixel::component_type>::max() );
00040     rgba_pixel white_pixel
00041     ( std::numeric_limits<rgba_pixel::component_type>::max(),
00042       std::numeric_limits<rgba_pixel::component_type>::max(),
00043       std::numeric_limits<rgba_pixel::component_type>::max(),
00044       std::numeric_limits<rgba_pixel::component_type>::max() );
00045 
00046     rgba_pixel blue_pixel
00047     ( 0, 0, std::numeric_limits<rgba_pixel::component_type>::max(),
00048       std::numeric_limits<rgba_pixel::component_type>::max() );
00049     rgba_pixel green_pixel
00050     ( 0, std::numeric_limits<rgba_pixel::component_type>::max(), 0,
00051       std::numeric_limits<rgba_pixel::component_type>::max() );
00052     rgba_pixel red_pixel
00053     ( std::numeric_limits<rgba_pixel::component_type>::max(), 0, 0,
00054       std::numeric_limits<rgba_pixel::component_type>::max() );
00055 
00056     rgba_pixel yellow_pixel
00057     ( 0, std::numeric_limits<rgba_pixel::component_type>::max(), 
00058       std::numeric_limits<rgba_pixel::component_type>::max(),
00059       std::numeric_limits<rgba_pixel::component_type>::max() );
00060     rgba_pixel magenta_pixel
00061     ( std::numeric_limits<rgba_pixel::component_type>::max(), 0,
00062       std::numeric_limits<rgba_pixel::component_type>::max(),
00063       std::numeric_limits<rgba_pixel::component_type>::max() );
00064     rgba_pixel cyan_pixel
00065     ( std::numeric_limits<rgba_pixel::component_type>::max(), 
00066       std::numeric_limits<rgba_pixel::component_type>::max(), 0,
00067       std::numeric_limits<rgba_pixel::component_type>::max() );
00068 
00069   } // namespace graphic
00070 } // namespace claw
00071 
00072 /*----------------------------------------------------------------------------*/
00076 claw::graphic::rgb_pixel::rgb_pixel()
00077 {
00078 
00079 } // rgb_pixel::rgb_pixel()
00080 
00081 /*----------------------------------------------------------------------------*/
00088 claw::graphic::rgb_pixel::rgb_pixel
00089 ( component_type r, component_type g, component_type b )
00090 { 
00091   components.red = r;
00092   components.green = g;
00093   components.blue = b;
00094 } // rgb_pixel::rgb_pixel()
00095 
00096 /*----------------------------------------------------------------------------*/
00101 claw::graphic::rgb_pixel::rgb_pixel( const rgba_pixel& p )
00102 { 
00103   components.red = p.components.red;
00104   components.green = p.components.green;
00105   components.blue = p.components.blue;
00106 } // rgb_pixel::rgb_pixel()
00107 
00108 /*----------------------------------------------------------------------------*/
00113 bool claw::graphic::rgb_pixel::operator==(const rgb_pixel& that) const
00114 { 
00115   return (components.red == that.components.red)
00116     && (components.green == that.components.green)
00117     && (components.blue == that.components.blue);
00118 } // rgb_pixel::operator==()
00119 
00120 /*----------------------------------------------------------------------------*/
00125 bool claw::graphic::rgb_pixel::operator==(const rgba_pixel& that) const
00126 { 
00127   return *this == rgb_pixel(that);
00128 } // rgb_pixel::operator==()
00129 
00130 /*----------------------------------------------------------------------------*/
00135 bool claw::graphic::rgb_pixel::operator!=(const rgb_pixel& that) const
00136 { 
00137   return !(*this == that);
00138 } // rgb_pixel::operator!=()
00139 
00140 /*----------------------------------------------------------------------------*/
00145 bool claw::graphic::rgb_pixel::operator!=(const rgba_pixel& that) const
00146 { 
00147   return !(*this == that);
00148 } // rgb_pixel::operator!=()
00149 
00150 
00151 
00152 
00153 /*----------------------------------------------------------------------------*/
00157 claw::graphic::rgba_pixel::rgba_pixel()
00158 {
00159 
00160 } // rgba_pixel::rgba_pixel()
00161 
00162 /*----------------------------------------------------------------------------*/
00170 claw::graphic::rgba_pixel::rgba_pixel
00171 ( component_type r, component_type g, component_type b, component_type a )
00172 { 
00173   components.red = r;
00174   components.green = g;
00175   components.blue = b;
00176   components.alpha = a;
00177 } // rgba_pixel::rgba_pixel()
00178 
00179 /*----------------------------------------------------------------------------*/
00185 claw::graphic::rgba_pixel&
00186 claw::graphic::rgba_pixel::operator=( const rgb_pixel& that )
00187 {
00188   components.red = that.components.red;
00189   components.green = that.components.green;
00190   components.blue = that.components.blue;
00191   components.alpha = 255;
00192 
00193   return *this;
00194 } // rgba_pixel::operator=()
00195 
00196 /*----------------------------------------------------------------------------*/
00201 bool claw::graphic::rgba_pixel::operator==( const rgba_pixel& that ) const
00202 {
00203   return pixel == that.pixel;
00204 } // rgba_pixel::operator==()
00205 
00206 /*----------------------------------------------------------------------------*/
00211 bool claw::graphic::rgba_pixel::operator!=( const rgba_pixel& that ) const
00212 {
00213   return pixel != that.pixel;
00214 } // rgba_pixel::operator!=()
00215 
00216 /*----------------------------------------------------------------------------*/
00226 claw::graphic::rgba_pixel::component_type
00227 claw::graphic::rgba_pixel::luminosity() const
00228 {
00229   return ((unsigned int)components.red * 183 
00230           + (unsigned int)components.green * 54 
00231           + (unsigned int)components.blue * 18
00232           ) / 256;
00233 } // rgba_pixel::luminosity()

Generated on 9 Nov 2009 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.6.1