Próbuję zaimplementować kompresję delta dla dwóch bitmap. Wydaje mi się że z kompresją jest ok, lecz problem pojawia się przy dekompresji. Nie wiem w którym miejscu robię błąd.
void comp_DELTA (string input1, string input2, string output)
{
ifstream old0(input1);
ifstream current0(input2);
ofstream compress(output);
vector <char> old;
vector <char> current;
streampos length;
if (old0)
{
old0.seekg(0,ios::end);
length = old0.tellg();
old0.seekg(0,std::ios::beg);
old.resize(length);
old0.read(&old[0],length);
}
if (current0)
{
current0.seekg(0,ios::end);
length = current0.tellg();
current0.seekg(0,std::ios::beg);
current.resize(length);
current0.read(¤t[0],length);
}
compress<<input1<<endl;
compress<<input2<<endl;
int counter=0, pos_beg=0;
for(int i=0; i<length; i++)
{
if(old[i]==current[i])
{
if(counter==0)
{
counter++;
pos_beg=i;
}
else if(counter>0) counter++;
if(i+1==length)
{
compress<<"("<<pos_beg<<";"<<counter<<")";
break;
}
}
else if(old[i]!=current[i])
{
if(counter<6)
{
for(int j=0; j<counter; j++)
compress<<current[j+pos_beg];
counter=0;
pos_beg=0;
}
else if(counter>=6)
{
compress<<"("<<pos_beg<<";"<<counter<<")";
counter=0;
pos_beg=0;
}
}
}
}
void decomp_DELTA (string input_path)
{
ifstream input(input_path);
string old0, current0;
input>>old0;
input>>current0;
input.seekg(1, ios::cur);
ifstream old1(old0);
ofstream current1(current0);
vector <char> old;
int length;
if (old1)
{
old1.seekg(0,ios::end);
length = old1.tellg();
old1.seekg(0,std::ios::beg);
old.resize(length);
old1.read(&old[0],length);
}
input.seekg(1, ios::cur);
char znak1, znak2, znak3;
int start, amount, counter=0;
stringstream a,b;
while(counter<length)
{
znak1=input.get();
if(znak1=='(')
{
input>>start;
znak2=input.get();
input>>amount;
znak3=input.get();
if((znak2==';') && (znak3==')'))
for(int i=start; i<(start+amount); i++)
{
current1<<old[i];
counter++;
}
else
{
a<<start;
b<<amount;
int minus=input.tellg();
minus-=(2+a.str().length()+b.str().length());
input.seekg(minus,ios::beg);
current1<<znak1;
counter++;
}
}
else {current1<<znak1; counter++;}
}
}