I have been developing my own compression algorithm for my school project.It is like LZ77 but uses fixed blocks,and a dictionary containing the position of the repeating block (dic.inpos)& where it is to be copied(dic.charpos);I am using Gnu C++,The program crashes or gets stuck on initializing in..
Also the program runs almost finely when run in debugger..
(but never completes decompression)
#include<iostream>
#include<fstream>
#include "cmpfmem.h"
struct dicv
{
unsigned long inpos;
unsigned long charpos;
};
int main()
{
unsigned short int blocksize;
unsigned long int dicsize;
char filename[512]="F:\\Mana.vpcf";
const unsigned long int ULfilesize=ffunc::getfilesize(filename);
unsigned char *in=NULL,*out=NULL;
dicv *dic=NULL;
std::ifstream ifile;
ifile.open(filename,std::ios::binary);
ifile.read((char*)&blocksize,sizeof blocksize);
ifile.read((char*)&dicsize,sizeof dicsize);
dic=new dicv [dicsize];
for(unsigned long i=0;i<=dicsize;++i)
{
ifile.read((char*)&dic[i],sizeof dic[i]);
}
unsigned long insize=ULfilesize-2-4-(8*dicsize);
in=new unsigned char[ULfilesize-2-4-(8*dicsize)];
for(unsigned long j=0;j<insize;++j)
{
ifile.read((char*)&in[j],sizeof in[j]);
}
out= new unsigned char[insize*blocksize];
unsigned long searchin=0;
unsigned long inpos=0,outpos=0;
for(;inpos<=insize;)
{
if(dic[searchin].inpos==inpos)
{
for(unsigned long k=0;k<blocksize;++k)
{
out[outpos++]=out[dic[searchin].charpos+k];
}
++inpos;
++searchin;
}
else
{
out[outpos++]=in[inpos++];
}
}
std::ofstream ofile;
ofile.open("F:\\Mana1.ucf",std::ios::binary);
for(unsigned long l=0;l<outpos;++l)
ofile.write((char*)&out[l],sizeof out[l]);
ofile.close();
ifile.close();
}