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} }
116 if (!
ref->prim.r.x.num)
160 #define BT709_alpha 1.099296826809442
161 #define BT709_beta 0.018053968510807
168 return (0.0 > Lc) ? 0.0
169 : (
b > Lc) ? 4.500 * Lc
170 :
a * pow(Lc, 0.45) - (
a - 1.0);
178 return (0.0 >
E) ? 0.0
179 : (
b >
E) ?
E / 4.500
180 : pow((
E + (
a - 1.0)) /
a, 1.0 / 0.45);
185 return (0.0 > Lc) ? 0.0 : pow(Lc, 1.0/ 2.2);
190 return (0.0 >
E) ? 0.0 : pow(
E, 2.2);
195 return (0.0 > Lc) ? 0.0 : pow(Lc, 1.0/ 2.8);
200 return (0.0 >
E) ? 0.0 : pow(
E, 2.8);
205 const double a = 1.1115;
206 const double b = 0.0228;
208 return (0.0 > Lc) ? 0.0
209 : (
b > Lc) ? 4.000 * Lc
210 :
a * pow(Lc, 0.45) - (
a - 1.0);
215 const double a = 1.1115;
216 const double b = 4.000 * 0.0228;
218 return (0.0 >
E) ? 0.0
219 : (
b >
E) ?
E / 4.000
220 : pow((
E + (
a - 1.0)) /
a, 1.0 / 0.45);
230 return (0.01 > Lc) ? 0.0 : 1.0 + log10(Lc) / 2.0;
235 return (0.0 >
E) ? 0.01 : pow(10.0, 2.0 * (
E - 1.0));
241 return (0.00316227766 > Lc) ? 0.0 : 1.0 + log10(Lc) / 2.5;
246 return (0.0 >
E) ? 0.00316227766 : pow(10.0, 2.5 * (
E - 1.0));
254 return (-
b >= Lc) ? -
a * pow(-Lc, 0.45) + (
a - 1.0)
255 : (
b > Lc) ? 4.500 * Lc
256 :
a * pow( Lc, 0.45) - (
a - 1.0);
264 return (-
b >=
E) ? -pow((-
E + (
a - 1.0)) /
a, 1.0 / 0.45)
265 : (
b >
E) ?
E / 4.500
266 : pow((
E + (
a - 1.0)) /
a, 1.0 / 0.45);
274 return (-0.0045 >= Lc) ? -(
a * pow(-4.0 * Lc, 0.45) + (
a - 1.0)) / 4.0
275 : (
b > Lc) ? 4.500 * Lc
276 :
a * pow( Lc, 0.45) - (
a - 1.0);
284 return (-0.02025 >=
E) ? -pow((-4.0 *
E - (
a - 1.0)) /
a, 1.0 / 0.45) / 4.0
285 : (
b >
E) ?
E / 4.500
286 : pow((
E + (
a - 1.0)) /
a, 1.0 / 0.45);
291 const double a = 1.055;
292 const double b = 0.0031308;
294 return (0.0 > Lc) ? 0.0
295 : (
b > Lc) ? 12.92 * Lc
296 :
a * pow(Lc, 1.0 / 2.4) - (
a - 1.0);
301 const double a = 1.055;
302 const double b = 12.92 * 0.0031308;
304 return (0.0 >
E) ? 0.0
305 : (
b >
E) ?
E / 12.92
306 : pow((
E + (
a - 1.0)) /
a, 2.4);
310 #define PQ_c1 ( 3424.0 / 4096.0)
311 #define PQ_c2 ( 32.0 * 2413.0 / 4096.0)
312 #define PQ_c3 ( 32.0 * 2392.0 / 4096.0)
313 #define PQ_m (128.0 * 2523.0 / 4096.0)
314 #define PQ_n ( 0.25 * 2610.0 / 4096.0)
320 const double c3 =
PQ_c3;
321 const double m =
PQ_m;
322 const double n =
PQ_n;
323 const double L = Lc / 10000.0;
324 const double Ln = pow(
L, n);
326 return (0.0 > Lc) ? 0.0
327 : pow((
c1 +
c2 * Ln) / (1.0 + c3 * Ln), m);
335 const double c3 =
PQ_c3;
336 const double m =
PQ_m;
337 const double n =
PQ_n;
338 const double Em = pow(
E, 1.0 / m);
340 return (
c1 > Em) ? 0.0
341 : 10000.0 * pow((Em -
c1) / (
c2 - c3 * Em), 1.0 / n);
349 return (0.0 > Lc) ? 0.0 : pow(
DCI_L /
DCI_P * Lc, 1.0 / 2.6);
357 #define HLG_a 0.17883277
358 #define HLG_b 0.28466892
359 #define HLG_c 0.55991073
368 return (0.0 > Lc) ? 0.0 :
369 (Lc <= 1.0 / 12.0 ? sqrt(3.0 * Lc) :
a *
log(12.0 * Lc -
b) +
c);
377 return (0.0 >
E) ? 0.0 :
378 (
E <= 0.5 ?
E *
E / 3.0 : (
exp((
E -
c) /
a) +
b) / 12.0);
435 for (
int i = 0;
i < 3;
i++)
436 E[
i] = (Lw - Lb) *
E[
i] + Lb;
441 for (
int i = 0;
i < 3;
i++)
442 L[
i] = (
L[
i] - Lb) / (Lw - Lb);
445 #define WRAP_SDR_OETF(name) \
446 static void oetf_##name(double L[3]) \
448 for (int i = 0; i < 3; i++) \
449 L[i] = trc_##name(L[i]); \
452 static void oetf_##name##_inv(double E[3]) \
454 for (int i = 0; i < 3; i++) \
455 E[i] = trc_##name##_inv(E[i]); \
462 #define WRAP_SDR_EOTF(name) \
463 static void eotf_##name(double Lw, double Lb, double E[3]) \
465 oetf_##name##_inv(E); \
466 eotf_linear(Lw, Lb, E); \
469 static void eotf_##name##_inv(double Lw, double Lb, double L[3]) \
471 eotf_linear_inv(Lw, Lb, L); \
481 const double Lw_inv = pow(Lw, 1.0 / 2.4);
482 const double Lb_inv = pow(Lb, 1.0 / 2.4);
483 const double a = pow(Lw_inv - Lb_inv, 2.4);
484 const double b = Lb_inv / (Lw_inv - Lb_inv);
486 for (
int i = 0;
i < 3;
i++)
487 E[
i] = (-
b >
E[
i]) ? 0.0 :
a * pow(
E[
i] +
b, 2.4);
492 const double Lw_inv = pow(Lw, 1.0 / 2.4);
493 const double Lb_inv = pow(Lb, 1.0 / 2.4);
494 const double a = pow(Lw_inv - Lb_inv, 2.4);
495 const double b = Lb_inv / (Lw_inv - Lb_inv);
497 for (
int i = 0;
i < 3;
i++)
498 L[
i] = (0.0 >
L[
i]) ? 0.0 : pow(
L[
i] /
a, 1.0 / 2.4) -
b;
503 for (
int i = 0;
i < 3;
i++)
509 for (
int i = 0;
i < 3;
i++)
516 #define DCI_X (42.94 / DCI_L)
517 #define DCI_Z (45.82 / DCI_L)
521 const double Lw[3] = {
DCI_X * Lw_Y, Lw_Y,
DCI_Z * Lw_Y };
522 const double Lb[3] = {
DCI_X * Lb_Y, Lb_Y,
DCI_Z * Lb_Y };
524 for (
int i = 0;
i < 3;
i++) {
526 E[
i] =
E[
i] * (Lw[
i] - Lb[
i]) + Lb[
i];
532 const double Lw[3] = {
DCI_X * Lw_Y, Lw_Y,
DCI_Z * Lw_Y };
533 const double Lb[3] = {
DCI_X * Lb_Y, Lb_Y,
DCI_Z * Lb_Y };
535 for (
int i = 0;
i < 3;
i++) {
536 L[
i] = (
L[
i] - Lb[
i]) / (Lw[
i] - Lb[
i]);
543 const double gamma =
fmax(1.2 + 0.42 * log10(Lw / 1000.0), 1.0);
552 const double beta = sqrt(3 * pow(Lb / Lw, 1.0 / gamma));
555 for (
int i = 0;
i < 3;
i++)
558 luma = 0.2627 *
E[0] + 0.6780 *
E[1] + 0.0593 *
E[2];
559 luma = pow(
fmax(luma, 0.0), gamma - 1.0);
560 for (
int i = 0;
i < 3;
i++)
566 const double gamma =
fmax(1.2 + 0.42 * log10(Lw / 1000.0), 1.0);
567 const double beta = sqrt(3 * pow(Lb / Lw, 1 / gamma));
568 double luma = 0.2627 *
L[0] + 0.6780 *
L[1] + 0.0593 *
L[2];
571 luma = pow(luma / Lw, (1 - gamma) / gamma);
572 for (
int i = 0;
i < 3;
i++)
575 L[0] =
L[1] =
L[2] = 0.0;
578 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.
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)
#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]
@ 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)
@ 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
@ 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_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
static void eotf_linear(const double Lw, const double Lb, double E[3])
@ AVCOL_TRC_BT709
also ITU-R BT1361
@ 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.
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".
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
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_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)