Go to the documentation of this file.
38 #define AVR(d) { (int)(d * 100000 + 0.5), 100000 }
71 #define WP_D65 { AVR(0.3127), AVR(0.3290) }
72 #define WP_C { AVR(0.3100), AVR(0.3160) }
73 #define WP_DCI { AVR(0.3140), AVR(0.3510) }
74 #define WP_E { {1, 3}, {1, 3} }
103 if (!
p->prim.r.x.num)
121 if (!
ref->prim.r.x.num)
197 #define BT709_alpha 1.099296826809442
198 #define BT709_beta 0.018053968510807
205 return (0.0 > Lc) ? 0.0
206 : (
b > Lc) ? 4.500 * Lc
207 :
a * pow(Lc, 0.45) - (
a - 1.0);
215 return (0.0 >
E) ? 0.0
216 : (
b >
E) ?
E / 4.500
217 : pow((
E + (
a - 1.0)) /
a, 1.0 / 0.45);
222 return (0.0 > Lc) ? 0.0 : pow(Lc, 1.0/ 2.2);
227 return (0.0 >
E) ? 0.0 : pow(
E, 2.2);
232 return (0.0 > Lc) ? 0.0 : pow(Lc, 1.0/ 2.8);
237 return (0.0 >
E) ? 0.0 : pow(
E, 2.8);
242 const double a = 1.1115;
243 const double b = 0.0228;
245 return (0.0 > Lc) ? 0.0
246 : (
b > Lc) ? 4.000 * Lc
247 :
a * pow(Lc, 0.45) - (
a - 1.0);
252 const double a = 1.1115;
253 const double b = 4.000 * 0.0228;
255 return (0.0 >
E) ? 0.0
256 : (
b >
E) ?
E / 4.000
257 : pow((
E + (
a - 1.0)) /
a, 1.0 / 0.45);
267 return (0.01 > Lc) ? 0.0 : 1.0 + log10(Lc) / 2.0;
272 return (0.0 >
E) ? 0.01 : pow(10.0, 2.0 * (
E - 1.0));
278 return (0.00316227766 > Lc) ? 0.0 : 1.0 + log10(Lc) / 2.5;
283 return (0.0 >
E) ? 0.00316227766 : pow(10.0, 2.5 * (
E - 1.0));
291 return (-
b >= Lc) ? -
a * pow(-Lc, 0.45) + (
a - 1.0)
292 : (
b > Lc) ? 4.500 * Lc
293 :
a * pow( Lc, 0.45) - (
a - 1.0);
301 return (-
b >=
E) ? -pow((-
E + (
a - 1.0)) /
a, 1.0 / 0.45)
302 : (
b >
E) ?
E / 4.500
303 : pow((
E + (
a - 1.0)) /
a, 1.0 / 0.45);
311 return (-0.0045 >= Lc) ? -(
a * pow(-4.0 * Lc, 0.45) + (
a - 1.0)) / 4.0
312 : (
b > Lc) ? 4.500 * Lc
313 :
a * pow( Lc, 0.45) - (
a - 1.0);
321 return (-0.02025 >=
E) ? -pow((-4.0 *
E - (
a - 1.0)) /
a, 1.0 / 0.45) / 4.0
322 : (
b >
E) ?
E / 4.500
323 : pow((
E + (
a - 1.0)) /
a, 1.0 / 0.45);
328 const double a = 1.055;
329 const double b = 0.0031308;
331 return (0.0 > Lc) ? 0.0
332 : (
b > Lc) ? 12.92 * Lc
333 :
a * pow(Lc, 1.0 / 2.4) - (
a - 1.0);
338 const double a = 1.055;
339 const double b = 12.92 * 0.0031308;
341 return (0.0 >
E) ? 0.0
342 : (
b >
E) ?
E / 12.92
343 : pow((
E + (
a - 1.0)) /
a, 2.4);
347 #define PQ_c1 ( 3424.0 / 4096.0)
348 #define PQ_c2 ( 32.0 * 2413.0 / 4096.0)
349 #define PQ_c3 ( 32.0 * 2392.0 / 4096.0)
350 #define PQ_m (128.0 * 2523.0 / 4096.0)
351 #define PQ_n ( 0.25 * 2610.0 / 4096.0)
357 const double c3 =
PQ_c3;
358 const double m =
PQ_m;
359 const double n =
PQ_n;
360 const double L = Lc / 10000.0;
361 const double Ln = pow(
L, n);
363 return (0.0 > Lc) ? 0.0
364 : pow((
c1 +
c2 * Ln) / (1.0 + c3 * Ln), m);
372 const double c3 =
PQ_c3;
373 const double m =
PQ_m;
374 const double n =
PQ_n;
375 const double Em = pow(
E, 1.0 / m);
377 return (
c1 > Em) ? 0.0
378 : 10000.0 * pow((Em -
c1) / (
c2 - c3 * Em), 1.0 / n);
386 return (0.0 > Lc) ? 0.0 : pow(
DCI_L /
DCI_P * Lc, 1.0 / 2.6);
394 #define HLG_a 0.17883277
395 #define HLG_b 0.28466892
396 #define HLG_c 0.55991073
405 return (0.0 > Lc) ? 0.0 :
406 (Lc <= 1.0 / 12.0 ? sqrt(3.0 * Lc) :
a *
log(12.0 * Lc -
b) +
c);
414 return (0.0 >
E) ? 0.0 :
415 (
E <= 0.5 ?
E *
E / 3.0 : (
exp((
E -
c) /
a) +
b) / 12.0);
419 #define VLOG_c2 0.181
420 #define VLOG_b 0.00873
421 #define VLOG_c 0.241514
422 #define VLOG_d 0.598206
430 return (
E <
c1) ? (5.6 *
E + 0.125) :
431 (
c * log10(
E +
b) + d);
440 return (
E <
c2) ? (
E - 0.125) / 5.6 :
441 (pow(10.0, ((
E - d) /
c)) -
b);
514 for (
int i = 0;
i < 3;
i++)
515 E[
i] = (Lw - Lb) *
E[
i] + Lb;
520 for (
int i = 0;
i < 3;
i++)
521 L[
i] = (
L[
i] - Lb) / (Lw - Lb);
524 #define WRAP_SDR_OETF(name) \
525 static void oetf_##name(double L[3]) \
527 for (int i = 0; i < 3; i++) \
528 L[i] = trc_##name(L[i]); \
531 static void oetf_##name##_inv(double E[3]) \
533 for (int i = 0; i < 3; i++) \
534 E[i] = trc_##name##_inv(E[i]); \
541 #define WRAP_SDR_EOTF(name) \
542 static void eotf_##name(double Lw, double Lb, double E[3]) \
544 oetf_##name##_inv(E); \
545 eotf_linear(Lw, Lb, E); \
548 static void eotf_##name##_inv(double Lw, double Lb, double L[3]) \
550 eotf_linear_inv(Lw, Lb, L); \
560 const double Lw_inv = pow(Lw, 1.0 / 2.4);
561 const double Lb_inv = pow(Lb, 1.0 / 2.4);
562 const double a = pow(Lw_inv - Lb_inv, 2.4);
563 const double b = Lb_inv / (Lw_inv - Lb_inv);
565 for (
int i = 0;
i < 3;
i++)
566 E[
i] = (-
b >
E[
i]) ? 0.0 :
a * pow(
E[
i] +
b, 2.4);
571 const double Lw_inv = pow(Lw, 1.0 / 2.4);
572 const double Lb_inv = pow(Lb, 1.0 / 2.4);
573 const double a = pow(Lw_inv - Lb_inv, 2.4);
574 const double b = Lb_inv / (Lw_inv - Lb_inv);
576 for (
int i = 0;
i < 3;
i++)
577 L[
i] = (0.0 >
L[
i]) ? 0.0 : pow(
L[
i] /
a, 1.0 / 2.4) -
b;
582 for (
int i = 0;
i < 3;
i++)
588 for (
int i = 0;
i < 3;
i++)
595 #define DCI_X (42.94 / DCI_L)
596 #define DCI_Z (45.82 / DCI_L)
600 const double Lw[3] = {
DCI_X * Lw_Y, Lw_Y,
DCI_Z * Lw_Y };
601 const double Lb[3] = {
DCI_X * Lb_Y, Lb_Y,
DCI_Z * Lb_Y };
603 for (
int i = 0;
i < 3;
i++) {
605 E[
i] =
E[
i] * (Lw[
i] - Lb[
i]) + Lb[
i];
611 const double Lw[3] = {
DCI_X * Lw_Y, Lw_Y,
DCI_Z * Lw_Y };
612 const double Lb[3] = {
DCI_X * Lb_Y, Lb_Y,
DCI_Z * Lb_Y };
614 for (
int i = 0;
i < 3;
i++) {
615 L[
i] = (
L[
i] - Lb[
i]) / (Lw[
i] - Lb[
i]);
622 const double gamma =
fmax(1.2 + 0.42 * log10(Lw / 1000.0), 1.0);
631 const double beta = sqrt(3 * pow(Lb / Lw, 1.0 / gamma));
634 for (
int i = 0;
i < 3;
i++)
637 luma = 0.2627 *
E[0] + 0.6780 *
E[1] + 0.0593 *
E[2];
638 luma = pow(
fmax(luma, 0.0), gamma - 1.0);
639 for (
int i = 0;
i < 3;
i++)
645 const double gamma =
fmax(1.2 + 0.42 * log10(Lw / 1000.0), 1.0);
646 const double beta = sqrt(3 * pow(Lb / Lw, 1 / gamma));
647 double luma = 0.2627 *
L[0] + 0.6780 *
L[1] + 0.0593 *
L[2];
650 luma = pow(luma / Lw, (1 - gamma) / gamma);
651 for (
int i = 0;
i < 3;
i++)
654 L[0] =
L[1] =
L[2] = 0.0;
657 for (
int i = 0;
i < 3;
i++)
static double trc_bt1361_inv(double E)
static av_always_inline AVRational abs_sub_q(AVRational r1, AVRational r2)
AVColorTransferCharacteristic
Color Transfer Characteristic.
static const double approximate_gamma_ext[AVCOL_TRC_EXT_NB - AVCOL_TRC_EXT_BASE]
AVWhitepointCoefficients wp
static double trc_smpte240M(double Lc)
Struct that contains both white point location and primaries location, providing the complete descrip...
av_csp_trc_function av_csp_trc_func_inv_from_id(enum AVColorTransferCharacteristic trc)
Returns the mathematical inverse of the corresponding TRC function.
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
@ AVCOL_TRC_NB
Not part of ABI.
const struct AVLumaCoefficients * av_csp_luma_coeffs_from_avcsp(enum AVColorSpace csp)
Retrieves the Luma coefficients necessary to construct a conversion matrix from an enum constant desc...
@ AVCOL_SPC_NB
Not part of ABI.
static void eotf_smpte_st428_1_inv(const double Lw_Y, const double Lb_Y, double L[3])
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
@ AVCOL_TRC_BT2020_12
ITU-R BT2020 for 12-bit system.
Struct containing luma coefficients to be used for RGB to YUV/YCoCg, or similar calculations.
AVColorPrimaries
Chromaticity coordinates of the source primaries.
AVRational av_sub_q(AVRational b, AVRational c)
Subtract one rational from another.
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
av_csp_trc_function av_csp_trc_func_from_id(enum AVColorTransferCharacteristic trc)
Determine the function needed to apply the given AVColorTransferCharacteristic to linear input.
static double trc_log_inv(double E)
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
static const av_csp_trc_function trc_inv_funcs_ext[AVCOL_TRC_EXT_NB - AVCOL_TRC_EXT_BASE]
#define WRAP_SDR_OETF(name)
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
static double trc_gamma22(double Lc)
static void eotf_linear_inv(const double Lw, const double Lb, double L[3])
@ AVCOL_TRC_LOG_SQRT
"Logarithmic transfer characteristic (100 * Sqrt(10) : 1 range)"
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
static double trc_smpte240M_inv(double E)
static double trc_iec61966_2_1(double Lc)
@ AVCOL_PRI_NB
Not part of ABI.
const AVColorPrimariesDesc * av_csp_primaries_desc_from_id(enum AVColorPrimaries prm)
Retrieves a complete gamut description from an enum constant describing the color primaries.
@ AVCOL_TRC_BT1361_ECG
ITU-R BT1361 Extended Colour Gamut.
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
static const double approximate_gamma[AVCOL_TRC_NB]
static const AVColorPrimariesDesc color_primaries_ext[AVCOL_PRI_EXT_NB - AVCOL_PRI_EXT_BASE]
@ AVCOL_PRI_SMPTE428
SMPTE ST 428-1 (CIE 1931 XYZ)
static void eotf_smpte_st2084_inv(const double Lw, const double Lb, double L[3])
enum AVColorPrimaries av_csp_primaries_id_from_desc(const AVColorPrimariesDesc *prm)
Detects which enum AVColorPrimaries constant corresponds to the given complete gamut description.
@ AVCOL_PRI_SMPTE240M
identical to above, also called "SMPTE C" even though it uses D65
static double trc_gamma28_inv(double E)
@ AVCOL_PRI_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
static void eotf_bt1886_inv(const double Lw, const double Lb, double L[3])
Rational number (pair of numerator and denominator).
@ AVCOL_TRC_IEC61966_2_4
IEC 61966-2-4.
static const av_csp_trc_function trc_funcs[AVCOL_TRC_NB]
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
static double trc_bt1361(double Lc)
static double trc_v_log(double E)
@ AVCOL_TRC_BT2020_10
ITU-R BT2020 for 10-bit system.
static void eotf_arib_std_b67(const double Lw, const double Lb, double E[3])
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
double av_csp_approximate_eotf_gamma(enum AVColorTransferCharacteristic trc)
Determine a suitable EOTF 'gamma' value to match the supplied AVColorTransferCharacteristic.
@ AVCOL_PRI_BT2020
ITU-R BT2020.
static const AVColorPrimariesDesc color_primaries[AVCOL_PRI_NB]
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
@ AVCOL_PRI_SMPTE431
SMPTE ST 431-2 (2011) / DCI P3.
static const av_csp_trc_function trc_funcs_ext[AVCOL_TRC_EXT_NB - AVCOL_TRC_EXT_BASE]
static const av_csp_eotf_function eotf_inv_funcs[AVCOL_TRC_NB]
@ AVCOL_PRI_FILM
colour filters using Illuminant C
static double trc_log(double Lc)
@ AVCOL_TRC_LOG
"Logarithmic transfer characteristic (100:1 range)"
static double trc_smpte_st2084(double Lc)
static const av_csp_trc_function trc_inv_funcs[AVCOL_TRC_NB]
static AVRational av_make_q(int num, int den)
Create an AVRational.
double av_csp_approximate_trc_gamma(enum AVColorTransferCharacteristic trc)
Determine a suitable 'gamma' value to match the supplied AVColorTransferCharacteristic.
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
@ AVCOL_TRC_EXT_NB
Not part of ABI.
static void eotf_linear(const double Lw, const double Lb, double E[3])
@ AVCOL_TRC_BT709
also ITU-R BT1361
static const double approximate_eotf_gamma_ext[AVCOL_TRC_EXT_NB - AVCOL_TRC_EXT_BASE]
@ AVCOL_SPC_SMPTE240M
derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
double(* av_csp_trc_function)(double)
Function pointer representing a double -> double transfer function that performs either an OETF trans...
#define i(width, name, range_min, range_max)
static double trc_iec61966_2_4_inv(double E)
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
static const double approximate_eotf_gamma[AVCOL_TRC_NB]
AVColorSpace
YUV colorspace type.
static double trc_bt709(double Lc)
static void eotf_smpte_st2084(const double Lw, const double Lb, double E[3])
void(* av_csp_eotf_function)(double Lw, double Lb, double c[3])
Function pointer representing an ITU EOTF transfer for a given reference display configuration.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
@ AVCOL_PRI_BT470M
also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
static double trc_linear(double Lc)
double fmax(double, double)
#define WRAP_SDR_EOTF(name)
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
@ AVCOL_PRI_EXT_NB
Not part of ABI.
static double trc_gamma28(double Lc)
static double trc_arib_std_b67_inv(double E)
@ AVCOL_SPC_FCC
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
static void eotf_smpte_st428_1(const double Lw_Y, const double Lb_Y, double E[3])
static int ref[MAX_W *MAX_W]
@ AVCOL_TRC_SMPTE170M
also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
static double trc_log_sqrt(double Lc)
static const av_csp_eotf_function eotf_funcs[AVCOL_TRC_NB]
@ AVCOL_PRI_SMPTE432
SMPTE ST 432-1 (2010) / P3 D65 / Display P3.
static double trc_gamma22_inv(double E)
AVRational av_add_q(AVRational b, AVRational c)
Add two rationals.
static double trc_smpte_st2084_inv(double E)
static double trc_v_log_inv(double E)
static double trc_iec61966_2_1_inv(double E)
AVPrimaryCoefficients prim
static const struct AVLumaCoefficients luma_coefficients[AVCOL_SPC_NB]
av_csp_eotf_function av_csp_itu_eotf(enum AVColorTransferCharacteristic trc)
Returns the ITU EOTF corresponding to a given TRC.
@ AVCOL_TRC_SMPTE428
SMPTE ST 428-1.
static double trc_bt709_inv(double E)
static double trc_log_sqrt_inv(double E)
static double trc_arib_std_b67(double Lc)
static double trc_smpte_st428_1_inv(double E)
static double trc_smpte_st428_1(double Lc)
static void eotf_arib_std_b67_inv(const double Lw, const double Lb, double L[3])
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
static void eotf_bt1886(const double Lw, const double Lb, double E[3])
av_csp_eotf_function av_csp_itu_eotf_inv(enum AVColorTransferCharacteristic trc)
Returns the mathematical inverse of the corresponding EOTF.
static double trc_iec61966_2_4(double Lc)