Conversion.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #ifndef CONVERSION__HPP
  2. #define CONVERSION__HPP
  3. #include <cmath>
  4. #include <iostream>
  5. #include <tuple>
  6. class Conversion
  7. {
  8. public:
  9. static constexpr float sRGB_to_XYZ_m[3][3] = { { 0.4124f, 0.3576f, 0.1805f},
  10. { 0.2126f, 0.7152f, 0.0722f},
  11. { 0.0193f, 0.1192f, 0.9505f} };
  12. // More accurate matrix
  13. //static constexpr float RGB_to_XYZ_m[3][3] = { { 0.412424f, 357579f, 0.180464f},
  14. // { 0.212656f, 0.715158f, 0.0721856f},
  15. // { 0.0193324f, 0.119193f, 0.950444f} };
  16. static constexpr float XYZ_to_sRGB_m[3][3] = { {3.2406f, -1.5372f, -0.4986f},
  17. {-0.9689f, 1.8758f, 0.0415f},
  18. {0.0557f, -0.2040f, 1.0570f} };
  19. static float linear_to_non_linear(float data);
  20. static float* linear_to_non_linear(const float* data, unsigned int length);
  21. static float non_linear_to_linear(float data);
  22. static float* non_linear_to_linear(const float* data, unsigned int length);
  23. static std::tuple<float, float, float> sRGB_to_XYZ(float r, float g, float b);
  24. // Warning data contains pixel with RGB components.
  25. // length is the number of pixel, not the real length of the data array.
  26. // The length of the data array is length*3.
  27. static float* sRGB_to_XYZ(const float* data, const unsigned int length);
  28. static float sRGB_to_Y_of_XYZ(float r, float g, float b);
  29. // Warning data contains pixel with RGB components.
  30. // length is the number of pixel, not the real length of the data array.
  31. // The length of the data array is length*3.
  32. static float* sRGB_to_Y_of_XYZ(const float* data, const unsigned int length);
  33. static std::tuple<float, float, float> XYZ_to_Lab(float x, float y, float z);
  34. // Warning data contains pixel with RGB components.
  35. // length is the number of pixel, not the real length of the data array.
  36. // The length of the data array is length*3.
  37. static float* XYZ_to_Lab(const float* data, const unsigned int length);
  38. static std::tuple<float, float, float> sRGB_to_Lab(float r, float g, float b);
  39. // Warning data contains pixel with RGB components.
  40. // length is the number of pixel, not the real length of the data array.
  41. // The length of the data array is length*3.
  42. static float* sRGB_to_Lab(const float* data, const unsigned int length);
  43. static float sRGB_to_L_of_Lab(float r, float g, float b);
  44. static std::tuple<float, float, float> Lab_to_LCH(float L, float a, float b);
  45. // Warning data contains pixel with Lab components.
  46. // length is the number of pixel, not the real length of the data array.
  47. // The length of the data array is length*3.
  48. static float* Lab_to_LCH(const float* data, const unsigned int length);
  49. static float Lab_to_C_of_LCH(float a, float b);
  50. static float Lab_to_H_of_LCH(float a, float b);
  51. static std::tuple<float, float, float> LCH_to_Lab(float L, float C, float H);
  52. // Warning data contains pixel with LCH components.
  53. // length is the number of pixel, not the real length of the data array.
  54. // The length of the data array is length*3.
  55. static float* LCH_to_Lab(const float* data, const unsigned int length);
  56. static std::tuple<float, float, float> Lab_to_XYZ(float L, float a, float b);
  57. // Warning data contains pixel with Lab components.
  58. // length is the number of pixel, not the real length of the data array.
  59. // The length of the data array is length*3.
  60. static float* Lab_to_XYZ(const float* data, const unsigned int length);
  61. static std::tuple<float, float, float> XYZ_to_sRGB(float x, float y, float z);
  62. // Warning data contains pixel with XYZ components.
  63. // length is the number of pixel, not the real length of the data array.
  64. // The length of the data array is length*3.
  65. static float* XYZ_to_sRGB(const float* data, const unsigned int length);
  66. // Warning data contains pixel with LCH components.
  67. // length is the number of pixel, not the real length of the data array.
  68. // The length of the data array is length*3.
  69. static float* LCH_to_sRGB(const float* data, const unsigned int length);
  70. };
  71. #endif