author | ecalot
<ecalot> 2003-12-08 13:18:28 UTC |
committer | ecalot
<ecalot> 2003-12-08 13:18:28 UTC |
parent | be0a4113e132178618ad24e90481fb32b2f02724 |
PR/src/lib/formats/Attic/bmp.c | +14 | -9 |
PR/src/lib/formats/Attic/mid.c | +1 | -1 |
PR/src/lib/formats/Attic/pal.c | +14 | -26 |
PR/src/lib/formats/Attic/plv.c | +22 | -12 |
diff --git a/PR/src/lib/formats/Attic/bmp.c b/PR/src/lib/formats/Attic/bmp.c index 4f37052..861348f 100644 --- a/PR/src/lib/formats/Attic/bmp.c +++ b/PR/src/lib/formats/Attic/bmp.c @@ -39,11 +39,16 @@ bmp.c: Princed Resources : BMP file support #include "memory.h" #include "compile.h" -char mFormatExtractBmp(unsigned char* data, char *vFileext,unsigned long int size,tImage image) { +char mFormatExtractBmp(unsigned char* data, const char *vFileext,unsigned long int size,tImage image) { + /* + This function will expand the data into an image structure, + then the bitmap structure will be saved to disk + + Note: The old structure is passed by paremeters in order to + keep the right palette. + */ + if ((mExpandGraphic(data,&image,size))>0) { - //Create base dir - repairFolders(vFileext); - makebase(vFileext); //Write bitmap mWriteBitMap(image,vFileext); //free bitmap @@ -60,17 +65,18 @@ char mFormatCompileBmp(unsigned char* data, FILE* fp, tResource *res) { tImage img; unsigned char aux[10000]; - if (!mReadBitMap(&img,data,(*res).size)) return 0; + if (!mReadBitMap(&img,data,res->size)) return 0; mCompressGraphic(aux,&img,&size); + free(img.pix); mAddFileToDatFile(fp,aux,size); - (*res).size=size; //this was a bug (added to debug ;) ironic, don't you think? + res->size=size; //this was a bug (added to debug ;) ironic, don't you think? /* Note: after the debugging we realized this line was missing so this is not a bug anymore*/ return 1; } -char mWriteBitMap(tImage img,char* vFile) { +char mWriteBitMap(tImage img,const char* vFile) { //declare variables unsigned char i=0; @@ -120,8 +126,7 @@ char mWriteBitMap(tImage img,char* vFile) { 0x22,0x22,0x22,0 }; - - if ((bitmap = fopen (vFile,"wb"))==NULL) return 0; + if (!writeOpen(vFile, &bitmap)) return 0; filesize=((img.size+1)/2+118); width=img.width; diff --git a/PR/src/lib/formats/Attic/mid.c b/PR/src/lib/formats/Attic/mid.c index abb59a2..1c0d4e8 100644 --- a/PR/src/lib/formats/Attic/mid.c +++ b/PR/src/lib/formats/Attic/mid.c @@ -47,7 +47,7 @@ char mFormatCompileMid(unsigned char* data, FILE* fp, tResource *res) { unsigned char* file; file=getMemory((*res).size); - file[0]=(*res).type-2; //Now should be 0x02 //First character must be a 0x01 (wav type in dat) + file[0]=(res->type==4)?2:0; //Now should be 0x02 //First character must be a 0x01 (wav type in dat) memcpy(file+1,data,(*res).size); (*res).size++; mAddFileToDatFile(fp,file,(*res).size); diff --git a/PR/src/lib/formats/Attic/pal.c b/PR/src/lib/formats/Attic/pal.c index de48f7a..5ffa304 100644 --- a/PR/src/lib/formats/Attic/pal.c +++ b/PR/src/lib/formats/Attic/pal.c @@ -44,21 +44,6 @@ pal.c: Princed Resources : JASC PAL files support | Jasc Palette handling functions | \***************************************************************/ -//Private function taken from the parser - -#define chgnum(n) ((0x30<(n))&&((n)<0x3A))?((n)-(0x30)):0 - -//Tokenizer simple -//Sintaxis: getNumberToken(string texto,var int token,char caracterSeparador, -// var int startPosition, int deprecated) -int getNumberToken(char texto[],unsigned short int *token,char tokenizer,int* i,int k) { - char a; - //Copiar el string hasta que se encuentre el token o se termine la linea. - //En caso de que no entre el texto en el token, lo deja truncado pero avanza i hasta el final - for (*token=0;(((a=texto[(*i)++])!=tokenizer)&&a);(*token)=(*token)*10+chgnum(a)); - return (a); -} - //Public functions char mFormatExtractPal(unsigned char** data, char *vFileext,unsigned long int size) { //Convert palette from POP format to JASC format @@ -73,9 +58,12 @@ char mImportPalette(unsigned char** data, unsigned short *size) { unsigned char palh[]=PAL_HEADER; unsigned char pals[]=PAL_SAMPLE; unsigned char* pal; - unsigned short int parsed; + unsigned char* pal2; + unsigned char* data2; + //unsigned short int parsed; + unsigned char r,g,b; int i=0; - int k=0; + int k=16; //check size if (*size<130) return 0; @@ -84,20 +72,20 @@ char mImportPalette(unsigned char** data, unsigned short *size) { //set palette with sample memcpy(pal,pals,100); + pal2=pal+4; //verify jasc pal header while (palh[i]==(*data)[i++]); - if (i!=sizeof(palh)) return 0; + if (i!=sizeof(palh)) return 0; //pallete differs with headers //set current values - for (;k<16;k++) { - getNumberToken((*data),&parsed,' ',&i,4); - pal[(k*3)+4]=(parsed+2)>>2; - getNumberToken((*data),&parsed,' ',&i,4); - pal[(k*3)+5]=(parsed+2)>>2; - getNumberToken((*data),&parsed,'\r',&i,4); - pal[(k*3)+6]=(parsed+2)>>2; - i++; //Jump \n + data2=strtok(*data+sizeof(palh),"\r\n"); + while (k--) { + if (!sscanf(data2,"%d %d %d",&r,&g,&b)) return 0; + *(pal2++)=(r+2)>>2; + *(pal2++)=(g+2)>>2; + *(pal2++)=(b+2)>>2; + data2=strtok(NULL,"\r\n"); } //free old data and set new diff --git a/PR/src/lib/formats/Attic/plv.c b/PR/src/lib/formats/Attic/plv.c index 221a862..2d890b2 100644 --- a/PR/src/lib/formats/Attic/plv.c +++ b/PR/src/lib/formats/Attic/plv.c @@ -51,28 +51,33 @@ plv.c: Princed Resources : PLV prince level files support //Private function to get the currect date/time char* getDate() { //Code taken from RDR 1.4.1a coded by Enrique Calot - //TODO: improve variable names //TODO: define date string format for plv //Declare variables - static char semana [] = DATE_WEEKDAYS; - static char meses [] = DATE_MONTHS; + static char weeks [] = DATE_WEEKDAYS; + static char months [] = DATE_MONTHS; static char formated [37]; - time_t fechat; - struct tm* fecha; - int agno; + time_t datet; + struct tm* date; - time(&fechat); - fecha = gmtime(&fechat); - agno = (*fecha).tm_year+1900; + time(&datet); + date = gmtime(&datet); //Format: "Tue, 26 Nov 2002 22:16:39 GMT" - sprintf(formated,"%s, %d %s %.4d %.2d:%.2d:%.2d GMT",(semana+(4*((*fecha).tm_wday))),((*fecha).tm_mday),(meses+(4*((*fecha).tm_mon))),agno,((*fecha).tm_hour),((*fecha).tm_min),((*fecha).tm_sec)); + sprintf(formated,"%s, %d %s %.4d %.2d:%.2d:%.2d GMT", + weeks+4*(date->tm_wday), + date->tm_mday, + months+4*(date->tm_mon), + date->tm_year+1900, + date->tm_hour, + date->tm_min, + date->tm_sec + ); return formated; } -char mFormatExtractPlv(unsigned char* data, char *vFileext,unsigned long int size,unsigned char level, char* filename, char* desc, char* title) { +char mFormatExtractPlv(unsigned char* data, const char *vFileext,unsigned long int size,unsigned char level, const char* filename, const char* desc, const char* title) { //Plv files are saved as raw except you must ignore the checksum and add the plv constant file header //Variables @@ -80,6 +85,7 @@ char mFormatExtractPlv(unsigned char* data, char *vFileext,unsigned long int siz char ok; char sizeOfNow; char* now; + const char* nullString=""; //Get current time now=getDate(); @@ -88,6 +94,10 @@ char mFormatExtractPlv(unsigned char* data, char *vFileext,unsigned long int siz //Ignore checksum size--; + //Validate null strings when no description is set + if (desc==NULL) desc=nullString; + if (title==NULL) title=nullString; + /* Writing file */ //Safe open for writing mode @@ -114,9 +124,9 @@ char mFormatExtractPlv(unsigned char* data, char *vFileext,unsigned long int siz ok=ok&&fwrite(PLV_FOOT_ORIG_FILE,sizeof(PLV_FOOT_ORIG_FILE),1,target); ok=ok&&fwrite(filename,strlen(filename)+1,1,target); + //Close file and return ok=ok&&(!fclose(target)); return ok; - } char mFormatCompilePlv(unsigned char* data, FILE* fp, tResource *res) {