Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

PixelRGB.h

Go to the documentation of this file.
00001 /*************************************************************************
00008  *
00009  * Source code for Real Time Image Library (libRTImage) 
00010  *
00011  * Leeds Vision Group give permission for this code to be copied, modified 
00012  * and distributed within the University of Leeds subject to the following
00013  * conditions:-
00014  *
00015  * - The code is not to be used for commercial gain.
00016  * - The code and use thereof will be attributed to the authors where
00017  *   appropriate (including demonstrations which rely on it's use).
00018  * - All modified, distributions of the source files will retain this header.
00019  *
00020  ****************************************************************************/
00021 
00022 #ifndef PIXEL_RGB_H
00023 #define PIXEL_RGB_H
00024 
00025 #include <iostream>
00026 
00027 using namespace std;
00028 
00029 class PixelRGB
00037 {
00050         friend ostream& operator << (ostream& os, PixelRGB& p)
00051         {
00052                 os << "(" << p[0] << "," << p[1] << "," << p[2] << ")";
00053                 return os;
00054         }
00055                 
00056 protected:
00057         int pixel[3];   
00058 
00059         
00060 public:
00066         PixelRGB()
00067          { pixel[0] = pixel[1] = pixel[2] = 0; }
00068         
00069 
00076         PixelRGB(int red, int green, int blue)
00077         {
00078                 pixel[0] = red;
00079                 pixel[1] = green;
00080                 pixel[2] = blue;
00081         }
00082 
00083         
00094         PixelRGB& operator = (PixelRGB& p) 
00095         {
00096                 pixel[0] = p[0];
00097                 pixel[1] = p[1];
00098                 pixel[2] = p[2];
00099 
00100                 return *this;
00101         }
00102 
00103         
00114         int& operator [] (int i) 
00115         {
00116                 return pixel[i];
00117         }
00118 
00119 
00127         operator int* ()
00128         {
00129                 return (int*) pixel;
00130         }
00131 
00132         
00144         bool operator == (PixelRGB& p)
00145         {
00146                 return (   pixel[0] == p.pixel[0]
00147                         && pixel[1] == p.pixel[1]
00148                         && pixel[2] == p.pixel[2]);
00149         }
00150 
00151         
00164         bool operator != (PixelRGB& p)
00165         {
00166                 return (   pixel[0] != p.pixel[0]
00167                         || pixel[1] != p.pixel[1]
00168                         || pixel[2] != p.pixel[2]);
00169         }
00170 
00182         PixelRGB& operator += (PixelRGB& p)
00183         {
00184                 pixel[0] += p[0];
00185                 pixel[1] += p[1];
00186                 pixel[2] += p[2];
00187 
00188                 return *this;
00189         }                          
00190               
00201         PixelRGB& operator -= (PixelRGB& p)
00202         {
00203                 if((pixel[0] -= p[0]) < 0) pixel[0] = -pixel[0];
00204                 if((pixel[1] -= p[1]) < 1) pixel[1] = -pixel[1];
00205                 if((pixel[2] -= p[2]) < 2) pixel[2] = -pixel[2];
00206 
00207                 return *this;
00208         }                           
00209 
00219         PixelRGB& operator *= (double k) 
00220         {
00221                 pixel[0] = (int) (k*(double)pixel[0]);
00222                 pixel[1] = (int) (k*(double)pixel[1]);
00223                 pixel[2] = (int) (k*(double)pixel[2]);
00224 
00225                 return *this;
00226         }                             
00227 
00228 };
00229 
00230 
00231 #endif  // PIXEL_RGB_H

Generated at Fri Aug 13 17:29:21 2004 for libRTImage by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001