author | ecalot
<ecalot> 2003-10-23 14:19:53 UTC |
committer | ecalot
<ecalot> 2003-10-23 14:19:53 UTC |
parent | beaba0656cfbcf2ce0ac7c12724931c9680567a9 |
PR/src/lib/actions/import.c | +56 | -50 |
PR/src/lib/compression/rle_compress.c | +38 | -45 |
PR/src/lib/compression/rle_decompress.c | +38 | -45 |
PR/src/lib/compression/rlev_decompress.c | +38 | -45 |
PR/src/lib/formats/Attic/bmp.c | +41 | -10 |
PR/src/lib/formats/Attic/pal.c | +34 | -3 |
PR/src/lib/formats/Attic/wav.c | +53 | -18 |
PR/src/lib/object/image/image16.c | +38 | -45 |
PR/src/lib/object/image/image2.c | +38 | -45 |
PR/src/lib/object/image/image256.c | +38 | -45 |
PR/src/lib/object/image/image_common.c | +38 | -45 |
PR/src/parser.c | +33 | -0 |
diff --git a/PR/src/lib/actions/import.c b/PR/src/lib/actions/import.c index 88d9041..9d9542a 100644 --- a/PR/src/lib/actions/import.c +++ b/PR/src/lib/actions/import.c @@ -1,3 +1,36 @@ +/* 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 +*/ + +/* +compile.c: Princed Resources : DAT Compiler +\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 +*/ + /***************************************************************\ | I M P L E M E N T A T I O N | \***************************************************************/ @@ -6,6 +39,7 @@ #include "compile.h" #include "memory.h" #include "bmp.h" +#include "mid.h" #include "wav.h" #include "pal.h" #include "parser.h" @@ -27,17 +61,13 @@ char mBeginDatFile(FILE* *fp,char* vFile) { void mAddFileToDatFile(FILE* fp, char* data, int size) { //calculates the checksum of a file - //unsigned char sndHeader[]={0,2}; unsigned char checksum=0; int k; for (k=0;k<size;k++) checksum+=data[k]; checksum=~checksum; -printf("mAddFileToDatFile: llega X1 size=%d\n",size); //writes the header and the midi sound fwrite(&checksum,1,1,fp); fwrite(data,size,1,fp); -printf("mAddFileToDatFile: llega X2\n"); - } void mSetEndFile(FILE* fp,int sizeOfIndex) { @@ -55,10 +85,10 @@ void mSetEndFile(FILE* fp,int sizeOfIndex) { int mCreateIndexInDatFile(FILE* fp, tResource* r[], char* vUpperFile) { //Add extra text at the end of the file - int k=2; - unsigned short int tot=0; - unsigned short int junk=0; unsigned short int i=0; + unsigned short int junk=0; + unsigned short int tot=0; + int k=2; int pos=ftell(fp); fwrite(&tot,2,1,fp); @@ -80,35 +110,19 @@ int mCreateIndexInDatFile(FILE* fp, tResource* r[], char* vUpperFile) { return k; } -//Format detection function -void mAddCompiledFileToDatFile(FILE* fp,unsigned char** data, tResource *res) { - printf("llega G size=%d\n",res->size); - +//Format detection function (private function, not in header file) +char mAddCompiledFileToDatFile(FILE* fp,unsigned char** data, tResource *res) { switch ((*res).type) { case 2: //compile bitmap - printf("llega 1\n"); - printf("bitmap size in=%d\n",res->size); - if (!mFormatCompileBmp(*data,fp,res)) { - printf("Error!!\n"); - } - printf("bitmap size out=%d\n",res->size); - break; + return mFormatCompileBmp(*data,fp,res); case 3: //compile wave mFormatCompileWav(*data,fp,res); break; case 4: //compile midi - //send to mid - { - unsigned char* file; - file=getMemory((*res).size); - file[0]=(*res).type-2; - memcpy(file+1,*data,(*res).size); - (*res).size++; - mAddFileToDatFile(fp,file,(*res).size); - free(file); - } + mFormatCompileMid(*data,fp,res); break; - case 6: + case 6: //compile palette + //TODO: make mFormatCompilePal and stop using char** for data mImportPalette(data,&((*res).size)); case 1: case 5: @@ -116,6 +130,7 @@ void mAddCompiledFileToDatFile(FILE* fp,unsigned char** data, tResource *res) { mAddFileToDatFile(fp,*data,(*res).size); break; } + return 1; } /***************************************************************\ @@ -134,24 +149,23 @@ char mSaveFile(char* vFile,unsigned char *d, int s) { } } -/* - Return values: - -1 File couldn't be open for writing - 00 File succesfully compiled - positive number: number of missing files - - -*/ int compile(char* vFiledat, char* vDirExt, tResource* r[], char opt) { + /* + Return values: + -1 File couldn't be open for writing + 00 File succesfully compiled + positive number: number of missing files + */ + FILE* fp; - char vUpperFile[200]; char vFileext[200]; - unsigned char* data; + char vUpperFile[200]; int ok=0; + unsigned char* data; unsigned short int i=0; if (!mBeginDatFile(&fp,vFiledat)) { - printf("Error opening the file.\r\n"); +// printf("Error opening the file.\r\n"); return -1; } @@ -164,18 +178,10 @@ int compile(char* vFiledat, char* vDirExt, tResource* r[], char opt) { //the file is in the archive, so I'll add it to the main dat body if ((*r[i]).size=mLoadFileArray(vFileext,&data)) { (*r[i]).offset=(unsigned short)ftell(fp); - mAddCompiledFileToDatFile(fp,&data,r[i]); - - { - char sss[300]; - sprintf(sss,"r1\\bmp%05d.raw",i); -printf("size: id=%d size=%d %02x %02x %02x %02x %02x %02x %02x\n",i,r[i]->size,data[0],data[1],data[2],data[3],data[4],data[5],data[6]); - - mSaveFile(sss,data,r[i]->size); + if (!mAddCompiledFileToDatFile(fp,&data,r[i])) { + ok++; } - free(data); - printf("libere ok\n"); } else { ok++; } diff --git a/PR/src/lib/compression/rle_compress.c b/PR/src/lib/compression/rle_compress.c index 7f7d781..87cebcd 100644 --- a/PR/src/lib/compression/rle_compress.c +++ b/PR/src/lib/compression/rle_compress.c @@ -1,3 +1,36 @@ +/* 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 +\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 +*/ + /***************************************************************\ | I M P L E M E N T A T I O N | \***************************************************************/ @@ -7,8 +40,7 @@ #include "memory.h" //reserved memory for the Lzx algorithm -#define MAX_MOD_SIZE_IN_LZX 32001 -//38401 +#define MAX_MOD_SIZE_IN_LZX 32001 /* 38401 */ //modulus to be used in the 10 bits of the algorithm #define MAX_MXD_SIZE_IN_LZX 0x400 @@ -30,8 +62,8 @@ unsigned char popBit(unsigned char *byte) { //Expands B3/B4 algorithm void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { - int pos,h; char k; + int pos,h; unsigned char maskbyte,rep; //printf("expandLzx %d %d \n",virtualSize,cursor); @@ -55,29 +87,24 @@ void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { //Compress B1/B2 algorithm void compressRle(unsigned char* data,tImage* img,int *dataSize) { -// //printf("llega 3.51\n"); //Declare pointers char* cursorData = data; char* counter; char* cursorPix = (*img).pix; char* imgEnd = (*img).pix+((*img).size>>1)-1; - //printf("llega 3.52\n"); while (cursorPix<imgEnd) { //Step 1: Create counter *(counter=(cursorData++))=-1; //Step 2: Look and copy the string until a repeated byte is found - while ((cursorPix<imgEnd)&&(*cursorPix!=*(cursorPix+1))&&((*counter)!=127)) { cursorPix++; (*counter)++; *(cursorData)=*(cursorPix-1); cursorData++; } -////printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd); - //cursorPix--; //Step 3: If there was a repeated string, let's ignore it and add the cursor with the repetitions if (*counter==-1) { while ((cursorPix<imgEnd)&&(*cursorPix==(*(cursorPix+1)))&&((*counter)!=-128)) { @@ -91,15 +118,9 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { } *(cursorData++)=0; *(cursorData++)=*(cursorPix); -// //printf("compressRle: cursorData=%d data=%d cursorPix=%d imgEnd=%d\n",(int)cursorData,(int)data,(int)((*img).pix),(int)imgEnd); - *dataSize=(int)cursorData-(int)data; + *dataSize=(int)cursorData-(int)data; //Note: data loss in 64 bits architectures } - - - - - //Expands an array into an image int mExpandGraphic(char* array,tImage *image, int virtualSize) { /* @@ -111,22 +132,19 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) { normaly: (* ignored types) checksum* - height - 00 - width - 00 - 00* - compression type */ -////printf("expand graphic le ejecuta %d\n",virtualSize); int cursor=0; int i=1; //Get memory for the image image->height=((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]) ; -i=i+2; + i=i+2; image->width =((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]); -i=i+2; + i=i+2; (*image).size =(*image).height*(*image).width; -//printf("h=%d, w=%d %x %x %x %x \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]); virtualSize=(((*image).height*((*image).width+((*image).width&1)))>>1); i++; -//printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize); switch ((unsigned char)array[i++]) { case PG_COMP_RAW: //No Compression Algorithm if (((*image).pix=getMemory(virtualSize))==NULL) return -1; @@ -163,18 +181,14 @@ i=i+2; } break; case PG_COMP_LZX_LR: //LZ Groody Up to Down Version Compression Algorithm - //printf("llega b4\n"); if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; expandLzx(array,image,&i,cursor,virtualSize); break; case PG_COMP_LZX_UD: //LZ Groody Left to Right Version Compression Algorithm -//printf("hi\n"); if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; { unsigned char* outputaux=getMemory(virtualSize); - //printf("antes\n"); expandLzx(array,image,&i,cursor,virtualSize); - //printf("despues\n"); //Transpose while (cursor<virtualSize) outputaux[transpose(cursor,(*image).width,(*image).height)]=(*image).pix[cursor++]; free((*image).pix); @@ -234,24 +248,3 @@ int mCompressGraphic(unsigned char* data,tImage i, int* size) { #endif return 1; } - -/***************************************************************\ -| File handling | -\***************************************************************/ - -//Deprecated -/* -char mLoadFilePalette(char* vFile,int address, char* pal) { - FILE *fp; - char aux; - - if ((fp=fopen(vFile,"rb"))==NULL) { - return 0; - } else { - fseek (fp, address, SEEK_SET); - aux=fread (pal,SIZE_OF_PALETTE,1,fp); - fclose(fp); - return aux; - } -} -*/ diff --git a/PR/src/lib/compression/rle_decompress.c b/PR/src/lib/compression/rle_decompress.c index 7f7d781..87cebcd 100644 --- a/PR/src/lib/compression/rle_decompress.c +++ b/PR/src/lib/compression/rle_decompress.c @@ -1,3 +1,36 @@ +/* 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 +\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 +*/ + /***************************************************************\ | I M P L E M E N T A T I O N | \***************************************************************/ @@ -7,8 +40,7 @@ #include "memory.h" //reserved memory for the Lzx algorithm -#define MAX_MOD_SIZE_IN_LZX 32001 -//38401 +#define MAX_MOD_SIZE_IN_LZX 32001 /* 38401 */ //modulus to be used in the 10 bits of the algorithm #define MAX_MXD_SIZE_IN_LZX 0x400 @@ -30,8 +62,8 @@ unsigned char popBit(unsigned char *byte) { //Expands B3/B4 algorithm void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { - int pos,h; char k; + int pos,h; unsigned char maskbyte,rep; //printf("expandLzx %d %d \n",virtualSize,cursor); @@ -55,29 +87,24 @@ void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { //Compress B1/B2 algorithm void compressRle(unsigned char* data,tImage* img,int *dataSize) { -// //printf("llega 3.51\n"); //Declare pointers char* cursorData = data; char* counter; char* cursorPix = (*img).pix; char* imgEnd = (*img).pix+((*img).size>>1)-1; - //printf("llega 3.52\n"); while (cursorPix<imgEnd) { //Step 1: Create counter *(counter=(cursorData++))=-1; //Step 2: Look and copy the string until a repeated byte is found - while ((cursorPix<imgEnd)&&(*cursorPix!=*(cursorPix+1))&&((*counter)!=127)) { cursorPix++; (*counter)++; *(cursorData)=*(cursorPix-1); cursorData++; } -////printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd); - //cursorPix--; //Step 3: If there was a repeated string, let's ignore it and add the cursor with the repetitions if (*counter==-1) { while ((cursorPix<imgEnd)&&(*cursorPix==(*(cursorPix+1)))&&((*counter)!=-128)) { @@ -91,15 +118,9 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { } *(cursorData++)=0; *(cursorData++)=*(cursorPix); -// //printf("compressRle: cursorData=%d data=%d cursorPix=%d imgEnd=%d\n",(int)cursorData,(int)data,(int)((*img).pix),(int)imgEnd); - *dataSize=(int)cursorData-(int)data; + *dataSize=(int)cursorData-(int)data; //Note: data loss in 64 bits architectures } - - - - - //Expands an array into an image int mExpandGraphic(char* array,tImage *image, int virtualSize) { /* @@ -111,22 +132,19 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) { normaly: (* ignored types) checksum* - height - 00 - width - 00 - 00* - compression type */ -////printf("expand graphic le ejecuta %d\n",virtualSize); int cursor=0; int i=1; //Get memory for the image image->height=((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]) ; -i=i+2; + i=i+2; image->width =((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]); -i=i+2; + i=i+2; (*image).size =(*image).height*(*image).width; -//printf("h=%d, w=%d %x %x %x %x \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]); virtualSize=(((*image).height*((*image).width+((*image).width&1)))>>1); i++; -//printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize); switch ((unsigned char)array[i++]) { case PG_COMP_RAW: //No Compression Algorithm if (((*image).pix=getMemory(virtualSize))==NULL) return -1; @@ -163,18 +181,14 @@ i=i+2; } break; case PG_COMP_LZX_LR: //LZ Groody Up to Down Version Compression Algorithm - //printf("llega b4\n"); if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; expandLzx(array,image,&i,cursor,virtualSize); break; case PG_COMP_LZX_UD: //LZ Groody Left to Right Version Compression Algorithm -//printf("hi\n"); if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; { unsigned char* outputaux=getMemory(virtualSize); - //printf("antes\n"); expandLzx(array,image,&i,cursor,virtualSize); - //printf("despues\n"); //Transpose while (cursor<virtualSize) outputaux[transpose(cursor,(*image).width,(*image).height)]=(*image).pix[cursor++]; free((*image).pix); @@ -234,24 +248,3 @@ int mCompressGraphic(unsigned char* data,tImage i, int* size) { #endif return 1; } - -/***************************************************************\ -| File handling | -\***************************************************************/ - -//Deprecated -/* -char mLoadFilePalette(char* vFile,int address, char* pal) { - FILE *fp; - char aux; - - if ((fp=fopen(vFile,"rb"))==NULL) { - return 0; - } else { - fseek (fp, address, SEEK_SET); - aux=fread (pal,SIZE_OF_PALETTE,1,fp); - fclose(fp); - return aux; - } -} -*/ diff --git a/PR/src/lib/compression/rlev_decompress.c b/PR/src/lib/compression/rlev_decompress.c index 7f7d781..87cebcd 100644 --- a/PR/src/lib/compression/rlev_decompress.c +++ b/PR/src/lib/compression/rlev_decompress.c @@ -1,3 +1,36 @@ +/* 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 +\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 +*/ + /***************************************************************\ | I M P L E M E N T A T I O N | \***************************************************************/ @@ -7,8 +40,7 @@ #include "memory.h" //reserved memory for the Lzx algorithm -#define MAX_MOD_SIZE_IN_LZX 32001 -//38401 +#define MAX_MOD_SIZE_IN_LZX 32001 /* 38401 */ //modulus to be used in the 10 bits of the algorithm #define MAX_MXD_SIZE_IN_LZX 0x400 @@ -30,8 +62,8 @@ unsigned char popBit(unsigned char *byte) { //Expands B3/B4 algorithm void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { - int pos,h; char k; + int pos,h; unsigned char maskbyte,rep; //printf("expandLzx %d %d \n",virtualSize,cursor); @@ -55,29 +87,24 @@ void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { //Compress B1/B2 algorithm void compressRle(unsigned char* data,tImage* img,int *dataSize) { -// //printf("llega 3.51\n"); //Declare pointers char* cursorData = data; char* counter; char* cursorPix = (*img).pix; char* imgEnd = (*img).pix+((*img).size>>1)-1; - //printf("llega 3.52\n"); while (cursorPix<imgEnd) { //Step 1: Create counter *(counter=(cursorData++))=-1; //Step 2: Look and copy the string until a repeated byte is found - while ((cursorPix<imgEnd)&&(*cursorPix!=*(cursorPix+1))&&((*counter)!=127)) { cursorPix++; (*counter)++; *(cursorData)=*(cursorPix-1); cursorData++; } -////printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd); - //cursorPix--; //Step 3: If there was a repeated string, let's ignore it and add the cursor with the repetitions if (*counter==-1) { while ((cursorPix<imgEnd)&&(*cursorPix==(*(cursorPix+1)))&&((*counter)!=-128)) { @@ -91,15 +118,9 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { } *(cursorData++)=0; *(cursorData++)=*(cursorPix); -// //printf("compressRle: cursorData=%d data=%d cursorPix=%d imgEnd=%d\n",(int)cursorData,(int)data,(int)((*img).pix),(int)imgEnd); - *dataSize=(int)cursorData-(int)data; + *dataSize=(int)cursorData-(int)data; //Note: data loss in 64 bits architectures } - - - - - //Expands an array into an image int mExpandGraphic(char* array,tImage *image, int virtualSize) { /* @@ -111,22 +132,19 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) { normaly: (* ignored types) checksum* - height - 00 - width - 00 - 00* - compression type */ -////printf("expand graphic le ejecuta %d\n",virtualSize); int cursor=0; int i=1; //Get memory for the image image->height=((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]) ; -i=i+2; + i=i+2; image->width =((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]); -i=i+2; + i=i+2; (*image).size =(*image).height*(*image).width; -//printf("h=%d, w=%d %x %x %x %x \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]); virtualSize=(((*image).height*((*image).width+((*image).width&1)))>>1); i++; -//printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize); switch ((unsigned char)array[i++]) { case PG_COMP_RAW: //No Compression Algorithm if (((*image).pix=getMemory(virtualSize))==NULL) return -1; @@ -163,18 +181,14 @@ i=i+2; } break; case PG_COMP_LZX_LR: //LZ Groody Up to Down Version Compression Algorithm - //printf("llega b4\n"); if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; expandLzx(array,image,&i,cursor,virtualSize); break; case PG_COMP_LZX_UD: //LZ Groody Left to Right Version Compression Algorithm -//printf("hi\n"); if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; { unsigned char* outputaux=getMemory(virtualSize); - //printf("antes\n"); expandLzx(array,image,&i,cursor,virtualSize); - //printf("despues\n"); //Transpose while (cursor<virtualSize) outputaux[transpose(cursor,(*image).width,(*image).height)]=(*image).pix[cursor++]; free((*image).pix); @@ -234,24 +248,3 @@ int mCompressGraphic(unsigned char* data,tImage i, int* size) { #endif return 1; } - -/***************************************************************\ -| File handling | -\***************************************************************/ - -//Deprecated -/* -char mLoadFilePalette(char* vFile,int address, char* pal) { - FILE *fp; - char aux; - - if ((fp=fopen(vFile,"rb"))==NULL) { - return 0; - } else { - fseek (fp, address, SEEK_SET); - aux=fread (pal,SIZE_OF_PALETTE,1,fp); - fclose(fp); - return aux; - } -} -*/ diff --git a/PR/src/lib/formats/Attic/bmp.c b/PR/src/lib/formats/Attic/bmp.c index 685e347..2ee114b 100644 --- a/PR/src/lib/formats/Attic/bmp.c +++ b/PR/src/lib/formats/Attic/bmp.c @@ -1,3 +1,35 @@ +/* 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 +*/ + +/* +bmp.c: Princed Resources : BMP file support +\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 +*/ #include <stdio.h> #include <stdlib.h> @@ -7,13 +39,13 @@ #include "compile.h" char mFormatExtractBmp(unsigned char* data, char *vFileext,unsigned long int size,tImage image) { -printf("hola, vengo a colgarme\n"); +//printf("hola, vengo a colgarme\n"); if ((mExpandGraphic(data,&image,size))>0) { -printf("ya expandi\n"); +//printf("ya expandi\n"); mWriteBitMap(image,vFileext); -printf("Escribi el bitmap\n"); +//printf("Escribi el bitmap\n"); free(image.pix); -printf("libere imagen\n"); +//printf("libere imagen\n"); return 1; } else { return 0; @@ -25,15 +57,14 @@ char mFormatCompileBmp(unsigned char* data, FILE* fp, tResource *res) { int size; tImage img; unsigned char aux[10000]; + if (!mReadBitMap(&img,data,(*res).size)) return 0; - //free(data); - //printf("llega 2\n"); mCompressGraphic(aux,img,&size); - printf("llega ssss2\n"); +//printf("llega ssss2\n"); free(img.pix); - printf("llega ssss3\n"); +//printf("llega ssss3\n"); mAddFileToDatFile(fp,aux,size); - printf("llega ssss4\n"); +//printf("llega ssss4\n"); (*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; @@ -156,7 +187,7 @@ char mReadBitMap(tImage* img,char* data, int size) { //Calculate serialized widths width=(width+1)>>1; //raw serialized width - width2=width+((-width)&3); //bmp 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)); diff --git a/PR/src/lib/formats/Attic/pal.c b/PR/src/lib/formats/Attic/pal.c index 487bd3f..55701f0 100644 --- a/PR/src/lib/formats/Attic/pal.c +++ b/PR/src/lib/formats/Attic/pal.c @@ -1,4 +1,37 @@ +/* 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 +*/ + +/* +pal.c: Princed Resources : JASC PAL files support +\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 +*/ + +//Includes #include <string.h> #include <stdlib.h> #include <stdio.h> @@ -80,7 +113,5 @@ void mExportPalette(unsigned char** data, unsigned long int *size) { void mLoadPalette(char* array,tImage *image) { int k=0; int i; - for (i=5;i<5+16*3;i++) { - (*image).pal[k++]=array[i]; - } + for (i=5;i<(5+16*3);i++) (*image).pal[k++]=array[i]; } diff --git a/PR/src/lib/formats/Attic/wav.c b/PR/src/lib/formats/Attic/wav.c index bd99954..41d3c3c 100644 --- a/PR/src/lib/formats/Attic/wav.c +++ b/PR/src/lib/formats/Attic/wav.c @@ -1,27 +1,61 @@ +/* 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 +*/ + +/* +wav.c: Princed Resources : WAV files support +\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 +*/ + +//Includes #include "wav.h" #include "compile.h" - char mFormatExtractWav(unsigned char* data, char *vFileext,unsigned long int size) { - - unsigned char wav[]=WAVE_HEADER; FILE* target; char ok; + unsigned char wav[]=WAVE_HEADER; - size-=2; - ok=((target=fopen(vFileext,"wb"))!=NULL); - wav[4]=(unsigned char)((size+36)&0xFF); - wav[5]=(unsigned char)(((size+36)>>8)&0xFF); - wav[6]=(unsigned char)(((size+36)>>16)&0xFF); - wav[7]=(unsigned char)(((size+36)>>24)&0xFF); - - wav[40]=(unsigned char)((size)&0xFF); - wav[41]=(unsigned char)(((size)>>8)&0xFF); - wav[42]=(unsigned char)(((size)>>16)&0xFF); - wav[43]=(unsigned char)(((size)>>24)&0xFF); - ok=ok&&fwrite(wav,sizeof(wav),1,target); - ok=ok&&fwrite(data+2,size-2,1,target); - ok=ok&&(!fclose(target)); + size-=2; + ok=((target=fopen(vFileext,"wb"))!=NULL); + + wav[4]=(unsigned char)((size+36)&0xFF); + wav[5]=(unsigned char)(((size+36)>>8)&0xFF); + wav[6]=(unsigned char)(((size+36)>>16)&0xFF); + wav[7]=(unsigned char)(((size+36)>>24)&0xFF); + + wav[40]=(unsigned char)((size)&0xFF); + wav[41]=(unsigned char)(((size)>>8)&0xFF); + wav[42]=(unsigned char)(((size)>>16)&0xFF); + wav[43]=(unsigned char)(((size)>>24)&0xFF); + + ok=ok&&fwrite(wav,sizeof(wav),1,target); + ok=ok&&fwrite(data+2,size-2,1,target); + ok=ok&&(!fclose(target)); return ok; } @@ -29,10 +63,11 @@ char mFormatExtractWav(unsigned char* data, char *vFileext,unsigned long int siz char 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); 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; + 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); return 1; } diff --git a/PR/src/lib/object/image/image16.c b/PR/src/lib/object/image/image16.c index 7f7d781..87cebcd 100644 --- a/PR/src/lib/object/image/image16.c +++ b/PR/src/lib/object/image/image16.c @@ -1,3 +1,36 @@ +/* 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 +\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 +*/ + /***************************************************************\ | I M P L E M E N T A T I O N | \***************************************************************/ @@ -7,8 +40,7 @@ #include "memory.h" //reserved memory for the Lzx algorithm -#define MAX_MOD_SIZE_IN_LZX 32001 -//38401 +#define MAX_MOD_SIZE_IN_LZX 32001 /* 38401 */ //modulus to be used in the 10 bits of the algorithm #define MAX_MXD_SIZE_IN_LZX 0x400 @@ -30,8 +62,8 @@ unsigned char popBit(unsigned char *byte) { //Expands B3/B4 algorithm void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { - int pos,h; char k; + int pos,h; unsigned char maskbyte,rep; //printf("expandLzx %d %d \n",virtualSize,cursor); @@ -55,29 +87,24 @@ void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { //Compress B1/B2 algorithm void compressRle(unsigned char* data,tImage* img,int *dataSize) { -// //printf("llega 3.51\n"); //Declare pointers char* cursorData = data; char* counter; char* cursorPix = (*img).pix; char* imgEnd = (*img).pix+((*img).size>>1)-1; - //printf("llega 3.52\n"); while (cursorPix<imgEnd) { //Step 1: Create counter *(counter=(cursorData++))=-1; //Step 2: Look and copy the string until a repeated byte is found - while ((cursorPix<imgEnd)&&(*cursorPix!=*(cursorPix+1))&&((*counter)!=127)) { cursorPix++; (*counter)++; *(cursorData)=*(cursorPix-1); cursorData++; } -////printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd); - //cursorPix--; //Step 3: If there was a repeated string, let's ignore it and add the cursor with the repetitions if (*counter==-1) { while ((cursorPix<imgEnd)&&(*cursorPix==(*(cursorPix+1)))&&((*counter)!=-128)) { @@ -91,15 +118,9 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { } *(cursorData++)=0; *(cursorData++)=*(cursorPix); -// //printf("compressRle: cursorData=%d data=%d cursorPix=%d imgEnd=%d\n",(int)cursorData,(int)data,(int)((*img).pix),(int)imgEnd); - *dataSize=(int)cursorData-(int)data; + *dataSize=(int)cursorData-(int)data; //Note: data loss in 64 bits architectures } - - - - - //Expands an array into an image int mExpandGraphic(char* array,tImage *image, int virtualSize) { /* @@ -111,22 +132,19 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) { normaly: (* ignored types) checksum* - height - 00 - width - 00 - 00* - compression type */ -////printf("expand graphic le ejecuta %d\n",virtualSize); int cursor=0; int i=1; //Get memory for the image image->height=((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]) ; -i=i+2; + i=i+2; image->width =((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]); -i=i+2; + i=i+2; (*image).size =(*image).height*(*image).width; -//printf("h=%d, w=%d %x %x %x %x \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]); virtualSize=(((*image).height*((*image).width+((*image).width&1)))>>1); i++; -//printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize); switch ((unsigned char)array[i++]) { case PG_COMP_RAW: //No Compression Algorithm if (((*image).pix=getMemory(virtualSize))==NULL) return -1; @@ -163,18 +181,14 @@ i=i+2; } break; case PG_COMP_LZX_LR: //LZ Groody Up to Down Version Compression Algorithm - //printf("llega b4\n"); if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; expandLzx(array,image,&i,cursor,virtualSize); break; case PG_COMP_LZX_UD: //LZ Groody Left to Right Version Compression Algorithm -//printf("hi\n"); if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; { unsigned char* outputaux=getMemory(virtualSize); - //printf("antes\n"); expandLzx(array,image,&i,cursor,virtualSize); - //printf("despues\n"); //Transpose while (cursor<virtualSize) outputaux[transpose(cursor,(*image).width,(*image).height)]=(*image).pix[cursor++]; free((*image).pix); @@ -234,24 +248,3 @@ int mCompressGraphic(unsigned char* data,tImage i, int* size) { #endif return 1; } - -/***************************************************************\ -| File handling | -\***************************************************************/ - -//Deprecated -/* -char mLoadFilePalette(char* vFile,int address, char* pal) { - FILE *fp; - char aux; - - if ((fp=fopen(vFile,"rb"))==NULL) { - return 0; - } else { - fseek (fp, address, SEEK_SET); - aux=fread (pal,SIZE_OF_PALETTE,1,fp); - fclose(fp); - return aux; - } -} -*/ diff --git a/PR/src/lib/object/image/image2.c b/PR/src/lib/object/image/image2.c index 7f7d781..87cebcd 100644 --- a/PR/src/lib/object/image/image2.c +++ b/PR/src/lib/object/image/image2.c @@ -1,3 +1,36 @@ +/* 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 +\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 +*/ + /***************************************************************\ | I M P L E M E N T A T I O N | \***************************************************************/ @@ -7,8 +40,7 @@ #include "memory.h" //reserved memory for the Lzx algorithm -#define MAX_MOD_SIZE_IN_LZX 32001 -//38401 +#define MAX_MOD_SIZE_IN_LZX 32001 /* 38401 */ //modulus to be used in the 10 bits of the algorithm #define MAX_MXD_SIZE_IN_LZX 0x400 @@ -30,8 +62,8 @@ unsigned char popBit(unsigned char *byte) { //Expands B3/B4 algorithm void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { - int pos,h; char k; + int pos,h; unsigned char maskbyte,rep; //printf("expandLzx %d %d \n",virtualSize,cursor); @@ -55,29 +87,24 @@ void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { //Compress B1/B2 algorithm void compressRle(unsigned char* data,tImage* img,int *dataSize) { -// //printf("llega 3.51\n"); //Declare pointers char* cursorData = data; char* counter; char* cursorPix = (*img).pix; char* imgEnd = (*img).pix+((*img).size>>1)-1; - //printf("llega 3.52\n"); while (cursorPix<imgEnd) { //Step 1: Create counter *(counter=(cursorData++))=-1; //Step 2: Look and copy the string until a repeated byte is found - while ((cursorPix<imgEnd)&&(*cursorPix!=*(cursorPix+1))&&((*counter)!=127)) { cursorPix++; (*counter)++; *(cursorData)=*(cursorPix-1); cursorData++; } -////printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd); - //cursorPix--; //Step 3: If there was a repeated string, let's ignore it and add the cursor with the repetitions if (*counter==-1) { while ((cursorPix<imgEnd)&&(*cursorPix==(*(cursorPix+1)))&&((*counter)!=-128)) { @@ -91,15 +118,9 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { } *(cursorData++)=0; *(cursorData++)=*(cursorPix); -// //printf("compressRle: cursorData=%d data=%d cursorPix=%d imgEnd=%d\n",(int)cursorData,(int)data,(int)((*img).pix),(int)imgEnd); - *dataSize=(int)cursorData-(int)data; + *dataSize=(int)cursorData-(int)data; //Note: data loss in 64 bits architectures } - - - - - //Expands an array into an image int mExpandGraphic(char* array,tImage *image, int virtualSize) { /* @@ -111,22 +132,19 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) { normaly: (* ignored types) checksum* - height - 00 - width - 00 - 00* - compression type */ -////printf("expand graphic le ejecuta %d\n",virtualSize); int cursor=0; int i=1; //Get memory for the image image->height=((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]) ; -i=i+2; + i=i+2; image->width =((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]); -i=i+2; + i=i+2; (*image).size =(*image).height*(*image).width; -//printf("h=%d, w=%d %x %x %x %x \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]); virtualSize=(((*image).height*((*image).width+((*image).width&1)))>>1); i++; -//printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize); switch ((unsigned char)array[i++]) { case PG_COMP_RAW: //No Compression Algorithm if (((*image).pix=getMemory(virtualSize))==NULL) return -1; @@ -163,18 +181,14 @@ i=i+2; } break; case PG_COMP_LZX_LR: //LZ Groody Up to Down Version Compression Algorithm - //printf("llega b4\n"); if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; expandLzx(array,image,&i,cursor,virtualSize); break; case PG_COMP_LZX_UD: //LZ Groody Left to Right Version Compression Algorithm -//printf("hi\n"); if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; { unsigned char* outputaux=getMemory(virtualSize); - //printf("antes\n"); expandLzx(array,image,&i,cursor,virtualSize); - //printf("despues\n"); //Transpose while (cursor<virtualSize) outputaux[transpose(cursor,(*image).width,(*image).height)]=(*image).pix[cursor++]; free((*image).pix); @@ -234,24 +248,3 @@ int mCompressGraphic(unsigned char* data,tImage i, int* size) { #endif return 1; } - -/***************************************************************\ -| File handling | -\***************************************************************/ - -//Deprecated -/* -char mLoadFilePalette(char* vFile,int address, char* pal) { - FILE *fp; - char aux; - - if ((fp=fopen(vFile,"rb"))==NULL) { - return 0; - } else { - fseek (fp, address, SEEK_SET); - aux=fread (pal,SIZE_OF_PALETTE,1,fp); - fclose(fp); - return aux; - } -} -*/ diff --git a/PR/src/lib/object/image/image256.c b/PR/src/lib/object/image/image256.c index 7f7d781..87cebcd 100644 --- a/PR/src/lib/object/image/image256.c +++ b/PR/src/lib/object/image/image256.c @@ -1,3 +1,36 @@ +/* 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 +\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 +*/ + /***************************************************************\ | I M P L E M E N T A T I O N | \***************************************************************/ @@ -7,8 +40,7 @@ #include "memory.h" //reserved memory for the Lzx algorithm -#define MAX_MOD_SIZE_IN_LZX 32001 -//38401 +#define MAX_MOD_SIZE_IN_LZX 32001 /* 38401 */ //modulus to be used in the 10 bits of the algorithm #define MAX_MXD_SIZE_IN_LZX 0x400 @@ -30,8 +62,8 @@ unsigned char popBit(unsigned char *byte) { //Expands B3/B4 algorithm void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { - int pos,h; char k; + int pos,h; unsigned char maskbyte,rep; //printf("expandLzx %d %d \n",virtualSize,cursor); @@ -55,29 +87,24 @@ void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { //Compress B1/B2 algorithm void compressRle(unsigned char* data,tImage* img,int *dataSize) { -// //printf("llega 3.51\n"); //Declare pointers char* cursorData = data; char* counter; char* cursorPix = (*img).pix; char* imgEnd = (*img).pix+((*img).size>>1)-1; - //printf("llega 3.52\n"); while (cursorPix<imgEnd) { //Step 1: Create counter *(counter=(cursorData++))=-1; //Step 2: Look and copy the string until a repeated byte is found - while ((cursorPix<imgEnd)&&(*cursorPix!=*(cursorPix+1))&&((*counter)!=127)) { cursorPix++; (*counter)++; *(cursorData)=*(cursorPix-1); cursorData++; } -////printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd); - //cursorPix--; //Step 3: If there was a repeated string, let's ignore it and add the cursor with the repetitions if (*counter==-1) { while ((cursorPix<imgEnd)&&(*cursorPix==(*(cursorPix+1)))&&((*counter)!=-128)) { @@ -91,15 +118,9 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { } *(cursorData++)=0; *(cursorData++)=*(cursorPix); -// //printf("compressRle: cursorData=%d data=%d cursorPix=%d imgEnd=%d\n",(int)cursorData,(int)data,(int)((*img).pix),(int)imgEnd); - *dataSize=(int)cursorData-(int)data; + *dataSize=(int)cursorData-(int)data; //Note: data loss in 64 bits architectures } - - - - - //Expands an array into an image int mExpandGraphic(char* array,tImage *image, int virtualSize) { /* @@ -111,22 +132,19 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) { normaly: (* ignored types) checksum* - height - 00 - width - 00 - 00* - compression type */ -////printf("expand graphic le ejecuta %d\n",virtualSize); int cursor=0; int i=1; //Get memory for the image image->height=((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]) ; -i=i+2; + i=i+2; image->width =((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]); -i=i+2; + i=i+2; (*image).size =(*image).height*(*image).width; -//printf("h=%d, w=%d %x %x %x %x \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]); virtualSize=(((*image).height*((*image).width+((*image).width&1)))>>1); i++; -//printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize); switch ((unsigned char)array[i++]) { case PG_COMP_RAW: //No Compression Algorithm if (((*image).pix=getMemory(virtualSize))==NULL) return -1; @@ -163,18 +181,14 @@ i=i+2; } break; case PG_COMP_LZX_LR: //LZ Groody Up to Down Version Compression Algorithm - //printf("llega b4\n"); if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; expandLzx(array,image,&i,cursor,virtualSize); break; case PG_COMP_LZX_UD: //LZ Groody Left to Right Version Compression Algorithm -//printf("hi\n"); if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; { unsigned char* outputaux=getMemory(virtualSize); - //printf("antes\n"); expandLzx(array,image,&i,cursor,virtualSize); - //printf("despues\n"); //Transpose while (cursor<virtualSize) outputaux[transpose(cursor,(*image).width,(*image).height)]=(*image).pix[cursor++]; free((*image).pix); @@ -234,24 +248,3 @@ int mCompressGraphic(unsigned char* data,tImage i, int* size) { #endif return 1; } - -/***************************************************************\ -| File handling | -\***************************************************************/ - -//Deprecated -/* -char mLoadFilePalette(char* vFile,int address, char* pal) { - FILE *fp; - char aux; - - if ((fp=fopen(vFile,"rb"))==NULL) { - return 0; - } else { - fseek (fp, address, SEEK_SET); - aux=fread (pal,SIZE_OF_PALETTE,1,fp); - fclose(fp); - return aux; - } -} -*/ diff --git a/PR/src/lib/object/image/image_common.c b/PR/src/lib/object/image/image_common.c index 7f7d781..87cebcd 100644 --- a/PR/src/lib/object/image/image_common.c +++ b/PR/src/lib/object/image/image_common.c @@ -1,3 +1,36 @@ +/* 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 +\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 +*/ + /***************************************************************\ | I M P L E M E N T A T I O N | \***************************************************************/ @@ -7,8 +40,7 @@ #include "memory.h" //reserved memory for the Lzx algorithm -#define MAX_MOD_SIZE_IN_LZX 32001 -//38401 +#define MAX_MOD_SIZE_IN_LZX 32001 /* 38401 */ //modulus to be used in the 10 bits of the algorithm #define MAX_MXD_SIZE_IN_LZX 0x400 @@ -30,8 +62,8 @@ unsigned char popBit(unsigned char *byte) { //Expands B3/B4 algorithm void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { - int pos,h; char k; + int pos,h; unsigned char maskbyte,rep; //printf("expandLzx %d %d \n",virtualSize,cursor); @@ -55,29 +87,24 @@ void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { //Compress B1/B2 algorithm void compressRle(unsigned char* data,tImage* img,int *dataSize) { -// //printf("llega 3.51\n"); //Declare pointers char* cursorData = data; char* counter; char* cursorPix = (*img).pix; char* imgEnd = (*img).pix+((*img).size>>1)-1; - //printf("llega 3.52\n"); while (cursorPix<imgEnd) { //Step 1: Create counter *(counter=(cursorData++))=-1; //Step 2: Look and copy the string until a repeated byte is found - while ((cursorPix<imgEnd)&&(*cursorPix!=*(cursorPix+1))&&((*counter)!=127)) { cursorPix++; (*counter)++; *(cursorData)=*(cursorPix-1); cursorData++; } -////printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd); - //cursorPix--; //Step 3: If there was a repeated string, let's ignore it and add the cursor with the repetitions if (*counter==-1) { while ((cursorPix<imgEnd)&&(*cursorPix==(*(cursorPix+1)))&&((*counter)!=-128)) { @@ -91,15 +118,9 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { } *(cursorData++)=0; *(cursorData++)=*(cursorPix); -// //printf("compressRle: cursorData=%d data=%d cursorPix=%d imgEnd=%d\n",(int)cursorData,(int)data,(int)((*img).pix),(int)imgEnd); - *dataSize=(int)cursorData-(int)data; + *dataSize=(int)cursorData-(int)data; //Note: data loss in 64 bits architectures } - - - - - //Expands an array into an image int mExpandGraphic(char* array,tImage *image, int virtualSize) { /* @@ -111,22 +132,19 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) { normaly: (* ignored types) checksum* - height - 00 - width - 00 - 00* - compression type */ -////printf("expand graphic le ejecuta %d\n",virtualSize); int cursor=0; int i=1; //Get memory for the image image->height=((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]) ; -i=i+2; + i=i+2; image->width =((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]); -i=i+2; + i=i+2; (*image).size =(*image).height*(*image).width; -//printf("h=%d, w=%d %x %x %x %x \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]); virtualSize=(((*image).height*((*image).width+((*image).width&1)))>>1); i++; -//printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize); switch ((unsigned char)array[i++]) { case PG_COMP_RAW: //No Compression Algorithm if (((*image).pix=getMemory(virtualSize))==NULL) return -1; @@ -163,18 +181,14 @@ i=i+2; } break; case PG_COMP_LZX_LR: //LZ Groody Up to Down Version Compression Algorithm - //printf("llega b4\n"); if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; expandLzx(array,image,&i,cursor,virtualSize); break; case PG_COMP_LZX_UD: //LZ Groody Left to Right Version Compression Algorithm -//printf("hi\n"); if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; { unsigned char* outputaux=getMemory(virtualSize); - //printf("antes\n"); expandLzx(array,image,&i,cursor,virtualSize); - //printf("despues\n"); //Transpose while (cursor<virtualSize) outputaux[transpose(cursor,(*image).width,(*image).height)]=(*image).pix[cursor++]; free((*image).pix); @@ -234,24 +248,3 @@ int mCompressGraphic(unsigned char* data,tImage i, int* size) { #endif return 1; } - -/***************************************************************\ -| File handling | -\***************************************************************/ - -//Deprecated -/* -char mLoadFilePalette(char* vFile,int address, char* pal) { - FILE *fp; - char aux; - - if ((fp=fopen(vFile,"rb"))==NULL) { - return 0; - } else { - fseek (fp, address, SEEK_SET); - aux=fread (pal,SIZE_OF_PALETTE,1,fp); - fclose(fp); - return aux; - } -} -*/ diff --git a/PR/src/parser.c b/PR/src/parser.c index 539b45b..0aa3129 100644 --- a/PR/src/parser.c +++ b/PR/src/parser.c @@ -1,3 +1,36 @@ +/* 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 +*/ + +/* +parser.c: Parser +\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf + Copyright 2003 Enrique Calot + Created: 1 May 2003 + + Author: Enrique Calot <ecalot.cod@princed.com.ar> + Version: 1.00 (2003-May-01) + + Note: + DO NOT remove this copyright notice +*/ + /****************************************************************\ | Libreria de manejo de strings, conversiones y parsing | \****************************************************************/