Originally committed as revision 25163 to svn://svn.ffmpeg.org/ffmpeg/trunk
Unified · Split
| @@ -29,6 +29,7 @@ · 28 unmodified lines | |||
| 29 | #include "libavutil/intreadwrite.h" | 29 | #include "libavutil/intreadwrite.h" |
| 30 | 30 | ||
| 31 | typedef struct RawVideoContext { | 31 | typedef struct RawVideoContext { |
| 32 | uint32_t palette[AVPALETTE_COUNT]; | ||
| 32 | unsigned char * buffer; /* block of memory for holding one frame */ | 33 | unsigned char * buffer; /* block of memory for holding one frame */ |
| 33 | int length; /* number of bytes in buffer */ | 34 | int length; /* number of bytes in buffer */ |
| 34 | int flip; | 35 | int flip; |
| @@ -81,15 +82,18 @@ static av_cold int raw_init_decoder(AVCodecContext *avctx) · 46 unmodified lines | |||
| 81 | avctx->pix_fmt = find_pix_fmt(pix_fmt_bps_avi, avctx->bits_per_coded_sample); | 82 | avctx->pix_fmt = find_pix_fmt(pix_fmt_bps_avi, avctx->bits_per_coded_sample); |
| 82 | 83 | ||
| 83 | context->length = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height); | 84 | 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 | } | ||
| 85 | context->pic.pict_type = FF_I_TYPE; | 92 | context->pic.pict_type = FF_I_TYPE; |
| 86 | context->pic.key_frame = 1; | 93 | context->pic.key_frame = 1; |
| 87 | 94 | ||
| 88 | avctx->coded_frame= &context->pic; | 95 | avctx->coded_frame= &context->pic; |
| 89 | 96 | ||
| 90 | if (!context->buffer) | ||
| 91 | return -1; | ||
| 92 | |||
| 93 | if((avctx->extradata_size >= 9 && !memcmp(avctx->extradata + avctx->extradata_size - 9, "BottomUp", 9)) || | 97 | if((avctx->extradata_size >= 9 && !memcmp(avctx->extradata + avctx->extradata_size - 9, "BottomUp", 9)) || |
| 94 | avctx->codec_tag == MKTAG( 3 , 0 , 0 , 0 )) | 98 | avctx->codec_tag == MKTAG( 3 , 0 , 0 , 0 )) |
| 95 | context->flip=1; | 99 | context->flip=1; |
| @@ -117,11 +121,9 @@ static int raw_decode(AVCodecContext *avctx, · 21 unmodified lines | |||
| 117 | frame->top_field_first = avctx->coded_frame->top_field_first; | 121 | frame->top_field_first = avctx->coded_frame->top_field_first; |
| 118 | 122 | ||
| 119 | //2bpp and 4bpp raw in avi and mov (yes this is ugly ...) | 123 | //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) && | 124 | if (context->buffer) { |
| 121 | avctx->pix_fmt==PIX_FMT_PAL8 && | ||
| 122 | (!avctx->codec_tag || avctx->codec_tag == MKTAG('r','a','w',' '))){ | ||
| 123 | int i; | 125 | int i; |
| 124 | uint8_t *dst = context->buffer + 256*4; | 126 | uint8_t *dst = context->buffer; |
| 125 | buf_size = context->length - 256*4; | 127 | buf_size = context->length - 256*4; |
| 126 | if (avctx->bits_per_coded_sample == 4){ | 128 | if (avctx->bits_per_coded_sample == 4){ |
| 127 | for(i=0; 2*i+1 < buf_size; i++){ | 129 | for(i=0; 2*i+1 < buf_size; i++){ |
| @@ -147,7 +149,7 @@ static int raw_decode(AVCodecContext *avctx, · 19 unmodified lines | |||
| 147 | 149 | ||
| 148 | avpicture_fill(picture, buf, avctx->pix_fmt, avctx->width, avctx->height); | 150 | avpicture_fill(picture, buf, avctx->pix_fmt, avctx->width, avctx->height); |
| 149 | if(avctx->pix_fmt==PIX_FMT_PAL8 && buf_size < context->length){ | 151 | if(avctx->pix_fmt==PIX_FMT_PAL8 && buf_size < context->length){ |
| 150 | frame->data[1]= context->buffer; | 152 | frame->data[1]= context->palette; |
| 151 | } | 153 | } |
| 152 | if (avctx->palctrl && avctx->palctrl->palette_changed) { | 154 | if (avctx->palctrl && avctx->palctrl->palette_changed) { |
| 153 | memcpy(frame->data[1], avctx->palctrl->palette, AVPALETTE_SIZE); | 155 | memcpy(frame->data[1], avctx->palctrl->palette, AVPALETTE_SIZE); |