avutil/csp: add av_csp_approximate_eotf_gamma()

2.2 gamma was used for bt.1886 aproximation as the most common target in
real world.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
This commit is contained in:
Kacper Michajłow
2025-10-13 02:36:35 +02:00
parent 3115c0c0e6
commit 00e43619cd
4 changed files with 41 additions and 1 deletions
+3
View File
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2025-03-28
API changes, most recent first:
2025-10-xx - xxxxxxxxxx - lavu 60.14.100 - csp.h
Add av_csp_approximate_eotf_gamma().
2025-08-xx - xxxxxxxxxx - lavf 62.6.100 - oggparsevorbis.h oggparseopus.h oggparseflac.h
Drop header packets from secondary chained ogg/{flac, opus, vorbis} streams
from demuxer output.
+21
View File
@@ -157,6 +157,27 @@ double av_csp_approximate_trc_gamma(enum AVColorTransferCharacteristic trc)
return 0.0;
}
static const double approximate_eotf_gamma[AVCOL_TRC_NB] = {
[AVCOL_TRC_BT709] = 2.2,
[AVCOL_TRC_SMPTE170M] = 2.2,
[AVCOL_TRC_SMPTE240M] = 2.2,
[AVCOL_TRC_BT1361_ECG] = 2.2,
[AVCOL_TRC_BT2020_10] = 2.2,
[AVCOL_TRC_BT2020_12] = 2.2,
[AVCOL_TRC_GAMMA22] = 2.2,
[AVCOL_TRC_IEC61966_2_1] = 2.2,
[AVCOL_TRC_GAMMA28] = 2.8,
[AVCOL_TRC_LINEAR] = 1.0,
[AVCOL_TRC_SMPTE428] = 2.6,
};
double av_csp_approximate_eotf_gamma(enum AVColorTransferCharacteristic trc)
{
if ((unsigned)trc >= AVCOL_TRC_NB)
return 0.0;
return approximate_eotf_gamma[trc];
}
#define BT709_alpha 1.099296826809442
#define BT709_beta 0.018053968510807
+16
View File
@@ -133,6 +133,22 @@ enum AVColorPrimaries av_csp_primaries_id_from_desc(const AVColorPrimariesDesc *
*/
double av_csp_approximate_trc_gamma(enum AVColorTransferCharacteristic trc);
/**
* Determine a suitable EOTF 'gamma' value to match the supplied
* AVColorTransferCharacteristic.
*
* This function returns the gamma value (exponent) for a simple pure power
* function approximation of the supplied AVColorTransferCharacteristic, or 0.
* if no reasonable approximation exists.
*
* EOTF(v) = (L_w - L_b) * v^gamma + L_b
*
* @return Will return an approximation to the simple gamma function matching
* the supplied Transfer Characteristic EOTF, Will return 0.0 for any
* we cannot reasonably match against.
*/
double av_csp_approximate_eotf_gamma(enum AVColorTransferCharacteristic trc);
/**
* Determine the function needed to apply the given
* AVColorTransferCharacteristic to linear input.
+1 -1
View File
@@ -79,7 +79,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 60
#define LIBAVUTIL_VERSION_MINOR 13
#define LIBAVUTIL_VERSION_MINOR 14
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \