mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-24 10:34:05 +00:00
encry coef transfs
This commit is contained in:
parent
7ad5f8bbe5
commit
73c3203a26
193
src/cabac.c
193
src/cabac.c
|
@ -271,6 +271,7 @@ void kvz_cabac_write_coeff_remain(cabac_data_t * const cabac, const uint32_t sym
|
||||||
{
|
{
|
||||||
int32_t code_number = symbol;
|
int32_t code_number = symbol;
|
||||||
uint32_t length;
|
uint32_t length;
|
||||||
|
|
||||||
if (code_number < (3 << r_param)) {
|
if (code_number < (3 << r_param)) {
|
||||||
length = code_number >> r_param;
|
length = code_number >> r_param;
|
||||||
CABAC_BINS_EP(cabac, (1 << (length + 1)) - 2 , length + 1, "coeff_abs_level_remaining");
|
CABAC_BINS_EP(cabac, (1 << (length + 1)) - 2 , length + 1, "coeff_abs_level_remaining");
|
||||||
|
@ -287,6 +288,198 @@ void kvz_cabac_write_coeff_remain(cabac_data_t * const cabac, const uint32_t sym
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void kvz_cabac_write_coeff_remain_encry(struct encoder_state_t * const state, cabac_data_t * const cabac,const uint32_t symbol, const uint32_t r_param, int32_t base_level)
|
||||||
|
{
|
||||||
|
int32_t codeNumber = (int32_t)symbol;
|
||||||
|
uint32_t length;
|
||||||
|
|
||||||
|
if (codeNumber < (3 << r_param)) {
|
||||||
|
length = codeNumber>>r_param;
|
||||||
|
CABAC_BINS_EP(cabac, (1 << (length + 1)) - 2 , length + 1, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP( (1<<(length+1))-2 , length+1);
|
||||||
|
uint32_t Suffix = (codeNumber%(1<<r_param));
|
||||||
|
|
||||||
|
if(!r_param)
|
||||||
|
CABAC_BINS_EP(cabac, Suffix, r_param, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(Suffix, r_param);
|
||||||
|
if(r_param==1) {
|
||||||
|
if(!(( base_level ==2 )&& (codeNumber==4 || codeNumber==5) ) ) {
|
||||||
|
uint32_t key = ff_get_key(&state->tile->dbs_g, 1);
|
||||||
|
state->tile->m_prev_pos = ( Suffix + ( state->tile->m_prev_pos^key ) ) & 1;
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 1, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos, 1);
|
||||||
|
} else {
|
||||||
|
CABAC_BINS_EP(cabac, Suffix, 1, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(Suffix, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if(r_param==2) {
|
||||||
|
if( base_level ==1) {
|
||||||
|
uint32_t key =ff_get_key(&state->tile->dbs_g, 2);
|
||||||
|
state->tile->m_prev_pos = ( Suffix + ( state->tile->m_prev_pos^key ) ) & 3;
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 2, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos, 2);
|
||||||
|
} else
|
||||||
|
if( base_level ==2) {
|
||||||
|
if(codeNumber<=7 || codeNumber>=12) {
|
||||||
|
uint32_t key = ff_get_key(&state->tile->dbs_g, 2);
|
||||||
|
state->tile->m_prev_pos = ( Suffix + ( state->tile->m_prev_pos^key ) ) & 3;
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 2, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos, 2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if(codeNumber<10) {
|
||||||
|
uint32_t key = ff_get_key(&state->tile->dbs_g, 1);
|
||||||
|
state->tile->m_prev_pos = (( (Suffix&1) + ( state->tile->m_prev_pos^key )) & 1);
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 2, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos, 2);
|
||||||
|
} else
|
||||||
|
CABAC_BINS_EP(cabac, Suffix, 2, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(Suffix, 2);
|
||||||
|
} else { //base_level=3
|
||||||
|
if(codeNumber<=7 || codeNumber>11) {
|
||||||
|
uint32_t key = ff_get_key(&state->tile->dbs_g, 2);
|
||||||
|
state->tile->m_prev_pos = (Suffix + ( state->tile->m_prev_pos^key ) ) & 3;
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 2, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos, 2);
|
||||||
|
} else {
|
||||||
|
uint32_t key = ff_get_key(&state->tile->dbs_g, 1);
|
||||||
|
state->tile->m_prev_pos = ((Suffix&2))+(( (Suffix&1) + ( state->tile->m_prev_pos^key)) & 1);
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 2, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
if(r_param==3) {
|
||||||
|
if( base_level ==1) {
|
||||||
|
uint32_t key = ff_get_key(&state->tile->dbs_g, 3);
|
||||||
|
state->tile->m_prev_pos = ( Suffix + ( state->tile->m_prev_pos^key ) ) & 7;
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 3, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos, 3);
|
||||||
|
}
|
||||||
|
else if( base_level ==2) {
|
||||||
|
if(codeNumber<=15 || codeNumber>23) {
|
||||||
|
uint32_t key = ff_get_key(&state->tile->dbs_g, 3);
|
||||||
|
state->tile->m_prev_pos = ( Suffix + ( state->tile->m_prev_pos^key ) ) & 7;
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 3, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos, 3);
|
||||||
|
} else
|
||||||
|
if(codeNumber<=19){
|
||||||
|
uint32_t key = ff_get_key(&state->tile->dbs_g, 2);
|
||||||
|
state->tile->m_prev_pos = ((Suffix&4))+(( (Suffix&3) + (state->tile->m_prev_pos^key )) & 3);
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 3, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos, 3);
|
||||||
|
} else
|
||||||
|
if(codeNumber<=21){
|
||||||
|
uint32_t key = ff_get_key(&state->tile->dbs_g, 1);
|
||||||
|
state->tile->m_prev_pos = 4+(( (Suffix&1) + ( state->tile->m_prev_pos^key )) & 1);
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 3, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos, 3);
|
||||||
|
} else
|
||||||
|
CABAC_BINS_EP(cabac, Suffix, 3, "coeff_abs_level_remaining");
|
||||||
|
// m_pcBinIf->encodeBinsEP(Suffix, 3);
|
||||||
|
} else {//base_level=3
|
||||||
|
CABAC_BINS_EP(cabac, Suffix, 3, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(Suffix, 3);
|
||||||
|
if(codeNumber<=15 || codeNumber>23) {
|
||||||
|
uint32_t key = ff_get_key(&state->tile->dbs_g, 3);
|
||||||
|
state->tile->m_prev_pos = (Suffix + ( state->tile->m_prev_pos^key ) ) & 7;
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 3, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos, 3);
|
||||||
|
} else
|
||||||
|
if(codeNumber<=19) {
|
||||||
|
uint32_t key = ff_get_key(&state->tile->dbs_g, 2);
|
||||||
|
state->tile->m_prev_pos = (( (Suffix&3) + ( state->tile->m_prev_pos^key )) &3);
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 3, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos, 3);
|
||||||
|
} else
|
||||||
|
if(codeNumber<=23) {
|
||||||
|
uint32_t key = ff_get_key(&state->tile->dbs_g, 1);
|
||||||
|
state->tile->m_prev_pos = (Suffix&6)+(( (Suffix&1) + (state->tile->m_prev_pos^key )) & 1);
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 3, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos, 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
if(r_param==4) {
|
||||||
|
if( base_level ==1) {
|
||||||
|
uint32_t key = ff_get_key(&state->tile->dbs_g, 4);
|
||||||
|
state->tile->m_prev_pos = ( Suffix + ( state->tile->m_prev_pos^key ) ) & 15;
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 4, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos, 4);
|
||||||
|
} else
|
||||||
|
if( base_level ==2) {
|
||||||
|
if(codeNumber<=31 || codeNumber>47) {
|
||||||
|
uint32_t key = ff_get_key(&state->tile->dbs_g, 4);
|
||||||
|
state->tile->m_prev_pos = ( Suffix + ( state->tile->m_prev_pos^key ) ) & 15;
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, r_param, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos, r_param);
|
||||||
|
} else
|
||||||
|
if(codeNumber<=39) {
|
||||||
|
uint32_t key = ff_get_key(&state->tile->dbs_g, 3);
|
||||||
|
state->tile->m_prev_pos = (( (Suffix&7) + ( state->tile->m_prev_pos^key )) & 7);
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 4, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos, 4);
|
||||||
|
} else
|
||||||
|
if(codeNumber<=43) {
|
||||||
|
uint32_t key = ff_get_key(&state->tile->dbs_g, 2);
|
||||||
|
state->tile->m_prev_pos = 8+(( (Suffix&3) + ( state->tile->m_prev_pos^key )) & 3);
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 4, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos, 4);
|
||||||
|
} else
|
||||||
|
if(codeNumber<=45){
|
||||||
|
uint32_t key = ff_get_key(&state->tile->dbs_g, 1);
|
||||||
|
state->tile->m_prev_pos = 12+(( (Suffix&1) + ( state->tile->m_prev_pos^key )) & 1);
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 4, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos, 4);
|
||||||
|
} else
|
||||||
|
CABAC_BINS_EP(cabac, Suffix, 4, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(Suffix, 4);
|
||||||
|
} else {//base_level=3
|
||||||
|
if(codeNumber<=31 || codeNumber>47) {
|
||||||
|
uint32_t key = ff_get_key(&state->tile->dbs_g, 4);
|
||||||
|
state->tile->m_prev_pos = (Suffix + ( state->tile->m_prev_pos^key ) ) & 15;
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, r_param, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos, r_param);
|
||||||
|
} else
|
||||||
|
if(codeNumber<=39) {
|
||||||
|
uint32_t key = ff_get_key(&state->tile->dbs_g, 3);
|
||||||
|
state->tile->m_prev_pos = (( (Suffix&7) + ( state->tile->m_prev_pos^key )) & 7);
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 4, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos, 4);
|
||||||
|
} else
|
||||||
|
if(codeNumber<=43) {
|
||||||
|
uint32_t key = ff_get_key(&state->tile->dbs_g, 2);
|
||||||
|
state->tile->m_prev_pos = 8+(( (Suffix&3) + ( state->tile->m_prev_pos^key )) & 3);
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 4, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos, 4);
|
||||||
|
} else
|
||||||
|
if(codeNumber<=47) {
|
||||||
|
uint32_t key = ff_get_key(&state->tile->dbs_g, 1);
|
||||||
|
state->tile->m_prev_pos = (Suffix&14)+(( (Suffix&1) + (state->tile->m_prev_pos^key )) & 1);
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 4, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
length = r_param;
|
||||||
|
codeNumber = codeNumber - ( 3 << r_param);
|
||||||
|
while (codeNumber >= (1<<length)) {
|
||||||
|
codeNumber -= (1<<(length));
|
||||||
|
++length;
|
||||||
|
}
|
||||||
|
CABAC_BINS_EP(cabac, (1 << (3 + length + 1 - r_param)) - 2, 3 + length + 1 - r_param, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP((1<<(COEF_REMAIN_BIN_REDUCTION+length+1-r_param))-2,COEF_REMAIN_BIN_REDUCTION+length+1-r_param);
|
||||||
|
uint32_t Suffix = codeNumber;
|
||||||
|
uint32_t key = ff_get_key(&state->tile->dbs_g, length);
|
||||||
|
uint32_t mask = ( (1<<length ) -1 );
|
||||||
|
state->tile->m_prev_pos = ( Suffix + ( state->tile->m_prev_pos^key ) ) & mask;
|
||||||
|
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, length, "coeff_abs_level_remaining");
|
||||||
|
//m_pcBinIf->encodeBinsEP(m_prev_pos,length);
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* \brief
|
* \brief
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -104,6 +104,8 @@ void kvz_cabac_finish(cabac_data_t *data);
|
||||||
void kvz_cabac_flush(cabac_data_t *data);
|
void kvz_cabac_flush(cabac_data_t *data);
|
||||||
void kvz_cabac_write_coeff_remain(cabac_data_t *cabac, uint32_t symbol,
|
void kvz_cabac_write_coeff_remain(cabac_data_t *cabac, uint32_t symbol,
|
||||||
uint32_t r_param);
|
uint32_t r_param);
|
||||||
|
void kvz_cabac_write_coeff_remain_encry(struct encoder_state_t * const state, cabac_data_t * const cabac, const uint32_t symbol,
|
||||||
|
const uint32_t r_param, int32_t base_level);
|
||||||
void kvz_cabac_write_ep_ex_golomb(struct encoder_state_t * const state, cabac_data_t *data,
|
void kvz_cabac_write_ep_ex_golomb(struct encoder_state_t * const state, cabac_data_t *data,
|
||||||
uint32_t symbol, uint32_t count);
|
uint32_t symbol, uint32_t count);
|
||||||
void kvz_cabac_write_unary_max_symbol(cabac_data_t *data, cabac_ctx_t *ctx,
|
void kvz_cabac_write_unary_max_symbol(cabac_data_t *data, cabac_ctx_t *ctx,
|
||||||
|
|
|
@ -1932,12 +1932,16 @@ void kvz_encode_coeff_nxn(encoder_state_t * const state, coeff_t *coeff, uint8_t
|
||||||
CABAC_BIN(cabac, symbol, "coeff_abs_level_greater2_flag");
|
CABAC_BIN(cabac, symbol, "coeff_abs_level_greater2_flag");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (be_valid && sign_hidden) {
|
||||||
|
coeff_signs = coeff_signs >> 1;
|
||||||
|
if(!state->cabac.only_count)
|
||||||
|
if (state->encoder_control->cfg->crypto_features & KVZ_CRYPTO_TRANSF_COEFF_SIGNS)
|
||||||
|
coeff_signs = coeff_signs ^ ff_get_key(&state->tile->dbs_g, num_non_zero-1);
|
||||||
|
CABAC_BINS_EP(cabac, coeff_signs , (num_non_zero - 1), "coeff_sign_flag");
|
||||||
|
} else {
|
||||||
if(!state->cabac.only_count)
|
if(!state->cabac.only_count)
|
||||||
if (state->encoder_control->cfg->crypto_features & KVZ_CRYPTO_TRANSF_COEFF_SIGNS)
|
if (state->encoder_control->cfg->crypto_features & KVZ_CRYPTO_TRANSF_COEFF_SIGNS)
|
||||||
coeff_signs = coeff_signs ^ ff_get_key(&state->tile->dbs_g, num_non_zero);
|
coeff_signs = coeff_signs ^ ff_get_key(&state->tile->dbs_g, num_non_zero);
|
||||||
if (be_valid && sign_hidden) {
|
|
||||||
CABAC_BINS_EP(cabac, (coeff_signs >> 1), (num_non_zero - 1), "coeff_sign_flag");
|
|
||||||
} else {
|
|
||||||
CABAC_BINS_EP(cabac, coeff_signs, num_non_zero, "coeff_sign_flag");
|
CABAC_BINS_EP(cabac, coeff_signs, num_non_zero, "coeff_sign_flag");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1948,6 +1952,12 @@ void kvz_encode_coeff_nxn(encoder_state_t * const state, coeff_t *coeff, uint8_t
|
||||||
int32_t base_level = (idx < C1FLAG_NUMBER) ? (2 + first_coeff2) : 1;
|
int32_t base_level = (idx < C1FLAG_NUMBER) ? (2 + first_coeff2) : 1;
|
||||||
|
|
||||||
if (abs_coeff[idx] >= base_level) {
|
if (abs_coeff[idx] >= base_level) {
|
||||||
|
if(!state->cabac.only_count) {
|
||||||
|
if (state->encoder_control->cfg->crypto_features & KVZ_CRYPTO_TRANSF_COEFFS)
|
||||||
|
kvz_cabac_write_coeff_remain_encry(state, cabac, abs_coeff[idx] - base_level, go_rice_param, base_level);
|
||||||
|
else
|
||||||
|
kvz_cabac_write_coeff_remain(cabac, abs_coeff[idx] - base_level, go_rice_param);
|
||||||
|
} else
|
||||||
kvz_cabac_write_coeff_remain(cabac, abs_coeff[idx] - base_level, go_rice_param);
|
kvz_cabac_write_coeff_remain(cabac, abs_coeff[idx] - base_level, go_rice_param);
|
||||||
|
|
||||||
if (abs_coeff[idx] > 3 * (1 << go_rice_param)) {
|
if (abs_coeff[idx] > 3 * (1 << go_rice_param)) {
|
||||||
|
|
Loading…
Reference in a new issue