author | ecalot
<ecalot> 2003-12-14 18:56:48 UTC |
committer | ecalot
<ecalot> 2003-12-14 18:56:48 UTC |
parent | ae7e8fc9b14da6b614faf9952893613e5fabe129 |
PR/src/lib/formats/Attic/bmp.c | +14 | -16 |
PR/src/lib/formats/Attic/mid.c | +1 | -1 |
PR/src/lib/formats/Attic/pal.c | +9 | -9 |
PR/src/lib/formats/Attic/plv.c | +12 | -9 |
PR/src/lib/formats/Attic/wav.c | +6 | -5 |
diff --git a/PR/src/lib/formats/Attic/bmp.c b/PR/src/lib/formats/Attic/bmp.c index 861348f..6ac44b2 100644 --- a/PR/src/lib/formats/Attic/bmp.c +++ b/PR/src/lib/formats/Attic/bmp.c @@ -63,7 +63,7 @@ char mFormatExtractBmp(unsigned char* data, const char *vFileext,unsigned long i char mFormatCompileBmp(unsigned char* data, FILE* fp, tResource *res) { int size; tImage img; - unsigned char aux[10000]; + unsigned char aux[32700]; if (!mReadBitMap(&img,data,res->size)) return 0; mCompressGraphic(aux,&img,&size); @@ -71,7 +71,7 @@ char mFormatCompileBmp(unsigned char* data, FILE* fp, tResource *res) { free(img.pix); mAddFileToDatFile(fp,aux,size); - res->size=size; //this was a bug (added to debug ;) ironic, don't you think? + res->size=(unsigned short)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; } @@ -79,8 +79,6 @@ char mFormatCompileBmp(unsigned char* data, FILE* fp, tResource *res) { char mWriteBitMap(tImage img,const char* vFile) { //declare variables - unsigned char i=0; - unsigned char j=0; char b; char c; char a; @@ -149,11 +147,11 @@ char mWriteBitMap(tImage img,const char* vFile) { //BEGIN of format writing //Write ColorTable for (a=0;a<16;a++) { - b=a*3; - c=a<<2; - header[54+c]=(img.pal[b+2])*4; //Red - header[55+c]=(img.pal[b+1])*4; //Green - header[56+c]=(img.pal[b])*4; //Blue + b=(char)(a*3); + c=(char)(a<<2); + header[54+c]=(unsigned char)(img.pal[b+2]*4); //Red + header[55+c]=(unsigned char)(img.pal[b+1]*4); //Green + header[56+c]=(unsigned char)(img.pal[b]*4); //Blue } //Write header fwrite(header,118,1,bitmap); @@ -170,8 +168,8 @@ char mWriteBitMap(tImage img,const char* vFile) { } -char mReadBitMap(tImage* img,char* data, int size) { - char ok; +char mReadBitMap(tImage* img,unsigned char* data, int size) { + int ok; unsigned short int width; unsigned short int height; int width2; @@ -182,8 +180,8 @@ char mReadBitMap(tImage* img,char* data, int size) { ok=ok&& data[0]=='B' && data[1]=='M'; //Read sizes from header - width=data[18]+(data[19]<<8); - height=data[22]+(data[23]<<8); + width=(unsigned short)(data[18]+(data[19]<<8)); + height=(unsigned short)(data[22]+(data[23]<<8)); //Save sizes into image (*img).width=width; //width in pixels @@ -191,11 +189,11 @@ char mReadBitMap(tImage* img,char* data, int size) { (*img).size=height*width; //total of pixels //Calculate serialized widths - width=(width+1)>>1; //raw serialized width - width2=width+((-width)&3); //bmp serialized width + width=(unsigned short)((width+1)>>1); //raw serialized width + width2=width+((-width)&3); //bmp serialized width //Validate image and file size; get memory to allocate the image - ok=ok&& ( ((*img).height*width2) == (size-118)); + ok=ok&& ((img->height*width2)==(size-118)); ok=ok&& ( ((*img).pix=getMemory((*img).size/2)) != NULL ); //if validations==wrong diff --git a/PR/src/lib/formats/Attic/mid.c b/PR/src/lib/formats/Attic/mid.c index 1c0d4e8..1eb1bcf 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==4)?2:0; //Now should be 0x02 //First character must be a 0x01 (wav type in dat) + file[0]=(unsigned char)((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 5ffa304..b977c6b 100644 --- a/PR/src/lib/formats/Attic/pal.c +++ b/PR/src/lib/formats/Attic/pal.c @@ -59,7 +59,7 @@ char mImportPalette(unsigned char** data, unsigned short *size) { unsigned char pals[]=PAL_SAMPLE; unsigned char* pal; unsigned char* pal2; - unsigned char* data2; + char* data2; //unsigned short int parsed; unsigned char r,g,b; int i=0; @@ -79,12 +79,12 @@ char mImportPalette(unsigned char** data, unsigned short *size) { if (i!=sizeof(palh)) return 0; //pallete differs with headers //set current values - data2=strtok(*data+sizeof(palh),"\r\n"); + data2=strtok((char*)(*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; + *(pal2++)=(unsigned char)((r+2)>>2); + *(pal2++)=(unsigned char)((g+2)>>2); + *(pal2++)=(unsigned char)((b+2)>>2); data2=strtok(NULL,"\r\n"); } @@ -100,11 +100,11 @@ void mExportPalette(unsigned char** data, unsigned long int *size) { unsigned char* aux=getMemory(240); unsigned char i; - sprintf(pal,PAL_HEADER); + strcpy((char*)pal,PAL_HEADER); for (i=0;i<16;i++) { - sprintf(aux,pal); - sprintf(pal,"%s%d %d %d\r\n",aux,(*data)[(i*3)+5]<<2,(*data)[(i*3)+6]<<2,(*data)[(i*3)+7]<<2); + strcpy((char*)aux,(char*)pal); + sprintf((char*)pal,"%s%d %d %d\r\n",aux,(*data)[(i*3)+5]<<2,(*data)[(i*3)+6]<<2,(*data)[(i*3)+7]<<2); } for (i=0;pal[i];i++); free(*data); @@ -114,6 +114,6 @@ void mExportPalette(unsigned char** data, unsigned long int *size) { } //TODO: use a macro -void mLoadPalette(char* array,tImage *image) { +void mLoadPalette(unsigned char* array,tImage *image) { memcpy(image->pal,array+5,16*3); } diff --git a/PR/src/lib/formats/Attic/plv.c b/PR/src/lib/formats/Attic/plv.c index 2d890b2..1503e28 100644 --- a/PR/src/lib/formats/Attic/plv.c +++ b/PR/src/lib/formats/Attic/plv.c @@ -77,19 +77,20 @@ char* getDate() { } -char mFormatExtractPlv(unsigned char* data, const char *vFileext,unsigned long int size,unsigned char level, const char* filename, const char* desc, const 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, const char* vDatAuthor) { //Plv files are saved as raw except you must ignore the checksum and add the plv constant file header //Variables FILE* target; - char ok; - char sizeOfNow; + int ok; + unsigned char sizeOfNow; char* now; const char* nullString=""; + static const char* author="PR user"; //Get current time now=getDate(); - sizeOfNow=strlen(now)+1; + sizeOfNow=(unsigned char)(strlen(now)+1); //Ignore checksum size--; @@ -97,6 +98,7 @@ char mFormatExtractPlv(unsigned char* data, const char *vFileext,unsigned long i //Validate null strings when no description is set if (desc==NULL) desc=nullString; if (title==NULL) title=nullString; + if (vDatAuthor==NULL) vDatAuthor=author; /* Writing file */ @@ -113,7 +115,9 @@ char mFormatExtractPlv(unsigned char* data, const char *vFileext,unsigned long i ok=ok&&fwrite(data+1,size,1,target); //Write footers - ok=ok&&fwrite(PLV_FOOT,sizeof(PLV_FOOT),1,target); + ok=ok&&fwrite(PLV_FOOT_EDITOR,sizeof(PLV_FOOT_EDITOR),1,target); + ok=ok&&fwrite(vDatAuthor,strlen(vDatAuthor)+1,1,target); + ok=ok&&fwrite(PLV_FOOT_TITLE,sizeof(PLV_FOOT_TITLE),1,target); ok=ok&&fwrite(title,strlen(title)+1,1,target); ok=ok&&fwrite(PLV_FOOT_DESC,sizeof(PLV_FOOT_DESC),1,target); ok=ok&&fwrite(desc,strlen(desc)+1,1,target); @@ -126,18 +130,17 @@ char mFormatExtractPlv(unsigned char* data, const char *vFileext,unsigned long i //Close file and return ok=ok&&(!fclose(target)); - return ok; + return (char)ok; } char mFormatCompilePlv(unsigned char* data, FILE* fp, tResource *res) { -// unsigned char* file; unsigned long int size; //This is ignoring all kind of verifications and assuming (res->size)>PLV_HEADER_SIZE !!! //TODO: must verify the plv format version, if not 1, then PR is too old! - memcpy(&size,data+PLV_HEADER_SIZE_OFFSET,4); //Only when longs are 4 bytes - mAddFileToDatFile(fp,data+PLV_HEADER_A_SIZE+PLV_HEADER_B_SIZE+1+4,size); + //memcpy(&size,data+PLV_HEADER_SIZE_OFFSET,4); //Only when longs are 4 bytes +// mAddFileToDatFile(fp,data+PLV_HEADER_A_SIZE+PLV_HEADER_B_SIZE+1+4,size); // free(file); return 1; } diff --git a/PR/src/lib/formats/Attic/wav.c b/PR/src/lib/formats/Attic/wav.c index 41d3c3c..01ab224 100644 --- a/PR/src/lib/formats/Attic/wav.c +++ b/PR/src/lib/formats/Attic/wav.c @@ -34,14 +34,15 @@ wav.c: Princed Resources : WAV files support //Includes #include "wav.h" #include "compile.h" +#include "disk.h" -char mFormatExtractWav(unsigned char* data, char *vFileext,unsigned long int size) { +int mFormatExtractWav(unsigned char* data, char *vFileext,unsigned long int size) { FILE* target; - char ok; + int ok; unsigned char wav[]=WAVE_HEADER; size-=2; - ok=((target=fopen(vFileext,"wb"))!=NULL); + ok=writeOpen(vFileext,&target); wav[4]=(unsigned char)((size+36)&0xFF); wav[5]=(unsigned char)(((size+36)>>8)&0xFF); @@ -60,12 +61,12 @@ char mFormatExtractWav(unsigned char* data, char *vFileext,unsigned long int siz return ok; } -char mFormatCompileWav(unsigned char* data, FILE* fp, tResource *res) { +int mFormatCompileWav(unsigned char* data, FILE* fp, tResource *res) { unsigned char wav[]=WAVE_HEADER; int i=sizeof(wav); if ((*res).size<=i) return 0; - (*res).size-=(--i); + res->size-=(--i); while ((i==4||i==5||i==6||i==7||i==40||i==41||i==42||i==43||(data[i]==wav[i]))&&(i--)); data[sizeof(wav)-1]=1; //First character must be a 0x01 (wav type in dat) if (i==-1) mAddFileToDatFile(fp,data+sizeof(wav)-1,(*res).size);