comparison rawdec.c @ 12514:e6d711ba5760 libavcodec

rawdec: ensure that there is always a valid palette for formats that should have one like gray8 etc.
author reimar
date Sat, 25 Sep 2010 08:44:35 +0000
parents 46191b10d663
children
comparison
equal deleted inserted replaced
12513:66c6184769af 12514:e6d711ba5760
23 * @file 23 * @file
24 * Raw Video Decoder 24 * Raw Video Decoder
25 */ 25 */
26 26
27 #include "avcodec.h" 27 #include "avcodec.h"
28 #include "imgconvert.h"
28 #include "raw.h" 29 #include "raw.h"
29 #include "libavutil/intreadwrite.h" 30 #include "libavutil/intreadwrite.h"
31 #include "libavcore/imgutils.h"
30 32
31 typedef struct RawVideoContext { 33 typedef struct RawVideoContext {
32 uint32_t palette[AVPALETTE_COUNT]; 34 uint32_t palette[AVPALETTE_COUNT];
33 unsigned char * buffer; /* block of memory for holding one frame */ 35 unsigned char * buffer; /* block of memory for holding one frame */
34 int length; /* number of bytes in buffer */ 36 int length; /* number of bytes in buffer */
79 else if (avctx->codec_tag) 81 else if (avctx->codec_tag)
80 avctx->pix_fmt = find_pix_fmt(ff_raw_pix_fmt_tags, avctx->codec_tag); 82 avctx->pix_fmt = find_pix_fmt(ff_raw_pix_fmt_tags, avctx->codec_tag);
81 else if (avctx->pix_fmt == PIX_FMT_NONE && avctx->bits_per_coded_sample) 83 else if (avctx->pix_fmt == PIX_FMT_NONE && avctx->bits_per_coded_sample)
82 avctx->pix_fmt = find_pix_fmt(pix_fmt_bps_avi, avctx->bits_per_coded_sample); 84 avctx->pix_fmt = find_pix_fmt(pix_fmt_bps_avi, avctx->bits_per_coded_sample);
83 85
86 ff_set_systematic_pal(context->palette, avctx->pix_fmt);
84 context->length = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height); 87 context->length = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
85 if((avctx->bits_per_coded_sample == 4 || avctx->bits_per_coded_sample == 2) && 88 if((avctx->bits_per_coded_sample == 4 || avctx->bits_per_coded_sample == 2) &&
86 avctx->pix_fmt==PIX_FMT_PAL8 && 89 avctx->pix_fmt==PIX_FMT_PAL8 &&
87 (!avctx->codec_tag || avctx->codec_tag == MKTAG('r','a','w',' '))){ 90 (!avctx->codec_tag || avctx->codec_tag == MKTAG('r','a','w',' '))){
88 context->buffer = av_malloc(context->length); 91 context->buffer = av_malloc(context->length);
146 149
147 if(buf_size < context->length - (avctx->pix_fmt==PIX_FMT_PAL8 ? 256*4 : 0)) 150 if(buf_size < context->length - (avctx->pix_fmt==PIX_FMT_PAL8 ? 256*4 : 0))
148 return -1; 151 return -1;
149 152
150 avpicture_fill(picture, buf, avctx->pix_fmt, avctx->width, avctx->height); 153 avpicture_fill(picture, buf, avctx->pix_fmt, avctx->width, avctx->height);
151 if(avctx->pix_fmt==PIX_FMT_PAL8 && buf_size < context->length){ 154 if((avctx->pix_fmt==PIX_FMT_PAL8 && buf_size < context->length) ||
155 (avctx->pix_fmt!=PIX_FMT_PAL8 &&
156 (av_pix_fmt_descriptors[avctx->pix_fmt].flags & PIX_FMT_PAL))){
152 frame->data[1]= context->palette; 157 frame->data[1]= context->palette;
153 } 158 }
154 if (avctx->palctrl && avctx->palctrl->palette_changed) { 159 if (avctx->palctrl && avctx->palctrl->palette_changed) {
155 memcpy(frame->data[1], avctx->palctrl->palette, AVPALETTE_SIZE); 160 memcpy(frame->data[1], avctx->palctrl->palette, AVPALETTE_SIZE);
156 avctx->palctrl->palette_changed = 0; 161 avctx->palctrl->palette_changed = 0;