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@outlook.com>
release/7.1
Andreas Rheinhardt 8 months ago
parent eef5d60ac6
commit cf96c0295e
  1. 11
      libavcodec/huffyuvdec.c
  2. 11
      libavcodec/huffyuvenc.c

@ -70,8 +70,10 @@ typedef struct HYuvDecContext {
int context; int context;
int last_slice_end; int last_slice_end;
uint8_t *temp[3]; union {
uint16_t *temp16[3]; ///< identical to temp but 16bit type uint8_t *temp[3];
uint16_t *temp16[3];
};
uint8_t len[4][MAX_VLC_N]; uint8_t len[4][MAX_VLC_N];
uint32_t bits[4][MAX_VLC_N]; uint32_t bits[4][MAX_VLC_N];
uint32_t pix_bgr_map[1<<VLC_BITS]; 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; HYuvDecContext *s = avctx->priv_data;
int i; int i;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++)
av_freep(&s->temp[i]); av_freep(&s->temp[i]);
s->temp16[i] = NULL;
}
av_freep(&s->bitstream_buffer); 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); s->temp[i] = av_malloc(4 * avctx->width + 16);
if (!s->temp[i]) if (!s->temp[i])
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
s->temp16[i] = (uint16_t*)s->temp[i];
} }
return 0; return 0;

@ -65,8 +65,10 @@ typedef struct HYuvEncContext {
int context; int context;
int picture_number; int picture_number;
uint8_t *temp[3]; union {
uint16_t *temp16[3]; ///< identical to temp but 16bit type uint8_t *temp[3];
uint16_t *temp16[3];
};
uint64_t stats[4][MAX_VLC_N]; uint64_t stats[4][MAX_VLC_N];
uint8_t len[4][MAX_VLC_N]; uint8_t len[4][MAX_VLC_N];
uint32_t bits[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); s->temp[i] = av_malloc(4 * avctx->width + 16);
if (!s->temp[i]) if (!s->temp[i])
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
s->temp16[i] = (uint16_t*)s->temp[i];
} }
return 0; return 0;
@ -1040,10 +1041,8 @@ static av_cold int encode_end(AVCodecContext *avctx)
av_freep(&avctx->stats_out); av_freep(&avctx->stats_out);
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++)
av_freep(&s->temp[i]); av_freep(&s->temp[i]);
s->temp16[i] = NULL;
}
return 0; return 0;
} }

Loading…
Cancel
Save