col4.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // ======================================================================== //
  2. // Copyright 2009-2017 Intel Corporation //
  3. // //
  4. // Licensed under the Apache License, Version 2.0 (the "License"); //
  5. // you may not use this file except in compliance with the License. //
  6. // You may obtain a copy of the License at //
  7. // //
  8. // http://www.apache.org/licenses/LICENSE-2.0 //
  9. // //
  10. // Unless required by applicable law or agreed to in writing, software //
  11. // distributed under the License is distributed on an "AS IS" BASIS, //
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
  13. // See the License for the specific language governing permissions and //
  14. // limitations under the License. //
  15. // ======================================================================== //
  16. #pragma once
  17. #include "math.h"
  18. namespace embree
  19. {
  20. ////////////////////////////////////////////////////////////////////////////////
  21. /// RGBA Color Class
  22. ////////////////////////////////////////////////////////////////////////////////
  23. template<typename T> struct Col4
  24. {
  25. T r, g, b, a;
  26. ////////////////////////////////////////////////////////////////////////////////
  27. /// Construction
  28. ////////////////////////////////////////////////////////////////////////////////
  29. __forceinline Col4 ( ) { }
  30. __forceinline Col4 ( const Col4& other ) { r = other.r; g = other.g; b = other.b; a = other.a; }
  31. __forceinline Col4& operator=( const Col4& other ) { r = other.r; g = other.g; b = other.b; a = other.a; return *this; }
  32. __forceinline explicit Col4 (const T& v) : r(v), g(v), b(v), a(v) {}
  33. __forceinline Col4 (const T& r, const T& g, const T& b, const T& a) : r(r), g(g), b(b), a(a) {}
  34. ////////////////////////////////////////////////////////////////////////////////
  35. /// Constants
  36. ////////////////////////////////////////////////////////////////////////////////
  37. __forceinline Col4 (ZeroTy) : r(zero) , g(zero) , b(zero) , a(zero) {}
  38. __forceinline Col4 (OneTy) : r(one) , g(one) , b(one) , a(one) {}
  39. __forceinline Col4 (PosInfTy) : r(pos_inf), g(pos_inf), b(pos_inf), a(pos_inf) {}
  40. __forceinline Col4 (NegInfTy) : r(neg_inf), g(neg_inf), b(neg_inf), a(neg_inf) {}
  41. };
  42. /*! output operator */
  43. template<typename T> inline std::ostream& operator<<(std::ostream& cout, const Col4<T>& a) {
  44. return cout << "(" << a.r << ", " << a.g << ", " << a.b << ", " << a.a << ")";
  45. }
  46. /*! default template instantiations */
  47. typedef Col4<unsigned char> Col4uc;
  48. typedef Col4<float > Col4f;
  49. }