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

Clément Bœsch ubitux at gmail.com
Sun Jan 6 06:31:48 CET 2013


On Sun, Jan 06, 2013 at 06:31:21AM +0100, Clément Bœsch wrote:
> On Sun, Jan 06, 2013 at 05:57:50AM +0100, Clément Bœsch wrote:
> > ---
> > 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(-)
> > 
> 
> New patch attached, which should be better. But I have two questions:
> 
>  - why is pixel_step unused?
>  - AV_PIX_FMT_YUV420P is planar while AV_PIX_FMT_YUYV422 is packed, is
>    this correct?
> 

Even better with the patch.

-- 
Clément B.
-------------- next part --------------
From 9f395669cc0da500aabd483f9df2448018faa7d5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <ubitux at gmail.com>
Date: Sun, 6 Jan 2013 05:55:21 +0100
Subject: [PATCH] lavfi/kerndeint: fix width/linesize usage.

---
 libavfilter/vf_kerndeint.c | 29 +++++++++++++++--------------
 tests/ref/lavfi/kerndeint  | 20 ++++++++++----------
 2 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/libavfilter/vf_kerndeint.c b/libavfilter/vf_kerndeint.c
index 26f2e49..c576a25 100644
--- a/libavfilter/vf_kerndeint.c
+++ b/libavfilter/vf_kerndeint.c
@@ -39,9 +39,9 @@ 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           tmp_linesize[4];
     int           pixel_step;
 } KerndeintContext;
 
@@ -101,9 +101,10 @@ static int config_props(AVFilterLink *inlink)
     int ret;
 
     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, kerndeint->tmp_linesize,
                           inlink->w, inlink->h, inlink->format, 1);
     if (ret < 0)
         return ret;
@@ -137,8 +138,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,27 +160,27 @@ 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];
-        psrc_linesize     = outpic->linesize[plane];
+        psrc_linesize     = kerndeint->tmp_linesize[plane];
         dstp = dstp_saved = outpic->data[plane];
         dst_linesize      = outpic->linesize[plane];
         srcp              = srcp_saved + (1 - order) * src_linesize;
         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 +206,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 +288,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..04a8a5f 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
-yuv420p             a935cce07c5287b92c6d5220361866ed
-yuyv422             f549c98059ba9ce50e28204256d13b5d
+0bgr                2c1fbf9ac9f65c550c80cacb6b648802
+0rgb                82f8e0da5bb1936db2f05bb73d0d7e2f
+abgr                cec9030dd5f1a7668b87a464c0e84a0f
+argb                aef66bcd93f4540deb20411828c66b26
+bgr0                409f064064a6d3002b5d2923090fd1b3
+bgra                623644ec55b980383fee3d1c11a72f3a
+rgb0                a9b041315a27f3c3fd6823faedc2f2cc
+rgba                36061278228a1a5c31f3f180b167488a
+yuv420p             40ca042814882b0b791cbec38e289702
+yuyv422             1cdabf26a3f5e42f44f8dccec99b489a
-- 
1.8.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130106/bd8f89d6/attachment.asc>


More information about the ffmpeg-devel mailing list