all_processings.cpp 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. return ret;
  48. }
  49. float* yCurve(float* data, unsigned int width, unsigned int height, float yCs, float yCb, float yCm, float yCw, float yCh)
  50. {
  51. ImageHDR img(data, width, height);
  52. img.yCurve(yCs, yCb, yCm, yCw, yCh);
  53. img.non_linear_to_linear();
  54. img.linear=true;
  55. float* ret = new float[width * height * 3];
  56. memcpy(ret, img.data, width * height * 3 * sizeof(float));
  57. return ret;
  58. }
  59. float* lightnessMask(float* data, unsigned int width, unsigned int height, bool lms, bool lmb, bool lmm, bool lmw, bool lmh)
  60. {
  61. ImageHDR img(data, width, height);
  62. img.lightnessMask(lms, lmb, lmm, lmw, lmh);
  63. img.non_linear_to_linear();
  64. img.linear=true;
  65. float* ret = new float[width * height * 3];
  66. memcpy(ret, img.data, width * height * 3 * sizeof(float));
  67. return ret;
  68. }
  69. float* saturation(float* data, unsigned int width, unsigned int height, float saturation)
  70. {
  71. ImageHDR img(data, width, height);
  72. img.saturation(saturation);
  73. img.non_linear_to_linear();
  74. img.linear=true;
  75. float* ret = new float[width * height * 3];
  76. memcpy(ret, img.data, width * height * 3 * sizeof(float));
  77. return ret;
  78. }
  79. 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)
  80. {
  81. ImageHDR img(data, width, height);
  82. float sel_light[2] = { ce_sel_light_l, ce_sel_light_h };
  83. float sel_chr[2] = { ce_sel_chr_l, ce_sel_chr_h };
  84. float sel_hue[2] = { ce_sel_hue_l, ce_sel_hue_h };
  85. img.colorEditor(sel_light, sel_chr, sel_hue, ce_tol, ce_edit_hue, ce_edit_expo, ce_edit_con, ce_edit_sat, ce_mask);
  86. float* ret = new float[width * height * 3];
  87. memcpy(ret, img.data, width * height * 3 * sizeof(float));
  88. return ret;
  89. }
  90. float* full_process(float* data, unsigned int width, unsigned int height,
  91. float exposure,
  92. float contrast,
  93. float yCs, float yCb, float yCm, float yCw, float yCh,
  94. bool lms, bool lmb, bool lmm, bool lmw, bool lmh,
  95. float saturation,
  96. 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)
  97. {
  98. ImageHDR img(data, width, height);
  99. // ******************************************
  100. img.exposure(exposure);
  101. // ******************************************
  102. // ******************************************
  103. img.contrast(contrast);
  104. // ******************************************
  105. // ******************************************
  106. img.yCurve(yCs, yCb, yCm, yCw, yCh);
  107. // ******************************************
  108. // ******************************************
  109. img.lightnessMask(lms, lmb, lmm, lmw, lmh);
  110. // ******************************************
  111. // ******************************************
  112. img.saturation(saturation);
  113. // ******************************************
  114. // ******************************************
  115. float sel_light[2] = {ce_sel_light_l, ce_sel_light_h};
  116. float sel_chr[2] = {ce_sel_chr_l, ce_sel_chr_h};
  117. float sel_hue[2] = {ce_sel_hue_l, ce_sel_hue_h};
  118. img.colorEditor(sel_light, sel_chr, sel_hue, ce_tol, ce_edit_hue, ce_edit_expo, ce_edit_con, ce_edit_sat, ce_mask);
  119. // ******************************************
  120. if(img.linear==false){
  121. img.non_linear_to_linear();
  122. img.linear=true;
  123. }
  124. float *ret = new float[width*height*3];
  125. memcpy(ret, img.data, width * height * 3 * sizeof(float));
  126. return ret;
  127. }
  128. float* full_process_5CO(float* data, unsigned int width, unsigned int height,
  129. float exposure,
  130. float contrast,
  131. float yCs, float yCb, float yCm, float yCw, float yCh,
  132. bool lms, bool lmb, bool lmm, bool lmw, bool lmh,
  133. float saturation,
  134. float ce_sel_light_l_co1, float ce_sel_light_h_co1, float ce_sel_chr_l_co1, float ce_sel_chr_h_co1, float ce_sel_hue_l_co1, float ce_sel_hue_h_co1, float ce_tol_co1, float ce_edit_hue_co1, float ce_edit_expo_co1, float ce_edit_con_co1, float ce_edit_sat_co1, bool ce_mask_co1,
  135. float ce_sel_light_l_co2, float ce_sel_light_h_co2, float ce_sel_chr_l_co2, float ce_sel_chr_h_co2, float ce_sel_hue_l_co2, float ce_sel_hue_h_co2, float ce_tol_co2, float ce_edit_hue_co2, float ce_edit_expo_co2, float ce_edit_con_co2, float ce_edit_sat_co2, bool ce_mask_co2,
  136. float ce_sel_light_l_co3, float ce_sel_light_h_co3, float ce_sel_chr_l_co3, float ce_sel_chr_h_co3, float ce_sel_hue_l_co3, float ce_sel_hue_h_co3, float ce_tol_co3, float ce_edit_hue_co3, float ce_edit_expo_co3, float ce_edit_con_co3, float ce_edit_sat_co3, bool ce_mask_co3,
  137. float ce_sel_light_l_co4, float ce_sel_light_h_co4, float ce_sel_chr_l_co4, float ce_sel_chr_h_co4, float ce_sel_hue_l_co4, float ce_sel_hue_h_co4, float ce_tol_co4, float ce_edit_hue_co4, float ce_edit_expo_co4, float ce_edit_con_co4, float ce_edit_sat_co4, bool ce_mask_co4,
  138. float ce_sel_light_l_co5, float ce_sel_light_h_co5, float ce_sel_chr_l_co5, float ce_sel_chr_h_co5, float ce_sel_hue_l_co5, float ce_sel_hue_h_co5, float ce_tol_co5, float ce_edit_hue_co5, float ce_edit_expo_co5, float ce_edit_con_co5, float ce_edit_sat_co5, bool ce_mask_co5)
  139. {
  140. ImageHDR img(data, width, height);
  141. // ******************************************
  142. img.exposure(exposure);
  143. // ******************************************
  144. // ******************************************
  145. img.contrast(contrast);
  146. // ******************************************
  147. // ******************************************
  148. img.yCurve(yCs, yCb, yCm, yCw, yCh);
  149. // ******************************************
  150. // ******************************************
  151. img.lightnessMask(lms, lmb, lmm, lmw, lmh);
  152. // ******************************************
  153. // ******************************************
  154. img.saturation(saturation);
  155. // ******************************************
  156. // ******************************************
  157. // COLOR EDITOR 0
  158. // TEST !!!! A SUPPRIMER NORMALEMENT.
  159. float sel_light[2] = { 0,100 };
  160. float sel_chr[2] = { 0,100 };
  161. float sel_hue[2] = { 0,360 };
  162. img.colorEditor(sel_light, sel_chr, sel_hue, 0.1, 0, 0, 0, 0, false);
  163. // ******************************************
  164. // COLOR EDITOR 1
  165. sel_light[0] = ce_sel_light_l_co1; sel_light[1] = ce_sel_light_h_co1;
  166. sel_chr[0] = ce_sel_chr_l_co1; sel_chr[1] = ce_sel_chr_h_co1;
  167. sel_hue[0] = ce_sel_hue_l_co1; sel_hue[1] = ce_sel_hue_h_co1;
  168. img.colorEditor(sel_light, sel_chr, sel_hue, ce_tol_co1, ce_edit_hue_co1, ce_edit_expo_co1, ce_edit_con_co1, ce_edit_sat_co1, ce_mask_co1);
  169. // ******************************************
  170. // COLOR EDITOR 2
  171. sel_light[0] = ce_sel_light_l_co2; sel_light[1] = ce_sel_light_h_co2;
  172. sel_chr[0] = ce_sel_chr_l_co2; sel_chr[1] = ce_sel_chr_h_co2;
  173. sel_hue[0] = ce_sel_hue_l_co2; sel_hue[1] = ce_sel_hue_h_co2;
  174. img.colorEditor(sel_light, sel_chr, sel_hue, ce_tol_co2, ce_edit_hue_co2, ce_edit_expo_co2, ce_edit_con_co2, ce_edit_sat_co2, ce_mask_co2);
  175. // ******************************************
  176. // COLOR EDITOR 3
  177. sel_light[0] = ce_sel_light_l_co3; sel_light[1] = ce_sel_light_h_co3;
  178. sel_chr[0] = ce_sel_chr_l_co3; sel_chr[1] = ce_sel_chr_h_co3;
  179. sel_hue[0] = ce_sel_hue_l_co3; sel_hue[1] = ce_sel_hue_h_co3;
  180. img.colorEditor(sel_light, sel_chr, sel_hue, ce_tol_co3, ce_edit_hue_co3, ce_edit_expo_co3, ce_edit_con_co3, ce_edit_sat_co3, ce_mask_co3);
  181. // ******************************************
  182. // COLOR EDITOR 4
  183. sel_light[0] = ce_sel_light_l_co4; sel_light[1] = ce_sel_light_h_co4;
  184. sel_chr[0] = ce_sel_chr_l_co4; sel_chr[1] = ce_sel_chr_h_co4;
  185. sel_hue[0] = ce_sel_hue_l_co4; sel_hue[1] = ce_sel_hue_h_co4;
  186. img.colorEditor(sel_light, sel_chr, sel_hue, ce_tol_co4, ce_edit_hue_co4, ce_edit_expo_co4, ce_edit_con_co4, ce_edit_sat_co4, ce_mask_co4);
  187. // ******************************************
  188. // COLOR EDITOR 5
  189. sel_light[0] = ce_sel_light_l_co5; sel_light[1] = ce_sel_light_h_co5;
  190. sel_chr[0] = ce_sel_chr_l_co5; sel_chr[1] = ce_sel_chr_h_co5;
  191. sel_hue[0] = ce_sel_hue_l_co5; sel_hue[1] = ce_sel_hue_h_co5;
  192. img.colorEditor(sel_light, sel_chr, sel_hue, ce_tol_co5, ce_edit_hue_co5, ce_edit_expo_co5, ce_edit_con_co5, ce_edit_sat_co5, ce_mask_co5);
  193. // ******************************************
  194. if (img.linear == false) {
  195. img.non_linear_to_linear();
  196. img.linear = true;
  197. }
  198. float* ret = new float[width * height * 3];
  199. memcpy(ret, img.data, width * height * 3 * sizeof(float));
  200. return ret;
  201. }