~ubuntu-branches/ubuntu/lucid/ffmpeg/lucid-security

« back to all changes in this revision

Viewing changes to libavcodec/dv.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2009-03-13 09:18:28 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090313091828-n4ktby5eca487uhv
Tags: 3:0.svn20090303-1ubuntu1+unstripped1
merge from ubuntu.jaunty branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
91
92
static inline void dv_calc_mb_coordinates(const DVprofile *d, int chan, int seq, int slot,
92
93
                                          uint16_t *tbl)
93
94
{
94
 
    const static uint8_t off[] = { 2, 6, 8, 0, 4 };
95
 
    const static uint8_t shuf1[] = { 36, 18, 54, 0, 72 };
96
 
    const static uint8_t shuf2[] = { 24, 12, 36, 0, 48 };
97
 
    const static uint8_t shuf3[] = { 18, 9, 27, 0, 36 };
98
 
 
99
 
    const static uint8_t l_start[] = {0, 4, 9, 13, 18, 22, 27, 31, 36, 40};
100
 
    const static uint8_t l_start_shuffled[] = { 9, 4, 13, 0, 18 };
101
 
 
102
 
    const static uint8_t serpent1[] = {0, 1, 2, 2, 1, 0,
 
95
    static const uint8_t off[] = { 2, 6, 8, 0, 4 };
 
96
    static const uint8_t shuf1[] = { 36, 18, 54, 0, 72 };
 
97
    static const uint8_t shuf2[] = { 24, 12, 36, 0, 48 };
 
98
    static const uint8_t shuf3[] = { 18, 9, 27, 0, 36 };
 
99
 
 
100
    static const uint8_t l_start[] = {0, 4, 9, 13, 18, 22, 27, 31, 36, 40};
 
101
    static const uint8_t l_start_shuffled[] = { 9, 4, 13, 0, 18 };
 
102
 
 
103
    static const uint8_t serpent1[] = {0, 1, 2, 2, 1, 0,
103
104
                                       0, 1, 2, 2, 1, 0,
104
105
                                       0, 1, 2, 2, 1, 0,
105
106
                                       0, 1, 2, 2, 1, 0,
106
107
                                       0, 1, 2};
107
 
    const static uint8_t serpent2[] = {0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0,
 
108
    static const uint8_t serpent2[] = {0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0,
108
109
                                       0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0,
109
110
                                       0, 1, 2, 3, 4, 5};
110
111
 
111
 
    const static uint8_t remap[][2] = {{ 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, /* dummy */
 
112
    static const uint8_t remap[][2] = {{ 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, /* dummy */
112
113
                                       { 0, 0}, { 0, 1}, { 0, 2}, { 0, 3}, {10, 0},
113
114
                                       {10, 1}, {10, 2}, {10, 3}, {20, 0}, {20, 1},
114
115
                                       {20, 2}, {20, 3}, {30, 0}, {30, 1}, {30, 2},
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
    }
 
820
 
 
821
    return 0;
832
822
}
833
823
 
834
824
static av_always_inline int dv_init_enc_block(EncBlockInfo* bi, uint8_t *data, int linesize, DVVideoContext *s, int bias)
862
852
    bi->partial_bit_buffer = 0;
863
853
    bi->cur_ac = 0;
864
854
    if (data) {
 
855
        bi->dct_mode = dv_guess_dct_mode(s, data, linesize);
865
856
        s->get_pixels(blk, data, linesize);
866
 
        bi->dct_mode = (s->avctx->flags & CODEC_FLAG_INTERLACED_DCT) &&
867
 
                       dv_guess_dct_mode(blk);
868
857
        s->fdct[bi->dct_mode](blk);
869
858
    } else {
870
859
        /* We rely on the fact that encoding all zeros leads to an immediate EOB,
1183
1172
     *      compression scheme (if any).
1184
1173
     */
1185
1174
    int apt   = (c->sys->pix_fmt == PIX_FMT_YUV420P ? 0 : 1);
1186
 
    int stype = (c->sys->pix_fmt == PIX_FMT_YUV422P ? 4 : 0);
1187
1175
 
1188
1176
    uint8_t aspect = 0;
1189
1177
    if ((int)(av_q2d(c->avctx->sample_aspect_ratio) * c->avctx->width / c->avctx->height * 10) >= 17) /* 16:9 */
1213
1201
                   0xf;       /* reserved -- always 1 */
1214
1202
          buf[3] = (3 << 6) | /* reserved -- always 1 */
1215
1203
                   (c->sys->dsf << 5) | /*  system: 60fields/50fields */
1216
 
                   stype;               /* signal type video compression */
 
1204
                   c->sys->video_stype; /* signal type video compression */
1217
1205
          buf[4] = 0xff;      /* VISC: 0xff -- no information */
1218
1206
          break;
1219
1207
    case dv_video_control: