| author | ecalot
<ecalot> 2004-06-16 21:11:45 UTC |
| committer | ecalot
<ecalot> 2004-06-16 21:11:45 UTC |
| parent | 19958133b0d33597e6f30b42a667799739ae2d80 |
| FP/src/include/compress.h | +94 | -0 |
| FP/src/include/dat.h | +1 | -1 |
| FP/src/include/disk.h | +3 | -0 |
| FP/src/include/resources.h | +33 | -3 |
| FP/src/res/dat.c | +3 | -4 |
| FP/src/res/disk.c | +11 | -22 |
| FP/src/res/resources.c | +9 | -107 |
diff --git a/FP/src/include/compress.h b/FP/src/include/compress.h new file mode 100644 index 0000000..784830d --- /dev/null +++ b/FP/src/include/compress.h @@ -0,0 +1,94 @@ +/* Princed V3 - Prince of Persia Level Editor for PC Version + Copyright (C) 2003 Princed Development Team + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + The authors of this program may be contacted at http://forum.princed.com.ar +*/ + +/* +compress.c: Princed Resources : Image Compressor headers +\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf + Copyright 2003 Princed Development Team + Created: 24 Aug 2003 + + Author: Enrique Calot <ecalot.cod@princed.com.ar> + Version: 1.01 (2003-Oct-23) + + Note: + DO NOT remove this copyright notice +*/ + +#ifndef _COMPRESS_H_ +#define _COMPRESS_H_ + +#define SIZE_OF_PALETTE 3*16 + +#define COMPRESS_RAW 0x00 +#define COMPRESS_RLE_LR 0x01 +#define COMPRESS_RLE_UD 0x02 +#define COMPRESS_LZG_LR 0x03 +#define COMPRESS_LZG_UD 0x04 + +#define COMPRESS_WORKING_ALGORITHMS 3 + +#define COMPRESS_RESULT_FATAL -2 +#define COMPRESS_RESULT_WARNING -1 +#define COMPRESS_RESULT_SUCCESS 0 + +/* reserved memory for the Lzx algorithm */ +#define MAX_MOD_SIZE_IN_LZG 32001 /* 38401 */ +/* modulus to be used in the 10 bits of the algorithm */ +#define MAX_MXD_SIZE_IN_LZG 0x400 + +typedef struct { + int width; + int widthInBytes; + int height; + unsigned char* pix; + unsigned char pal[SIZE_OF_PALETTE]; + unsigned char type; /* XY where X=B if 4 bits or X=0 if 1 bit; Y=algorithm */ +}tImage; + +/* Prototypes */ + +int mCompressGraphic(unsigned char** a,tImage* i, int* size); +int mExpandGraphic(const unsigned char* array,tImage *image, int size); + +#define getCarry(a) ((a)>>6) +#define getAlgor(a) a&0x4F + +/* + Class future definitions + +public: + char cPrincedGraph::mOpenGraphDat (char* fileName); + char cPrincedGraph::mSaveGraphDat (char* fileName); + char cPrincedGraph::mGetGraphFull (int id, CBitmap &bitmap, CBitmap &mask); + char cPrincedGraph::mGetGraphMap (int id, CBitmap &bitmap); + char cPrincedGraph::mGetGraphMask (int id, CBitmap &bmask); + char cPrincedGraph::mSetGraph (int id, CBitmap &bitmap); + int cPrincedGraph::mGetGraphCount (); + char cPrincedGraph::mSaveImportBmp (int id, char* fileName); + char cPrincedGraph::mSaveExportBmp (int id, char* fileName); + +private: + unsigned char* file; + int fileSize; + tImage* imageArray[256]; + int imageArrayLength; + +*/ +#endif diff --git a/FP/src/include/dat.h b/FP/src/include/dat.h index a162a60..0315d82 100644 --- a/FP/src/include/dat.h +++ b/FP/src/include/dat.h @@ -52,7 +52,7 @@ mWriteCloseDatFile(r,dontSave,optionflag,backupExtension) #ifdef PR_DAT_INCLUDE_DATREAD /* DAT reading primitives */ int mReadBeginDatFile(unsigned short int *numberOfItems,const char* vFile); -int mReadFileInDatFile(int indexNumber,unsigned char* *data,unsigned long int *size); +int mReadFileInDatFile(int indexNumber,unsigned char** data,unsigned long int *size); int mReadInitResource(tResource** res,const unsigned char* data,long size); void mReadCloseDatFile(); #endif diff --git a/FP/src/include/disk.h b/FP/src/include/disk.h index 2e92498..29df8ab 100644 --- a/FP/src/include/disk.h +++ b/FP/src/include/disk.h @@ -44,6 +44,9 @@ disk.h: Princed Resources : Disk Access & File handling functions headers /* 64 Kb */ #define SIZE_OF_FILE 256*1024 +#define DIR_SEPARATOR '/' + + typedef enum {eFile,eDirectory,eNotFound}whatIs; #define charToUpper(a) ((a)&0xDF) diff --git a/FP/src/include/resources.h b/FP/src/include/resources.h index 707ee46..4695cec 100644 --- a/FP/src/include/resources.h +++ b/FP/src/include/resources.h @@ -46,9 +46,39 @@ resources.h: Free Prince : Resource Handler //tWave resGetWave(int dd, int resId); //tImage resGetImage(int dd, int resId); -enum tDataType {eImages=2,eWave,eMidi,eLevels} - -typedef struct tData { +typedef enum {eImages=2,eWave,eMidi,eLevels}tDataType; + +#define MAX_FILENAME_SIZE 260 +#define MAX_RES_COUNT 25000 + +/* Item Types */ + +#define RES_TYPE_RAW 0 +#define RES_TYPE_LEVEL 1 +#define RES_TYPE_IMAGE 2 +#define RES_TYPE_WAVE 3 +#define RES_TYPE_MIDI 4 +#define RES_TYPE_BINARY 5 +#define RES_TYPE_PALETTE 6 +#define RES_TYPE_PCSPEAKER 7 + +#define RES_TYPECOUNT 8 + +/* types */ +typedef struct { + unsigned short int palette; + unsigned short int size; + unsigned long int offset; + unsigned char number; /* Used for level number */ + char type; + char* path; + unsigned char* palAux; + char* name; + char* desc; +}tResource; + + +typedef struct { int frames; tDataType type; void* pFrames; diff --git a/FP/src/res/dat.c b/FP/src/res/dat.c index 070ba99..6bc9a6b 100644 --- a/FP/src/res/dat.c +++ b/FP/src/res/dat.c @@ -33,7 +33,6 @@ dat.c: Princed Resources : DAT library #include <stdio.h> #include <string.h> -#include "pr.h" #include "disk.h" #include "dat.h" @@ -129,9 +128,9 @@ int mReadInitResource(tResource** res,const unsigned char* data,long size) { (*res)->number=0; (*res)->size=(unsigned short int)size; (*res)->offset=(unsigned short)offset; /* TODO delete this line */ - (*res)->type=verifyHeader(data,(unsigned short int)size); + /* (*res)->type=verifyHeader(data,(unsigned short int)size); */ } else { /* If resource type is invalid or 0, the type will be decided by PR */ - if (!((*res)->type)) (*res)->type=verifyHeader(data,(unsigned short int)size); + if (!((*res)->type)) (*res)->type=0;//verifyHeader(data,(unsigned short int)size); } return 0; } @@ -154,7 +153,7 @@ int mWriteBeginDatFile(const char* vFile, int optionflag) { 0 File couldn't be open */ - if (writeOpen(vFile,&writeDatFile,optionflag|backup_flag)) { + if (writeOpen(vFile,&writeDatFile,optionflag)) { fseek(writeDatFile,6,SEEK_SET); return 1; } else { diff --git a/FP/src/res/disk.c b/FP/src/res/disk.c index afb01d2..094b39f 100644 --- a/FP/src/res/disk.c +++ b/FP/src/res/disk.c @@ -39,31 +39,21 @@ disk.c: Princed Resources : Disk Access & File handling functions /* Defines */ #include "memory.h" #include <string.h> -#include "pr.h" #include "disk.h" //#include "xmlparse.h" /* equalsIgnoreCase */ #define IGNORERECURSIVEFUNCTIONS +#define UNIX #include <sys/types.h> #include <sys/stat.h> +#include "resources.h" #ifdef UNIX - #define defmkdir(a) mkdir (a,(mode_t)0755) - #include <dirent.h> - #include <termios.h> - #include <unistd.h> - #include <fcntl.h> - #define osIndepGetCharacter() getchar() + #define defmkdir(a) mkdir (a,(mode_t)0755) #else - #include <direct.h> - #include "direntwin.h" - #define defmkdir(a) mkdir (a) - #include <conio.h> - #define osIndepGetCharacter() getche() + #define defmkdir(a) mkdir (a) #endif -extern FILE* outputStream; - /***************************************************************\ | Disk Access & File handling functions | \***************************************************************/ @@ -72,7 +62,6 @@ extern FILE* outputStream; const char *repairFolders(const char* a) { int i,k; static char result[MAX_FILENAME_SIZE]; -fld("rf1"); for (i=0,k=0;a[i]&&(k<MAX_FILENAME_SIZE);) { if (isDirSep(a,i)) { @@ -85,9 +74,7 @@ fld("rf1"); } k++; } -fld("rf2"); result[k]=0; -fld("rf3"); return result; } @@ -187,7 +174,7 @@ int writeClose(FILE* fp,int dontSave,int optionflag,const char* backupExtension) char* fileName; unsigned long int size; - if (getFromOpenFilesList(fp,&fileName,&content,&size)) { + //if (getFromOpenFilesList(fp,&fileName,&content,&size)) { if (dontSave) { fclose(fp); if (size) { @@ -197,7 +184,9 @@ int writeClose(FILE* fp,int dontSave,int optionflag,const char* backupExtension) } else { remove(fileName); } - } else { + //} +#if 0 + else { /* File Existed before and we need to back it up */ if (hasFlag(backup_flag)) { char aux[MAX_FILENAME_SIZE]; @@ -212,7 +201,7 @@ int writeClose(FILE* fp,int dontSave,int optionflag,const char* backupExtension) fwrite(content,1,size,fp); } } - +#endif free(fileName); if (size) free(content); } @@ -255,8 +244,8 @@ int writeOpen(const char* vFileext, FILE* *fp, int optionflag) { if not, we need to know the name in case we need to delete it */ - addFileToOpenFilesList(file,hasFlag(backup_flag)); - if ((result=((*fp=fopen(file,"wb"))!=NULL))) addPointerToOpenFilesList(*fp); +// addFileToOpenFilesList(file,hasFlag(backup_flag)); + result=((*fp=fopen(file,"wb"))!=NULL);// addPointerToOpenFilesList(*fp); return result; } diff --git a/FP/src/res/resources.c b/FP/src/res/resources.c index dbd9217..8174356 100644 --- a/FP/src/res/resources.c +++ b/FP/src/res/resources.c @@ -37,6 +37,8 @@ extract.c: Princed Resources : DAT Extractor #include <string.h> #include "freeprince.h" +#include "compress.h" + #include "dat.h" #include "disk.h" @@ -61,126 +63,26 @@ for (id=0;id<MAX_RES_COUNT;id++) {\ For parameter documentation, see pr.c */ -int extract(const char* vFiledat,const char* vDirExt, tResource* r[], int optionflag, const char* vDatFileName, const char* vDatAuthor,const char* backupExtension) { - char vFileext[MAX_FILENAME_SIZE]; +int prVerifyDatType(const char* vFiledat) { int indexNumber; - int ok=1; long int id; - tImage image; /* this is used to make a persistent palette */ unsigned char* data; unsigned long int size; + int type=RES_TYPE_BINARY; unsigned short int numberOfItems; - unsigned short int paletteId=0; /* Initialize abstract variables to read this new DAT file */ if (!mReadBeginDatFile(&numberOfItems,vFiledat)) return -1; -fld("a"); - /* Initializes the palette list */ - initializePaletteList; -fld("b"); /* main loop */ - for (indexNumber=0;ok&&(indexNumber<numberOfItems);indexNumber++) { + for (indexNumber=0;(indexNumber<numberOfItems)&&(type==RES_TYPE_BINARY);indexNumber++) { id=mReadFileInDatFile(indexNumber,&data,&size); -fld("c"); -printf("*K) id=%d size=%d %d:%d:%d:%d:%d:%d\n",id,size,data[0],data[1],data[2],data[3],data[4],data[5]); - - if (id<0) return -3; /* Read error */ + if (id<0) return -1; /* Read error */ if (id==0xFFFF) continue; /* Tammo Jan Bug fix */ - if (id>=MAX_RES_COUNT) return -3; /* A file with an ID out of range will be treated as invalid */ -fld("d"); - - /* set resource information on this index entry */ - if (mReadInitResource(r+id,data,size)) return -2; -fld("e"); -printf("z->%d\n",r[id]->type); - if ((r[id]->type==RES_TYPE_PALETTE)||isInThePartialList(r[id]->path,id)) { /* If the resource was specified or is a palette, do the tasks */ - if (!(hasFlag(unknown_flag))) { /* If unknown flag is set do nothing but generate the unknown.xml file */ - if (hasFlag(raw_flag)) r[id]->type=0; /* If "extract as raw" is set, type is 0 */ - - /* get save file name (if unknown document it in the xml) */ - getFileName(vFileext,vDirExt,r[id],(unsigned short)id,vFiledat,vDatFileName,optionflag,backupExtension); -fld("f"); - switch (r[id]->type) { - case RES_TYPE_LEVEL: - ok=ok&&mFormatExportPlv(data,vFileext,size,r[id]->number,vDatFileName,r[id]->name,r[id]->desc,vDatAuthor,optionflag,backupExtension); - break; - case RES_TYPE_BINARY: /* Binary files */ - case RES_TYPE_RAW: /* Raw files */ - ok=ok&&writeData(data,1,vFileext,size,optionflag,backupExtension); /* Ignore checksum */ - break; - case RES_TYPE_PALETTE: /* save and remember palette file */ - /* This will remember the palette for the next images */ - r[id]->palAux=getMemory(size); - memcpy(r[id]->palAux,data,size); - if (!paletteId) { /* In case there is no loaded palettes load immediately the first found palette to clear garbage */ - mLoadPalette(data,image); - paletteId=id; - } - /* This will export the palette */ - if (isInThePartialList(r[id]->path,id)) /* If the palette was specified extract it */ - ok=ok&&mFormatExportPal(data,vFileext,size,optionflag,backupExtension); - break; - case RES_TYPE_PCSPEAKER: /* save pcs file */ - case RES_TYPE_MIDI: /* save midi file */ -printf("a->%d\n",ok); - ok=ok&&mFormatExportMid(data,vFileext,size,optionflag,backupExtension); -printf("b->%d\n",ok); - break; - case RES_TYPE_WAVE: /* save wav file */ - ok=ok&&mFormatExportWav(data,vFileext,size,optionflag,backupExtension); - break; - case RES_TYPE_IMAGE: /* save image */ - /* Palette handling */ -fld("Z1"); - if (r[id]->palette!=paletteId) { /* The palette isn't the already loaded */ - if (r[id]->palette) { /* We need a palette */ - /* - We need a palette and it is not the palette we have loaded in memory - So a new palette is going to be loaded. - */ - if ((r[r[id]->palette]->palAux)!=NULL) { /* If this palette wasn't loaded, it becomes loaded */ - mLoadPalette(r[r[id]->palette]->palAux,image); - paletteId=r[id]->palette; /* sets the new palette loaded */ - } - } - } - /* Export bitmap */ -fld("Z2"); - ok=ok&&mFormatExportBmp(data,vFileext,size,image,optionflag,backupExtension); -fld("Z3"); - break; - } - /* Verbose information */ - if (hasFlag(verbose_flag)) { - if (ok) { - fprintf(outputStream,PR_TEXT_EXPORT_WORKING,getFileNameFromPath(vFileext)); - } else { - fprintf(outputStream,PR_TEXT_EXPORT_ERROR,getFileNameFromPath(vFileext)); - } - } - } else { - /* if the dat file is unknown, add it in the xml */ - getFileName(vFileext,vDirExt,r[id],(unsigned short)id,vFiledat,vDatFileName,optionflag,backupExtension); - } - /*freeAllocation(data);*/ - } + if (id>=MAX_RES_COUNT) return -1; /* A file with an ID out of range will be treated as invalid */ + type=0;//verifyHeader(data,size); } - /* Free allocated resources, dynamic strings and the index */ - for (id=0;id<MAX_RES_COUNT;id++) { - if (r[id]!=NULL) { - freeAllocation(r[id]->palAux); - freeAllocation(r[id]->desc); - freeAllocation(r[id]->name); - freeAllocation(r[id]->path); - free(r[id]); - } - } mReadCloseDatFile(); - - /* Close unknownXML */ - endUnknownXml(optionflag,backupExtension); - return ok-1; + return type+10; } -