git » fp-git.git » commit bec6ba2

finished pop2 4bit palette for extraction

author ecalot
2006-06-10 03:27:32 UTC
committer ecalot
2006-06-10 03:27:32 UTC
parent d9aa93af22387d59f4a9cd18cfd94f5098f878c7

finished pop2 4bit palette for extraction

PR/src/lib/layers/autodetect.c +7 -2
PR/src/lib/object/palette/pop1_16c.c +2 -2
PR/src/lib/object/palette/pop2_4bit.c +11 -10

diff --git a/PR/src/lib/layers/autodetect.c b/PR/src/lib/layers/autodetect.c
index 24ff977..b271d3d 100644
--- a/PR/src/lib/layers/autodetect.c
+++ b/PR/src/lib/layers/autodetect.c
@@ -76,7 +76,12 @@ int verifyPaletteHeaderPop1(tBinary c) {
 
 int verifyPaletteHeaderPop2(tBinary c) {
 	return (
-		(c.size==384)&&(c.data[0]==0x00)
+		(c.size>=(3*16)) &&
+		(c.data[0]==0x00) &&
+		(c.data[1]==0x00) &&
+		(c.data[2]==0x00) &&
+		(c.size % 3 == 0 ) &&
+		isA64kPalette(c)
 	);
 }
 
@@ -121,8 +126,8 @@ tResourceType verifyHeader(tBinary c) { /* TODO: add the pop version as another
 	if (verifyImage16Header  (c)) return eResTypeImage16;
 	if (verifyImage256Header (c)) return eResTypeImage256;
 	if (verifyPaletteHeaderPop1  (c)) return eResTypePop1Palette4bits;
-	if (verifyPaletteHeaderPop2  (c)) return eResTypePop2Palette4bits;
 	if (verifyPaletteHeaderPop2_256  (c)) return eResTypePop2PaletteNColors;
+	if (verifyPaletteHeaderPop2  (c)) return eResTypePop2Palette4bits;
 	if (verifyWaveHeader     (c)) return eResTypeWave;
 	if (verifySpeakerHeader  (c)) return eResTypePcspeaker;
 	return eResTypeBinary;
diff --git a/PR/src/lib/object/palette/pop1_16c.c b/PR/src/lib/object/palette/pop1_16c.c
index 6f52d9b..9099a90 100644
--- a/PR/src/lib/object/palette/pop1_16c.c
+++ b/PR/src/lib/object/palette/pop1_16c.c
@@ -277,8 +277,8 @@ int objPop1Palette4bitsSet(void* o,tResource* res) {
 		res->content.data[(i*3)+5]=convert24to18(pal->c[i].g);
 		res->content.data[(i*3)+6]=convert24to18(pal->c[i].b);
 	}
-	res->content.size=100;
-	res->content.data=pal->raw;
+/*	res->content.size=100;
+	res->content.data=pal->raw;*/
 	mWriteFileInDatFile(res);
 	return PR_RESULT_SUCCESS;
 }
diff --git a/PR/src/lib/object/palette/pop2_4bit.c b/PR/src/lib/object/palette/pop2_4bit.c
index 4ee54d2..46c9854 100644
--- a/PR/src/lib/object/palette/pop2_4bit.c
+++ b/PR/src/lib/object/palette/pop2_4bit.c
@@ -66,17 +66,17 @@ int readPalette(tPalette* p, unsigned char* data, int dataSize);
 
 typedef struct { 
 	tColor c[16];
-	unsigned char raw[384];
+	tBinary raw;
 }tPop2_4bitsPalette;
 
 void* objPalette_pop2_4bitsCreate(tBinary cont, int *error) {
 	int i;
 	tPop2_4bitsPalette* pal;
 	
-	if (cont.size!=384) {
+/*	if (cont.size!=384) {
 		*error=PR_RESULT_XML_AND_DAT_FORMAT_DO_NOT_MATCH;
 		return NULL;
-	}
+	} TODO: use the check from autodetect */
 
 	pal=(tPop2_4bitsPalette*)malloc(sizeof(tPop2_4bitsPalette));
 	
@@ -86,7 +86,8 @@ void* objPalette_pop2_4bitsCreate(tBinary cont, int *error) {
 		pal->c[i].b=cont.data[(i*3)+2]<<2;
 	}
 
-	memcpy(pal->raw,cont.data,384);
+	/*memcpy(pal->raw,cont.data,384);*/
+	pal->raw=tbinaryallocandcopy(cont); /* TODO: check if it is mandatory to copy */
 
 	*error=PR_RESULT_SUCCESS;
 	
@@ -99,7 +100,7 @@ int objPalette_pop2_4bitsWrite(void* o, const char* file, int optionflag, const
 
 	/* Export extra palette information */
 	sprintf(aux,"%s.more",file);
-	writeData(pal->raw,0,aux,384,optionflag,backupExtension);
+	writeData(pal->raw.data,0,aux,pal->raw.size,optionflag,backupExtension);
 
 	return writePal(file,16,pal->c,optionflag,backupExtension);
 }
@@ -122,7 +123,7 @@ void* objPop2Palette4bitsRead(const char* file,int *result) {
 	sprintf(aux,"%s.more",file);
 	raw=mLoadFileArray(aux);
 	if (raw.size!=100) return NULL; /* TODO; free memory */
-	memcpy(pal->raw,raw.data,100);
+	/*memcpy(pal->raw,raw.data,100);*/
 	free(raw.data);
 
 	*result=readPal(file,&colorArray,&colors);
@@ -144,15 +145,15 @@ int objPop2Palette4bitsSet(void* o,tResource* res) {
 	tPop2_4bitsPalette* pal=o;
 	int i;
 
-	res->content.size=384;
-	res->content.data=pal->raw;
+	/*res->content.size=384;
+	res->content.data=pal->raw;*/
 	for (i=0;i<16;i++) {
 		res->content.data[(i*3)+4]=convert24to18(pal->c[i].r);
 		res->content.data[(i*3)+5]=convert24to18(pal->c[i].g);
 		res->content.data[(i*3)+6]=convert24to18(pal->c[i].b);
 	}
-	res->content.size=384;
-	res->content.data=pal->raw;
+	/*res->content.size=384;
+	res->content.data=pal->raw;*/
 	mWriteFileInDatFile(res);
 	return PR_RESULT_SUCCESS;
 }