author | ecalot
<ecalot> 2006-02-22 18:56:39 UTC |
committer | ecalot
<ecalot> 2006-02-22 18:56:39 UTC |
parent | 5d949aad209da2a0db00e1a840094ebcb8c0d341 |
PR/src/include/image.h | +2 | -1 |
PR/src/include/object.h | +2 | -0 |
PR/src/include/other.h | +3 | -1 |
PR/src/include/palette.h | +4 | -3 |
PR/src/include/sound.h | +4 | -4 |
PR/src/lib/actions/import.c | +22 | -35 |
PR/src/lib/object/image/image16.c | +2 | -2 |
PR/src/lib/object/image/image2.c | +2 | -2 |
PR/src/lib/object/image/image256.c | +2 | -2 |
PR/src/lib/object/image/image_common.c | +2 | -2 |
PR/src/lib/object/object.c | +45 | -7 |
PR/src/lib/object/other/binary.c | +2 | -3 |
PR/src/lib/object/palette/pop1_16c.c | +6 | -6 |
PR/src/lib/object/palette/pop2_256c.c | +6 | -6 |
PR/src/lib/object/palette/pop2_4bit.c | +6 | -6 |
diff --git a/PR/src/include/image.h b/PR/src/include/image.h index e3cfc84..37c3108 100644 --- a/PR/src/include/image.h +++ b/PR/src/include/image.h @@ -35,6 +35,7 @@ image.h: Princed Resources : Image handling headers #define _IMAGE_H_ #include "reslist.h" +#include "binary.h" typedef struct { unsigned char r; @@ -63,7 +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); +void* objImageCreate(tBinary c, tObject palette, int *error); int objImageWrite(void* img,const char* file,int optionflag,const char* backupExtension); #define getCarry(a) ((((a)>>4)&7)+1) diff --git a/PR/src/include/object.h b/PR/src/include/object.h index 89fc5ae..8e5d6da 100644 --- a/PR/src/include/object.h +++ b/PR/src/include/object.h @@ -39,6 +39,8 @@ object.h: Princed Resources : Main item class types and prototypes tObject getObject(tResource* r, int* error); int writeObject(tObject o, const char* file, int optionflag, const char* backupExtension); +tObject readObject(const char* file,tResource newRes,int *result); +void setObject(tObject o,int *result); int paletteGetBits(tObject pal); int paletteGetColors(tObject pal); diff --git a/PR/src/include/other.h b/PR/src/include/other.h index a719ef6..2556e01 100644 --- a/PR/src/include/other.h +++ b/PR/src/include/other.h @@ -33,7 +33,9 @@ other.h: Princed Resources : #ifndef _OTHER_H_ #define _OTHER_H_ -void* objBinaryCreate(unsigned char* data, int size, int *error); +#include "binary.h" + +void* objBinaryCreate(tBinary c, int *error); int objBinaryWrite(void* o, const char* file, int optionflag, const char* backupExtension); #endif diff --git a/PR/src/include/palette.h b/PR/src/include/palette.h index f80d147..6cd0cb1 100644 --- a/PR/src/include/palette.h +++ b/PR/src/include/palette.h @@ -35,6 +35,7 @@ pal.h: Princed Resources : JASC PAL files support headers #define _PALETTE_H_ #include "image.h" /* tPalette, tImage */ +#include "binary.h" #define SAMPLE_PAL16 {\ {0x00,0x00,0x00},\ @@ -53,15 +54,15 @@ pal.h: Princed Resources : JASC PAL files support headers {0xff,0x50,0xff},\ {0xff,0xf8,0x50},\ {0xff,0xff,0xff}} - +/* int getPalette(const tPalette* p, int bits, const tColor** palette); int setPalette(tPalette* p, int bits, tColor* palette); tPalette createPalette(); int readPalette(tPalette* p, unsigned char* data, int dataSize); int applyPalette(tPalette* p,tImage *i); +*/ - -void* objPalette_pop1_4bitsCreate(unsigned char* data, int size, int *error); +void* objPalette_pop1_4bitsCreate(tBinary c, int *error); int objPalette_pop1_4bitsWrite(void* o, const char* file, int optionflag, const char* backupExtension); tColor* objPalette_pop1_4bitsGetColors(void* o); diff --git a/PR/src/include/sound.h b/PR/src/include/sound.h index c9825f0..823e6b7 100644 --- a/PR/src/include/sound.h +++ b/PR/src/include/sound.h @@ -39,15 +39,15 @@ sound.h: Princed Resources : #include "wav.h" int objSoundWrite(void* o, const char* file, int write(const char* file,tBinary* data,int optionflag, const char* backupExtension), int optionflag, const char* backupExtension); -void* objSoundCreate(unsigned char* data, int size, int *error); +void* objSoundCreate(tBinary c, int *error); #define objWaveWrite(a,b,c,d) objSoundWrite(a,b,writeWav,c,d) #define objMidiWrite(a,b,c,d) objSoundWrite(a,b,writeMid,c,d) #define objPcspeakerWrite(a,b,c,d) objBinaryWrite(a,b,c,d) -#define objWaveCreate(a,b,c) objSoundCreate(a,b,c) -#define objMidiCreate(a,b,c) objSoundCreate(a,b,c) -#define objPcspeakerCreate(a,b,c) objSoundCreate(a,b,c) +#define objWaveCreate(a,b) objSoundCreate(a,b) +#define objMidiCreate(a,b) objSoundCreate(a,b) +#define objPcspeakerCreate(a,b) objSoundCreate(a,b) #endif diff --git a/PR/src/lib/actions/import.c b/PR/src/lib/actions/import.c index 1d57027..b85dab8 100644 --- a/PR/src/lib/actions/import.c +++ b/PR/src/lib/actions/import.c @@ -45,6 +45,7 @@ import.c: Princed Resources : DAT Importer #include "idlist.h" #include "memory.h" #include "unknown.h" +#include "object.h" #include "bmp.h" #include "mid.h" @@ -54,33 +55,6 @@ import.c: Princed Resources : DAT Importer extern FILE* outputStream; -/***************************************************************\ -| Dat compiling primitive | -\***************************************************************/ - -/* Format detection function (private function, not in header file) */ -int mAddCompiledFileToDatFile(tResource* res,const char* vFile) { - /* return true if ok, false if error */ - switch (res->type) { - case eResTypeLevel: - return mFormatImportPlv(res); - case eResTypeImage: - return mFormatImportBmp(res); - case eResTypeWave: - return mFormatImportWav(res); - case eResTypeMidi: - case eResTypePcspeaker: - return mFormatImportMid(res); - case eResTypePop1Palette4bits: - /* return mFormatImportPal(res,vFile); TODO: fix */ - case eResTypeBinary: - default: - mWriteFileInDatFile(res); - break; - } - return 1; /* true */ -} - /***************************************************************\ | M A I N F U N C T I O N | \***************************************************************/ @@ -103,6 +77,8 @@ int import_full(const char* vFiledat, const char* vDirExt, tResourceList* r, int list_firstCursor(r); while ((res=list_getCursor(r))) { + int result; + tObject o; /* remember only id and type */ newRes.id=res->id; newRes.type=res->type; @@ -111,21 +87,25 @@ int import_full(const char* vFiledat, const char* vDirExt, tResourceList* r, int if (hasFlag(raw_flag)) newRes.type=0; /* compile from raw */ getFileName(vFileext,vDirExt,res,vFiledat,vDatFileName,optionflag,backupExtension,NULL); /* the file is in the archive, so I'll add it to the main DAT body */ - newRes.content=mLoadFileArray(vFileext); - if (newRes.content.size>0) { +/* newRes.content=mLoadFileArray(vFileext);*/ +/* if (newRes.content.size>0) {*/ /* TODO: let each format handle the files */ - if (!mAddCompiledFileToDatFile(&newRes,vFileext)) { + o=readObject(vFileext,newRes,&result); +/* if (!fatal(ok)) */ + setObject(o,&result); + +/* if (!fatal(ok)) { if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_ERRORS,getFileNameFromPath(vFileext)); error++; } else { if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_SUCCESS,getFileNameFromPath(vFileext)); ok++; - } - free(newRes.content.data); - } else { + }*/ + /*free(newRes.content.data);*/ +/* } else { if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_NOT_OPEN,getFileNameFromPath(vFileext)); error++; - } + }*/ list_nextCursor(r); } @@ -169,14 +149,20 @@ int import_partial(const char* vFiledat, const char* vDirExt, tResourceList* r, resourceListAddInfo(r,&res); if (isInTheItemMatchingList(res.path,res.id)) { /* If the resource was specified */ + int result; + tObject o; if ((!res.type)&&(!hasFlag(raw_flag))) res.type=verifyHeader(res.content); 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,NULL); + o=readObject(vFileext,newRes,&result); +/* if (!fatal(ok)) */ + setObject(o,&result); + /* the file is in the partial matching list, so I'll import */ - newRes.content=mLoadFileArray(vFileext); +/* newRes.content=mLoadFileArray(vFileext); if (newRes.content.size>0) { newRes.id=res.id; newRes.type=res.type; @@ -192,6 +178,7 @@ int import_partial(const char* vFiledat, const char* vDirExt, tResourceList* r, if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_NOT_OPEN,getFileNameFromPath(vFileext)); errors++; } + */ } else { /* the file wasn't in the partial matching list, so I'll re-copy it from the open DAT file */ mWriteFileInDatFileIgnoreChecksum(&res); diff --git a/PR/src/lib/object/image/image16.c b/PR/src/lib/object/image/image16.c index 174e367..0b7d26e 100644 --- a/PR/src/lib/object/image/image16.c +++ b/PR/src/lib/object/image/image16.c @@ -391,7 +391,7 @@ int pop2decompress(const unsigned char* input, int inputSize, int verify, unsign extern FILE* outputStream; -void* objImageCreate(unsigned char* data, int size, tObject palette, int *error) { /* use get like main.c */ +void* objImageCreate(tBinary cont, tObject palette, int *error) { /* use get like main.c */ /* * This function will expand the data into an image structure, @@ -406,7 +406,7 @@ void* objImageCreate(unsigned char* data, int size, tObject palette, int *error) image=(tImage*)malloc(sizeof(tImage)); /* Expand graphic and check results */ - *error=mExpandGraphic(data,image,size); + *error=mExpandGraphic(cont.data,image,cont.size); /* TODO: pass tBinary */ /* if ((result==COMPRESS_RESULT_WARNING)&&hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_EXPORT_BMP_WARN);*/ if (*error==COMPRESS_RESULT_FATAL) { diff --git a/PR/src/lib/object/image/image2.c b/PR/src/lib/object/image/image2.c index 174e367..0b7d26e 100644 --- a/PR/src/lib/object/image/image2.c +++ b/PR/src/lib/object/image/image2.c @@ -391,7 +391,7 @@ int pop2decompress(const unsigned char* input, int inputSize, int verify, unsign extern FILE* outputStream; -void* objImageCreate(unsigned char* data, int size, tObject palette, int *error) { /* use get like main.c */ +void* objImageCreate(tBinary cont, tObject palette, int *error) { /* use get like main.c */ /* * This function will expand the data into an image structure, @@ -406,7 +406,7 @@ void* objImageCreate(unsigned char* data, int size, tObject palette, int *error) image=(tImage*)malloc(sizeof(tImage)); /* Expand graphic and check results */ - *error=mExpandGraphic(data,image,size); + *error=mExpandGraphic(cont.data,image,cont.size); /* TODO: pass tBinary */ /* if ((result==COMPRESS_RESULT_WARNING)&&hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_EXPORT_BMP_WARN);*/ if (*error==COMPRESS_RESULT_FATAL) { diff --git a/PR/src/lib/object/image/image256.c b/PR/src/lib/object/image/image256.c index 174e367..0b7d26e 100644 --- a/PR/src/lib/object/image/image256.c +++ b/PR/src/lib/object/image/image256.c @@ -391,7 +391,7 @@ int pop2decompress(const unsigned char* input, int inputSize, int verify, unsign extern FILE* outputStream; -void* objImageCreate(unsigned char* data, int size, tObject palette, int *error) { /* use get like main.c */ +void* objImageCreate(tBinary cont, tObject palette, int *error) { /* use get like main.c */ /* * This function will expand the data into an image structure, @@ -406,7 +406,7 @@ void* objImageCreate(unsigned char* data, int size, tObject palette, int *error) image=(tImage*)malloc(sizeof(tImage)); /* Expand graphic and check results */ - *error=mExpandGraphic(data,image,size); + *error=mExpandGraphic(cont.data,image,cont.size); /* TODO: pass tBinary */ /* if ((result==COMPRESS_RESULT_WARNING)&&hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_EXPORT_BMP_WARN);*/ if (*error==COMPRESS_RESULT_FATAL) { diff --git a/PR/src/lib/object/image/image_common.c b/PR/src/lib/object/image/image_common.c index 174e367..0b7d26e 100644 --- a/PR/src/lib/object/image/image_common.c +++ b/PR/src/lib/object/image/image_common.c @@ -391,7 +391,7 @@ int pop2decompress(const unsigned char* input, int inputSize, int verify, unsign extern FILE* outputStream; -void* objImageCreate(unsigned char* data, int size, tObject palette, int *error) { /* use get like main.c */ +void* objImageCreate(tBinary cont, tObject palette, int *error) { /* use get like main.c */ /* * This function will expand the data into an image structure, @@ -406,7 +406,7 @@ void* objImageCreate(unsigned char* data, int size, tObject palette, int *error) image=(tImage*)malloc(sizeof(tImage)); /* Expand graphic and check results */ - *error=mExpandGraphic(data,image,size); + *error=mExpandGraphic(cont.data,image,cont.size); /* TODO: pass tBinary */ /* if ((result==COMPRESS_RESULT_WARNING)&&hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_EXPORT_BMP_WARN);*/ if (*error==COMPRESS_RESULT_FATAL) { diff --git a/PR/src/lib/object/object.c b/PR/src/lib/object/object.c index 6f4ff99..c39f49b 100644 --- a/PR/src/lib/object/object.c +++ b/PR/src/lib/object/object.c @@ -51,27 +51,27 @@ tObject getObject(tResource* r, int* error) { o.type=r->type; switch (o.type) { case eResTypeLevel: - /*o.obj=objLevelCreate(r->data,r->size,r->number,vDatFileName,r->name,r->desc,r->datAuthor,error); */ + /*o.obj=objLevelCreate(r->content,r->number,vDatFileName,r->name,r->desc,r->datAuthor,error); */ break; case eResTypeBinary: /* Binary files */ case eResTypeText: /* Text files */ case eResTypeRaw: /* Raw files */ - o.obj=objBinaryCreate(r->content.data,r->content.size,error); + o.obj=objBinaryCreate(r->content,error); break; case eResTypePop1Palette4bits: /* save and remember palette file */ - o.obj=objPalette_pop1_4bitsCreate(r->content.data,r->content.size,error); + o.obj=objPalette_pop1_4bitsCreate(r->content,error); break; case eResTypePcspeaker: /* save pcs file */ - o.obj=objPcspeakerCreate(r->content.data,r->content.size,error); + o.obj=objPcspeakerCreate(r->content,error); break; case eResTypeMidi: /* save midi file */ - o.obj=objMidiCreate(r->content.data,r->content.size,error); + o.obj=objMidiCreate(r->content,error); break; case eResTypeWave: /* save wav file */ - o.obj=objWaveCreate(r->content.data,r->content.size,error); + o.obj=objWaveCreate(r->content,error); break; case eResTypeImage: /* save image */ - o.obj=objImageCreate(r->content.data,r->content.size,r->palette,error); + o.obj=objImageCreate(r->content,r->palette,error); break; default: break; @@ -124,5 +124,43 @@ tColor* paletteGetColorArray(tObject pal) { } } +/***************************************************************\ +| Dat compiling primitive | +\***************************************************************/ +void setObject(tObject o,int *result) { +} + +/* Format detection function (private function, not in header file) */ +tObject readObject(const char* file,tResource res,int *result) { + /* return true if ok, false if error */ + tObject o; + switch (res.type) { + case eResTypeLevel: + /*o.obj=objLevelRead(file,res.content,result);*/ + break; + case eResTypeImage: + /*o.obj=objImageRead(file,res.content,res.palette,result);*/ + break; + case eResTypeWave: + /*o.obj=objWaveRead(file,res.content,result);*/ + break; + case eResTypeMidi: + /*o.obj=objMidiRead(file,res.content,result);*/ + break; + case eResTypePcspeaker: + /*o.obj=objPcspeakerRead(file,res.content,result);*/ + break; + case eResTypePop1Palette4bits: + /*o.obj=objPop1Palette4bitsRead(file,res.content,result);*/ + break; + case eResTypeBinary: + default: + /*o.obj=objBinatyRead(file,res,result);*/ + break; + } + o.type=res.type; + + return o; +} diff --git a/PR/src/lib/object/other/binary.c b/PR/src/lib/object/other/binary.c index fbe136b..92858b1 100644 --- a/PR/src/lib/object/other/binary.c +++ b/PR/src/lib/object/other/binary.c @@ -44,13 +44,12 @@ | Binary Object | \***************************************************************/ -void* objBinaryCreate(unsigned char* data, int size, int *error) { /* use get like main.c */ +void* objBinaryCreate(tBinary cont, int *error) { /* use get like main.c */ tBinary* r; *error=PR_RESULT_SUCCESS; r=(tBinary*)malloc(sizeof(tBinary)); - r->data=data; - r->size=size; + *r=cont; return (void*)r; } diff --git a/PR/src/lib/object/palette/pop1_16c.c b/PR/src/lib/object/palette/pop1_16c.c index b500cf2..be4b4ea 100644 --- a/PR/src/lib/object/palette/pop1_16c.c +++ b/PR/src/lib/object/palette/pop1_16c.c @@ -169,11 +169,11 @@ typedef struct { unsigned char raw[100]; }tPop1_4bitsPalette; -void* objPalette_pop1_4bitsCreate(unsigned char* data, int size, int *error) { +void* objPalette_pop1_4bitsCreate(tBinary cont, int *error) { int i; tPop1_4bitsPalette* pal; - if (size!=100) { + if (cont.size!=100) { *error=PR_RESULT_XML_AND_DAT_FORMAT_DO_NOT_MATCH; return NULL; } @@ -181,12 +181,12 @@ 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)+4]<<2; - pal->c[i].g=data[(i*3)+5]<<2; - pal->c[i].b=data[(i*3)+6]<<2; + pal->c[i].r=cont.data[(i*3)+4]<<2; + pal->c[i].g=cont.data[(i*3)+5]<<2; + pal->c[i].b=cont.data[(i*3)+6]<<2; } - memcpy(pal->raw,data,100); + memcpy(pal->raw,cont.data,100); *error=PR_RESULT_SUCCESS; diff --git a/PR/src/lib/object/palette/pop2_256c.c b/PR/src/lib/object/palette/pop2_256c.c index b500cf2..be4b4ea 100644 --- a/PR/src/lib/object/palette/pop2_256c.c +++ b/PR/src/lib/object/palette/pop2_256c.c @@ -169,11 +169,11 @@ typedef struct { unsigned char raw[100]; }tPop1_4bitsPalette; -void* objPalette_pop1_4bitsCreate(unsigned char* data, int size, int *error) { +void* objPalette_pop1_4bitsCreate(tBinary cont, int *error) { int i; tPop1_4bitsPalette* pal; - if (size!=100) { + if (cont.size!=100) { *error=PR_RESULT_XML_AND_DAT_FORMAT_DO_NOT_MATCH; return NULL; } @@ -181,12 +181,12 @@ 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)+4]<<2; - pal->c[i].g=data[(i*3)+5]<<2; - pal->c[i].b=data[(i*3)+6]<<2; + pal->c[i].r=cont.data[(i*3)+4]<<2; + pal->c[i].g=cont.data[(i*3)+5]<<2; + pal->c[i].b=cont.data[(i*3)+6]<<2; } - memcpy(pal->raw,data,100); + memcpy(pal->raw,cont.data,100); *error=PR_RESULT_SUCCESS; diff --git a/PR/src/lib/object/palette/pop2_4bit.c b/PR/src/lib/object/palette/pop2_4bit.c index b500cf2..be4b4ea 100644 --- a/PR/src/lib/object/palette/pop2_4bit.c +++ b/PR/src/lib/object/palette/pop2_4bit.c @@ -169,11 +169,11 @@ typedef struct { unsigned char raw[100]; }tPop1_4bitsPalette; -void* objPalette_pop1_4bitsCreate(unsigned char* data, int size, int *error) { +void* objPalette_pop1_4bitsCreate(tBinary cont, int *error) { int i; tPop1_4bitsPalette* pal; - if (size!=100) { + if (cont.size!=100) { *error=PR_RESULT_XML_AND_DAT_FORMAT_DO_NOT_MATCH; return NULL; } @@ -181,12 +181,12 @@ 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)+4]<<2; - pal->c[i].g=data[(i*3)+5]<<2; - pal->c[i].b=data[(i*3)+6]<<2; + pal->c[i].r=cont.data[(i*3)+4]<<2; + pal->c[i].g=cont.data[(i*3)+5]<<2; + pal->c[i].b=cont.data[(i*3)+6]<<2; } - memcpy(pal->raw,data,100); + memcpy(pal->raw,cont.data,100); *error=PR_RESULT_SUCCESS;