summaryrefslogtreecommitdiff
path: root/libavfilter/fflcms2.c
diff options
context:
space:
mode:
authorLeo Izen <leo.izen@gmail.com>2022-05-28 09:30:36 -0400
committerRonald S. Bultje <rsbultje@gmail.com>2022-06-01 13:52:38 -0400
commitd42b410e05ad1c4d6e74aa981b4a4423103291fb (patch)
treeef3a78871469fd303caa770e888d78779998d030 /libavfilter/fflcms2.c
parent77b529fbd228fe30a870e3157f051885b436ad92 (diff)
avutil/csp: create public API for colorspace structs
This commit moves some of the functionality from avfilter/colorspace into avutil/csp and exposes it as a public API so it can be used by libavcodec and/or libavformat. It also converts those structs from double values to AVRational to make regression testing easier and more consistent. Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
Diffstat (limited to 'libavfilter/fflcms2.c')
-rw-r--r--libavfilter/fflcms2.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/libavfilter/fflcms2.c b/libavfilter/fflcms2.c
index efc7cb5189..fd370fb310 100644
--- a/libavfilter/fflcms2.c
+++ b/libavfilter/fflcms2.c
@@ -18,6 +18,7 @@
*/
#include "libavutil/color_utils.h"
+#include "libavutil/csp.h"
#include "fflcms2.h"
@@ -148,20 +149,20 @@ int ff_icc_profile_generate(FFIccContext *s,
cmsHPROFILE *out_profile)
{
cmsToneCurve *tonecurve;
- const struct ColorPrimaries *prim;
+ const AVColorPrimariesDesc *prim;
int ret;
- if (!(prim = ff_get_color_primaries(color_prim)))
+ if (!(prim = av_csp_primaries_desc_from_id(color_prim)))
return AVERROR_INVALIDDATA;
if ((ret = get_curve(s, color_trc, &tonecurve)) < 0)
return ret;
*out_profile = cmsCreateRGBProfileTHR(s->ctx,
- &(cmsCIExyY) { prim->wp.xw, prim->wp.yw, 1.0 },
+ &(cmsCIExyY) { av_q2d(prim->wp.x), av_q2d(prim->wp.y), 1.0 },
&(cmsCIExyYTRIPLE) {
- .Red = { prim->prim.xr, prim->prim.yr, 1.0 },
- .Green = { prim->prim.xg, prim->prim.yg, 1.0 },
- .Blue = { prim->prim.xb, prim->prim.yb, 1.0 },
+ .Red = { av_q2d(prim->prim.r.x), av_q2d(prim->prim.r.y), 1.0 },
+ .Green = { av_q2d(prim->prim.g.x), av_q2d(prim->prim.g.y), 1.0 },
+ .Blue = { av_q2d(prim->prim.b.x), av_q2d(prim->prim.b.y), 1.0 },
},
(cmsToneCurve *[3]) { tonecurve, tonecurve, tonecurve }
);
@@ -194,15 +195,15 @@ int ff_icc_profile_attach(FFIccContext *s, cmsHPROFILE profile, AVFrame *frame)
return 0;
}
-static av_always_inline void XYZ_xy(cmsCIEXYZ XYZ, double *x, double *y)
+static av_always_inline void XYZ_xy(cmsCIEXYZ XYZ, AVCIExy *xy)
{
double k = 1.0 / (XYZ.X + XYZ.Y + XYZ.Z);
- *x = k * XYZ.X;
- *y = k * XYZ.Y;
+ xy->x = av_d2q(k * XYZ.X, 100000);
+ xy->y = av_d2q(k * XYZ.Y, 100000);
}
int ff_icc_profile_read_primaries(FFIccContext *s, cmsHPROFILE profile,
- struct ColorPrimaries *out_primaries)
+ AVColorPrimariesDesc *out_primaries)
{
static const uint8_t testprimaries[4][3] = {
{ 0xFF, 0, 0 }, /* red */
@@ -211,8 +212,8 @@ int ff_icc_profile_read_primaries(FFIccContext *s, cmsHPROFILE profile,
{ 0xFF, 0xFF, 0xFF }, /* white */
};
- struct WhitepointCoefficients *wp = &out_primaries->wp;
- struct PrimaryCoefficients *prim = &out_primaries->prim;
+ AVWhitepointCoefficients *wp = &out_primaries->wp;
+ AVPrimaryCoefficients *prim = &out_primaries->prim;
cmsFloat64Number prev_adapt;
cmsHPROFILE xyz;
cmsHTRANSFORM tf;
@@ -241,10 +242,10 @@ int ff_icc_profile_read_primaries(FFIccContext *s, cmsHPROFILE profile,
cmsDoTransform(tf, testprimaries, dst, 4);
cmsDeleteTransform(tf);
- XYZ_xy(dst[0], &prim->xr, &prim->yr);
- XYZ_xy(dst[1], &prim->xg, &prim->yg);
- XYZ_xy(dst[2], &prim->xb, &prim->yb);
- XYZ_xy(dst[3], &wp->xw, &wp->yw);
+ XYZ_xy(dst[0], &prim->r);
+ XYZ_xy(dst[1], &prim->g);
+ XYZ_xy(dst[2], &prim->b);
+ XYZ_xy(dst[3], wp);
return 0;
}