2014-01-24 10:37:15 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* This file is part of Kvazaar HEVC encoder.
|
2014-02-21 13:00:20 +00:00
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* Copyright (C) 2013-2015 Tampere University of Technology and others (see
|
2014-01-24 10:37:15 +00:00
|
|
|
* COPYING file).
|
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* Kvazaar is free software: you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2.1 of the License, or (at your
|
|
|
|
* option) any later version.
|
2014-01-24 10:37:15 +00:00
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* Kvazaar is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
|
|
|
* more details.
|
2014-01-24 10:37:15 +00:00
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with Kvazaar. If not, see <http://www.gnu.org/licenses/>.
|
2014-01-24 10:37:15 +00:00
|
|
|
****************************************************************************/
|
|
|
|
|
2013-09-18 09:16:03 +00:00
|
|
|
#include "context.h"
|
|
|
|
|
2016-04-01 14:14:23 +00:00
|
|
|
#include "tables.h"
|
2013-09-18 09:16:03 +00:00
|
|
|
|
2012-08-15 10:22:31 +00:00
|
|
|
|
2014-02-06 15:57:41 +00:00
|
|
|
// stuff
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
const uint8_t kvz_INIT_SAO_MERGE_FLAG[3] = { 153, 153, 153 };
|
|
|
|
const uint8_t kvz_INIT_SAO_TYPE_IDX[3] = { 160, 185, 200 };
|
2014-02-06 15:57:41 +00:00
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
const uint8_t kvz_INIT_QT_ROOT_CBF[3][1] = {
|
2014-02-21 13:00:20 +00:00
|
|
|
{ 79, },
|
|
|
|
{ 79, },
|
|
|
|
{ CNU, },
|
2014-02-06 15:57:41 +00:00
|
|
|
};
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
const uint8_t kvz_INIT_MVP_IDX[3][2] = {
|
2014-02-21 13:00:20 +00:00
|
|
|
{ 168, CNU, },
|
|
|
|
{ 168, CNU, },
|
|
|
|
{ CNU, CNU, },
|
2014-02-06 15:57:41 +00:00
|
|
|
};
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
const uint8_t kvz_INIT_REF_PIC[3][2] = {
|
2014-02-21 13:00:20 +00:00
|
|
|
{ 153, 153 },
|
|
|
|
{ 153, 153 },
|
|
|
|
{ CNU, CNU },
|
2014-02-06 15:57:41 +00:00
|
|
|
};
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
const uint8_t kvz_INIT_MVD[3][2] = {
|
2014-02-21 13:00:20 +00:00
|
|
|
{ 169, 198, },
|
|
|
|
{ 140, 198, },
|
|
|
|
{ CNU, CNU, },
|
2014-02-06 15:57:41 +00:00
|
|
|
};
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
const uint8_t kvz_INIT_MERGE_FLAG_EXT[3][1] = {
|
2014-02-21 13:00:20 +00:00
|
|
|
{ 154, },
|
|
|
|
{ 110, },
|
2014-02-06 15:57:41 +00:00
|
|
|
{ CNU, },
|
|
|
|
};
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
const uint8_t kvz_INIT_MERGE_IDX_EXT[3][1] = {
|
2014-02-21 13:00:20 +00:00
|
|
|
{ 137, },
|
|
|
|
{ 122, },
|
2014-02-06 15:57:41 +00:00
|
|
|
{ CNU, },
|
|
|
|
};
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
const uint8_t kvz_INIT_SKIP_FLAG[3][3] = {
|
2014-02-21 13:00:20 +00:00
|
|
|
{ 197, 185, 201, },
|
|
|
|
{ 197, 185, 201, },
|
2014-02-06 15:57:41 +00:00
|
|
|
{ CNU, CNU, CNU, },
|
|
|
|
};
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
const uint8_t kvz_INIT_PRED_MODE[3][1] = {
|
2014-02-21 13:00:20 +00:00
|
|
|
{ 134, },
|
|
|
|
{ 149, },
|
2014-02-06 15:57:41 +00:00
|
|
|
{ CNU, },
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
const uint8_t kvz_INIT_PART_SIZE[3][4] = {
|
2014-02-21 13:00:20 +00:00
|
|
|
{ 154, 139, CNU, CNU, },
|
|
|
|
{ 154, 139, CNU, CNU, },
|
|
|
|
{ 184, CNU, CNU, CNU, },
|
2014-02-06 15:57:41 +00:00
|
|
|
};
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
const uint8_t kvz_INIT_SPLIT_FLAG[3][3] = {
|
2014-02-06 15:57:41 +00:00
|
|
|
{ 107, 139, 126 },
|
|
|
|
{ 107, 139, 126 },
|
|
|
|
{ 139, 141, 157 },
|
|
|
|
};
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
const uint8_t kvz_INIT_INTRA_PRED_MODE[3] = {
|
2014-02-21 13:00:20 +00:00
|
|
|
183, 154, 184
|
2014-02-06 15:57:41 +00:00
|
|
|
};
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
const uint8_t kvz_INIT_CHROMA_PRED_MODE[3][2] = {
|
2014-02-21 13:00:20 +00:00
|
|
|
{ 152, 139 },
|
|
|
|
{ 152, 139 },
|
2014-02-06 15:57:41 +00:00
|
|
|
{ 63, 139 },
|
|
|
|
};
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
const uint8_t kvz_INIT_INTER_DIR[3][5] = {
|
2015-03-06 14:26:16 +00:00
|
|
|
{ 95, 79, 63, 31, 31, },
|
|
|
|
{ 95, 79, 63, 31, 31, },
|
|
|
|
{ CNU, CNU, CNU, CNU, CNU, },
|
|
|
|
};
|
2014-02-06 15:57:41 +00:00
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
const uint8_t kvz_INIT_TRANS_SUBDIV_FLAG[3][3] = {
|
2014-02-21 13:00:20 +00:00
|
|
|
{ 224, 167, 122 },
|
|
|
|
{ 124, 138, 94 },
|
2014-02-06 15:57:41 +00:00
|
|
|
{ 153, 138, 138 },
|
|
|
|
};
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
const uint8_t kvz_INIT_QT_CBF[3][8] = {
|
2014-09-11 09:44:41 +00:00
|
|
|
{ 153, 111, CNU, CNU, 149, 92, 167, 154 },
|
|
|
|
{ 153, 111, CNU, CNU, 149, 107, 167, 154 },
|
|
|
|
{ 111, 141, CNU, CNU, 94, 138, 182, 154 },
|
2014-02-06 15:57:41 +00:00
|
|
|
};
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
const uint8_t kvz_INIT_SIG_CG_FLAG[3][4] = {
|
2014-02-06 15:57:41 +00:00
|
|
|
{ 121, 140, 61, 154 },
|
|
|
|
{ 121, 140, 61, 154 },
|
|
|
|
{ 91, 171, 134, 141 },
|
|
|
|
};
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
const uint8_t kvz_INIT_SIG_FLAG[3][42] = {
|
2014-02-06 15:57:41 +00:00
|
|
|
{170,154,139,153,139,123,123, 63,124,166,
|
|
|
|
183,140,136,153,154,166,183,140,136,153,
|
|
|
|
154,166,183,140,136,153,154,170,153,138,
|
|
|
|
138,122,121,122,121,167,151,183,140,151,
|
|
|
|
183,140},
|
|
|
|
{155,154,139,153,139,123,123,63,153,166,
|
|
|
|
183,140,136,153,154,166,183,140,136,153,
|
|
|
|
154,166,183,140,136,153,154,170,153,123,
|
|
|
|
123,107,121,107,121,167,151,183,140,151,
|
|
|
|
183,140},
|
|
|
|
{111,111,125,110,110,94,124,108,124,107,
|
|
|
|
125,141,179,153,125,107,125,141,179,153,
|
|
|
|
125,107,125,141,179,153,125,140,139,182,
|
|
|
|
182,152,136,152,136,153,136,139,111,136,
|
|
|
|
139,111},
|
|
|
|
};
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
const uint8_t kvz_INIT_LAST[3][30] = {
|
2014-02-06 15:57:41 +00:00
|
|
|
{ 125, 110, 124, 110, 95, 94, 125, 111, 111, 79, 125, 126, 111, 111, 79,
|
|
|
|
108, 123, 93, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU },
|
|
|
|
{ 125, 110, 94, 110, 95, 79, 125, 111, 110, 78, 110, 111, 111, 95, 94,
|
|
|
|
108, 123, 108, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU },
|
|
|
|
{ 110, 110, 124, 125, 140, 153, 125, 127, 140, 109, 111, 143, 127, 111, 79,
|
|
|
|
108, 123, 63, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU },
|
|
|
|
};
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
const uint8_t kvz_INIT_ONE_FLAG[3][24] =
|
2014-02-06 15:57:41 +00:00
|
|
|
{
|
|
|
|
{154,196,167,167,154,152,167,182,182,134,149,136,153,121,136,122,169,208,166,167,154,152,167,182},
|
|
|
|
{154,196,196,167,154,152,167,182,182,134,149,136,153,121,136,137,169,194,166,167,154,167,137,182},
|
|
|
|
{140, 92,137,138,140,152,138,139,153, 74,149, 92,139,107,122,152,140,179,166,182,140,227,122,197},
|
|
|
|
};
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
const uint8_t kvz_INIT_ABS_FLAG[3][6] =
|
2014-02-06 15:57:41 +00:00
|
|
|
{
|
2014-02-21 13:00:20 +00:00
|
|
|
{ 107,167, 91,107,107,167},
|
|
|
|
{ 107,167, 91,122,107,167},
|
2014-02-06 15:57:41 +00:00
|
|
|
{ 138,153,136,167,152,152},
|
|
|
|
};
|
|
|
|
|
2014-04-02 07:54:03 +00:00
|
|
|
static const uint8_t INIT_TRANSFORMSKIP_FLAG[3][2] =
|
|
|
|
{
|
|
|
|
{ 139, 139},
|
|
|
|
{ 139, 139},
|
|
|
|
{ 139, 139},
|
|
|
|
};
|
|
|
|
|
2014-02-06 15:57:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-09-19 09:47:39 +00:00
|
|
|
/**
|
|
|
|
* \brief Initialize struct cabac_ctx.
|
|
|
|
*/
|
2015-08-26 08:50:27 +00:00
|
|
|
void kvz_ctx_init(cabac_ctx_t *ctx, uint32_t qp, uint32_t init_value)
|
2013-09-19 09:47:39 +00:00
|
|
|
{
|
|
|
|
int slope = (init_value >> 4) * 5 - 45;
|
|
|
|
int offset = ((init_value & 15) << 3) - 16;
|
|
|
|
int init_state = MIN(MAX(1, ((slope * (int)qp) >> 4) + offset), 126);
|
|
|
|
|
2013-09-19 10:10:32 +00:00
|
|
|
if (init_state >= 64) {
|
|
|
|
ctx->uc_state = ((init_state - 64) << 1) + 1;
|
2013-09-19 09:47:39 +00:00
|
|
|
} else {
|
|
|
|
ctx->uc_state = (63 - init_state) << 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-19 09:20:34 +00:00
|
|
|
/**
|
|
|
|
* \brief Initialize cabac context to be used for coding
|
|
|
|
* \param encoder encoder control struct
|
|
|
|
* \param slice type of slice we are coding (P/B/I)
|
|
|
|
*/
|
2014-04-04 08:50:07 +00:00
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
void kvz_init_contexts(encoder_state_t *state, int8_t QP, int8_t slice)
|
2012-08-15 10:22:31 +00:00
|
|
|
{
|
2015-03-04 15:00:23 +00:00
|
|
|
cabac_data_t * const cabac = &state->cabac;
|
2012-08-15 10:22:31 +00:00
|
|
|
uint16_t i;
|
2013-09-09 09:11:09 +00:00
|
|
|
|
2013-09-19 09:20:34 +00:00
|
|
|
// Initialize contexts
|
2015-08-26 08:50:27 +00:00
|
|
|
kvz_ctx_init(&cabac->ctx.transform_skip_model_luma, QP, INIT_TRANSFORMSKIP_FLAG[slice][0]);
|
|
|
|
kvz_ctx_init(&cabac->ctx.transform_skip_model_chroma, QP, INIT_TRANSFORMSKIP_FLAG[slice][1]);
|
2014-04-02 07:54:03 +00:00
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
kvz_ctx_init(&cabac->ctx.sao_merge_flag_model, QP, kvz_INIT_SAO_MERGE_FLAG[slice]);
|
|
|
|
kvz_ctx_init(&cabac->ctx.sao_type_idx_model, QP, kvz_INIT_SAO_TYPE_IDX[slice]);
|
2013-10-23 16:51:39 +00:00
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
kvz_ctx_init(&cabac->ctx.cu_merge_flag_ext_model, QP, kvz_INIT_MERGE_FLAG_EXT[slice][0]);
|
|
|
|
kvz_ctx_init(&cabac->ctx.cu_merge_idx_ext_model, QP, kvz_INIT_MERGE_IDX_EXT[slice][0]);
|
|
|
|
kvz_ctx_init(&cabac->ctx.cu_pred_mode_model, QP, kvz_INIT_PRED_MODE[slice][0]);
|
2013-04-19 07:56:40 +00:00
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
kvz_ctx_init(&cabac->ctx.cu_skip_flag_model[0], QP, kvz_INIT_SKIP_FLAG[slice][0]);
|
|
|
|
kvz_ctx_init(&cabac->ctx.cu_skip_flag_model[1], QP, kvz_INIT_SKIP_FLAG[slice][1]);
|
|
|
|
kvz_ctx_init(&cabac->ctx.cu_skip_flag_model[2], QP, kvz_INIT_SKIP_FLAG[slice][2]);
|
2013-04-19 07:56:40 +00:00
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
kvz_ctx_init(&cabac->ctx.split_flag_model[0], QP, kvz_INIT_SPLIT_FLAG[slice][0]);
|
|
|
|
kvz_ctx_init(&cabac->ctx.split_flag_model[1], QP, kvz_INIT_SPLIT_FLAG[slice][1]);
|
|
|
|
kvz_ctx_init(&cabac->ctx.split_flag_model[2], QP, kvz_INIT_SPLIT_FLAG[slice][2]);
|
2012-08-15 10:22:31 +00:00
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
kvz_ctx_init(&cabac->ctx.intra_mode_model, QP, kvz_INIT_INTRA_PRED_MODE[slice]);
|
2012-08-15 10:22:31 +00:00
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
kvz_ctx_init(&cabac->ctx.chroma_pred_model[0], QP, kvz_INIT_CHROMA_PRED_MODE[slice][0]);
|
|
|
|
kvz_ctx_init(&cabac->ctx.chroma_pred_model[1], QP, kvz_INIT_CHROMA_PRED_MODE[slice][1]);
|
2014-02-21 13:00:20 +00:00
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
kvz_ctx_init(&cabac->ctx.cu_abs_model_chroma[0], QP, kvz_INIT_ABS_FLAG[slice][4]);
|
|
|
|
kvz_ctx_init(&cabac->ctx.cu_abs_model_chroma[1], QP, kvz_INIT_ABS_FLAG[slice][5]);
|
2012-08-15 10:22:31 +00:00
|
|
|
|
2013-09-09 11:22:53 +00:00
|
|
|
//TODO: ignore P/B contexts on intra frame
|
2015-08-26 08:50:27 +00:00
|
|
|
kvz_ctx_init(&cabac->ctx.cu_qt_root_cbf_model, QP, kvz_INIT_QT_ROOT_CBF[slice][0]);
|
2013-09-18 11:21:03 +00:00
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
kvz_ctx_init(&cabac->ctx.cu_mvd_model[0], QP, kvz_INIT_MVD[slice][0]);
|
|
|
|
kvz_ctx_init(&cabac->ctx.cu_mvd_model[1], QP, kvz_INIT_MVD[slice][1]);
|
|
|
|
kvz_ctx_init(&cabac->ctx.cu_ref_pic_model[0], QP, kvz_INIT_REF_PIC[slice][0]);
|
|
|
|
kvz_ctx_init(&cabac->ctx.cu_ref_pic_model[1], QP, kvz_INIT_REF_PIC[slice][1]);
|
|
|
|
kvz_ctx_init(&cabac->ctx.mvp_idx_model[0], QP, kvz_INIT_MVP_IDX[slice][0]);
|
|
|
|
kvz_ctx_init(&cabac->ctx.mvp_idx_model[1], QP, kvz_INIT_MVP_IDX[slice][1]);
|
2014-02-21 13:00:20 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
2015-08-26 08:50:27 +00:00
|
|
|
kvz_ctx_init(&cabac->ctx.cu_sig_coeff_group_model[i], QP, kvz_INIT_SIG_CG_FLAG[slice][i]);
|
|
|
|
kvz_ctx_init(&cabac->ctx.cu_abs_model_luma[i], QP, kvz_INIT_ABS_FLAG[slice][i]);
|
|
|
|
kvz_ctx_init(&cabac->ctx.part_size_model[i], QP, kvz_INIT_PART_SIZE[slice][i]);
|
2012-08-15 10:22:31 +00:00
|
|
|
}
|
2013-09-19 09:20:34 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
2015-08-26 08:50:27 +00:00
|
|
|
kvz_ctx_init(&cabac->ctx.trans_subdiv_model[i], QP, kvz_INIT_TRANS_SUBDIV_FLAG[slice][i]);
|
2014-09-11 09:44:41 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < 4; i++) {
|
2015-08-26 08:50:27 +00:00
|
|
|
kvz_ctx_init(&cabac->ctx.qt_cbf_model_luma[i], QP, kvz_INIT_QT_CBF[slice][i]);
|
|
|
|
kvz_ctx_init(&cabac->ctx.qt_cbf_model_chroma[i], QP, kvz_INIT_QT_CBF[slice][i + 4]);
|
2013-02-05 13:48:06 +00:00
|
|
|
}
|
|
|
|
|
2015-03-06 14:26:16 +00:00
|
|
|
for (i = 0; i < 5; i++) {
|
2015-08-26 08:50:27 +00:00
|
|
|
kvz_ctx_init(&cabac->ctx.inter_dir[i], QP, kvz_INIT_INTER_DIR[slice][i]);
|
2015-03-06 14:26:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 09:20:34 +00:00
|
|
|
for (i = 0; i < 8; i++) {
|
2015-08-26 08:50:27 +00:00
|
|
|
kvz_ctx_init(&cabac->ctx.cu_one_model_chroma[i], QP, kvz_INIT_ONE_FLAG[slice][i+16]);
|
2012-08-15 10:22:31 +00:00
|
|
|
}
|
2013-02-05 13:48:06 +00:00
|
|
|
|
2013-09-19 09:20:34 +00:00
|
|
|
for (i = 0; i < 15; i++) {
|
2015-08-26 08:50:27 +00:00
|
|
|
kvz_ctx_init(&cabac->ctx.cu_ctx_last_y_luma[i], QP, kvz_INIT_LAST[slice][i] );
|
|
|
|
kvz_ctx_init(&cabac->ctx.cu_ctx_last_x_luma[i], QP, kvz_INIT_LAST[slice][i] );
|
2013-02-05 13:48:06 +00:00
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
kvz_ctx_init(&cabac->ctx.cu_ctx_last_y_chroma[i], QP, kvz_INIT_LAST[slice][i+15] );
|
|
|
|
kvz_ctx_init(&cabac->ctx.cu_ctx_last_x_chroma[i], QP, kvz_INIT_LAST[slice][i+15] );
|
2012-08-15 10:22:31 +00:00
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
kvz_ctx_init(&cabac->ctx.cu_one_model_luma[i], QP, kvz_INIT_ONE_FLAG[slice][i]);
|
2012-08-15 10:22:31 +00:00
|
|
|
}
|
2015-08-26 08:50:27 +00:00
|
|
|
kvz_ctx_init(&cabac->ctx.cu_one_model_luma[15], QP, kvz_INIT_ONE_FLAG[slice][15]);
|
2014-02-21 13:00:20 +00:00
|
|
|
|
2013-09-19 09:20:34 +00:00
|
|
|
for (i = 0; i < 27; i++) {
|
2015-08-26 08:50:27 +00:00
|
|
|
kvz_ctx_init(&cabac->ctx.cu_sig_model_luma[i], QP, kvz_INIT_SIG_FLAG[slice][i]);
|
|
|
|
if(i < 15) kvz_ctx_init(&cabac->ctx.cu_sig_model_chroma[i], QP, kvz_INIT_SIG_FLAG[slice][i+27]);
|
2012-08-15 10:22:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
void kvz_context_copy(encoder_state_t * const target_state, const encoder_state_t * const source_state) {
|
2015-03-04 15:00:23 +00:00
|
|
|
cabac_data_t * const target_cabac = &target_state->cabac;
|
|
|
|
const cabac_data_t * const source_cabac = &source_state->cabac;
|
2014-05-08 08:12:57 +00:00
|
|
|
|
2014-09-23 22:04:12 +00:00
|
|
|
if (target_cabac == source_cabac) return;
|
|
|
|
|
|
|
|
target_cabac->ctx = source_cabac->ctx;
|
2014-05-08 08:12:57 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 09:20:34 +00:00
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
uint32_t kvz_context_get_sig_coeff_group( uint32_t *sig_coeff_group_flag,
|
2013-09-19 09:20:34 +00:00
|
|
|
uint32_t pos_x,
|
|
|
|
uint32_t pos_y,
|
|
|
|
int32_t width)
|
2013-02-05 13:48:06 +00:00
|
|
|
{
|
|
|
|
uint32_t uiRight = 0;
|
|
|
|
uint32_t uiLower = 0;
|
|
|
|
width >>= 2;
|
2013-09-19 09:20:34 +00:00
|
|
|
if (pos_x < (uint32_t)width - 1) uiRight = (sig_coeff_group_flag[pos_y * width + pos_x + 1] != 0);
|
|
|
|
if (pos_y < (uint32_t)width - 1) uiLower = (sig_coeff_group_flag[(pos_y + 1 ) * width + pos_x] != 0);
|
2013-02-05 13:48:06 +00:00
|
|
|
|
2013-09-19 09:20:34 +00:00
|
|
|
return uiRight || uiLower;
|
2013-02-05 13:48:06 +00:00
|
|
|
}
|
2012-08-15 10:22:31 +00:00
|
|
|
|
|
|
|
|
2014-02-21 13:00:20 +00:00
|
|
|
/**
|
2013-09-19 09:20:34 +00:00
|
|
|
* \brief Pattern decision for context derivation process of significant_coeff_flag
|
|
|
|
* \param sig_coeff_group_flag pointer to prior coded significant coeff group
|
|
|
|
* \param pos_x column of current coefficient group
|
|
|
|
* \param pos_y row of current coefficient group
|
|
|
|
* \param width width of the block
|
|
|
|
* \returns pattern for current coefficient group
|
|
|
|
*/
|
2014-02-21 13:00:20 +00:00
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
int32_t kvz_context_calc_pattern_sig_ctx(const uint32_t *sig_coeff_group_flag, uint32_t pos_x, uint32_t pos_y, int32_t width)
|
2012-08-15 10:22:31 +00:00
|
|
|
{
|
2013-02-05 13:48:06 +00:00
|
|
|
uint32_t sigRight = 0;
|
|
|
|
uint32_t sigLower = 0;
|
2013-09-19 09:20:34 +00:00
|
|
|
|
|
|
|
if (width == 4) return -1;
|
|
|
|
|
2012-08-15 10:22:31 +00:00
|
|
|
width >>= 2;
|
2013-09-19 09:20:34 +00:00
|
|
|
if (pos_x < (uint32_t)width - 1) sigRight = (sig_coeff_group_flag[pos_y * width + pos_x + 1] != 0);
|
|
|
|
if (pos_y < (uint32_t)width - 1) sigLower = (sig_coeff_group_flag[(pos_y + 1 ) * width + pos_x] != 0);
|
2014-02-21 13:00:20 +00:00
|
|
|
|
2012-08-15 10:22:31 +00:00
|
|
|
return sigRight + (sigLower<<1);
|
|
|
|
}
|
2013-02-05 13:48:06 +00:00
|
|
|
|
2012-08-15 10:22:31 +00:00
|
|
|
|
2013-09-19 09:20:34 +00:00
|
|
|
/**
|
|
|
|
* \brief Context derivation process of coeff_abs_significant_flag
|
|
|
|
* \param pattern_sig_ctx pattern for current coefficient group
|
|
|
|
* \param scan_idx pixel scan type in use
|
|
|
|
* \param pos_x column of current scan position
|
|
|
|
* \param pos_y row of current scan position
|
|
|
|
* \param block_type log2 value of block size if square block, or 4 otherwise
|
|
|
|
* \param width width of the block
|
|
|
|
* \param texture_type texture type (TEXT_LUMA...)
|
|
|
|
* \returns ctx_inc for current scan position
|
|
|
|
*/
|
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
int32_t kvz_context_get_sig_ctx_inc(int32_t pattern_sig_ctx, uint32_t scan_idx, int32_t pos_x,
|
2014-04-04 08:32:56 +00:00
|
|
|
int32_t pos_y, int32_t block_type, int8_t texture_type)
|
2012-08-15 10:22:31 +00:00
|
|
|
{
|
2013-09-18 11:21:03 +00:00
|
|
|
const int32_t ctx_ind_map[16] =
|
2012-08-15 10:22:31 +00:00
|
|
|
{
|
|
|
|
0, 1, 4, 5,
|
|
|
|
2, 3, 4, 5,
|
|
|
|
6, 6, 8, 8,
|
|
|
|
7, 7, 8, 8
|
|
|
|
};
|
|
|
|
|
2013-09-19 09:20:34 +00:00
|
|
|
int32_t cnt,offset,pos_x_in_subset,pos_y_in_subset;
|
2012-08-15 10:22:31 +00:00
|
|
|
|
2013-09-19 09:20:34 +00:00
|
|
|
if (pos_x + pos_y == 0) return 0;
|
2012-08-15 10:22:31 +00:00
|
|
|
|
2013-09-19 09:20:34 +00:00
|
|
|
if (block_type == 2) return ctx_ind_map[4 * pos_y + pos_x];
|
|
|
|
|
|
|
|
offset = (block_type == 3) ? ((scan_idx == SCAN_DIAG) ? 9 : 15) : ((texture_type == 0) ? 21 : 12);
|
|
|
|
pos_x_in_subset = pos_x - ((pos_x>>2)<<2);
|
|
|
|
pos_y_in_subset = pos_y - ((pos_y>>2)<<2);
|
2014-02-21 13:00:20 +00:00
|
|
|
|
2013-09-19 09:20:34 +00:00
|
|
|
if (pattern_sig_ctx == 0) {
|
2014-02-21 13:00:20 +00:00
|
|
|
cnt = (pos_x_in_subset + pos_y_in_subset <= 2) ? ((pos_x_in_subset + pos_y_in_subset==0) ? 2 : 1) : 0;
|
2013-09-19 09:20:34 +00:00
|
|
|
} else if (pattern_sig_ctx==1) {
|
|
|
|
cnt = (pos_y_in_subset <= 1) ? ((pos_y_in_subset == 0) ? 2 : 1) : 0;
|
|
|
|
} else if (pattern_sig_ctx==2) {
|
|
|
|
cnt = (pos_x_in_subset <= 1) ? ((pos_x_in_subset == 0) ? 2 : 1) : 0;
|
|
|
|
} else {
|
2012-08-15 10:22:31 +00:00
|
|
|
cnt = 2;
|
|
|
|
}
|
2013-09-18 11:21:03 +00:00
|
|
|
return (( texture_type == 0 && ((pos_x>>2) + (pos_y>>2)) > 0 ) ? 3 : 0) + offset + cnt;
|
2012-08-15 10:22:31 +00:00
|
|
|
}
|