Path: blob/master/dep/ffmpeg/include/libavutil/csp.h
7490 views
/*1* Copyright (c) 2015 Kevin Wheatley <[email protected]>2* Copyright (c) 2016 Ronald S. Bultje <[email protected]>3* Copyright (c) 2023 Leo Izen <[email protected]>4*5* This file is part of FFmpeg.6*7* FFmpeg is free software; you can redistribute it and/or8* modify it under the terms of the GNU Lesser General Public9* License as published by the Free Software Foundation; either10* version 2.1 of the License, or (at your option) any later version.11*12* FFmpeg is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU15* Lesser General Public License for more details.16*17* You should have received a copy of the GNU Lesser General Public18* License along with FFmpeg; if not, write to the Free Software19* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA20*/2122#ifndef AVUTIL_CSP_H23#define AVUTIL_CSP_H2425#include "pixfmt.h"26#include "rational.h"2728/**29* @file30* Colorspace value utility functions for libavutil.31* @ingroup lavu_math_csp32* @author Ronald S. Bultje <[email protected]>33* @author Leo Izen <[email protected]>34* @author Kevin Wheatley <[email protected]>35*/3637/**38* @defgroup lavu_math_csp Colorspace Utility39* @ingroup lavu_math40* @{41*/4243/**44* Struct containing luma coefficients to be used for RGB to YUV/YCoCg, or similar45* calculations.46*/47typedef struct AVLumaCoefficients {48AVRational cr, cg, cb;49} AVLumaCoefficients;5051/**52* Struct containing chromaticity x and y values for the standard CIE 193153* chromaticity definition.54*/55typedef struct AVCIExy {56AVRational x, y;57} AVCIExy;5859/**60* Struct defining the red, green, and blue primary locations in terms of CIE61* 1931 chromaticity x and y.62*/63typedef struct AVPrimaryCoefficients {64AVCIExy r, g, b;65} AVPrimaryCoefficients;6667/**68* Struct defining white point location in terms of CIE 1931 chromaticity x69* and y.70*/71typedef AVCIExy AVWhitepointCoefficients;7273/**74* Struct that contains both white point location and primaries location, providing75* the complete description of a color gamut.76*/77typedef struct AVColorPrimariesDesc {78AVWhitepointCoefficients wp;79AVPrimaryCoefficients prim;80} AVColorPrimariesDesc;8182/**83* Function pointer representing a double -> double transfer function that84* performs either an OETF transfer function, or alternatively an inverse EOTF85* function (in particular, for SMPTE ST 2084 / PQ). This function inputs86* linear light, and outputs gamma encoded light.87*88* See ITU-T H.273 for more information.89*/90typedef double (*av_csp_trc_function)(double);9192/**93* Retrieves the Luma coefficients necessary to construct a conversion matrix94* from an enum constant describing the colorspace.95* @param csp An enum constant indicating YUV or similar colorspace.96* @return The Luma coefficients associated with that colorspace, or NULL97* if the constant is unknown to libavutil.98*/99const AVLumaCoefficients *av_csp_luma_coeffs_from_avcsp(enum AVColorSpace csp);100101/**102* Retrieves a complete gamut description from an enum constant describing the103* color primaries.104* @param prm An enum constant indicating primaries105* @return A description of the colorspace gamut associated with that enum106* constant, or NULL if the constant is unknown to libavutil.107*/108const AVColorPrimariesDesc *av_csp_primaries_desc_from_id(enum AVColorPrimaries prm);109110/**111* Detects which enum AVColorPrimaries constant corresponds to the given complete112* gamut description.113* @see enum AVColorPrimaries114* @param prm A description of the colorspace gamut115* @return The enum constant associated with this gamut, or116* AVCOL_PRI_UNSPECIFIED if no clear match can be identified.117*/118enum AVColorPrimaries av_csp_primaries_id_from_desc(const AVColorPrimariesDesc *prm);119120/**121* Determine a suitable 'gamma' value to match the supplied122* AVColorTransferCharacteristic.123*124* See Apple Technical Note TN2257 (https://developer.apple.com/library/mac/technotes/tn2257/_index.html)125*126* This function returns the gamma exponent for the OETF. For example, sRGB is approximated127* by gamma 2.2, not by gamma 0.45455.128*129* @return Will return an approximation to the simple gamma function matching130* the supplied Transfer Characteristic, Will return 0.0 for any131* we cannot reasonably match against.132*/133double av_csp_approximate_trc_gamma(enum AVColorTransferCharacteristic trc);134135/**136* Determine the function needed to apply the given137* AVColorTransferCharacteristic to linear input.138*139* The function returned should expect a nominal domain and range of [0.0-1.0]140* values outside of this range maybe valid depending on the chosen141* characteristic function.142*143* @return Will return pointer to the function matching the144* supplied Transfer Characteristic. If unspecified will145* return NULL:146*/147av_csp_trc_function av_csp_trc_func_from_id(enum AVColorTransferCharacteristic trc);148149/**150* Returns the mathematical inverse of the corresponding TRC function.151*/152av_csp_trc_function av_csp_trc_func_inv_from_id(enum AVColorTransferCharacteristic trc);153154/**155* Function pointer representing an ITU EOTF transfer for a given reference156* display configuration.157*158* @param Lw The white point luminance of the display, in nits (cd/m^2).159* @param Lb The black point luminance of the display, in nits (cd/m^2).160*/161typedef void (*av_csp_eotf_function)(double Lw, double Lb, double c[3]);162163/**164* Returns the ITU EOTF corresponding to a given TRC. This converts from the165* signal level [0,1] to the raw output display luminance in nits (cd/m^2).166* This is done per channel in RGB space, except for AVCOL_TRC_SMPTE428, which167* assumes CIE XYZ in- and output.168*169* @return A pointer to the function implementing the given TRC, or NULL if no170* such function is defined.171*172* @note In general, the resulting function is defined (wherever possible) for173* out-of-range values, even though these values do not have a physical174* meaning on the given display. Users should clamp inputs (or outputs)175* if this behavior is not desired.176*177* This is also the case for functions like PQ, which are defined over an178* absolute signal range independent of the target display capabilities.179*/180av_csp_eotf_function av_csp_itu_eotf(enum AVColorTransferCharacteristic trc);181182/**183* Returns the mathematical inverse of the corresponding EOTF.184*/185av_csp_eotf_function av_csp_itu_eotf_inv(enum AVColorTransferCharacteristic trc);186187/**188* @}189*/190191#endif /* AVUTIL_CSP_H */192193194