00001
00015 #ifndef _DLRCOMPUTERVISION_PIXELRGB_H_
00016 #define _DLRCOMPUTERVISION_PIXELRGB_H_
00017
00018 #include <dlrCommon/typePromoter.h>
00019 #include <dlrCommon/types.h>
00020
00021 namespace dlr {
00022
00023 namespace computerVision {
00024
00025 template<class Type>
00026 struct PixelRGB
00027 {
00032 PixelRGB()
00033 : red(), green(), blue() {}
00034
00035
00045 PixelRGB(const Type& red, const Type& green, const Type& blue)
00046 : red(red), green(green), blue(blue) {}
00047
00048
00052 ~PixelRGB() {}
00053
00054
00066 template<class Iter>
00067 inline Iter&
00068 copyFromIterator(Iter& iter);
00069
00070
00082 template<class Iter>
00083 inline Iter&
00084 copyToIterator(Iter& iter);
00085
00086
00087
00088
00089 Type red;
00090 Type green;
00091 Type blue;
00092
00093
00094
00095
00105 template <class OtherType>
00106 inline PixelRGB<Type>&
00107 operator+=(const PixelRGB<OtherType>& other);
00108
00109
00119 template <class OtherType>
00120 inline PixelRGB<Type>&
00121 operator-=(const PixelRGB<OtherType>& other);
00122
00123
00133 template <class Scalar>
00134 inline PixelRGB<Type>&
00135 operator*=(const Scalar& scalar);
00136
00137
00147 template <class Scalar>
00148 inline PixelRGB<Type>&
00149 operator/=(const Scalar& scalar);
00150
00151
00152
00153
00162 static inline bool
00163 isContiguous();
00164
00165 };
00166
00167
00168 typedef PixelRGB<UnsignedInt8> PixelRGB8;
00169 typedef PixelRGB<UnsignedInt16> PixelRGB16;
00170 typedef PixelRGB<Int16> PixelRGBSigned16;
00171 typedef PixelRGB<Int32> PixelRGBSigned32;
00172 typedef PixelRGB<Float32> PixelRGBFloat32;
00173 typedef PixelRGB<Float64> PixelRGBFloat64;
00174
00175
00188 template<class Scalar, class Type>
00189 inline PixelRGB<
00190 typename dlr::common::TypePromoter<Scalar, Type>::ResultType>
00191 operator*(Scalar scalar, const PixelRGB<Type>& pixel1);
00192
00193
00208 template<class Type0, class Type1>
00209 inline PixelRGB<
00210 typename dlr::common::TypePromoter<Type0, Type1>::ResultType>
00211 operator+(const PixelRGB<Type0>& pixel0, const PixelRGB<Type1>& pixel1);
00212
00213
00228 template<class Type0, class Type1>
00229 inline PixelRGB<
00230 typename dlr::common::TypePromoter<Type0, Type1>::ResultType>
00231 operator-(const PixelRGB<Type0>& pixel0, const PixelRGB<Type1>& pixel1);
00232
00233
00248 template<class Type0, class Type1>
00249 inline PixelRGB<
00250 typename dlr::common::TypePromoter<Type0, Type1>::ResultType>
00251 operator*(const PixelRGB<Type0>& pixel0, const PixelRGB<Type1>& pixel1);
00252
00253
00268 template<class Type0, class Type1>
00269 inline PixelRGB<
00270 typename dlr::common::TypePromoter<Type0, Type1>::ResultType>
00271 operator/(const PixelRGB<Type0>& pixel0, const PixelRGB<Type1>& pixel1);
00272
00273
00285 template<class Type>
00286 inline bool
00287 operator==(const PixelRGB<Type>& pixel0, const PixelRGB<Type>& pixel1);
00288
00289 }
00290
00291 }
00292
00293
00294
00295
00296 namespace dlr {
00297
00298 namespace computerVision {
00299
00300
00301
00302
00303 template<class Type>
00304 template<class Iter>
00305 inline Iter&
00306 PixelRGB<Type>::
00307 copyFromIterator(Iter& iter)
00308 {
00309 red = *(iter++);
00310 green = *(iter++);
00311 blue = *(iter++);
00312 return iter;
00313 }
00314
00315
00316
00317
00318
00319 template<class Type>
00320 template<class Iter>
00321 inline Iter&
00322 PixelRGB<Type>::
00323 copyToIterator(Iter& iter)
00324 {
00325 *(iter++) = red;
00326 *(iter++) = green;
00327 *(iter++) = blue;
00328 return iter;
00329 }
00330
00331
00332
00333
00334
00335 template<class Type>
00336 template <class OtherType>
00337 inline PixelRGB<Type>&
00338 PixelRGB<Type>::
00339 operator+=(const PixelRGB<OtherType>& other)
00340 {
00341 red += other.red;
00342 green += other.green;
00343 blue += other.blue;
00344 return *this;
00345 }
00346
00347
00348
00349
00350 template<class Type>
00351 template <class OtherType>
00352 inline PixelRGB<Type>&
00353 PixelRGB<Type>::
00354 operator-=(const PixelRGB<OtherType>& other)
00355 {
00356 red -= other.red;
00357 green -= other.green;
00358 blue -= other.blue;
00359 return *this;
00360 }
00361
00362
00363
00364
00365 template<class Type>
00366 template <class Scalar>
00367 inline PixelRGB<Type>&
00368 PixelRGB<Type>::
00369 operator*=(const Scalar& scalar)
00370 {
00371 red *= scalar;
00372 green *= scalar;
00373 blue *= scalar;
00374 return *this;
00375 }
00376
00377
00378
00379
00380 template<class Type>
00381 template <class Scalar>
00382 inline PixelRGB<Type>&
00383 PixelRGB<Type>::
00384 operator/=(const Scalar& scalar)
00385 {
00386 red /= scalar;
00387 green /= scalar;
00388 blue /= scalar;
00389 return *this;
00390 }
00391
00392
00393
00394
00395
00396 template<class Type>
00397 inline bool
00398 PixelRGB<Type>::
00399 isContiguous()
00400 {
00401 Type dummy;
00402 Type* typePtr = &dummy;
00403 PixelRGB<Type>* pixelPtr = reinterpret_cast<PixelRGB<Type>*>(typePtr);
00404 PixelRGB<Type>* pixelPtr2 = pixelPtr + 1;
00405 return
00406 ((reinterpret_cast<Type*>(&(pixelPtr2->red)) == &(typePtr[3]))
00407 && (reinterpret_cast<Type*>(&(pixelPtr2->green)) == &(typePtr[4]))
00408 && (reinterpret_cast<Type*>(&(pixelPtr2->blue)) == &(typePtr[5])));
00409 }
00410
00411
00412
00413
00414 template<class Scalar, class Type>
00415 inline PixelRGB<
00416 typename dlr::common::TypePromoter<Scalar, Type>::ResultType>
00417 operator*(Scalar scalar, const PixelRGB<Type>& pixel1)
00418 {
00419 return PixelRGB<
00420 typename dlr::common::TypePromoter<Scalar, Type>::ResultType>(
00421 scalar * pixel1.red,
00422 scalar * pixel1.green,
00423 scalar * pixel1.blue);
00424 }
00425
00426
00427
00428
00429 template<class Type0, class Type1>
00430 inline PixelRGB<
00431 typename dlr::common::TypePromoter<Type0, Type1>::ResultType>
00432 operator+(const PixelRGB<Type0>& pixel0, const PixelRGB<Type1>& pixel1)
00433 {
00434 return PixelRGB<
00435 typename dlr::common::TypePromoter<Type0, Type1>::ResultType>(
00436 pixel0.red + pixel1.red,
00437 pixel0.green + pixel1.green,
00438 pixel0.blue + pixel1.blue);
00439 }
00440
00441
00442
00443
00444 template<class Type0, class Type1>
00445 inline PixelRGB<
00446 typename dlr::common::TypePromoter<Type0, Type1>::ResultType>
00447 operator-(const PixelRGB<Type0>& pixel0, const PixelRGB<Type1>& pixel1)
00448 {
00449 return PixelRGB<
00450 typename dlr::common::TypePromoter<Type0, Type1>::ResultType>(
00451 pixel0.red - pixel1.red,
00452 pixel0.green - pixel1.green,
00453 pixel0.blue - pixel1.blue);
00454 }
00455
00456
00457
00458
00459 template<class Type0, class Type1>
00460 inline PixelRGB<
00461 typename dlr::common::TypePromoter<Type0, Type1>::ResultType>
00462 operator*(const PixelRGB<Type0>& pixel0, const PixelRGB<Type1>& pixel1)
00463 {
00464 return PixelRGB<
00465 typename dlr::common::TypePromoter<Type0, Type1>::ResultType>(
00466 pixel0.red * pixel1.red,
00467 pixel0.green * pixel1.green,
00468 pixel0.blue * pixel1.blue);
00469 }
00470
00471
00472
00473
00474 template<class Type0, class Type1>
00475 inline PixelRGB<
00476 typename dlr::common::TypePromoter<Type0, Type1>::ResultType>
00477 operator/(const PixelRGB<Type0>& pixel0, const PixelRGB<Type1>& pixel1)
00478 {
00479 return PixelRGB<
00480 typename dlr::common::TypePromoter<Type0, Type1>::ResultType>(
00481 pixel0.red / pixel1.red,
00482 pixel0.green / pixel1.green,
00483 pixel0.blue / pixel1.blue);
00484 }
00485
00486
00487
00488
00489 template<class Type>
00490 inline bool
00491 operator==(const PixelRGB<Type>& pixel0, const PixelRGB<Type>& pixel1)
00492 {
00493 return (pixel0.red == pixel1.red
00494 && pixel0.green == pixel1.green
00495 && pixel0.blue == pixel1.blue);
00496 }
00497
00498 }
00499
00500 }
00501
00502 #endif