comparison mjpeg.c @ 5003:ddb28de352bb libavcodec

split jpeg_ls into jpeglsdec, jpeglsenc and jpegls
author aurel
date Sun, 13 May 2007 23:16:56 +0000
parents 3fa689636240
children 5c3c39298e91
comparison
equal deleted inserted replaced
5002:09cb686ffc0b 5003:ddb28de352bb
35 35
36 #include "avcodec.h" 36 #include "avcodec.h"
37 #include "dsputil.h" 37 #include "dsputil.h"
38 #include "mpegvideo.h" 38 #include "mpegvideo.h"
39 #include "bytestream.h" 39 #include "bytestream.h"
40 #include "mjpeg.h"
41 #include "jpeglsdec.h"
40 42
41 /* use two quantizer tables (one for luminance and one for chrominance) */ 43 /* use two quantizer tables (one for luminance and one for chrominance) */
42 /* not yet working */ 44 /* not yet working */
43 #undef TWOMATRIXES 45 #undef TWOMATRIXES
44 46
51 uint8_t huff_size_ac_luminance[256]; 53 uint8_t huff_size_ac_luminance[256];
52 uint16_t huff_code_ac_luminance[256]; 54 uint16_t huff_code_ac_luminance[256];
53 uint8_t huff_size_ac_chrominance[256]; 55 uint8_t huff_size_ac_chrominance[256];
54 uint16_t huff_code_ac_chrominance[256]; 56 uint16_t huff_code_ac_chrominance[256];
55 } MJpegContext; 57 } MJpegContext;
56
57 /* JPEG marker codes */
58 typedef enum {
59 /* start of frame */
60 SOF0 = 0xc0, /* baseline */
61 SOF1 = 0xc1, /* extended sequential, huffman */
62 SOF2 = 0xc2, /* progressive, huffman */
63 SOF3 = 0xc3, /* lossless, huffman */
64
65 SOF5 = 0xc5, /* differential sequential, huffman */
66 SOF6 = 0xc6, /* differential progressive, huffman */
67 SOF7 = 0xc7, /* differential lossless, huffman */
68 JPG = 0xc8, /* reserved for JPEG extension */
69 SOF9 = 0xc9, /* extended sequential, arithmetic */
70 SOF10 = 0xca, /* progressive, arithmetic */
71 SOF11 = 0xcb, /* lossless, arithmetic */
72
73 SOF13 = 0xcd, /* differential sequential, arithmetic */
74 SOF14 = 0xce, /* differential progressive, arithmetic */
75 SOF15 = 0xcf, /* differential lossless, arithmetic */
76
77 DHT = 0xc4, /* define huffman tables */
78
79 DAC = 0xcc, /* define arithmetic-coding conditioning */
80
81 /* restart with modulo 8 count "m" */
82 RST0 = 0xd0,
83 RST1 = 0xd1,
84 RST2 = 0xd2,
85 RST3 = 0xd3,
86 RST4 = 0xd4,
87 RST5 = 0xd5,
88 RST6 = 0xd6,
89 RST7 = 0xd7,
90
91 SOI = 0xd8, /* start of image */
92 EOI = 0xd9, /* end of image */
93 SOS = 0xda, /* start of scan */
94 DQT = 0xdb, /* define quantization tables */
95 DNL = 0xdc, /* define number of lines */
96 DRI = 0xdd, /* define restart interval */
97 DHP = 0xde, /* define hierarchical progression */
98 EXP = 0xdf, /* expand reference components */
99
100 APP0 = 0xe0,
101 APP1 = 0xe1,
102 APP2 = 0xe2,
103 APP3 = 0xe3,
104 APP4 = 0xe4,
105 APP5 = 0xe5,
106 APP6 = 0xe6,
107 APP7 = 0xe7,
108 APP8 = 0xe8,
109 APP9 = 0xe9,
110 APP10 = 0xea,
111 APP11 = 0xeb,
112 APP12 = 0xec,
113 APP13 = 0xed,
114 APP14 = 0xee,
115 APP15 = 0xef,
116
117 JPG0 = 0xf0,
118 JPG1 = 0xf1,
119 JPG2 = 0xf2,
120 JPG3 = 0xf3,
121 JPG4 = 0xf4,
122 JPG5 = 0xf5,
123 JPG6 = 0xf6,
124 SOF48 = 0xf7, ///< JPEG-LS
125 LSE = 0xf8, ///< JPEG-LS extension parameters
126 JPG9 = 0xf9,
127 JPG10 = 0xfa,
128 JPG11 = 0xfb,
129 JPG12 = 0xfc,
130 JPG13 = 0xfd,
131
132 COM = 0xfe, /* comment */
133
134 TEM = 0x01, /* temporary private use for arithmetic coding */
135
136 /* 0x02 -> 0xbf reserved */
137 } JPEG_MARKER;
138 58
139 #if 0 59 #if 0
140 /* These are the sample quantization tables given in JPEG spec section K.1. 60 /* These are the sample quantization tables given in JPEG spec section K.1.
141 * The spec says that the values given produce "good" quality, and 61 * The spec says that the values given produce "good" quality, and
142 * when divided by 2, "very good" quality. 62 * when divided by 2, "very good" quality.
299 default:\ 219 default:\
300 case 7: ret= (left + top)>>1; break;\ 220 case 7: ret= (left + top)>>1; break;\
301 } 221 }
302 222
303 #ifdef CONFIG_ENCODERS 223 #ifdef CONFIG_ENCODERS
304 static inline void put_marker(PutBitContext *p, int code)
305 {
306 put_bits(p, 8, 0xff);
307 put_bits(p, 8, code);
308 }
309
310 /* table_class: 0 = DC coef, 1 = AC coefs */ 224 /* table_class: 0 = DC coef, 1 = AC coefs */
311 static int put_huffman_table(MpegEncContext *s, int table_class, int table_id, 225 static int put_huffman_table(MpegEncContext *s, int table_class, int table_id,
312 const uint8_t *bits_table, const uint8_t *value_table) 226 const uint8_t *bits_table, const uint8_t *value_table)
313 { 227 {
314 PutBitContext *p = &s->pb; 228 PutBitContext *p = &s->pb;
831 745
832 #endif //CONFIG_ENCODERS 746 #endif //CONFIG_ENCODERS
833 747
834 /******************************************/ 748 /******************************************/
835 /* decoding */ 749 /* decoding */
836
837 #define MAX_COMPONENTS 4
838
839 typedef struct MJpegDecodeContext {
840 AVCodecContext *avctx;
841 GetBitContext gb;
842
843 int start_code; /* current start code */
844 int buffer_size;
845 uint8_t *buffer;
846
847 int16_t quant_matrixes[4][64];
848 VLC vlcs[2][4];
849 int qscale[4]; ///< quantizer scale calculated from quant_matrixes
850
851 int org_height; /* size given at codec init */
852 int first_picture; /* true if decoding first picture */
853 int interlaced; /* true if interlaced */
854 int bottom_field; /* true if bottom field */
855 int lossless;
856 int ls;
857 int progressive;
858 int rgb;
859 int rct; /* standard rct */
860 int pegasus_rct; /* pegasus reversible colorspace transform */
861 int bits; /* bits per component */
862
863 int maxval;
864 int near; ///< near lossless bound (si 0 for lossless)
865 int t1,t2,t3;
866 int reset; ///< context halfing intervall ?rename
867
868 int width, height;
869 int mb_width, mb_height;
870 int nb_components;
871 int component_id[MAX_COMPONENTS];
872 int h_count[MAX_COMPONENTS]; /* horizontal and vertical count for each component */
873 int v_count[MAX_COMPONENTS];
874 int comp_index[MAX_COMPONENTS];
875 int dc_index[MAX_COMPONENTS];
876 int ac_index[MAX_COMPONENTS];
877 int nb_blocks[MAX_COMPONENTS];
878 int h_scount[MAX_COMPONENTS];
879 int v_scount[MAX_COMPONENTS];
880 int h_max, v_max; /* maximum h and v counts */
881 int quant_index[4]; /* quant table index for each component */
882 int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */
883 AVFrame picture; /* picture structure */
884 int linesize[MAX_COMPONENTS]; ///< linesize << interlaced
885 int8_t *qscale_table;
886 DECLARE_ALIGNED_8(DCTELEM, block[64]);
887 ScanTable scantable;
888 DSPContext dsp;
889
890 int restart_interval;
891 int restart_count;
892
893 int buggy_avid;
894 int cs_itu601;
895 int interlace_polarity;
896
897 int mjpb_skiptosod;
898
899 int cur_scan; /* current scan, used by JPEG-LS */
900 } MJpegDecodeContext;
901
902 #include "jpeg_ls.c" //FIXME make jpeg-ls more independent
903 750
904 static int mjpeg_decode_dht(MJpegDecodeContext *s); 751 static int mjpeg_decode_dht(MJpegDecodeContext *s);
905 752
906 static int build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table, 753 static int build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table,
907 int nb_codes, int use_static, int is_ac) 754 int nb_codes, int use_static, int is_ac)
1662 if(s->lossless){ 1509 if(s->lossless){
1663 if(s->ls){ 1510 if(s->ls){
1664 // for(){ 1511 // for(){
1665 // reset_ls_coding_parameters(s, 0); 1512 // reset_ls_coding_parameters(s, 0);
1666 1513
1667 ls_decode_picture(s, predictor, point_transform, ilv); 1514 ff_jpegls_decode_picture(s, predictor, point_transform, ilv);
1668 }else{ 1515 }else{
1669 if(s->rgb){ 1516 if(s->rgb){
1670 if(ljpeg_decode_rgb_scan(s, predictor, point_transform) < 0) 1517 if(ljpeg_decode_rgb_scan(s, predictor, point_transform) < 0)
1671 return -1; 1518 return -1;
1672 }else{ 1519 }else{
2093 s->progressive=0; 1940 s->progressive=0;
2094 if (mjpeg_decode_sof(s) < 0) 1941 if (mjpeg_decode_sof(s) < 0)
2095 return -1; 1942 return -1;
2096 break; 1943 break;
2097 case LSE: 1944 case LSE:
2098 if (decode_lse(s) < 0) 1945 if (ff_jpegls_decode_lse(s) < 0)
2099 return -1; 1946 return -1;
2100 break; 1947 break;
2101 case EOI: 1948 case EOI:
2102 s->cur_scan = 0; 1949 s->cur_scan = 0;
2103 if ((s->buggy_avid && !s->interlaced) || s->restart_interval) 1950 if ((s->buggy_avid && !s->interlaced) || s->restart_interval)