예제 #1
0
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;
}
예제 #2
0
void imgCompressor::compresse()//图片压缩
{
    ofstream img_com("/home/cxy229/image/img_compressed",ios::app);
    if(!img_com)
    {
        cout<<" fail to open img_compressed"<<endl;
        exit(1);
    }

    ifstream image;
    image.open("/home/cxy229/image/data.dat",ios::in);
    if(!image.good())    //文件未成功打开
    {
        cerr<<" error:: unable to open image! "<<endl;
        exit(1);
    }

    char temp[65];
    string str = "";
    int k = 0;
    while(!image.eof())
    {
        image.getline(temp,65);
        for(k = 0; k < 64; k += 8)
        {
            str = swich(temp + k, 8);
            img_com<<h_tree.coding(str);//将压缩后的编码写入文件
        }
        img_com<<endl;
    }

    image.close();
    img_com.close();
}