diff mbox series

[FFmpeg-devel] swscale: fix chroma width rounding

Message ID 1622646164-30564-1-git-send-email-lance.lmwang@gmail.com
State New
Headers show
Series [FFmpeg-devel] swscale: fix chroma width rounding | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Lance Wang June 2, 2021, 3:02 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

fixes vertical line at the right side of video for rgb24toyv12 conversion.
Please reproduce it with below command:
./ffplay -f lavfi -i "testsrc=size=529x656,ocv=filter_name=smooth,format=yuv420p"

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libswscale/rgb2rgb_template.c     | 2 +-
 libswscale/x86/rgb2rgb_template.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Lance Wang June 3, 2021, 2:15 a.m. UTC | #1
On Wed, Jun 02, 2021 at 11:02:44PM +0800, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> fixes vertical line at the right side of video for rgb24toyv12 conversion.
> Please reproduce it with below command:
> ./ffplay -f lavfi -i "testsrc=size=529x656,ocv=filter_name=smooth,format=yuv420p"

Please reproduce it with below command:
./ffplay -f lavfi -i "testsrc=size=529x656,format=bgr24,format=yuv420p"

> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libswscale/rgb2rgb_template.c     | 2 +-
>  libswscale/x86/rgb2rgb_template.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libswscale/rgb2rgb_template.c b/libswscale/rgb2rgb_template.c
> index 42c6980..e716ba5 100644
> --- a/libswscale/rgb2rgb_template.c
> +++ b/libswscale/rgb2rgb_template.c
> @@ -654,7 +654,7 @@ void ff_rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst,
>      int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
>      int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
>      int y;
> -    const int chromWidth = width >> 1;
> +    const int chromWidth = AV_CEIL_RSHIFT(width, 1);
>  
>      for (y = 0; y < height; y += 2) {
>          int i;
> diff --git a/libswscale/x86/rgb2rgb_template.c b/libswscale/x86/rgb2rgb_template.c
> index ae2469e..704b0fa 100644
> --- a/libswscale/x86/rgb2rgb_template.c
> +++ b/libswscale/x86/rgb2rgb_template.c
> @@ -1578,7 +1578,7 @@ static inline void RENAME(rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_
>  #define BGR2U_IDX "16*4+16*33"
>  #define BGR2V_IDX "16*4+16*34"
>      int y;
> -    const x86_reg chromWidth= width>>1;
> +    const x86_reg chromWidth = AV_CEIL_RSHIFT(width, 1);
>  
>      if (height > 2) {
>          ff_rgb24toyv12_c(src, ydst, udst, vdst, width, 2, lumStride, chromStride, srcStride, rgb2yuv);
> -- 
> 1.8.3.1
>
Michael Niedermayer June 3, 2021, 7:10 p.m. UTC | #2
On Wed, Jun 02, 2021 at 11:02:44PM +0800, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> fixes vertical line at the right side of video for rgb24toyv12 conversion.
> Please reproduce it with below command:
> ./ffplay -f lavfi -i "testsrc=size=529x656,ocv=filter_name=smooth,format=yuv420p"
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libswscale/rgb2rgb_template.c     | 2 +-
>  libswscale/x86/rgb2rgb_template.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libswscale/rgb2rgb_template.c b/libswscale/rgb2rgb_template.c
> index 42c6980..e716ba5 100644
> --- a/libswscale/rgb2rgb_template.c
> +++ b/libswscale/rgb2rgb_template.c
> @@ -654,7 +654,7 @@ void ff_rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst,
>      int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
>      int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
>      int y;
> -    const int chromWidth = width >> 1;
> +    const int chromWidth = AV_CEIL_RSHIFT(width, 1);
>  
>      for (y = 0; y < height; y += 2) {
>          int i;
> diff --git a/libswscale/x86/rgb2rgb_template.c b/libswscale/x86/rgb2rgb_template.c
> index ae2469e..704b0fa 100644
> --- a/libswscale/x86/rgb2rgb_template.c
> +++ b/libswscale/x86/rgb2rgb_template.c
> @@ -1578,7 +1578,7 @@ static inline void RENAME(rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_
>  #define BGR2U_IDX "16*4+16*33"
>  #define BGR2V_IDX "16*4+16*34"
>      int y;
> -    const x86_reg chromWidth= width>>1;
> +    const x86_reg chromWidth = AV_CEIL_RSHIFT(width, 1);
>  
>      if (height > 2) {
>          ff_rgb24toyv12_c(src, ydst, udst, vdst, width, 2, lumStride, chromStride, srcStride, rgb2yuv);

the comments above the functions are incorrect if you add support for odd width
also the code writes outside the luma array i think with this change

thx

[...]
Lance Wang June 4, 2021, 2:52 a.m. UTC | #3
On Thu, Jun 03, 2021 at 09:10:13PM +0200, Michael Niedermayer wrote:
> On Wed, Jun 02, 2021 at 11:02:44PM +0800, lance.lmwang@gmail.com wrote:
> > From: Limin Wang <lance.lmwang@gmail.com>
> > 
> > fixes vertical line at the right side of video for rgb24toyv12 conversion.
> > Please reproduce it with below command:
> > ./ffplay -f lavfi -i "testsrc=size=529x656,ocv=filter_name=smooth,format=yuv420p"
> > 
> > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > ---
> >  libswscale/rgb2rgb_template.c     | 2 +-
> >  libswscale/x86/rgb2rgb_template.c | 2 +-
> >  2 files changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/libswscale/rgb2rgb_template.c b/libswscale/rgb2rgb_template.c
> > index 42c6980..e716ba5 100644
> > --- a/libswscale/rgb2rgb_template.c
> > +++ b/libswscale/rgb2rgb_template.c
> > @@ -654,7 +654,7 @@ void ff_rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst,
> >      int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
> >      int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
> >      int y;
> > -    const int chromWidth = width >> 1;
> > +    const int chromWidth = AV_CEIL_RSHIFT(width, 1);
> >  
> >      for (y = 0; y < height; y += 2) {
> >          int i;
> > diff --git a/libswscale/x86/rgb2rgb_template.c b/libswscale/x86/rgb2rgb_template.c
> > index ae2469e..704b0fa 100644
> > --- a/libswscale/x86/rgb2rgb_template.c
> > +++ b/libswscale/x86/rgb2rgb_template.c
> > @@ -1578,7 +1578,7 @@ static inline void RENAME(rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_
> >  #define BGR2U_IDX "16*4+16*33"
> >  #define BGR2V_IDX "16*4+16*34"
> >      int y;
> > -    const x86_reg chromWidth= width>>1;
> > +    const x86_reg chromWidth = AV_CEIL_RSHIFT(width, 1);
> >  
> >      if (height > 2) {
> >          ff_rgb24toyv12_c(src, ydst, udst, vdst, width, 2, lumStride, chromStride, srcStride, rgb2yuv);
> 
> the comments above the functions are incorrect if you add support for odd width
> also the code writes outside the luma array i think with this change

Sorry, I haven't notice the comments say about that, then I prefer not to use 
the optimized bgr24toYV12 unscaled conversion when width%2. Will update the
patch.

> 
> thx
> 
> [...]
> -- 
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> Those who are too smart to engage in politics are punished by being
> governed by those who are dumber. -- Plato 



> _______________________________________________
> 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/libswscale/rgb2rgb_template.c b/libswscale/rgb2rgb_template.c
index 42c6980..e716ba5 100644
--- a/libswscale/rgb2rgb_template.c
+++ b/libswscale/rgb2rgb_template.c
@@ -654,7 +654,7 @@  void ff_rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst,
     int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
     int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
     int y;
-    const int chromWidth = width >> 1;
+    const int chromWidth = AV_CEIL_RSHIFT(width, 1);
 
     for (y = 0; y < height; y += 2) {
         int i;
diff --git a/libswscale/x86/rgb2rgb_template.c b/libswscale/x86/rgb2rgb_template.c
index ae2469e..704b0fa 100644
--- a/libswscale/x86/rgb2rgb_template.c
+++ b/libswscale/x86/rgb2rgb_template.c
@@ -1578,7 +1578,7 @@  static inline void RENAME(rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_
 #define BGR2U_IDX "16*4+16*33"
 #define BGR2V_IDX "16*4+16*34"
     int y;
-    const x86_reg chromWidth= width>>1;
+    const x86_reg chromWidth = AV_CEIL_RSHIFT(width, 1);
 
     if (height > 2) {
         ff_rgb24toyv12_c(src, ydst, udst, vdst, width, 2, lumStride, chromStride, srcStride, rgb2yuv);