Revision 1149acdc libavcodec/asv1.c

View differences:

libavcodec/asv1.c
158 158
    return reverse[ get_bits(gb, n) << (8-n) ];
159 159
}
160 160

  
161
static inline void asv2_put_bits(PutBitContext *pb, int n, int v){
162
    put_bits(pb, n, reverse[ v << (8-n) ]);
163
}
164

  
161 165
static inline int asv1_get_level(GetBitContext *gb){
162 166
    int code= get_vlc2(gb, level_vlc.table, VLC_BITS, 1);
163 167

  
......
182 186
    }
183 187
}
184 188

  
189
static inline void asv2_put_level(PutBitContext *pb, int level){
190
    unsigned int index= level + 31;
191

  
192
    if(index <= 62) put_bits(pb, asv2_level_tab[index][1], asv2_level_tab[index][0]);
193
    else{
194
        put_bits(pb, asv2_level_tab[31][1], asv2_level_tab[31][0]);
195
        asv2_put_bits(pb, 8, level&0xFF);
196
    }
197
}
198

  
185 199
static inline int asv1_decode_block(ASV1Context *a, DCTELEM block[64]){
186 200
    int i;
187 201

  
......
235 249
    return 0;
236 250
}
237 251

  
238
static inline void encode_block(ASV1Context *a, DCTELEM block[64]){
252
static inline void asv1_encode_block(ASV1Context *a, DCTELEM block[64]){
239 253
    int i;
240 254
    int nc_count=0;
241 255
    
......
268 282
    put_bits(&a->pb, ccp_tab[16][1], ccp_tab[16][0]);
269 283
}
270 284

  
285
static inline void asv2_encode_block(ASV1Context *a, DCTELEM block[64]){
286
    int i;
287
    int count=0;
288
    
289
    for(count=63; count>3; count--){
290
        const int index= scantab[count];
291

  
292
        if( (block[index]*a->q_intra_matrix[index] + (1<<15))>>16 ) 
293
            break;
294
    }
295
    
296
    count >>= 2;
297

  
298
    asv2_put_bits(&a->pb, 4, count);
299
    asv2_put_bits(&a->pb, 8, (block[0] + 32)>>6);
300
    block[0]= 0;
301
    
302
    for(i=0; i<=count; i++){
303
        const int index= scantab[4*i];
304
        int ccp=0;
305

  
306
        if( (block[index + 0] = (block[index + 0]*a->q_intra_matrix[index + 0] + (1<<15))>>16) ) ccp |= 8;
307
        if( (block[index + 8] = (block[index + 8]*a->q_intra_matrix[index + 8] + (1<<15))>>16) ) ccp |= 4;
308
        if( (block[index + 1] = (block[index + 1]*a->q_intra_matrix[index + 1] + (1<<15))>>16) ) ccp |= 2;
309
        if( (block[index + 9] = (block[index + 9]*a->q_intra_matrix[index + 9] + (1<<15))>>16) ) ccp |= 1;
310

  
311
        if(i) put_bits(&a->pb, ac_ccp_tab[ccp][1], ac_ccp_tab[ccp][0]);
312
        else  put_bits(&a->pb, dc_ccp_tab[ccp][1], dc_ccp_tab[ccp][0]);
313

  
314
        if(ccp){
315
            if(ccp&8) asv2_put_level(&a->pb, block[index + 0]);
316
            if(ccp&4) asv2_put_level(&a->pb, block[index + 8]);
317
            if(ccp&2) asv2_put_level(&a->pb, block[index + 1]);
318
            if(ccp&1) asv2_put_level(&a->pb, block[index + 9]);
319
        }
320
    }
321
}
322

  
271 323
static inline int decode_mb(ASV1Context *a, DCTELEM block[6][64]){
272 324
    int i;
273 325

  
......
290 342
static inline void encode_mb(ASV1Context *a, DCTELEM block[6][64]){
291 343
    int i;
292 344

  
293
    for(i=0; i<6; i++){
294
        encode_block(a, block[i]);
345
    if(a->avctx->codec_id == CODEC_ID_ASV1){
346
        for(i=0; i<6; i++)
347
            asv1_encode_block(a, block[i]);
348
    }else{
349
        for(i=0; i<6; i++)
350
            asv2_encode_block(a, block[i]);
295 351
    }
296 352
}
297 353

  
......
417 473
}
418 474
#endif
419 475

  
420
    p->quality= (32 + a->inv_qscale/2)/a->inv_qscale;
421
    memset(p->qscale_table, p->quality, p->qstride*a->mb_height);
422
    
423 476
    *picture= *(AVFrame*)&a->picture;
424 477
    *data_size = sizeof(AVPicture);
425 478

  
......
471 524
    
472 525
    size= get_bit_count(&a->pb)/32;
473 526
    
474
    a->dsp.bswap_buf((uint32_t*)buf, (uint32_t*)buf, size);
527
    if(avctx->codec_id == CODEC_ID_ASV1)
528
        a->dsp.bswap_buf((uint32_t*)buf, (uint32_t*)buf, size);
529
    else{
530
        int i;
531
        for(i=0; i<4*size; i++)
532
            buf[i]= reverse[ buf[i] ];
533
    }
475 534
    
476 535
    return size*4;
477 536
}
......
494 553
    ASV1Context * const a = avctx->priv_data;
495 554
    AVFrame *p= (AVFrame*)&a->picture;
496 555
    int i;
556
    const int scale= avctx->codec_id == CODEC_ID_ASV1 ? 1 : 2;
497 557
 
498 558
    common_init(avctx);
499 559
    init_vlcs(a);
......
511 571
    for(i=0; i<64; i++){
512 572
        int index= scantab[i];
513 573

  
514
        if(avctx->codec_id == CODEC_ID_ASV1)
515
            a->intra_matrix[i]= 64 *ff_mpeg1_default_intra_matrix[index] / a->inv_qscale;
516
        else
517
            a->intra_matrix[i]= 128*ff_mpeg1_default_intra_matrix[index] / a->inv_qscale;
574
        a->intra_matrix[i]= 64*scale*ff_mpeg1_default_intra_matrix[index] / a->inv_qscale;
518 575
    }
519 576

  
520 577
    p->qstride= a->mb_width;
521 578
    p->qscale_table= av_mallocz( p->qstride * a->mb_height);
579
    p->quality= (32*scale + a->inv_qscale/2)/a->inv_qscale;
580
    memset(p->qscale_table, p->quality, p->qstride*a->mb_height);
522 581

  
523 582
    return 0;
524 583
}
......
526 585
static int encode_init(AVCodecContext *avctx){
527 586
    ASV1Context * const a = avctx->priv_data;
528 587
    int i;
529
 
588
    const int scale= avctx->codec_id == CODEC_ID_ASV1 ? 1 : 2;
589

  
530 590
    common_init(avctx);
531 591
    
532 592
    if(avctx->global_quality == 0) avctx->global_quality= 4*FF_QUALITY_SCALE;
533 593

  
534
    a->inv_qscale= (32*FF_QUALITY_SCALE +  avctx->global_quality/2) / avctx->global_quality;
594
    a->inv_qscale= (32*scale*FF_QUALITY_SCALE +  avctx->global_quality/2) / avctx->global_quality;
535 595
    
536 596
    avctx->extradata= av_mallocz(8);
537 597
    avctx->extradata_size=8;
......
539 599
    ((uint32_t*)avctx->extradata)[1]= le2me_32(ff_get_fourcc("ASUS"));
540 600
    
541 601
    for(i=0; i<64; i++){
542
        int q= 32*ff_mpeg1_default_intra_matrix[i];
602
        int q= 32*scale*ff_mpeg1_default_intra_matrix[i];
543 603
        a->q_intra_matrix[i]= ((a->inv_qscale<<16) + q/2) / q;
544 604
    }
545 605

  
......
594 654
    //encode_end,
595 655
};
596 656

  
657
AVCodec asv2_encoder = {
658
    "asv2",
659
    CODEC_TYPE_VIDEO,
660
    CODEC_ID_ASV2,
661
    sizeof(ASV1Context),
662
    encode_init,
663
    encode_frame,
664
    //encode_end,
665
};
666

  
597 667
#endif //CONFIG_ENCODERS

Also available in: Unified diff