fltPackedColor.I 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file fltPackedColor.I
  10. * @author drose
  11. * @date 2000-08-25
  12. */
  13. INLINE std::ostream &
  14. operator << (std::ostream &out, const FltPackedColor &color) {
  15. color.output(out);
  16. return out;
  17. }
  18. /**
  19. *
  20. */
  21. INLINE FltPackedColor::
  22. FltPackedColor() {
  23. _a = 0;
  24. _b = 0;
  25. _g = 0;
  26. _r = 0;
  27. }
  28. /**
  29. * Returns the four-component color as a LColor, where each component is in
  30. * the range [0, 1].
  31. */
  32. INLINE LColor FltPackedColor::
  33. get_color() const {
  34. return LColor(_r / 255.0, _g / 255.0, _b / 255.0, _a / 255.0);
  35. }
  36. /**
  37. * Returns the three-component color as an LRGBColor (ignoring the alpha
  38. * component), where each component is in the range [0, 1].
  39. */
  40. INLINE LRGBColor FltPackedColor::
  41. get_rgb() const {
  42. return LRGBColor(_r / 255.0, _g / 255.0, _b / 255.0);
  43. }
  44. /**
  45. * Sets the color according to the indicated four-component LColor value
  46. * (including alpha).
  47. */
  48. INLINE void FltPackedColor::
  49. set_color(const LColor &color) {
  50. _r = (int)floor(color[0] * 255.0);
  51. _g = (int)floor(color[1] * 255.0);
  52. _b = (int)floor(color[2] * 255.0);
  53. _a = (int)floor(color[3] * 255.0);
  54. }
  55. /**
  56. * Sets the color according to the indicated three-component LRGBColor value,
  57. * and set the alpha to 1.0.
  58. */
  59. INLINE void FltPackedColor::
  60. set_rgb(const LRGBColor &color) {
  61. _r = (int)floor(color[0] * 255.0);
  62. _g = (int)floor(color[1] * 255.0);
  63. _b = (int)floor(color[2] * 255.0);
  64. _a = 255;
  65. }