/src/FreeImage/Source/FreeImage/ToneMapping.cpp

https://bitbucket.org/cabalistic/ogredeps/ · C++ · 75 lines · 31 code · 5 blank · 39 comment · 17 complexity · 78c45951d85450dea81646c99079f6f7 MD5 · raw file

  1. // ==========================================================
  2. // Tone mapping operators
  3. //
  4. // Design and implementation by
  5. // - Hervé Drolon (drolon@infonie.fr)
  6. //
  7. // This file is part of FreeImage 3
  8. //
  9. // COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
  10. // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
  11. // THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
  12. // OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
  13. // CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
  14. // THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
  15. // SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
  16. // PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
  17. // THIS DISCLAIMER.
  18. //
  19. // Use at your own risk!
  20. // ==========================================================
  21. #include "FreeImage.h"
  22. #include "Utilities.h"
  23. /**
  24. Performs a tone mapping on a 48-bit RGB or a 96-bit RGBF image and returns a 24-bit image.
  25. The meaning of the parameters depends on the choosen algorithm.
  26. When both parameters are set to zero, a default set of parameters is used.
  27. @param dib Input RGB/RGBF image
  28. @param tmo Tone mapping operator
  29. @param first_param First parameter of the algorithm
  30. @param second_param Second parameter of the algorithm
  31. return Returns a 24-bit tone mapped image if successful, returns NULL otherwise
  32. */
  33. FIBITMAP * DLL_CALLCONV
  34. FreeImage_ToneMapping(FIBITMAP *dib, FREE_IMAGE_TMO tmo, double first_param, double second_param) {
  35. if(FreeImage_HasPixels(dib)) {
  36. switch(tmo) {
  37. // Adaptive logarithmic mapping (F. Drago, 2003)
  38. case FITMO_DRAGO03:
  39. if((first_param == 0) && (second_param == 0)) {
  40. // use default values (gamma = 2.2, exposure = 0)
  41. return FreeImage_TmoDrago03(dib, 2.2, 0);
  42. } else {
  43. // use user's value
  44. return FreeImage_TmoDrago03(dib, first_param, second_param);
  45. }
  46. break;
  47. // Dynamic range reduction inspired by photoreceptor phhysiology (E. Reinhard, 2005)
  48. case FITMO_REINHARD05:
  49. if((first_param == 0) && (second_param == 0)) {
  50. // use default values by setting intensity to 0 and contrast to 0
  51. return FreeImage_TmoReinhard05(dib, 0, 0);
  52. } else {
  53. // use user's value
  54. return FreeImage_TmoReinhard05(dib, first_param, second_param);
  55. }
  56. break;
  57. // Gradient Domain HDR Compression (R. Fattal, 2002)
  58. case FITMO_FATTAL02:
  59. if((first_param == 0) && (second_param == 0)) {
  60. // use default values by setting color saturation to 0.5 and attenuation to 0.85
  61. return FreeImage_TmoFattal02(dib, 0.5, 0.85);
  62. } else {
  63. // use user's value
  64. return FreeImage_TmoFattal02(dib, first_param, second_param);
  65. }
  66. break;
  67. }
  68. }
  69. return NULL;
  70. }