📄 dcttce.c
字号:
coefficients->matrix[current_row][current_col] = 1.5 * threshold; } p = p * QCCWAVTCE_ALPHA_1D + symbol * QCCWAVTCE_ALPHA_1D_O; if (symbol) { subband_significance[subband]++; significance_map[current_row][current_col] = QCCWAVDCTTCE_S_NEW; if (QccWAVdcttceUpdateModel(model, 0.5)) { QccErrorAddMessage("(QccWAVdcttceNZNPass): Error calling QccWAVdcttceUpdateModel()"); return(1); } if (buffer->type == QCCBITBUFFER_OUTPUT) { symbol = (int)(sign_array[current_row][current_col]); return_value = QccENTArithmeticEncode(&symbol, 1, model, buffer); if (return_value == 1) return(1); else { if (return_value == 2) return(2); } } else { if (QccENTArithmeticDecode(buffer, model, &symbol, 1)) return(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); } } } } } } return(0);}int static QccWAVdcttceSPass(QccWAVSubbandPyramid *coefficients, char **significance_map, double threshold, QccENTArithmeticModel *model, QccBitBuffer *buffer, int *max_coefficient_bits){ int return_value; int subband; int num_subbands; int subband_origin_row; int subband_origin_col; int subband_num_rows; int subband_num_cols; int row, col; int current_row, current_col; char *p_char; int symbol; double p = 0.4; num_subbands = QccWAVSubbandPyramidNumLevelsToNumSubbands(coefficients->num_levels); for (subband = 0; subband < num_subbands; subband++) { if ((threshold - 0.000001) < pow((double)2, (double)(max_coefficient_bits[subband]))) { if (QccWAVSubbandPyramidSubbandSize(coefficients, subband, &subband_num_rows, &subband_num_cols)) { QccErrorAddMessage("(QccWAVdcttceSPass): Error calling QccWAVSubbandPyramidSubbandSize()"); return(1); } if (QccWAVSubbandPyramidSubbandOffsets(coefficients, subband, &subband_origin_row, &subband_origin_col)) { QccErrorAddMessage("(QccWAVdcttceSPass): Error calling QccWAVSubbandPyramidSubbandOffsets()"); return(1); } for (row = 0; row < subband_num_rows; row++) { 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]); if (*p_char == QCCWAVDCTTCE_S) { if (QccWAVdcttceUpdateModel(model, p)) { QccErrorAddMessage("(QccWAVdcttceSPass): Error calling QccWAVdcttceUpdateModel()"); return(1); } 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); if (return_value == 1) return(1); else { if (return_value == 2) return(2); } } else { if (QccENTArithmeticDecode(buffer,model,&symbol, 1)) return(2); coefficients->matrix[current_row][current_col] += (symbol == 1) ? threshold / 2 : -threshold / 2; } p = p * QCCWAVTCE_ALPHA_1D + symbol * QCCWAVTCE_ALPHA_1D_O; } else { if (*p_char == QCCWAVDCTTCE_S_NEW) *p_char = QCCWAVDCTTCE_S; if (*p_char == QCCWAVDCTTCE_NZN_NEW) *p_char = QCCWAVDCTTCE_NZN; } } } } } return(0);}int QccWAVdcttceEncode(const QccIMGImageComponent *image, int num_levels, int target_bit_cnt, double stepsize, int overlap_sample, double smooth_factor, QccBitBuffer *output_buffer){ int return_value; QccENTArithmeticModel *model = NULL; QccWAVSubbandPyramid image_subband_pyramid; char **sign_array = NULL; char **significance_map = NULL; double **p_estimation = NULL; double *subband_significance = NULL; int *max_coefficient_bits = NULL; double image_mean; double threshold; int num_symbols[1] = { 2 }; int row, col; int num_subbands; int bitplane_cnt = 1; int block_size; QccWAVSubbandPyramidInitialize(&image_subband_pyramid); if (image == NULL) return(0); if (output_buffer == NULL) return(0); block_size = (1 << num_levels); if ((image->num_rows % block_size) || (image->num_cols % block_size)) { QccErrorAddMessage("(QccWAVdcttceEncode): Image size (%d x %d) is not an integer multiple of block size %d", image->num_cols, image->num_rows, block_size); goto Error; } if ((target_bit_cnt == QCCENT_ANYNUMBITS) && (stepsize <= 0)) { QccErrorAddMessage("(QccWAVdcttceEncode): Either a target bit cnt or a quantization stepsize must be specified"); goto Error; } if ((sign_array = (char **)malloc(sizeof(char *) * image->num_rows)) == NULL) { QccErrorAddMessage("(QccWAVdcttceEncode): Error allocating memory"); goto Error; } for (row = 0; row < image->num_rows; row++) if ((sign_array[row] = (char *)malloc(sizeof(char) * image->num_cols)) == NULL) { QccErrorAddMessage("(QccWAVdcttceEncode): Error allocating memory"); goto Error; } if ((significance_map = (char **)malloc(sizeof(char *) * image->num_rows)) == NULL) { QccErrorAddMessage("(QccWAVdcttceEncode): Error allocating memory"); goto Error; } for (row = 0; row < image->num_rows; row++) if ((significance_map[row] = (char *)malloc(sizeof(char) * image->num_cols)) == NULL) { QccErrorAddMessage("(QccWAVdcttceEncode): Error allocating memory"); goto Error; } for (row = 0; row < image->num_rows; row++) for (col = 0; col < image->num_cols; col++) significance_map[row][col] = QCCWAVDCTTCE_Z; num_subbands = QccWAVSubbandPyramidNumLevelsToNumSubbands(num_levels); if ((max_coefficient_bits = (int *)malloc(sizeof(int) * num_subbands)) == NULL) { QccErrorAddMessage("(QccWAVdcttceEncode): Error allocating memory"); goto Error; } if ((p_estimation = (double **)malloc(sizeof(double *) * image->num_rows)) == NULL) { QccErrorAddMessage("(QccWAVdcttceEncode): Error allocating memory"); goto Error; } for (row = 0; row < image->num_rows; row++) if ((p_estimation[row] = (double *)malloc(sizeof(double) * image->num_cols)) == NULL) { QccErrorAddMessage("(QccWAVdcttceEncode): Error allocating memory"); goto Error; } for (row = 0; row < image->num_rows; row++) for (col = 0; col < image->num_cols; col++) p_estimation[row][col] = 0.0000001; if ((subband_significance = (double*)calloc(num_subbands, sizeof(double))) == NULL) { QccErrorAddMessage("(QccWAVdcttceEncode): Error allocating memory"); goto Error; } image_subband_pyramid.num_levels = num_levels; image_subband_pyramid.num_rows = image->num_rows; image_subband_pyramid.num_cols = image->num_cols; if (QccWAVSubbandPyramidAlloc(&image_subband_pyramid)) { QccErrorAddMessage("(QccWAVdcttceEncode): Error calling QccWAVSubbandPyramidAlloc()"); goto Error; } //DCT transform and/or quantization if (QccWAVdcttceEncodeDCT(&image_subband_pyramid, sign_array, image, num_levels, &image_mean, max_coefficient_bits, stepsize, overlap_sample, smooth_factor)) { QccErrorAddMessage("(QccWAVdcttceEncode): Error calling QccWAVdcttceEncodeDWT()"); goto Error; } //encoder header information if (QccWAVdcttceEncodeHeader(output_buffer, num_levels, image->num_rows, image->num_cols, image_mean, stepsize, max_coefficient_bits[0], overlap_sample, smooth_factor)) { QccErrorAddMessage("(QccWAVdcttceEncode): Error calling QccWAVdcttceEncodeHeader()"); goto Error; } if (QccWAVdcttceEncodeBitPlaneInfo(output_buffer, num_subbands, max_coefficient_bits)) { QccErrorAddMessage("(QccWAVdcttceEncode): Error calling QccWAVdcttceEncodeBitPlaneInfo()"); goto Error; } if ((model = QccENTArithmeticEncodeStart(num_symbols, 1, NULL, target_bit_cnt)) == NULL) { QccErrorAddMessage("(QccWAVdcttceEncode): Error calling QccENTArithmeticEncodeStart()"); goto Error; } QccENTArithmeticSetModelAdaption(model, QCCENT_NONADAPTIVE); threshold = pow((double)2, (double)max_coefficient_bits[0]); if (stepsize <= 0) // totally embedding without quantization while (1) { return_value = QccWAVdcttceNZNPass(&image_subband_pyramid, significance_map, sign_array, threshold, p_estimation, subband_significance, model, output_buffer, max_coefficient_bits); if (return_value == 1) { QccErrorAddMessage("(QccWAVdcttceEncode): Error calling QccWAVdcttceNZNPass()"); goto Error; } else { if (return_value == 2) goto Finished; } return_value = QccWAVdcttceIPPass(&image_subband_pyramid, significance_map, sign_array, threshold, p_estimation, subband_significance, model, output_buffer,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -