00001
00015 #ifndef _DLRCOMPUTERVISION_PIXELRGB_H_
00016 #define _DLRCOMPUTERVISION_PIXELRGB_H_
00017
00018 #include <dlrCommon/types.h>
00019
00020 namespace dlr {
00021
00022 namespace computerVision {
00023
00024 template<class TYPE>
00025 struct PixelRGB
00026 {
00031 PixelRGB()
00032 : red(), green(), blue() {}
00033
00034
00044 PixelRGB(const TYPE& red, const TYPE& green, const TYPE& blue)
00045 : red(red), green(green), blue(blue) {}
00046
00047
00051 ~PixelRGB() {}
00052
00053
00065 template<class Iter>
00066 inline Iter&
00067 copyFromIterator(Iter& iter);
00068
00069
00081 template<class Iter>
00082 inline Iter&
00083 copyToIterator(Iter& iter);
00084
00085
00086
00087
00088 TYPE red;
00089 TYPE green;
00090 TYPE blue;
00091
00092
00093
00094
00103 static inline bool
00104 isContiguous();
00105
00106 };
00107
00108
00109 typedef PixelRGB<UnsignedInt8> PixelRGB8;
00110 typedef PixelRGB<UnsignedInt16> PixelRGB16;
00111 typedef PixelRGB<Int16> PixelRGBSigned16;
00112 typedef PixelRGB<Int32> PixelRGBSigned32;
00113 typedef PixelRGB<Float32> PixelRGBFloat32;
00114 typedef PixelRGB<Float64> PixelRGBFloat64;
00115
00116
00131 template<class TYPE>
00132 inline PixelRGB<TYPE>
00133 operator-(const PixelRGB<TYPE>& pixel0, const PixelRGB<TYPE>& pixel1);
00134
00135
00147 template<class TYPE>
00148 inline bool
00149 operator==(const PixelRGB<TYPE>& pixel0, const PixelRGB<TYPE>& pixel1);
00150
00151 }
00152
00153 }
00154
00155
00156
00157
00158 namespace dlr {
00159
00160 namespace computerVision {
00161
00162
00163
00164
00165 template<class TYPE>
00166 template<class Iter>
00167 inline Iter&
00168 PixelRGB<TYPE>::
00169 copyFromIterator(Iter& iter)
00170 {
00171 red = *(iter++);
00172 green = *(iter++);
00173 blue = *(iter++);
00174 return iter;
00175 }
00176
00177
00178
00179
00180
00181 template<class TYPE>
00182 template<class Iter>
00183 inline Iter&
00184 PixelRGB<TYPE>::
00185 copyToIterator(Iter& iter)
00186 {
00187 *(iter++) = red;
00188 *(iter++) = green;
00189 *(iter++) = blue;
00190 return iter;
00191 }
00192
00193
00194
00195
00196
00197 template<class TYPE>
00198 inline bool
00199 PixelRGB<TYPE>::
00200 isContiguous()
00201 {
00202 TYPE dummy;
00203 TYPE* typePtr = &dummy;
00204 PixelRGB<TYPE>* pixelPtr = reinterpret_cast<PixelRGB<TYPE>*>(typePtr);
00205 PixelRGB<TYPE>* pixelPtr2 = pixelPtr + 1;
00206 return
00207 ((reinterpret_cast<TYPE*>(&(pixelPtr2->red)) == &(typePtr[3]))
00208 && (reinterpret_cast<TYPE*>(&(pixelPtr2->green)) == &(typePtr[4]))
00209 && (reinterpret_cast<TYPE*>(&(pixelPtr2->blue)) == &(typePtr[5])));
00210 }
00211
00212
00213
00214
00215 template<class TYPE>
00216 inline PixelRGB<TYPE>
00217 operator-(const PixelRGB<TYPE>& pixel0, const PixelRGB<TYPE>& pixel1)
00218 {
00219 return PixelRGB<TYPE>(
00220 pixel0.red - pixel1.red,
00221 pixel0.green - pixel1.green,
00222 pixel0.blue - pixel1.blue);
00223 }
00224
00225
00226
00227
00228 template<class TYPE>
00229 inline bool
00230 operator==(const PixelRGB<TYPE>& pixel0, const PixelRGB<TYPE>& pixel1)
00231 {
00232 return (pixel0.red == pixel1.red
00233 && pixel0.green == pixel1.green
00234 && pixel0.blue == pixel1.blue);
00235 }
00236
00237 }
00238
00239 }
00240
00241 #endif