author | ecalot
<ecalot> 2005-03-24 02:17:12 UTC |
committer | ecalot
<ecalot> 2005-03-24 02:17:12 UTC |
parent | a9eecd8a0371351421d0805791be59581bbd80a2 |
PR/src/Makefile | +44 | -22 |
PR/src/lib/compression/lzg_compress.c | +0 | -1 |
PR/src/lib/compression/rle_compress.c | +6 | -5 |
PR/src/lib/compression/rle_decompress.c | +9 | -7 |
PR/src/lib/compression/rlev_decompress.c | +9 | -7 |
PR/src/lib/layers/autodetect.c | +1 | -2 |
PR/src/lib/layers/idlist.c | +1 | -2 |
PR/src/lib/object/image/image16.c | +13 | -126 |
PR/src/lib/object/image/image2.c | +13 | -126 |
PR/src/lib/object/image/image256.c | +13 | -126 |
PR/src/lib/object/image/image_common.c | +13 | -126 |
PR/src/lib/xml/tree.c | +1 | -2 |
PR/src/lib/xml/unknown.c | +1 | -2 |
diff --git a/PR/src/Makefile b/PR/src/Makefile index c3f86c4..685873d 100644 --- a/PR/src/Makefile +++ b/PR/src/Makefile @@ -17,10 +17,10 @@ OS := $(shell uname) ifeq ($(OS),Linux) LINUX = -DLINUX OS = GNU/Linux - SRC2 = + PORTS = else LINUX = -DNOLINUX - SRC2 = getopt.o getopt1.o + PORTS = getopt.o getopt1.o ifeq ($(OS),Darwin) LINUX = -DNOLINUX -DMACOS endif @@ -50,11 +50,16 @@ else LINKERRELEASE = -s endif -OBJFILES = import.o compress.o export.o resources.o tasks.o disk.o\ - xmlparse.o xmlsearch.o dat.o bmp.o mid.o pal.o wav.o plv.o\ - memory.o $(SRC2) pr.o +FILES = import.o compress.o export.o resources.o tasks.o disk.o\ + dat.o bmp.o mid.o pal.o wav.o plv.o\ + memory.o pr.o -SRC3 = main.o filedir.o +XML = parse.o search.o +COMPRESS = compress.o lzg_compress.o lzg_uncompress.o rle_compress.o rle_uncompress.o +CONSOLE = main.o filedir.o + +EXEOBJ = $(FILES) $(XML) $(COMPRESS) $(CONSOLE) $(PORTS) +LIBOBJ = $(FILES) $(XML) $(COMPRESS) $(PORTS) EXEFILE = bin/pr XMLFILE = bin/resources.xml @@ -65,20 +70,21 @@ LINKEROPTIONS = $(LINKERRELEASE) #main file -$(EXEFILE): $(OBJFILES) $(XMLFILE) $(SRC3) +$(EXEFILE): $(EXEOBJ) $(INFO) Linking files... $(MAKEDIR) bin - $(CC) $(OPTIONS) -o bin/pr $(OBJFILES) $(SRC3) + $(CC) $(OPTIONS) -o bin/pr $(EXEOBJ) $(INFO) Program successfully compiled $(INFO) $(INFO) Please read readme.txt for syntax information $(INFO) #command options +.PHONY: clean cleanxml build all lib clean: $(INFO) Erasing temporary object files... - $(REMOVER) $(OBJFILES) $(EXEFILE) $(SRC3) + $(REMOVER) $(EXEOBJ) $(EXEFILE) cleanxml: $(INFO) Erasing xml file... @@ -88,13 +94,13 @@ build: clean bin/pr all: $(EXEFILE) -lib: $(OBJFILES) $(SRC3) +lib: $(LIBOBJ) $(MAKEDIR) bin $(INFO) Making dynamic library... - $(CC) $(OPTIONS) -o bin/pr.so $(OBJFILES) -Llibc -shared -dynamic + $(CC) $(OPTIONS) -o bin/pr.so $(LIBOBJ) -Llibc -shared -dynamic $(INFO) Library successfully compiled $(INFO) - $(INFO) Please read lib/readme.coders.txt and pr.h for interfaces + $(INFO) Please read readme.coders.txt and pr.h for interfaces $(INFO) #files @@ -116,9 +122,25 @@ export.o: lib/export.c $(INFO) Compiling export module... $(CC) -c lib/export.c $(OPTIONS) -compress.o: lib/compress.c +compress.o: lib/compression/main.c $(INFO) Compiling compression module... - $(CC) -c lib/compress.c $(OPTIONS) + $(CC) -c lib/compression/main.c -o compress.o $(OPTIONS) + +lzg_compress.o: lib/compression/lzg_compress.c + $(INFO) Compiling LZG compression module... + $(CC) -c lib/compression/lzg_compress.c $(OPTIONS) + +rle_compress.o: lib/compression/rle_compress.c + $(INFO) Compiling RLE compression module... + $(CC) -c lib/compression/rle_compress.c $(OPTIONS) + +lzg_uncompress.o: lib/compression/lzg_uncompress.c + $(INFO) Compiling LZG uncompression module... + $(CC) -c lib/compression/lzg_uncompress.c $(OPTIONS) + +rle_uncompress.o: lib/compression/rle_uncompress.c + $(INFO) Compiling RLE uncompression module... + $(CC) -c lib/compression/rle_uncompress.c $(OPTIONS) main.o: console/main.c $(INFO) Compiling command parsing module for standard mode... @@ -140,20 +162,20 @@ tasks.o: lib/tasks.c $(INFO) Compiling extra tasks module... $(CC) -c lib/tasks.c $(OPTIONS) -xmlparse.o: lib/xmlparse.c - $(INFO) Compiling xml parsing module... - $(CC) -c lib/xmlparse.c $(OPTIONS) +parse.o: lib/xml/parse.c + $(INFO) Compiling XML parsing module... + $(CC) -c lib/xml/parse.c $(OPTIONS) -xmlsearch.o: lib/xmlsearch.c - $(INFO) Compiling xml search features... - $(CC) -c lib/xmlsearch.c $(OPTIONS) +search.o: lib/xml/search.c + $(INFO) Compiling XML search features... + $(CC) -c lib/xml/search.c $(OPTIONS) disk.o: lib/disk.c $(INFO) Compiling disk access library... $(CC) -c lib/disk.c $(OPTIONS) dat.o: lib/dat.c - $(INFO) Compiling dat editing library... + $(INFO) Compiling DAT editing library... $(CC) -c lib/dat.c $(OPTIONS) bmp.o: lib/formats/bmp.c @@ -161,7 +183,7 @@ bmp.o: lib/formats/bmp.c $(CC) -c lib/formats/bmp.c $(OPTIONS) mid.o: lib/formats/mid.c - $(INFO) Compiling midi audio files support \(mid\)... + $(INFO) Compiling MIDI audio files support \(mid\)... $(CC) -c lib/formats/mid.c $(OPTIONS) plv.o: lib/formats/plv.c diff --git a/PR/src/lib/compression/lzg_compress.c b/PR/src/lib/compression/lzg_compress.c index 3b5fd83..8ac3a62 100644 --- a/PR/src/lib/compression/lzg_compress.c +++ b/PR/src/lib/compression/lzg_compress.c @@ -202,7 +202,6 @@ void compressLzg(const unsigned char* input2, int inputSize, /* No suitable pattern found. Just copy the current byte. */ pushMaskBit(1, output, &outputPos); output[outputPos] = input[inputPos]; -printf("copy i=%d o=%d data=%02x\n", outputPos, inputPos, output[outputPos]); inputPos++; outputPos++; } diff --git a/PR/src/lib/compression/rle_compress.c b/PR/src/lib/compression/rle_compress.c index 8ad5be0..3b55656 100644 --- a/PR/src/lib/compression/rle_compress.c +++ b/PR/src/lib/compression/rle_compress.c @@ -35,12 +35,13 @@ compress.c: Princed Resources : Image Compression Library #include <stdio.h> /* Compress using the Run Length Encoding algorithm */ -void compressRle(unsigned char* data,tImage* img,int *dataSize) { +void compressRle(const unsigned char* input, int inputSize, + unsigned char* output, int *outputSize) { /* Declare pointers */ - unsigned char* cursorData = data; + unsigned char* cursorData = output; char* counter; - unsigned char* cursorPix = img->pix; - unsigned char* imgEnd = img->pix+(*dataSize); + const unsigned char* cursorPix = input; + const unsigned char* imgEnd = input+(*outputSize); while (cursorPix<imgEnd) { /* Step 1: Create counter */ @@ -85,6 +86,6 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { } else { (*counter)--; }*/ - *dataSize=(int)((long int)cursorData-(long int)data); /* Note: casted to long for portability with 64 bits architectures */ + *outputSize=(int)((long int)cursorData-(long int)output); /* Note: casted to long for portability with 64 bits architectures */ } diff --git a/PR/src/lib/compression/rle_decompress.c b/PR/src/lib/compression/rle_decompress.c index 0a947eb..c593513 100644 --- a/PR/src/lib/compression/rle_decompress.c +++ b/PR/src/lib/compression/rle_decompress.c @@ -33,28 +33,30 @@ compress.c: Princed Resources : Image Compression Library */ #include <stdio.h> +#include "compress.h" /* Expands RLE algorithm */ -int expandRle(const unsigned char* array, int arraySize, tImage* image, int imageSize) { +int expandRle(const unsigned char* input, int inputSize, + unsigned char* output, int *outputSize) { int cursor=0; register signed char rep; int pos=0; - if ((image->pix=getMemory(imageSize+128))==NULL) return COMPRESS_RESULT_FATAL; /* reserve memory */ + if ((output=malloc(*outputSize+128))==NULL) return COMPRESS_RESULT_FATAL; /* reserve memory */ /* main loop */ - while (cursor<imageSize) { - rep=(signed char)(array[pos++]); + while (cursor<*outputSize) { + rep=(signed char)(input[pos++]); if (rep<0) { /* Negative */ - while (rep++) image->pix[cursor++]=array[pos]; + while (rep++) output[cursor++]=input[pos]; pos++; } else { /* Positive */ rep=~rep; - while (rep++) image->pix[cursor++]=array[pos++]; + while (rep++) output[cursor++]=input[pos++]; } } - return ((pos==arraySize)&(cursor==imageSize))-1; /* WARNING or SUCCESS */ + return ((pos==inputSize)&(cursor==*outputSize))-1; /* WARNING or SUCCESS */ } diff --git a/PR/src/lib/compression/rlev_decompress.c b/PR/src/lib/compression/rlev_decompress.c index 0a947eb..c593513 100644 --- a/PR/src/lib/compression/rlev_decompress.c +++ b/PR/src/lib/compression/rlev_decompress.c @@ -33,28 +33,30 @@ compress.c: Princed Resources : Image Compression Library */ #include <stdio.h> +#include "compress.h" /* Expands RLE algorithm */ -int expandRle(const unsigned char* array, int arraySize, tImage* image, int imageSize) { +int expandRle(const unsigned char* input, int inputSize, + unsigned char* output, int *outputSize) { int cursor=0; register signed char rep; int pos=0; - if ((image->pix=getMemory(imageSize+128))==NULL) return COMPRESS_RESULT_FATAL; /* reserve memory */ + if ((output=malloc(*outputSize+128))==NULL) return COMPRESS_RESULT_FATAL; /* reserve memory */ /* main loop */ - while (cursor<imageSize) { - rep=(signed char)(array[pos++]); + while (cursor<*outputSize) { + rep=(signed char)(input[pos++]); if (rep<0) { /* Negative */ - while (rep++) image->pix[cursor++]=array[pos]; + while (rep++) output[cursor++]=input[pos]; pos++; } else { /* Positive */ rep=~rep; - while (rep++) image->pix[cursor++]=array[pos++]; + while (rep++) output[cursor++]=input[pos++]; } } - return ((pos==arraySize)&(cursor==imageSize))-1; /* WARNING or SUCCESS */ + return ((pos==inputSize)&(cursor==*outputSize))-1; /* WARNING or SUCCESS */ } diff --git a/PR/src/lib/layers/autodetect.c b/PR/src/lib/layers/autodetect.c index 53a8c9a..320ad31 100644 --- a/PR/src/lib/layers/autodetect.c +++ b/PR/src/lib/layers/autodetect.c @@ -245,8 +245,6 @@ void emptyTable(tResource* r[]) { while (i--) *(r++)=NULL; } - - /* parse file */ int parseFile(const char* vFile, const char* datFile, tResource* r[]) { /* Declare error variable */ @@ -328,3 +326,4 @@ void getFileName(char* vFileext,const char* vDirExt,tResource* r,unsigned short sprintf(vFileext,"%s/%s",vDirExt,r->path); } } + diff --git a/PR/src/lib/layers/idlist.c b/PR/src/lib/layers/idlist.c index 53a8c9a..320ad31 100644 --- a/PR/src/lib/layers/idlist.c +++ b/PR/src/lib/layers/idlist.c @@ -245,8 +245,6 @@ void emptyTable(tResource* r[]) { while (i--) *(r++)=NULL; } - - /* parse file */ int parseFile(const char* vFile, const char* datFile, tResource* r[]) { /* Declare error variable */ @@ -328,3 +326,4 @@ void getFileName(char* vFileext,const char* vDirExt,tResource* r,unsigned short sprintf(vFileext,"%s/%s",vDirExt,r->path); } } + diff --git a/PR/src/lib/object/image/image16.c b/PR/src/lib/object/image/image16.c index 0478f81..00be94a 100644 --- a/PR/src/lib/object/image/image16.c +++ b/PR/src/lib/object/image/image16.c @@ -43,6 +43,19 @@ compress.c: Princed Resources : Image Compression Library | I M P L E M E N T A T I O N | \***************************************************************/ +/***************************************************************\ +| Internal compression prototypes | +\***************************************************************/ + +void compressLzg(const unsigned char* input, int inputSize, + unsigned char* output, int *outputSize); +void compressRle(const unsigned char* input, int inputSize, + unsigned char* output, int *outputSize); +int expandLzg(const unsigned char* input, int inputSize, + unsigned char* output, int *outputSize); +int expandRle(const unsigned char* input, int inputSize, + unsigned char* output, int *outputSize); + /***************************************************************\ | Image transpose | \***************************************************************/ @@ -70,132 +83,6 @@ void antiTransposeImage(tImage* image,int size) { image->pix=outputaux; } -/***************************************************************\ -| Uncompression algorithms | -\***************************************************************/ - -/* LZG expansion algorithm sub function */ -unsigned char popBit(unsigned char *byte) { - unsigned char bit=(unsigned char)((*byte)&1); - (*byte)>>=1; - return bit; -} - -/* Expands LZ Groody algorithm. This is the core of PR */ -int expandLzg(const unsigned char* array, int arraySize, tImage* image, int imageSize) { - char k; - int location,h,cursor=0,pos=0; - unsigned char maskbyte,rep; - - if ((image->pix=getMemory(/*imageSize*/MAX_MOD_SIZE_IN_LZG))==NULL) return COMPRESS_RESULT_FATAL; /* reserve memory */ - for(location=0;location<MAX_MOD_SIZE_IN_LZG;image->pix[location]=0,location++); /* clean output garbage */ - - /* main loop */ - while (cursor<imageSize) { - maskbyte=array[pos++]; - for (k=8;k&&(cursor<imageSize);k--) { - if (popBit(&maskbyte)) { - image->pix[cursor++]=array[pos++]; - } else { - location=66+(((rep=array[pos])&3)<<8)+(unsigned char)array[pos+1];pos+=2; - rep=(unsigned char)((rep>>2)+3); - while (rep--) { /* Be careful in big images */ - h=cursor/MAX_MXD_SIZE_IN_LZG-((location%MAX_MXD_SIZE_IN_LZG)>(cursor%MAX_MXD_SIZE_IN_LZG)); - image->pix[cursor++]=image->pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZG+(location++)%MAX_MXD_SIZE_IN_LZG]; -/* - h=((cursor-(location&0x3FF))&(~0x3FF)); - image->pix[cursor]=image->pix[((h<0)?0:h)+(location&0x3FF)]; - cursor++;location++; -*/ - } - } - } - } - return ((pos==arraySize)&(cursor==imageSize))-1; /* WARNING or SUCCESS */ -} - -/* Expands RLE algorithm */ -int expandRle(const unsigned char* array, int arraySize, tImage* image, int imageSize) { - int cursor=0; - register signed char rep; - int pos=0; - - if ((image->pix=getMemory(imageSize+128))==NULL) return COMPRESS_RESULT_FATAL; /* reserve memory */ - - /* main loop */ - while (cursor<imageSize) { - rep=(signed char)(array[pos++]); - if (rep<0) { - /* Negative */ - while (rep++) image->pix[cursor++]=array[pos]; - pos++; - } else { - /* Positive */ - rep=~rep; - while (rep++) image->pix[cursor++]=array[pos++]; - } - } - return ((pos==arraySize)&(cursor==imageSize))-1; /* WARNING or SUCCESS */ -} - -/***************************************************************\ -| Compression algorithms | -\***************************************************************/ - -/* Compress using the Run Length Encoding algorithm */ -void compressRle(unsigned char* data,tImage* img,int *dataSize) { - /* Declare pointers */ - unsigned char* cursorData = data; - char* counter; - unsigned char* cursorPix = img->pix; - unsigned char* imgEnd = img->pix+(*dataSize); - - while (cursorPix<imgEnd) { - /* Step 1: Create counter */ - counter=(char*)(cursorData++); - *counter=-1; - - /* Step 2: Look and copy the string until more than two repeated bytes are found */ - while ( - (cursorPix+1<imgEnd)&& /* bugfix: reads one more */ - ( - (*cursorPix!=*(cursorPix+1))|| - ( - /* (*cursorPix==*(cursorPix+1))&& */ - ((cursorPix+2)<imgEnd)&& /* bugfix: reads one more */ - (*cursorPix!=*(cursorPix+2)) - ) - )&& - ((*counter)!=127) - ) { - *(cursorData)=*(cursorPix); - (*counter)++; - cursorPix++; - cursorData++; - } - - /* Step 3: If there was a repeated string, let's ignore it and add the cursor with the repetitions */ - if (*counter==-1) { - while ((cursorPix+1<imgEnd)&&(*cursorPix==(*(cursorPix+1)))&&((*counter)!=-128)) { - cursorPix++; - (*counter)--; - } - - *(cursorData)=*(cursorPix); /* Print repeated char */ - cursorPix++; - cursorData++; - } - } - /* Write the last char - if ((*counter)>0) { - *(cursorData++)=0; - *(cursorData)= ||||||| 0xff ||||| *(cursorPix); ||||||| - } else { - (*counter)--; - }*/ - *dataSize=(int)((long int)cursorData-(long int)data); /* Note: casted to long for portability with 64 bits architectures */ -} - /***************************************************************\ | Main compress and expand graphics | \***************************************************************/ diff --git a/PR/src/lib/object/image/image2.c b/PR/src/lib/object/image/image2.c index 0478f81..00be94a 100644 --- a/PR/src/lib/object/image/image2.c +++ b/PR/src/lib/object/image/image2.c @@ -43,6 +43,19 @@ compress.c: Princed Resources : Image Compression Library | I M P L E M E N T A T I O N | \***************************************************************/ +/***************************************************************\ +| Internal compression prototypes | +\***************************************************************/ + +void compressLzg(const unsigned char* input, int inputSize, + unsigned char* output, int *outputSize); +void compressRle(const unsigned char* input, int inputSize, + unsigned char* output, int *outputSize); +int expandLzg(const unsigned char* input, int inputSize, + unsigned char* output, int *outputSize); +int expandRle(const unsigned char* input, int inputSize, + unsigned char* output, int *outputSize); + /***************************************************************\ | Image transpose | \***************************************************************/ @@ -70,132 +83,6 @@ void antiTransposeImage(tImage* image,int size) { image->pix=outputaux; } -/***************************************************************\ -| Uncompression algorithms | -\***************************************************************/ - -/* LZG expansion algorithm sub function */ -unsigned char popBit(unsigned char *byte) { - unsigned char bit=(unsigned char)((*byte)&1); - (*byte)>>=1; - return bit; -} - -/* Expands LZ Groody algorithm. This is the core of PR */ -int expandLzg(const unsigned char* array, int arraySize, tImage* image, int imageSize) { - char k; - int location,h,cursor=0,pos=0; - unsigned char maskbyte,rep; - - if ((image->pix=getMemory(/*imageSize*/MAX_MOD_SIZE_IN_LZG))==NULL) return COMPRESS_RESULT_FATAL; /* reserve memory */ - for(location=0;location<MAX_MOD_SIZE_IN_LZG;image->pix[location]=0,location++); /* clean output garbage */ - - /* main loop */ - while (cursor<imageSize) { - maskbyte=array[pos++]; - for (k=8;k&&(cursor<imageSize);k--) { - if (popBit(&maskbyte)) { - image->pix[cursor++]=array[pos++]; - } else { - location=66+(((rep=array[pos])&3)<<8)+(unsigned char)array[pos+1];pos+=2; - rep=(unsigned char)((rep>>2)+3); - while (rep--) { /* Be careful in big images */ - h=cursor/MAX_MXD_SIZE_IN_LZG-((location%MAX_MXD_SIZE_IN_LZG)>(cursor%MAX_MXD_SIZE_IN_LZG)); - image->pix[cursor++]=image->pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZG+(location++)%MAX_MXD_SIZE_IN_LZG]; -/* - h=((cursor-(location&0x3FF))&(~0x3FF)); - image->pix[cursor]=image->pix[((h<0)?0:h)+(location&0x3FF)]; - cursor++;location++; -*/ - } - } - } - } - return ((pos==arraySize)&(cursor==imageSize))-1; /* WARNING or SUCCESS */ -} - -/* Expands RLE algorithm */ -int expandRle(const unsigned char* array, int arraySize, tImage* image, int imageSize) { - int cursor=0; - register signed char rep; - int pos=0; - - if ((image->pix=getMemory(imageSize+128))==NULL) return COMPRESS_RESULT_FATAL; /* reserve memory */ - - /* main loop */ - while (cursor<imageSize) { - rep=(signed char)(array[pos++]); - if (rep<0) { - /* Negative */ - while (rep++) image->pix[cursor++]=array[pos]; - pos++; - } else { - /* Positive */ - rep=~rep; - while (rep++) image->pix[cursor++]=array[pos++]; - } - } - return ((pos==arraySize)&(cursor==imageSize))-1; /* WARNING or SUCCESS */ -} - -/***************************************************************\ -| Compression algorithms | -\***************************************************************/ - -/* Compress using the Run Length Encoding algorithm */ -void compressRle(unsigned char* data,tImage* img,int *dataSize) { - /* Declare pointers */ - unsigned char* cursorData = data; - char* counter; - unsigned char* cursorPix = img->pix; - unsigned char* imgEnd = img->pix+(*dataSize); - - while (cursorPix<imgEnd) { - /* Step 1: Create counter */ - counter=(char*)(cursorData++); - *counter=-1; - - /* Step 2: Look and copy the string until more than two repeated bytes are found */ - while ( - (cursorPix+1<imgEnd)&& /* bugfix: reads one more */ - ( - (*cursorPix!=*(cursorPix+1))|| - ( - /* (*cursorPix==*(cursorPix+1))&& */ - ((cursorPix+2)<imgEnd)&& /* bugfix: reads one more */ - (*cursorPix!=*(cursorPix+2)) - ) - )&& - ((*counter)!=127) - ) { - *(cursorData)=*(cursorPix); - (*counter)++; - cursorPix++; - cursorData++; - } - - /* Step 3: If there was a repeated string, let's ignore it and add the cursor with the repetitions */ - if (*counter==-1) { - while ((cursorPix+1<imgEnd)&&(*cursorPix==(*(cursorPix+1)))&&((*counter)!=-128)) { - cursorPix++; - (*counter)--; - } - - *(cursorData)=*(cursorPix); /* Print repeated char */ - cursorPix++; - cursorData++; - } - } - /* Write the last char - if ((*counter)>0) { - *(cursorData++)=0; - *(cursorData)= ||||||| 0xff ||||| *(cursorPix); ||||||| - } else { - (*counter)--; - }*/ - *dataSize=(int)((long int)cursorData-(long int)data); /* Note: casted to long for portability with 64 bits architectures */ -} - /***************************************************************\ | Main compress and expand graphics | \***************************************************************/ diff --git a/PR/src/lib/object/image/image256.c b/PR/src/lib/object/image/image256.c index 0478f81..00be94a 100644 --- a/PR/src/lib/object/image/image256.c +++ b/PR/src/lib/object/image/image256.c @@ -43,6 +43,19 @@ compress.c: Princed Resources : Image Compression Library | I M P L E M E N T A T I O N | \***************************************************************/ +/***************************************************************\ +| Internal compression prototypes | +\***************************************************************/ + +void compressLzg(const unsigned char* input, int inputSize, + unsigned char* output, int *outputSize); +void compressRle(const unsigned char* input, int inputSize, + unsigned char* output, int *outputSize); +int expandLzg(const unsigned char* input, int inputSize, + unsigned char* output, int *outputSize); +int expandRle(const unsigned char* input, int inputSize, + unsigned char* output, int *outputSize); + /***************************************************************\ | Image transpose | \***************************************************************/ @@ -70,132 +83,6 @@ void antiTransposeImage(tImage* image,int size) { image->pix=outputaux; } -/***************************************************************\ -| Uncompression algorithms | -\***************************************************************/ - -/* LZG expansion algorithm sub function */ -unsigned char popBit(unsigned char *byte) { - unsigned char bit=(unsigned char)((*byte)&1); - (*byte)>>=1; - return bit; -} - -/* Expands LZ Groody algorithm. This is the core of PR */ -int expandLzg(const unsigned char* array, int arraySize, tImage* image, int imageSize) { - char k; - int location,h,cursor=0,pos=0; - unsigned char maskbyte,rep; - - if ((image->pix=getMemory(/*imageSize*/MAX_MOD_SIZE_IN_LZG))==NULL) return COMPRESS_RESULT_FATAL; /* reserve memory */ - for(location=0;location<MAX_MOD_SIZE_IN_LZG;image->pix[location]=0,location++); /* clean output garbage */ - - /* main loop */ - while (cursor<imageSize) { - maskbyte=array[pos++]; - for (k=8;k&&(cursor<imageSize);k--) { - if (popBit(&maskbyte)) { - image->pix[cursor++]=array[pos++]; - } else { - location=66+(((rep=array[pos])&3)<<8)+(unsigned char)array[pos+1];pos+=2; - rep=(unsigned char)((rep>>2)+3); - while (rep--) { /* Be careful in big images */ - h=cursor/MAX_MXD_SIZE_IN_LZG-((location%MAX_MXD_SIZE_IN_LZG)>(cursor%MAX_MXD_SIZE_IN_LZG)); - image->pix[cursor++]=image->pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZG+(location++)%MAX_MXD_SIZE_IN_LZG]; -/* - h=((cursor-(location&0x3FF))&(~0x3FF)); - image->pix[cursor]=image->pix[((h<0)?0:h)+(location&0x3FF)]; - cursor++;location++; -*/ - } - } - } - } - return ((pos==arraySize)&(cursor==imageSize))-1; /* WARNING or SUCCESS */ -} - -/* Expands RLE algorithm */ -int expandRle(const unsigned char* array, int arraySize, tImage* image, int imageSize) { - int cursor=0; - register signed char rep; - int pos=0; - - if ((image->pix=getMemory(imageSize+128))==NULL) return COMPRESS_RESULT_FATAL; /* reserve memory */ - - /* main loop */ - while (cursor<imageSize) { - rep=(signed char)(array[pos++]); - if (rep<0) { - /* Negative */ - while (rep++) image->pix[cursor++]=array[pos]; - pos++; - } else { - /* Positive */ - rep=~rep; - while (rep++) image->pix[cursor++]=array[pos++]; - } - } - return ((pos==arraySize)&(cursor==imageSize))-1; /* WARNING or SUCCESS */ -} - -/***************************************************************\ -| Compression algorithms | -\***************************************************************/ - -/* Compress using the Run Length Encoding algorithm */ -void compressRle(unsigned char* data,tImage* img,int *dataSize) { - /* Declare pointers */ - unsigned char* cursorData = data; - char* counter; - unsigned char* cursorPix = img->pix; - unsigned char* imgEnd = img->pix+(*dataSize); - - while (cursorPix<imgEnd) { - /* Step 1: Create counter */ - counter=(char*)(cursorData++); - *counter=-1; - - /* Step 2: Look and copy the string until more than two repeated bytes are found */ - while ( - (cursorPix+1<imgEnd)&& /* bugfix: reads one more */ - ( - (*cursorPix!=*(cursorPix+1))|| - ( - /* (*cursorPix==*(cursorPix+1))&& */ - ((cursorPix+2)<imgEnd)&& /* bugfix: reads one more */ - (*cursorPix!=*(cursorPix+2)) - ) - )&& - ((*counter)!=127) - ) { - *(cursorData)=*(cursorPix); - (*counter)++; - cursorPix++; - cursorData++; - } - - /* Step 3: If there was a repeated string, let's ignore it and add the cursor with the repetitions */ - if (*counter==-1) { - while ((cursorPix+1<imgEnd)&&(*cursorPix==(*(cursorPix+1)))&&((*counter)!=-128)) { - cursorPix++; - (*counter)--; - } - - *(cursorData)=*(cursorPix); /* Print repeated char */ - cursorPix++; - cursorData++; - } - } - /* Write the last char - if ((*counter)>0) { - *(cursorData++)=0; - *(cursorData)= ||||||| 0xff ||||| *(cursorPix); ||||||| - } else { - (*counter)--; - }*/ - *dataSize=(int)((long int)cursorData-(long int)data); /* Note: casted to long for portability with 64 bits architectures */ -} - /***************************************************************\ | Main compress and expand graphics | \***************************************************************/ diff --git a/PR/src/lib/object/image/image_common.c b/PR/src/lib/object/image/image_common.c index 0478f81..00be94a 100644 --- a/PR/src/lib/object/image/image_common.c +++ b/PR/src/lib/object/image/image_common.c @@ -43,6 +43,19 @@ compress.c: Princed Resources : Image Compression Library | I M P L E M E N T A T I O N | \***************************************************************/ +/***************************************************************\ +| Internal compression prototypes | +\***************************************************************/ + +void compressLzg(const unsigned char* input, int inputSize, + unsigned char* output, int *outputSize); +void compressRle(const unsigned char* input, int inputSize, + unsigned char* output, int *outputSize); +int expandLzg(const unsigned char* input, int inputSize, + unsigned char* output, int *outputSize); +int expandRle(const unsigned char* input, int inputSize, + unsigned char* output, int *outputSize); + /***************************************************************\ | Image transpose | \***************************************************************/ @@ -70,132 +83,6 @@ void antiTransposeImage(tImage* image,int size) { image->pix=outputaux; } -/***************************************************************\ -| Uncompression algorithms | -\***************************************************************/ - -/* LZG expansion algorithm sub function */ -unsigned char popBit(unsigned char *byte) { - unsigned char bit=(unsigned char)((*byte)&1); - (*byte)>>=1; - return bit; -} - -/* Expands LZ Groody algorithm. This is the core of PR */ -int expandLzg(const unsigned char* array, int arraySize, tImage* image, int imageSize) { - char k; - int location,h,cursor=0,pos=0; - unsigned char maskbyte,rep; - - if ((image->pix=getMemory(/*imageSize*/MAX_MOD_SIZE_IN_LZG))==NULL) return COMPRESS_RESULT_FATAL; /* reserve memory */ - for(location=0;location<MAX_MOD_SIZE_IN_LZG;image->pix[location]=0,location++); /* clean output garbage */ - - /* main loop */ - while (cursor<imageSize) { - maskbyte=array[pos++]; - for (k=8;k&&(cursor<imageSize);k--) { - if (popBit(&maskbyte)) { - image->pix[cursor++]=array[pos++]; - } else { - location=66+(((rep=array[pos])&3)<<8)+(unsigned char)array[pos+1];pos+=2; - rep=(unsigned char)((rep>>2)+3); - while (rep--) { /* Be careful in big images */ - h=cursor/MAX_MXD_SIZE_IN_LZG-((location%MAX_MXD_SIZE_IN_LZG)>(cursor%MAX_MXD_SIZE_IN_LZG)); - image->pix[cursor++]=image->pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZG+(location++)%MAX_MXD_SIZE_IN_LZG]; -/* - h=((cursor-(location&0x3FF))&(~0x3FF)); - image->pix[cursor]=image->pix[((h<0)?0:h)+(location&0x3FF)]; - cursor++;location++; -*/ - } - } - } - } - return ((pos==arraySize)&(cursor==imageSize))-1; /* WARNING or SUCCESS */ -} - -/* Expands RLE algorithm */ -int expandRle(const unsigned char* array, int arraySize, tImage* image, int imageSize) { - int cursor=0; - register signed char rep; - int pos=0; - - if ((image->pix=getMemory(imageSize+128))==NULL) return COMPRESS_RESULT_FATAL; /* reserve memory */ - - /* main loop */ - while (cursor<imageSize) { - rep=(signed char)(array[pos++]); - if (rep<0) { - /* Negative */ - while (rep++) image->pix[cursor++]=array[pos]; - pos++; - } else { - /* Positive */ - rep=~rep; - while (rep++) image->pix[cursor++]=array[pos++]; - } - } - return ((pos==arraySize)&(cursor==imageSize))-1; /* WARNING or SUCCESS */ -} - -/***************************************************************\ -| Compression algorithms | -\***************************************************************/ - -/* Compress using the Run Length Encoding algorithm */ -void compressRle(unsigned char* data,tImage* img,int *dataSize) { - /* Declare pointers */ - unsigned char* cursorData = data; - char* counter; - unsigned char* cursorPix = img->pix; - unsigned char* imgEnd = img->pix+(*dataSize); - - while (cursorPix<imgEnd) { - /* Step 1: Create counter */ - counter=(char*)(cursorData++); - *counter=-1; - - /* Step 2: Look and copy the string until more than two repeated bytes are found */ - while ( - (cursorPix+1<imgEnd)&& /* bugfix: reads one more */ - ( - (*cursorPix!=*(cursorPix+1))|| - ( - /* (*cursorPix==*(cursorPix+1))&& */ - ((cursorPix+2)<imgEnd)&& /* bugfix: reads one more */ - (*cursorPix!=*(cursorPix+2)) - ) - )&& - ((*counter)!=127) - ) { - *(cursorData)=*(cursorPix); - (*counter)++; - cursorPix++; - cursorData++; - } - - /* Step 3: If there was a repeated string, let's ignore it and add the cursor with the repetitions */ - if (*counter==-1) { - while ((cursorPix+1<imgEnd)&&(*cursorPix==(*(cursorPix+1)))&&((*counter)!=-128)) { - cursorPix++; - (*counter)--; - } - - *(cursorData)=*(cursorPix); /* Print repeated char */ - cursorPix++; - cursorData++; - } - } - /* Write the last char - if ((*counter)>0) { - *(cursorData++)=0; - *(cursorData)= ||||||| 0xff ||||| *(cursorPix); ||||||| - } else { - (*counter)--; - }*/ - *dataSize=(int)((long int)cursorData-(long int)data); /* Note: casted to long for portability with 64 bits architectures */ -} - /***************************************************************\ | Main compress and expand graphics | \***************************************************************/ diff --git a/PR/src/lib/xml/tree.c b/PR/src/lib/xml/tree.c index 53a8c9a..320ad31 100644 --- a/PR/src/lib/xml/tree.c +++ b/PR/src/lib/xml/tree.c @@ -245,8 +245,6 @@ void emptyTable(tResource* r[]) { while (i--) *(r++)=NULL; } - - /* parse file */ int parseFile(const char* vFile, const char* datFile, tResource* r[]) { /* Declare error variable */ @@ -328,3 +326,4 @@ void getFileName(char* vFileext,const char* vDirExt,tResource* r,unsigned short sprintf(vFileext,"%s/%s",vDirExt,r->path); } } + diff --git a/PR/src/lib/xml/unknown.c b/PR/src/lib/xml/unknown.c index 53a8c9a..320ad31 100644 --- a/PR/src/lib/xml/unknown.c +++ b/PR/src/lib/xml/unknown.c @@ -245,8 +245,6 @@ void emptyTable(tResource* r[]) { while (i--) *(r++)=NULL; } - - /* parse file */ int parseFile(const char* vFile, const char* datFile, tResource* r[]) { /* Declare error variable */ @@ -328,3 +326,4 @@ void getFileName(char* vFileext,const char* vDirExt,tResource* r,unsigned short sprintf(vFileext,"%s/%s",vDirExt,r->path); } } +