all_processings.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. #include "pch.h"
  20. #include <iostream>
  21. #include <chrono>
  22. #include <cstdlib>
  23. #include <vector>
  24. #include <ctime>
  25. #include <Eigen/Core>
  26. #include <unsupported/Eigen/Splines>
  27. #include "ImageHDR.hpp"
  28. #include "YCurve.hpp"
  29. #include "Conversion.hpp"
  30. #include "all_processings.hpp"
  31. float* exposure(float* data, unsigned int width, unsigned int height, float exposure)
  32. {
  33. ImageHDR img(data, width, height);
  34. img.exposure(exposure);
  35. float* ret = new float[width * height * 3];
  36. memcpy(ret, img.data, width * height * 3 * sizeof(float));
  37. return ret;
  38. }
  39. float* contrast(float* data, unsigned int width, unsigned int height, float constrast)
  40. {
  41. ImageHDR img(data, width, height);
  42. img.contrast(constrast);
  43. img.non_linear_to_linear();
  44. img.linear=true;
  45. float* ret = new float[width * height * 3];
  46. memcpy(ret, img.data, width * height * 3 * sizeof(float));
  47. img.display_debug();
  48. return ret;
  49. }
  50. float* yCurve(float* data, unsigned int width, unsigned int height, float yCs, float yCb, float yCm, float yCw, float yCh)
  51. {
  52. ImageHDR img(data, width, height);
  53. img.yCurve(yCs, yCb, yCm, yCw, yCh);
  54. img.non_linear_to_linear();
  55. img.linear=true;
  56. float* ret = new float[width * height * 3];
  57. memcpy(ret, img.data, width * height * 3 * sizeof(float));
  58. //img.display_debug();
  59. return ret;
  60. }
  61. float* lightnessMask(float* data, unsigned int width, unsigned int height, bool lms, bool lmb, bool lmm, bool lmw, bool lmh)
  62. {
  63. ImageHDR img(data, width, height);
  64. img.lightnessMask(lms, lmb, lmm, lmw, lmh);
  65. img.non_linear_to_linear();
  66. float* ret = new float[width * height * 3];
  67. memcpy(ret, img.data, width * height * 3 * sizeof(float));
  68. return ret;
  69. }
  70. float* saturation(float* data, unsigned int width, unsigned int height, float saturation)
  71. {
  72. ImageHDR img(data, width, height);
  73. img.saturation(saturation);
  74. float* dataRGB = Conversion::LCH_to_sRGB(img.data, width * height);
  75. free(img.data);
  76. img.data = dataRGB;
  77. float* ret = new float[width * height * 3];
  78. memcpy(ret, img.data, width * height * 3 * sizeof(float));
  79. return ret;
  80. }
  81. float* colorEditor(float* data, unsigned int width, unsigned int height, float ce_sel_light_l, float ce_sel_light_h, float ce_sel_chr_l, float ce_sel_chr_h, float ce_sel_hue_l, float ce_sel_hue_h, float ce_tol, float ce_edit_hue, float ce_edit_expo, float ce_edit_con, float ce_edit_sat, bool ce_mask)
  82. {
  83. ImageHDR img(data, width, height);
  84. float sel_light[2] = { ce_sel_light_l, ce_sel_light_h };
  85. float sel_chr[2] = { ce_sel_chr_l, ce_sel_chr_h };
  86. float sel_hue[2] = { ce_sel_hue_l, ce_sel_hue_h };
  87. img.colorEditor(sel_light, sel_chr, sel_hue, ce_tol, ce_edit_hue, ce_edit_expo, ce_edit_con, ce_edit_sat, ce_mask);
  88. float* ret = new float[width * height * 3];
  89. memcpy(ret, img.data, width * height * 3 * sizeof(float));
  90. return ret;
  91. }
  92. float* full_process(float* data, unsigned int width, unsigned int height,
  93. float exposure,
  94. float contrast,
  95. float yCs, float yCb, float yCm, float yCw, float yCh,
  96. bool lms, bool lmb, bool lmm, bool lmw, bool lmh,
  97. float saturation,
  98. float ce_sel_light_l, float ce_sel_light_h, float ce_sel_chr_l, float ce_sel_chr_h, float ce_sel_hue_l, float ce_sel_hue_h, float ce_tol, float ce_edit_hue, float ce_edit_expo, float ce_edit_con, float ce_edit_sat, bool ce_mask)
  99. {
  100. ImageHDR img(data, width, height);
  101. // ******************************************
  102. img.exposure(exposure);
  103. // ******************************************
  104. // ******************************************
  105. img.contrast(contrast);
  106. // ******************************************
  107. // ******************************************
  108. img.yCurve(yCs, yCb, yCm, yCw, yCh);
  109. // ******************************************
  110. // ******************************************
  111. img.lightnessMask(lms, lmb, lmm, lmw, lmh);
  112. // ******************************************
  113. // ******************************************
  114. img.saturation(saturation);
  115. // ******************************************
  116. // ******************************************
  117. float sel_light[2] = {ce_sel_light_l, ce_sel_light_h};
  118. float sel_chr[2] = {ce_sel_chr_l, ce_sel_chr_h};
  119. float sel_hue[2] = {ce_sel_hue_l, ce_sel_hue_h};
  120. img.colorEditor(sel_light, sel_chr, sel_hue, ce_tol, ce_edit_hue, ce_edit_expo, ce_edit_con, ce_edit_sat, ce_mask);
  121. // ******************************************
  122. float *ret = new float[width*height*3];
  123. memcpy(ret, img.data, width * height * 3 * sizeof(float));
  124. return ret;
  125. }