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>
This commit is contained in:
Andreas Rheinhardt 2024-04-04 05:59:57 +02:00
parent eef5d60ac6
commit cf96c0295e
2 changed files with 10 additions and 12 deletions

View File

@ -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;

View File

@ -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;
}