author | ecalot
<ecalot> 2006-02-17 18:31:40 UTC |
committer | ecalot
<ecalot> 2006-02-17 18:31:40 UTC |
parent | d0a672b5f93e8ee5f0ccb28ddffa000f74d8145e |
PR/src/include/image.h | +1 | -0 |
PR/src/include/object.h | +1 | -0 |
PR/src/include/pal.h | +4 | -1 |
PR/src/include/palette.h | +1 | -0 |
PR/src/lib/actions/export.c | +13 | -9 |
PR/src/lib/formats/pal.c | +7 | -22 |
PR/src/lib/object/object.c | +27 | -0 |
PR/src/lib/object/palette/pop1_16c.c | +16 | -3 |
PR/src/lib/object/palette/pop2_256c.c | +16 | -3 |
PR/src/lib/object/palette/pop2_4bit.c | +16 | -3 |
diff --git a/PR/src/include/image.h b/PR/src/include/image.h index 28286aa..c3cdfe6 100644 --- a/PR/src/include/image.h +++ b/PR/src/include/image.h @@ -64,6 +64,7 @@ typedef struct { int mCompressGraphic(unsigned char** a,tImage* i, int* size); /* make it private */ void* objImageCreate(unsigned char* data, int size, tObject palette, int *error); +int objImageWrite(void* img,const char* file,int optionflag,const char* backupExtension); #define getCarry(a) ((((a)>>4)&7)+1) #define getAlgor(a) a&0x4F diff --git a/PR/src/include/object.h b/PR/src/include/object.h index 9c0df5a..f75c138 100644 --- a/PR/src/include/object.h +++ b/PR/src/include/object.h @@ -37,5 +37,6 @@ object.h: Princed Resources : Main item class types and prototypes #include "common.h" tObject getObject(tResource* r, int* error); +int writeObject(tObject o, const char* file, int optionflag, const char* backupExtension); #endif diff --git a/PR/src/include/pal.h b/PR/src/include/pal.h index 865272e..7699a02 100644 --- a/PR/src/include/pal.h +++ b/PR/src/include/pal.h @@ -34,13 +34,14 @@ pal.h: Princed Resources : JASC PAL files support headers #ifndef _PAL_H_ #define _PAL_H_ +#include "image.h" #include "palette.h" /* #define PAL_SAMPLE {0x97, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x08, 0x0F, 0x07, 0x0C, 0x13, 0x0C, 0x11, 0x16, 0x11, 0x17, 0x1C, 0x1E, 0x21, 0x25, 0x2F, 0x31, 0x33, 0x3F, 0x3F, 0x3F, 0x2A, 0x2A, 0x2A, 0x15, 0x15, 0x15, 0x17, 0x1C, 0x20, 0x07, 0x0C, 0x13, 0x0C, 0x12, 0x17, 0x15, 0x1A, 0x1F, 0x00, 0x1D, 0x13, 0x00, 0x29, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} */ -int mFormatExportPal(const tPalette* p, int bits, char *vFileext, int optionflag, const char* backupExtension); +/*int mFormatExportPal(const tPalette* p, int bits, char *vFileext, int optionflag, const char* backupExtension);*/ int mFormatImportPal(tPalette* p,int* bits, const char* vFile); /* @@ -51,4 +52,6 @@ int mFormatImportPal(tPalette* p,int* bits, const char* vFile); memcpy(((image).pal),((array)+1),(16*3)) */ +int writePal(const char* file, int colors, const tColor* colorArray, int optionflag, const char* backupExtension); + #endif diff --git a/PR/src/include/palette.h b/PR/src/include/palette.h index ca33274..ea3b31c 100644 --- a/PR/src/include/palette.h +++ b/PR/src/include/palette.h @@ -62,5 +62,6 @@ int applyPalette(tPalette* p,tImage *i); 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); #endif diff --git a/PR/src/lib/actions/export.c b/PR/src/lib/actions/export.c index b86c3ec..e0aca26 100644 --- a/PR/src/lib/actions/export.c +++ b/PR/src/lib/actions/export.c @@ -71,7 +71,7 @@ extern FILE* outputStream; */ int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int optionflag, const char* vDatFileName, const char* vDatAuthor,const char* backupExtension,const char* format) { - char vFileext[MAX_FILENAME_SIZE]; + char file[MAX_FILENAME_SIZE]; int indexNumber; int ok; /* tImage image; * this is used to make a persistent palette */ @@ -107,10 +107,10 @@ int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int opti if (hasFlag(raw_flag)) res.type=0; /* If "extract as raw" is set, type is 0 */ /* get save file name (if unknown document is in the XML) */ - getFileName(vFileext,vDirExt,&res,vFiledat,vDatFileName,optionflag,backupExtension,format); + getFileName(file,vDirExt,&res,vFiledat,vDatFileName,optionflag,backupExtension,format); /* handle palette linking */ - switch (res.type) { + switch (res.type) { /* TODO: use if and elsif */ case eResTypePop1Palette4bits: { /* save and remember palette file */ tPaletteListItem e; /* TODO: decide if the palette list has to be erased from the code */ o=e.pal=currentPalette=getObject(&res,&ok); @@ -136,19 +136,23 @@ int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int opti o=getObject(&res,&ok); break; } - + /* TODO: warning counting here */ +/* if (!fatal(ok)) */ + ok=writeObject(o,file,optionflag,backupExtension); + /* Verbose information */ - if (hasFlag(verbose_flag)) { + /*if (hasFlag(verbose_flag)) { if (ok) { - fprintf(outputStream,PR_TEXT_EXPORT_WORKING,getFileNameFromPath(vFileext)); + fprintf(outputStream,PR_TEXT_EXPORT_WORKING,getFileNameFromPath(file)); } else { - fprintf(outputStream,PR_TEXT_EXPORT_ERROR,getFileNameFromPath(vFileext)); + fprintf(outputStream,PR_TEXT_EXPORT_ERROR,getFileNameFromPath(file)); } - } + } TODO: add warning counter */ + ok=1; /* efit the for and add !fatal(ok)*/ if (ok) count++; } else { /* If the DAT file is unknown, add it in the XML */ - getFileName(vFileext,vDirExt,&res,vFiledat,vDatFileName,optionflag,backupExtension,format); + getFileName(file,vDirExt,&res,vFiledat,vDatFileName,optionflag,backupExtension,format); } } } diff --git a/PR/src/lib/formats/pal.c b/PR/src/lib/formats/pal.c index c77ec20..60e8515 100644 --- a/PR/src/lib/formats/pal.c +++ b/PR/src/lib/formats/pal.c @@ -46,40 +46,25 @@ pal.c: Princed Resources : JASC PAL files support /*static const char* enter="\r\n";*/ /* Public functions */ -int mFormatExportPal(const tPalette* p, int bits, char *vFileext, int optionflag, const char* backupExtension) { -/* unsigned char* pal=malloc(256*4+50);*/ - unsigned char* aux=malloc(MAX_FILENAME_SIZE); - const tColor* palette; +int writePal(const char* file, int colors, const tColor* colorArray, int optionflag, const char* backupExtension) { int i; FILE* fd; - /* Export extra palette information */ - /*sprintf((char*)aux,"%s.more",vFileext); - writeData(data,1,(char*)aux,size,optionflag,backupExtension); TODO fix that */ - /* open file */ - if (!writeOpen(vFileext,&fd,optionflag)) return 0; /* false */ - - /* Convert palette from tPalette format to JASC format */ - getPalette(p, bits, &palette); + if (!writeOpen(file,&fd,optionflag)) return 0; /* false */ - fprintf(fd,"JASC-PAL\r\n%04d\r\n%d\r\n",100,1<<bits); - for (i=0;i<(1<<bits);i++) { + fprintf(fd,"JASC-PAL\r\n%04d\r\n%d\r\n",100,colors); + for (i=0;i<colors;i++) { fprintf(fd,"%d %d %d\r\n", - palette[i].r, - palette[i].g, - palette[i].b + colorArray[i].r, + colorArray[i].g, + colorArray[i].b ); } - /*for (i=0;pal[i];i++); - size=i-1;*/ /* save JASC palette */ -/* i=writeData(pal,0,vFileext,size,optionflag,backupExtension);*/ writeCloseOk(fd,optionflag,backupExtension); -/* free(pal);*/ - free(aux); return i; } diff --git a/PR/src/lib/object/object.c b/PR/src/lib/object/object.c index cf75ae6..cfd01b7 100644 --- a/PR/src/lib/object/object.c +++ b/PR/src/lib/object/object.c @@ -78,5 +78,32 @@ tObject getObject(tResource* r, int* error) { return o; } +int writeObject(tObject o, const char* file, int optionflag, const char* backupExtension) { + int error; + switch (o.type) { + case eResTypeLevel: + break; + case eResTypeBinary: /* Binary files */ + case eResTypeText: /* Text files */ + case eResTypeRaw: /* Raw files */ + break; + case eResTypePop1Palette4bits: /* save and remember palette file */ + error=objPalette_pop1_4bitsWrite(o.obj,file,optionflag,backupExtension); + break; + case eResTypePcspeaker: /* save pcs file */ + break; + case eResTypeMidi: /* save midi file */ + break; + case eResTypeWave: /* save wav file */ + break; + case eResTypeImage: /* save image */ + error=objImageWrite(o.obj,file,optionflag,backupExtension); + break; + default: + break; + } + + return error; +} diff --git a/PR/src/lib/object/palette/pop1_16c.c b/PR/src/lib/object/palette/pop1_16c.c index 8c5b8c8..3672695 100644 --- a/PR/src/lib/object/palette/pop1_16c.c +++ b/PR/src/lib/object/palette/pop1_16c.c @@ -41,6 +41,8 @@ palette.c: Princed Resources : The palette object implementation #include "palette.h" #include "memory.h" +#include "pal.h" + void addPop1Raw(tPalette* p,unsigned char* data, int dataSize); /***************************************************************\ @@ -179,9 +181,9 @@ void* objPalette_pop1_4bitsCreate(unsigned char* data, int size, int *error) { pal=(tPop1_4bitsPalette*)malloc(sizeof(tPop1_4bitsPalette)); for (i=0;i<16;i++) { - pal->c[i].r=data[(i*3)+5]<<2; - pal->c[i].g=data[(i*3)+6]<<2; - pal->c[i].b=data[(i*3)+7]<<2; + pal->c[i].r=data[(i*3)+4]<<2; + pal->c[i].g=data[(i*3)+5]<<2; + pal->c[i].b=data[(i*3)+6]<<2; } memcpy(pal->raw,data,100); @@ -191,3 +193,14 @@ void* objPalette_pop1_4bitsCreate(unsigned char* data, int size, int *error) { return (void*)pal; } +int objPalette_pop1_4bitsWrite(void* o, const char* file, int optionflag, const char* backupExtension) { + tPop1_4bitsPalette* pal=o; + /*unsigned char* aux=malloc(MAX_FILENAME_SIZE);*/ + /* TODO: add the write of the extra information */ + /* Export extra palette information */ + /*sprintf((char*)aux,"%s.more",file); + writeData(data,1,(char*)aux,size,optionflag,backupExtension); TODO fix that */ + + return writePal(file,16,pal->c,optionflag,backupExtension); +} + diff --git a/PR/src/lib/object/palette/pop2_256c.c b/PR/src/lib/object/palette/pop2_256c.c index 8c5b8c8..3672695 100644 --- a/PR/src/lib/object/palette/pop2_256c.c +++ b/PR/src/lib/object/palette/pop2_256c.c @@ -41,6 +41,8 @@ palette.c: Princed Resources : The palette object implementation #include "palette.h" #include "memory.h" +#include "pal.h" + void addPop1Raw(tPalette* p,unsigned char* data, int dataSize); /***************************************************************\ @@ -179,9 +181,9 @@ void* objPalette_pop1_4bitsCreate(unsigned char* data, int size, int *error) { pal=(tPop1_4bitsPalette*)malloc(sizeof(tPop1_4bitsPalette)); for (i=0;i<16;i++) { - pal->c[i].r=data[(i*3)+5]<<2; - pal->c[i].g=data[(i*3)+6]<<2; - pal->c[i].b=data[(i*3)+7]<<2; + pal->c[i].r=data[(i*3)+4]<<2; + pal->c[i].g=data[(i*3)+5]<<2; + pal->c[i].b=data[(i*3)+6]<<2; } memcpy(pal->raw,data,100); @@ -191,3 +193,14 @@ void* objPalette_pop1_4bitsCreate(unsigned char* data, int size, int *error) { return (void*)pal; } +int objPalette_pop1_4bitsWrite(void* o, const char* file, int optionflag, const char* backupExtension) { + tPop1_4bitsPalette* pal=o; + /*unsigned char* aux=malloc(MAX_FILENAME_SIZE);*/ + /* TODO: add the write of the extra information */ + /* Export extra palette information */ + /*sprintf((char*)aux,"%s.more",file); + writeData(data,1,(char*)aux,size,optionflag,backupExtension); TODO fix that */ + + return writePal(file,16,pal->c,optionflag,backupExtension); +} + diff --git a/PR/src/lib/object/palette/pop2_4bit.c b/PR/src/lib/object/palette/pop2_4bit.c index 8c5b8c8..3672695 100644 --- a/PR/src/lib/object/palette/pop2_4bit.c +++ b/PR/src/lib/object/palette/pop2_4bit.c @@ -41,6 +41,8 @@ palette.c: Princed Resources : The palette object implementation #include "palette.h" #include "memory.h" +#include "pal.h" + void addPop1Raw(tPalette* p,unsigned char* data, int dataSize); /***************************************************************\ @@ -179,9 +181,9 @@ void* objPalette_pop1_4bitsCreate(unsigned char* data, int size, int *error) { pal=(tPop1_4bitsPalette*)malloc(sizeof(tPop1_4bitsPalette)); for (i=0;i<16;i++) { - pal->c[i].r=data[(i*3)+5]<<2; - pal->c[i].g=data[(i*3)+6]<<2; - pal->c[i].b=data[(i*3)+7]<<2; + pal->c[i].r=data[(i*3)+4]<<2; + pal->c[i].g=data[(i*3)+5]<<2; + pal->c[i].b=data[(i*3)+6]<<2; } memcpy(pal->raw,data,100); @@ -191,3 +193,14 @@ void* objPalette_pop1_4bitsCreate(unsigned char* data, int size, int *error) { return (void*)pal; } +int objPalette_pop1_4bitsWrite(void* o, const char* file, int optionflag, const char* backupExtension) { + tPop1_4bitsPalette* pal=o; + /*unsigned char* aux=malloc(MAX_FILENAME_SIZE);*/ + /* TODO: add the write of the extra information */ + /* Export extra palette information */ + /*sprintf((char*)aux,"%s.more",file); + writeData(data,1,(char*)aux,size,optionflag,backupExtension); TODO fix that */ + + return writePal(file,16,pal->c,optionflag,backupExtension); +} +