// FIXME dithering if bitdepth goes down?
// FIXME bitexact for fate integration?
-static const double ycgco_matrix[3][3] =
-{
- { 0.25, 0.5, 0.25 },
- { -0.25, 0.5, -0.25 },
- { 0.5, 0, -0.5 },
-};
-
-static const double gbr_matrix[3][3] =
-{
- { 0, 1, 0 },
- { 0, -0.5, 0.5 },
- { 0.5, -0.5, 0 },
-};
-
-/*
- * All constants explained in e.g. https://linuxtv.org/downloads/v4l-dvb-apis/ch02s06.html
- * The older ones (bt470bg/m) are also explained in their respective ITU docs
- * (e.g. https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf)
- * whereas the newer ones can typically be copied directly from wikipedia :)
- */
-static const struct LumaCoefficients luma_coefficients[AVCOL_SPC_NB] = {
- [AVCOL_SPC_FCC] = { 0.30, 0.59, 0.11 },
- [AVCOL_SPC_BT470BG] = { 0.299, 0.587, 0.114 },
- [AVCOL_SPC_SMPTE170M] = { 0.299, 0.587, 0.114 },
- [AVCOL_SPC_BT709] = { 0.2126, 0.7152, 0.0722 },
- [AVCOL_SPC_SMPTE240M] = { 0.212, 0.701, 0.087 },
- [AVCOL_SPC_YCOCG] = { 0.25, 0.5, 0.25 },
- [AVCOL_SPC_RGB] = { 1, 1, 1 },
- [AVCOL_SPC_BT2020_NCL] = { 0.2627, 0.6780, 0.0593 },
- [AVCOL_SPC_BT2020_CL] = { 0.2627, 0.6780, 0.0593 },
-};
-
-static const struct LumaCoefficients *get_luma_coefficients(enum AVColorSpace csp)
-{
- const struct LumaCoefficients *coeffs;
-
- if (csp >= AVCOL_SPC_NB)
- return NULL;
- coeffs = &luma_coefficients[csp];
- if (!coeffs->cr)
- return NULL;
-
- return coeffs;
-}
-
-static void fill_rgb2yuv_table(const struct LumaCoefficients *coeffs,
- double rgb2yuv[3][3])
-{
- double bscale, rscale;
-
- // special ycgco matrix
- if (coeffs->cr == 0.25 && coeffs->cg == 0.5 && coeffs->cb == 0.25) {
- memcpy(rgb2yuv, ycgco_matrix, sizeof(double) * 9);
- return;
- } else if (coeffs->cr == 1 && coeffs->cg == 1 && coeffs->cb == 1) {
- memcpy(rgb2yuv, gbr_matrix, sizeof(double) * 9);
- return;
- }
-
- rgb2yuv[0][0] = coeffs->cr;
- rgb2yuv[0][1] = coeffs->cg;
- rgb2yuv[0][2] = coeffs->cb;
- bscale = 0.5 / (coeffs->cb - 1.0);
- rscale = 0.5 / (coeffs->cr - 1.0);
- rgb2yuv[1][0] = bscale * coeffs->cr;
- rgb2yuv[1][1] = bscale * coeffs->cg;
- rgb2yuv[1][2] = 0.5;
- rgb2yuv[2][0] = 0.5;
- rgb2yuv[2][1] = rscale * coeffs->cg;
- rgb2yuv[2][2] = rscale * coeffs->cb;
-}
-
// FIXME I'm pretty sure gamma22/28 also have a linear toe slope, but I can't
// find any actual tables that document their real values...
// See http://www.13thmonkey.org/~boris/gammacorrection/ first graph why it matters
s->delin_lut[n] = av_clip_int16(lrint(d * 28672.0));
// linearize
- if (v <= -in_beta) {
+ if (v <= -in_beta * in_delta) {
l = -pow((1.0 - in_alpha - v) * in_ialpha, in_igamma);
- } else if (v < in_beta) {
+ } else if (v < in_beta * in_delta) {
l = v * in_idelta;
} else {
l = pow((v + in_alpha - 1.0) * in_ialpha, in_igamma);
s->yuv2yuv(out_data, td->out_linesize, in_data, td->in_linesize, w, h,
s->yuv2yuv_coeffs, s->yuv_offset);
} else {
- // FIXME maybe (for caching effciency) do pipeline per-line instead of
+ // FIXME maybe (for caching efficiency) do pipeline per-line instead of
// full buffer per function? (Or, since yuv2rgb requires 2 lines: per
// 2 lines, for yuv420.)
/*
s->in_rng = in->color_range;
if (s->user_irng != AVCOL_RANGE_UNSPECIFIED)
s->in_rng = s->user_irng;
- s->in_lumacoef = get_luma_coefficients(s->in_csp);
+ s->in_lumacoef = ff_get_luma_coefficients(s->in_csp);
if (!s->in_lumacoef) {
av_log(ctx, AV_LOG_ERROR,
"Unsupported input colorspace %d (%s)\n",
if (!s->out_lumacoef) {
s->out_csp = out->colorspace;
s->out_rng = out->color_range;
- s->out_lumacoef = get_luma_coefficients(s->out_csp);
+ s->out_lumacoef = ff_get_luma_coefficients(s->out_csp);
if (!s->out_lumacoef) {
if (s->out_csp == AVCOL_SPC_UNSPECIFIED) {
if (s->user_all == CS_UNSPECIFIED) {
}
for (n = 0; n < 8; n++)
s->yuv_offset[0][n] = off;
- fill_rgb2yuv_table(s->in_lumacoef, rgb2yuv);
+ ff_fill_rgb2yuv_table(s->in_lumacoef, rgb2yuv);
ff_matrix_invert_3x3(rgb2yuv, yuv2rgb);
bits = 1 << (in_desc->comp[0].depth - 1);
for (n = 0; n < 3; n++) {
}
for (n = 0; n < 8; n++)
s->yuv_offset[1][n] = off;
- fill_rgb2yuv_table(s->out_lumacoef, rgb2yuv);
+ ff_fill_rgb2yuv_table(s->out_lumacoef, rgb2yuv);
bits = 1 << (29 - out_desc->comp[0].depth);
for (out_rng = s->out_y_rng, n = 0; n < 3; n++, out_rng = s->out_uv_rng) {
for (m = 0; m < 3; m++) {
return 0;
}
-static int init(AVFilterContext *ctx)
+static av_cold int init(AVFilterContext *ctx)
{
ColorSpaceContext *s = ctx->priv;
ENUM("smpte432", AVCOL_PRI_SMPTE432, "prm"),
ENUM("bt2020", AVCOL_PRI_BT2020, "prm"),
ENUM("jedec-p22", AVCOL_PRI_JEDEC_P22, "prm"),
+ ENUM("ebu3213", AVCOL_PRI_EBU3213, "prm"),
{ "trc", "Output transfer characteristics",
OFFSET(user_trc), AV_OPT_TYPE_INT, { .i64 = AVCOL_TRC_UNSPECIFIED },