mp->offset_bits_len = av_log2(avctx->width * avctx->height) + 1;
mp->vpt = av_mallocz(avctx->height * sizeof(YuvPixel));
mp->hpt = av_mallocz(h4 * w4 / 16 * sizeof(YuvPixel));
+ if (!mp->changes_map || !mp->vpt || !mp->hpt) {
+ av_freep(&mp->changes_map);
+ av_freep(&mp->vpt);
+ av_freep(&mp->hpt);
+ return AVERROR(ENOMEM);
+ }
avctx->pix_fmt = AV_PIX_FMT_RGB555;
- avcodec_get_frame_defaults(&mp->frame);
+
+ mp->frame = av_frame_alloc();
+ if (!mp->frame) {
+ mp_decode_end(avctx);
+ return AVERROR(ENOMEM);
+ }
+
return 0;
}
GetBitContext gb;
int i, count1, count2, sz, ret;
- if ((ret = ff_reget_buffer(avctx, &mp->frame)) < 0)
- if ((ret = ff_reget_buffer(avctx, mp->frame)) < 0) {
- av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
++ if ((ret = ff_reget_buffer(avctx, mp->frame)) < 0)
return ret;
- }
/* le32 bitstream msb first */
- av_fast_malloc(&mp->bswapbuf, &mp->bswapbuf_size, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ av_fast_padded_malloc(&mp->bswapbuf, &mp->bswapbuf_size, buf_size);
if (!mp->bswapbuf)
return AVERROR(ENOMEM);
mp->dsp.bswap_buf((uint32_t *)mp->bswapbuf, (const uint32_t *)buf, buf_size / 4);
goto end;
if (mp->changes_map[0] == 0) {
- *(uint16_t *)mp->frame.data[0] = get_bits(&gb, 15);
+ *(uint16_t *)mp->frame->data[0] = get_bits(&gb, 15);
mp->changes_map[0] = 1;
}
- mp_read_codes_table(mp, &gb);
+ if (mp_read_codes_table(mp, &gb) < 0)
+ goto end;
sz = get_bits(&gb, 18);
if (avctx->extradata[0] != 5)
unsigned short color4[4];
unsigned char index, idx;
unsigned short ta, tb;
- unsigned short *pixels = (unsigned short *)s->frame.data[0];
+ unsigned short *pixels = (unsigned short *)s->frame->data[0];
int row_ptr = 0;
- int pixel_ptr = 0;
+ int pixel_ptr = -4;
int block_ptr;
int pixel_x, pixel_y;
int total_blocks;
s->buf = buf;
s->size = buf_size;
- if ((ret = ff_reget_buffer(avctx, &s->frame)) < 0)
- if ((ret = ff_reget_buffer(avctx, s->frame)) < 0) {
- av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
++ if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
return ret;
- }
rpza_decode_stream(s);
return AVERROR_INVALIDDATA;
}
- if ((frame_width == s->avctx->width && frame_height == s->avctx->height) &&
- (frame_x || frame_y)) {
-
- s->x_off = frame_x;
- s->y_off = frame_y;
- }
- frame_x -= s->x_off;
- frame_y -= s->y_off;
-
/* if only a certain region will be updated, copy the entire previous
* frame before the decode */
- if (s->prev_frame.data[0] &&
+ if (s->prev_frame->data[0] &&
(frame_x || frame_y || (frame_width != s->avctx->width) ||
(frame_height != s->avctx->height))) {
return 0;
}
- av_free(s->unpack_buffer);
+ static av_cold int vmdvideo_decode_end(AVCodecContext *avctx)
+ {
+ VmdVideoContext *s = avctx->priv_data;
+
+ av_frame_free(&s->prev_frame);
++ av_freep(&s->unpack_buffer);
++ s->unpack_buffer_size = 0;
+
+ return 0;
+ }
+
static av_cold int vmdvideo_decode_init(AVCodecContext *avctx)
{
VmdVideoContext *s = avctx->priv_data;
r = raw_palette[palette_index++] * 4;
g = raw_palette[palette_index++] * 4;
b = raw_palette[palette_index++] * 4;
- palette32[i] = (r << 16) | (g << 8) | (b);
+ palette32[i] = 0xFFU << 24 | (r << 16) | (g << 8) | (b);
+ palette32[i] |= palette32[i] >> 6 & 0x30303;
}
- avcodec_get_frame_defaults(&s->prev_frame);
+ s->prev_frame = av_frame_alloc();
+ if (!s->prev_frame) {
+ vmdvideo_decode_end(avctx);
+ return AVERROR(ENOMEM);
+ }
return 0;
}
return buf_size;
}
- static av_cold int vmdvideo_decode_end(AVCodecContext *avctx)
- {
- VmdVideoContext *s = avctx->priv_data;
-
- av_frame_unref(&s->prev_frame);
- av_freep(&s->unpack_buffer);
- s->unpack_buffer_size = 0;
-
- return 0;
- }
-
--
/*
* Audio Decoder
*/