[FFmpeg-cvslog] avcodec/huffyuv(dec|enc): Use union for temp/temp16

Andreas Rheinhardt git at videolan.org
Sun Apr 7 23:17:56 EEST 2024


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Thu Apr  4 05:59:57 2024 +0200| [cf96c0295ea9c8f58617408ed68dbb1cba8d1682] | committer: Andreas Rheinhardt

avcodec/huffyuv(dec|enc): Use union for temp/temp16

These pointers already point to the same buffers, so using
a union is possible and avoids the overhead of syncing the
pointers (and saves some memory).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=cf96c0295ea9c8f58617408ed68dbb1cba8d1682
---

 libavcodec/huffyuvdec.c | 11 +++++------
 libavcodec/huffyuvenc.c | 11 +++++------
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c
index e390380867..12ecfcb933 100644
--- a/libavcodec/huffyuvdec.c
+++ b/libavcodec/huffyuvdec.c
@@ -70,8 +70,10 @@ typedef struct HYuvDecContext {
     int context;
     int last_slice_end;
 
-    uint8_t *temp[3];
-    uint16_t *temp16[3];                    ///< identical to temp but 16bit type
+    union {
+        uint8_t  *temp[3];
+        uint16_t *temp16[3];
+    };
     uint8_t len[4][MAX_VLC_N];
     uint32_t bits[4][MAX_VLC_N];
     uint32_t pix_bgr_map[1<<VLC_BITS];
@@ -323,10 +325,8 @@ static av_cold int decode_end(AVCodecContext *avctx)
     HYuvDecContext *s = avctx->priv_data;
     int i;
 
-    for (int i = 0; i < 3; i++) {
+    for (int i = 0; i < 3; i++)
         av_freep(&s->temp[i]);
-        s->temp16[i] = NULL;
-    }
 
     av_freep(&s->bitstream_buffer);
 
@@ -607,7 +607,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
         s->temp[i] = av_malloc(4 * avctx->width + 16);
         if (!s->temp[i])
             return AVERROR(ENOMEM);
-        s->temp16[i] = (uint16_t*)s->temp[i];
     }
 
     return 0;
diff --git a/libavcodec/huffyuvenc.c b/libavcodec/huffyuvenc.c
index 8329666fc0..4f709143a2 100644
--- a/libavcodec/huffyuvenc.c
+++ b/libavcodec/huffyuvenc.c
@@ -65,8 +65,10 @@ typedef struct HYuvEncContext {
     int context;
     int picture_number;
 
-    uint8_t *temp[3];
-    uint16_t *temp16[3];                    ///< identical to temp but 16bit type
+    union {
+        uint8_t  *temp[3];
+        uint16_t *temp16[3];
+    };
     uint64_t stats[4][MAX_VLC_N];
     uint8_t len[4][MAX_VLC_N];
     uint32_t bits[4][MAX_VLC_N];
@@ -436,7 +438,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
         s->temp[i] = av_malloc(4 * avctx->width + 16);
         if (!s->temp[i])
             return AVERROR(ENOMEM);
-        s->temp16[i] = (uint16_t*)s->temp[i];
     }
 
     return 0;
@@ -1040,10 +1041,8 @@ static av_cold int encode_end(AVCodecContext *avctx)
 
     av_freep(&avctx->stats_out);
 
-    for (int i = 0; i < 3; i++) {
+    for (int i = 0; i < 3; i++)
         av_freep(&s->temp[i]);
-        s->temp16[i] = NULL;
-    }
 
     return 0;
 }



More information about the ffmpeg-cvslog mailing list