📄 zerotree.c
字号:
return(0);}static int QccWAVZerotreeReadHeader(FILE *infile, QccWAVZerotree *zerotree){ if ((infile == NULL) || (zerotree == NULL)) return(0); if (QccFileReadMagicNumber(infile, zerotree->magic_num, &zerotree->major_version, &zerotree->minor_version)) { QccErrorAddMessage("(QccWAVZerotreeReadHeader): Error reading magic number in %s", zerotree->filename); return(1); } if (strcmp(zerotree->magic_num, QCCWAVZEROTREE_MAGICNUM)) { QccErrorAddMessage("(QccWAVZerotreeReadHeader): %s is not of zerotree (%s) type", zerotree->filename, QCCWAVZEROTREE_MAGICNUM); return(1); } fscanf(infile, "%d", &(zerotree->image_num_cols)); if (ferror(infile) || feof(infile)) { QccErrorAddMessage("(QccWAVZerotreeReadHeader): Error reading number of image columns in %s", zerotree->filename); return(1); } if (QccFileSkipWhiteSpace(infile, 0)) { QccErrorAddMessage("(QccWAVZerotreeReadHeader): Error reading number of image columns in %s", zerotree->filename); return(1); } fscanf(infile, "%d", &(zerotree->image_num_rows)); if (ferror(infile) || feof(infile)) { QccErrorAddMessage("(QccWAVZerotreeReadHeader): Error reading number of image rows in %s", zerotree->filename); return(1); } if (QccFileSkipWhiteSpace(infile, 0)) { QccErrorAddMessage("(QccWAVZerotreeReadHeader): Error reading number of image rows in %s", zerotree->filename); return(1); } fscanf(infile, "%lf", &(zerotree->image_mean)); if (ferror(infile) || feof(infile)) { QccErrorAddMessage("(QccWAVZerotreeReadHeader): Error reading image mean in %s", zerotree->filename); return(1); } if (QccFileSkipWhiteSpace(infile, 0)) { QccErrorAddMessage("(QccWAVZerotreeReadHeader): Error reading image mean in %s", zerotree->filename); return(1); } fscanf(infile, "%d", &(zerotree->num_levels)); if (ferror(infile) || feof(infile)) { QccErrorAddMessage("(QccWAVZerotreeReadHeader): Error reading number of levels in %s", zerotree->filename); return(1); } zerotree->num_subbands = QccWAVSubbandPyramidNumLevelsToNumSubbands(zerotree->num_levels); if (QccFileSkipWhiteSpace(infile, 0)) { QccErrorAddMessage("(QccWAVZerotreeReadHeader): Error reading number of subbands in %s", zerotree->filename); return(1); } fscanf(infile, "%d%*1[\n]", &(zerotree->alphabet_size)); if (ferror(infile) || feof(infile)) { QccErrorAddMessage("(QccWAVZerotreeReadHeader): Error reading alphabet size in %s", zerotree->filename); return(1); } return(0); }static int QccWAVZerotreeReadData(FILE *infile, QccWAVZerotree *zerotree){ int subband; int row, col; if (zerotree == NULL) return(0); if (QccWAVZerotreeAlloc(zerotree)) { QccErrorAddMessage("(QccWAVZerotreeReadData): Error calling QccWAVZerotreeAlloc()"); goto QccWAVZerotreeReadDataErr; } for (subband = 0; subband < zerotree->num_subbands; subband++) for (row = 0; row < zerotree->num_rows[subband]; row++) for (col = 0; col < zerotree->num_cols[subband]; col++) if (QccFileReadChar(infile, &(zerotree->zerotree[subband][row][col]))) { QccErrorAddMessage("(QccWAVZerotreeReadData): Error calling QccFileReadChar()"); goto QccWAVZerotreeReadDataErr; } return(0); QccWAVZerotreeReadDataErr: QccWAVZerotreeFree(zerotree); return(1);}int QccWAVZerotreeRead(QccWAVZerotree *zerotree){ FILE *infile = NULL; if (zerotree == NULL) return(0); if ((infile = QccFileOpen(zerotree->filename, "r")) == NULL) { QccErrorAddMessage("(QccWAVZerotreeRead): Error calling QccFileOpen()"); return(1); } if (QccWAVZerotreeReadHeader(infile, zerotree)) { QccErrorAddMessage("(QccWAVZerotreeRead): Error calling QccWAVZerotreeReadHeader()"); return(1); } if (QccWAVZerotreeReadData(infile, zerotree)) { QccErrorAddMessage("(QccWAVZerotreeRead): Error calling QccWAVZerotreeReadData()"); return(1); } QccFileClose(infile); return(0);}static int QccWAVZerotreeWriteHeader(FILE *outfile, const QccWAVZerotree *zerotree){ if ((outfile == NULL) || (zerotree == NULL)) return(0); if (QccFileWriteMagicNumber(outfile, QCCWAVZEROTREE_MAGICNUM)) goto QccErr; fprintf(outfile, "%d %d\n% 16.9e\n%d\n%d\n", zerotree->image_num_cols, zerotree->image_num_rows, zerotree->image_mean, zerotree->num_levels, QCCWAVZEROTREE_NUMSYMBOLS); if (ferror(outfile)) goto QccErr; return(0); QccErr: QccErrorAddMessage("(QccWAVZerotreeWriteHeader): Error writing header to %s", zerotree->filename); return(1);}static int QccWAVZerotreeWriteData(FILE *outfile, const QccWAVZerotree *zerotree){ int subband; int row, col; for (subband = 0; subband < zerotree->num_subbands; subband++) for (row = 0; row < zerotree->num_rows[subband]; row++) for (col = 0; col < zerotree->num_cols[subband]; col++) if (QccFileWriteChar(outfile, zerotree->zerotree[subband][row][col])) { QccErrorAddMessage("(QccWAVZerotreeWrite): Error calling QccFileWriteChar()"); return(1); } return(0);}int QccWAVZerotreeWrite(const QccWAVZerotree *zerotree){ FILE *outfile; if (zerotree == NULL) return(0); if ((outfile = QccFileOpen(zerotree->filename, "w")) == NULL) { QccErrorAddMessage("(QccWAVZerotreeWrite): Error calling QccFileOpen()"); return(1); } if (QccWAVZerotreeWriteHeader(outfile, zerotree)) { QccErrorAddMessage("(QccWAVZerotreeWrite): Error calling QccWAVZerotreeWriteHeader()"); return(1); } if (QccWAVZerotreeWriteData(outfile, zerotree)) { QccErrorAddMessage("(QccWAVZerotreeWrite): Error calling QccWAVZerotreeWriteData()"); return(1); } QccFileClose(outfile); return(0);}int QccWAVZerotreeCarveOutZerotree(QccWAVZerotree *zerotree, int subband, int row, int col){ int child_row, child_col; int num_children; int num_subbands; int child_subband; int child_subband_start, child_subband_end; num_subbands = zerotree->num_subbands; if (subband >= num_subbands) return(0); if (subband) child_subband_start = child_subband_end = subband + 3; else { child_subband_start = 1; child_subband_end = 3; } for (child_subband = child_subband_start; child_subband <= child_subband_end; child_subband++) if (child_subband < num_subbands) { num_children = (child_subband < 4) ? 1 : 2; for (child_row = num_children*row; child_row < num_children*(row + 1); child_row++) for (child_col = num_children*col; child_col < num_children*(col + 1); child_col++) { QccWAVZerotreeCarveOutZerotree(zerotree, child_subband, child_row, child_col); QccWAVZerotreeMakeSymbolNull(&(zerotree->zerotree [child_subband] [child_row][child_col])); } } return(0);}int QccWAVZerotreeUndoZerotree(QccWAVZerotree *zerotree, int subband, int row, int col){ int child_row, child_col; int num_children; int num_subbands; int child_subband; int child_subband_start, child_subband_end; num_subbands = zerotree->num_subbands; if (subband >= num_subbands) return(0); if (subband) child_subband_start = child_subband_end = subband + 3; else { child_subband_start = 1; child_subband_end = 3; } for (child_subband = child_subband_start; child_subband <= child_subband_end; child_subband++) if (child_subband < num_subbands) { num_children = (child_subband < 4) ? 1 : 2; for (child_row = num_children*row; child_row < num_children*(row + 1); child_row++) for (child_col = num_children*col; child_col < num_children*(col + 1); child_col++) { QccWAVZerotreeMakeSymbolNonnull(&(zerotree->zerotree [child_subband] [child_row][child_col])); QccWAVZerotreeUndoZerotree(zerotree, child_subband, child_row, child_col); } } return(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -