git » fp-git.git » commit a101227

continuing the image import hook (still untested)

author ecalot
2006-02-25 07:14:31 UTC
committer ecalot
2006-02-25 07:14:31 UTC
parent 18f2b5f128f2cdc38ff9d92324231e4583b21a7a

continuing the image import hook (still untested)

PR/src/include/bitmap.h +1 -0
PR/src/include/bmp.h +1 -0
PR/src/include/common.h +1 -0
PR/src/include/image.h +1 -0
PR/src/include/png.h +1 -0
PR/src/lib/object/image/image16.c +34 -4
PR/src/lib/object/image/image2.c +34 -4
PR/src/lib/object/image/image256.c +34 -4
PR/src/lib/object/image/image_common.c +34 -4

diff --git a/PR/src/include/bitmap.h b/PR/src/include/bitmap.h
index 811cd60..d033587 100644
--- a/PR/src/include/bitmap.h
+++ b/PR/src/include/bitmap.h
@@ -46,5 +46,6 @@ int mWriteBitMap(tImage img,const char* vFile,int optionflag,const char* backupE
 int mReadBitMap(tImage* img,unsigned char* data, int size); /* Note: this will ignore the palette */
 
 int mWriteBmp(const char* file,const unsigned char* data, int w, int h, int bits, int colors, tColor* colorArray, int lineWidth, int optionflag, const char* backupExtension);
+int readBmp(const char* file, unsigned char** data, int *ph, int *pw,  int *pbits, int *pcolors, tColor** colorArray, int *plineWidth);
 
 #endif
diff --git a/PR/src/include/bmp.h b/PR/src/include/bmp.h
index 811cd60..d033587 100644
--- a/PR/src/include/bmp.h
+++ b/PR/src/include/bmp.h
@@ -46,5 +46,6 @@ int mWriteBitMap(tImage img,const char* vFile,int optionflag,const char* backupE
 int mReadBitMap(tImage* img,unsigned char* data, int size); /* Note: this will ignore the palette */
 
 int mWriteBmp(const char* file,const unsigned char* data, int w, int h, int bits, int colors, tColor* colorArray, int lineWidth, int optionflag, const char* backupExtension);
+int readBmp(const char* file, unsigned char** data, int *ph, int *pw,  int *pbits, int *pcolors, tColor** colorArray, int *plineWidth);
 
 #endif
diff --git a/PR/src/include/common.h b/PR/src/include/common.h
index 5e3a510..5fdf449 100644
--- a/PR/src/include/common.h
+++ b/PR/src/include/common.h
@@ -231,5 +231,6 @@ PARSING_OPTRAW\
 #define PR_RESULT_WAV_UNSUPPORTED_BITRATE -28
 #define PR_RESULT_WAV_UNSUPPORTED_SAMPLERATE -29
 #define PR_RESULT_WAV_UNSUPPORTED_STEREO -30
+#define PR_RESULT_ERR_BMP_BITRATE_DIFFERS -31
 
 #endif
diff --git a/PR/src/include/image.h b/PR/src/include/image.h
index b1f0458..2a57528 100644
--- a/PR/src/include/image.h
+++ b/PR/src/include/image.h
@@ -55,6 +55,7 @@ typedef struct {
 	int width;
 	int widthInBytes;
 	int height;
+	int bits;
 	unsigned char* pix;
 	tObject pal;
 	unsigned char type; /* XY where X=B if 4 bits or X=0 if 1 bit; Y=algorithm */
diff --git a/PR/src/include/png.h b/PR/src/include/png.h
index 811cd60..d033587 100644
--- a/PR/src/include/png.h
+++ b/PR/src/include/png.h
@@ -46,5 +46,6 @@ int mWriteBitMap(tImage img,const char* vFile,int optionflag,const char* backupE
 int mReadBitMap(tImage* img,unsigned char* data, int size); /* Note: this will ignore the palette */
 
 int mWriteBmp(const char* file,const unsigned char* data, int w, int h, int bits, int colors, tColor* colorArray, int lineWidth, int optionflag, const char* backupExtension);
+int readBmp(const char* file, unsigned char** data, int *ph, int *pw,  int *pbits, int *pcolors, tColor** colorArray, int *plineWidth);
 
 #endif
diff --git a/PR/src/lib/object/image/image16.c b/PR/src/lib/object/image/image16.c
index 1b22f65..351bb31 100644
--- a/PR/src/lib/object/image/image16.c
+++ b/PR/src/lib/object/image/image16.c
@@ -417,6 +417,7 @@ void* objImageCreate(tBinary cont, tObject palette, int *error) { /* use get lik
 	image->pal=palette;
 	bits=paletteGetBits(image->pal);
 	if (bits!=getCarry(image->type)) printf("error, palette mismatch\n");
+	image->bits=getCarry(image->type);
 	
 	return (void*)image;
 }
@@ -449,7 +450,39 @@ void objImageFree(void* img) {
 }
 
 void* objImageRead(const char* file,tObject palette, int *result) {
-/*int mFormatImportBmp(tResource *res) {*/
+	int bits;
+	tImage* image=(tImage*)malloc(sizeof(tImage));
+	tColor* colorArray;
+	int colors;
+
+	*result=readBmp(file,&(image->pix),&(image->height),&(image->width),&(image->bits),&colors,&colorArray,&(image->widthInBytes));
+	/* check if image was succesfully read loaded */
+	if (*result!=PR_RESULT_SUCCESS) {
+		free(image->pix);
+		free(colorArray);
+		free(image);
+		return NULL;
+	}
+
+	/* check the palette information */
+	
+	image->pal=palette;
+	bits=paletteGetBits(image->pal);
+	if (bits && bits!=getCarry(image->type)) { /* bits=0 means all palettes allowed or ignore palette check */
+		*result=PR_RESULT_ERR_BMP_BITRATE_DIFFERS;
+		free(image->pix);
+		free(colorArray);
+		free(image);
+		return NULL;
+	}
+
+	/* TODO: palette content checks */
+	
+	free(colorArray);
+	return (void*)image;
+}
+
+/*int mFormatImportBmp(tResource *res) { --> objImageSet */
 	/*tImage img;*/
 
 /*	if (!mReadBitMap(&img,)) return 0; * false *
@@ -458,6 +491,3 @@ void* objImageRead(const char* file,tObject palette, int *result) {
 	mWriteFileInDatFile(res);
 	free(img.pix);
 */
-	return NULL;
-}
-
diff --git a/PR/src/lib/object/image/image2.c b/PR/src/lib/object/image/image2.c
index 1b22f65..351bb31 100644
--- a/PR/src/lib/object/image/image2.c
+++ b/PR/src/lib/object/image/image2.c
@@ -417,6 +417,7 @@ void* objImageCreate(tBinary cont, tObject palette, int *error) { /* use get lik
 	image->pal=palette;
 	bits=paletteGetBits(image->pal);
 	if (bits!=getCarry(image->type)) printf("error, palette mismatch\n");
+	image->bits=getCarry(image->type);
 	
 	return (void*)image;
 }
@@ -449,7 +450,39 @@ void objImageFree(void* img) {
 }
 
 void* objImageRead(const char* file,tObject palette, int *result) {
-/*int mFormatImportBmp(tResource *res) {*/
+	int bits;
+	tImage* image=(tImage*)malloc(sizeof(tImage));
+	tColor* colorArray;
+	int colors;
+
+	*result=readBmp(file,&(image->pix),&(image->height),&(image->width),&(image->bits),&colors,&colorArray,&(image->widthInBytes));
+	/* check if image was succesfully read loaded */
+	if (*result!=PR_RESULT_SUCCESS) {
+		free(image->pix);
+		free(colorArray);
+		free(image);
+		return NULL;
+	}
+
+	/* check the palette information */
+	
+	image->pal=palette;
+	bits=paletteGetBits(image->pal);
+	if (bits && bits!=getCarry(image->type)) { /* bits=0 means all palettes allowed or ignore palette check */
+		*result=PR_RESULT_ERR_BMP_BITRATE_DIFFERS;
+		free(image->pix);
+		free(colorArray);
+		free(image);
+		return NULL;
+	}
+
+	/* TODO: palette content checks */
+	
+	free(colorArray);
+	return (void*)image;
+}
+
+/*int mFormatImportBmp(tResource *res) { --> objImageSet */
 	/*tImage img;*/
 
 /*	if (!mReadBitMap(&img,)) return 0; * false *
@@ -458,6 +491,3 @@ void* objImageRead(const char* file,tObject palette, int *result) {
 	mWriteFileInDatFile(res);
 	free(img.pix);
 */
-	return NULL;
-}
-
diff --git a/PR/src/lib/object/image/image256.c b/PR/src/lib/object/image/image256.c
index 1b22f65..351bb31 100644
--- a/PR/src/lib/object/image/image256.c
+++ b/PR/src/lib/object/image/image256.c
@@ -417,6 +417,7 @@ void* objImageCreate(tBinary cont, tObject palette, int *error) { /* use get lik
 	image->pal=palette;
 	bits=paletteGetBits(image->pal);
 	if (bits!=getCarry(image->type)) printf("error, palette mismatch\n");
+	image->bits=getCarry(image->type);
 	
 	return (void*)image;
 }
@@ -449,7 +450,39 @@ void objImageFree(void* img) {
 }
 
 void* objImageRead(const char* file,tObject palette, int *result) {
-/*int mFormatImportBmp(tResource *res) {*/
+	int bits;
+	tImage* image=(tImage*)malloc(sizeof(tImage));
+	tColor* colorArray;
+	int colors;
+
+	*result=readBmp(file,&(image->pix),&(image->height),&(image->width),&(image->bits),&colors,&colorArray,&(image->widthInBytes));
+	/* check if image was succesfully read loaded */
+	if (*result!=PR_RESULT_SUCCESS) {
+		free(image->pix);
+		free(colorArray);
+		free(image);
+		return NULL;
+	}
+
+	/* check the palette information */
+	
+	image->pal=palette;
+	bits=paletteGetBits(image->pal);
+	if (bits && bits!=getCarry(image->type)) { /* bits=0 means all palettes allowed or ignore palette check */
+		*result=PR_RESULT_ERR_BMP_BITRATE_DIFFERS;
+		free(image->pix);
+		free(colorArray);
+		free(image);
+		return NULL;
+	}
+
+	/* TODO: palette content checks */
+	
+	free(colorArray);
+	return (void*)image;
+}
+
+/*int mFormatImportBmp(tResource *res) { --> objImageSet */
 	/*tImage img;*/
 
 /*	if (!mReadBitMap(&img,)) return 0; * false *
@@ -458,6 +491,3 @@ void* objImageRead(const char* file,tObject palette, int *result) {
 	mWriteFileInDatFile(res);
 	free(img.pix);
 */
-	return NULL;
-}
-
diff --git a/PR/src/lib/object/image/image_common.c b/PR/src/lib/object/image/image_common.c
index 1b22f65..351bb31 100644
--- a/PR/src/lib/object/image/image_common.c
+++ b/PR/src/lib/object/image/image_common.c
@@ -417,6 +417,7 @@ void* objImageCreate(tBinary cont, tObject palette, int *error) { /* use get lik
 	image->pal=palette;
 	bits=paletteGetBits(image->pal);
 	if (bits!=getCarry(image->type)) printf("error, palette mismatch\n");
+	image->bits=getCarry(image->type);
 	
 	return (void*)image;
 }
@@ -449,7 +450,39 @@ void objImageFree(void* img) {
 }
 
 void* objImageRead(const char* file,tObject palette, int *result) {
-/*int mFormatImportBmp(tResource *res) {*/
+	int bits;
+	tImage* image=(tImage*)malloc(sizeof(tImage));
+	tColor* colorArray;
+	int colors;
+
+	*result=readBmp(file,&(image->pix),&(image->height),&(image->width),&(image->bits),&colors,&colorArray,&(image->widthInBytes));
+	/* check if image was succesfully read loaded */
+	if (*result!=PR_RESULT_SUCCESS) {
+		free(image->pix);
+		free(colorArray);
+		free(image);
+		return NULL;
+	}
+
+	/* check the palette information */
+	
+	image->pal=palette;
+	bits=paletteGetBits(image->pal);
+	if (bits && bits!=getCarry(image->type)) { /* bits=0 means all palettes allowed or ignore palette check */
+		*result=PR_RESULT_ERR_BMP_BITRATE_DIFFERS;
+		free(image->pix);
+		free(colorArray);
+		free(image);
+		return NULL;
+	}
+
+	/* TODO: palette content checks */
+	
+	free(colorArray);
+	return (void*)image;
+}
+
+/*int mFormatImportBmp(tResource *res) { --> objImageSet */
 	/*tImage img;*/
 
 /*	if (!mReadBitMap(&img,)) return 0; * false *
@@ -458,6 +491,3 @@ void* objImageRead(const char* file,tObject palette, int *result) {
 	mWriteFileInDatFile(res);
 	free(img.pix);
 */
-	return NULL;
-}
-