git » fp-git.git » commit 6d6e8de

forked image to support different types

author ecalot
2006-03-06 07:02:42 UTC
committer ecalot
2006-03-06 07:02:42 UTC
parent 6e73c204d456cff2e4a078a469c10c304cc0bbc3

forked image to support different types

PR/src/Makefile +8 -4
PR/src/lib/object/image/image16.c +0 -32
PR/src/lib/object/image/image2.c +0 -32
PR/src/lib/object/image/image256.c +12 -163
PR/src/lib/object/image/image_common.c +0 -32

diff --git a/PR/src/Makefile b/PR/src/Makefile
index d04c3d0..afa0f68 100644
--- a/PR/src/Makefile
+++ b/PR/src/Makefile
@@ -56,7 +56,7 @@ XML      = .parse.o .search.o .unknown.o .translate.o .tree.o
 COMPRESS = .lzg_compress.o .lzg_uncompress.o .rle_compress.o .rle_uncompress.o .rlec_uncompress.o 
 LAYERS   = .dat.o .memory.o .list.o .reslist.o .pallist.o .disk.o .idlist.o .autodetect.o .stringformat.o .resourcematch.o
 FORMAT   = .bmp.o .mid.o .pal.o .wav.o .plv.o
-OBJECT   = .object.o .pop1_4bit.o .image.o .binary.o .sounds.o .level.o
+OBJECT   = .object.o .pop1_4bit.o .image16.o .image256.o .binary.o .sounds.o .level.o
 CONSOLE  = .main.o .filedir.o
 MAIN     = .pr.o
 
@@ -170,9 +170,13 @@ $(XMLFILE): xml/resources.xml
 	$(INFO) Compiling main item class...
 	$(CC) $(OPTIONS) -c lib/object/main.c -o $@
 
-.image.o: lib/object/image/image.c include/image.h include/compress.h include/disk.h include/memory.h
-	$(INFO) Compiling image type class...
-	$(CC) $(OPTIONS) -c lib/object/image/image.c -o $@
+.image16.o: lib/object/image/image16.c include/image.h include/compress.h include/disk.h include/memory.h
+	$(INFO) Compiling 16 colors image type class...
+	$(CC) $(OPTIONS) -c lib/object/image/image16.c -o $@
+
+.image256.o: lib/object/image/image256.c include/image.h include/compress.h include/disk.h include/memory.h
+	$(INFO) Compiling 256 colors image type class...
+	$(CC) $(OPTIONS) -c lib/object/image/image256.c -o $@
 
 .lzg_compress.o: lib/compression/lzg_compress.c include/compress.h
 	$(INFO) Compiling LZG compression module...
diff --git a/PR/src/lib/object/image/image16.c b/PR/src/lib/object/image/image16.c
index 453c749..b3bc79e 100644
--- a/PR/src/lib/object/image/image16.c
+++ b/PR/src/lib/object/image/image16.c
@@ -181,10 +181,6 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes)
 		return COMPRESS_RESULT_FATAL;
 	}
 
-	/* special format has a special function */
-	if (image->type==0xf3)
-		return pop2decompress(data,dataSizeInBytes-6,image->width,&(image->pix),&imageSizeInBytes);
-
 #define checkSize if (imageSizeInBytes!=(image->widthInBytes*image->height))\
 	return COMPRESS_RESULT_FATAL
 #define checkResult if (result==COMPRESS_RESULT_FATAL)\
@@ -348,34 +344,6 @@ int mCompressGraphic(tBinary* input, tBinary* output, int ignoreFirstBytes, int
 	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 */
-	unsigned char* tempOutput;
-
-	int tempOutputSize;
-	int osCheck;
-
-	osCheck=array2short(input)-6;
-	input+=2;
-
-	/*os=osCheck;*/
-	tempOutputSize=0;
-	printf("lzg=%d is=%d osc=%d\n", expandLzg(input,inputSize-2,&tempOutput,&tempOutputSize),inputSize,osCheck);
-
-	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("rle=%d osCheck=%d\n", expandRleC(output,os,&output2,&os2,verify), osCheck);
-	fwrite(output2,os2,1,out);
-
-	fclose(out);
-
-	printf("os=%d oscheck=%d\n",os,osCheck);*/
-	return COMPRESS_RESULT_SUCCESS;
-}
-
 extern FILE* outputStream;
 
 void* objImageCreate(tBinary cont, tObject palette, int *error) { /* use get like main.c */
diff --git a/PR/src/lib/object/image/image2.c b/PR/src/lib/object/image/image2.c
index 453c749..b3bc79e 100644
--- a/PR/src/lib/object/image/image2.c
+++ b/PR/src/lib/object/image/image2.c
@@ -181,10 +181,6 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes)
 		return COMPRESS_RESULT_FATAL;
 	}
 
-	/* special format has a special function */
-	if (image->type==0xf3)
-		return pop2decompress(data,dataSizeInBytes-6,image->width,&(image->pix),&imageSizeInBytes);
-
 #define checkSize if (imageSizeInBytes!=(image->widthInBytes*image->height))\
 	return COMPRESS_RESULT_FATAL
 #define checkResult if (result==COMPRESS_RESULT_FATAL)\
@@ -348,34 +344,6 @@ int mCompressGraphic(tBinary* input, tBinary* output, int ignoreFirstBytes, int
 	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 */
-	unsigned char* tempOutput;
-
-	int tempOutputSize;
-	int osCheck;
-
-	osCheck=array2short(input)-6;
-	input+=2;
-
-	/*os=osCheck;*/
-	tempOutputSize=0;
-	printf("lzg=%d is=%d osc=%d\n", expandLzg(input,inputSize-2,&tempOutput,&tempOutputSize),inputSize,osCheck);
-
-	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("rle=%d osCheck=%d\n", expandRleC(output,os,&output2,&os2,verify), osCheck);
-	fwrite(output2,os2,1,out);
-
-	fclose(out);
-
-	printf("os=%d oscheck=%d\n",os,osCheck);*/
-	return COMPRESS_RESULT_SUCCESS;
-}
-
 extern FILE* outputStream;
 
 void* objImageCreate(tBinary cont, tObject palette, int *error) { /* use get like main.c */
diff --git a/PR/src/lib/object/image/image256.c b/PR/src/lib/object/image/image256.c
index 453c749..3e4b267 100644
--- a/PR/src/lib/object/image/image256.c
+++ b/PR/src/lib/object/image/image256.c
@@ -96,46 +96,6 @@ image.c: Princed Resources : Image Compression Library
 
 int pop2decompress(const unsigned char* input, int inputSize, int verify, unsigned char** output,int* outputSize); 
 
-/***************************************************************\
-|                   Compression Level Manager                   |
-\***************************************************************/
-
-int compressionLevel=3;
-int compressionHigher;
-
-void setCompressionLevel(int cl) {
-	compressionLevel=cl;
-}
-
-/***************************************************************\
-|                        Image transpose                        |
-\***************************************************************/
-
-/* Determines where the transposed byte must be saved */
-int cmp_transpose(int x,int w,int h) {
-	return ((x%h)*(w))+(int)(x/h);
-}
-
-void cmp_transposeImage(tImage* image,int size) {
-	unsigned char* outputaux=getMemory(size);
-	int cursor;
-
-	for (cursor=0;cursor<size;cursor++)
-		outputaux[cmp_transpose(cursor,image->widthInBytes,image->height)]=image->pix[cursor];
-	free(image->pix);
-	image->pix=outputaux;
-}
-
-void cmp_antiTransposeImage(tBinary* b, int widthInBytes, int height) {
-	unsigned char* outputaux=getMemory(b->size);
-	int cursor;
-
-	for (cursor=0;cursor<b->size;cursor++)
-		outputaux[cursor]=b->data[cmp_transpose(cursor,widthInBytes,height)];
-	free(b->data);
-	b->data=outputaux;
-}
-
 /***************************************************************\
 |               Main compress and expand graphics               |
 \***************************************************************/
@@ -150,14 +110,13 @@ void cmp_antiTransposeImage(tBinary* b, int widthInBytes, int height) {
  */
 
 /* Expands an array into an image */
-int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) {
+int mExpandGraphic256(const unsigned char* data,tImage *image, int dataSizeInBytes) {
 	/*
 	 * Reads data and extracts tImage
 	 * returns the next image address or -1 in case of error
 	 */
 
 	int imageSizeInBytes=0;
-	int result;
 
 	image->height=array2short(data);
 	data+=2;
@@ -182,50 +141,11 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes)
 	}
 
 	/* special format has a special function */
-	if (image->type==0xf3)
-		return pop2decompress(data,dataSizeInBytes-6,image->width,&(image->pix),&imageSizeInBytes);
-
-#define checkSize if (imageSizeInBytes!=(image->widthInBytes*image->height))\
-	return COMPRESS_RESULT_FATAL
-#define checkResult if (result==COMPRESS_RESULT_FATAL)\
-	return COMPRESS_RESULT_FATAL
-
-	switch (getAlgor(image->type)) {
-		case COMPRESS_RAW: /* No Compression Algorithm */
-			if ((image->pix=getMemory(dataSizeInBytes))==NULL) return COMPRESS_RESULT_FATAL;
-			memcpy(image->pix,data,dataSizeInBytes);
-			imageSizeInBytes=image->widthInBytes*image->height;
-			result=COMPRESS_RESULT_SUCCESS;
-			break;
-		case COMPRESS_RLE_LR: /* RLE Left to Right Compression Algorithm */
-			result=expandRle(data,dataSizeInBytes,&(image->pix),&imageSizeInBytes);
-			checkSize;
-			break;
-		case COMPRESS_RLE_UD: /* RLE Up to Down Compression Algorithm */
-			result=expandRle(data,dataSizeInBytes,&(image->pix),&imageSizeInBytes);
-			checkResult;
-			checkSize;
-			cmp_transposeImage(image,imageSizeInBytes);
-			break;
-		case COMPRESS_LZG_LR: /* LZ Groody Left to Right Compression Algorithm */
-			result=expandLzg(data,dataSizeInBytes,&(image->pix),&imageSizeInBytes);
-			checkSize;
-			break;
-		case COMPRESS_LZG_UD: /* LZ Groody Up to Down Compression Algorithm */
-			result=expandLzg(data,dataSizeInBytes,&(image->pix),&imageSizeInBytes);
-			checkResult;
-			checkSize;
-			cmp_transposeImage(image,imageSizeInBytes);
-			break;
-		default:
-			result=COMPRESS_RESULT_FATAL; /* unknown algorithm */
-			break;
-	}
-	return result; /* Ok */
+	return pop2decompress(data,dataSizeInBytes-6,image->width,&(image->pix),&imageSizeInBytes);
 }
 
 /* Compress an image into binary data */
-int mCompressGraphic(tBinary* input, tBinary* output, int ignoreFirstBytes, int w, int h) {
+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];
@@ -242,88 +162,17 @@ int mCompressGraphic(tBinary* input, tBinary* output, int ignoreFirstBytes, int
 	 * Perform all compressions
 	 */
 
-	/* Forward compression */
-
-	/* COMPRESS_RAW
-	 * The allocation size is the image size.
-	 * The algorithm is hard-coded.
-	 * There is no need to code a transposed version because
-	 * we have no compression to improve.
-	 */
-	compressed[COMPRESS_RAW]=getMemory(imageSizeInBytes);
-	compressedSize[COMPRESS_RAW]=imageSizeInBytes;
-	memcpy(compressed[COMPRESS_RAW],input->data,imageSizeInBytes);
-
-	/* COMPRESS_RLE_LR
-	 * If all the uncompressed data has a big entropy, there
-	 * will be a control byte for a block of 127 bytes.
-	 * The allocation size has a maximum value of the image
-	 * size plus a byte each 127 bytes.
-	 * This is accoted by 2*n+50
-	 */
-	cLevel(2) {
-		compressed[COMPRESS_RLE_LR]=getMemory((2*imageSizeInBytes+50));
-		compressRle(
-			input->data,imageSizeInBytes,
-			compressed[COMPRESS_RLE_LR],&(compressedSize[COMPRESS_RLE_LR])
-		);
-		max_alg++;
-	}
-	/* COMPRESS_LZG_LR
-	 * If all the uncompressed data has a big entropy, there
-	 * will be a maskbyte for a block of 8 bytes.
-	 * The allocation size has a maximum value of the image
-	 * size plus a byte in 8.
-	 * Additionally, this compressor needs 1024 bytes extra
-	 * allocated.
-	 * This is accoted by 2*n+1050
-	 */
-	cLevel(4) {
-		cLevel(6)
-			setHigh;
-		else
-			unsetHigh;
-		compressed[COMPRESS_LZG_LR]=getMemory((2*imageSizeInBytes+1050));
-		compressLzg(
-			input->data,imageSizeInBytes,
-			compressed[COMPRESS_LZG_LR],&(compressedSize[COMPRESS_LZG_LR])
-		);
-		max_alg++;
-	}
-
-	/* Transposed compression
-	 * Transposition is used to test the same compression
-	 * algorithms with other input in order to get a better
-	 * compression.
-	 * The following algorithms will be the same as above, but
-	 * using the image matrix transposed.
-	 */
-	cLevel(3)
-		cmp_antiTransposeImage(input,w,h);
-
-	/* COMPRESS_RLE_UD */
-	cLevel(3) {
-		compressed[COMPRESS_RLE_UD]=getMemory(2*imageSizeInBytes+50);
-		compressRle(
-			input->data,imageSizeInBytes,
-			compressed[COMPRESS_RLE_UD],&(compressedSize[COMPRESS_RLE_UD])
-		);
-		max_alg++;
-	}
-
 	/* COMPRESS_LZG_UD */
-	cLevel(5) {
-		cLevel(7)
+	/*	cLevel(7)
 			setHigh;
 		else
-			unsetHigh;
+			unsetHigh;*/
 		compressed[COMPRESS_LZG_UD]=getMemory(2*imageSizeInBytes+1050);
 		compressLzg(
 			input->data,imageSizeInBytes,
 			compressed[COMPRESS_LZG_UD],&(compressedSize[COMPRESS_LZG_UD])
 		);
 		max_alg++;
-	}
 	/*
 	 * Process results
 	 */
@@ -378,7 +227,7 @@ int pop2decompress(const unsigned char* input, int inputSize, int verify, unsign
 
 extern FILE* outputStream;
 
-void* objImageCreate(tBinary cont, tObject palette, int *error) { /* use get like main.c */
+void* objImage256Create(tBinary cont, tObject palette, int *error) { /* use get like main.c */
 
 	/*
 	 * This function will expand the data into an image structure,
@@ -393,7 +242,7 @@ void* objImageCreate(tBinary cont, tObject palette, int *error) { /* use get lik
 	image=(tImage*)malloc(sizeof(tImage));
 
 	/* Expand graphic and check results */
-	*error=mExpandGraphic(cont.data,image,cont.size); /* TODO: pass tBinary */
+	*error=mExpandGraphic256(cont.data,image,cont.size); /* TODO: pass tBinary */
 /*	if ((result==COMPRESS_RESULT_WARNING)&&hasFlag(verbose_flag))
 		fprintf(outputStream,PR_TEXT_EXPORT_BMP_WARN);*/
 	if (*error==COMPRESS_RESULT_FATAL) {
@@ -409,7 +258,7 @@ void* objImageCreate(tBinary cont, tObject palette, int *error) { /* use get lik
 	return (void*)image;
 }
 
-int objImageWrite(void* img,const char* file,int optionflag,const char* backupExtension) {
+int objImage256Write(void* img,const char* file,int optionflag,const char* backupExtension) {
 	tImage* i=img;
 	int bits;
 	int colors;
@@ -429,14 +278,14 @@ int objImageWrite(void* img,const char* file,int optionflag,const char* backupEx
 	return mWriteBmp(file,i->pix,i->width,i->height,bits,colors,colorArray,i->widthInBytes,optionflag,backupExtension);
 }
 
-void objImageFree(void* img) {
+void objImage256Free(void* img) {
 	if (!img) return;
 	/* free bitmap */
 	free(((tImage*)img)->pix);
 	free(img);
 }
 
-void* objImageRead(const char* file,tObject palette, int *result) {
+void* objImage256Read(const char* file,tObject palette, int *result) {
 	int bits;
 	tImage* image=(tImage*)malloc(sizeof(tImage));
 	tColor* colorArray;
@@ -469,7 +318,7 @@ void* objImageRead(const char* file,tObject palette, int *result) {
 	/* TODO: generate image->type in objImageSet */
 
 /*int mFormatImportBmp(tResource *res) { --> objImageSet */
-int objImageSet(void* o,tResource* res) {
+int objImage256Set(void* o,tResource* res) {
 	tImage* img=o;
 	tBinary decompressed,compressed;
 	int algorithm;
@@ -477,7 +326,7 @@ int objImageSet(void* o,tResource* res) {
 	decompressed.data=img->pix;
 	decompressed.size=img->widthInBytes*img->height;
 	
-	algorithm=mCompressGraphic(&decompressed,&compressed,6,img->widthInBytes,img->height);
+	algorithm=mCompressGraphic256(&decompressed,&compressed,6,img->widthInBytes,img->height);
 
 	/*
 	 * Write header
diff --git a/PR/src/lib/object/image/image_common.c b/PR/src/lib/object/image/image_common.c
index 453c749..b3bc79e 100644
--- a/PR/src/lib/object/image/image_common.c
+++ b/PR/src/lib/object/image/image_common.c
@@ -181,10 +181,6 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes)
 		return COMPRESS_RESULT_FATAL;
 	}
 
-	/* special format has a special function */
-	if (image->type==0xf3)
-		return pop2decompress(data,dataSizeInBytes-6,image->width,&(image->pix),&imageSizeInBytes);
-
 #define checkSize if (imageSizeInBytes!=(image->widthInBytes*image->height))\
 	return COMPRESS_RESULT_FATAL
 #define checkResult if (result==COMPRESS_RESULT_FATAL)\
@@ -348,34 +344,6 @@ int mCompressGraphic(tBinary* input, tBinary* output, int ignoreFirstBytes, int
 	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 */
-	unsigned char* tempOutput;
-
-	int tempOutputSize;
-	int osCheck;
-
-	osCheck=array2short(input)-6;
-	input+=2;
-
-	/*os=osCheck;*/
-	tempOutputSize=0;
-	printf("lzg=%d is=%d osc=%d\n", expandLzg(input,inputSize-2,&tempOutput,&tempOutputSize),inputSize,osCheck);
-
-	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("rle=%d osCheck=%d\n", expandRleC(output,os,&output2,&os2,verify), osCheck);
-	fwrite(output2,os2,1,out);
-
-	fclose(out);
-
-	printf("os=%d oscheck=%d\n",os,osCheck);*/
-	return COMPRESS_RESULT_SUCCESS;
-}
-
 extern FILE* outputStream;
 
 void* objImageCreate(tBinary cont, tObject palette, int *error) { /* use get like main.c */