X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fqtrle.c;h=28f1720aea2db405fbe4f74105e65bf4d868e798;hb=b0de1c766329dd8c9960ad1722e2f653160abc1b;hp=3f173a596bb2054ee47ae805f3d98e446ad3d9c9;hpb=716d413c13981da15323c7a3821860536eefdbbb;p=ffmpeg diff --git a/libavcodec/qtrle.c b/libavcodec/qtrle.c index 3f173a596bb..28f1720aea2 100644 --- a/libavcodec/qtrle.c +++ b/libavcodec/qtrle.c @@ -37,32 +37,36 @@ #include "avcodec.h" #include "bytestream.h" +#include "internal.h" typedef struct QtrleContext { AVCodecContext *avctx; - AVFrame frame; + AVFrame *frame; GetByteContext g; uint32_t pal[256]; } QtrleContext; -#define CHECK_PIXEL_PTR(n) \ - if ((pixel_ptr + n > pixel_limit) || (pixel_ptr + n < 0)) { \ - av_log (s->avctx, AV_LOG_INFO, "Problem: pixel_ptr = %d, pixel_limit = %d\n", \ - pixel_ptr + n, pixel_limit); \ - return; \ - } \ +#define CHECK_PIXEL_PTR(n) \ + if ((pixel_ptr + n > pixel_limit) || (pixel_ptr + n < 0)) { \ + av_log (s->avctx, AV_LOG_ERROR, "Problem: pixel_ptr = %d, pixel_limit = %d\n",\ + pixel_ptr + n, pixel_limit); \ + return; \ + } \ static void qtrle_decode_1bpp(QtrleContext *s, int row_ptr, int lines_to_change) { int rle_code; - int pixel_ptr = 0; - int row_inc = s->frame.linesize[0]; + int pixel_ptr; + int row_inc = s->frame->linesize[0]; unsigned char pi0, pi1; /* 2 8-pixel values */ - unsigned char *rgb = s->frame.data[0]; - int pixel_limit = s->frame.linesize[0] * s->avctx->height; + unsigned char *rgb = s->frame->data[0]; + int pixel_limit = s->frame->linesize[0] * s->avctx->height; int skip; + row_ptr -= row_inc; + pixel_ptr = row_ptr; + lines_to_change++; while (lines_to_change) { skip = bytestream2_get_byte(&s->g); rle_code = (signed char)bytestream2_get_byte(&s->g); @@ -106,14 +110,15 @@ static inline void qtrle_decode_2n4bpp(QtrleContext *s, int row_ptr, { int rle_code, i; int pixel_ptr; - int row_inc = s->frame.linesize[0]; + int row_inc = s->frame->linesize[0]; unsigned char pi[16]; /* 16 palette indices */ - unsigned char *rgb = s->frame.data[0]; - int pixel_limit = s->frame.linesize[0] * s->avctx->height; + unsigned char *rgb = s->frame->data[0]; + int pixel_limit = s->frame->linesize[0] * s->avctx->height; int num_pixels = (bpp == 4) ? 8 : 16; while (lines_to_change--) { pixel_ptr = row_ptr + (num_pixels * (bytestream2_get_byte(&s->g) - 1)); + CHECK_PIXEL_PTR(0); while ((rle_code = (signed char)bytestream2_get_byte(&s->g)) != -1) { if (rle_code == 0) { @@ -161,13 +166,14 @@ static void qtrle_decode_8bpp(QtrleContext *s, int row_ptr, int lines_to_change) { int rle_code; int pixel_ptr; - int row_inc = s->frame.linesize[0]; + int row_inc = s->frame->linesize[0]; unsigned char pi1, pi2, pi3, pi4; /* 4 palette indexes */ - unsigned char *rgb = s->frame.data[0]; - int pixel_limit = s->frame.linesize[0] * s->avctx->height; + unsigned char *rgb = s->frame->data[0]; + int pixel_limit = s->frame->linesize[0] * s->avctx->height; while (lines_to_change--) { pixel_ptr = row_ptr + (4 * (bytestream2_get_byte(&s->g) - 1)); + CHECK_PIXEL_PTR(0); while ((rle_code = (signed char)bytestream2_get_byte(&s->g)) != -1) { if (rle_code == 0) { @@ -210,13 +216,14 @@ static void qtrle_decode_16bpp(QtrleContext *s, int row_ptr, int lines_to_change { int rle_code; int pixel_ptr; - int row_inc = s->frame.linesize[0]; + int row_inc = s->frame->linesize[0]; unsigned short rgb16; - unsigned char *rgb = s->frame.data[0]; - int pixel_limit = s->frame.linesize[0] * s->avctx->height; + unsigned char *rgb = s->frame->data[0]; + int pixel_limit = s->frame->linesize[0] * s->avctx->height; while (lines_to_change--) { pixel_ptr = row_ptr + (bytestream2_get_byte(&s->g) - 1) * 2; + CHECK_PIXEL_PTR(0); while ((rle_code = (signed char)bytestream2_get_byte(&s->g)) != -1) { if (rle_code == 0) { @@ -253,13 +260,14 @@ static void qtrle_decode_24bpp(QtrleContext *s, int row_ptr, int lines_to_change { int rle_code; int pixel_ptr; - int row_inc = s->frame.linesize[0]; + int row_inc = s->frame->linesize[0]; unsigned char r, g, b; - unsigned char *rgb = s->frame.data[0]; - int pixel_limit = s->frame.linesize[0] * s->avctx->height; + unsigned char *rgb = s->frame->data[0]; + int pixel_limit = s->frame->linesize[0] * s->avctx->height; while (lines_to_change--) { pixel_ptr = row_ptr + (bytestream2_get_byte(&s->g) - 1) * 3; + CHECK_PIXEL_PTR(0); while ((rle_code = (signed char)bytestream2_get_byte(&s->g)) != -1) { if (rle_code == 0) { @@ -299,13 +307,14 @@ static void qtrle_decode_32bpp(QtrleContext *s, int row_ptr, int lines_to_change { int rle_code; int pixel_ptr; - int row_inc = s->frame.linesize[0]; + int row_inc = s->frame->linesize[0]; unsigned int argb; - unsigned char *rgb = s->frame.data[0]; - int pixel_limit = s->frame.linesize[0] * s->avctx->height; + unsigned char *rgb = s->frame->data[0]; + int pixel_limit = s->frame->linesize[0] * s->avctx->height; while (lines_to_change--) { pixel_ptr = row_ptr + (bytestream2_get_byte(&s->g) - 1) * 4; + CHECK_PIXEL_PTR(0); while ((rle_code = (signed char)bytestream2_get_byte(&s->g)) != -1) { if (rle_code == 0) { @@ -376,27 +385,27 @@ static av_cold int qtrle_decode_init(AVCodecContext *avctx) return AVERROR_INVALIDDATA; } - s->frame.data[0] = NULL; + s->frame = av_frame_alloc(); + if (!s->frame) + return AVERROR(ENOMEM); return 0; } static int qtrle_decode_frame(AVCodecContext *avctx, - void *data, int *data_size, + void *data, int *got_frame, AVPacket *avpkt) { QtrleContext *s = avctx->priv_data; int header, start_line; int height, row_ptr; int has_palette = 0; + int ret; bytestream2_init(&s->g, avpkt->data, avpkt->size); - s->frame.reference = 1; - s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | - FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE; - if (avctx->reget_buffer(avctx, &s->frame)) { + if ((ret = ff_reget_buffer(avctx, s->frame)) < 0) { av_log (s->avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); - return -1; + return ret; } /* check if this frame is even supposed to change */ @@ -421,7 +430,7 @@ static int qtrle_decode_frame(AVCodecContext *avctx, start_line = 0; height = s->avctx->height; } - row_ptr = s->frame.linesize[0] * start_line; + row_ptr = s->frame->linesize[0] * start_line; switch (avctx->bits_per_coded_sample) { case 1: @@ -469,17 +478,18 @@ static int qtrle_decode_frame(AVCodecContext *avctx, const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); if (pal) { - s->frame.palette_has_changed = 1; + s->frame->palette_has_changed = 1; memcpy(s->pal, pal, AVPALETTE_SIZE); } /* make the palette available on the way out */ - memcpy(s->frame.data[1], s->pal, AVPALETTE_SIZE); + memcpy(s->frame->data[1], s->pal, AVPALETTE_SIZE); } done: - *data_size = sizeof(AVFrame); - *(AVFrame*)data = s->frame; + if ((ret = av_frame_ref(data, s->frame)) < 0) + return ret; + *got_frame = 1; /* always report that the buffer was completely consumed */ return avpkt->size; @@ -489,14 +499,14 @@ static av_cold int qtrle_decode_end(AVCodecContext *avctx) { QtrleContext *s = avctx->priv_data; - if (s->frame.data[0]) - avctx->release_buffer(avctx, &s->frame); + av_frame_free(&s->frame); return 0; } AVCodec ff_qtrle_decoder = { .name = "qtrle", + .long_name = NULL_IF_CONFIG_SMALL("QuickTime Animation (RLE) video"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_QTRLE, .priv_data_size = sizeof(QtrleContext), @@ -504,5 +514,4 @@ AVCodec ff_qtrle_decoder = { .close = qtrle_decode_end, .decode = qtrle_decode_frame, .capabilities = CODEC_CAP_DR1, - .long_name = NULL_IF_CONFIG_SMALL("QuickTime Animation (RLE) video"), };