diff mbox series

[FFmpeg-devel] ptrdiff_t related fixes and negative linesizes

Message ID CAPYw7P7WJsL5LBP+wHifeTb3j7A9ApTRYEp2JdZOQomyU=y8Ew@mail.gmail.com
State New
Headers show
Series [FFmpeg-devel] ptrdiff_t related fixes and negative linesizes | expand

Checks

Context Check Description
andriy/configure_x86 warning Failed to apply patch

Commit Message

Paul B Mahol Sept. 22, 2023, 5:37 p.m. UTC
Hi,

Patches attached.

Comments

Andreas Rheinhardt Sept. 22, 2023, 5:47 p.m. UTC | #1
Paul B Mahol:
> diff --git a/libavcodec/gifdec.c b/libavcodec/gifdec.c
> index d90e467cac..fb0b335088 100644
> --- a/libavcodec/gifdec.c
> +++ b/libavcodec/gifdec.c
> @@ -86,26 +86,29 @@ static void gif_read_palette(GifState *s, uint32_t *pal, int nb)
>  
>  static void gif_fill(AVFrame *picture, uint32_t color)
>  {
> -    uint32_t *p = (uint32_t *)picture->data[0];
> -    uint32_t *p_end = p + (picture->linesize[0] / sizeof(uint32_t)) * picture->height;
> -
> -    for (; p < p_end; p++)
> -        *p = color;
> +    const ptrdiff_t linesize = picture->linesize[0];
> +    const uint8_t *py = picture->data[0];
> +    const int w = picture->width;
> +    const int h = picture->height;
> +
> +    for (int y = 0; y < h; y++) {
> +        uint32_t *px = (uint32_t *)py;
> +        for (int x = 0; x < w; x++)
> +            px[x] = color;
> +        py += linesize;
> +    }
>  }
>  
>  static void gif_fill_rect(AVFrame *picture, uint32_t color, int l, int t, int w, int h)
>  {
> -    const ptrdiff_t linesize = picture->linesize[0] / sizeof(uint32_t);
> -    const uint32_t *py = (uint32_t *)picture->data[0] + t * linesize;
> -    const uint32_t *pr, *pb = py + h * linesize;
> -    uint32_t *px;
> -
> -    for (; py < pb; py += linesize) {
> -        px = (uint32_t *)py + l;
> -        pr = px + w;
> -
> -        for (; px < pr; px++)
> -            *px = color;
> +    const ptrdiff_t linesize = picture->linesize[0];
> +    const uint8_t *py = picture->data[0] + t * linesize;

Don't use const if you cast it away a few lines below.

> +
> +    for (int y = 0; y < h; y++) {
> +        uint32_t *px = ((uint32_t *)py) + l;
> +        for (int x = 0; x < w; x++)
> +            px[x] = color;
> +        py += linesize;
>      }
>  }
diff mbox series

Patch

From 9381993c4ce1a9b3958d9de6ce7ef4fb4113ea41 Mon Sep 17 00:00:00 2001
From: Paul B Mahol <onemda@gmail.com>
Date: Fri, 22 Sep 2023 19:31:47 +0200
Subject: [PATCH 3/3] avcodec/gifdec: rewrite functions that fill block/frame

Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavcodec/gifdec.c | 35 +++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/libavcodec/gifdec.c b/libavcodec/gifdec.c
index d90e467cac..fb0b335088 100644
--- a/libavcodec/gifdec.c
+++ b/libavcodec/gifdec.c
@@ -86,26 +86,29 @@  static void gif_read_palette(GifState *s, uint32_t *pal, int nb)
 
 static void gif_fill(AVFrame *picture, uint32_t color)
 {
-    uint32_t *p = (uint32_t *)picture->data[0];
-    uint32_t *p_end = p + (picture->linesize[0] / sizeof(uint32_t)) * picture->height;
-
-    for (; p < p_end; p++)
-        *p = color;
+    const ptrdiff_t linesize = picture->linesize[0];
+    const uint8_t *py = picture->data[0];
+    const int w = picture->width;
+    const int h = picture->height;
+
+    for (int y = 0; y < h; y++) {
+        uint32_t *px = (uint32_t *)py;
+        for (int x = 0; x < w; x++)
+            px[x] = color;
+        py += linesize;
+    }
 }
 
 static void gif_fill_rect(AVFrame *picture, uint32_t color, int l, int t, int w, int h)
 {
-    const ptrdiff_t linesize = picture->linesize[0] / sizeof(uint32_t);
-    const uint32_t *py = (uint32_t *)picture->data[0] + t * linesize;
-    const uint32_t *pr, *pb = py + h * linesize;
-    uint32_t *px;
-
-    for (; py < pb; py += linesize) {
-        px = (uint32_t *)py + l;
-        pr = px + w;
-
-        for (; px < pr; px++)
-            *px = color;
+    const ptrdiff_t linesize = picture->linesize[0];
+    const uint8_t *py = picture->data[0] + t * linesize;
+
+    for (int y = 0; y < h; y++) {
+        uint32_t *px = ((uint32_t *)py) + l;
+        for (int x = 0; x < w; x++)
+            px[x] = color;
+        py += linesize;
     }
 }
 
-- 
2.42.0