]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/vf_colorspace.c
lavfi/colorspace: move some functions to common file
[ffmpeg] / libavfilter / vf_colorspace.c
index f8d1ecdf4a82a69d1cc81554a4714d4c1844d200..2120199beed8652ff181588d2b8a618528c49d18 100644 (file)
@@ -170,78 +170,6 @@ typedef struct ColorSpaceContext {
 // 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
@@ -669,7 +597,7 @@ static int create_filtergraph(AVFilterContext *ctx,
         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",
@@ -682,7 +610,7 @@ static int create_filtergraph(AVFilterContext *ctx,
     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) {
@@ -724,7 +652,7 @@ static int create_filtergraph(AVFilterContext *ctx,
             }
             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++) {
@@ -757,7 +685,7 @@ static int create_filtergraph(AVFilterContext *ctx,
             }
             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++) {