voila donc je cherchais un programme permettant de compresser et decompresser un fichier texte, et image.
j'en ai trouver un, mais il est ecrit en c++, et je ne sait pas du tout le convertir en c tout court.
le voici donc, si quelqu'un pouvait m'aider ce serait simpa! :)
(un moyen de le traduire, ou un autre programme qui marche...)
merci d'avance!!
/*
Name : RLE
Author : Dauzat Lilian
Description : Compression / decompression suivant l'algorithme RLE
Date : 01/01/02
Copyright : Dauzat Lilian
Last update : 06/01/02
Email : obasileus@ifrance.com
*/
#include <stdio.h>
FILE *entre,*sortie;
unsigned char codeRepet=255,nbreRepet=1;
unsigned char AncCaract,caract,codeARepeter;
void compress(void);
void dcompress(void);
int main(int argc, char *argv[])
{
char option;
option = *argv[3];
entre = fopen(argv[1],"rb");
sortie = fopen(argv[2],"wb");
if (option == 'c') compress();
if (option == 'd') dcompress();
fclose(entre);
fclose(sortie);
return 0;
}
void compress(void)
{
fread(&AncCaract,sizeof(char),1,entre);
while (!feof(entre))
{
fread(&caract,sizeof(char),1,entre);
if (caract==AncCaract)
{
if (nbreRepet==253)
{
fwrite(&codeRepet,sizeof(char),1,sortie);
fwrite(&nbreRepet,sizeof(char),1,sortie);
fwrite(&AncCaract,sizeof(char),1,sortie);
nbreRepet = 1;
}
else nbreRepet++;
}
else
{
if (nbreRepet>3)
{
fwrite(&codeRepet,sizeof(char),1,sortie);
fwrite(&nbreRepet,sizeof(char),1,sortie);
fwrite(&AncCaract,sizeof(char),1,sortie);
}
else
{
for (short i=0 ; i!=nbreRepet ; i++)
{
fwrite(&AncCaract,sizeof(char),1,sortie);
}
}
nbreRepet = 1;
AncCaract = caract;
}
}
printf("Compression acheve");
}
void dcompress()
{
while (!feof(entre))
{
fread(&caract,sizeof(char),1,entre);
if (caract == codeRepet)
{
fread(&nbreRepet,sizeof(char),1,entre);
fread(&codeARepeter,sizeof(char),1,entre);
for (short i=0 ; i != nbreRepet ; i++)
{
fwrite(&codeARepeter,sizeof(char),1,sortie);
}
}
else
{
fwrite(&caract,sizeof(char),1,sortie);
}
}
printf("Decompression acheve");
}