comparison mjpeg.c @ 1351:0fc1a6f8ca94 libavcodec

few more error checks
author michaelni
date Tue, 08 Jul 2003 22:12:17 +0000
parents 1cbc2380d172
children a6b92de6a9fc
comparison
equal deleted inserted replaced
1350:e7c8051e1849 1351:0fc1a6f8ca94
840 int interlace_polarity; 840 int interlace_polarity;
841 } MJpegDecodeContext; 841 } MJpegDecodeContext;
842 842
843 static int mjpeg_decode_dht(MJpegDecodeContext *s); 843 static int mjpeg_decode_dht(MJpegDecodeContext *s);
844 844
845 static void build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table, 845 static int build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table,
846 int nb_codes) 846 int nb_codes)
847 { 847 {
848 uint8_t huff_size[256]; 848 uint8_t huff_size[256];
849 uint16_t huff_code[256]; 849 uint16_t huff_code[256];
850 850
851 memset(huff_size, 0, sizeof(huff_size)); 851 memset(huff_size, 0, sizeof(huff_size));
852 build_huffman_codes(huff_size, huff_code, bits_table, val_table); 852 build_huffman_codes(huff_size, huff_code, bits_table, val_table);
853 853
854 init_vlc(vlc, 9, nb_codes, huff_size, 1, 1, huff_code, 2, 2); 854 return init_vlc(vlc, 9, nb_codes, huff_size, 1, 1, huff_code, 2, 2);
855 } 855 }
856 856
857 static int mjpeg_decode_init(AVCodecContext *avctx) 857 static int mjpeg_decode_init(AVCodecContext *avctx)
858 { 858 {
859 MJpegDecodeContext *s = avctx->priv_data; 859 MJpegDecodeContext *s = avctx->priv_data;
968 968
969 /* build VLC and flush previous vlc if present */ 969 /* build VLC and flush previous vlc if present */
970 free_vlc(&s->vlcs[class][index]); 970 free_vlc(&s->vlcs[class][index]);
971 dprintf("class=%d index=%d nb_codes=%d\n", 971 dprintf("class=%d index=%d nb_codes=%d\n",
972 class, index, code_max + 1); 972 class, index, code_max + 1);
973 build_vlc(&s->vlcs[class][index], bits_table, val_table, code_max + 1); 973 if(build_vlc(&s->vlcs[class][index], bits_table, val_table, code_max + 1) < 0){
974 return -1;
975 }
974 } 976 }
975 return 0; 977 return 0;
976 } 978 }
977 979
978 static int mjpeg_decode_sof(MJpegDecodeContext *s) 980 static int mjpeg_decode_sof(MJpegDecodeContext *s)
1776 break; 1778 break;
1777 case DQT: 1779 case DQT:
1778 mjpeg_decode_dqt(s); 1780 mjpeg_decode_dqt(s);
1779 break; 1781 break;
1780 case DHT: 1782 case DHT:
1781 mjpeg_decode_dht(s); 1783 if(mjpeg_decode_dht(s) < 0){
1784 fprintf(stderr, "huffman table decode error\n");
1785 return -1;
1786 }
1782 break; 1787 break;
1783 case SOF0: 1788 case SOF0:
1784 s->lossless=0; 1789 s->lossless=0;
1785 if (mjpeg_decode_sof(s) < 0) 1790 if (mjpeg_decode_sof(s) < 0)
1786 return -1; 1791 return -1;