📄 bisk.c
字号:
if ((mask->num_rows != image->num_rows) || (mask->num_cols != image->num_cols)) { QccErrorAddMessage("(QccWAVbiskEncode): Mask and image must be same size"); goto Error; } mask_subband_pyramid.num_levels = 0; mask_subband_pyramid.num_rows = mask->num_rows; mask_subband_pyramid.num_cols = mask->num_cols; if (QccWAVSubbandPyramidAlloc(&mask_subband_pyramid)) { QccErrorAddMessage("(QccWAVbiskEncode): Error calling QccWAVSubbandPyramidAlloc()"); goto Error; } } if (QccWAVbiskEncodeDWT(&image_subband_pyramid, image, num_levels, &image_mean, &mask_subband_pyramid, mask, wavelet)) { QccErrorAddMessage("(QccWAVbiskEncode): Error calling QccWAVbiskEncodeDWT()"); goto Error; } if (QccWAVbiskEncode2(&image_subband_pyramid, (mask != NULL) ? &mask_subband_pyramid : NULL, image_mean, target_bit_cnt, output_buffer, rate_distortion_file)) { QccErrorAddMessage("(QccWAVbiskEncode): Error calling QccWAVbiskEncode2()"); goto Error; } return_value = 0; goto Return; Error: return_value = 1; Return: QccWAVSubbandPyramidFree(&image_subband_pyramid); QccWAVSubbandPyramidFree(&mask_subband_pyramid); return(return_value);}static int QccWAVbiskDecodeInverseDWT(QccWAVSubbandPyramid *image_subband_pyramid, QccWAVSubbandPyramid *mask_subband_pyramid, QccIMGImageComponent *image, double image_mean, const QccWAVWavelet *wavelet){ int row, col; if (mask_subband_pyramid != NULL) { if (QccWAVSubbandPyramidInverseShapeAdaptiveDWT(image_subband_pyramid, mask_subband_pyramid, wavelet)) { QccErrorAddMessage("(QccWAVbiskDecodeInverseDWT): Error calling QccWAVSubbandPyramidInverseShapeAdaptiveDWT()"); return(1); } } else if (QccWAVSubbandPyramidInverseDWT(image_subband_pyramid, wavelet)) { QccErrorAddMessage("(QccWAVbiskDecodeInverseDWT): Error calling QccWAVSubbandPyramidInverseDWT()"); return(1); } if (QccWAVSubbandPyramidAddMean(image_subband_pyramid, image_mean)) { QccErrorAddMessage("(QccWAVbiskDecodeInverseDWT): Error calling QccWAVSubbandPyramidAddMean()"); return(1); } if (mask_subband_pyramid != NULL) for (row = 0; row < image_subband_pyramid->num_rows; row++) for (col = 0; col < image_subband_pyramid->num_cols; col++) if (QccAlphaTransparent(mask_subband_pyramid->matrix[row][col])) image_subband_pyramid->matrix[row][col] = 0; if (QccMatrixCopy(image->image, image_subband_pyramid->matrix, image->num_rows, image->num_cols)) { QccErrorAddMessage("(QccWAVbiskDecodeInverseDWT): Error calling QccMatrixCopy()"); return(1); } return(0);}int QccWAVbiskDecodeHeader(QccBitBuffer *input_buffer, int *num_levels, int *num_rows, int *num_cols, double *image_mean, int *max_coefficient_bits){ int return_value; unsigned char ch; if (QccBitBufferGetChar(input_buffer, &ch)) { QccErrorAddMessage("(QccWAVbiskDecodeHeader): Error calling QccBitBufferPuChar()"); goto Error; } *num_levels = (int)ch; if (QccBitBufferGetInt(input_buffer, num_rows)) { QccErrorAddMessage("(QccWAVbiskDecodeHeader): Error calling QccBitBufferGetInt()"); goto Error; } if (QccBitBufferGetInt(input_buffer, num_cols)) { QccErrorAddMessage("(QccWAVbiskDecodeHeader): Error calling QccBitBufferGetInt()"); goto Error; } if (QccBitBufferGetDouble(input_buffer, image_mean)) { QccErrorAddMessage("(QccWAVbiskDecodeHeader): Error calling QccBitBufferGetDouble()"); goto Error; } if (QccBitBufferGetInt(input_buffer, max_coefficient_bits)) { QccErrorAddMessage("(QccWAVbiskDecodeHeader): Error calling QccBitBufferGetInt()"); goto Error; } return_value = 0; goto Return; Error: return_value = 1; Return: return(return_value);}int QccWAVbiskDecode2(QccBitBuffer *input_buffer, QccWAVSubbandPyramid *image_subband_pyramid, QccWAVSubbandPyramid *mask_subband_pyramid, int max_coefficient_bits, int target_bit_cnt){ int return_value; QccENTArithmeticModel *model = NULL; char **sign_array = NULL; double threshold; int row, col; QccList LIS; QccList LSP; if (image_subband_pyramid == NULL) return(0); if (input_buffer == NULL) return(0); QccListInitialize(&LIS); QccListInitialize(&LSP); if ((sign_array = (char **)malloc(sizeof(char *) * image_subband_pyramid->num_rows)) == NULL) { QccErrorAddMessage("(QccWAVbiskDecode2): Error allocating memory"); goto Error; } for (row = 0; row < image_subband_pyramid->num_rows; row++) if ((sign_array[row] = (char *)malloc(sizeof(char) * image_subband_pyramid->num_cols)) == NULL) { QccErrorAddMessage("(QccWAVbiskDecode2): Error allocating memory"); goto Error; } for (row = 0; row < image_subband_pyramid->num_rows; row++) for (col = 0; col < image_subband_pyramid->num_cols; col++) { image_subband_pyramid->matrix[row][col] = 0.0; sign_array[row][col] = QCCBISK_POSITIVE; } if ((model = QccENTArithmeticDecodeStart(input_buffer, QccWAVbiskNumSymbols, QCCBISK_NUM_CONTEXTS, NULL, target_bit_cnt)) == NULL) { QccErrorAddMessage("(QccWAVbiskDecode2): Error calling QccENTArithmeticDecodeStart()"); goto Error; } threshold = pow((double)2, (double)max_coefficient_bits); if (QccWAVbiskInitialization(&LIS, &LSP, image_subband_pyramid, mask_subband_pyramid)) { QccErrorAddMessage("(QccWAVbiskDecode2): Error calling QccWAVbiskInitialization()"); goto Error; } while (1) { return_value = QccWAVbiskSortingPass(image_subband_pyramid, mask_subband_pyramid, NULL, sign_array, threshold, &LIS, &LSP, model, input_buffer, NULL); if (return_value == 1) { QccErrorAddMessage("(QccWAVbiskDecode2): Error calling QccWAVbiskSortingPass()"); goto Error; } else if (return_value == 2) goto Finished; return_value = QccWAVbiskRefinementPass(image_subband_pyramid, &LSP, threshold, model, input_buffer, NULL); if (return_value == 1) { QccErrorAddMessage("(QccWAVbiskDecode2): Error calling QccWAVbiskRefinementPass()"); goto Error; } else if (return_value == 2) goto Finished; threshold /= 2.0; } Finished: if (QccWAVbiskDecodeApplySigns(image_subband_pyramid, mask_subband_pyramid, sign_array)) { QccErrorAddMessage("(QccWAVbiskDecode2): Error calling QccWAVbiskApplySigns()"); goto Error; } return_value = 0; QccErrorClearMessages(); goto Return; Error: return_value = 1; Return: if (sign_array != NULL) { for (row = 0; row < image_subband_pyramid->num_rows; row++) if (sign_array[row] != NULL) QccFree(sign_array[row]); QccFree(sign_array); } QccENTArithmeticFreeModel(model); QccWAVbiskFreeLIS(&LIS); QccListFree(&LSP); return(return_value);}int QccWAVbiskDecode(QccBitBuffer *input_buffer, QccIMGImageComponent *image, const QccIMGImageComponent *mask, int num_levels, const QccWAVWavelet *wavelet, double image_mean, int max_coefficient_bits, int target_bit_cnt){ int return_value; QccWAVSubbandPyramid image_subband_pyramid; QccWAVSubbandPyramid mask_subband_pyramid; QccWAVWavelet lazy_wavelet_transform; if (image == NULL) return(0); if (input_buffer == NULL) return(0); if (wavelet == NULL) return(0); QccWAVSubbandPyramidInitialize(&image_subband_pyramid); QccWAVSubbandPyramidInitialize(&mask_subband_pyramid); QccWAVWaveletInitialize(&lazy_wavelet_transform); 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("(QccWAVbiskDecode): Error calling QccWAVSubbandPyramidAlloc()"); goto Error; } if (mask != NULL) { if ((mask->num_rows != image->num_rows) || (mask->num_cols != image->num_cols)) { QccErrorAddMessage("(QccWAVbiskDecode): Mask and image must be same size"); goto Error; } if (QccWAVWaveletCreate(&lazy_wavelet_transform, "LWT.lft", "symmetric")) { QccErrorAddMessage("(QccWAVbiskDecode): Error calling QccWAVWaveletCreate()"); goto Error; } mask_subband_pyramid.num_levels = 0; mask_subband_pyramid.num_rows = mask->num_rows; mask_subband_pyramid.num_cols = mask->num_cols; if (QccWAVSubbandPyramidAlloc(&mask_subband_pyramid)) { QccErrorAddMessage("(QccWAVbiskDecode): Error calling QccWAVSubbandPyramidAlloc()"); goto Error; } if (QccMatrixCopy(mask_subband_pyramid.matrix, mask->image, mask->num_rows, mask->num_cols)) { QccErrorAddMessage("(QccWAVbiskDecode): Error calling QccMatrixCopy()"); goto Error; } if (QccWAVSubbandPyramidDWT(((mask != NULL) ? &mask_subband_pyramid : NULL), num_levels, &lazy_wavelet_transform)) { QccErrorAddMessage("(QccWAVbiskDecode): Error calling QccWAVSubbandPyramidDWT()"); goto Error; } } if (QccWAVbiskDecode2(input_buffer, &image_subband_pyramid, (mask != NULL) ? &mask_subband_pyramid : NULL, max_coefficient_bits, target_bit_cnt)) { QccErrorAddMessage("(QccWAVbiskDecode): Error calling QccWAVbiskDecode2()"); goto Error; } if (QccWAVbiskDecodeInverseDWT(&image_subband_pyramid, ((mask != NULL) ? &mask_subband_pyramid : NULL), image, image_mean, wavelet)) { QccErrorAddMessage("(QccWAVbiskDecode): Error calling QccWAVbiskDecodeInverseDWT()"); goto Error; } return_value = 0; QccErrorClearMessages(); goto Return; Error: return_value = 1; Return: QccWAVSubbandPyramidFree(&image_subband_pyramid); QccWAVSubbandPyramidFree(&mask_subband_pyramid); QccWAVWaveletFree(&lazy_wavelet_transform); return(return_value);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -