comparison asv1.c @ 2967:ef2149182f1c libavcodec

COSMETICS: Remove all trailing whitespace.
author diego
date Sat, 17 Dec 2005 18:14:38 +0000
parents 659b92488061
children 0b546eab515d
comparison
equal deleted inserted replaced
2966:564788471dd4 2967:ef2149182f1c
14 * 14 *
15 * You should have received a copy of the GNU Lesser General Public 15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software 16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 18 */
19 19
20 /** 20 /**
21 * @file asv1.c 21 * @file asv1.c
22 * ASUS V1/V2 codec. 22 * ASUS V1/V2 codec.
23 */ 23 */
24 24
25 #include "avcodec.h" 25 #include "avcodec.h"
26 #include "dsputil.h" 26 #include "dsputil.h"
27 #include "mpegvideo.h" 27 #include "mpegvideo.h"
28 28
29 //#undef NDEBUG 29 //#undef NDEBUG
30 //#include <assert.h> 30 //#include <assert.h>
31 31
32 #define VLC_BITS 6 32 #define VLC_BITS 6
33 #define ASV2_LEVEL_VLC_BITS 10 33 #define ASV2_LEVEL_VLC_BITS 10
34 34
35 typedef struct ASV1Context{ 35 typedef struct ASV1Context{
36 AVCodecContext *avctx; 36 AVCodecContext *avctx;
37 DSPContext dsp; 37 DSPContext dsp;
38 AVFrame picture; 38 AVFrame picture;
39 PutBitContext pb; 39 PutBitContext pb;
64 64
65 65
66 static const uint8_t ccp_tab[17][2]={ 66 static const uint8_t ccp_tab[17][2]={
67 {0x2,2}, {0x7,5}, {0xB,5}, {0x3,5}, 67 {0x2,2}, {0x7,5}, {0xB,5}, {0x3,5},
68 {0xD,5}, {0x5,5}, {0x9,5}, {0x1,5}, 68 {0xD,5}, {0x5,5}, {0x9,5}, {0x1,5},
69 {0xE,5}, {0x6,5}, {0xA,5}, {0x2,5}, 69 {0xE,5}, {0x6,5}, {0xA,5}, {0x2,5},
70 {0xC,5}, {0x4,5}, {0x8,5}, {0x3,2}, 70 {0xC,5}, {0x4,5}, {0x8,5}, {0x3,2},
71 {0xF,5}, //EOB 71 {0xF,5}, //EOB
72 }; 72 };
73 73
74 static const uint8_t level_tab[7][2]={ 74 static const uint8_t level_tab[7][2]={
114 static int done = 0; 114 static int done = 0;
115 115
116 if (!done) { 116 if (!done) {
117 done = 1; 117 done = 1;
118 118
119 init_vlc(&ccp_vlc, VLC_BITS, 17, 119 init_vlc(&ccp_vlc, VLC_BITS, 17,
120 &ccp_tab[0][1], 2, 1, 120 &ccp_tab[0][1], 2, 1,
121 &ccp_tab[0][0], 2, 1, 1); 121 &ccp_tab[0][0], 2, 1, 1);
122 init_vlc(&dc_ccp_vlc, VLC_BITS, 8, 122 init_vlc(&dc_ccp_vlc, VLC_BITS, 8,
123 &dc_ccp_tab[0][1], 2, 1, 123 &dc_ccp_tab[0][1], 2, 1,
124 &dc_ccp_tab[0][0], 2, 1, 1); 124 &dc_ccp_tab[0][0], 2, 1, 1);
125 init_vlc(&ac_ccp_vlc, VLC_BITS, 16, 125 init_vlc(&ac_ccp_vlc, VLC_BITS, 16,
126 &ac_ccp_tab[0][1], 2, 1, 126 &ac_ccp_tab[0][1], 2, 1,
127 &ac_ccp_tab[0][0], 2, 1, 1); 127 &ac_ccp_tab[0][0], 2, 1, 1);
128 init_vlc(&level_vlc, VLC_BITS, 7, 128 init_vlc(&level_vlc, VLC_BITS, 7,
129 &level_tab[0][1], 2, 1, 129 &level_tab[0][1], 2, 1,
130 &level_tab[0][0], 2, 1, 1); 130 &level_tab[0][0], 2, 1, 1);
131 init_vlc(&asv2_level_vlc, ASV2_LEVEL_VLC_BITS, 63, 131 init_vlc(&asv2_level_vlc, ASV2_LEVEL_VLC_BITS, 63,
132 &asv2_level_tab[0][1], 2, 1, 132 &asv2_level_tab[0][1], 2, 1,
133 &asv2_level_tab[0][0], 2, 1, 1); 133 &asv2_level_tab[0][0], 2, 1, 1);
134 } 134 }
135 } 135 }
136 136
179 179
180 static inline int asv1_decode_block(ASV1Context *a, DCTELEM block[64]){ 180 static inline int asv1_decode_block(ASV1Context *a, DCTELEM block[64]){
181 int i; 181 int i;
182 182
183 block[0]= 8*get_bits(&a->gb, 8); 183 block[0]= 8*get_bits(&a->gb, 8);
184 184
185 for(i=0; i<11; i++){ 185 for(i=0; i<11; i++){
186 const int ccp= get_vlc2(&a->gb, ccp_vlc.table, VLC_BITS, 1); 186 const int ccp= get_vlc2(&a->gb, ccp_vlc.table, VLC_BITS, 1);
187 187
188 if(ccp){ 188 if(ccp){
189 if(ccp == 16) break; 189 if(ccp == 16) break;
204 204
205 static inline int asv2_decode_block(ASV1Context *a, DCTELEM block[64]){ 205 static inline int asv2_decode_block(ASV1Context *a, DCTELEM block[64]){
206 int i, count, ccp; 206 int i, count, ccp;
207 207
208 count= asv2_get_bits(&a->gb, 4); 208 count= asv2_get_bits(&a->gb, 4);
209 209
210 block[0]= 8*asv2_get_bits(&a->gb, 8); 210 block[0]= 8*asv2_get_bits(&a->gb, 8);
211 211
212 ccp= get_vlc2(&a->gb, dc_ccp_vlc.table, VLC_BITS, 1); 212 ccp= get_vlc2(&a->gb, dc_ccp_vlc.table, VLC_BITS, 1);
213 if(ccp){ 213 if(ccp){
214 if(ccp&4) block[a->scantable.permutated[1]]= (asv2_get_level(&a->gb) * a->intra_matrix[1])>>4; 214 if(ccp&4) block[a->scantable.permutated[1]]= (asv2_get_level(&a->gb) * a->intra_matrix[1])>>4;
215 if(ccp&2) block[a->scantable.permutated[2]]= (asv2_get_level(&a->gb) * a->intra_matrix[2])>>4; 215 if(ccp&2) block[a->scantable.permutated[2]]= (asv2_get_level(&a->gb) * a->intra_matrix[2])>>4;
216 if(ccp&1) block[a->scantable.permutated[3]]= (asv2_get_level(&a->gb) * a->intra_matrix[3])>>4; 216 if(ccp&1) block[a->scantable.permutated[3]]= (asv2_get_level(&a->gb) * a->intra_matrix[3])>>4;
224 if(ccp&4) block[a->scantable.permutated[4*i+1]]= (asv2_get_level(&a->gb) * a->intra_matrix[4*i+1])>>4; 224 if(ccp&4) block[a->scantable.permutated[4*i+1]]= (asv2_get_level(&a->gb) * a->intra_matrix[4*i+1])>>4;
225 if(ccp&2) block[a->scantable.permutated[4*i+2]]= (asv2_get_level(&a->gb) * a->intra_matrix[4*i+2])>>4; 225 if(ccp&2) block[a->scantable.permutated[4*i+2]]= (asv2_get_level(&a->gb) * a->intra_matrix[4*i+2])>>4;
226 if(ccp&1) block[a->scantable.permutated[4*i+3]]= (asv2_get_level(&a->gb) * a->intra_matrix[4*i+3])>>4; 226 if(ccp&1) block[a->scantable.permutated[4*i+3]]= (asv2_get_level(&a->gb) * a->intra_matrix[4*i+3])>>4;
227 } 227 }
228 } 228 }
229 229
230 return 0; 230 return 0;
231 } 231 }
232 232
233 static inline void asv1_encode_block(ASV1Context *a, DCTELEM block[64]){ 233 static inline void asv1_encode_block(ASV1Context *a, DCTELEM block[64]){
234 int i; 234 int i;
235 int nc_count=0; 235 int nc_count=0;
236 236
237 put_bits(&a->pb, 8, (block[0] + 32)>>6); 237 put_bits(&a->pb, 8, (block[0] + 32)>>6);
238 block[0]= 0; 238 block[0]= 0;
239 239
240 for(i=0; i<10; i++){ 240 for(i=0; i<10; i++){
241 const int index= scantab[4*i]; 241 const int index= scantab[4*i];
242 int ccp=0; 242 int ccp=0;
243 243
244 if( (block[index + 0] = (block[index + 0]*a->q_intra_matrix[index + 0] + (1<<15))>>16) ) ccp |= 8; 244 if( (block[index + 0] = (block[index + 0]*a->q_intra_matrix[index + 0] + (1<<15))>>16) ) ccp |= 8;
245 if( (block[index + 8] = (block[index + 8]*a->q_intra_matrix[index + 8] + (1<<15))>>16) ) ccp |= 4; 245 if( (block[index + 8] = (block[index + 8]*a->q_intra_matrix[index + 8] + (1<<15))>>16) ) ccp |= 4;
246 if( (block[index + 1] = (block[index + 1]*a->q_intra_matrix[index + 1] + (1<<15))>>16) ) ccp |= 2; 246 if( (block[index + 1] = (block[index + 1]*a->q_intra_matrix[index + 1] + (1<<15))>>16) ) ccp |= 2;
247 if( (block[index + 9] = (block[index + 9]*a->q_intra_matrix[index + 9] + (1<<15))>>16) ) ccp |= 1; 247 if( (block[index + 9] = (block[index + 9]*a->q_intra_matrix[index + 9] + (1<<15))>>16) ) ccp |= 1;
248 248
249 if(ccp){ 249 if(ccp){
250 for(;nc_count; nc_count--) 250 for(;nc_count; nc_count--)
251 put_bits(&a->pb, ccp_tab[0][1], ccp_tab[0][0]); 251 put_bits(&a->pb, ccp_tab[0][1], ccp_tab[0][0]);
252 252
253 put_bits(&a->pb, ccp_tab[ccp][1], ccp_tab[ccp][0]); 253 put_bits(&a->pb, ccp_tab[ccp][1], ccp_tab[ccp][0]);
254 254
255 if(ccp&8) asv1_put_level(&a->pb, block[index + 0]); 255 if(ccp&8) asv1_put_level(&a->pb, block[index + 0]);
256 if(ccp&4) asv1_put_level(&a->pb, block[index + 8]); 256 if(ccp&4) asv1_put_level(&a->pb, block[index + 8]);
257 if(ccp&2) asv1_put_level(&a->pb, block[index + 1]); 257 if(ccp&2) asv1_put_level(&a->pb, block[index + 1]);
258 if(ccp&1) asv1_put_level(&a->pb, block[index + 9]); 258 if(ccp&1) asv1_put_level(&a->pb, block[index + 9]);
259 }else{ 259 }else{
264 } 264 }
265 265
266 static inline void asv2_encode_block(ASV1Context *a, DCTELEM block[64]){ 266 static inline void asv2_encode_block(ASV1Context *a, DCTELEM block[64]){
267 int i; 267 int i;
268 int count=0; 268 int count=0;
269 269
270 for(count=63; count>3; count--){ 270 for(count=63; count>3; count--){
271 const int index= scantab[count]; 271 const int index= scantab[count];
272 272
273 if( (block[index]*a->q_intra_matrix[index] + (1<<15))>>16 ) 273 if( (block[index]*a->q_intra_matrix[index] + (1<<15))>>16 )
274 break; 274 break;
275 } 275 }
276 276
277 count >>= 2; 277 count >>= 2;
278 278
279 asv2_put_bits(&a->pb, 4, count); 279 asv2_put_bits(&a->pb, 4, count);
280 asv2_put_bits(&a->pb, 8, (block[0] + 32)>>6); 280 asv2_put_bits(&a->pb, 8, (block[0] + 32)>>6);
281 block[0]= 0; 281 block[0]= 0;
282 282
283 for(i=0; i<=count; i++){ 283 for(i=0; i<=count; i++){
284 const int index= scantab[4*i]; 284 const int index= scantab[4*i];
285 int ccp=0; 285 int ccp=0;
286 286
287 if( (block[index + 0] = (block[index + 0]*a->q_intra_matrix[index + 0] + (1<<15))>>16) ) ccp |= 8; 287 if( (block[index + 0] = (block[index + 0]*a->q_intra_matrix[index + 0] + (1<<15))>>16) ) ccp |= 8;
303 303
304 static inline int decode_mb(ASV1Context *a, DCTELEM block[6][64]){ 304 static inline int decode_mb(ASV1Context *a, DCTELEM block[6][64]){
305 int i; 305 int i;
306 306
307 a->dsp.clear_blocks(block[0]); 307 a->dsp.clear_blocks(block[0]);
308 308
309 if(a->avctx->codec_id == CODEC_ID_ASV1){ 309 if(a->avctx->codec_id == CODEC_ID_ASV1){
310 for(i=0; i<6; i++){ 310 for(i=0; i<6; i++){
311 if( asv1_decode_block(a, block[i]) < 0) 311 if( asv1_decode_block(a, block[i]) < 0)
312 return -1; 312 return -1;
313 } 313 }
314 }else{ 314 }else{
315 for(i=0; i<6; i++){ 315 for(i=0; i<6; i++){
316 if( asv2_decode_block(a, block[i]) < 0) 316 if( asv2_decode_block(a, block[i]) < 0)
317 return -1; 317 return -1;
318 } 318 }
319 } 319 }
320 return 0; 320 return 0;
321 } 321 }
322 322
323 static inline int encode_mb(ASV1Context *a, DCTELEM block[6][64]){ 323 static inline int encode_mb(ASV1Context *a, DCTELEM block[6][64]){
324 int i; 324 int i;
325 325
326 if(a->pb.buf_end - a->pb.buf - (put_bits_count(&a->pb)>>3) < 30*16*16*3/2/8){ 326 if(a->pb.buf_end - a->pb.buf - (put_bits_count(&a->pb)>>3) < 30*16*16*3/2/8){
327 av_log(a->avctx, AV_LOG_ERROR, "encoded frame too large\n"); 327 av_log(a->avctx, AV_LOG_ERROR, "encoded frame too large\n");
328 return -1; 328 return -1;
329 } 329 }
330 330
339 } 339 }
340 340
341 static inline void idct_put(ASV1Context *a, int mb_x, int mb_y){ 341 static inline void idct_put(ASV1Context *a, int mb_x, int mb_y){
342 DCTELEM (*block)[64]= a->block; 342 DCTELEM (*block)[64]= a->block;
343 int linesize= a->picture.linesize[0]; 343 int linesize= a->picture.linesize[0];
344 344
345 uint8_t *dest_y = a->picture.data[0] + (mb_y * 16* linesize ) + mb_x * 16; 345 uint8_t *dest_y = a->picture.data[0] + (mb_y * 16* linesize ) + mb_x * 16;
346 uint8_t *dest_cb = a->picture.data[1] + (mb_y * 8 * a->picture.linesize[1]) + mb_x * 8; 346 uint8_t *dest_cb = a->picture.data[1] + (mb_y * 8 * a->picture.linesize[1]) + mb_x * 8;
347 uint8_t *dest_cr = a->picture.data[2] + (mb_y * 8 * a->picture.linesize[2]) + mb_x * 8; 347 uint8_t *dest_cr = a->picture.data[2] + (mb_y * 8 * a->picture.linesize[2]) + mb_x * 8;
348 348
349 a->dsp.idct_put(dest_y , linesize, block[0]); 349 a->dsp.idct_put(dest_y , linesize, block[0]);
359 359
360 static inline void dct_get(ASV1Context *a, int mb_x, int mb_y){ 360 static inline void dct_get(ASV1Context *a, int mb_x, int mb_y){
361 DCTELEM (*block)[64]= a->block; 361 DCTELEM (*block)[64]= a->block;
362 int linesize= a->picture.linesize[0]; 362 int linesize= a->picture.linesize[0];
363 int i; 363 int i;
364 364
365 uint8_t *ptr_y = a->picture.data[0] + (mb_y * 16* linesize ) + mb_x * 16; 365 uint8_t *ptr_y = a->picture.data[0] + (mb_y * 16* linesize ) + mb_x * 16;
366 uint8_t *ptr_cb = a->picture.data[1] + (mb_y * 8 * a->picture.linesize[1]) + mb_x * 8; 366 uint8_t *ptr_cb = a->picture.data[1] + (mb_y * 8 * a->picture.linesize[1]) + mb_x * 8;
367 uint8_t *ptr_cr = a->picture.data[2] + (mb_y * 8 * a->picture.linesize[2]) + mb_x * 8; 367 uint8_t *ptr_cr = a->picture.data[2] + (mb_y * 8 * a->picture.linesize[2]) + mb_x * 8;
368 368
369 a->dsp.get_pixels(block[0], ptr_y , linesize); 369 a->dsp.get_pixels(block[0], ptr_y , linesize);
370 a->dsp.get_pixels(block[1], ptr_y + 8, linesize); 370 a->dsp.get_pixels(block[1], ptr_y + 8, linesize);
371 a->dsp.get_pixels(block[2], ptr_y + 8*linesize , linesize); 371 a->dsp.get_pixels(block[2], ptr_y + 8*linesize , linesize);
372 a->dsp.get_pixels(block[3], ptr_y + 8*linesize + 8, linesize); 372 a->dsp.get_pixels(block[3], ptr_y + 8*linesize + 8, linesize);
373 for(i=0; i<4; i++) 373 for(i=0; i<4; i++)
374 a->dsp.fdct(block[i]); 374 a->dsp.fdct(block[i]);
375 375
376 if(!(a->avctx->flags&CODEC_FLAG_GRAY)){ 376 if(!(a->avctx->flags&CODEC_FLAG_GRAY)){
377 a->dsp.get_pixels(block[4], ptr_cb, a->picture.linesize[1]); 377 a->dsp.get_pixels(block[4], ptr_cb, a->picture.linesize[1]);
378 a->dsp.get_pixels(block[5], ptr_cr, a->picture.linesize[2]); 378 a->dsp.get_pixels(block[5], ptr_cr, a->picture.linesize[2]);
379 for(i=4; i<6; i++) 379 for(i=4; i<6; i++)
380 a->dsp.fdct(block[i]); 380 a->dsp.fdct(block[i]);
381 } 381 }
382 } 382 }
383 383
384 static int decode_frame(AVCodecContext *avctx, 384 static int decode_frame(AVCodecContext *avctx,
385 void *data, int *data_size, 385 void *data, int *data_size,
386 uint8_t *buf, int buf_size) 386 uint8_t *buf, int buf_size)
387 { 387 {
388 ASV1Context * const a = avctx->priv_data; 388 ASV1Context * const a = avctx->priv_data;
389 AVFrame *picture = data; 389 AVFrame *picture = data;
400 } 400 }
401 p->pict_type= I_TYPE; 401 p->pict_type= I_TYPE;
402 p->key_frame= 1; 402 p->key_frame= 1;
403 403
404 a->bitstream_buffer= av_fast_realloc(a->bitstream_buffer, &a->bitstream_buffer_size, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); 404 a->bitstream_buffer= av_fast_realloc(a->bitstream_buffer, &a->bitstream_buffer_size, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
405 405
406 if(avctx->codec_id == CODEC_ID_ASV1) 406 if(avctx->codec_id == CODEC_ID_ASV1)
407 a->dsp.bswap_buf((uint32_t*)a->bitstream_buffer, (uint32_t*)buf, buf_size/4); 407 a->dsp.bswap_buf((uint32_t*)a->bitstream_buffer, (uint32_t*)buf, buf_size/4);
408 else{ 408 else{
409 int i; 409 int i;
410 for(i=0; i<buf_size; i++) 410 for(i=0; i<buf_size; i++)
415 415
416 for(mb_y=0; mb_y<a->mb_height2; mb_y++){ 416 for(mb_y=0; mb_y<a->mb_height2; mb_y++){
417 for(mb_x=0; mb_x<a->mb_width2; mb_x++){ 417 for(mb_x=0; mb_x<a->mb_width2; mb_x++){
418 if( decode_mb(a, a->block) <0) 418 if( decode_mb(a, a->block) <0)
419 return -1; 419 return -1;
420 420
421 idct_put(a, mb_x, mb_y); 421 idct_put(a, mb_x, mb_y);
422 } 422 }
423 } 423 }
424 424
425 if(a->mb_width2 != a->mb_width){ 425 if(a->mb_width2 != a->mb_width){
426 mb_x= a->mb_width2; 426 mb_x= a->mb_width2;
427 for(mb_y=0; mb_y<a->mb_height2; mb_y++){ 427 for(mb_y=0; mb_y<a->mb_height2; mb_y++){
428 if( decode_mb(a, a->block) <0) 428 if( decode_mb(a, a->block) <0)
429 return -1; 429 return -1;
430 430
431 idct_put(a, mb_x, mb_y); 431 idct_put(a, mb_x, mb_y);
432 } 432 }
433 } 433 }
434 434
435 if(a->mb_height2 != a->mb_height){ 435 if(a->mb_height2 != a->mb_height){
436 mb_y= a->mb_height2; 436 mb_y= a->mb_height2;
437 for(mb_x=0; mb_x<a->mb_width; mb_x++){ 437 for(mb_x=0; mb_x<a->mb_width; mb_x++){
438 if( decode_mb(a, a->block) <0) 438 if( decode_mb(a, a->block) <0)
439 return -1; 439 return -1;
440 440
441 idct_put(a, mb_x, mb_y); 441 idct_put(a, mb_x, mb_y);
442 } 442 }
443 } 443 }
444 #if 0 444 #if 0
445 int i; 445 int i;
446 printf("%d %d\n", 8*buf_size, get_bits_count(&a->gb)); 446 printf("%d %d\n", 8*buf_size, get_bits_count(&a->gb));
447 for(i=get_bits_count(&a->gb); i<8*buf_size; i++){ 447 for(i=get_bits_count(&a->gb); i<8*buf_size; i++){
448 printf("%d", get_bits1(&a->gb)); 448 printf("%d", get_bits1(&a->gb));
449 } 449 }
455 455
456 *picture= *(AVFrame*)&a->picture; 456 *picture= *(AVFrame*)&a->picture;
457 *data_size = sizeof(AVPicture); 457 *data_size = sizeof(AVPicture);
458 458
459 emms_c(); 459 emms_c();
460 460
461 return (get_bits_count(&a->gb)+31)/32*4; 461 return (get_bits_count(&a->gb)+31)/32*4;
462 } 462 }
463 463
464 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ 464 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
465 ASV1Context * const a = avctx->priv_data; 465 ASV1Context * const a = avctx->priv_data;
467 AVFrame * const p= (AVFrame*)&a->picture; 467 AVFrame * const p= (AVFrame*)&a->picture;
468 int size; 468 int size;
469 int mb_x, mb_y; 469 int mb_x, mb_y;
470 470
471 init_put_bits(&a->pb, buf, buf_size); 471 init_put_bits(&a->pb, buf, buf_size);
472 472
473 *p = *pict; 473 *p = *pict;
474 p->pict_type= I_TYPE; 474 p->pict_type= I_TYPE;
475 p->key_frame= 1; 475 p->key_frame= 1;
476 476
477 for(mb_y=0; mb_y<a->mb_height2; mb_y++){ 477 for(mb_y=0; mb_y<a->mb_height2; mb_y++){
495 dct_get(a, mb_x, mb_y); 495 dct_get(a, mb_x, mb_y);
496 encode_mb(a, a->block); 496 encode_mb(a, a->block);
497 } 497 }
498 } 498 }
499 emms_c(); 499 emms_c();
500 500
501 align_put_bits(&a->pb); 501 align_put_bits(&a->pb);
502 while(put_bits_count(&a->pb)&31) 502 while(put_bits_count(&a->pb)&31)
503 put_bits(&a->pb, 8, 0); 503 put_bits(&a->pb, 8, 0);
504 504
505 size= put_bits_count(&a->pb)/32; 505 size= put_bits_count(&a->pb)/32;
506 506
507 if(avctx->codec_id == CODEC_ID_ASV1) 507 if(avctx->codec_id == CODEC_ID_ASV1)
508 a->dsp.bswap_buf((uint32_t*)buf, (uint32_t*)buf, size); 508 a->dsp.bswap_buf((uint32_t*)buf, (uint32_t*)buf, size);
509 else{ 509 else{
510 int i; 510 int i;
511 for(i=0; i<4*size; i++) 511 for(i=0; i<4*size; i++)
512 buf[i]= ff_reverse[ buf[i] ]; 512 buf[i]= ff_reverse[ buf[i] ];
513 } 513 }
514 514
515 return size*4; 515 return size*4;
516 } 516 }
517 517
518 static void common_init(AVCodecContext *avctx){ 518 static void common_init(AVCodecContext *avctx){
519 ASV1Context * const a = avctx->priv_data; 519 ASV1Context * const a = avctx->priv_data;
532 static int decode_init(AVCodecContext *avctx){ 532 static int decode_init(AVCodecContext *avctx){
533 ASV1Context * const a = avctx->priv_data; 533 ASV1Context * const a = avctx->priv_data;
534 AVFrame *p= (AVFrame*)&a->picture; 534 AVFrame *p= (AVFrame*)&a->picture;
535 int i; 535 int i;
536 const int scale= avctx->codec_id == CODEC_ID_ASV1 ? 1 : 2; 536 const int scale= avctx->codec_id == CODEC_ID_ASV1 ? 1 : 2;
537 537
538 common_init(avctx); 538 common_init(avctx);
539 init_vlcs(a); 539 init_vlcs(a);
540 ff_init_scantable(a->dsp.idct_permutation, &a->scantable, scantab); 540 ff_init_scantable(a->dsp.idct_permutation, &a->scantable, scantab);
541 avctx->pix_fmt= PIX_FMT_YUV420P; 541 avctx->pix_fmt= PIX_FMT_YUV420P;
542 542
567 ASV1Context * const a = avctx->priv_data; 567 ASV1Context * const a = avctx->priv_data;
568 int i; 568 int i;
569 const int scale= avctx->codec_id == CODEC_ID_ASV1 ? 1 : 2; 569 const int scale= avctx->codec_id == CODEC_ID_ASV1 ? 1 : 2;
570 570
571 common_init(avctx); 571 common_init(avctx);
572 572
573 if(avctx->global_quality == 0) avctx->global_quality= 4*FF_QUALITY_SCALE; 573 if(avctx->global_quality == 0) avctx->global_quality= 4*FF_QUALITY_SCALE;
574 574
575 a->inv_qscale= (32*scale*FF_QUALITY_SCALE + avctx->global_quality/2) / avctx->global_quality; 575 a->inv_qscale= (32*scale*FF_QUALITY_SCALE + avctx->global_quality/2) / avctx->global_quality;
576 576
577 avctx->extradata= av_mallocz(8); 577 avctx->extradata= av_mallocz(8);
578 avctx->extradata_size=8; 578 avctx->extradata_size=8;
579 ((uint32_t*)avctx->extradata)[0]= le2me_32(a->inv_qscale); 579 ((uint32_t*)avctx->extradata)[0]= le2me_32(a->inv_qscale);
580 ((uint32_t*)avctx->extradata)[1]= le2me_32(ff_get_fourcc("ASUS")); 580 ((uint32_t*)avctx->extradata)[1]= le2me_32(ff_get_fourcc("ASUS"));
581 581
582 for(i=0; i<64; i++){ 582 for(i=0; i<64; i++){
583 int q= 32*scale*ff_mpeg1_default_intra_matrix[i]; 583 int q= 32*scale*ff_mpeg1_default_intra_matrix[i];
584 a->q_intra_matrix[i]= ((a->inv_qscale<<16) + q/2) / q; 584 a->q_intra_matrix[i]= ((a->inv_qscale<<16) + q/2) / q;
585 } 585 }
586 586
591 ASV1Context * const a = avctx->priv_data; 591 ASV1Context * const a = avctx->priv_data;
592 592
593 av_freep(&a->bitstream_buffer); 593 av_freep(&a->bitstream_buffer);
594 av_freep(&a->picture.qscale_table); 594 av_freep(&a->picture.qscale_table);
595 a->bitstream_buffer_size=0; 595 a->bitstream_buffer_size=0;
596 596
597 return 0; 597 return 0;
598 } 598 }
599 599
600 AVCodec asv1_decoder = { 600 AVCodec asv1_decoder = {
601 "asv1", 601 "asv1",