From 75cf80ee8e4f1c60f3bdf41dd63d4e311fc52fea Mon Sep 17 00:00:00 2001 From: Dmitry Kovalev Date: Thu, 30 May 2013 14:50:41 -0700 Subject: [PATCH] Adding new encode_txfm function. Moving some code from vp9_pack_bitstream to encode_txfm function. Change-Id: Icc25d6083e54f09886216fea632ceac002042d7f --- vp9/encoder/vp9_bitstream.c | 86 +++++++++++++++++++++++-------------------- vp9/encoder/vp9_encodeframe.c | 1 + 2 files changed, 47 insertions(+), 40 deletions(-) diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c index 94e0b25..95e9a7d 100644 --- a/vp9/encoder/vp9_bitstream.c +++ b/vp9/encoder/vp9_bitstream.c @@ -1356,6 +1356,49 @@ static void encode_segmentation(VP9_COMP *cpi, vp9_writer *w) { } } + +static void encode_txfm(VP9_COMP *cpi, vp9_writer *w) { + VP9_COMMON *const cm = &cpi->common; + + // Mode + vp9_write_literal(w, MIN(cm->txfm_mode, ALLOW_32X32), 2); + if (cm->txfm_mode >= ALLOW_32X32) + vp9_write_bit(w, cm->txfm_mode == TX_MODE_SELECT); + + // Probabilities + if (cm->txfm_mode == TX_MODE_SELECT) { + cm->prob_tx[0] = get_prob(cpi->txfm_count_32x32p[TX_4X4] + + cpi->txfm_count_16x16p[TX_4X4] + + cpi->txfm_count_8x8p[TX_4X4], + cpi->txfm_count_32x32p[TX_4X4] + + cpi->txfm_count_32x32p[TX_8X8] + + cpi->txfm_count_32x32p[TX_16X16] + + cpi->txfm_count_32x32p[TX_32X32] + + cpi->txfm_count_16x16p[TX_4X4] + + cpi->txfm_count_16x16p[TX_8X8] + + cpi->txfm_count_16x16p[TX_16X16] + + cpi->txfm_count_8x8p[TX_4X4] + + cpi->txfm_count_8x8p[TX_8X8]); + cm->prob_tx[1] = get_prob(cpi->txfm_count_32x32p[TX_8X8] + + cpi->txfm_count_16x16p[TX_8X8], + cpi->txfm_count_32x32p[TX_8X8] + + cpi->txfm_count_32x32p[TX_16X16] + + cpi->txfm_count_32x32p[TX_32X32] + + cpi->txfm_count_16x16p[TX_8X8] + + cpi->txfm_count_16x16p[TX_16X16]); + cm->prob_tx[2] = get_prob(cpi->txfm_count_32x32p[TX_16X16], + cpi->txfm_count_32x32p[TX_16X16] + + cpi->txfm_count_32x32p[TX_32X32]); + vp9_write_prob(w, cm->prob_tx[0]); + vp9_write_prob(w, cm->prob_tx[1]); + vp9_write_prob(w, cm->prob_tx[2]); + } else { + cm->prob_tx[0] = 128; + cm->prob_tx[1] = 128; + cm->prob_tx[2] = 128; + } +} + void write_uncompressed_header(VP9_COMMON *cm, struct vp9_write_bit_buffer *wb) { const int scaling_active = cm->width != cm->display_width || @@ -1521,47 +1564,10 @@ void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, unsigned long *size) { } } - if (cpi->mb.e_mbd.lossless) { + if (xd->lossless) pc->txfm_mode = ONLY_4X4; - } else { - if (pc->txfm_mode == TX_MODE_SELECT) { - pc->prob_tx[0] = get_prob(cpi->txfm_count_32x32p[TX_4X4] + - cpi->txfm_count_16x16p[TX_4X4] + - cpi->txfm_count_8x8p[TX_4X4], - cpi->txfm_count_32x32p[TX_4X4] + - cpi->txfm_count_32x32p[TX_8X8] + - cpi->txfm_count_32x32p[TX_16X16] + - cpi->txfm_count_32x32p[TX_32X32] + - cpi->txfm_count_16x16p[TX_4X4] + - cpi->txfm_count_16x16p[TX_8X8] + - cpi->txfm_count_16x16p[TX_16X16] + - cpi->txfm_count_8x8p[TX_4X4] + - cpi->txfm_count_8x8p[TX_8X8]); - pc->prob_tx[1] = get_prob(cpi->txfm_count_32x32p[TX_8X8] + - cpi->txfm_count_16x16p[TX_8X8], - cpi->txfm_count_32x32p[TX_8X8] + - cpi->txfm_count_32x32p[TX_16X16] + - cpi->txfm_count_32x32p[TX_32X32] + - cpi->txfm_count_16x16p[TX_8X8] + - cpi->txfm_count_16x16p[TX_16X16]); - pc->prob_tx[2] = get_prob(cpi->txfm_count_32x32p[TX_16X16], - cpi->txfm_count_32x32p[TX_16X16] + - cpi->txfm_count_32x32p[TX_32X32]); - } else { - pc->prob_tx[0] = 128; - pc->prob_tx[1] = 128; - pc->prob_tx[2] = 128; - } - vp9_write_literal(&header_bc, pc->txfm_mode <= 3 ? pc->txfm_mode : 3, 2); - if (pc->txfm_mode > ALLOW_16X16) { - vp9_write_bit(&header_bc, pc->txfm_mode == TX_MODE_SELECT); - } - if (pc->txfm_mode == TX_MODE_SELECT) { - vp9_write_prob(&header_bc, pc->prob_tx[0]); - vp9_write_prob(&header_bc, pc->prob_tx[1]); - vp9_write_prob(&header_bc, pc->prob_tx[2]); - } - } + else + encode_txfm(cpi, &header_bc); // If appropriate update the inter mode probability context and code the // changes in the bitstream. diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index d4daed5..714a1bf 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -1835,6 +1835,7 @@ void vp9_encode_frame(VP9_COMP *cpi) { if (txfm_type != TX_MODE_SELECT) { cpi->common.prob_tx[0] = 128; cpi->common.prob_tx[1] = 128; + cpi->common.prob_tx[2] = 128; } cpi->common.comp_pred_mode = pred_type; encode_frame_internal(cpi); -- 2.7.4