Conversion.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // This file is part of HDRip.
  2. //
  3. // HDRip is free software: you can redistribute it and/or modify it
  4. // under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation, either version 3 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // HDRip is distributed in the hope that it will be useful, but
  9. // WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with HDRip. If not, see <https://www.gnu.org/licenses/>.
  15. //
  16. // HDRip project
  17. // Author : Rémi Synave
  18. // Contact : remi.synave@univ-littoral.fr
  19. #ifndef CONVERSION__HPP
  20. #define CONVERSION__HPP
  21. #include <cmath>
  22. #include <iostream>
  23. #include <tuple>
  24. class Conversion
  25. {
  26. public:
  27. static constexpr float sRGB_to_XYZ_m[3][3] = { { 0.4124f, 0.3576f, 0.1805f},
  28. { 0.2126f, 0.7152f, 0.0722f},
  29. { 0.0193f, 0.1192f, 0.9505f} };
  30. // More accurate matrix
  31. //static constexpr float RGB_to_XYZ_m[3][3] = { { 0.412424f, 357579f, 0.180464f},
  32. // { 0.212656f, 0.715158f, 0.0721856f},
  33. // { 0.0193324f, 0.119193f, 0.950444f} };
  34. static constexpr float XYZ_to_sRGB_m[3][3] = { {3.2406f, -1.5372f, -0.4986f},
  35. {-0.9689f, 1.8758f, 0.0415f},
  36. {0.0557f, -0.2040f, 1.0570f} };
  37. static float linear_to_non_linear(float data);
  38. static float* linear_to_non_linear(const float* data, unsigned int length);
  39. static float non_linear_to_linear(float data);
  40. static float* non_linear_to_linear(const float* data, unsigned int length);
  41. static std::tuple<float, float, float> sRGB_to_XYZ(float r, float g, float b);
  42. // Warning data contains pixel with RGB components.
  43. // length is the number of pixel, not the real length of the data array.
  44. // The length of the data array is length*3.
  45. static float* sRGB_to_XYZ(const float* data, const unsigned int length);
  46. static float sRGB_to_Y_of_XYZ(float r, float g, float b);
  47. // Warning data contains pixel with RGB components.
  48. // length is the number of pixel, not the real length of the data array.
  49. // The length of the data array is length*3.
  50. static float* sRGB_to_Y_of_XYZ(const float* data, const unsigned int length);
  51. static std::tuple<float, float, float> XYZ_to_Lab(float x, float y, float z);
  52. // Warning data contains pixel with RGB 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* XYZ_to_Lab(const float* data, const unsigned int length);
  56. static std::tuple<float, float, float> sRGB_to_Lab(float r, float g, float b);
  57. // Warning data contains pixel with RGB 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* sRGB_to_Lab(const float* data, const unsigned int length);
  61. static float sRGB_to_L_of_Lab(float r, float g, float b);
  62. static std::tuple<float, float, float> Lab_to_LCH(float L, float a, float b);
  63. // Warning data contains pixel with Lab components.
  64. // length is the number of pixel, not the real length of the data array.
  65. // The length of the data array is length*3.
  66. static float* Lab_to_LCH(const float* data, const unsigned int length);
  67. static float Lab_to_C_of_LCH(float a, float b);
  68. static float Lab_to_H_of_LCH(float a, float b);
  69. static std::tuple<float, float, float> LCH_to_Lab(float L, float C, float H);
  70. // Warning data contains pixel with LCH components.
  71. // length is the number of pixel, not the real length of the data array.
  72. // The length of the data array is length*3.
  73. static float* LCH_to_Lab(const float* data, const unsigned int length);
  74. static std::tuple<float, float, float> Lab_to_XYZ(float L, float a, float b);
  75. // Warning data contains pixel with Lab components.
  76. // length is the number of pixel, not the real length of the data array.
  77. // The length of the data array is length*3.
  78. static float* Lab_to_XYZ(const float* data, const unsigned int length);
  79. static std::tuple<float, float, float> XYZ_to_sRGB(float x, float y, float z);
  80. // Warning data contains pixel with XYZ components.
  81. // length is the number of pixel, not the real length of the data array.
  82. // The length of the data array is length*3.
  83. static float* XYZ_to_sRGB(const float* data, const unsigned int length);
  84. // Warning data contains pixel with LCH components.
  85. // length is the number of pixel, not the real length of the data array.
  86. // The length of the data array is length*3.
  87. static float* LCH_to_sRGB(const float* data, const unsigned int length);
  88. };
  89. #endif