Sorry if my question is not clear.I tried to use the library "lz.c" in my program.But it still doesn't work correctly.Anyone can help me??
Code:
#include "bitmap.h"
#include<stdio.h>
#include<iostream.h>
#include "lz.c"
int LZ_Compress( unsigned char *in, unsigned char *out,
unsigned int insize );
void LZ_Uncompress( unsigned char *in, unsigned char *out,
unsigned int insize );
int main()
{
unsigned char *out;
//load bitmap file
Fileheader bmfh;
Infoheader bmih;
RGBQUAD Palette[256];
unsigned char* Data;
FILE *f1;
FILE *f2;
f1=fopen("test.bmp","rb");
f2=fopen("LZ.77","wb");
fread(&bmfh,sizeof(Fileheader),1,f1);
fread(&bmih,sizeof(Infoheader),1,f1);
for(int i=0;i<256;i++)
{
fread(&Palette[i],sizeof(RGBQUAD),1,f1);
}
//read the actual bitmap data
fseek(f1,bmfh.OffBits,SEEK_SET);
long size=(((bmih.Width * (bmih.Bitperpixel / 8)) + 3) & (~3))*bmih.Height;
Data=new unsigned char[size];
fread((unsigned char*)Data,size,1,f1);
fwrite(&bmfh,sizeof(Fileheader),1,f2);
fwrite(&bmih,sizeof(Infoheader),1,f2);
for(i=0;i<256;i++)
{
fwrite(&Palette[i],sizeof(RGBQUAD),1,f2);
}
out=new unsigned char[size];
//pointer to output buffer
// begin LZ77 compression
int insize=4096;
int outsize=LZ_Compress(Data,out,insize);
fwrite(&out,outsize,1,f2);
fclose(f1);
fclose(f2);
}
Here is this guide to used the libray( file included "lz.c")
Syntax: outsize = LZ_Compress(in,out,insize)
outsize - Size of output buffer after compression
in - Pointer to the input buffer (uncompressed data)
out - Pointer to the output buffer (compressed data)
insize - Size of input buffer
The output buffer must be able to hold (insize*257/256 + 1) bytes.