col4.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "math.h"
  5. namespace embree
  6. {
  7. ////////////////////////////////////////////////////////////////////////////////
  8. /// RGBA Color Class
  9. ////////////////////////////////////////////////////////////////////////////////
  10. template<typename T> struct Col4
  11. {
  12. T r, g, b, a;
  13. ////////////////////////////////////////////////////////////////////////////////
  14. /// Construction
  15. ////////////////////////////////////////////////////////////////////////////////
  16. __forceinline Col4 ( ) { }
  17. __forceinline Col4 ( const Col4& other ) { r = other.r; g = other.g; b = other.b; a = other.a; }
  18. __forceinline Col4& operator=( const Col4& other ) { r = other.r; g = other.g; b = other.b; a = other.a; return *this; }
  19. __forceinline explicit Col4 (const T& v) : r(v), g(v), b(v), a(v) {}
  20. __forceinline Col4 (const T& r, const T& g, const T& b, const T& a) : r(r), g(g), b(b), a(a) {}
  21. ////////////////////////////////////////////////////////////////////////////////
  22. /// Constants
  23. ////////////////////////////////////////////////////////////////////////////////
  24. __forceinline Col4 (ZeroTy) : r(zero) , g(zero) , b(zero) , a(zero) {}
  25. __forceinline Col4 (OneTy) : r(one) , g(one) , b(one) , a(one) {}
  26. __forceinline Col4 (PosInfTy) : r(pos_inf), g(pos_inf), b(pos_inf), a(pos_inf) {}
  27. __forceinline Col4 (NegInfTy) : r(neg_inf), g(neg_inf), b(neg_inf), a(neg_inf) {}
  28. };
  29. /*! output operator */
  30. template<typename T> __forceinline embree_ostream operator<<(embree_ostream cout, const Col4<T>& a) {
  31. return cout << "(" << a.r << ", " << a.g << ", " << a.b << ", " << a.a << ")";
  32. }
  33. /*! default template instantiations */
  34. typedef Col4<unsigned char> Col4uc;
  35. typedef Col4<float > Col4f;
  36. }