Revision 94ed2a30 libavcodec/dv.c

View differences:

libavcodec/dv.c
58 58
    void (*get_pixels)(DCTELEM *block, const uint8_t *pixels, int line_size);
59 59
    void (*fdct[2])(DCTELEM *block);
60 60
    void (*idct_put[2])(uint8_t *dest, int line_size, DCTELEM *block);
61
    me_cmp_func ildct_cmp;
61 62
} DVVideoContext;
62 63

  
63 64
#define TEX_VLC_BITS 9
......
368 369

  
369 370
    /* Generic DSP setup */
370 371
    dsputil_init(&dsp, avctx);
372
    ff_set_cmp(&dsp, dsp.ildct_cmp, avctx->ildct_cmp);
371 373
    s->get_pixels = dsp.get_pixels;
374
    s->ildct_cmp = dsp.ildct_cmp[5];
372 375

  
373 376
    /* 88DCT setup */
374 377
    s->fdct[0]     = dsp.fdct;
......
805 808
    return pb;
806 809
}
807 810

  
808
//FIXME replace this by dsputil
809
#define SC(x, y) ((s[x] - s[y]) ^ ((s[x] - s[y]) >> 7))
810
static av_always_inline int dv_guess_dct_mode(DCTELEM *blk) {
811
    DCTELEM *s;
812
    int score88  = 0;
813
    int score248 = 0;
814
    int i;
815

  
816
    /* Compute 8-8 score (small values give a better chance for 8-8 DCT) */
817
    s = blk;
818
    for (i = 0; i < 7; i++) {
819
        score88 += SC(0,  8) + SC(1, 9) + SC(2, 10) + SC(3, 11) +
820
                   SC(4, 12) + SC(5,13) + SC(6, 14) + SC(7, 15);
821
        s += 8;
822
    }
823
    /* Compute 2-4-8 score (small values give a better chance for 2-4-8 DCT) */
824
    s = blk;
825
    for (i = 0; i < 6; i++) {
826
        score248 += SC(0, 16) + SC(1,17) + SC(2, 18) + SC(3, 19) +
827
                    SC(4, 20) + SC(5,21) + SC(6, 22) + SC(7, 23);
828
        s += 8;
829
    }
830

  
831
    return (score88 - score248 > -10);
811
static av_always_inline int dv_guess_dct_mode(DVVideoContext *s, uint8_t *data, int linesize) {
812
    if (s->avctx->flags & CODEC_FLAG_INTERLACED_DCT) {
813
        int ps = s->ildct_cmp(NULL, data, NULL, linesize, 8) - 400;
814
        if (ps > 0) {
815
            int is = s->ildct_cmp(NULL, data           , NULL, linesize<<1, 4) +
816
                     s->ildct_cmp(NULL, data + linesize, NULL, linesize<<1, 4);
817
            return (ps > is);
818
        }
819
    } else
820
        return 0;
832 821
}
833 822

  
834 823
static av_always_inline int dv_init_enc_block(EncBlockInfo* bi, uint8_t *data, int linesize, DVVideoContext *s, int bias)
......
862 851
    bi->partial_bit_buffer = 0;
863 852
    bi->cur_ac = 0;
864 853
    if (data) {
854
        bi->dct_mode = dv_guess_dct_mode(s, data, linesize);
865 855
        s->get_pixels(blk, data, linesize);
866
        bi->dct_mode = (s->avctx->flags & CODEC_FLAG_INTERLACED_DCT) &&
867
                       dv_guess_dct_mode(blk);
868 856
        s->fdct[bi->dct_mode](blk);
869 857
    } else {
870 858
        /* We rely on the fact that encoding all zeros leads to an immediate EOB,

Also available in: Unified diff