1 /*
2 * RV30 decoder
3 * Copyright (c) 2007 Konstantin Shishkov
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * RV30 decoder
25 */
26
30
33
34
36 {
37 int mb_bits;
39 int mb_size;
40 int rpr;
41
44 return -1;
48 return -1;
55 "Extradata does not contain selected resolution\n");
56 rpr = 0;
57 }
58 if(rpr){
61 }
64 mb_size = ((w + 15) >> 4) * ((h + 15) >> 4);
68 return 0;
69 }
70
71 /**
72 * Decode 4x4 intra types array.
73 */
75 {
76 int i, j, k;
77
79 for(j = 0; j < 4; j+= 2){
83 return -1;
84 }
85 for(k = 0; k < 2; k++){
89 if(dst[-1] == 9){
91 return -1;
92 }
93 }
94 }
95 }
96 return 0;
97 }
98
99 /**
100 * Decode macroblock information.
101 */
103 {
109
110 if (code > 11) {
112 return -1;
113 }
114 if(code > 5){
116 code -= 6;
117 }
119 return rv30_p_types[code];
120 else
121 return rv30_b_types[code];
122 }
123
125 const int stride,
const int lim)
126 {
129
130 for(i = 0; i < 4; i++){
131 diff = ((src[-2*step] - src[1*step]) - (src[-1*step] - src[0*step])*4) >> 3;
132 diff = av_clip(diff, -lim, lim);
133 src[-1*step] = cm[src[-1*step] +
diff];
134 src[ 0*step] = cm[src[ 0*step] -
diff];
136 }
137 }
138
140 {
142 int mb_pos, mb_x;
143 int i, j, k;
145 int loc_lim, cur_lim, left_lim = 0, top_lim = 0;
146
148 for(mb_x = 0; mb_x < s->
mb_width; mb_x++, mb_pos++){
154 }
155
156 /* all vertical edges are filtered first
157 * and horizontal edges are filtered on the next iteration
158 */
160 for(mb_x = 0; mb_x < s->
mb_width; mb_x++, mb_pos++){
162 if(mb_x)
164 for(j = 0; j < 16; j += 4){
166 for(i = !mb_x; i < 4; i++, Y += 4){
167 int ij = i + j;
168 loc_lim = 0;
170 loc_lim = cur_lim;
171 else if(!i && r->
deblock_coefs[mb_pos - 1] & (1 << (ij + 3)))
172 loc_lim = left_lim;
174 loc_lim = cur_lim;
175 if(loc_lim)
177 }
178 }
179 for(k = 0; k < 2; k++){
180 int cur_cbp, left_cbp = 0;
181 cur_cbp = (r->
cbp_chroma[mb_pos] >> (k*4)) & 0xF;
182 if(mb_x)
183 left_cbp = (r->
cbp_chroma[mb_pos - 1] >> (k*4)) & 0xF;
184 for(j = 0; j < 8; j += 4){
186 for(i = !mb_x; i < 2; i++, C += 4){
187 int ij = i + (j >> 1);
188 loc_lim = 0;
189 if (cur_cbp & (1 << ij))
190 loc_lim = cur_lim;
191 else if(!i && left_cbp & (1 << (ij + 1)))
192 loc_lim = left_lim;
193 else if( i && cur_cbp & (1 << (ij - 1)))
194 loc_lim = cur_lim;
195 if(loc_lim)
197 }
198 }
199 }
200 }
202 for(mb_x = 0; mb_x < s->
mb_width; mb_x++, mb_pos++){
204 if(row)
206 for(j = 4*!row; j < 16; j += 4){
208 for(i = 0; i < 4; i++, Y += 4){
209 int ij = i + j;
210 loc_lim = 0;
212 loc_lim = cur_lim;
214 loc_lim = top_lim;
216 loc_lim = cur_lim;
217 if(loc_lim)
219 }
220 }
221 for(k = 0; k < 2; k++){
222 int cur_cbp, top_cbp = 0;
223 cur_cbp = (r->
cbp_chroma[mb_pos] >> (k*4)) & 0xF;
224 if(row)
226 for(j = 4*!row; j < 8; j += 4){
228 for(i = 0; i < 2; i++, C += 4){
229 int ij = i + (j >> 1);
230 loc_lim = 0;
232 loc_lim = cur_lim;
233 else if(!j && top_cbp & (1 << (ij + 2)))
234 loc_lim = top_lim;
235 else if( j && cur_cbp & (1 << (ij - 2)))
236 loc_lim = cur_lim;
237 if(loc_lim)
239 }
240 }
241 }
242 }
243 }
244
245 /**
246 * Initialize decoder.
247 */
249 {
252
255 if (ret < 0)
259 return -1;
260 }
264 av_log(avctx,
AV_LOG_ERROR,
"Insufficient extradata - need at least %d bytes, got %d\n",
266 }
273 return 0;
274 }
275
291 };