admin管理员组文章数量:1532330
2023年12月22日发(作者:)
printf(i%8==7 ? "%02X/n " : "%02X ", pixel[i]);
}
printf("/n◎压缩数据(%d字节):/n ", code_size);
for (i=0; i printf(i%8==7 ? "%02X/n " : "%02X ", hfcode[i]); } //打印码表 printf("/n/n◎码表-编码字典(%d项)/n", data_num); for (i=0; i<256; i++) { if (code_table[i].codelength) { printf("%3d|%02X: ", i, i); for (j=0; j printf("%d", ((code_table[i].code << j)&0x80)>>7); } printf("/t"); } } printf("/n/n◎压缩率:%2.0f%% /t压缩时间:%.3f毫秒/n",(float)code_size/DNUM * 100, 1E3*(time2-time1)/LOOP); }void BitPrint(unsigned char *hfcode) { int i, j; int endbit = last_bit; unsigned char thebyte; for (i=0; i < code_size-1; i++) { thebyte = hfcode[i]; for (j=0; j<8; j++) { printf("%d", ((thebyte< } } if (last_bit == 7) { endbit = -1; } thebyte = hfcode[i]; for (j=7; j>endbit; j--) { printf("%d", ((thebyte<<(7-j))&0x80)>>7); } } void HuffmanCompress(unsigned char *pixel, unsigned char *hfcode, HuffCode * code_table) { int i, j; int curbit=7; //current bit in _thebyte_ unsigned int bytenum=0; //number of destination code can also be position of byte processed in destination unsigned int ptbyte=0; //position of byte processed in destination unsigned int curlength; //code's length of _curcode_ unsigned char curcode; //current byte's huffman code unsigned char thebyte=0; //destination byte write unsigned char value; //current byte's value (pixel[]) //process every byte for (i=0; i value = pixel[i]; curcode = (code_table[value]).code; curlength = (code_table[value]).codelength; //move out every bit from curcode to destination for (j=0;j<=curlength;j++) { if ((curcode< thebyte |= (unsigned char)(0x01< } curbit --; if (curbit < 0) { hfcode[ptbyte++] = thebyte; thebyte = 0; curbit = 7; bytenum ++; } } } //think about which bit is the end if (curbit != 7) { hfcode[ptbyte] = thebyte; bytenum ++; } code_size = bytenum; last_bit = curbit; } void HuffSelect(HuffNode *hfdata, int end, int *min1, int *min2) { int i; //variable for loop int s1, s2; HuffNode wath[30]; for (i=0; i<30; i++) { wath[i] = hfdata[i]; } s1 = s2 = 1; while (hfdata[s1].parent) { s1++; } for (i=2; i<=end; i++) { if (hfdata[i].parent == 0 && hfdata[i].weight < hfdata[s1].weight) { s1 = i; } } while (hfdata[s2].parent || s1 == s2) { s2++; } for (i=1; i<=end; i++) { if (hfdata[i].parent ==0 && hfdata[i].weight < hfdata[s2].weight && (i - s1)) { s2 = i; } } *min1 = s1; *min2 = s2; }void FrequencyCount(unsigned char *chs) { int i; for (i=0; i fCount[*(chs+i)] ++; } }
版权声明:本文标题:用C语言编写程序实现Zip或者Rar无损压缩算法 内容由热心网友自发贡献,该文观点仅代表作者本人,
转载请联系作者并注明出处:https://m.elefans.com/dongtai/1703207028a44065.html,
本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论