comparison mjpegdec.c @ 5068:93e369c55c31 libavcodec

fix mjpeg decoding with broken huffman table headers
author ods15
date Wed, 23 May 2007 18:41:34 +0000
parents 924fdd6175b1
children b985439e3e15
comparison
equal deleted inserted replaced
5067:6166fbf375cc 5068:93e369c55c31
60 } 60 }
61 61
62 return init_vlc(vlc, 9, nb_codes, huff_size, 1, 1, huff_code, 2, 2, use_static); 62 return init_vlc(vlc, 9, nb_codes, huff_size, 1, 1, huff_code, 2, 2, use_static);
63 } 63 }
64 64
65 static void build_basic_mjpeg_vlc(MJpegDecodeContext * s) {
66 build_vlc(&s->vlcs[0][0], ff_mjpeg_bits_dc_luminance,
67 ff_mjpeg_val_dc_luminance, 12, 0, 0);
68 build_vlc(&s->vlcs[0][1], ff_mjpeg_bits_dc_chrominance,
69 ff_mjpeg_val_dc_chrominance, 12, 0, 0);
70 build_vlc(&s->vlcs[1][0], ff_mjpeg_bits_ac_luminance,
71 ff_mjpeg_val_ac_luminance, 251, 0, 1);
72 build_vlc(&s->vlcs[1][1], ff_mjpeg_bits_ac_chrominance,
73 ff_mjpeg_val_ac_chrominance, 251, 0, 1);
74 }
75
65 int ff_mjpeg_decode_init(AVCodecContext *avctx) 76 int ff_mjpeg_decode_init(AVCodecContext *avctx)
66 { 77 {
67 MJpegDecodeContext *s = avctx->priv_data; 78 MJpegDecodeContext *s = avctx->priv_data;
68 79
69 s->avctx = avctx; 80 s->avctx = avctx;
73 s->buffer = NULL; 84 s->buffer = NULL;
74 s->start_code = -1; 85 s->start_code = -1;
75 s->first_picture = 1; 86 s->first_picture = 1;
76 s->org_height = avctx->coded_height; 87 s->org_height = avctx->coded_height;
77 88
78 build_vlc(&s->vlcs[0][0], ff_mjpeg_bits_dc_luminance, 89 build_basic_mjpeg_vlc(s);
79 ff_mjpeg_val_dc_luminance, 12, 0, 0);
80 build_vlc(&s->vlcs[0][1], ff_mjpeg_bits_dc_chrominance,
81 ff_mjpeg_val_dc_chrominance, 12, 0, 0);
82 build_vlc(&s->vlcs[1][0], ff_mjpeg_bits_ac_luminance,
83 ff_mjpeg_val_ac_luminance, 251, 0, 1);
84 build_vlc(&s->vlcs[1][1], ff_mjpeg_bits_ac_chrominance,
85 ff_mjpeg_val_ac_chrominance, 251, 0, 1);
86 90
87 if (avctx->flags & CODEC_FLAG_EXTERN_HUFF) 91 if (avctx->flags & CODEC_FLAG_EXTERN_HUFF)
88 { 92 {
89 av_log(avctx, AV_LOG_INFO, "mjpeg: using external huffman table\n"); 93 av_log(avctx, AV_LOG_INFO, "mjpeg: using external huffman table\n");
90 init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8); 94 init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8);
91 ff_mjpeg_decode_dht(s); 95 if (ff_mjpeg_decode_dht(s)) {
92 /* should check for error - but dunno */ 96 av_log(avctx, AV_LOG_ERROR, "mjpeg: error using external huffman table, switching back to internal\n");
97 build_basic_mjpeg_vlc(s);
98 }
93 } 99 }
94 if (avctx->extradata_size > 9 && 100 if (avctx->extradata_size > 9 &&
95 AV_RL32(avctx->extradata + 4) == MKTAG('f','i','e','l')) { 101 AV_RL32(avctx->extradata + 4) == MKTAG('f','i','e','l')) {
96 if (avctx->extradata[9] == 6) { /* quicktime icefloe 019 */ 102 if (avctx->extradata[9] == 6) { /* quicktime icefloe 019 */
97 s->interlace_polarity = 1; /* bottom field first */ 103 s->interlace_polarity = 1; /* bottom field first */