[FFmpeg-devel] [PATCH 1/4] avfilter/vf_colormatrix: increase precision

Thomas Mundt loudmax at yahoo.de
Fri Mar 25 23:31:12 CET 2016


Signed-off-by: Thomas Mundt <loudmax at yahoo.de>
---
 libavfilter/vf_colormatrix.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/libavfilter/vf_colormatrix.c b/libavfilter/vf_colormatrix.c
index 4a57fe0..ecd7a97 100644
--- a/libavfilter/vf_colormatrix.c
+++ b/libavfilter/vf_colormatrix.c
@@ -40,19 +40,11 @@
 #define NS(n) ((n) < 0 ? (int)((n)*65536.0-0.5+DBL_EPSILON) : (int)((n)*65536.0+0.5))
 #define CB(n) av_clip_uint8(n)
 
-static const double yuv_coeff[4][3][3] = {
-    { { +0.7152, +0.0722, +0.2126 }, // Rec.709 (0)
-      { -0.3850, +0.5000, -0.1150 },
-      { -0.4540, -0.0460, +0.5000 } },
-    { { +0.5900, +0.1100, +0.3000 }, // FCC (1)
-      { -0.3310, +0.5000, -0.1690 },
-      { -0.4210, -0.0790, +0.5000 } },
-    { { +0.5870, +0.1140, +0.2990 }, // Rec.601 (ITU-R BT.470-2/SMPTE 170M) (2)
-      { -0.3313, +0.5000, -0.1687 },
-      { -0.4187, -0.0813, +0.5000 } },
-    { { +0.7010, +0.0870, +0.2120 }, // SMPTE 240M (3)
-      { -0.3840, +0.5000, -0.1160 },
-      { -0.4450, -0.0550, +0.5000 } },
+static const double yuv_coeff_luma[4][3] = { 
+    { +0.7152, +0.0722, +0.2126 }, // Rec.709 (0)
+    { +0.5900, +0.1100, +0.3000 }, // FCC (1)
+    { +0.5870, +0.1140, +0.2990 }, // Rec.601 (ITU-R BT.470-2/SMPTE 170M) (2)
+    { +0.7010, +0.0870, +0.2120 }, // SMPTE 240M (3)
 };
 
 enum ColorMode {
@@ -148,11 +140,25 @@ static void solve_coefficients(double cm[3][3], double rgb[3][3], const double y
 static void calc_coefficients(AVFilterContext *ctx)
 {
     ColorMatrixContext *color = ctx->priv;
+    double yuv_coeff[4][3][3];
     double rgb_coeffd[4][3][3];
     double yuv_convertd[16][3][3];
+    double bscale, rscale;
     int v = 0;
     int i, j, k;
-
+    for (i = 0; i < 4; i++) {
+        yuv_coeff[i][0][0] = yuv_coeff_luma[i][0];
+        yuv_coeff[i][0][1] = yuv_coeff_luma[i][1];
+        yuv_coeff[i][0][2] = yuv_coeff_luma[i][2];
+        bscale = 0.5 / (yuv_coeff[i][0][1] - 1.0);
+        rscale = 0.5 / (yuv_coeff[i][0][2] - 1.0);
+        yuv_coeff[i][1][0] = bscale * yuv_coeff[i][0][0];
+        yuv_coeff[i][1][1] = 0.5;
+        yuv_coeff[i][1][2] = bscale * yuv_coeff[i][0][2];
+        yuv_coeff[i][2][0] = rscale * yuv_coeff[i][0][0];
+        yuv_coeff[i][2][1] = rscale * yuv_coeff[i][0][1];
+        yuv_coeff[i][2][2] = 0.5;
+    }
     for (i = 0; i < 4; i++)
         inverse3x3(rgb_coeffd[i], yuv_coeff[i]);
     for (i = 0; i < 4; i++) {
-- 
2.7.4.windows.1




More information about the ffmpeg-devel mailing list