git » fp-git.git » commit 3e57483

source clean

author ecalot
2006-06-24 22:43:16 UTC
committer ecalot
2006-06-24 22:43:16 UTC
parent f9b037637e7c450d24435e6ed6fc7f3430760b5e

source clean

PR/src/include/compress.h +2 -1
PR/src/include/memory.h +1 -0
PR/src/lib/compression/lzg_decompress.c +9 -9
PR/src/lib/layers/memory.c +12 -1
PR/src/lib/object/image/image16.c +3 -3
PR/src/lib/object/image/image256.c +39 -33
PR/src/lib/object/image/image_common.c +3 -3
PR/src/ports/winfiles/pr.dev +1 -1

diff --git a/PR/src/include/compress.h b/PR/src/include/compress.h
index 7bbf31c..c54f6bc 100644
--- a/PR/src/include/compress.h
+++ b/PR/src/include/compress.h
@@ -35,6 +35,7 @@ compress.h: Princed Resources : Compression headers
 #define _PR_COMPRESS_H_
 
 #include "common.h"
+#include "types.h"  /* tBinary */
 
 #define COMPRESS_RAW    0x00
 #define COMPRESS_RLE_LR 0x01
@@ -62,7 +63,7 @@ void compressRle(const unsigned char* input, int inputSize,
                  unsigned char* output, int *outputSize);
 
 /* decompress and allocates output */
-int expandLzg(const unsigned char* input, int inputSize,
+int expandLzg(/*const unsigned char* input, int inputSize*/ tBinary input,
                unsigned char** output, int *outputSize);
 int expandRle(const unsigned char* input, int inputSize,
                unsigned char** output, int *outputSize);
diff --git a/PR/src/include/memory.h b/PR/src/include/memory.h
index cbaf778..858e0c0 100644
--- a/PR/src/include/memory.h
+++ b/PR/src/include/memory.h
@@ -61,5 +61,6 @@ int getOrder(const char* order);
 #include "binary.h"
 tBinary tbinaryallocandcopy(tBinary c);
 void freeBinary(tBinary b);
+tBinary binaryCrop(tBinary old, int heading, int trailing);
 
 #endif
diff --git a/PR/src/lib/compression/lzg_decompress.c b/PR/src/lib/compression/lzg_decompress.c
index e206ef5..1949947 100644
--- a/PR/src/lib/compression/lzg_decompress.c
+++ b/PR/src/lib/compression/lzg_decompress.c
@@ -44,7 +44,7 @@ unsigned char popBit(unsigned char *byte) {
 }
 
 /* Expands LZ Groody algorithm. This is the core of PR */
-int expandLzg(const unsigned char* input, int inputSize,
+int expandLzg(/*const unsigned char* input, int inputSize,*/ tBinary input,
                unsigned char** output2, int *outputSize) {
 
 	int                    oCursor=0, iCursor=0;
@@ -59,11 +59,11 @@ int expandLzg(const unsigned char* input, int inputSize,
 	for(oCursor=0;oCursor<LZG_WINDOW_SIZE;output[oCursor++]=0);
 
 	/* main loop */
-	while (iCursor<inputSize&&oCursor<(*outputSize)) {
-		maskbyte=input[iCursor++];
-		for (k=8;k&&(iCursor<inputSize);k--) {
+	while (iCursor<input.size&&oCursor<(*outputSize)) {
+		maskbyte=input.data[iCursor++];
+		for (k=8;k&&(iCursor<input.size);k--) {
 			if (popBit(&maskbyte)) {
-				output[oCursor++]=input[iCursor++]; /* copy input to output */
+				output[oCursor++]=input.data[iCursor++]; /* copy input.data to output */
 			} else {
 				/*
 				 * loc:
@@ -72,8 +72,8 @@ int expandLzg(const unsigned char* input, int inputSize,
 				 * rep:
 				 *  6 bits for the repetition number (R). Add 3 to this number.
 				 */
-				loc= 66 + ((input[iCursor] & 0x03 /*00000011*/) <<8) + input[iCursor+1];
-				rep= 3  + ((input[iCursor] & 0xfc /*11111100*/) >>2);
+				loc= 66 + ((input.data[iCursor] & 0x03 /*00000011*/) <<8) + input.data[iCursor+1];
+				rep= 3  + ((input.data[iCursor] & 0xfc /*11111100*/) >>2);
 
 				iCursor+=2; /* move the cursor 2 bytes ahead */
 
@@ -87,14 +87,14 @@ int expandLzg(const unsigned char* input, int inputSize,
 		}
 	}
 
-	inputSize-=iCursor;
+	input.size-=iCursor;
 	/* ignore the first 1024 bytes */
 	*outputSize=oCursor-LZG_WINDOW_SIZE;
 	*output2=(unsigned char*)malloc(*outputSize);
 	for(iCursor=LZG_WINDOW_SIZE;iCursor<oCursor;iCursor++)
 		(*output2)[iCursor-LZG_WINDOW_SIZE]=output[iCursor];
 
-	if (oCursor>=(*outputSize)) return inputSize; /* TODO: check if this case never happens !!! */
+	if (oCursor>=(*outputSize)) return input.size; /* TODO: check if this case never happens !!! */
 
 	return (!maskbyte)-1;
 	/*return rep?COMPRESS_RESULT_WARNING:COMPRESS_RESULT_SUCCESS;*/
diff --git a/PR/src/lib/layers/memory.c b/PR/src/lib/layers/memory.c
index 10e457c..e9ca37b 100644
--- a/PR/src/lib/layers/memory.c
+++ b/PR/src/lib/layers/memory.c
@@ -60,11 +60,22 @@ tBinary tbinaryallocandcopy(tBinary c) {
 	aux.data=(unsigned char*)malloc(c.size);
 	aux.size=c.size;
 	aux.isCopy=0;
-	
+
 	if (aux.data) memcpy(aux.data,c.data,c.size);
 	return aux;
 }
 
+tBinary binaryCrop(tBinary old, int heading, int trailing) {
+	old.data+=heading;
+	old.size-=heading;
+
+	old.size-=trailing;
+
+	old.isCopy=1;
+
+	return old;
+}
+
 void str5lowercpy (char* dst,const char* src) {
 	int i;
 	for (i=0;(i<4)&&(*src);i++) {
diff --git a/PR/src/lib/object/image/image16.c b/PR/src/lib/object/image/image16.c
index 0ed1722..85db446 100644
--- a/PR/src/lib/object/image/image16.c
+++ b/PR/src/lib/object/image/image16.c
@@ -204,11 +204,11 @@ int mExpandGraphic(tBinary input, tImage *image) {
 			cmp_transposeImage(image,imageSizeInBytes);
 			break;
 		case COMPRESS_LZG_LR: /* LZ Groody Left to Right Compression Algorithm */
-			result=expandLzg(input.data,input.size,&(image->pix),&imageSizeInBytes);
+			result=expandLzg(input/*.data,input.size*/,&(image->pix),&imageSizeInBytes);
 			checkSize;
 			break;
 		case COMPRESS_LZG_UD: /* LZ Groody Up to Down Compression Algorithm */
-			result=expandLzg(input.data,input.size,&(image->pix),&imageSizeInBytes);
+			result=expandLzg(input/*.data,input.size*/,&(image->pix),&imageSizeInBytes);
 			checkResult;
 			checkSize;
 			cmp_transposeImage(image,imageSizeInBytes);
@@ -220,7 +220,7 @@ int mExpandGraphic(tBinary input, tImage *image) {
 	return result; /* Ok */
 }
 
-/* Compress an image into binary data */
+/* Compress an image into binary data TODO: send to common image */
 int mCompressGraphic(tBinary* input, tBinary* output, int ignoreFirstBytes, int w, int h) {
 /*								unsigned char* *data,tImage* image, int* dataSizeInBytes, int ignoreFirstBytes) {*/
 	/* Declare variables */
diff --git a/PR/src/lib/object/image/image256.c b/PR/src/lib/object/image/image256.c
index c08beee..e650088 100644
--- a/PR/src/lib/object/image/image256.c
+++ b/PR/src/lib/object/image/image256.c
@@ -38,9 +38,9 @@ image256.c: Princed Resources : Image Compression Library
 #include "common.h"
 #include "image.h"
 #include "memory.h"
-#include "disk.h" /* array2short */
+#include "disk.h"    /* array2short */
 #include "dat.h"
-#include "object.h" /* paletteGet* */
+#include "object.h"  /* paletteGet* */
 
 #include "palette.h" /* getColorArrayByColors */
 
@@ -94,7 +94,7 @@ image256.c: Princed Resources : Image Compression Library
 |                  I M P L E M E N T A T I O N                  |
 \***************************************************************/
 
-int pop2decompress(const unsigned char* input, int inputSize, int verify, unsigned char** output,int* outputSize);
+int pop2decompress(tBinary input, int verify, unsigned char** output,int* outputSize);
 
 /***************************************************************\
 |               Main compress and expand graphics               |
@@ -110,22 +110,23 @@ int pop2decompress(const unsigned char* input, int inputSize, int verify, unsign
  */
 
 /* Expands an array into an image */
-int mExpandGraphic256(const unsigned char* data,tImage *image, int dataSizeInBytes) {
+int mExpandGraphic256(tBinary input, tImage *image) {
 	/*
-	 * Reads data and extracts tImage
+	 * Reads input and extracts tImage
 	 * returns the next image address or -1 in case of error
 	 */
 
 	int imageSizeInBytes=0;
 
-	image->height=array2short(data);
-	data+=2;
-	image->width =array2short(data);
-	data+=2;
+	image->height=array2short(input.data);
+	input.data+=2;
+	image->width =array2short(input.data);
+	input.data+=2;
 
-	if (*(data++)>1) return PR_RESULT_COMPRESS_RESULT_FATAL; /* Verify format */
-	image->type=(unsigned char)(*(data++));
-	dataSizeInBytes-=6;
+	if (*(input.data++)>1) return PR_RESULT_COMPRESS_RESULT_FATAL; /* Verify format */
+	image->type=(unsigned char)(*(input.data++));
+	/* TODO: check the header knowing it has 256 colours and 8 bits/pixel */
+	input.size-=6;
 	switch (((image->type>>4)&7)+1) {
 	case 8:
 		image->widthInBytes=(image->width);
@@ -142,12 +143,12 @@ int mExpandGraphic256(const unsigned char* data,tImage *image, int dataSizeInByt
 	}
 
 	/* special format has a special function */
-	return pop2decompress(data,dataSizeInBytes,image->width,&(image->pix),&imageSizeInBytes); /* TODO: use tBinary */
+	return pop2decompress(input,image->width,&(image->pix),&imageSizeInBytes); /* TODO: use tBinary */
 }
 
 /* Compress an image into binary data */
 int mCompressGraphic256(tBinary* input, tBinary* output, int ignoreFirstBytes, int w, int h) {
-/*								unsigned char* *data,tImage* image, int* dataSizeInBytes, int ignoreFirstBytes) {*/
+
 	/* Declare variables */
 	unsigned char* compressed     [COMPRESS_WORKING_ALGORITHMS];
 	int            compressedSize [COMPRESS_WORKING_ALGORITHMS];
@@ -156,7 +157,7 @@ int mCompressGraphic256(tBinary* input, tBinary* output, int ignoreFirstBytes, i
 	int            imageSizeInBytes;
 	int            max_alg=1;
 
-	/* Initialize variables */
+	/* Initialise variables */
 	imageSizeInBytes=input->size; /*=image->widthInBytes*image->height;*/
 
 	/*
@@ -198,8 +199,7 @@ int mCompressGraphic256(tBinary* input, tBinary* output, int ignoreFirstBytes, i
 	return algorithm;
 }
 
-int pop2decompress(const unsigned char* input, int inputSize, int verify, unsigned char** output,int* outputSize) {
-	/* This function is in an experimental state and hasn't yet been linked to the program */
+int pop2decompress(tBinary input, int verify, unsigned char** output,int* outputSize) {
 	unsigned char* tempOutput;
 	unsigned char* lineI; /* chunk */
 	unsigned char* lineO; /* chunk */
@@ -210,18 +210,19 @@ int pop2decompress(const unsigned char* input, int inputSize, int verify, unsign
 
 	*output=malloc(*outputSize);
 	lineO=*output;
-	for (aux=0;aux<*outputSize;aux++) (*output)[aux]=0; /* initialize the array (TODO: only for debug, in fixed images it won't be necessary) */
+	for (aux=0;aux<*outputSize;aux++) (*output)[aux]=0; /* initialise the array (TODO: only for debug, in fixed images it won't be necessary) */
 	*outputSize=0;
 
-	osCheck=array2short(input)-6;
-	input+=2;
+	osCheck=array2short(input.data)-6;
+	input.data+=2;
+	input.size-=2; /* TODO: code binaryCrop(tBinary b, int heading, int trailing) */
 
-	/* First layer: expand the lgz */
+	/* First layer: expand the LGZ */
 	tempOutputSize=osCheck+6;
 
-	remaining=expandLzg(input,inputSize-2,&tempOutput,&tempOutputSize);
-	/*printf("Call:\n return=%d function input size=%d\n internal output size=%d result output size=%d\n",
-		remaining,inputSize,osCheck,tempOutputSize);*/
+	remaining=expandLzg(input/*.data,input.size*/,&tempOutput,&tempOutputSize);
+	/*printf("Call:\n return=%d function input.data size=%d\n internal output size=%d result output size=%d\n",
+		remaining,input.size,osCheck,tempOutputSize);*/
 	/*if ((osCheck+6)!=tempOutputSize)
 		printf(" Special case: more is coming\n");*/
 
@@ -235,7 +236,7 @@ int pop2decompress(const unsigned char* input, int inputSize, int verify, unsign
 			/*printf(" error: aux=%d tempOutputSize=%d\n",aux,tempOutputSize);*/
 			return PR_RESULT_COMPRESS_RESULT_WARNING;
 		}
-		aux2= expandRleV(lineI,aux,lineO,&lineSize);
+		aux2=expandRleV(lineI,aux,lineO,&lineSize);
 		/*if (aux2) printf(" error: rle=%d linesize=%d of %d. size=%d r=%d.\n",aux2, lineSize,verify,tempOutputSize,tempOutputSize-aux-2);*/
 		lineO+=lineSize;
 		*outputSize+=lineSize;
@@ -245,10 +246,15 @@ int pop2decompress(const unsigned char* input, int inputSize, int verify, unsign
 	} while (lineSize==verify && tempOutputSize>0);
 	/*printf(" return: linesize=%d verify=%d tempOutputSize=%d\n", lineSize, verify, tempOutputSize);*/
 	if (remaining) {
-		const unsigned char* start=input+(inputSize-0)-remaining;
+		/*const unsigned char* start=input.data+(input.size+2)-remaining;*/
+		tBinary tail;
+
+		tail.data=input.data+(input.size+2-remaining);
+		tail.size=remaining;
+
 		/*printf("Remaining tailing data: size=%d first=%02x %02x\n", remaining,start[0],start[1]);*/
 		tempOutputSize=0;
-		remaining=expandLzg(start,remaining,&tempOutput,&tempOutputSize);
+		expandLzg(tail/*.data,tail.size*/,&tempOutput,&tempOutputSize); /* TODO: check error output */
 
 		lineI=tempOutput;
 
@@ -279,8 +285,8 @@ int pop2decompress(const unsigned char* input, int inputSize, int verify, unsign
 /*
 	printf("rle=%d\n", expandRleC(tempOutput,tempOutputSize,output,outputSize,verify));
 
-	printf("lzg=%d\n", os3=expandLzg(input+8+is-8-os3+2,os3-2,&output,&os));
-	osCheck=input[7+is-8-os3+2]<<8|input[6+is-8-os3+2];
+	printf("lzg=%d\n", os3=expandLzg(input.data+8+is-8-os3+2,os3-2,&output,&os));
+	osCheck=input.data[7+is-8-os3+2]<<8|input.data[6+is-8-os3+2];
 
 	printf("rle=%d osCheck=%d\n", expandRleC(output,os,&output2,&os2,verify), osCheck);
 	fwrite(output2,os2,1,out);
@@ -310,7 +316,7 @@ void* objectImage256Create(tBinary cont, int *error) { /* use get like main.c */
 	image=(tImage*)malloc(sizeof(tImage));
 
 	/* Expand graphic and check results */
-	*error=mExpandGraphic256(cont.data,image,cont.size); /* TODO: pass tBinary */
+	*error=mExpandGraphic256(cont,image);
 /*	if ((result==COMPRESS_RESULT_WARNING)&&hasFlag(verbose_flag))
 		fprintf(outputStream,PR_TEXT_EXPORT_BMP_WARN);*/
 	if (*error==PR_RESULT_COMPRESS_RESULT_FATAL) {
@@ -338,8 +344,8 @@ void* objectImage256Create(tBinary cont, int *error) { /* use get like main.c */
 tColor* objPalette_256() {
 	static tColor c[256]={{0,0,0},{0,0,0}};
 	int i;
-	if (!c[2].r)
-		for (i=0;i<256;i++) { /* The greyscale */
+	if (!c[1].r)
+		for (i=0;i<256;i++) { /* The grayscale */
 			c[i].r=i;
 			c[i].g=i;
 			c[i].b=i;
@@ -381,7 +387,7 @@ void* objectImage256Read(const char* file,tObject palette, int *result) {
 	int colors;
 
 	*result=readBmp(file,&(image->pix),&(image->height),&(image->width),&(image->bits),&colors,&colorArray,&(image->widthInBytes));
-	/* check if image was succesfully read loaded */
+	/* check if image was successfully read loaded */
 	if (*result!=PR_RESULT_SUCCESS) {
 		free(image);
 		return NULL;
diff --git a/PR/src/lib/object/image/image_common.c b/PR/src/lib/object/image/image_common.c
index 0ed1722..85db446 100644
--- a/PR/src/lib/object/image/image_common.c
+++ b/PR/src/lib/object/image/image_common.c
@@ -204,11 +204,11 @@ int mExpandGraphic(tBinary input, tImage *image) {
 			cmp_transposeImage(image,imageSizeInBytes);
 			break;
 		case COMPRESS_LZG_LR: /* LZ Groody Left to Right Compression Algorithm */
-			result=expandLzg(input.data,input.size,&(image->pix),&imageSizeInBytes);
+			result=expandLzg(input/*.data,input.size*/,&(image->pix),&imageSizeInBytes);
 			checkSize;
 			break;
 		case COMPRESS_LZG_UD: /* LZ Groody Up to Down Compression Algorithm */
-			result=expandLzg(input.data,input.size,&(image->pix),&imageSizeInBytes);
+			result=expandLzg(input/*.data,input.size*/,&(image->pix),&imageSizeInBytes);
 			checkResult;
 			checkSize;
 			cmp_transposeImage(image,imageSizeInBytes);
@@ -220,7 +220,7 @@ int mExpandGraphic(tBinary input, tImage *image) {
 	return result; /* Ok */
 }
 
-/* Compress an image into binary data */
+/* Compress an image into binary data TODO: send to common image */
 int mCompressGraphic(tBinary* input, tBinary* output, int ignoreFirstBytes, int w, int h) {
 /*								unsigned char* *data,tImage* image, int* dataSizeInBytes, int ignoreFirstBytes) {*/
 	/* Declare variables */
diff --git a/PR/src/ports/winfiles/pr.dev b/PR/src/ports/winfiles/pr.dev
index 224c288..d8f1d23 100644
--- a/PR/src/ports/winfiles/pr.dev
+++ b/PR/src/ports/winfiles/pr.dev
@@ -933,7 +933,7 @@ BuildCmd=
 Major=1
 Minor=3
 Release=0
-Build=60
+Build=70
 LanguageID=2057
 CharsetID=1252
 CompanyName=Princed development team