git » fp-git.git » commit 6e73c20

added new types for different images

author ecalot
2006-03-06 05:12:43 UTC
committer ecalot
2006-03-06 05:12:43 UTC
parent 802fd999f0b793fd54a0a1a46b4e6ba6511258a7

added new types for different images

PR/src/include/common.h +3 -1
PR/src/include/dat.h +2 -1
PR/src/include/other.h +1 -0
PR/src/include/pr.h +2 -1
PR/src/lib/actions/export.c +3 -1
PR/src/lib/formats/plv.c +4 -1
PR/src/lib/layers/autodetect.c +2 -2
PR/src/lib/layers/dat.c +9 -10
PR/src/lib/object/object.c +5 -4
PR/src/lib/xml/parse.c +6 -1
PR/src/lib/xml/search.c +14 -0

diff --git a/PR/src/include/common.h b/PR/src/include/common.h
index d61a48e..b2d0c7a 100644
--- a/PR/src/include/common.h
+++ b/PR/src/include/common.h
@@ -87,7 +87,9 @@ typedef enum {
 	eResTypeNone=-1,
 	eResTypeRaw=0,
 	eResTypeLevel=1,
-	eResTypeImage=2,
+	eResTypeImage16=2,
+	eResTypeImage2=12,
+	eResTypeImage256=13,
 	eResTypeWave=3,
 	eResTypeMidi=4,
 	eResTypeBinary=5,
diff --git a/PR/src/include/dat.h b/PR/src/include/dat.h
index 167ca07..aba356d 100644
--- a/PR/src/include/dat.h
+++ b/PR/src/include/dat.h
@@ -46,7 +46,8 @@ typedef enum {
 tPopVersion mReadGetVersion();
 
 /* CheckSum verification */
-int checkSum(const unsigned char* data,int size);
+int checkSum(const unsigned char* data,int size); /* True or false if the checksum is right */
+unsigned char getChecksum(tBinary c); /* return the checksum value */
 
 #define PR_DAT_INCLUDE_DATREAD
 #define PR_DAT_INCLUDE_DATWRITE
diff --git a/PR/src/include/other.h b/PR/src/include/other.h
index 7528bae..1512159 100644
--- a/PR/src/include/other.h
+++ b/PR/src/include/other.h
@@ -41,5 +41,6 @@ void* objBinaryRead(const char* file,int *result);
 int objBinarySet(void* o,tResource* res);
 
 void* objLevelCreate(tBinary content,int number,const char* datfile,const char* name,const char* desc,const char* datAuthor,int *error); /* TODO: move to level.h */ 
+int objLevelWrite(void* o, const char* file, int optionflag, const char* backupExtension);
 
 #endif
diff --git a/PR/src/include/pr.h b/PR/src/include/pr.h
index a0c8398..3a470a1 100644
--- a/PR/src/include/pr.h
+++ b/PR/src/include/pr.h
@@ -61,6 +61,7 @@ typedef struct tTag {
 	char* version;
 	char* number;
 	char* flags;
+	char* colors;
 }tTag;
 
 /***************************************************************\
@@ -108,7 +109,7 @@ void  freeTagStructure    (tTag* structure);
 void  freeXmlCache        ();
 void  resourceTreeFixInheritances(tTag* *tree);
 tTag* resourceTreeGetChild(tTag* whereAmI);
-int   resourceTreeGetInfo (tTag* whereAmI,	char** tag, char** desc, char** path, char** file, char** type, char** name, char** palette, char** value, char** version, char** number);
+int   resourceTreeGetInfo (tTag* whereAmI, char** tag, char** desc, char** path, char** file, char** type, char** name, char** palette, char** value, char** version, char** number,char** colors);
 tTag* resourceTreeGetNext (tTag* whereAmI);
 void  xmlOptimizeCommonFactor    (tTag* tag);
 int   xmlGenerateFile     (const char* vFile,const tTag* t);
diff --git a/PR/src/lib/actions/export.c b/PR/src/lib/actions/export.c
index 810a4c3..6690bd8 100644
--- a/PR/src/lib/actions/export.c
+++ b/PR/src/lib/actions/export.c
@@ -120,7 +120,9 @@ int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int opti
 						e.id=res.id;
 						list_insert(&paletteBuffer,(void*)&e);
 					}	break;
-					case eResTypeImage: /* save image */
+					case eResTypeImage16: /* save image */
+					case eResTypeImage2: /* save image */
+					case eResTypeImage256: /* save image */
 						/* Palette handling */
 						if (resourceListCompareId(res.paletteId,bufferedPalette) /*TODO: add &&!paletteCheckCompatibility(currentPalette,image) */) { /* The palette isn't in the buffer */
 							tResource otherPalette;
diff --git a/PR/src/lib/formats/plv.c b/PR/src/lib/formats/plv.c
index 662bb35..597c11c 100644
--- a/PR/src/lib/formats/plv.c
+++ b/PR/src/lib/formats/plv.c
@@ -96,6 +96,7 @@ int writePlv(const char* file, tBinary content, int popversion, const char* datf
 	int ok;
 	unsigned char sizeOfNow;
 	char* now;
+	unsigned char checksum;
 	char levelnum[10];
 	const char* nullString="";
 	static const char* author=PLV_DEFAULT_AUTHOR;
@@ -132,6 +133,8 @@ int writePlv(const char* file, tBinary content, int popversion, const char* datf
 	ok=ok&&fwritelong(&content.size,target);
 
 	/* Write block 1: raw data without ignoring checksum */
+	checksum=getChecksum(content);
+	ok=ok&&fwritechar(&checksum,target);
 	ok=ok&&fwrite(content.data,content.size,1,target);
 
 	/* Write footers */
@@ -165,7 +168,7 @@ int writePlv(const char* file, tBinary content, int popversion, const char* datf
 
 	/* Close file and return */
 	ok=ok&&(!writeCloseOk(target,optionflag,backupExtension));
-	return ok;
+	return ok?PR_RESULT_SUCCESS:PR_RESULT_ERR_FILE_NOT_WRITE_ACCESS;
 }
 
 extern FILE* outputStream;
diff --git a/PR/src/lib/layers/autodetect.c b/PR/src/lib/layers/autodetect.c
index 6442f28..c2919ba 100644
--- a/PR/src/lib/layers/autodetect.c
+++ b/PR/src/lib/layers/autodetect.c
@@ -98,10 +98,10 @@ int verifyMidiHeader(tBinary c) {
 	;
 }
 
-tResourceType verifyHeader(tBinary c) {
+tResourceType verifyHeader(tBinary c) { /* TODO: add the pop version as another parameter to detect types */
 	if (verifyLevelHeader  (c)) return eResTypeLevel;
 	if (verifyMidiHeader   (c)) return eResTypeMidi;
-	if (verifyImageHeader  (c)) return eResTypeImage;
+	if (verifyImageHeader  (c)) return eResTypeImage16;
 	if (verifyPaletteHeader(c)) return eResTypePop1Palette4bits;
 	if (verifyWaveHeader   (c)) return eResTypeWave;
 	if (verifySpeakerHeader(c)) return eResTypePcspeaker;
diff --git a/PR/src/lib/layers/dat.c b/PR/src/lib/layers/dat.c
index 1c8536a..d6cecbe 100644
--- a/PR/src/lib/layers/dat.c
+++ b/PR/src/lib/layers/dat.c
@@ -556,23 +556,22 @@ void mWriteFileInDatFileIgnoreChecksum(const tResource* res) {
 	dat_write(&aux,res->content.data[0]);
 }
 
+unsigned char getChecksum(tBinary c) {
+	unsigned char  checksum = 0;
+
+	/* calculates the checksum */
+	while (c.size--) checksum+=*(c.data++);
+	return ~checksum;
+}
+
 void mWriteFileInDatFile(const tResource* res) {
 	/*
 	 * Adds a data resource to a DAT file keeping
 	 * abstractly the checksum verifications
 	 */
 
-	/* Declare variables */
-	int            k        = res->content.size;
-	unsigned char  checksum = 0;
-	const unsigned char* dataAux  = res->content.data;
-
-	/* calculates the checksum */
-	while (k--) checksum+=*(dataAux++);
-	checksum=~checksum;
-
 	/* write the resource contents */
-	dat_write(res,checksum);
+	dat_write(res,getChecksum(res->content));
 }
 
 void mWriteCloseDatFile(int dontSave,int optionflag, const char* backupExtension) {
diff --git a/PR/src/lib/object/object.c b/PR/src/lib/object/object.c
index eafcdbf..2d5044c 100644
--- a/PR/src/lib/object/object.c
+++ b/PR/src/lib/object/object.c
@@ -72,7 +72,7 @@ tObject getObject(tResource* r, int* error) {
 	case eResTypeWave: /* save wav file */
 		o.obj=objWaveCreate(r->content,error);
 		break;
-	case eResTypeImage: /* save image */
+	case eResTypeImage16: /* save image */
 		o.obj=objImageCreate(r->content,r->palette,error);
 		break;
 	default:
@@ -86,6 +86,7 @@ int writeObject(tObject o, const char* file, int optionflag, const char* backupE
 	int error;
 	switch (o.type) {
 	case eResTypeLevel:
+		error=objLevelWrite(o.obj,file,optionflag,backupExtension);
 		break;
 	case eResTypeBinary: /* Binary files */
 	case eResTypeText: /* Text files */
@@ -104,7 +105,7 @@ int writeObject(tObject o, const char* file, int optionflag, const char* backupE
 	case eResTypeWave: /* save wav file */
 		error=objWaveWrite(o.obj,file,optionflag,backupExtension);
 		break;
-	case eResTypeImage: /* save image */
+	case eResTypeImage16: /* save image */
 		error=objImageWrite(o.obj,file,optionflag,backupExtension);
 		break;
 	default:
@@ -158,7 +159,7 @@ void setObject(tObject o,int *result,tResource* res) {
 		case eResTypeLevel:
 			/*o.obj=objLevelRead(file,res.content,result);*/
 			break;
-		case eResTypeImage:
+		case eResTypeImage16:
 			*result=objImageSet(o.obj,res);
 			break;
 		case eResTypeWave:
@@ -189,7 +190,7 @@ tObject readObject(const char* file,tResource* res,int *result) {
 		case eResTypeLevel:
 			/*o.obj=objLevelRead(file,res.content,result);*/
 			break;
-		case eResTypeImage:
+		case eResTypeImage16:
 			o.obj=objImageRead(file,res->palette,result);
 			break;
 		case eResTypeWave:
diff --git a/PR/src/lib/xml/parse.c b/PR/src/lib/xml/parse.c
index 997c78d..8e09cac 100644
--- a/PR/src/lib/xml/parse.c
+++ b/PR/src/lib/xml/parse.c
@@ -125,6 +125,7 @@ void freeTagStructure(tTag* t) {
 	freeAllocation(t->version);
 	freeAllocation(t->number);
 	freeAllocation(t->flags);
+	freeAllocation(t->colors);
 	free(t);
 }
 
@@ -157,6 +158,7 @@ int parse_attribFill(char* attr,char* val, tTag* t) {
 	parse_FillAttr(t->number,"levelnumber"); /* levelnumber is a number alias */
 	parse_FillAttr(t->number,"number");
 	parse_FillAttr(t->flags,"flags");
+	parse_FillAttr(t->colors,"colors");
 
 	return PR_RESULT_ERR_XML_ATTR;
 }
@@ -373,6 +375,7 @@ tTag* parse_makeTree(char** p,char* name, int* error,tTag* father) {
 	parse_TotalInheritance(index);
 	parse_TotalInheritance(order);
 	parse_TotalInheritance(flags);
+	parse_TotalInheritance(colors);
 	/* parse_PartialConcatInheritance(tag->path,father->path,tag->value); */
 	if ((tag->value==NULL /*is folder */)||(tag->path!=NULL)) {
 		char* str;
@@ -577,7 +580,7 @@ tTag* resourceTreeGetChild(tTag* whereAmI) {
 	return whereAmI->child;
 }
 
-int   resourceTreeGetInfo (tTag* whereAmI, char** tag, char** desc, char** path, char** file, char** type, char** name, char** palette, char** value, char** version, char** number) {
+int   resourceTreeGetInfo (tTag* whereAmI, char** tag, char** desc, char** path, char** file, char** type, char** name, char** palette, char** value, char** version, char** number,char** colors) {
 	if (whereAmI==NULL) return 0; /* false */
 	*tag=whereAmI->tag;
 	*desc=whereAmI->desc;
@@ -589,5 +592,7 @@ int   resourceTreeGetInfo (tTag* whereAmI, char** tag, char** desc, char** path,
 	*value=whereAmI->value;
 	*version=whereAmI->version;
 	*number=whereAmI->number;
+	*colors=whereAmI->colors;
 	return 1; /* true */
 }
+
diff --git a/PR/src/lib/xml/search.c b/PR/src/lib/xml/search.c
index 9c5bd72..39edc8c 100644
--- a/PR/src/lib/xml/search.c
+++ b/PR/src/lib/xml/search.c
@@ -118,6 +118,20 @@ printf("tv=%s ti=%s tag=%s\n",t->value,t->index,t->tag);*/
 				res.type=i;
 		/* If error it returns 0 and the verifyHeader will try to detect the type */
 	}
+	if (res.type==eResTypeImage16) {
+		switch (ptoi(t->colors)) {
+		case 2:
+			res.type=eResTypeImage2;
+			break;										
+		case 256:
+			res.type=eResTypeImage256;
+			break;										
+		case 16:
+		default:
+			res.type=eResTypeImage16;
+			break;	
+		}
+	}
 #endif
 
 	/* Get the order */