diff mbox series

[FFmpeg-devel,1/4] avfilter/vf_sr.c: refine code to use AVPixFmtDescriptor.log2_chroma_h/w

Message ID 1582533650-1496-1-git-send-email-yejun.guo@intel.com
State Accepted
Headers show
Series [FFmpeg-devel,1/4] avfilter/vf_sr.c: refine code to use AVPixFmtDescriptor.log2_chroma_h/w
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Guo, Yejun Feb. 24, 2020, 8:40 a.m. UTC
Signed-off-by: Guo, Yejun <yejun.guo@intel.com>
---
 libavfilter/vf_sr.c | 40 ++++++----------------------------------
 1 file changed, 6 insertions(+), 34 deletions(-)

Comments

Pedro Arthur Feb. 24, 2020, 3:30 p.m. UTC | #1
Em seg., 24 de fev. de 2020 às 05:50, Guo, Yejun <yejun.guo@intel.com> escreveu:
>
> Signed-off-by: Guo, Yejun <yejun.guo@intel.com>
> ---
>  libavfilter/vf_sr.c | 40 ++++++----------------------------------
>  1 file changed, 6 insertions(+), 34 deletions(-)
>
> diff --git a/libavfilter/vf_sr.c b/libavfilter/vf_sr.c
> index 562b030..f000eda 100644
> --- a/libavfilter/vf_sr.c
> +++ b/libavfilter/vf_sr.c
> @@ -176,40 +176,12 @@ static int config_props(AVFilterLink *inlink)
>          sr_context->sws_slice_h = inlink->h;
>      } else {
>          if (inlink->format != AV_PIX_FMT_GRAY8){
> -            sws_src_h = sr_context->input.height;
> -            sws_src_w = sr_context->input.width;
> -            sws_dst_h = sr_context->output.height;
> -            sws_dst_w = sr_context->output.width;
> -
> -            switch (inlink->format){
> -            case AV_PIX_FMT_YUV420P:
> -                sws_src_h = AV_CEIL_RSHIFT(sws_src_h, 1);
> -                sws_src_w = AV_CEIL_RSHIFT(sws_src_w, 1);
> -                sws_dst_h = AV_CEIL_RSHIFT(sws_dst_h, 1);
> -                sws_dst_w = AV_CEIL_RSHIFT(sws_dst_w, 1);
> -                break;
> -            case AV_PIX_FMT_YUV422P:
> -                sws_src_w = AV_CEIL_RSHIFT(sws_src_w, 1);
> -                sws_dst_w = AV_CEIL_RSHIFT(sws_dst_w, 1);
> -                break;
> -            case AV_PIX_FMT_YUV444P:
> -                break;
> -            case AV_PIX_FMT_YUV410P:
> -                sws_src_h = AV_CEIL_RSHIFT(sws_src_h, 2);
> -                sws_src_w = AV_CEIL_RSHIFT(sws_src_w, 2);
> -                sws_dst_h = AV_CEIL_RSHIFT(sws_dst_h, 2);
> -                sws_dst_w = AV_CEIL_RSHIFT(sws_dst_w, 2);
> -                break;
> -            case AV_PIX_FMT_YUV411P:
> -                sws_src_w = AV_CEIL_RSHIFT(sws_src_w, 2);
> -                sws_dst_w = AV_CEIL_RSHIFT(sws_dst_w, 2);
> -                break;
> -            default:
> -                av_log(context, AV_LOG_ERROR,
> -                       "could not create SwsContext for scaling for given input pixel format: %s\n",
> -                       av_get_pix_fmt_name(inlink->format));
> -                return AVERROR(EIO);
> -            }
> +            const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
> +            sws_src_h = AV_CEIL_RSHIFT(sr_context->input.height, desc->log2_chroma_h);
> +            sws_src_w = AV_CEIL_RSHIFT(sr_context->input.width, desc->log2_chroma_w);
> +            sws_dst_h = AV_CEIL_RSHIFT(sr_context->output.height, desc->log2_chroma_h);
> +            sws_dst_w = AV_CEIL_RSHIFT(sr_context->output.width, desc->log2_chroma_w);
> +
>              sr_context->sws_contexts[0] = sws_getContext(sws_src_w, sws_src_h, AV_PIX_FMT_GRAY8,
>                                                           sws_dst_w, sws_dst_h, AV_PIX_FMT_GRAY8,
>                                                           SWS_BICUBIC, NULL, NULL, NULL);
> --
> 2.7.4
>
LGTM

> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Guo, Yejun Feb. 25, 2020, 6:06 a.m. UTC | #2
> -----Original Message-----
> From: Pedro Arthur [mailto:bygrandao@gmail.com]
> Sent: Monday, February 24, 2020 11:30 PM
> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
> Cc: Guo, Yejun <yejun.guo@intel.com>
> Subject: Re: [FFmpeg-devel] [PATCH 1/4] avfilter/vf_sr.c: refine code to use
> AVPixFmtDescriptor.log2_chroma_h/w
> 
> Em seg., 24 de fev. de 2020 às 05:50, Guo, Yejun <yejun.guo@intel.com>
> escreveu:
> >
> > Signed-off-by: Guo, Yejun <yejun.guo@intel.com>
> > ---
> >  libavfilter/vf_sr.c | 40 ++++++----------------------------------
> >  1 file changed, 6 insertions(+), 34 deletions(-)
> >
> > diff --git a/libavfilter/vf_sr.c b/libavfilter/vf_sr.c
> > index 562b030..f000eda 100644
> > --- a/libavfilter/vf_sr.c
> > +++ b/libavfilter/vf_sr.c
> desc->log2_chroma_w);
> > +
> >              sr_context->sws_contexts[0] = sws_getContext(sws_src_w,
> sws_src_h, AV_PIX_FMT_GRAY8,
> >
> sws_dst_w, sws_dst_h, AV_PIX_FMT_GRAY8,
> >
> SWS_BICUBIC, NULL, NULL, NULL);
> > --
> > 2.7.4
> >
> LGTM

Thanks. 

Since there is an issue in patch 3 and patch 4, I will send out V2 patch set without this one.

> 
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Guo, Yejun Feb. 29, 2020, 4:48 a.m. UTC | #3
> -----Original Message-----
> From: Guo, Yejun
> Sent: Tuesday, February 25, 2020 2:07 PM
> To: Pedro Arthur <bygrandao@gmail.com>; FFmpeg development discussions
> and patches <ffmpeg-devel@ffmpeg.org>
> Subject: RE: [FFmpeg-devel] [PATCH 1/4] avfilter/vf_sr.c: refine code to use
> AVPixFmtDescriptor.log2_chroma_h/w
> 
> 
> 
> > -----Original Message-----
> > From: Pedro Arthur [mailto:bygrandao@gmail.com]
> > Sent: Monday, February 24, 2020 11:30 PM
> > To: FFmpeg development discussions and patches
> <ffmpeg-devel@ffmpeg.org>
> > Cc: Guo, Yejun <yejun.guo@intel.com>
> > Subject: Re: [FFmpeg-devel] [PATCH 1/4] avfilter/vf_sr.c: refine code to use
> > AVPixFmtDescriptor.log2_chroma_h/w
> >
> > Em seg., 24 de fev. de 2020 às 05:50, Guo, Yejun <yejun.guo@intel.com>
> > escreveu:
> > >
> > > Signed-off-by: Guo, Yejun <yejun.guo@intel.com>
> > > ---
> > >  libavfilter/vf_sr.c | 40 ++++++----------------------------------
> > >  1 file changed, 6 insertions(+), 34 deletions(-)
> > >
> > > diff --git a/libavfilter/vf_sr.c b/libavfilter/vf_sr.c
> > > index 562b030..f000eda 100644
> > > --- a/libavfilter/vf_sr.c
> > > +++ b/libavfilter/vf_sr.c
> > desc->log2_chroma_w);
> > > +
> > >              sr_context->sws_contexts[0] =
> sws_getContext(sws_src_w,
> > sws_src_h, AV_PIX_FMT_GRAY8,
> > >
> > sws_dst_w, sws_dst_h, AV_PIX_FMT_GRAY8,
> > >
> > SWS_BICUBIC, NULL, NULL, NULL);
> > > --
> > > 2.7.4
> > >
> > LGTM
> 
> Thanks.
> 
> Since there is an issue in patch 3 and patch 4, I will send out V2 patch set
> without this one.

I'll push this patch (not this patch set) next Monday if no other comments. thanks.

> 
> >
> > > _______________________________________________
> > > ffmpeg-devel mailing list
> > > ffmpeg-devel@ffmpeg.org
> > > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > >
> > > To unsubscribe, visit link above, or email
> > > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavfilter/vf_sr.c b/libavfilter/vf_sr.c
index 562b030..f000eda 100644
--- a/libavfilter/vf_sr.c
+++ b/libavfilter/vf_sr.c
@@ -176,40 +176,12 @@  static int config_props(AVFilterLink *inlink)
         sr_context->sws_slice_h = inlink->h;
     } else {
         if (inlink->format != AV_PIX_FMT_GRAY8){
-            sws_src_h = sr_context->input.height;
-            sws_src_w = sr_context->input.width;
-            sws_dst_h = sr_context->output.height;
-            sws_dst_w = sr_context->output.width;
-
-            switch (inlink->format){
-            case AV_PIX_FMT_YUV420P:
-                sws_src_h = AV_CEIL_RSHIFT(sws_src_h, 1);
-                sws_src_w = AV_CEIL_RSHIFT(sws_src_w, 1);
-                sws_dst_h = AV_CEIL_RSHIFT(sws_dst_h, 1);
-                sws_dst_w = AV_CEIL_RSHIFT(sws_dst_w, 1);
-                break;
-            case AV_PIX_FMT_YUV422P:
-                sws_src_w = AV_CEIL_RSHIFT(sws_src_w, 1);
-                sws_dst_w = AV_CEIL_RSHIFT(sws_dst_w, 1);
-                break;
-            case AV_PIX_FMT_YUV444P:
-                break;
-            case AV_PIX_FMT_YUV410P:
-                sws_src_h = AV_CEIL_RSHIFT(sws_src_h, 2);
-                sws_src_w = AV_CEIL_RSHIFT(sws_src_w, 2);
-                sws_dst_h = AV_CEIL_RSHIFT(sws_dst_h, 2);
-                sws_dst_w = AV_CEIL_RSHIFT(sws_dst_w, 2);
-                break;
-            case AV_PIX_FMT_YUV411P:
-                sws_src_w = AV_CEIL_RSHIFT(sws_src_w, 2);
-                sws_dst_w = AV_CEIL_RSHIFT(sws_dst_w, 2);
-                break;
-            default:
-                av_log(context, AV_LOG_ERROR,
-                       "could not create SwsContext for scaling for given input pixel format: %s\n",
-                       av_get_pix_fmt_name(inlink->format));
-                return AVERROR(EIO);
-            }
+            const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+            sws_src_h = AV_CEIL_RSHIFT(sr_context->input.height, desc->log2_chroma_h);
+            sws_src_w = AV_CEIL_RSHIFT(sr_context->input.width, desc->log2_chroma_w);
+            sws_dst_h = AV_CEIL_RSHIFT(sr_context->output.height, desc->log2_chroma_h);
+            sws_dst_w = AV_CEIL_RSHIFT(sr_context->output.width, desc->log2_chroma_w);
+
             sr_context->sws_contexts[0] = sws_getContext(sws_src_w, sws_src_h, AV_PIX_FMT_GRAY8,
                                                          sws_dst_w, sws_dst_h, AV_PIX_FMT_GRAY8,
                                                          SWS_BICUBIC, NULL, NULL, NULL);