[FFmpeg-devel] [PATCH v5 2/3] ibavfilter/vf_cover_rect.c: change the cover_rect function for support cover frame can be changed

Michael Niedermayer michael at niedermayer.cc
Sun Jun 16 10:23:59 EEST 2019


On Sat, Jun 15, 2019 at 12:48:25AM +0800, lance.lmwang at gmail.com wrote:
> From: Limin Wang <lance.lmwang at gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
> ---
>  libavfilter/vf_cover_rect.c | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/libavfilter/vf_cover_rect.c b/libavfilter/vf_cover_rect.c
> index 898debf..b66c40b 100644
> --- a/libavfilter/vf_cover_rect.c
> +++ b/libavfilter/vf_cover_rect.c
> @@ -71,24 +71,25 @@ static int config_input(AVFilterLink *inlink)
>      return 0;
>  }
>  
> -static void cover_rect(CoverContext *cover, AVFrame *in, int offx, int offy)
> +static void cover_rect(AVFrame *cover_frame, AVFrame *in, int offx, int offy)
>  {
>      int x, y, p;
>  
>      for (p = 0; p < 3; p++) {
>          uint8_t *data = in->data[p] + (offx>>!!p) + (offy>>!!p) * in->linesize[p];
> -        const uint8_t *src = cover->cover_frame->data[p];
> -        int w = AV_CEIL_RSHIFT(cover->cover_frame->width , !!p);
> -        int h = AV_CEIL_RSHIFT(cover->cover_frame->height, !!p);
> +        const uint8_t *src = cover_frame->data[p];
> +        int w = AV_CEIL_RSHIFT(cover_frame->width , !!p);
> +        int h = AV_CEIL_RSHIFT(cover_frame->height, !!p);
>          for (y = 0; y < h; y++) {
>              for (x = 0; x < w; x++) {
>                  data[x] = src[x];
>              }
>              data += in->linesize[p];
> -            src += cover->cover_frame->linesize[p];
> +            src += cover_frame->linesize[p];
>          }
>      }

>  }
> +
>  static void blur(CoverContext *cover, AVFrame *in, int offx, int offy)
>  {
>      int x, y, p;
> @@ -139,6 +140,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
>      AVDictionaryEntry *ex, *ey, *ew, *eh;
>      int x = -1, y = -1, w = -1, h = -1;
>      char *xendptr = NULL, *yendptr = NULL, *wendptr = NULL, *hendptr = NULL;
> +    AVFrame *cover_frame = NULL;
>  
>      ex = av_dict_get(in->metadata, "lavfi.rect.x", NULL, AV_DICT_MATCH_CASE);
>      ey = av_dict_get(in->metadata, "lavfi.rect.y", NULL, AV_DICT_MATCH_CASE);
> @@ -174,6 +176,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
>      if (cover->cover_frame) {
>          if (w != cover->cover_frame->width || h != cover->cover_frame->height)
>              return AVERROR(EINVAL);
> +        cover_frame = cover->cover_frame;
>      }
>  
>      cover->width  = w;
> @@ -186,8 +189,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
>  
>      if (cover->mode == MODE_BLUR) {
>          blur (cover, in, x, y);

> -    } else {
> -        cover_rect(cover, in, x, y);
> +    } else if (cover_frame) {
> +        cover_rect(cover_frame, in, x, y);

replacing a field from the context by a local variable cannot make a field
null that was not before


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Its not that you shouldnt use gotos but rather that you should write
readable code and code with gotos often but not always is less readable
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20190616/1a52ffd3/attachment.sig>


More information about the ffmpeg-devel mailing list