git » fp-git.git » commit af174c2

hooked the priority list in the export code. Not tested.

author ecalot
2006-06-14 23:32:58 UTC
committer ecalot
2006-06-14 23:32:58 UTC
parent abad8511aa75e0dcb4942fc9d36e88be5f0d775a

hooked the priority list in the export code. Not tested.

PR/src/include/object.h +2 -0
PR/src/include/types.h +1 -1
PR/src/lib/actions/export.c +27 -16
PR/src/lib/object/object.c +3 -3

diff --git a/PR/src/include/object.h b/PR/src/include/object.h
index bc54ad7..97d4eda 100644
--- a/PR/src/include/object.h
+++ b/PR/src/include/object.h
@@ -46,4 +46,6 @@ int paletteGetBits(tObject pal);
 int paletteGetColors(tObject pal);
 tColor* paletteGetColorArray(tObject pal);
 
+int getColorsByType(tResourceType type);
+
 #endif
diff --git a/PR/src/include/types.h b/PR/src/include/types.h
index 1dcf0a5..8ec0b56 100644
--- a/PR/src/include/types.h
+++ b/PR/src/include/types.h
@@ -52,7 +52,7 @@ typedef struct {
 typedef struct {
 	tResourceId        id;
 	tResourceId        paletteId;
-	tObject            palette;
+	tObject*           palette;
 	tBinary            content;
 	unsigned long int  offset; /* Used internally in dat.c to remember the offset */
 	unsigned char      number; /* Used for level number */
diff --git a/PR/src/lib/actions/export.c b/PR/src/lib/actions/export.c
index 6a0cc81..c62f7e6 100644
--- a/PR/src/lib/actions/export.c
+++ b/PR/src/lib/actions/export.c
@@ -108,35 +108,46 @@ int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int opti
 				res.datAuthor=vDatAuthor;
 
 				/* handle palette linking */
-				switch (res.type) { /* TODO: use if and elsif */
+				switch (res.type) {
 					case eResTypePop2Palette4bits: 
 					case eResTypePop2PaletteNColors: 
 					case eResTypePop1Palette4bits: { /* save and remember palette file */
-						tPaletteListItem e; /* TODO: decide if the palette list has to be erased from the code */
+						/*tPaletteListItem e; * deprecated */
 						o=getObject(&res,&ok);
 						if (!ok) { /* if SUCCESS remember the palette, otherwise keep using the default one */
-							e.pal=currentPalette=o;
+
+							pl_add(&palettes,&o,res.id,lowPriority);
+							/*e.pal=currentPalette=o;
 							e.id=res.id;
-							/*list_insert(&paletteBuffer,(void*)&e);*/
+							list_insert(&paletteBuffer,(void*)&e);*/
 						}
 					}	break;
 					case eResTypeImage16: /* save image */
-					case eResTypeImage256: /* 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;
-							otherPalette.id=res.paletteId;
+/*						if (resourceListCompareId(res.paletteId,bufferedPalette) * add &&!paletteCheckCompatibility(currentPalette,image) *) { * The palette isn't in the buffer */
+						tResource otherPalette;
+						int priorityRight;
+						otherPalette.id=res.paletteId; /* TODO: use the try system */
 							/* Read the palette and load it into memory */
-							if (mReadFileInDatFileId(&otherPalette)==PR_RESULT_SUCCESS) {
-								tPaletteListItem e;
-								resourceListAddInfo(r,&otherPalette);
+						if (mReadFileInDatFileId(&otherPalette)==PR_RESULT_SUCCESS) {
+							o=getObject(&otherPalette,&ok);
+							pl_add(&palettes,&o,res.paletteId,highPriority);
+
+								/*tPaletteListItem e;
+								resourceListAddInfo(r,&otherPalette);*/
 								/* All right, it's not so bad, I can handle it! I'll buffer the new palette */
-								e.pal=currentPalette=getObject(&otherPalette,&ok);
-								e.id=res.id;
+								/*e.pal=currentPalette=getObject(&otherPalette,&ok);
+								e.id=res.id;*/
 								/*list_insert(&paletteBuffer,(void*)&e);*/
-							} /* else, that's bad, I'll have to use the previous palette, even if it is the default */
-						} /* else, good, the palette is buffered */
-						res.palette=currentPalette;
+						} /* else, that's bad, I'll have to use the previous palette, even if it is the default */
+						 /* else, good, the palette is buffered */
+						/*res.palette=currentPalette;*/
+						res.palette=pl_get(&palettes,&priorityRight,getColorsByType(res.type));
+						if (!priorityRight) {
+							printf("Warning: the selected palette can't be applied to the image\n");
+						}
+					}
 					default:
 						o=getObject(&res,&ok);
 						break;
diff --git a/PR/src/lib/object/object.c b/PR/src/lib/object/object.c
index 1f10bcb..ceeaff9 100644
--- a/PR/src/lib/object/object.c
+++ b/PR/src/lib/object/object.c
@@ -82,10 +82,10 @@ tObject getObject(tResource* r, int* error) {
 		o.obj=objImage2Create(r->content,error);
 		break;
 	case eResTypeImage16: /* save image */
-		o.obj=objImage16Create(r->content,r->palette,error);
+		o.obj=objImage16Create(r->content,*r->palette,error);
 		break;
 	case eResTypeImage256: /* save image */
-		o.obj=objImage256Create(r->content,r->palette,error);
+		o.obj=objImage256Create(r->content,*r->palette,error);
 		break;
 	default:
 printf("Exception: Unhooked type %d\n",o.type);
@@ -226,7 +226,7 @@ tObject readObject(const char* file,tResource* res,int *result) {
 			/*o.obj=objLevelRead(file,res.content,result); TODO */
 			break;
 		case eResTypeImage16:
-			o.obj=objImage16Read(file,res->palette,result);
+			o.obj=objImage16Read(file,*res->palette,result);
 			break;
 		case eResTypeWave:
 			o.obj=objWaveRead(file,result);