History

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

Reimar Döffinger committed 16 years ago

Commit 2efcde71 parent 177477f1 file · +11 −9Browse files

Unified · Split

libavcodec/rawdec.c+11−9
@@ -29,6 +29,7 @@ · 28 unmodified lines
2929 #include "libavutil/intreadwrite.h"
3030
3131 typedef struct RawVideoContext {
32+ uint32_t palette[AVPALETTE_COUNT];
3233 unsigned char * buffer; /* block of memory for holding one frame */
3334 int length; /* number of bytes in buffer */
3435 int flip;
@@ -81,15 +82,18 @@ static av_cold int raw_init_decoder(AVCodecContext *avctx) · 46 unmodified lines
8182 avctx->pix_fmt = find_pix_fmt(pix_fmt_bps_avi, avctx->bits_per_coded_sample);
8283
8384 context->length = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
84− context->buffer = av_malloc(context->length);
85+ if((avctx->bits_per_coded_sample == 4 || avctx->bits_per_coded_sample == 2) &&
86+ avctx->pix_fmt==PIX_FMT_PAL8 &&
87+ (!avctx->codec_tag || avctx->codec_tag == MKTAG('r','a','w',' '))){
88+ context->buffer = av_malloc(context->length);
89+ if (!context->buffer)
90+ return -1;
91+ }
8592 context->pic.pict_type = FF_I_TYPE;
8693 context->pic.key_frame = 1;
8794
8895 avctx->coded_frame= &context->pic;
8996
90− if (!context->buffer)
91− return -1;
92−
9397 if((avctx->extradata_size >= 9 && !memcmp(avctx->extradata + avctx->extradata_size - 9, "BottomUp", 9)) ||
9498 avctx->codec_tag == MKTAG( 3 , 0 , 0 , 0 ))
9599 context->flip=1;
@@ -117,11 +121,9 @@ static int raw_decode(AVCodecContext *avctx, · 21 unmodified lines
117121 frame->top_field_first = avctx->coded_frame->top_field_first;
118122
119123 //2bpp and 4bpp raw in avi and mov (yes this is ugly ...)
120− if((avctx->bits_per_coded_sample == 4 || avctx->bits_per_coded_sample == 2) &&
121− avctx->pix_fmt==PIX_FMT_PAL8 &&
122− (!avctx->codec_tag || avctx->codec_tag == MKTAG('r','a','w',' '))){
124+ if (context->buffer) {
123125 int i;
124− uint8_t *dst = context->buffer + 256*4;
126+ uint8_t *dst = context->buffer;
125127 buf_size = context->length - 256*4;
126128 if (avctx->bits_per_coded_sample == 4){
127129 for(i=0; 2*i+1 < buf_size; i++){
@@ -147,7 +149,7 @@ static int raw_decode(AVCodecContext *avctx, · 19 unmodified lines
147149
148150 avpicture_fill(picture, buf, avctx->pix_fmt, avctx->width, avctx->height);
149151 if(avctx->pix_fmt==PIX_FMT_PAL8 && buf_size < context->length){
150− frame->data[1]= context->buffer;
152+ frame->data[1]= context->palette;
151153 }
152154 if (avctx->palctrl && avctx->palctrl->palette_changed) {
153155 memcpy(frame->data[1], avctx->palctrl->palette, AVPALETTE_SIZE);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t