Pixel.tcc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #include "core/image/Pixel.h"
  7. #ifdef NICE_USELIB_FBASICS
  8. #include "core/basics/Exception.h"
  9. #else
  10. #include <exception>
  11. #endif
  12. namespace NICE {
  13. // Constructors:
  14. // -------------
  15. template<class T>
  16. Pixel<T>::Pixel():VectorT<T>()
  17. {
  18. }
  19. template<class T>
  20. Pixel<T>::Pixel(T gray):VectorT<T>(1, gray)
  21. {
  22. }
  23. template<class T>
  24. Pixel<T>::Pixel(T *color,size_t nochannels, const VectorBase::Mode mode):VectorT<T>(color,nochannels, mode)
  25. {
  26. }
  27. template<class T>
  28. Pixel<T>::Pixel(T r, T g, T b):VectorT<T>(3)
  29. {
  30. this->data[0] = r;
  31. this->data[1] = g;
  32. this->data[2] = b;
  33. }
  34. template<class T>
  35. Pixel<T>::operator T() const
  36. {
  37. if(this->size()==0)
  38. return 0;
  39. else
  40. return this->constData[0];
  41. }
  42. template<class T>
  43. T Pixel<T>::gray() const
  44. {
  45. if(this->size()==1) {
  46. return this->constData[0];
  47. } else if(this->size()==0) {
  48. throw std::range_error("invalid channel number");
  49. } else if(this->size()==3) {
  50. throw std::range_error("not implemented yet");
  51. } else {
  52. throw std::range_error("invalid channel number");
  53. }
  54. }
  55. template<class T>
  56. const T* Pixel<T>::color() const
  57. {
  58. return this->constData;
  59. }
  60. template<class T>
  61. void Pixel<T>::getColor(T *buffer) const
  62. {
  63. ippsCopy(this->constData, buffer, this->size());
  64. }
  65. }; // namespace NICE