5 const INT16 ff_mpeg1_default_intra_matrix
[64] = {
6 8, 16, 19, 22, 26, 27, 29, 34,
7 16, 16, 22, 24, 27, 29, 34, 37,
8 19, 22, 26, 27, 29, 34, 34, 38,
9 22, 22, 26, 27, 29, 34, 37, 40,
10 22, 26, 27, 29, 32, 35, 40, 48,
11 26, 27, 29, 32, 35, 40, 48, 58,
12 26, 27, 29, 34, 38, 46, 56, 69,
13 27, 29, 35, 38, 46, 56, 69, 83
16 const INT16 ff_mpeg1_default_non_intra_matrix
[64] = {
17 16, 16, 16, 16, 16, 16, 16, 16,
18 16, 16, 16, 16, 16, 16, 16, 16,
19 16, 16, 16, 16, 16, 16, 16, 16,
20 16, 16, 16, 16, 16, 16, 16, 16,
21 16, 16, 16, 16, 16, 16, 16, 16,
22 16, 16, 16, 16, 16, 16, 16, 16,
23 16, 16, 16, 16, 16, 16, 16, 16,
24 16, 16, 16, 16, 16, 16, 16, 16,
27 const unsigned char vlc_dc_table
[256] = {
30 4, 4, 4, 4, 4, 4, 4, 4,
31 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
32 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
33 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
35 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
36 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
37 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
38 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
40 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
41 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
42 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
43 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
44 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
45 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
46 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
47 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
50 const UINT16 vlc_dc_lum_code
[12] = {
51 0x4, 0x0, 0x1, 0x5, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe, 0x1ff,
53 const unsigned char vlc_dc_lum_bits
[12] = {
54 3, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9, 9,
57 const UINT16 vlc_dc_chroma_code
[12] = {
58 0x0, 0x1, 0x2, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe, 0x3fe, 0x3ff,
60 const unsigned char vlc_dc_chroma_bits
[12] = {
61 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10,
64 /* simple include everything table for dc, first byte is bits number next 3 are code*/
65 static UINT32 mpeg1_lum_dc_uni
[512];
66 static UINT32 mpeg1_chr_dc_uni
[512];
68 static const UINT16 mpeg1_vlc
[113][2] = {
69 { 0x3, 2 }, { 0x4, 4 }, { 0x5, 5 }, { 0x6, 7 },
70 { 0x26, 8 }, { 0x21, 8 }, { 0xa, 10 }, { 0x1d, 12 },
71 { 0x18, 12 }, { 0x13, 12 }, { 0x10, 12 }, { 0x1a, 13 },
72 { 0x19, 13 }, { 0x18, 13 }, { 0x17, 13 }, { 0x1f, 14 },
73 { 0x1e, 14 }, { 0x1d, 14 }, { 0x1c, 14 }, { 0x1b, 14 },
74 { 0x1a, 14 }, { 0x19, 14 }, { 0x18, 14 }, { 0x17, 14 },
75 { 0x16, 14 }, { 0x15, 14 }, { 0x14, 14 }, { 0x13, 14 },
76 { 0x12, 14 }, { 0x11, 14 }, { 0x10, 14 }, { 0x18, 15 },
77 { 0x17, 15 }, { 0x16, 15 }, { 0x15, 15 }, { 0x14, 15 },
78 { 0x13, 15 }, { 0x12, 15 }, { 0x11, 15 }, { 0x10, 15 },
79 { 0x3, 3 }, { 0x6, 6 }, { 0x25, 8 }, { 0xc, 10 },
80 { 0x1b, 12 }, { 0x16, 13 }, { 0x15, 13 }, { 0x1f, 15 },
81 { 0x1e, 15 }, { 0x1d, 15 }, { 0x1c, 15 }, { 0x1b, 15 },
82 { 0x1a, 15 }, { 0x19, 15 }, { 0x13, 16 }, { 0x12, 16 },
83 { 0x11, 16 }, { 0x10, 16 }, { 0x5, 4 }, { 0x4, 7 },
84 { 0xb, 10 }, { 0x14, 12 }, { 0x14, 13 }, { 0x7, 5 },
85 { 0x24, 8 }, { 0x1c, 12 }, { 0x13, 13 }, { 0x6, 5 },
86 { 0xf, 10 }, { 0x12, 12 }, { 0x7, 6 }, { 0x9, 10 },
87 { 0x12, 13 }, { 0x5, 6 }, { 0x1e, 12 }, { 0x14, 16 },
88 { 0x4, 6 }, { 0x15, 12 }, { 0x7, 7 }, { 0x11, 12 },
89 { 0x5, 7 }, { 0x11, 13 }, { 0x27, 8 }, { 0x10, 13 },
90 { 0x23, 8 }, { 0x1a, 16 }, { 0x22, 8 }, { 0x19, 16 },
91 { 0x20, 8 }, { 0x18, 16 }, { 0xe, 10 }, { 0x17, 16 },
92 { 0xd, 10 }, { 0x16, 16 }, { 0x8, 10 }, { 0x15, 16 },
93 { 0x1f, 12 }, { 0x1a, 12 }, { 0x19, 12 }, { 0x17, 12 },
94 { 0x16, 12 }, { 0x1f, 13 }, { 0x1e, 13 }, { 0x1d, 13 },
95 { 0x1c, 13 }, { 0x1b, 13 }, { 0x1f, 16 }, { 0x1e, 16 },
96 { 0x1d, 16 }, { 0x1c, 16 }, { 0x1b, 16 },
97 { 0x1, 6 }, /* escape */
101 static const UINT16 mpeg2_vlc
[113][2] = {
102 {0x02, 2}, {0x06, 3}, {0x07, 4}, {0x1c, 5},
103 {0x1d, 5}, {0x05, 6}, {0x04, 6}, {0x7b, 7},
104 {0x7c, 7}, {0x23, 8}, {0x22, 8}, {0xfa, 8},
105 {0xfb, 8}, {0xfe, 8}, {0xff, 8}, {0x1f,14},
106 {0x1e,14}, {0x1d,14}, {0x1c,14}, {0x1b,14},
107 {0x1a,14}, {0x19,14}, {0x18,14}, {0x17,14},
108 {0x16,14}, {0x15,14}, {0x14,14}, {0x13,14},
109 {0x12,14}, {0x11,14}, {0x10,14}, {0x18,15},
110 {0x17,15}, {0x16,15}, {0x15,15}, {0x14,15},
111 {0x13,15}, {0x12,15}, {0x11,15}, {0x10,15},
112 {0x02, 3}, {0x06, 5}, {0x79, 7}, {0x27, 8},
113 {0x20, 8}, {0x16,13}, {0x15,13}, {0x1f,15},
114 {0x1e,15}, {0x1d,15}, {0x1c,15}, {0x1b,15},
115 {0x1a,15}, {0x19,15}, {0x13,16}, {0x12,16},
116 {0x11,16}, {0x10,16}, {0x05, 5}, {0x07, 7},
117 {0xfc, 8}, {0x0c,10}, {0x14,13}, {0x07, 5},
118 {0x26, 8}, {0x1c,12}, {0x13,13}, {0x06, 6},
119 {0xfd, 8}, {0x12,12}, {0x07, 6}, {0x04, 9},
120 {0x12,13}, {0x06, 7}, {0x1e,12}, {0x14,16},
121 {0x04, 7}, {0x15,12}, {0x05, 7}, {0x11,12},
122 {0x78, 7}, {0x11,13}, {0x7a, 7}, {0x10,13},
123 {0x21, 8}, {0x1a,16}, {0x25, 8}, {0x19,16},
124 {0x24, 8}, {0x18,16}, {0x05, 9}, {0x17,16},
125 {0x07, 9}, {0x16,16}, {0x0d,10}, {0x15,16},
126 {0x1f,12}, {0x1a,12}, {0x19,12}, {0x17,12},
127 {0x16,12}, {0x1f,13}, {0x1e,13}, {0x1d,13},
128 {0x1c,13}, {0x1b,13}, {0x1f,16}, {0x1e,16},
129 {0x1d,16}, {0x1c,16}, {0x1b,16},
130 {0x01,6}, /* escape */
134 static const INT8 mpeg1_level
[111] = {
135 1, 2, 3, 4, 5, 6, 7, 8,
136 9, 10, 11, 12, 13, 14, 15, 16,
137 17, 18, 19, 20, 21, 22, 23, 24,
138 25, 26, 27, 28, 29, 30, 31, 32,
139 33, 34, 35, 36, 37, 38, 39, 40,
140 1, 2, 3, 4, 5, 6, 7, 8,
141 9, 10, 11, 12, 13, 14, 15, 16,
142 17, 18, 1, 2, 3, 4, 5, 1,
143 2, 3, 4, 1, 2, 3, 1, 2,
144 3, 1, 2, 3, 1, 2, 1, 2,
145 1, 2, 1, 2, 1, 2, 1, 2,
146 1, 2, 1, 2, 1, 2, 1, 2,
147 1, 1, 1, 1, 1, 1, 1, 1,
151 static const INT8 mpeg1_run
[111] = {
152 0, 0, 0, 0, 0, 0, 0, 0,
153 0, 0, 0, 0, 0, 0, 0, 0,
154 0, 0, 0, 0, 0, 0, 0, 0,
155 0, 0, 0, 0, 0, 0, 0, 0,
156 0, 0, 0, 0, 0, 0, 0, 0,
157 1, 1, 1, 1, 1, 1, 1, 1,
158 1, 1, 1, 1, 1, 1, 1, 1,
159 1, 1, 2, 2, 2, 2, 2, 3,
160 3, 3, 3, 4, 4, 4, 5, 5,
161 5, 6, 6, 6, 7, 7, 8, 8,
162 9, 9, 10, 10, 11, 11, 12, 12,
163 13, 13, 14, 14, 15, 15, 16, 16,
164 17, 18, 19, 20, 21, 22, 23, 24,
165 25, 26, 27, 28, 29, 30, 31,
168 static UINT8 mpeg1_index_run
[2][64];
169 static INT8 mpeg1_max_level
[2][64];
171 static RLTable rl_mpeg1
= {
179 static RLTable rl_mpeg2
= {
187 static const UINT8 mbAddrIncrTable
[35][2] = {
221 {0x8, 11}, /* escape */
222 {0xf, 11}, /* stuffing */
225 static const UINT8 mbPatTable
[63][2] = {
291 #define MB_INTRA 0x01
295 #define MB_QUANT 0x10
297 static const UINT8 table_mb_ptype
[32][2] = {
299 { 3, 5 }, // 0x01 MB_INTRA
300 { 1, 2 }, // 0x02 MB_PAT
306 { 1, 3 }, // 0x08 MB_FOR
308 { 1, 1 }, // 0x0A MB_FOR|MB_PAT
315 { 1, 6 }, // 0x11 MB_QUANT|MB_INTRA
316 { 1, 5 }, // 0x12 MB_QUANT|MB_PAT
324 { 2, 5 }, // 0x1A MB_QUANT|MB_FOR|MB_PAT
332 static const UINT8 table_mb_btype
[32][2] = {
334 { 3, 5 }, // 0x01 MB_INTRA
337 { 2, 3 }, // 0x04 MB_BACK
339 { 3, 3 }, // 0x06 MB_BACK|MB_PAT
341 { 2, 4 }, // 0x08 MB_FOR
343 { 3, 4 }, // 0x0A MB_FOR|MB_PAT
345 { 2, 2 }, // 0x0C MB_FOR|MB_BACK
347 { 3, 2 }, // 0x0E MB_FOR|MB_BACK|MB_PAT
350 { 1, 6 }, // 0x11 MB_QUANT|MB_INTRA
355 { 2, 6 }, // 0x16 MB_QUANT|MB_BACK|MB_PAT
359 { 3, 6 }, // 0x1A MB_QUANT|MB_FOR|MB_PAT
363 { 2, 5 }, // 0x1E MB_QUANT|MB_FOR|MB_BACK|MB_PAT
367 static const UINT8 mbMotionVectorTable
[17][2] = {
387 static const int frame_rate_tab
[9] = {
389 (int)(23.976 * FRAME_RATE_BASE
),
390 (int)(24 * FRAME_RATE_BASE
),
391 (int)(25 * FRAME_RATE_BASE
),
392 (int)(29.97 * FRAME_RATE_BASE
),
393 (int)(30 * FRAME_RATE_BASE
),
394 (int)(50 * FRAME_RATE_BASE
),
395 (int)(59.94 * FRAME_RATE_BASE
),
396 (int)(60 * FRAME_RATE_BASE
),
399 static const UINT8 non_linear_qscale
[32] = {
400 0, 1, 2, 3, 4, 5, 6, 7,
401 8,10,12,14,16,18,20,22,
402 24,28,32,36,40,44,48,52,
403 56,64,72,80,88,96,104,112,
406 UINT8 ff_mpeg1_dc_scale_table
[128]={ // MN: mpeg2 really can have such large qscales?
407 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
408 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
409 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
410 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
411 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
414 static const float mpeg1_aspect
[16]={
435 static const float mpeg2_aspect
[16]={