git » fp-git.git » commit b51d5cb

more bugfixes

author ecalot
2006-02-18 16:02:29 UTC
committer ecalot
2006-02-18 16:02:29 UTC
parent 9cdc755775d81a212f91073bbe62e9d0bafea3d3

more bugfixes

PR/src/include/palette.h +1 -0
PR/src/lib/actions/export.c +2 -1
PR/src/lib/object/image/image16.c +11 -3
PR/src/lib/object/image/image2.c +11 -3
PR/src/lib/object/image/image256.c +11 -3
PR/src/lib/object/image/image_common.c +11 -3
PR/src/lib/object/palette/pop1_16c.c +33 -0
PR/src/lib/object/palette/pop2_256c.c +33 -0
PR/src/lib/object/palette/pop2_4bit.c +33 -0

diff --git a/PR/src/include/palette.h b/PR/src/include/palette.h
index e43f362..f80d147 100644
--- a/PR/src/include/palette.h
+++ b/PR/src/include/palette.h
@@ -65,5 +65,6 @@ void* objPalette_pop1_4bitsCreate(unsigned char* data, int size, int *error);
 int objPalette_pop1_4bitsWrite(void* o, const char* file, int optionflag, const char* backupExtension);
 
 tColor* objPalette_pop1_4bitsGetColors(void* o);
+tColor* paletteGetColorArrayForColors(int colors);
 
 #endif
diff --git a/PR/src/lib/actions/export.c b/PR/src/lib/actions/export.c
index b738b04..cedcfd4 100644
--- a/PR/src/lib/actions/export.c
+++ b/PR/src/lib/actions/export.c
@@ -127,8 +127,9 @@ printf("id=(%d,%s,%d)\n",res.paletteId.value,res.paletteId.index,res.paletteId.o
 							/* Read the palette and load it into memory */
 							if (mReadFileInDatFileId(&otherPalette)==PR_RESULT_SUCCESS) {
 								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(&res,&ok);
+								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 */
diff --git a/PR/src/lib/object/image/image16.c b/PR/src/lib/object/image/image16.c
index 390a10a..e5f8fa8 100644
--- a/PR/src/lib/object/image/image16.c
+++ b/PR/src/lib/object/image/image16.c
@@ -42,6 +42,8 @@ image.c: Princed Resources : Image Compression Library
 #include "dat.h"
 #include "object.h" /* paletteGet* */
 
+#include "palette.h" /* getColorArrayByColors */
+
 #include "bmp.h"
 
 /* Compression level explanation:
@@ -426,9 +428,15 @@ int objImageWrite(void* img,const char* file,int optionflag,const char* backupEx
 	int colors;
 	tColor* colorArray;
 
-	bits=paletteGetBits(i->pal);
-	colors=paletteGetColors(i->pal);
-	colorArray=paletteGetColorArray(i->pal);
+	if (i->pal.type!=eResTypeNone) {
+		bits=paletteGetBits(i->pal);
+		colors=paletteGetColors(i->pal);
+		colorArray=paletteGetColorArray(i->pal);
+	} else {
+		bits=getCarry(i->type);
+		colors=1<<bits;
+		colorArray=paletteGetColorArrayForColors(colors);
+	}
 	
 	/* Write bitmap */
 	return mWriteBmp(file,i->pix,i->width,i->height,bits,colors,colorArray,i->widthInBytes,optionflag,backupExtension);
diff --git a/PR/src/lib/object/image/image2.c b/PR/src/lib/object/image/image2.c
index 390a10a..e5f8fa8 100644
--- a/PR/src/lib/object/image/image2.c
+++ b/PR/src/lib/object/image/image2.c
@@ -42,6 +42,8 @@ image.c: Princed Resources : Image Compression Library
 #include "dat.h"
 #include "object.h" /* paletteGet* */
 
+#include "palette.h" /* getColorArrayByColors */
+
 #include "bmp.h"
 
 /* Compression level explanation:
@@ -426,9 +428,15 @@ int objImageWrite(void* img,const char* file,int optionflag,const char* backupEx
 	int colors;
 	tColor* colorArray;
 
-	bits=paletteGetBits(i->pal);
-	colors=paletteGetColors(i->pal);
-	colorArray=paletteGetColorArray(i->pal);
+	if (i->pal.type!=eResTypeNone) {
+		bits=paletteGetBits(i->pal);
+		colors=paletteGetColors(i->pal);
+		colorArray=paletteGetColorArray(i->pal);
+	} else {
+		bits=getCarry(i->type);
+		colors=1<<bits;
+		colorArray=paletteGetColorArrayForColors(colors);
+	}
 	
 	/* Write bitmap */
 	return mWriteBmp(file,i->pix,i->width,i->height,bits,colors,colorArray,i->widthInBytes,optionflag,backupExtension);
diff --git a/PR/src/lib/object/image/image256.c b/PR/src/lib/object/image/image256.c
index 390a10a..e5f8fa8 100644
--- a/PR/src/lib/object/image/image256.c
+++ b/PR/src/lib/object/image/image256.c
@@ -42,6 +42,8 @@ image.c: Princed Resources : Image Compression Library
 #include "dat.h"
 #include "object.h" /* paletteGet* */
 
+#include "palette.h" /* getColorArrayByColors */
+
 #include "bmp.h"
 
 /* Compression level explanation:
@@ -426,9 +428,15 @@ int objImageWrite(void* img,const char* file,int optionflag,const char* backupEx
 	int colors;
 	tColor* colorArray;
 
-	bits=paletteGetBits(i->pal);
-	colors=paletteGetColors(i->pal);
-	colorArray=paletteGetColorArray(i->pal);
+	if (i->pal.type!=eResTypeNone) {
+		bits=paletteGetBits(i->pal);
+		colors=paletteGetColors(i->pal);
+		colorArray=paletteGetColorArray(i->pal);
+	} else {
+		bits=getCarry(i->type);
+		colors=1<<bits;
+		colorArray=paletteGetColorArrayForColors(colors);
+	}
 	
 	/* Write bitmap */
 	return mWriteBmp(file,i->pix,i->width,i->height,bits,colors,colorArray,i->widthInBytes,optionflag,backupExtension);
diff --git a/PR/src/lib/object/image/image_common.c b/PR/src/lib/object/image/image_common.c
index 390a10a..e5f8fa8 100644
--- a/PR/src/lib/object/image/image_common.c
+++ b/PR/src/lib/object/image/image_common.c
@@ -42,6 +42,8 @@ image.c: Princed Resources : Image Compression Library
 #include "dat.h"
 #include "object.h" /* paletteGet* */
 
+#include "palette.h" /* getColorArrayByColors */
+
 #include "bmp.h"
 
 /* Compression level explanation:
@@ -426,9 +428,15 @@ int objImageWrite(void* img,const char* file,int optionflag,const char* backupEx
 	int colors;
 	tColor* colorArray;
 
-	bits=paletteGetBits(i->pal);
-	colors=paletteGetColors(i->pal);
-	colorArray=paletteGetColorArray(i->pal);
+	if (i->pal.type!=eResTypeNone) {
+		bits=paletteGetBits(i->pal);
+		colors=paletteGetColors(i->pal);
+		colorArray=paletteGetColorArray(i->pal);
+	} else {
+		bits=getCarry(i->type);
+		colors=1<<bits;
+		colorArray=paletteGetColorArrayForColors(colors);
+	}
 	
 	/* Write bitmap */
 	return mWriteBmp(file,i->pix,i->width,i->height,bits,colors,colorArray,i->widthInBytes,optionflag,backupExtension);
diff --git a/PR/src/lib/object/palette/pop1_16c.c b/PR/src/lib/object/palette/pop1_16c.c
index cf111bf..b500cf2 100644
--- a/PR/src/lib/object/palette/pop1_16c.c
+++ b/PR/src/lib/object/palette/pop1_16c.c
@@ -208,3 +208,36 @@ tColor* objPalette_pop1_4bitsGetColors(void* o) {
 	tPop1_4bitsPalette* pal=o;
 	return pal->c;
 }
+
+tColor* paletteGetColorArrayForColors(int colors) {
+	static tColor p1[2];
+	static tColor p4[2];
+	static tColor p8[2];
+	int i;
+
+	switch(colors) {
+	case 2:
+		/* Palette 1 bit */
+		p1[0].r=0;
+		p1[0].g=0;
+		p1[0].b=0;
+		p1[1].r=255;
+		p1[1].g=255;
+		p1[1].b=255;
+		return p1;
+	case 16:
+		/* Palette 4 bits */
+		memcpy(p4, sample_pal4, 16);
+		return p4;
+	case 256:
+		/* Palette 8 bits */
+		for (i=0;i<256;i++) {
+			p8[i].r=i;
+			p8[i].g=i;
+			p8[i].b=i;
+		}
+		return p8;
+	default:
+		return NULL; /* unsupported bit rate */
+	}
+}
diff --git a/PR/src/lib/object/palette/pop2_256c.c b/PR/src/lib/object/palette/pop2_256c.c
index cf111bf..b500cf2 100644
--- a/PR/src/lib/object/palette/pop2_256c.c
+++ b/PR/src/lib/object/palette/pop2_256c.c
@@ -208,3 +208,36 @@ tColor* objPalette_pop1_4bitsGetColors(void* o) {
 	tPop1_4bitsPalette* pal=o;
 	return pal->c;
 }
+
+tColor* paletteGetColorArrayForColors(int colors) {
+	static tColor p1[2];
+	static tColor p4[2];
+	static tColor p8[2];
+	int i;
+
+	switch(colors) {
+	case 2:
+		/* Palette 1 bit */
+		p1[0].r=0;
+		p1[0].g=0;
+		p1[0].b=0;
+		p1[1].r=255;
+		p1[1].g=255;
+		p1[1].b=255;
+		return p1;
+	case 16:
+		/* Palette 4 bits */
+		memcpy(p4, sample_pal4, 16);
+		return p4;
+	case 256:
+		/* Palette 8 bits */
+		for (i=0;i<256;i++) {
+			p8[i].r=i;
+			p8[i].g=i;
+			p8[i].b=i;
+		}
+		return p8;
+	default:
+		return NULL; /* unsupported bit rate */
+	}
+}
diff --git a/PR/src/lib/object/palette/pop2_4bit.c b/PR/src/lib/object/palette/pop2_4bit.c
index cf111bf..b500cf2 100644
--- a/PR/src/lib/object/palette/pop2_4bit.c
+++ b/PR/src/lib/object/palette/pop2_4bit.c
@@ -208,3 +208,36 @@ tColor* objPalette_pop1_4bitsGetColors(void* o) {
 	tPop1_4bitsPalette* pal=o;
 	return pal->c;
 }
+
+tColor* paletteGetColorArrayForColors(int colors) {
+	static tColor p1[2];
+	static tColor p4[2];
+	static tColor p8[2];
+	int i;
+
+	switch(colors) {
+	case 2:
+		/* Palette 1 bit */
+		p1[0].r=0;
+		p1[0].g=0;
+		p1[0].b=0;
+		p1[1].r=255;
+		p1[1].g=255;
+		p1[1].b=255;
+		return p1;
+	case 16:
+		/* Palette 4 bits */
+		memcpy(p4, sample_pal4, 16);
+		return p4;
+	case 256:
+		/* Palette 8 bits */
+		for (i=0;i<256;i++) {
+			p8[i].r=i;
+			p8[i].g=i;
+			p8[i].b=i;
+		}
+		return p8;
+	default:
+		return NULL; /* unsupported bit rate */
+	}
+}