mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-24 13:56:33 +02:00
pngdec: use av_fast_padded_malloc(z)
Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
parent
8fbf940e16
commit
dd1d29bd5f
@ -60,7 +60,10 @@ typedef struct PNGDecContext {
|
|||||||
uint32_t palette[256];
|
uint32_t palette[256];
|
||||||
uint8_t *crow_buf;
|
uint8_t *crow_buf;
|
||||||
uint8_t *last_row;
|
uint8_t *last_row;
|
||||||
|
int last_row_size;
|
||||||
uint8_t *tmp_row;
|
uint8_t *tmp_row;
|
||||||
|
uint8_t *buffer;
|
||||||
|
int buffer_size;
|
||||||
int pass;
|
int pass;
|
||||||
int crow_size; /* compressed row size (include filter type) */
|
int crow_size; /* compressed row size (include filter type) */
|
||||||
int row_size; /* decompressed row size */
|
int row_size; /* decompressed row size */
|
||||||
@ -509,7 +512,6 @@ static int decode_frame(AVCodecContext *avctx,
|
|||||||
int buf_size = avpkt->size;
|
int buf_size = avpkt->size;
|
||||||
AVFrame *p;
|
AVFrame *p;
|
||||||
AVDictionary *metadata = NULL;
|
AVDictionary *metadata = NULL;
|
||||||
uint8_t *crow_buf_base = NULL;
|
|
||||||
uint32_t tag, length;
|
uint32_t tag, length;
|
||||||
int64_t sig;
|
int64_t sig;
|
||||||
int ret;
|
int ret;
|
||||||
@ -667,7 +669,7 @@ static int decode_frame(AVCodecContext *avctx,
|
|||||||
if (avctx->pix_fmt == AV_PIX_FMT_PAL8)
|
if (avctx->pix_fmt == AV_PIX_FMT_PAL8)
|
||||||
memcpy(p->data[1], s->palette, 256 * sizeof(uint32_t));
|
memcpy(p->data[1], s->palette, 256 * sizeof(uint32_t));
|
||||||
/* empty row is used if differencing to the first row */
|
/* empty row is used if differencing to the first row */
|
||||||
s->last_row = av_mallocz(s->row_size);
|
av_fast_padded_mallocz(&s->last_row, &s->last_row_size, s->row_size);
|
||||||
if (!s->last_row)
|
if (!s->last_row)
|
||||||
goto fail;
|
goto fail;
|
||||||
if (s->interlace_type ||
|
if (s->interlace_type ||
|
||||||
@ -677,12 +679,12 @@ static int decode_frame(AVCodecContext *avctx,
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
/* compressed row */
|
/* compressed row */
|
||||||
crow_buf_base = av_malloc(s->row_size + 16);
|
av_fast_padded_malloc(&s->buffer, &s->buffer_size, s->row_size + 16);
|
||||||
if (!crow_buf_base)
|
if (!s->buffer)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
/* we want crow_buf+1 to be 16-byte aligned */
|
/* we want crow_buf+1 to be 16-byte aligned */
|
||||||
s->crow_buf = crow_buf_base + 15;
|
s->crow_buf = s->buffer + 15;
|
||||||
s->zstream.avail_out = s->crow_size;
|
s->zstream.avail_out = s->crow_size;
|
||||||
s->zstream.next_out = s->crow_buf;
|
s->zstream.next_out = s->crow_buf;
|
||||||
}
|
}
|
||||||
@ -861,9 +863,7 @@ static int decode_frame(AVCodecContext *avctx,
|
|||||||
ret = bytestream2_tell(&s->gb);
|
ret = bytestream2_tell(&s->gb);
|
||||||
the_end:
|
the_end:
|
||||||
inflateEnd(&s->zstream);
|
inflateEnd(&s->zstream);
|
||||||
av_free(crow_buf_base);
|
|
||||||
s->crow_buf = NULL;
|
s->crow_buf = NULL;
|
||||||
av_freep(&s->last_row);
|
|
||||||
av_freep(&s->tmp_row);
|
av_freep(&s->tmp_row);
|
||||||
return ret;
|
return ret;
|
||||||
fail:
|
fail:
|
||||||
@ -914,6 +914,10 @@ static av_cold int png_dec_end(AVCodecContext *avctx)
|
|||||||
av_frame_free(&s->last_picture.f);
|
av_frame_free(&s->last_picture.f);
|
||||||
ff_thread_release_buffer(avctx, &s->picture);
|
ff_thread_release_buffer(avctx, &s->picture);
|
||||||
av_frame_free(&s->picture.f);
|
av_frame_free(&s->picture.f);
|
||||||
|
av_freep(&s->buffer);
|
||||||
|
s->buffer_size = 0;
|
||||||
|
av_freep(&s->last_row);
|
||||||
|
s->last_row_size = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user