pixelRGBA.h

Go to the documentation of this file.
00001 
00015 #ifndef _DLRCOMPUTERVISION_PIXELRGBA_H_
00016 #define _DLRCOMPUTERVISION_PIXELRGBA_H_
00017 
00018 #include <dlrCommon/types.h>
00019 
00020 namespace dlr {
00021 
00022   namespace computerVision {
00023     
00024     template<class TYPE>
00025     struct PixelRGBA
00026     {
00027     public:
00028 
00033       PixelRGBA()
00034         : red(), green(), blue(), alpha() {}
00035 
00036     
00048       PixelRGBA(const TYPE& red, const TYPE& green, const TYPE& blue,
00049                 const TYPE& alpha)
00050         : red(red), green(green), blue(blue), alpha(alpha) {}
00051 
00052 
00056       ~PixelRGBA() {}
00057 
00058     
00070       template<class Iter>
00071       inline Iter&
00072       copyFromIterator(Iter& iter);
00073 
00074 
00086       template<class Iter>
00087       inline Iter&
00088       copyToIterator(Iter& iter);
00089 
00090 
00091       /* ====== Public data members ====== */
00092 
00093       TYPE red;
00094       TYPE green;
00095       TYPE blue;
00096       TYPE alpha;
00097 
00098 
00099       /* ====== Static member functions ====== */
00100 
00109       static inline bool
00110       isContiguous();
00111 
00112     };
00113 
00114 
00115     typedef PixelRGBA<UnsignedInt8> PixelRGBA8;
00116     typedef PixelRGBA<UnsignedInt16> PixelRGBA16;
00117     typedef PixelRGBA<Int16> PixelRGBASigned16;
00118     typedef PixelRGBA<Int32> PixelRGBASigned32;
00119     typedef PixelRGBA<Float32> PixelRGBAFloat32;
00120     typedef PixelRGBA<Float64> PixelRGBAFloat64;
00121 
00122 
00137     template<class TYPE>
00138     inline PixelRGBA<TYPE>
00139     operator-(const PixelRGBA<TYPE>& pixel0, const PixelRGBA<TYPE>& pixel1);
00140 
00141   
00153     template<class TYPE>
00154     inline bool
00155     operator==(const PixelRGBA<TYPE>& pixel0, const PixelRGBA<TYPE>& pixel1);
00156 
00157   } // namespace computerVision    
00158 
00159 } // namespace dlr
00160   
00161 /* ============ Definitions of inline & template functions ============ */
00162 
00163 
00164 namespace dlr {
00165 
00166   namespace computerVision {
00167     
00168     // This member function copies the pixel component values, in
00169     // order, from consecutive iterator targets, incrementing the
00170     // iterator after each copy.
00171     template<class TYPE>
00172     template<class Iter>
00173     inline Iter&
00174     PixelRGBA<TYPE>::
00175     copyFromIterator(Iter& iter)
00176     {
00177       red = *(iter++);
00178       green = *(iter++);
00179       blue = *(iter++);
00180       alpha = *(iter++);
00181       return iter;
00182     }
00183 
00184 
00185     // This member function assigns the pixel component values, in
00186     // order, to consecutive iterator targets, incrementing the
00187     // iterator after each assignment.
00188     template<class TYPE>
00189     template<class Iter>
00190     inline Iter&
00191     PixelRGBA<TYPE>::
00192     copyToIterator(Iter& iter)
00193     {
00194       *(iter++) = red;
00195       *(iter++) = green;
00196       *(iter++) = blue;
00197       *(iter++) = alpha;
00198       return iter;
00199     }
00200 
00201 
00202     // This static member function indicates whether or not a pixel
00203     // instance is memory identical to a contiguous array of Component
00204     // type.
00205     template<class TYPE>
00206     inline bool
00207     PixelRGBA<TYPE>::
00208     isContiguous()
00209     {
00210       TYPE dummy;
00211       TYPE* typePtr = &dummy;
00212       PixelRGBA<TYPE>* pixelPtr = reinterpret_cast<PixelRGBA<TYPE>*>(typePtr);
00213       PixelRGBA<TYPE>* pixelPtr2 = pixelPtr + 1;
00214       return
00215         ((reinterpret_cast<TYPE*>(&(pixelPtr2->red)) == &(typePtr[4]))
00216          && (reinterpret_cast<TYPE*>(&(pixelPtr2->green)) == &(typePtr[5]))
00217          && (reinterpret_cast<TYPE*>(&(pixelPtr2->blue)) == &(typePtr[6]))
00218          && (reinterpret_cast<TYPE*>(&(pixelPtr2->alpha)) == &(typePtr[7])));
00219     }
00220 
00221 
00222     // This operator subtracts the values of the individual color
00223     // components of its arguments.
00224     template<class TYPE>
00225     inline PixelRGBA<TYPE>
00226     operator-(const PixelRGBA<TYPE>& pixel0, const PixelRGBA<TYPE>& pixel1)
00227     {
00228       return PixelRGBA<TYPE>(
00229         pixel0.red - pixel1.red,
00230         pixel0.green - pixel1.green,
00231         pixel0.blue - pixel1.blue,
00232         pixel0.alpha - pixel1.alpha);
00233     }
00234 
00235 
00236     // This operator returns true if the contents of the two argments
00237     // are identical, false otherwise.
00238     template<class TYPE>
00239     inline bool
00240     operator==(const PixelRGBA<TYPE>& pixel0, const PixelRGBA<TYPE>& pixel1)
00241     {
00242       return (pixel0.red == pixel1.red
00243               && pixel0.green == pixel1.green
00244               && pixel0.blue == pixel1.blue
00245               && pixel0.alpha == pixel1.alpha);
00246     }
00247 
00248   } // namespace computerVision    
00249 
00250 } // namespace dlr
00251 
00252 #endif /* #ifndef _DLRCOMPUTERVISION_PIXELRGBA_H_ */

Generated on Wed Nov 25 12:15:05 2009 for dlrComputerVision Utility Library by  doxygen 1.5.8