📄 spiht.c
字号:
} else sign_array[row][col] = 0; if (coefficient_magnitude > max_coefficient) max_coefficient = coefficient_magnitude; } else 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])) { coefficient_magnitude = fabs(image_subband_pyramid->matrix[row][col]); if (image_subband_pyramid->matrix[row][col] != coefficient_magnitude) { image_subband_pyramid->matrix[row][col] = coefficient_magnitude; sign_array[row][col] = 1; } else sign_array[row][col] = 0; if (coefficient_magnitude > max_coefficient) max_coefficient = coefficient_magnitude; } *max_coefficient_bits = (int)floor(QccMathLog2(max_coefficient)); return(0);}static int QccSPIHTDecodeApplySigns(QccWAVSubbandPyramid *image_subband_pyramid, QccWAVSubbandPyramid *mask_subband_pyramid, int **sign_array){ int row, col; 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 (sign_array[row][col]) image_subband_pyramid->matrix[row][col] *= -1; } else 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])) && sign_array[row][col]) image_subband_pyramid->matrix[row][col] *= -1; return(0);}static int QccSPIHTEncodeDWT(QccWAVSubbandPyramid *image_subband_pyramid, double *image_mean, const QccIMGImageComponent *image, int num_levels, QccWAVSubbandPyramid *mask_subband_pyramid, const QccIMGImageComponent *mask, const QccWAVWavelet *wavelet, const QccWAVPerceptualWeights *perceptual_weights){ int row, col; if (mask == NULL) { if (QccMatrixCopy(image_subband_pyramid->matrix, image->image, image->num_rows, image->num_cols)) { QccErrorAddMessage("(QccSPIHTEncodeDWT): Error calling QccMatrixCopy()"); return(1); } if (QccWAVSubbandPyramidSubtractMean(image_subband_pyramid, image_mean, NULL)) { QccErrorAddMessage("(QccSPIHTEncodeDWT): Error calling QccWAVSubbandPyramidSubtractMean()"); return(1); } } else { if (QccMatrixCopy(mask_subband_pyramid->matrix, mask->image, mask->num_rows, mask->num_cols)) { QccErrorAddMessage("(QccSPIHTEncodeDWT): Error calling QccMatrixCopy()"); return(1); } *image_mean = QccIMGImageComponentShapeAdaptiveMean(image, mask); 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; else image_subband_pyramid->matrix[row][col] = image->image[row][col] - *image_mean; } if (mask != NULL) { if (QccWAVSubbandPyramidShapeAdaptiveDWT(image_subband_pyramid, mask_subband_pyramid, num_levels, wavelet)) { QccErrorAddMessage("(QccSPIHTEncodeDWT): Error calling QccWAVSubbandPyramidShapeAdaptiveDWT()"); return(1); } } else if (QccWAVSubbandPyramidDWT(image_subband_pyramid, num_levels, wavelet)) { QccErrorAddMessage("(QccSPIHTEncodeDWT): Error calling QccWAVSubbandPyramidDWT()"); return(1); } if (perceptual_weights != NULL) if (QccWAVPerceptualWeightsApply(image_subband_pyramid, perceptual_weights)) { QccErrorAddMessage("(QccSPIHTEncodeDWT): Error calling QccWAVPerceptualWeightsApply()"); return(1); } return(0);}static int QccSPIHTDecodeInverseDWT(QccWAVSubbandPyramid *image_subband_pyramid, QccWAVSubbandPyramid *mask_subband_pyramid, QccIMGImageComponent *image, double image_mean, const QccWAVWavelet *wavelet, const QccWAVPerceptualWeights *perceptual_weights){ int row, col; if (perceptual_weights != NULL) if (QccWAVPerceptualWeightsRemove(image_subband_pyramid, perceptual_weights)) { QccErrorAddMessage("(QccSPIHTDecodeInverseDWT): Error calling QccWAVPerceptualWeightsRemove()"); return(1); } if (mask_subband_pyramid != NULL) { if (QccWAVSubbandPyramidInverseShapeAdaptiveDWT(image_subband_pyramid, mask_subband_pyramid, wavelet)) { QccErrorAddMessage("(QccSPIHTDecodeInverseDWT): Error calling QccWAVSubbandPyramidInverseShapeAdaptiveDWT()"); return(1); } } else if (QccWAVSubbandPyramidInverseDWT(image_subband_pyramid, wavelet)) { QccErrorAddMessage("(QccSPIHTDecodeInverseDWT): Error calling QccWAVSubbandPyramidInverseDWT()"); return(1); } if (QccWAVSubbandPyramidAddMean(image_subband_pyramid, image_mean)) { QccErrorAddMessage("(QccSPIHTDecodeInverseDWT): 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("(QccSPIHTDecodeInverseDWT): Error calling QccMatrixCopy()"); return(1); } if (QccIMGImageComponentSetMaxMin(image)) { QccErrorAddMessage("(QccSPIHTDecodeInverseDWT): Error calling QccIMGImageComponentSetMaxMin()"); return(1); } return(0);}static int QccSPIHTGetOffspring(QccWAVSubbandPyramid *subband_pyramid, int row, int col, int *offspring_row, int *offspring_col, int block_size){ int baseband_num_rows; int baseband_num_cols; int num_offspring; if (!subband_pyramid->num_levels) return(0); if ((2*row >= subband_pyramid->num_rows) || (2*col >= subband_pyramid->num_cols)) return(0); QccWAVSubbandPyramidSubbandSize(subband_pyramid, 0, &baseband_num_rows, &baseband_num_cols); if ((row < baseband_num_rows) && (col < baseband_num_cols)) { num_offspring = 3; offspring_row[0] = row; offspring_col[0] = col + baseband_num_cols; offspring_row[1] = row + baseband_num_rows; offspring_col[1] = col; offspring_row[2] = row + baseband_num_rows; offspring_col[2] = col + baseband_num_cols; } else { num_offspring = 4; offspring_row[0] = row * 2; offspring_col[0] = col * 2; offspring_row[1] = row * 2 + block_size; offspring_col[1] = col * 2; offspring_row[2] = row * 2; offspring_col[2] = col * 2 + block_size; offspring_row[3] = row * 2 + block_size; offspring_col[3] = col * 2 + block_size; } return(num_offspring);}static int QccSPIHTDescendantsOutsideMask(QccWAVSubbandPyramid *subband_pyramid, QccWAVSubbandPyramid *mask, int row, int col, int block_size);static int QccSPIHTOutsideMask(QccWAVSubbandPyramid *subband_pyramid, QccWAVSubbandPyramid *mask, int row, int col, int block_size){ int block_row, block_col; if (mask == NULL) return(0); for (block_row = 0; block_row < block_size; block_row++) for (block_col = 0; block_col < block_size; block_col++) if (!QccAlphaTransparent(mask->matrix [row + block_row][col + block_col])) return(0); if (!QccSPIHTDescendantsOutsideMask(subband_pyramid, mask, row, col, block_size)) return(0); return(1);}static int QccSPIHTDescendantsOutsideMask(QccWAVSubbandPyramid *subband_pyramid, QccWAVSubbandPyramid *mask, int row, int col, int block_size){ int offspring_row[4]; int offspring_col[4]; int num_offspring; int offspring; if (mask == NULL) return(0); num_offspring = QccSPIHTGetOffspring(subband_pyramid, row, col, offspring_row, offspring_col, block_size); if (!num_offspring) return(1); for (offspring = 0; offspring < num_offspring; offspring++) if (!QccSPIHTOutsideMask(subband_pyramid, mask, offspring_row[offspring], offspring_col[offspring], block_size)) return(0); return(1);}static int QccSPIHTAlgorithmInitialize(QccWAVSubbandPyramid *subband_pyramid, QccWAVSubbandPyramid *mask, QccList *LIP, QccList *LIS, int block_size){ int subband_num_rows, subband_num_cols; int row, col; QccSPIHTCoefficientBlock coefficient_block; QccListNode *new_node; if (QccWAVSubbandPyramidSubbandSize(subband_pyramid, 0, &subband_num_rows, &subband_num_cols)) { QccErrorAddMessage("(QccSPIHTAlgorithmInitialize): Error calling QccWAVSubbandPyramidSubbandSize()"); return(1); } for (row = 0; row < subband_num_rows; row += block_size) for (col = 0; col < subband_num_cols; col += block_size) if (!QccSPIHTOutsideMask(subband_pyramid, mask, row, col, block_size)) { coefficient_block.row = row; coefficient_block.col = col; coefficient_block.type = QCCSPIHT_TYPE_A; coefficient_block.state = 0; if ((new_node = QccListCreateNode(sizeof(QccSPIHTCoefficientBlock), (void *)(&coefficient_block))) == NULL) { QccErrorAddMessage("(QccSPIHTAlgorithmInitialize): Error calling QccListCreateNode()"); return(1); } if (QccListAppendNode(LIP, new_node)) { QccErrorAddMessage("(QccSPIHTAlgorithmInitialize): Error calling QccListAppendNode()"); return(1); } if ((new_node = QccListCreateNode(sizeof(QccSPIHTCoefficientBlock), (void *)(&coefficient_block))) == NULL) { QccErrorAddMessage("(QccSPIHTAlgorithmInitialize): Error calling QccListCreateNode()"); return(1); } if (QccListAppendNode(LIS, new_node)) { QccErrorAddMessage("(QccSPIHTAlgorithmInitialize): Error calling QccListAppendNode()"); return(1); } } return(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -