csp.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright (c) 2015 Kevin Wheatley <kevin.j.wheatley@gmail.com>
  3. * Copyright (c) 2016 Ronald S. Bultje <rsbultje@gmail.com>
  4. * Copyright (c) 2023 Leo Izen <leo.izen@gmail.com>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #ifndef AVUTIL_CSP_H
  23. #define AVUTIL_CSP_H
  24. #include "pixfmt.h"
  25. #include "rational.h"
  26. /**
  27. * @file
  28. * Colorspace value utility functions for libavutil.
  29. * @ingroup lavu_math_csp
  30. * @author Ronald S. Bultje <rsbultje@gmail.com>
  31. * @author Leo Izen <leo.izen@gmail.com>
  32. * @author Kevin Wheatley <kevin.j.wheatley@gmail.com>
  33. */
  34. /**
  35. * @defgroup lavu_math_csp Colorspace Utility
  36. * @ingroup lavu_math
  37. * @{
  38. */
  39. /**
  40. * Struct containing luma coefficients to be used for RGB to YUV/YCoCg, or similar
  41. * calculations.
  42. */
  43. typedef struct AVLumaCoefficients {
  44. AVRational cr, cg, cb;
  45. } AVLumaCoefficients;
  46. /**
  47. * Struct containing chromaticity x and y values for the standard CIE 1931
  48. * chromaticity definition.
  49. */
  50. typedef struct AVCIExy {
  51. AVRational x, y;
  52. } AVCIExy;
  53. /**
  54. * Struct defining the red, green, and blue primary locations in terms of CIE
  55. * 1931 chromaticity x and y.
  56. */
  57. typedef struct AVPrimaryCoefficients {
  58. AVCIExy r, g, b;
  59. } AVPrimaryCoefficients;
  60. /**
  61. * Struct defining white point location in terms of CIE 1931 chromaticity x
  62. * and y.
  63. */
  64. typedef AVCIExy AVWhitepointCoefficients;
  65. /**
  66. * Struct that contains both white point location and primaries location, providing
  67. * the complete description of a color gamut.
  68. */
  69. typedef struct AVColorPrimariesDesc {
  70. AVWhitepointCoefficients wp;
  71. AVPrimaryCoefficients prim;
  72. } AVColorPrimariesDesc;
  73. /**
  74. * Function pointer representing a double -> double transfer function that performs
  75. * an EOTF transfer inversion. This function outputs linear light.
  76. */
  77. typedef double (*av_csp_trc_function)(double);
  78. /**
  79. * Retrieves the Luma coefficients necessary to construct a conversion matrix
  80. * from an enum constant describing the colorspace.
  81. * @param csp An enum constant indicating YUV or similar colorspace.
  82. * @return The Luma coefficients associated with that colorspace, or NULL
  83. * if the constant is unknown to libavutil.
  84. */
  85. const AVLumaCoefficients *av_csp_luma_coeffs_from_avcsp(enum AVColorSpace csp);
  86. /**
  87. * Retrieves a complete gamut description from an enum constant describing the
  88. * color primaries.
  89. * @param prm An enum constant indicating primaries
  90. * @return A description of the colorspace gamut associated with that enum
  91. * constant, or NULL if the constant is unknown to libavutil.
  92. */
  93. const AVColorPrimariesDesc *av_csp_primaries_desc_from_id(enum AVColorPrimaries prm);
  94. /**
  95. * Detects which enum AVColorPrimaries constant corresponds to the given complete
  96. * gamut description.
  97. * @see enum AVColorPrimaries
  98. * @param prm A description of the colorspace gamut
  99. * @return The enum constant associated with this gamut, or
  100. * AVCOL_PRI_UNSPECIFIED if no clear match can be idenitified.
  101. */
  102. enum AVColorPrimaries av_csp_primaries_id_from_desc(const AVColorPrimariesDesc *prm);
  103. /**
  104. * Determine a suitable 'gamma' value to match the supplied
  105. * AVColorTransferCharacteristic.
  106. *
  107. * See Apple Technical Note TN2257 (https://developer.apple.com/library/mac/technotes/tn2257/_index.html)
  108. *
  109. * This function returns the gamma exponent for the OETF. For example, sRGB is approximated
  110. * by gamma 2.2, not by gamma 0.45455.
  111. *
  112. * @return Will return an approximation to the simple gamma function matching
  113. * the supplied Transfer Characteristic, Will return 0.0 for any
  114. * we cannot reasonably match against.
  115. */
  116. double av_csp_approximate_trc_gamma(enum AVColorTransferCharacteristic trc);
  117. /**
  118. * Determine the function needed to apply the given
  119. * AVColorTransferCharacteristic to linear input.
  120. *
  121. * The function returned should expect a nominal domain and range of [0.0-1.0]
  122. * values outside of this range maybe valid depending on the chosen
  123. * characteristic function.
  124. *
  125. * @return Will return pointer to the function matching the
  126. * supplied Transfer Characteristic. If unspecified will
  127. * return NULL:
  128. */
  129. av_csp_trc_function av_csp_trc_func_from_id(enum AVColorTransferCharacteristic trc);
  130. /**
  131. * @}
  132. */
  133. #endif /* AVUTIL_CSP_H */