[FFmpeg-devel] [PATCH] lavfi/kerndeint: use width instead of linesize.

Clément Bœsch ubitux at gmail.com
Sun Jan 6 05:57:50 CET 2013


---
I may be completely wrong, but the code looks way more legit this way.
---
 libavfilter/vf_kerndeint.c | 28 ++++++++++++++--------------
 tests/ref/lavfi/kerndeint  | 18 +++++++++---------
 2 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/libavfilter/vf_kerndeint.c b/libavfilter/vf_kerndeint.c
index 26f2e49..6f43cc1 100644
--- a/libavfilter/vf_kerndeint.c
+++ b/libavfilter/vf_kerndeint.c
@@ -39,9 +39,8 @@ typedef struct {
     const AVClass *class;
     int           frame; ///< frame count, starting from 0
     int           thresh, map, order, sharp, twoway;
-    int           vsub;
+    int           vsub, hsub;
     uint8_t       *tmp_data [4];  ///< temporary plane data buffer
-    int           tmp_bwidth[4];  ///< temporary plane byte width
     int           pixel_step;
 } KerndeintContext;
 
@@ -98,12 +97,13 @@ static int config_props(AVFilterLink *inlink)
 {
     KerndeintContext *kerndeint = inlink->dst->priv;
     const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[inlink->format];
-    int ret;
+    int ret, linesizes[4];
 
     kerndeint->vsub = desc->log2_chroma_h;
+    kerndeint->hsub = desc->log2_chroma_w;
     kerndeint->pixel_step = av_get_bits_per_pixel(desc) >> 3;
 
-    ret = av_image_alloc(kerndeint->tmp_data, kerndeint->tmp_bwidth,
+    ret = av_image_alloc(kerndeint->tmp_data, linesizes,
                           inlink->w, inlink->h, inlink->format, 1);
     if (ret < 0)
         return ret;
@@ -137,8 +137,8 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *inpic)
     uint8_t *dstp, *dstp_saved;
     const uint8_t *srcp_saved;
 
-    int src_linesize, psrc_linesize, dst_linesize, bwidth;
-    int x, y, plane, val, hi, lo, g, h, n = kerndeint->frame++;
+    int src_linesize, psrc_linesize, dst_linesize;
+    int x, y, plane, val, hi, lo, g, w, h, n = kerndeint->frame++;
     double valf;
 
     const int thresh = kerndeint->thresh;
@@ -159,7 +159,7 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *inpic)
 
     for (plane = 0; inpic->data[plane] && plane < 4; plane++) {
         h = plane == 0 ? inlink->h : inlink->h >> kerndeint->vsub;
-        bwidth = kerndeint->tmp_bwidth[plane];
+        w = plane == 0 ? inlink->w : inlink->w >> kerndeint->hsub;
 
         srcp = srcp_saved = inpic->data[plane];
         src_linesize      = inpic->linesize[plane];
@@ -170,16 +170,16 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *inpic)
         dstp              = dstp_saved + (1 - order) * dst_linesize;
 
         for (y = 0; y < h; y += 2) {
-            memcpy(dstp, srcp, bwidth);
+            memcpy(dstp, srcp, w);
             srcp += 2 * src_linesize;
             dstp += 2 * dst_linesize;
         }
 
         // Copy through the lines that will be missed below.
-        memcpy(dstp_saved + order            * dst_linesize, srcp_saved + (1 -     order) * src_linesize, bwidth);
-        memcpy(dstp_saved + (2 + order    )  * dst_linesize, srcp_saved + (3 -     order) * src_linesize, bwidth);
-        memcpy(dstp_saved + (h - 2 + order)  * dst_linesize, srcp_saved + (h - 1 - order) * src_linesize, bwidth);
-        memcpy(dstp_saved + (h - 4 + order)  * dst_linesize, srcp_saved + (h - 3 - order) * src_linesize, bwidth);
+        memcpy(dstp_saved + order            * dst_linesize, srcp_saved + (1 -     order) * src_linesize, w);
+        memcpy(dstp_saved + (2 + order    )  * dst_linesize, srcp_saved + (3 -     order) * src_linesize, w);
+        memcpy(dstp_saved + (h - 2 + order)  * dst_linesize, srcp_saved + (h - 1 - order) * src_linesize, w);
+        memcpy(dstp_saved + (h - 4 + order)  * dst_linesize, srcp_saved + (h - 3 - order) * src_linesize, w);
 
         /* For the other field choose adaptively between using the previous field
            or the interpolant from the current field. */
@@ -205,7 +205,7 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *inpic)
         dstp   = dstp_saved + 5 * dst_linesize - (1 - order) * dst_linesize;
 
         for (y = 5 - (1 - order); y <= h - 5 - (1 - order); y += 2) {
-            for (x = 0; x < bwidth; x++) {
+            for (x = 0; x < w; x++) {
                 if (thresh == 0 || n == 0 ||
                     (abs((int)prvp[x]  - (int)srcp[x])  > thresh) ||
                     (abs((int)prvpp[x] - (int)srcpp[x]) > thresh) ||
@@ -287,7 +287,7 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *inpic)
 
         srcp = inpic->data[plane];
         dstp = kerndeint->tmp_data[plane];
-        av_image_copy_plane(dstp, psrc_linesize, srcp, src_linesize, bwidth, h);
+        av_image_copy_plane(dstp, psrc_linesize, srcp, src_linesize, w, h);
     }
 
     avfilter_unref_buffer(inpic);
diff --git a/tests/ref/lavfi/kerndeint b/tests/ref/lavfi/kerndeint
index b03f977..34ead7d 100644
--- a/tests/ref/lavfi/kerndeint
+++ b/tests/ref/lavfi/kerndeint
@@ -1,10 +1,10 @@
-0bgr                58fb0bda60562ce17e75f1c3459d0504
-0rgb                d29f6a7b63ade359ec81f5856633ec06
-abgr                71071045b8ec66a6d0a38bb3fed1ca51
-argb                93ba0daa1e945ad1a6f8c0c1cd2e1858
-bgr0                364b8bcd1c7a384902077bc7190c5ea3
-bgra                81ac8315a4c66e363bc6fa3e99d9cd2b
-rgb0                ae0c2afbc266345c1372276755595105
-rgba                42a6cc9b815ca0ee69c29db3616ce25e
+0bgr                2c1fbf9ac9f65c550c80cacb6b648802
+0rgb                82f8e0da5bb1936db2f05bb73d0d7e2f
+abgr                cec9030dd5f1a7668b87a464c0e84a0f
+argb                aef66bcd93f4540deb20411828c66b26
+bgr0                409f064064a6d3002b5d2923090fd1b3
+bgra                623644ec55b980383fee3d1c11a72f3a
+rgb0                a9b041315a27f3c3fd6823faedc2f2cc
+rgba                36061278228a1a5c31f3f180b167488a
 yuv420p             a935cce07c5287b92c6d5220361866ed
-yuyv422             f549c98059ba9ce50e28204256d13b5d
+yuyv422             1cdabf26a3f5e42f44f8dccec99b489a
-- 
1.8.1



More information about the ffmpeg-devel mailing list