[FFmpeg-devel] [PATCH 2/2] swscale/swscale_unscaled: fix shift values in planarToP01xWrapper

James Almer jamrial at gmail.com
Mon Oct 21 16:26:04 EEST 2024


The current calculation was a no-op, setting the entire array to 0.
Use the shift value from the dest descriptor, as the source one is planar with
no shifts whatsoever.

Signed-off-by: James Almer <jamrial at gmail.com>
---
 libswscale/swscale_unscaled.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c
index a7fdb438a6..5e963ced15 100644
--- a/libswscale/swscale_unscaled.c
+++ b/libswscale/swscale_unscaled.c
@@ -268,23 +268,12 @@ static int planarToP01xWrapper(SwsContext *c, const uint8_t *const src8[],
                                int srcSliceH, uint8_t *const dstParam8[],
                                const int dstStride[])
 {
-    const AVPixFmtDescriptor *src_format = av_pix_fmt_desc_get(c->srcFormat);
     const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->dstFormat);
     const uint16_t **src = (const uint16_t**)src8;
     uint16_t *dstY = (uint16_t*)(dstParam8[0] + dstStride[0] * srcSliceY);
     uint16_t *dstUV = (uint16_t*)(dstParam8[1] + dstStride[1] * srcSliceY / 2);
     int x, y;
 
-    /* Calculate net shift required for values. */
-    const int shift[3] = {
-        dst_format->comp[0].depth + dst_format->comp[0].shift -
-        src_format->comp[0].depth - src_format->comp[0].shift,
-        dst_format->comp[1].depth + dst_format->comp[1].shift -
-        src_format->comp[1].depth - src_format->comp[1].shift,
-        dst_format->comp[2].depth + dst_format->comp[2].shift -
-        src_format->comp[2].depth - src_format->comp[2].shift,
-    };
-
     av_assert0(!(srcStride[0] % 2 || srcStride[1] % 2 || srcStride[2] % 2 ||
                  dstStride[0] % 2 || dstStride[1] % 2));
 
@@ -292,7 +281,7 @@ static int planarToP01xWrapper(SwsContext *c, const uint8_t *const src8[],
         uint16_t *tdstY = dstY;
         const uint16_t *tsrc0 = src[0];
         for (x = c->srcW; x > 0; x--) {
-            *tdstY++ = *tsrc0++ << shift[0];
+            *tdstY++ = *tsrc0++ << dst_format->comp[0].shift;
         }
         src[0] += srcStride[0] / 2;
         dstY += dstStride[0] / 2;
@@ -302,8 +291,8 @@ static int planarToP01xWrapper(SwsContext *c, const uint8_t *const src8[],
             const uint16_t *tsrc1 = src[1];
             const uint16_t *tsrc2 = src[2];
             for (x = c->srcW / 2; x > 0; x--) {
-                *tdstUV++ = *tsrc1++ << shift[1];
-                *tdstUV++ = *tsrc2++ << shift[2];
+                *tdstUV++ = *tsrc1++ << dst_format->comp[1].shift;
+                *tdstUV++ = *tsrc2++ << dst_format->comp[2].shift;
             }
             src[1] += srcStride[1] / 2;
             src[2] += srcStride[2] / 2;
-- 
2.47.0



More information about the ffmpeg-devel mailing list