int main() { ifstream image; image.open("/home/cxy229/image/data.dat"); if(!image.good()) //文件未成功打开 { cerr<<" error:: unable to open image! "<<endl; exit(1); } char aaaa[4]={'a','b','c','d'}; int w[4]={5,6,7,8}; HuffmanTree<char> test; test.setTree(w,aaaa,4,0); test.encode(test.getroot(),""); cout<<"d:"<<test.coding('d')<<endl; cout<<"c:"<<test.coding('c')<<endl; cout<<"b:"<<test.coding('b')<<endl; cout<<"a:"<<test.coding('a')<<endl; cout<<test.uncoding("010110"); cout<<endl; imgCompressor img; img.run(); return 0; }
int main(int argc, char* argv[]) { if (argc < 4) { cerr << "please provide an appropriate flag (-compress/-decompress) and two file names." << endl; return -1; } HuffmanTree tree; ifstream in(argv[2], ios::in | ios::binary); ofstream out(argv[3], ios::out | ios::binary); if (strcmp(argv[1], "-compress") == 0) { tree.encode(in, out); } else if (strcmp(argv[1], "-decompress") == 0) { tree.decode(in, out); } return 0; }
void imgCompressor::buildTree() { h_tree.setTree(wei,color,sum,""); h_tree.encode(h_tree.getroot(),""); }