Go to the documentation of this file.
32 memset(
s, 0,
sizeof(*
s));
34 s->ctx = cmsCreateContext(
NULL,
s);
38 cmsSetLogErrorHandlerTHR(
s->ctx,
log_cb);
45 cmsFreeToneCurve(
s->curves[
i]);
46 cmsDeleteContext(
s->ctx);
47 memset(
s, 0,
sizeof(*
s));
51 cmsToneCurve **out_curve)
61 s->curves[trc] = cmsBuildGamma(
s->ctx, 1.0);
64 s->curves[trc] = cmsBuildGamma(
s->ctx, 2.2);
67 s->curves[trc] = cmsBuildGamma(
s->ctx, 2.8);
73 s->curves[trc] = cmsBuildParametricToneCurve(
s->ctx, 4, (
double[5]) {
76 1 - 1/1.099296826809442,
78 4.5 * 0.018053968510807,
82 s->curves[trc] = cmsBuildParametricToneCurve(
s->ctx, 4, (
double[5]) {
91 s->curves[trc] = cmsBuildParametricToneCurve(
s->ctx, 8, (
double[5]) {
100 s->curves[trc] = cmsBuildParametricToneCurve(
s->ctx, 8, (
double[5]) {
109 s->curves[trc] = cmsBuildParametricToneCurve(
s->ctx, 4, (
double[5]) {
118 s->curves[trc] = cmsBuildParametricToneCurve(
s->ctx, 2, (
double[3]) {
120 pow(52.37/48.0, 1/2.6),
141 *out_curve =
s->curves[trc];
148 cmsHPROFILE *out_profile)
150 cmsToneCurve *tonecurve;
159 *out_profile = cmsCreateRGBProfileTHR(
s->ctx,
160 &(cmsCIExyY) { av_q2d(prim->wp.x), av_q2d(prim->wp.y), 1.0 },
162 .Red = { av_q2d(prim->prim.r.x), av_q2d(prim->prim.r.y), 1.0 },
163 .Green = { av_q2d(prim->prim.g.x), av_q2d(prim->prim.g.y), 1.0 },
164 .Blue = { av_q2d(prim->prim.b.x), av_q2d(prim->prim.b.y), 1.0 },
166 (cmsToneCurve *[3]) { tonecurve, tonecurve, tonecurve }
174 cmsUInt32Number
size;
199 double k = 1.0 / (
XYZ.X +
XYZ.Y +
XYZ.Z);
215 cmsCIEXYZ *white,
fixed;
221 if (cmsGetEncodedICCversion(
profile) >= 0x4000000) {
222 switch (cmsGetHeaderRenderingIntent(
profile)) {
223 case INTENT_RELATIVE_COLORIMETRIC:
224 case INTENT_ABSOLUTE_COLORIMETRIC: ;
229 if (!(white = cmsReadTag(
profile, cmsSigMediaWhitePointTag)))
235 "profile media white point tag (expected %.4f %.4f, "
244 if (!cmsWriteTag(
profile, cmsSigMediaWhitePointTag, &
fixed))
258 static const uint8_t testprimaries[4][3] = {
262 { 0xFF, 0xFF, 0xFF },
267 cmsFloat64Number prev_adapt;
272 xyz = cmsCreateXYZProfileTHR(
s->ctx);
277 prev_adapt = cmsSetAdaptationStateTHR(
s->ctx, 0.0);
278 tf = cmsCreateTransformTHR(
s->ctx,
profile, TYPE_RGB_8, xyz, TYPE_XYZ_DBL,
279 INTENT_ABSOLUTE_COLORIMETRIC,
283 cmsFLAGS_NOOPTIMIZE |
284 cmsFLAGS_LOWRESPRECALC |
285 cmsFLAGS_GRIDPOINTS(2));
286 cmsSetAdaptationStateTHR(
s->ctx, prev_adapt);
287 cmsCloseProfile(xyz);
293 cmsDoTransform(tf, testprimaries,
dst, 4);
294 cmsDeleteTransform(tf);
306 static const uint8_t testramp[16][3] = {
328 cmsToneCurve *tonecurve;
335 ref = cmsCreateGrayProfileTHR(
s->ctx, cmsD50_xyY(), tonecurve);
339 tf = cmsCreateTransformTHR(
s->ctx,
profile, TYPE_RGB_8,
ref, TYPE_GRAY_DBL,
340 INTENT_RELATIVE_COLORIMETRIC,
341 cmsFLAGS_NOCACHE | cmsFLAGS_NOOPTIMIZE);
342 cmsCloseProfile(
ref);
349 cmsDeleteTransform(tf);
static void error(const char *err)
#define AV_LOG_WARNING
Something somehow does not look correct.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int ff_icc_profile_read_primaries(FFIccContext *s, cmsHPROFILE profile, AVColorPrimariesDesc *out_primaries)
Read the color primaries and white point coefficients encoded by an ICC profile, and return the raw v...
AVColorTransferCharacteristic
Color Transfer Characteristic.
AVWhitepointCoefficients wp
Struct that contains both white point location and primaries location, providing the complete descrip...
uint8_t * data
The data buffer.
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
This structure describes decoded (raw) audio or video data.
@ AVCOL_TRC_NB
Not part of ABI.
@ AVCOL_TRC_BT2020_12
ITU-R BT2020 for 12-bit system.
AVColorPrimaries
Chromaticity coordinates of the source primaries.
AVRational av_sub_q(AVRational b, AVRational c)
Subtract one rational from another.
int ff_icc_profile_attach(FFIccContext *s, cmsHPROFILE profile, AVFrame *frame)
Attach an ICC profile to a frame.
static av_always_inline void XYZ_xy(cmsCIEXYZ XYZ, AVCIExy *xy)
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
int ff_icc_context_init(FFIccContext *s, void *avctx)
Initializes an FFIccContext.
Struct defining the red, green, and blue primary locations in terms of CIE 1931 chromaticity x and y.
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
@ 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 const AVCIExy wp_d50
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
static int get_curve(FFIccContext *s, enum AVColorTransferCharacteristic trc, cmsToneCurve **out_curve)
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.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
void ff_icc_context_uninit(FFIccContext *s)
static __device__ float fabs(float a)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Rational number (pair of numerator and denominator).
@ AVCOL_TRC_IEC61966_2_4
IEC 61966-2-4.
@ AV_FRAME_DATA_ICC_PROFILE
The data contains an ICC profile as an opaque octet buffer following the format described by ISO 1507...
AVFrameSideData * av_frame_new_side_data_from_buf(AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef *buf)
Add a new side data to a frame from an existing AVBufferRef.
@ AVCOL_TRC_BT2020_10
ITU-R BT2020 for 10-bit system.
int ff_icc_profile_detect_transfer(FFIccContext *s, cmsHPROFILE profile, enum AVColorTransferCharacteristic *out_trc)
Attempt detecting the transfer characteristic that best approximates the transfer function encoded by...
Struct containing chromaticity x and y values for the standard CIE 1931 chromaticity definition.
int ff_icc_profile_generate(FFIccContext *s, enum AVColorPrimaries color_prim, enum AVColorTransferCharacteristic color_trc, cmsHPROFILE *out_profile)
Generate an ICC profile for a given combination of color primaries and transfer function.
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
@ AVCOL_TRC_LOG
"Logarithmic transfer characteristic (100:1 range)"
static AVRational av_make_q(int num, int den)
Create an AVRational.
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
#define AVERROR_EXTERNAL
Generic error in an external library.
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
size_t size
Size of data in bytes.
@ AVCOL_TRC_BT709
also ITU-R BT1361
#define i(width, name, range_min, range_max)
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
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
A reference to a data buffer.
int ff_icc_profile_sanitize(FFIccContext *s, cmsHPROFILE profile)
Sanitize an ICC profile to try and fix badly broken values.
AVRational av_add_q(AVRational b, AVRational c)
Add two rationals.
AVPrimaryCoefficients prim
#define fixed(width, name, value)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
@ AVCOL_TRC_SMPTE428
SMPTE ST 428-1.
static void log_cb(cmsContext ctx, cmsUInt32Number error, const char *str)
static av_always_inline AVRational abs_sub_q(AVRational r1, AVRational r2)