Commit 2efcde73 authored by Reimar Döffinger's avatar Reimar Döffinger

rawdec: only allocate a full-frame size buffer if it actually will

be used, place palette buffer in the context to simplify this.

Originally committed as revision 25163 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 177477f5
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
typedef struct RawVideoContext { typedef struct RawVideoContext {
uint32_t palette[AVPALETTE_COUNT];
unsigned char * buffer; /* block of memory for holding one frame */ unsigned char * buffer; /* block of memory for holding one frame */
int length; /* number of bytes in buffer */ int length; /* number of bytes in buffer */
int flip; int flip;
...@@ -81,15 +82,18 @@ static av_cold int raw_init_decoder(AVCodecContext *avctx) ...@@ -81,15 +82,18 @@ static av_cold int raw_init_decoder(AVCodecContext *avctx)
avctx->pix_fmt = find_pix_fmt(pix_fmt_bps_avi, avctx->bits_per_coded_sample); avctx->pix_fmt = find_pix_fmt(pix_fmt_bps_avi, avctx->bits_per_coded_sample);
context->length = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height); context->length = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
context->buffer = av_malloc(context->length); if((avctx->bits_per_coded_sample == 4 || avctx->bits_per_coded_sample == 2) &&
avctx->pix_fmt==PIX_FMT_PAL8 &&
(!avctx->codec_tag || avctx->codec_tag == MKTAG('r','a','w',' '))){
context->buffer = av_malloc(context->length);
if (!context->buffer)
return -1;
}
context->pic.pict_type = FF_I_TYPE; context->pic.pict_type = FF_I_TYPE;
context->pic.key_frame = 1; context->pic.key_frame = 1;
avctx->coded_frame= &context->pic; avctx->coded_frame= &context->pic;
if (!context->buffer)
return -1;
if((avctx->extradata_size >= 9 && !memcmp(avctx->extradata + avctx->extradata_size - 9, "BottomUp", 9)) || if((avctx->extradata_size >= 9 && !memcmp(avctx->extradata + avctx->extradata_size - 9, "BottomUp", 9)) ||
avctx->codec_tag == MKTAG( 3 , 0 , 0 , 0 )) avctx->codec_tag == MKTAG( 3 , 0 , 0 , 0 ))
context->flip=1; context->flip=1;
...@@ -117,11 +121,9 @@ static int raw_decode(AVCodecContext *avctx, ...@@ -117,11 +121,9 @@ static int raw_decode(AVCodecContext *avctx,
frame->top_field_first = avctx->coded_frame->top_field_first; frame->top_field_first = avctx->coded_frame->top_field_first;
//2bpp and 4bpp raw in avi and mov (yes this is ugly ...) //2bpp and 4bpp raw in avi and mov (yes this is ugly ...)
if((avctx->bits_per_coded_sample == 4 || avctx->bits_per_coded_sample == 2) && if (context->buffer) {
avctx->pix_fmt==PIX_FMT_PAL8 &&
(!avctx->codec_tag || avctx->codec_tag == MKTAG('r','a','w',' '))){
int i; int i;
uint8_t *dst = context->buffer + 256*4; uint8_t *dst = context->buffer;
buf_size = context->length - 256*4; buf_size = context->length - 256*4;
if (avctx->bits_per_coded_sample == 4){ if (avctx->bits_per_coded_sample == 4){
for(i=0; 2*i+1 < buf_size; i++){ for(i=0; 2*i+1 < buf_size; i++){
...@@ -147,7 +149,7 @@ static int raw_decode(AVCodecContext *avctx, ...@@ -147,7 +149,7 @@ static int raw_decode(AVCodecContext *avctx,
avpicture_fill(picture, buf, avctx->pix_fmt, avctx->width, avctx->height); avpicture_fill(picture, buf, avctx->pix_fmt, avctx->width, avctx->height);
if(avctx->pix_fmt==PIX_FMT_PAL8 && buf_size < context->length){ if(avctx->pix_fmt==PIX_FMT_PAL8 && buf_size < context->length){
frame->data[1]= context->buffer; frame->data[1]= context->palette;
} }
if (avctx->palctrl && avctx->palctrl->palette_changed) { if (avctx->palctrl && avctx->palctrl->palette_changed) {
memcpy(frame->data[1], avctx->palctrl->palette, AVPALETTE_SIZE); memcpy(frame->data[1], avctx->palctrl->palette, AVPALETTE_SIZE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment