[FFmpeg-devel] Fw: [PATCH] Refactor two near-identical clauses.

Submitted by Shlomi Fish on June 12, 2018, 9:53 a.m.

Details

Message ID 20180612125320.3eb312fc@telaviv1.shlomifish.org
State New
Headers show

Commit Message

Shlomi Fish June 12, 2018, 9:53 a.m.
This message did not arrive to the list after three submissions.

Begin forwarded message:

Date: Tue, 12 Jun 2018 12:42:52 +0300
From: Shlomi Fish <shlomif@shlomifish.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Shlomi Fish <shlomif@shlomifish.org>
Subject: [PATCH] Refactor two near-identical clauses.


Placed under the Expat licence . All tests pass.
---
 libavfilter/vf_weave.c | 33 ++++++++++++++-------------------
 1 file changed, 14 insertions(+), 19 deletions(-)

+                            s->linesize[i], s->planeheight[i]);
     }
 
     out->pts = s->double_weave ? s->prev->pts : in->pts / 2;

Comments

Shlomi Fish June 12, 2018, 10:01 a.m.
On Tue, 12 Jun 2018 12:53:20 +0300
Shlomi Fish <shlomif@shlomifish.org> wrote:

> This message did not arrive to the list after three submissions.
> 

Just for the record, the patch can also be found here:

http://www.shlomifish.org/Files/files/code/0001-Refactor-two-near-identical-clauses.patch

> Begin forwarded message:
> 
> Date: Tue, 12 Jun 2018 12:42:52 +0300
> From: Shlomi Fish <shlomif@shlomifish.org>
> To: ffmpeg-devel@ffmpeg.org
> Cc: Shlomi Fish <shlomif@shlomifish.org>
> Subject: [PATCH] Refactor two near-identical clauses.
> 
> 
> Placed under the Expat licence . All tests pass.
> ---
>  libavfilter/vf_weave.c | 33 ++++++++++++++-------------------
>  1 file changed, 14 insertions(+), 19 deletions(-)
> 
> diff --git a/libavfilter/vf_weave.c b/libavfilter/vf_weave.c
> index 037f5d1cf2..be371201e1 100644
> --- a/libavfilter/vf_weave.c
> +++ b/libavfilter/vf_weave.c
> @@ -23,6 +23,7 @@
>  #include "libavutil/pixdesc.h"
>  #include "avfilter.h"
>  #include "internal.h"
> +#include <stdbool.h>
>  
>  typedef struct WeaveContext {
>      const AVClass *class;
> @@ -84,6 +85,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
>      AVFilterLink *outlink = ctx->outputs[0];
>      AVFrame *out;
>      int i;
> +    bool weave;
> +    int field1, field2;
>  
>      if (!s->prev) {
>          s->prev = in;
> @@ -98,26 +101,18 @@ static int filter_frame(AVFilterLink *inlink, AVFrame
> *in) }
>      av_frame_copy_props(out, in);
>  
> +    weave = (s->double_weave && !(inlink->frame_count_out & 1));
> +    field1 = s->first_field * weave;
> +    field2 = s->first_field * !weave;
>      for (i = 0; i < s->nb_planes; i++) {
> -        if (s->double_weave && !(inlink->frame_count_out & 1)) {
> -            av_image_copy_plane(out->data[i] + out->linesize[i] *
> s->first_field,
> -                                out->linesize[i] * 2,
> -                                in->data[i], in->linesize[i],
> -                                s->linesize[i], s->planeheight[i]);
> -            av_image_copy_plane(out->data[i] + out->linesize[i]
> * !s->first_field,
> -                                out->linesize[i] * 2,
> -                                s->prev->data[i], s->prev->linesize[i],
> -                                s->linesize[i], s->planeheight[i]);
> -        } else {
> -            av_image_copy_plane(out->data[i] + out->linesize[i]
> * !s->first_field,
> -                                out->linesize[i] * 2,
> -                                in->data[i], in->linesize[i],
> -                                s->linesize[i], s->planeheight[i]);
> -            av_image_copy_plane(out->data[i] + out->linesize[i] *
> s->first_field,
> -                                out->linesize[i] * 2,
> -                                s->prev->data[i], s->prev->linesize[i],
> -                                s->linesize[i], s->planeheight[i]);
> -        }
> +        av_image_copy_plane(out->data[i] + out->linesize[i] * field1,
> +                            out->linesize[i] * 2,
> +                            in->data[i], in->linesize[i],
> +                            s->linesize[i], s->planeheight[i]);
> +        av_image_copy_plane(out->data[i] + out->linesize[i] * field2,
> +                            out->linesize[i] * 2,
> +                            s->prev->data[i], s->prev->linesize[i],
> +                            s->linesize[i], s->planeheight[i]);
>      }
>  
>      out->pts = s->double_weave ? s->prev->pts : in->pts / 2;
Shlomi Fish June 16, 2018, 4:30 p.m.
On Tue, 12 Jun 2018 12:53:20 +0300
Shlomi Fish <shlomif@shlomifish.org> wrote:

> This message did not arrive to the list after three submissions.
> 

hi all!

Ping! Can this patch please be reviewed?

> Begin forwarded message:
> 
> Date: Tue, 12 Jun 2018 12:42:52 +0300
> From: Shlomi Fish <shlomif@shlomifish.org>
> To: ffmpeg-devel@ffmpeg.org
> Cc: Shlomi Fish <shlomif@shlomifish.org>
> Subject: [PATCH] Refactor two near-identical clauses.
> 
> 
> Placed under the Expat licence . All tests pass.
> ---
>  libavfilter/vf_weave.c | 33 ++++++++++++++-------------------
>  1 file changed, 14 insertions(+), 19 deletions(-)
> 
> diff --git a/libavfilter/vf_weave.c b/libavfilter/vf_weave.c
> index 037f5d1cf2..be371201e1 100644
> --- a/libavfilter/vf_weave.c
> +++ b/libavfilter/vf_weave.c
> @@ -23,6 +23,7 @@
>  #include "libavutil/pixdesc.h"
>  #include "avfilter.h"
>  #include "internal.h"
> +#include <stdbool.h>
>  
>  typedef struct WeaveContext {
>      const AVClass *class;
> @@ -84,6 +85,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
>      AVFilterLink *outlink = ctx->outputs[0];
>      AVFrame *out;
>      int i;
> +    bool weave;
> +    int field1, field2;
>  
>      if (!s->prev) {
>          s->prev = in;
> @@ -98,26 +101,18 @@ static int filter_frame(AVFilterLink *inlink, AVFrame
> *in) }
>      av_frame_copy_props(out, in);
>  
> +    weave = (s->double_weave && !(inlink->frame_count_out & 1));
> +    field1 = s->first_field * weave;
> +    field2 = s->first_field * !weave;
>      for (i = 0; i < s->nb_planes; i++) {
> -        if (s->double_weave && !(inlink->frame_count_out & 1)) {
> -            av_image_copy_plane(out->data[i] + out->linesize[i] *
> s->first_field,
> -                                out->linesize[i] * 2,
> -                                in->data[i], in->linesize[i],
> -                                s->linesize[i], s->planeheight[i]);
> -            av_image_copy_plane(out->data[i] + out->linesize[i]
> * !s->first_field,
> -                                out->linesize[i] * 2,
> -                                s->prev->data[i], s->prev->linesize[i],
> -                                s->linesize[i], s->planeheight[i]);
> -        } else {
> -            av_image_copy_plane(out->data[i] + out->linesize[i]
> * !s->first_field,
> -                                out->linesize[i] * 2,
> -                                in->data[i], in->linesize[i],
> -                                s->linesize[i], s->planeheight[i]);
> -            av_image_copy_plane(out->data[i] + out->linesize[i] *
> s->first_field,
> -                                out->linesize[i] * 2,
> -                                s->prev->data[i], s->prev->linesize[i],
> -                                s->linesize[i], s->planeheight[i]);
> -        }
> +        av_image_copy_plane(out->data[i] + out->linesize[i] * field1,
> +                            out->linesize[i] * 2,
> +                            in->data[i], in->linesize[i],
> +                            s->linesize[i], s->planeheight[i]);
> +        av_image_copy_plane(out->data[i] + out->linesize[i] * field2,
> +                            out->linesize[i] * 2,
> +                            s->prev->data[i], s->prev->linesize[i],
> +                            s->linesize[i], s->planeheight[i]);
>      }
>  
>      out->pts = s->double_weave ? s->prev->pts : in->pts / 2;
Michael Niedermayer June 17, 2018, 1:05 a.m.
On Tue, Jun 12, 2018 at 12:53:20PM +0300, Shlomi Fish wrote:
> This message did not arrive to the list after three submissions.
> 
> Begin forwarded message:
> 
> Date: Tue, 12 Jun 2018 12:42:52 +0300
> From: Shlomi Fish <shlomif@shlomifish.org>
> To: ffmpeg-devel@ffmpeg.org
> Cc: Shlomi Fish <shlomif@shlomifish.org>
> Subject: [PATCH] Refactor two near-identical clauses.
> 
> 
> Placed under the Expat licence . All tests pass.
> ---
>  libavfilter/vf_weave.c | 33 ++++++++++++++-------------------
>  1 file changed, 14 insertions(+), 19 deletions(-)
> 
> diff --git a/libavfilter/vf_weave.c b/libavfilter/vf_weave.c
> index 037f5d1cf2..be371201e1 100644
> --- a/libavfilter/vf_weave.c
> +++ b/libavfilter/vf_weave.c
> @@ -23,6 +23,7 @@
>  #include "libavutil/pixdesc.h"
>  #include "avfilter.h"
>  #include "internal.h"
> +#include <stdbool.h>
>  
>  typedef struct WeaveContext {
>      const AVClass *class;
> @@ -84,6 +85,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
>      AVFilterLink *outlink = ctx->outputs[0];
>      AVFrame *out;
>      int i;
> +    bool weave;
> +    int field1, field2;
>  
>      if (!s->prev) {
>          s->prev = in;
> @@ -98,26 +101,18 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
>      }
>      av_frame_copy_props(out, in);
>  
> +    weave = (s->double_weave && !(inlink->frame_count_out & 1));
> +    field1 = s->first_field * weave;
> +    field2 = s->first_field * !weave;
>      for (i = 0; i < s->nb_planes; i++) {
> -        if (s->double_weave && !(inlink->frame_count_out & 1)) {
> -            av_image_copy_plane(out->data[i] + out->linesize[i] *
> s->first_field,

this seems to be corrupted by line breaks

[...]

Patch hide | download patch | download mbox

diff --git a/libavfilter/vf_weave.c b/libavfilter/vf_weave.c
index 037f5d1cf2..be371201e1 100644
--- a/libavfilter/vf_weave.c
+++ b/libavfilter/vf_weave.c
@@ -23,6 +23,7 @@ 
 #include "libavutil/pixdesc.h"
 #include "avfilter.h"
 #include "internal.h"
+#include <stdbool.h>
 
 typedef struct WeaveContext {
     const AVClass *class;
@@ -84,6 +85,8 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     AVFilterLink *outlink = ctx->outputs[0];
     AVFrame *out;
     int i;
+    bool weave;
+    int field1, field2;
 
     if (!s->prev) {
         s->prev = in;
@@ -98,26 +101,18 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     }
     av_frame_copy_props(out, in);
 
+    weave = (s->double_weave && !(inlink->frame_count_out & 1));
+    field1 = s->first_field * weave;
+    field2 = s->first_field * !weave;
     for (i = 0; i < s->nb_planes; i++) {
-        if (s->double_weave && !(inlink->frame_count_out & 1)) {
-            av_image_copy_plane(out->data[i] + out->linesize[i] *
s->first_field,
-                                out->linesize[i] * 2,
-                                in->data[i], in->linesize[i],
-                                s->linesize[i], s->planeheight[i]);
-            av_image_copy_plane(out->data[i] + out->linesize[i]
* !s->first_field,
-                                out->linesize[i] * 2,
-                                s->prev->data[i], s->prev->linesize[i],
-                                s->linesize[i], s->planeheight[i]);
-        } else {
-            av_image_copy_plane(out->data[i] + out->linesize[i]
* !s->first_field,
-                                out->linesize[i] * 2,
-                                in->data[i], in->linesize[i],
-                                s->linesize[i], s->planeheight[i]);
-            av_image_copy_plane(out->data[i] + out->linesize[i] *
s->first_field,
-                                out->linesize[i] * 2,
-                                s->prev->data[i], s->prev->linesize[i],
-                                s->linesize[i], s->planeheight[i]);
-        }
+        av_image_copy_plane(out->data[i] + out->linesize[i] * field1,
+                            out->linesize[i] * 2,
+                            in->data[i], in->linesize[i],
+                            s->linesize[i], s->planeheight[i]);
+        av_image_copy_plane(out->data[i] + out->linesize[i] * field2,
+                            out->linesize[i] * 2,
+                            s->prev->data[i], s->prev->linesize[i],