git » fp-git.git » commit 57128d2

added a way to remember the palette in case we do not know the whole format

author ecalot
2006-02-16 21:04:04 UTC
committer ecalot
2006-02-16 21:04:04 UTC
parent 0290fad1b4de551894ced94a66a757f0e59e8549

added a way to remember the palette in case we do not know the whole format

PR/src/include/image.h +2 -0
PR/src/include/memory.h +1 -0
PR/src/lib/formats/pal.c +1 -1
PR/src/lib/layers/memory.c +8 -0
PR/src/lib/object/palette/pop1_16c.c +14 -0
PR/src/lib/object/palette/pop2_256c.c +14 -0
PR/src/lib/object/palette/pop2_4bit.c +14 -0

diff --git a/PR/src/include/image.h b/PR/src/include/image.h
index 8a7214e..c6992bb 100644
--- a/PR/src/include/image.h
+++ b/PR/src/include/image.h
@@ -44,6 +44,8 @@ typedef struct {
 	tColor p8[256];
 	tColor p4[16];
 	tColor p1[2];
+	unsigned char* pop1raw;
+	int pop1rawSize;
 }tPalette;
 
 typedef struct { 
diff --git a/PR/src/include/memory.h b/PR/src/include/memory.h
index 392a9ea..996aefd 100644
--- a/PR/src/include/memory.h
+++ b/PR/src/include/memory.h
@@ -38,6 +38,7 @@ memory.h: Princed Resources : Memory handling & comparison prototypes
 
 #define getMemory(size) ((unsigned char*)malloc(size))
 char* strallocandcopy(const char* text);
+unsigned char* binaryallocandcopy(const unsigned char* bin,int size);
 #define freeAllocation(m) if ((m)!=NULL) free(m)
 
 #define ptoi(p) ((p!=NULL)?atoi(p):0)
diff --git a/PR/src/lib/formats/pal.c b/PR/src/lib/formats/pal.c
index 5ac5a5a..c77ec20 100644
--- a/PR/src/lib/formats/pal.c
+++ b/PR/src/lib/formats/pal.c
@@ -83,7 +83,7 @@ int mFormatExportPal(const tPalette* p, int bits, char *vFileext, int optionflag
 	return i;
 }
 
-int mFormatImportPal(tPalette* p,int* bits, const char* vFile) {
+int mFormatImportPal(tPalette* p, int* bits, const char* vFile) {
 	/* declare variables */
 	unsigned char* pals;
 	unsigned char* pals1;
diff --git a/PR/src/lib/layers/memory.c b/PR/src/lib/layers/memory.c
index 30ee27c..e88d843 100644
--- a/PR/src/lib/layers/memory.c
+++ b/PR/src/lib/layers/memory.c
@@ -44,6 +44,14 @@ char* strallocandcopy(const char* text) {
 	return aux;
 }
 
+unsigned char* binaryallocandcopy(const unsigned char* bin,int size) {
+	unsigned char* aux;
+	if (bin==NULL) return NULL;
+	aux=(unsigned char*)malloc(size);
+	if (aux) memcpy(aux,bin,size);
+	return aux;
+}
+
 void str5lowercpy (char* dst,const char* src) {
 	int i;
 	for (i=0;(i<4)&&(*src);i++) {
diff --git a/PR/src/lib/object/palette/pop1_16c.c b/PR/src/lib/object/palette/pop1_16c.c
index e066943..6bf0186 100644
--- a/PR/src/lib/object/palette/pop1_16c.c
+++ b/PR/src/lib/object/palette/pop1_16c.c
@@ -39,6 +39,9 @@ palette.c: Princed Resources : The palette object implementation
 #include <string.h>
 #include <stdio.h>
 #include "palette.h"
+#include "memory.h"
+
+void addPop1Raw(tPalette* p,unsigned char* data, int dataSize);
 
 /***************************************************************\
 |                         Palette Object                        |
@@ -101,6 +104,9 @@ tPalette createPalette() {
 		r.p8[i].g=i;
 		r.p8[i].b=i;
 	}
+
+	/* initialize the rest */
+	r.pop1raw=NULL;
 	return r;
 }
 
@@ -126,6 +132,8 @@ int readPalette(tPalette* p, unsigned char* data, int dataSize) {
 			c[i].b=data[(i*3)+7]<<2;
 		}
 		bits=4;
+		/* this palette needs to be remembered as binary */
+		addPop1Raw(p,data+1,dataSize-1);
 		break;
 	case 3*256+1:
 	case 3*320+1:
@@ -147,3 +155,9 @@ int applyPalette(tPalette* p,tImage *i) {
 	return 0;
 }
 
+void addPop1Raw(tPalette* p,unsigned char* data, int dataSize) {
+	freeAllocation(p->pop1raw);
+	p->pop1raw=binaryallocandcopy(data,dataSize);
+	p->pop1rawSize=dataSize;
+}
+
diff --git a/PR/src/lib/object/palette/pop2_256c.c b/PR/src/lib/object/palette/pop2_256c.c
index e066943..6bf0186 100644
--- a/PR/src/lib/object/palette/pop2_256c.c
+++ b/PR/src/lib/object/palette/pop2_256c.c
@@ -39,6 +39,9 @@ palette.c: Princed Resources : The palette object implementation
 #include <string.h>
 #include <stdio.h>
 #include "palette.h"
+#include "memory.h"
+
+void addPop1Raw(tPalette* p,unsigned char* data, int dataSize);
 
 /***************************************************************\
 |                         Palette Object                        |
@@ -101,6 +104,9 @@ tPalette createPalette() {
 		r.p8[i].g=i;
 		r.p8[i].b=i;
 	}
+
+	/* initialize the rest */
+	r.pop1raw=NULL;
 	return r;
 }
 
@@ -126,6 +132,8 @@ int readPalette(tPalette* p, unsigned char* data, int dataSize) {
 			c[i].b=data[(i*3)+7]<<2;
 		}
 		bits=4;
+		/* this palette needs to be remembered as binary */
+		addPop1Raw(p,data+1,dataSize-1);
 		break;
 	case 3*256+1:
 	case 3*320+1:
@@ -147,3 +155,9 @@ int applyPalette(tPalette* p,tImage *i) {
 	return 0;
 }
 
+void addPop1Raw(tPalette* p,unsigned char* data, int dataSize) {
+	freeAllocation(p->pop1raw);
+	p->pop1raw=binaryallocandcopy(data,dataSize);
+	p->pop1rawSize=dataSize;
+}
+
diff --git a/PR/src/lib/object/palette/pop2_4bit.c b/PR/src/lib/object/palette/pop2_4bit.c
index e066943..6bf0186 100644
--- a/PR/src/lib/object/palette/pop2_4bit.c
+++ b/PR/src/lib/object/palette/pop2_4bit.c
@@ -39,6 +39,9 @@ palette.c: Princed Resources : The palette object implementation
 #include <string.h>
 #include <stdio.h>
 #include "palette.h"
+#include "memory.h"
+
+void addPop1Raw(tPalette* p,unsigned char* data, int dataSize);
 
 /***************************************************************\
 |                         Palette Object                        |
@@ -101,6 +104,9 @@ tPalette createPalette() {
 		r.p8[i].g=i;
 		r.p8[i].b=i;
 	}
+
+	/* initialize the rest */
+	r.pop1raw=NULL;
 	return r;
 }
 
@@ -126,6 +132,8 @@ int readPalette(tPalette* p, unsigned char* data, int dataSize) {
 			c[i].b=data[(i*3)+7]<<2;
 		}
 		bits=4;
+		/* this palette needs to be remembered as binary */
+		addPop1Raw(p,data+1,dataSize-1);
 		break;
 	case 3*256+1:
 	case 3*320+1:
@@ -147,3 +155,9 @@ int applyPalette(tPalette* p,tImage *i) {
 	return 0;
 }
 
+void addPop1Raw(tPalette* p,unsigned char* data, int dataSize) {
+	freeAllocation(p->pop1raw);
+	p->pop1raw=binaryallocandcopy(data,dataSize);
+	p->pop1rawSize=dataSize;
+}
+