cms.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (C) 2024 Niklas Haas
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef SWSCALE_CMS_H
  21. #define SWSCALE_CMS_H
  22. #include <stdbool.h>
  23. #include "libavutil/csp.h"
  24. #include "csputils.h"
  25. #include "swscale.h"
  26. #include "utils.h"
  27. /* Minimum, maximum, and default knee point for perceptual tone mapping [0,1] */
  28. #define PERCEPTUAL_KNEE_MIN 0.10f
  29. #define PERCEPTUAL_KNEE_MAX 0.80f
  30. #define PERCEPTUAL_KNEE_DEF 0.40f
  31. /* Ratio between source average and target average. */
  32. #define PERCEPTUAL_ADAPTATION 0.40f
  33. /* (Relative) chromaticity protection zone for perceptual mapping [0,1] */
  34. #define PERCEPTUAL_DEADZONE 0.30f
  35. /* Contrast setting for perceptual tone mapping. [0,1.5] */
  36. #define PERCEPTUAL_CONTRAST 0.50f
  37. /* Tuning constants for overriding the contrast near extremes */
  38. #define SLOPE_TUNING 1.50f /* [0,10] */
  39. #define SLOPE_OFFSET 0.20f /* [0,1] */
  40. /* Strength of the perceptual saturation mapping component [0,1] */
  41. #define PERCEPTUAL_STRENGTH 0.80f
  42. /* Knee point to use for perceptual soft clipping [0,1] */
  43. #define SOFTCLIP_KNEE 0.70f
  44. /* I vs C curve gamma to use for colorimetric clipping [0,10] */
  45. #define COLORIMETRIC_GAMMA 1.80f
  46. /* Struct describing a color mapping operation */
  47. typedef struct SwsColorMap {
  48. SwsColor src;
  49. SwsColor dst;
  50. SwsIntent intent;
  51. } SwsColorMap;
  52. /**
  53. * Returns true if the given color map is a semantic no-op - that is,
  54. * the overall RGB end to end transform would an identity mapping.
  55. */
  56. bool ff_sws_color_map_noop(const SwsColorMap *map);
  57. /**
  58. * Generates a single end-to-end color mapping 3DLUT embedding a static tone
  59. * mapping curve.
  60. *
  61. * Returns 0 on success, or a negative error code on failure.
  62. */
  63. int ff_sws_color_map_generate_static(v3u16_t *lut, int size, const SwsColorMap *map);
  64. /**
  65. * Generates a split pair of 3DLUTS, going to IPT and back, allowing an
  66. * arbitrary dynamic EETF to be nestled in between these two operations.
  67. *
  68. * See ff_sws_tone_map_generate().
  69. *
  70. * Returns 0 on success, or a negative error code on failure.
  71. */
  72. int ff_sws_color_map_generate_dynamic(v3u16_t *input, v3u16_t *output,
  73. int size_input, int size_I, int size_PT,
  74. const SwsColorMap *map);
  75. /**
  76. * Generate a 1D LUT of size `size` adapting intensity (I) levels from the
  77. * source to the destination color space. The LUT is normalized to the
  78. * relevant intensity range directly. The second channel of each entry returns
  79. * the corresponding 15-bit scaling factor for the P/T channels. The scaling
  80. * factor k may be applied as `(1 << 15) - k + (PT * k >> 15)`.
  81. *
  82. * This is designed to be used with sws_gamut_map_generate_dynamic().
  83. *
  84. * Returns 0 on success, or a negative error code on failure.
  85. */
  86. void ff_sws_tone_map_generate(v2u16_t *lut, int size, const SwsColorMap *map);
  87. #endif // SWSCALE_GAMUT_MAPPING_H