Pixel.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * NICE-Core - efficient algebra and computer vision methods
  3. * - libimage - An image/template for new NICE libraries
  4. * See file License for license information.
  5. */
  6. #ifndef _IMAGE_PIXEL_H
  7. #define _IMAGE_PIXEL_H
  8. //
  9. #include <vector>
  10. #include <numeric>
  11. #include <core/vector/VectorBase.h>
  12. #include <core/vector/VectorT.h>
  13. namespace NICE {
  14. //! Class for a color pixel
  15. template<class T>
  16. class Pixel : public VectorT<T>
  17. {
  18. public:
  19. //! Default constructor.
  20. Pixel();
  21. //! Constructor with gray value.
  22. /*!
  23. * \param gray gray value
  24. */
  25. Pixel(T gray);
  26. //! Constructor with r,g,b values.
  27. /*!
  28. * \param r red channel
  29. * \param g green channel
  30. * \param b blue channel
  31. */
  32. Pixel(T r, T g, T b);
  33. //! Constructor with array of values.
  34. /*!
  35. * \param color color value array
  36. * \param channels number of channels (default 3)
  37. * \param mode copy mode of the color spezified by \c color
  38. */
  39. Pixel(T *color, size_t channels=3,
  40. const VectorBase::Mode mode = VectorBase::copy);
  41. //! Destructor of Pixel.
  42. virtual ~Pixel(){}
  43. //! Access the first channel.
  44. /*!
  45. * \return the value of the first color channel
  46. */
  47. inline operator T() const;
  48. //! Return number of channels of this pixel.
  49. inline size_t channels() const { return this->size(); }
  50. //! Return gray value.
  51. inline T gray() const;
  52. // Return color array.
  53. inline const T *color() const;
  54. // Copy color array to \c buffer.
  55. inline void getColor(T *buffer) const;
  56. //! Create a black pixel
  57. static Pixel Black() { return Pixel(std::numeric_limits<T>::min()); }
  58. //! Create a white pixel
  59. static Pixel White() { return Pixel(std::numeric_limits<T>::max()); }
  60. //! Create a gray pixel
  61. static Pixel Gray() { return Pixel((std::numeric_limits<T>::max()+std::numeric_limits<T>::min()/static_cast<T>(2))); }
  62. //! Create a black RGB color pixel
  63. static Pixel RGB_Black() { return Pixel(std::numeric_limits<T>::min(),std::numeric_limits<T>::min(),std::numeric_limits<T>::min()); }
  64. //! Create a red RGB color pixel
  65. static Pixel RGB_Red() { return Pixel(std::numeric_limits<T>::max(),std::numeric_limits<T>::min(),std::numeric_limits<T>::min()); }
  66. //! Create a green RGB color pixel
  67. static Pixel RGB_Green() { return Pixel(std::numeric_limits<T>::min(),std::numeric_limits<T>::max(),std::numeric_limits<T>::min()); }
  68. //! Create a blue RGB color pixel
  69. static Pixel RGB_Blue() { return Pixel(std::numeric_limits<T>::min(),std::numeric_limits<T>::min(),std::numeric_limits<T>::max()); }
  70. //! Create a white RGB color pixel
  71. static Pixel RGB_White() { return Pixel(std::numeric_limits<T>::max(),std::numeric_limits<T>::max(),std::numeric_limits<T>::max()); }
  72. };
  73. }; // namespace NICE
  74. //#ifdef __GNUC__
  75. #include "core/image/Pixel.tcc"
  76. //#endif
  77. #endif // PIXEL_H