Mercurial > libavcodec.hg
changeset 5468:74949d4ea79c libavcodec
dnxhd 185 interlaced support
author | bcoudurier |
---|---|
date | Sat, 04 Aug 2007 13:17:53 +0000 |
parents | 740cf5d1691e |
children | 0418cc1c3899 |
files | dnxhddata.h dnxhddec.c |
diffstat | 2 files changed, 51 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/dnxhddata.h Sat Aug 04 13:10:16 2007 +0000 +++ b/dnxhddata.h Sat Aug 04 13:17:53 2007 +0000 @@ -46,28 +46,26 @@ 82, 77, 80, 86, 84, 82, 82, 82, }; -/* FIXME permute */ static const uint8_t dnxhd_1243_luma_weigth[] = { - 0,32,35,35,38,40,44,45, - 32,33,35,35,39,42,44,45, - 33,35,34,37,41,42,45,45, - 35,35,37,40,41,44,45,48, - 35,37,38,40,43,45,47,48, - 36,36,38,40,45,47,48,47, - 35,36,38,41,45,46,47,48, - 36,37,39,41,44,45,47,47, + 0, 32, 32, 33, 33, 35, 35, 35, + 35, 35, 35, 35, 34, 35, 38, 40, + 39, 37, 37, 37, 36, 35, 36, 38, + 40, 41, 42, 44, 45, 44, 42, 41, + 40, 38, 36, 36, 37, 38, 40, 43, + 44, 45, 45, 45, 45, 45, 45, 41, + 39, 41, 45, 47, 47, 48, 48, 48, + 46, 44, 45, 47, 47, 48, 47, 47, }; -/* FIXME permute */ static const uint8_t dnxhd_1243_chroma_weigth[] = { - 0,32,37,39,41,42,45,45, - 36,36,39,41,43,45,46,45, - 37,41,41,43,45,44,45,46, - 43,42,43,46,44,45,46,48, - 43,44,47,45,44,46,47,49, - 44,46,44,45,45,47,48,47, - 44,42,46,44,45,46,47,48, - 41,43,45,44,45,46,47,47, + 0, 32, 36, 37, 36, 37, 39, 39, + 41, 43, 43, 42, 41, 41, 41, 42, + 43, 43, 43, 44, 44, 44, 46, 47, + 46, 45, 45, 45, 45, 46, 44, 44, + 45, 44, 42, 41, 43, 46, 45, 44, + 45, 45, 45, 46, 46, 46, 45, 44, + 45, 44, 45, 47, 47, 48, 49, 48, + 46, 45, 46, 47, 47, 48, 47, 47, }; static const uint8_t dnxhd_1238_dc_codes[12] = {
--- a/dnxhddec.c Sat Aug 04 13:10:16 2007 +0000 +++ b/dnxhddec.c Sat Aug 04 13:17:53 2007 +0000 @@ -69,12 +69,12 @@ dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_level, dnxhd_1238_ac_run_flag, dnxhd_1238_ac_index_flag, dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1238_run }, -/* { 1243, 1920, 1080, 1, 917504, 458752, 4, 8, */ -/* dnxhd_1243_luma_weigth, dnxhd_1243_chroma_weigth, */ -/* dnxhd_1238_dc_codes, dnxhd_1238_dc_bits, */ -/* dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_level, */ -/* dnxhd_1238_ac_run_flag, dnxhd_1238_ac_index_flag, */ -/* dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1238_run }, */ + { 1243, 1920, 1080, 1, 917504, 458752, 4, 8, + dnxhd_1243_luma_weigth, dnxhd_1243_chroma_weigth, + dnxhd_1238_dc_codes, dnxhd_1238_dc_bits, + dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_level, + dnxhd_1238_ac_run_flag, dnxhd_1238_ac_index_flag, + dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1238_run }, }; static int dnxhd_get_cid_table(int cid) @@ -125,7 +125,7 @@ return 0; } -static int dnxhd_decode_header(DNXHDContext *ctx, uint8_t *buf, int buf_size) +static int dnxhd_decode_header(DNXHDContext *ctx, uint8_t *buf, int buf_size, int first_field) { static const uint8_t header_prefix[] = { 0x00, 0x00, 0x02, 0x80, 0x01 }; int i; @@ -137,9 +137,11 @@ av_log(ctx->avctx, AV_LOG_ERROR, "error in header\n"); return -1; } - if (buf[5] & 2) {/* interlaced FIXME top or bottom */ + if (buf[5] & 2) { /* interlaced */ + ctx->cur_field = buf[5] & 1; ctx->picture.interlaced_frame = 1; - av_log(ctx->avctx, AV_LOG_DEBUG, "interlaced %d\n", buf[5] & 3); + ctx->picture.top_field_first = first_field && ctx->cur_field == 1; + av_log(ctx->avctx, AV_LOG_DEBUG, "interlaced %d, cur field %d\n", buf[5] & 3, ctx->cur_field); } ctx->height = AV_RB16(buf + 0x18); @@ -265,10 +267,22 @@ for (i = 0; i < 8; i++) { dnxhd_decode_dct_block(ctx, ctx->blocks[i], i, qscale); } + + if (ctx->picture.interlaced_frame) { + dct_linesize_luma <<= 1; + dct_linesize_chroma <<= 1; + } + dest_y = ctx->picture.data[0] + ((y * dct_linesize_luma) << 4) + (x << 4); dest_u = ctx->picture.data[1] + ((y * dct_linesize_chroma) << 4) + (x << 3); dest_v = ctx->picture.data[2] + ((y * dct_linesize_chroma) << 4) + (x << 3); + if (ctx->cur_field) { + dest_y += ctx->picture.linesize[0]; + dest_u += ctx->picture.linesize[1]; + dest_v += ctx->picture.linesize[2]; + } + dct_offset = dct_linesize_luma << 3; ctx->dsp.idct_put(dest_y, dct_linesize_luma, ctx->blocks[0]); ctx->dsp.idct_put(dest_y + 8, dct_linesize_luma, ctx->blocks[1]); @@ -308,10 +322,12 @@ { DNXHDContext *ctx = avctx->priv_data; AVFrame *picture = data; + int first_field = 1; dprintf(avctx, "frame size %d\n", buf_size); - if (dnxhd_decode_header(ctx, buf, buf_size) < 0) + decode_coding_unit: + if (dnxhd_decode_header(ctx, buf, buf_size, first_field) < 0) return -1; avctx->pix_fmt = PIX_FMT_YUV422P; @@ -319,15 +335,24 @@ return -1; avcodec_set_dimensions(avctx, ctx->width, ctx->height); + if (first_field) { if (ctx->picture.data[0]) avctx->release_buffer(avctx, &ctx->picture); if (avctx->get_buffer(avctx, &ctx->picture) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; } + } dnxhd_decode_macroblocks(ctx, buf + 0x280, buf_size - 0x280); + if (first_field && ctx->picture.interlaced_frame) { + buf += ctx->cid_table->coding_unit_size; + buf_size -= ctx->cid_table->coding_unit_size; + first_field = 0; + goto decode_coding_unit; + } + *picture = ctx->picture; *data_size = sizeof(AVPicture); return buf_size;