git » fp-git.git » commit 3eaa7c0

added primitives in the image file

author ecalot
2006-02-17 15:58:55 UTC
committer ecalot
2006-02-17 15:58:55 UTC
parent e75f9ac571419d73d44c06625ee7b105493f755f

added primitives in the image file

PR/src/include/image.h +5 -2
PR/src/lib/object/image/image16.c +19 -10
PR/src/lib/object/image/image2.c +19 -10
PR/src/lib/object/image/image256.c +19 -10
PR/src/lib/object/image/image_common.c +19 -10
PR/src/lib/object/object.c +3 -1

diff --git a/PR/src/include/image.h b/PR/src/include/image.h
index c6992bb..28286aa 100644
--- a/PR/src/include/image.h
+++ b/PR/src/include/image.h
@@ -34,6 +34,8 @@ image.h: Princed Resources : Image handling headers
 #ifndef _IMAGE_H_
 #define _IMAGE_H_
 
+#include "reslist.h"
+
 typedef struct { 
 	unsigned char r;
 	unsigned char g;
@@ -59,8 +61,9 @@ typedef struct {
 
 /* Prototypes */
 
-int mCompressGraphic(unsigned char** a,tImage* i, int* size);
-int mExpandGraphic  (const unsigned char* array,tImage *image, int size);
+int mCompressGraphic(unsigned char** a,tImage* i, int* size); /* make it private */
+
+void* objImageCreate(unsigned char* data, int size, tObject palette, int *error);
 
 #define getCarry(a) ((((a)>>4)&7)+1)
 #define getAlgor(a) a&0x4F
diff --git a/PR/src/lib/object/image/image16.c b/PR/src/lib/object/image/image16.c
index dd2c7e6..f23fd4d 100644
--- a/PR/src/lib/object/image/image16.c
+++ b/PR/src/lib/object/image/image16.c
@@ -19,7 +19,7 @@
 */
 
 /*
-compress.c: Princed Resources : Image Compression Library
+image.c: Princed Resources : Image Compression Library
 \xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf
  Copyright 2003, 2004, 2005, 2006 Princed Development Team
   Created: 24 Aug 2003
@@ -390,7 +390,8 @@ int pop2decompress(const unsigned char* input, int inputSize, int verify, unsign
 
 extern FILE* outputStream;
 
-int mFormatExportBmp(const unsigned char* data, const char *vFileext,unsigned long int size,tImage image,int optionflag, const char* backupExtension) {
+void* objImageCreate(unsigned char* data, int size, tObject palette, int *error) { /* use get like main.c */
+
 	/*
 	 * This function will expand the data into an image structure,
 	 * then the bitmap structure will be saved to disk
@@ -399,20 +400,28 @@ int mFormatExportBmp(const unsigned char* data, const char *vFileext,unsigned lo
 	 *       keep the right palette.
 	 */
 
-	int result;
+	tImage* image;
+	image=(tImage*)malloc(sizeof(tImage));
 
 	/* Expand graphic and check results */
-	result=mExpandGraphic(data,&image,size);
-	if ((result==COMPRESS_RESULT_WARNING)&&hasFlag(verbose_flag))
-		fprintf(outputStream,PR_TEXT_EXPORT_BMP_WARN);
-	if (result==COMPRESS_RESULT_FATAL) return 0; /* false */
+	*error=mExpandGraphic(data,image,size);
+/*	if ((result==COMPRESS_RESULT_WARNING)&&hasFlag(verbose_flag))
+		fprintf(outputStream,PR_TEXT_EXPORT_BMP_WARN);*/
+	if (*error==COMPRESS_RESULT_FATAL) return NULL;
+
+	return (void*)image;
+}
 
+int objImageWrite(void* img,const char* file,int optionflag,const char* backupExtension) {
 	/* Write bitmap */
-	mWriteBitMap(image,vFileext,optionflag,backupExtension);
+	return mWriteBitMap(*((tImage*)img),file,optionflag,backupExtension);
+}
 
+void objImageFree(void* img) {
+	if (!img) return;
 	/* free bitmap */
-	free(image.pix);
-	return 1; /* true */
+	free(((tImage*)img)->pix);
+	free(img);
 }
 
 int mFormatImportBmp(tResource *res) {
diff --git a/PR/src/lib/object/image/image2.c b/PR/src/lib/object/image/image2.c
index dd2c7e6..f23fd4d 100644
--- a/PR/src/lib/object/image/image2.c
+++ b/PR/src/lib/object/image/image2.c
@@ -19,7 +19,7 @@
 */
 
 /*
-compress.c: Princed Resources : Image Compression Library
+image.c: Princed Resources : Image Compression Library
 \xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf
  Copyright 2003, 2004, 2005, 2006 Princed Development Team
   Created: 24 Aug 2003
@@ -390,7 +390,8 @@ int pop2decompress(const unsigned char* input, int inputSize, int verify, unsign
 
 extern FILE* outputStream;
 
-int mFormatExportBmp(const unsigned char* data, const char *vFileext,unsigned long int size,tImage image,int optionflag, const char* backupExtension) {
+void* objImageCreate(unsigned char* data, int size, tObject palette, int *error) { /* use get like main.c */
+
 	/*
 	 * This function will expand the data into an image structure,
 	 * then the bitmap structure will be saved to disk
@@ -399,20 +400,28 @@ int mFormatExportBmp(const unsigned char* data, const char *vFileext,unsigned lo
 	 *       keep the right palette.
 	 */
 
-	int result;
+	tImage* image;
+	image=(tImage*)malloc(sizeof(tImage));
 
 	/* Expand graphic and check results */
-	result=mExpandGraphic(data,&image,size);
-	if ((result==COMPRESS_RESULT_WARNING)&&hasFlag(verbose_flag))
-		fprintf(outputStream,PR_TEXT_EXPORT_BMP_WARN);
-	if (result==COMPRESS_RESULT_FATAL) return 0; /* false */
+	*error=mExpandGraphic(data,image,size);
+/*	if ((result==COMPRESS_RESULT_WARNING)&&hasFlag(verbose_flag))
+		fprintf(outputStream,PR_TEXT_EXPORT_BMP_WARN);*/
+	if (*error==COMPRESS_RESULT_FATAL) return NULL;
+
+	return (void*)image;
+}
 
+int objImageWrite(void* img,const char* file,int optionflag,const char* backupExtension) {
 	/* Write bitmap */
-	mWriteBitMap(image,vFileext,optionflag,backupExtension);
+	return mWriteBitMap(*((tImage*)img),file,optionflag,backupExtension);
+}
 
+void objImageFree(void* img) {
+	if (!img) return;
 	/* free bitmap */
-	free(image.pix);
-	return 1; /* true */
+	free(((tImage*)img)->pix);
+	free(img);
 }
 
 int mFormatImportBmp(tResource *res) {
diff --git a/PR/src/lib/object/image/image256.c b/PR/src/lib/object/image/image256.c
index dd2c7e6..f23fd4d 100644
--- a/PR/src/lib/object/image/image256.c
+++ b/PR/src/lib/object/image/image256.c
@@ -19,7 +19,7 @@
 */
 
 /*
-compress.c: Princed Resources : Image Compression Library
+image.c: Princed Resources : Image Compression Library
 \xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf
  Copyright 2003, 2004, 2005, 2006 Princed Development Team
   Created: 24 Aug 2003
@@ -390,7 +390,8 @@ int pop2decompress(const unsigned char* input, int inputSize, int verify, unsign
 
 extern FILE* outputStream;
 
-int mFormatExportBmp(const unsigned char* data, const char *vFileext,unsigned long int size,tImage image,int optionflag, const char* backupExtension) {
+void* objImageCreate(unsigned char* data, int size, tObject palette, int *error) { /* use get like main.c */
+
 	/*
 	 * This function will expand the data into an image structure,
 	 * then the bitmap structure will be saved to disk
@@ -399,20 +400,28 @@ int mFormatExportBmp(const unsigned char* data, const char *vFileext,unsigned lo
 	 *       keep the right palette.
 	 */
 
-	int result;
+	tImage* image;
+	image=(tImage*)malloc(sizeof(tImage));
 
 	/* Expand graphic and check results */
-	result=mExpandGraphic(data,&image,size);
-	if ((result==COMPRESS_RESULT_WARNING)&&hasFlag(verbose_flag))
-		fprintf(outputStream,PR_TEXT_EXPORT_BMP_WARN);
-	if (result==COMPRESS_RESULT_FATAL) return 0; /* false */
+	*error=mExpandGraphic(data,image,size);
+/*	if ((result==COMPRESS_RESULT_WARNING)&&hasFlag(verbose_flag))
+		fprintf(outputStream,PR_TEXT_EXPORT_BMP_WARN);*/
+	if (*error==COMPRESS_RESULT_FATAL) return NULL;
+
+	return (void*)image;
+}
 
+int objImageWrite(void* img,const char* file,int optionflag,const char* backupExtension) {
 	/* Write bitmap */
-	mWriteBitMap(image,vFileext,optionflag,backupExtension);
+	return mWriteBitMap(*((tImage*)img),file,optionflag,backupExtension);
+}
 
+void objImageFree(void* img) {
+	if (!img) return;
 	/* free bitmap */
-	free(image.pix);
-	return 1; /* true */
+	free(((tImage*)img)->pix);
+	free(img);
 }
 
 int mFormatImportBmp(tResource *res) {
diff --git a/PR/src/lib/object/image/image_common.c b/PR/src/lib/object/image/image_common.c
index dd2c7e6..f23fd4d 100644
--- a/PR/src/lib/object/image/image_common.c
+++ b/PR/src/lib/object/image/image_common.c
@@ -19,7 +19,7 @@
 */
 
 /*
-compress.c: Princed Resources : Image Compression Library
+image.c: Princed Resources : Image Compression Library
 \xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf
  Copyright 2003, 2004, 2005, 2006 Princed Development Team
   Created: 24 Aug 2003
@@ -390,7 +390,8 @@ int pop2decompress(const unsigned char* input, int inputSize, int verify, unsign
 
 extern FILE* outputStream;
 
-int mFormatExportBmp(const unsigned char* data, const char *vFileext,unsigned long int size,tImage image,int optionflag, const char* backupExtension) {
+void* objImageCreate(unsigned char* data, int size, tObject palette, int *error) { /* use get like main.c */
+
 	/*
 	 * This function will expand the data into an image structure,
 	 * then the bitmap structure will be saved to disk
@@ -399,20 +400,28 @@ int mFormatExportBmp(const unsigned char* data, const char *vFileext,unsigned lo
 	 *       keep the right palette.
 	 */
 
-	int result;
+	tImage* image;
+	image=(tImage*)malloc(sizeof(tImage));
 
 	/* Expand graphic and check results */
-	result=mExpandGraphic(data,&image,size);
-	if ((result==COMPRESS_RESULT_WARNING)&&hasFlag(verbose_flag))
-		fprintf(outputStream,PR_TEXT_EXPORT_BMP_WARN);
-	if (result==COMPRESS_RESULT_FATAL) return 0; /* false */
+	*error=mExpandGraphic(data,image,size);
+/*	if ((result==COMPRESS_RESULT_WARNING)&&hasFlag(verbose_flag))
+		fprintf(outputStream,PR_TEXT_EXPORT_BMP_WARN);*/
+	if (*error==COMPRESS_RESULT_FATAL) return NULL;
+
+	return (void*)image;
+}
 
+int objImageWrite(void* img,const char* file,int optionflag,const char* backupExtension) {
 	/* Write bitmap */
-	mWriteBitMap(image,vFileext,optionflag,backupExtension);
+	return mWriteBitMap(*((tImage*)img),file,optionflag,backupExtension);
+}
 
+void objImageFree(void* img) {
+	if (!img) return;
 	/* free bitmap */
-	free(image.pix);
-	return 1; /* true */
+	free(((tImage*)img)->pix);
+	free(img);
 }
 
 int mFormatImportBmp(tResource *res) {
diff --git a/PR/src/lib/object/object.c b/PR/src/lib/object/object.c
index 2987a2e..7304d37 100644
--- a/PR/src/lib/object/object.c
+++ b/PR/src/lib/object/object.c
@@ -32,7 +32,9 @@ main.c: Princed Resources : Main item class implementation
 
 #include "object.h"
 #include "reslist.h"
+
 #include "other.h"
+#include "image.h"
 
 tObject getObject(tResource* r, int* error) {
 	tObject o;
@@ -60,7 +62,7 @@ tObject getObject(tResource* r, int* error) {
 		/*o.obj=objWaveCreate(r->data,r->size,error); */
 		break;
 	case eResTypeImage: /* save image */
-		/*o.obj=objImageCreate(r->data,r->size,r->pal,error); */
+		o.obj=objImageCreate(r->data,r->size,r->palette,error);
 		break;
 	default:
 		break;