Revision 6b259e43

View differences:

libavcodec/dnxhddata.h
46 46
    82, 77, 80, 86, 84, 82, 82, 82,
47 47
};
48 48

  
49
/* FIXME permute */
50 49
static const uint8_t dnxhd_1243_luma_weigth[] = {
51
     0,32,35,35,38,40,44,45,
52
    32,33,35,35,39,42,44,45,
53
    33,35,34,37,41,42,45,45,
54
    35,35,37,40,41,44,45,48,
55
    35,37,38,40,43,45,47,48,
56
    36,36,38,40,45,47,48,47,
57
    35,36,38,41,45,46,47,48,
58
    36,37,39,41,44,45,47,47,
50
     0, 32, 32, 33, 33, 35, 35, 35,
51
    35, 35, 35, 35, 34, 35, 38, 40,
52
    39, 37, 37, 37, 36, 35, 36, 38,
53
    40, 41, 42, 44, 45, 44, 42, 41,
54
    40, 38, 36, 36, 37, 38, 40, 43,
55
    44, 45, 45, 45, 45, 45, 45, 41,
56
    39, 41, 45, 47, 47, 48, 48, 48,
57
    46, 44, 45, 47, 47, 48, 47, 47,
59 58
};
60 59

  
61
/* FIXME permute */
62 60
static const uint8_t dnxhd_1243_chroma_weigth[] = {
63
     0,32,37,39,41,42,45,45,
64
    36,36,39,41,43,45,46,45,
65
    37,41,41,43,45,44,45,46,
66
    43,42,43,46,44,45,46,48,
67
    43,44,47,45,44,46,47,49,
68
    44,46,44,45,45,47,48,47,
69
    44,42,46,44,45,46,47,48,
70
    41,43,45,44,45,46,47,47,
61
     0, 32, 36, 37, 36, 37, 39, 39,
62
    41, 43, 43, 42, 41, 41, 41, 42,
63
    43, 43, 43, 44, 44, 44, 46, 47,
64
    46, 45, 45, 45, 45, 46, 44, 44,
65
    45, 44, 42, 41, 43, 46, 45, 44,
66
    45, 45, 45, 46, 46, 46, 45, 44,
67
    45, 44, 45, 47, 47, 48, 49, 48,
68
    46, 45, 46, 47, 47, 48, 47, 47,
71 69
};
72 70

  
73 71
static const uint8_t dnxhd_1238_dc_codes[12] = {
libavcodec/dnxhddec.c
69 69
      dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_level,
70 70
      dnxhd_1238_ac_run_flag, dnxhd_1238_ac_index_flag,
71 71
      dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1238_run },
72
/*     { 1243, 1920, 1080, 1, 917504, 458752, 4, 8, */
73
/*       dnxhd_1243_luma_weigth, dnxhd_1243_chroma_weigth, */
74
/*       dnxhd_1238_dc_codes, dnxhd_1238_dc_bits, */
75
/*       dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_level, */
76
/*       dnxhd_1238_ac_run_flag, dnxhd_1238_ac_index_flag, */
77
/*       dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1238_run }, */
72
    { 1243, 1920, 1080, 1, 917504, 458752, 4, 8,
73
      dnxhd_1243_luma_weigth, dnxhd_1243_chroma_weigth,
74
      dnxhd_1238_dc_codes, dnxhd_1238_dc_bits,
75
      dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_level,
76
      dnxhd_1238_ac_run_flag, dnxhd_1238_ac_index_flag,
77
      dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1238_run },
78 78
};
79 79

  
80 80
static int dnxhd_get_cid_table(int cid)
......
125 125
    return 0;
126 126
}
127 127

  
128
static int dnxhd_decode_header(DNXHDContext *ctx, uint8_t *buf, int buf_size)
128
static int dnxhd_decode_header(DNXHDContext *ctx, uint8_t *buf, int buf_size, int first_field)
129 129
{
130 130
    static const uint8_t header_prefix[] = { 0x00, 0x00, 0x02, 0x80, 0x01 };
131 131
    int i;
......
137 137
        av_log(ctx->avctx, AV_LOG_ERROR, "error in header\n");
138 138
        return -1;
139 139
    }
140
    if (buf[5] & 2) {/* interlaced FIXME top or bottom */
140
    if (buf[5] & 2) { /* interlaced */
141
        ctx->cur_field = buf[5] & 1;
141 142
        ctx->picture.interlaced_frame = 1;
142
        av_log(ctx->avctx, AV_LOG_DEBUG, "interlaced %d\n", buf[5] & 3);
143
        ctx->picture.top_field_first = first_field && ctx->cur_field == 1;
144
        av_log(ctx->avctx, AV_LOG_DEBUG, "interlaced %d, cur field %d\n", buf[5] & 3, ctx->cur_field);
143 145
    }
144 146

  
145 147
    ctx->height = AV_RB16(buf + 0x18);
......
265 267
    for (i = 0; i < 8; i++) {
266 268
        dnxhd_decode_dct_block(ctx, ctx->blocks[i], i, qscale);
267 269
    }
270

  
271
    if (ctx->picture.interlaced_frame) {
272
        dct_linesize_luma   <<= 1;
273
        dct_linesize_chroma <<= 1;
274
    }
275

  
268 276
    dest_y = ctx->picture.data[0] + ((y * dct_linesize_luma)   << 4) + (x << 4);
269 277
    dest_u = ctx->picture.data[1] + ((y * dct_linesize_chroma) << 4) + (x << 3);
270 278
    dest_v = ctx->picture.data[2] + ((y * dct_linesize_chroma) << 4) + (x << 3);
271 279

  
280
    if (ctx->cur_field) {
281
        dest_y += ctx->picture.linesize[0];
282
        dest_u += ctx->picture.linesize[1];
283
        dest_v += ctx->picture.linesize[2];
284
    }
285

  
272 286
    dct_offset = dct_linesize_luma << 3;
273 287
    ctx->dsp.idct_put(dest_y,                  dct_linesize_luma, ctx->blocks[0]);
274 288
    ctx->dsp.idct_put(dest_y + 8,              dct_linesize_luma, ctx->blocks[1]);
......
308 322
{
309 323
    DNXHDContext *ctx = avctx->priv_data;
310 324
    AVFrame *picture = data;
325
    int first_field = 1;
311 326

  
312 327
    dprintf(avctx, "frame size %d\n", buf_size);
313 328

  
314
    if (dnxhd_decode_header(ctx, buf, buf_size) < 0)
329
 decode_coding_unit:
330
    if (dnxhd_decode_header(ctx, buf, buf_size, first_field) < 0)
315 331
        return -1;
316 332

  
317 333
    avctx->pix_fmt = PIX_FMT_YUV422P;
......
319 335
        return -1;
320 336
    avcodec_set_dimensions(avctx, ctx->width, ctx->height);
321 337

  
338
    if (first_field) {
322 339
    if (ctx->picture.data[0])
323 340
        avctx->release_buffer(avctx, &ctx->picture);
324 341
    if (avctx->get_buffer(avctx, &ctx->picture) < 0) {
325 342
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
326 343
        return -1;
327 344
    }
345
    }
328 346

  
329 347
    dnxhd_decode_macroblocks(ctx, buf + 0x280, buf_size - 0x280);
330 348

  
349
    if (first_field && ctx->picture.interlaced_frame) {
350
        buf      += ctx->cid_table->coding_unit_size;
351
        buf_size -= ctx->cid_table->coding_unit_size;
352
        first_field = 0;
353
        goto decode_coding_unit;
354
    }
355

  
331 356
    *picture = ctx->picture;
332 357
    *data_size = sizeof(AVPicture);
333 358
    return buf_size;

Also available in: Unified diff