[FFmpeg-cvslog] avfilter/vf_colormatrix: increase precision

Thomas Mundt git at videolan.org
Sun Jun 5 19:45:59 CEST 2016


ffmpeg | branch: master | Thomas Mundt <loudmax at yahoo.de> | Sat Mar 26 11:53:36 2016 +0100| [2e395bbccffed726bd73e841740f767218f791bc] | committer: Michael Niedermayer

avfilter/vf_colormatrix: increase precision

Signed-off-by: Thomas Mundt <loudmax at yahoo.de>
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2e395bbccffed726bd73e841740f767218f791bc
---

 libavfilter/vf_colormatrix.c       |   38 +++++++++++++++++++++---------------
 tests/ref/fate/filter-colormatrix1 |    2 +-
 tests/ref/fate/filter-colormatrix2 |    2 +-
 3 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/libavfilter/vf_colormatrix.c b/libavfilter/vf_colormatrix.c
index 4a57fe0..c783671 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 {
@@ -122,7 +114,7 @@ AVFILTER_DEFINE_CLASS(colormatrix);
 #define imh im[2][1]
 #define imi im[2][2]
 
-static void inverse3x3(double im[3][3], const double m[3][3])
+static void inverse3x3(double im[3][3], double m[3][3])
 {
     double det = ma * (me * mi - mf * mh) - mb * (md * mi - mf * mg) + mc * (md * mh - me * mg);
     det = 1.0 / det;
@@ -137,7 +129,7 @@ static void inverse3x3(double im[3][3], const double m[3][3])
     imi = det * (ma * me - mb * md);
 }
 
-static void solve_coefficients(double cm[3][3], double rgb[3][3], const double yuv[3][3])
+static void solve_coefficients(double cm[3][3], double rgb[3][3], double yuv[3][3])
 {
     int i, j;
     for (i = 0; i < 3; i++)
@@ -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++) {
diff --git a/tests/ref/fate/filter-colormatrix1 b/tests/ref/fate/filter-colormatrix1
index 0f008e0..2f25f6c 100644
--- a/tests/ref/fate/filter-colormatrix1
+++ b/tests/ref/fate/filter-colormatrix1
@@ -1 +1 @@
-colormatrix1        0a0640b2d4ccd4e793f4919d82a89523
+colormatrix1        1593e24a71db42d07781b92665cf99a9
diff --git a/tests/ref/fate/filter-colormatrix2 b/tests/ref/fate/filter-colormatrix2
index 7f3232e..b57b594 100644
--- a/tests/ref/fate/filter-colormatrix2
+++ b/tests/ref/fate/filter-colormatrix2
@@ -1 +1 @@
-colormatrix2        5eb17671c03496ae43723e49832ab17a
+colormatrix2        cafba294debb89f59143b519f3cd1673



More information about the ffmpeg-cvslog mailing list