?? tce.c
字號:
if ((p2 = QccVectorAlloc(subband_num_cols)) == NULL)
{
QccErrorAddMessage("(QccWAVtceRevEst): Error calling QccVectorAlloc()");
goto Error;
}
p1 = QccMathMax(QCCTCE_BOUNDARY_VALUE,
((double)subband_significance[subband]) /
(subband_num_rows*subband_num_cols)) *
(1 + alpha_h) / (2 * alpha_v + 2 * alpha_h);
for (col = 0; col < subband_num_cols; col++)
p2[col] = p1;
for (row = subband_num_rows - 1; row >= 0; row--)
{
p1 = p2[0]*(1 - alpha_v)/(1 + alpha_h);
current_row = subband_origin_row + row;
for (col = subband_num_cols - 1; col >= 0; col--)
{
current_col = subband_origin_col + col;
p_char = &(significance_map[current_row][current_col]);
p[current_row][current_col] = alpha_h * p1 + alpha_v*p2[col];
if (*p_char == QCCTCE_S)
{
p1 = alpha_h * p1 + filter_coef * QCCWAVTCE_REFINE_HOLDER;
subband_significance[subband] += QCCWAVTCE_REFINE_HOLDER;
}
else
{
v = (*p_char == QCCTCE_S_NEW);
p1 = alpha_h * p1 + filter_coef * v;
subband_significance[subband] += v;
}
p2[col] = p1 + alpha_v * p2[col];
}
p3 = p2[0]*(1 - alpha_v)/(1 + alpha_h);
for (col = 0; col < subband_num_cols; col++)
{
p_char = &(significance_map[current_row][subband_origin_col + col]);
p2[col] = p2[col] + alpha_h * p3;
if (*p_char == QCCTCE_S)
p3 = alpha_h * p3 + filter_coef * QCCWAVTCE_REFINE_HOLDER;
else
{
v = (*p_char == QCCTCE_S_NEW);
p3 = alpha_h * p3 + filter_coef * v;
}
}
}
return_value = 0;
goto Return;
Error:
return_value = 1;
Return:
QccVectorFree(p2);
return(return_value);
}
static int QccWAVUpdateNZNStatus(int subband_origin_row,
int subband_origin_col,
int subband_num_row,
int subband_num_col,
int row,
int col,
char** significance_map,
int subband)
{
//Updata neighbors
int current_row, current_col;
int shifted_row, shifted_col;
current_row = subband_origin_row + row;
current_col = subband_origin_col + col;
if (row > 0)
{
shifted_row = current_row - 1;
shifted_col = current_col;
if (significance_map[shifted_row][shifted_col] < QCCTCE_S)
significance_map[shifted_row][shifted_col] = QCCTCE_NZN_NEW;
if (col > 0)
{
shifted_row = current_row - 1;
shifted_col = current_col - 1;
if (significance_map[shifted_row][shifted_col] < QCCTCE_S)
significance_map[shifted_row][shifted_col] = QCCTCE_NZN_NEW;
}
if (col < subband_num_col - 1)
{
shifted_row = current_row - 1;
shifted_col = current_col + 1;
if (significance_map[shifted_row][shifted_col] < QCCTCE_S)
significance_map[shifted_row][shifted_col] = QCCTCE_NZN_NEW;
}
}
if (row < subband_num_row - 1)
{
shifted_row = current_row + 1;
shifted_col = current_col;
if (significance_map[shifted_row][shifted_col] < QCCTCE_S)
significance_map[shifted_row][shifted_col] = QCCTCE_NZN_NEW;
if (col > 0)
{
shifted_row = current_row + 1;
shifted_col = current_col - 1;
if (significance_map[shifted_row][shifted_col] < QCCTCE_S)
significance_map[shifted_row][shifted_col] = QCCTCE_NZN_NEW;
}
if (col < subband_num_col - 1)
{
shifted_row = current_row + 1;
shifted_col = current_col + 1;
if (significance_map[shifted_row][shifted_col] < QCCTCE_S)
significance_map[shifted_row][shifted_col] = QCCTCE_NZN_NEW;
}
}
if (col > 0)
{
shifted_row = current_row;
shifted_col = current_col - 1;
if (significance_map[shifted_row][shifted_col] < QCCTCE_S)
significance_map[shifted_row][shifted_col] = QCCTCE_NZN_NEW;
}
if (col < subband_num_col - 1)
{
shifted_row = current_row;
shifted_col = current_col + 1;
if (significance_map[shifted_row][shifted_col] < QCCTCE_S)
significance_map[shifted_row][shifted_col] = QCCTCE_NZN_NEW;
}
return(0);
}
static int QccWAVtceIPBand(QccWAVSubbandPyramid *coefficients,
char **significance_map,
char **sign_array,
double **p_estimation,
double *subband_significance,
int subband,
double threshold,
QccENTArithmeticModel *model,
QccBitBuffer *buffer)
{
int return_value;
int subband_origin_row;
int subband_origin_col;
int subband_num_rows;
int subband_num_cols;
int row, col;
int current_row, current_col;
double p1;
double p3;
double p;
double p_forward;
double p_parent;
QccVector p2 = NULL;
int parent_subband;
double scale;
double parent_density;
double child_density;
int v;
int symbol;
double p_lowerbound = 0;
double weight[2];
double filter_coef;
double increment;
char *p_char;
double alpha_v, alpha_h;
if (subband % 3==1)
{
//LH horizental more important
alpha_h = QCCWAVTCE_ALPHA_HIGH;
alpha_v = QCCWAVTCE_ALPHA_LOW;
}
else
{
if (subband % 3==2)
{
alpha_h = QCCWAVTCE_ALPHA_LOW;
alpha_v = QCCWAVTCE_ALPHA_HIGH;
}
else
{
alpha_h = QCCWAVTCE_ALPHA;
alpha_v = QCCWAVTCE_ALPHA;
}
}
// initialization all the constants
filter_coef = (1 - alpha_h)*(1 - alpha_v) / (2*alpha_h + 2*alpha_v);
weight[0] = (1 - alpha_h) * (1 - alpha_v)/((1 + alpha_h)*(1 + alpha_v));
weight[1] = (2*alpha_h + 2*alpha_v) / ((1 + alpha_h)*(1 + alpha_v));
if (QccWAVSubbandPyramidSubbandSize(coefficients,
subband,
&subband_num_rows,
&subband_num_cols))
{
QccErrorAddMessage("(QccWAVtceIPBand): Error calling QccWAVSubbandPyramidSubbandSize()");
goto Error;
}
if (QccWAVSubbandPyramidSubbandOffsets(coefficients,
subband,
&subband_origin_row,
&subband_origin_col))
{
QccErrorAddMessage("(QccWAVtceIPBand): Error calling QccWAVSubbandPyramidSubbandOffsets()");
goto Error;
}
if ((p2 = QccVectorAlloc(subband_num_cols)) == NULL)
{
QccErrorAddMessage("(QccWAVtceIPBand): Error calling QccVectorAlloc()");
goto Error;
}
child_density =
subband_significance[subband] / (subband_num_rows * subband_num_cols);
p_lowerbound = 1.0 / (subband_num_rows * subband_num_cols);
if (subband <= 3)
{
parent_subband = 0;
parent_density =
subband_significance[0] / (subband_num_rows * subband_num_cols);
}
else
{
parent_subband = subband - 3;
parent_density =
subband_significance[parent_subband] /
(subband_num_rows * subband_num_cols) * 4;
}
for (col = 0; col < subband_num_cols; col++)
p2[col] = p_estimation[subband_origin_row][subband_origin_col + col] *
2 * (1 + alpha_h) / (2*alpha_v + 2*alpha_h);
scale =
QccMathMax(child_density, p_lowerbound) /
QccMathMax(parent_density, p_lowerbound);
increment =
1.0 / (subband_num_rows * subband_num_cols) /
QccMathMax(parent_density, p_lowerbound);
for (row = 0; row < subband_num_rows; row++)
{
p1 = p2[0]*(1 - alpha_v)/(1 + alpha_h);
current_row = subband_origin_row + row;
for (col = 0; col < subband_num_cols; col++)
{
current_col = subband_origin_col + col;
p_char = &(significance_map[current_row][current_col]);
p_forward = alpha_h*p1 + alpha_v*p2[col];
if (*p_char < QCCTCE_S)
{
p = p_forward + p_estimation[current_row][current_col];
if (subband != 0)
{
if (subband <= 3)
p_parent = p_estimation[row][col];
else
p_parent = p_estimation[current_row/2][current_col/2];
if (p < QCCWAVTCE_PREDICT_THRESHOLD)
{
p_parent = QccMathMin(p_parent*scale, 0.8);
p =
p * QCCWAVTCE_CURRENT_SCALE +
QCCWAVTCE_PARENT_SCALE * p_parent;
}
}
if (QccWAVtceUpdateModel(model, p))
{
QccErrorAddMessage("(QccWAVtceIPBand): Error calling QccWAVtceUpdateModel()");
return_value = 1;
goto Error;
}
if (buffer->type == QCCBITBUFFER_OUTPUT)
{
if (coefficients->matrix[current_row][current_col] >=
threshold)
{
symbol = 1;
coefficients->matrix[current_row][current_col] -=
threshold;
}
else
symbol = 0;
return_value =
QccENTArithmeticEncode(&symbol, 1,model, buffer);
}
else
{
if (QccENTArithmeticDecode(buffer,model,&symbol, 1))
{
return_value = 2;
goto Return;
}
else
return_value = 0;
if (symbol)
coefficients->matrix[current_row][current_col] =
1.5 * threshold;
}
v = symbol;
if (symbol)
{
subband_significance[subband]++;
scale += increment;
*p_char = QCCTCE_S_NEW;
if (QccWAVtceUpdateModel(model, 0.5))
{
QccErrorAddMessage("(QccWAVtceIPBand): Error calling QccWAVtceUpdateModel()");
goto Error;
}
if (buffer->type == QCCBITBUFFER_OUTPUT)
{
symbol = (int)(sign_array[current_row][current_col]);
return_value =
QccENTArithmeticEncode(&symbol, 1,model, buffer);
}
else
{
if (QccENTArithmeticDecode(buffer,model,&symbol, 1))
return_value = 2;
sign_array[current_row][current_col] = (char)symbol;
}
QccWAVUpdateNZNStatus(subband_origin_row,
subband_origin_col,
subband_num_rows,
subband_num_cols,
row,
col,
significance_map,
subband);
}
if (return_value == 2)
goto Return;
else
{
if (return_value)
{
QccErrorAddMessage("(QccWAVtceIPBand): QccWAVtceIPBand()");
goto Error;
}
}
p1 = alpha_h * p1 + filter_coef * v;
p2[col] = p1 + alpha_v * p2[col];
}
else
{
p1 = alpha_h * p1 + filter_coef * QCCWAVTCE_REFINE_HOLDER;
p2[col] = p1 + alpha_v * p2[col];
}
p_estimation[subband_origin_row + row][subband_origin_col + col] =
p_forward;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -