#include "stdio.h" #include "stdlib.h" /* Crappy little test program for testing RLE code Read 100x100 pixel greyscale images Write them as RLE Decompress them back to their originals */ int Nx = 100; int Ny = 100; int main(int argc,char **argv) { FILE *fptr,*fout; char foutname[128],finname[128]; unsigned char *inbuffer,*outbuffer; int len,i,j,c; signed char count; /* Open the input file */ if ((fptr = fopen(argv[1],"r")) == NULL) { fprintf(stderr,"Failed to read file\n"); exit(-1); } /* Open the output file */ sprintf(foutname,"%s.rle",argv[1]); if ((fout = fopen(foutname,"w")) == NULL) { fprintf(stderr,"Failed to open output file\n"); exit(-1); } /* Malloc space for the buffers */ if ((inbuffer = malloc(Nx*sizeof(unsigned char))) == NULL) { fprintf(stderr,"malloc failed for input buffer!\n"); exit(-1); } if ((outbuffer = malloc((Nx+1+Nx/128)*sizeof(unsigned char))) == NULL) { fprintf(stderr,"malloc failed for output buffer!\n"); exit(-1); } /* Compress the file, scan line at a time */ for (j=0;j 0) { len += count; c = fgetc(fptr); fputc(c,fout); for (i=1;i