RgbTransform.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #pragma once
  2. // STL includes
  3. #include <cstdint>
  4. ///
  5. /// Color transformation to adjust the saturation and value of a RGB color value
  6. ///
  7. class RgbTransform
  8. {
  9. public:
  10. ///
  11. /// Default constructor
  12. ///
  13. RgbTransform();
  14. ///
  15. /// Constructor
  16. ///
  17. /// @param gammaR The used red gamma
  18. /// @param gammaG The used green gamma
  19. /// @param gammab The used blue gamma
  20. /// @param backlightThreshold The used lower brightness
  21. /// @param backlightColored use color in backlight
  22. /// @param brightnessHigh The used higher brightness
  23. ///
  24. RgbTransform(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation);
  25. /// @return The current red gamma value
  26. double getGammaR() const;
  27. /// @return The current green gamma value
  28. double getGammaG() const;
  29. /// @return The current blue gamma value
  30. double getGammaB() const;
  31. /// @param gammaR New red gamma value
  32. /// @param gammaG New green gamma value
  33. /// @param gammaB New blue gamma value
  34. void setGamma(double gammaR,double gammaG=-1, double gammaB=-1);
  35. /// @return The current lower brightness
  36. int getBacklightThreshold() const;
  37. /// @param backlightThreshold New lower brightness
  38. void setBacklightThreshold(double backlightThreshold);
  39. /// @return The current state
  40. bool getBacklightColored() const;
  41. /// @param backlightColored en/disable colored backlight
  42. void setBacklightColored(bool backlightColored);
  43. /// @return return state of backlight
  44. bool getBackLightEnabled() const;
  45. /// @param enable en/disable backlight
  46. void setBackLightEnabled(bool enable);
  47. /// @return The current brightness
  48. uint8_t getBrightness() const;
  49. /// @param brightness New brightness
  50. void setBrightness(uint8_t brightness);
  51. /// @return The current brightnessCompensation value
  52. uint8_t getBrightnessCompensation() const;
  53. /// @param brightnessCompensation new brightnessCompensation
  54. void setBrightnessCompensation(uint8_t brightnessCompensation);
  55. ///
  56. /// get component values of brightness for compensated brightness
  57. ///
  58. /// @param rgb the rgb component
  59. /// @param cmy the cyan magenta yellow component
  60. /// @param w the white component
  61. ///
  62. /// @note The values are updated in place.
  63. ///
  64. void getBrightnessComponents(uint8_t & rgb, uint8_t & cmy, uint8_t & w) const;
  65. ///
  66. /// Apply the transform the the given RGB values.
  67. ///
  68. /// @param red The red color component
  69. /// @param green The green color component
  70. /// @param blue The blue color component
  71. ///
  72. /// @note The values are updated in place.
  73. ///
  74. void transform(uint8_t & red, uint8_t & green, uint8_t & blue);
  75. private:
  76. ///
  77. /// init
  78. ///
  79. /// @param gammaR The used red gamma
  80. /// @param gammaG The used green gamma
  81. /// @param gammab The used blue gamma
  82. /// @param backlightThreshold The used lower brightness
  83. /// @param backlightColored en/disable color in backlight
  84. /// @param brightness The used brightness
  85. /// @param brightnessCompensation The used brightness compensation
  86. ///
  87. void init(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation);
  88. /// (re)-initilize the color mapping
  89. void initializeMapping(); /// The saturation gain
  90. void updateBrightnessComponents();
  91. /// backlight variables
  92. bool _backLightEnabled
  93. , _backlightColored;
  94. double _backlightThreshold
  95. , _sumBrightnessLow;
  96. /// gamma variables
  97. double _gammaR
  98. , _gammaG
  99. , _gammaB;
  100. /// The mapping from input color to output color
  101. uint8_t _mappingR[256]
  102. , _mappingG[256]
  103. , _mappingB[256];
  104. /// brightness variables
  105. uint8_t _brightness
  106. , _brightnessCompensation
  107. , _brightness_rgb
  108. , _brightness_cmy
  109. , _brightness_w;
  110. };