author | ecalot
<ecalot> 2006-02-10 19:04:21 UTC |
committer | ecalot
<ecalot> 2006-02-10 19:04:21 UTC |
parent | cf52126ba142a0e5f9a6f0839b5d6363fdbcd11e |
PR/src/include/compress.h | +15 | -21 |
PR/src/include/disk.h | +1 | -1 |
PR/src/include/image.h | +15 | -21 |
PR/src/include/pal.h | +7 | -4 |
PR/src/include/palette.h | +63 | -0 |
PR/src/include/pallist.h | +52 | -0 |
PR/src/include/plv.h | +3 | -3 |
PR/src/lib/actions/export.c | +22 | -16 |
PR/src/lib/actions/import.c | +1 | -1 |
PR/src/lib/compression/lzg_decompress.c | +4 | -4 |
PR/src/lib/compression/rlev_decompress.c | +2 | -4 |
PR/src/lib/formats/bmp.c | +1 | -1 |
PR/src/lib/formats/pal.c | +39 | -35 |
PR/src/lib/layers/autodetect.c | +10 | -2 |
PR/src/lib/layers/disk.c | +17 | -17 |
PR/src/lib/layers/pallist.c | +46 | -0 |
PR/src/lib/object/image/image16.c | +52 | -6 |
PR/src/lib/object/image/image2.c | +52 | -6 |
PR/src/lib/object/image/image256.c | +52 | -6 |
PR/src/lib/object/image/image_common.c | +52 | -6 |
PR/src/lib/object/palette/pop1_16c.c | +42 | -11 |
PR/src/lib/object/palette/pop2_256c.c | +42 | -11 |
PR/src/lib/object/palette/pop2_4bit.c | +42 | -11 |
diff --git a/PR/src/include/compress.h b/PR/src/include/compress.h index fd0c3b0..fe09811 100644 --- a/PR/src/include/compress.h +++ b/PR/src/include/compress.h @@ -34,7 +34,19 @@ compress.h: Princed Resources : Image compression headers #ifndef _COMPRESS_H_ #define _COMPRESS_H_ -#define SIZE_OF_PALETTE 3*16 +typedef struct { /* TODO: move to image.h */ + unsigned char r; + unsigned char g; + unsigned char b; +}tColor; + +typedef struct { + tColor p8[256]; + tColor p4[16]; + tColor p1[2]; +}tPalette; + +#define SIZE_OF_PALETTE 3*16 /* TODO: erase this line */ #define COMPRESS_RAW 0x00 #define COMPRESS_RLE_LR 0x01 @@ -48,33 +60,15 @@ compress.h: Princed Resources : Image compression headers #define COMPRESS_RESULT_WARNING -1 #define COMPRESS_RESULT_SUCCESS 0 -typedef struct { +typedef struct { /* TODO: move to image.h */ int width; int widthInBytes; int height; unsigned char* pix; - unsigned char pal[SIZE_OF_PALETTE]; + tPalette pal; unsigned char type; /* XY where X=B if 4 bits or X=0 if 1 bit; Y=algorithm */ }tImage; -#define DEFAULT_PALETTE \ - "\x00\x00\x00"\ - "\x00\x00\xa0"\ - "\x00\xa7\x00"\ - "\x00\xa7\xa0"\ - "\xa0\x00\x00"\ - "\xa0\x00\xa0"\ - "\xa0\x50\x00"\ - "\xa0\xa7\xa0"\ - "\x50\x50\x50"\ - "\x50\x50\xff"\ - "\x50\xf8\x50"\ - "\x50\xf8\xff"\ - "\xff\x50\x50"\ - "\xff\x50\xff"\ - "\xff\xf8\x50"\ - "\xff\xff\xff" - /* Prototypes */ int mCompressGraphic(unsigned char** a,tImage* i, int* size); diff --git a/PR/src/include/disk.h b/PR/src/include/disk.h index 856727f..5e6ee44 100644 --- a/PR/src/include/disk.h +++ b/PR/src/include/disk.h @@ -49,7 +49,7 @@ disk.h: Princed Resources : Disk Access & File handling prototypes /* Path defines */ #ifndef WIN32 - #define DIR_SEPARATOR '/' +#define DIR_SEPARATOR '/' #else #define DIR_SEPARATOR '\\' #endif diff --git a/PR/src/include/image.h b/PR/src/include/image.h index fd0c3b0..fe09811 100644 --- a/PR/src/include/image.h +++ b/PR/src/include/image.h @@ -34,7 +34,19 @@ compress.h: Princed Resources : Image compression headers #ifndef _COMPRESS_H_ #define _COMPRESS_H_ -#define SIZE_OF_PALETTE 3*16 +typedef struct { /* TODO: move to image.h */ + unsigned char r; + unsigned char g; + unsigned char b; +}tColor; + +typedef struct { + tColor p8[256]; + tColor p4[16]; + tColor p1[2]; +}tPalette; + +#define SIZE_OF_PALETTE 3*16 /* TODO: erase this line */ #define COMPRESS_RAW 0x00 #define COMPRESS_RLE_LR 0x01 @@ -48,33 +60,15 @@ compress.h: Princed Resources : Image compression headers #define COMPRESS_RESULT_WARNING -1 #define COMPRESS_RESULT_SUCCESS 0 -typedef struct { +typedef struct { /* TODO: move to image.h */ int width; int widthInBytes; int height; unsigned char* pix; - unsigned char pal[SIZE_OF_PALETTE]; + tPalette pal; unsigned char type; /* XY where X=B if 4 bits or X=0 if 1 bit; Y=algorithm */ }tImage; -#define DEFAULT_PALETTE \ - "\x00\x00\x00"\ - "\x00\x00\xa0"\ - "\x00\xa7\x00"\ - "\x00\xa7\xa0"\ - "\xa0\x00\x00"\ - "\xa0\x00\xa0"\ - "\xa0\x50\x00"\ - "\xa0\xa7\xa0"\ - "\x50\x50\x50"\ - "\x50\x50\xff"\ - "\x50\xf8\x50"\ - "\x50\xf8\xff"\ - "\xff\x50\x50"\ - "\xff\x50\xff"\ - "\xff\xf8\x50"\ - "\xff\xff\xff" - /* Prototypes */ int mCompressGraphic(unsigned char** a,tImage* i, int* size); diff --git a/PR/src/include/pal.h b/PR/src/include/pal.h index aa5b598..865272e 100644 --- a/PR/src/include/pal.h +++ b/PR/src/include/pal.h @@ -34,18 +34,21 @@ pal.h: Princed Resources : JASC PAL files support headers #ifndef _PAL_H_ #define _PAL_H_ -#include "reslist.h" +#include "palette.h" -#define PAL_HEADER "JASC-PAL\r\n0100\r\n16\r\n" +/* #define PAL_SAMPLE {0x97, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x08, 0x0F, 0x07, 0x0C, 0x13, 0x0C, 0x11, 0x16, 0x11, 0x17, 0x1C, 0x1E, 0x21, 0x25, 0x2F, 0x31, 0x33, 0x3F, 0x3F, 0x3F, 0x2A, 0x2A, 0x2A, 0x15, 0x15, 0x15, 0x17, 0x1C, 0x20, 0x07, 0x0C, 0x13, 0x0C, 0x12, 0x17, 0x15, 0x1A, 0x1F, 0x00, 0x1D, 0x13, 0x00, 0x29, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} +*/ -int mFormatExportPal(const unsigned char* data, char *vFileext,unsigned long int size,int optionflag,const char* backupExtensio); -int mFormatImportPal(tResource *res,const char* vFile); +int mFormatExportPal(const tPalette* p, int bits, char *vFileext, int optionflag, const char* backupExtension); +int mFormatImportPal(tPalette* p,int* bits, const char* vFile); +/* #define mLoadPalette(array,image,popversion)\ if (popversion==pop1)\ memcpy(((image).pal),((array)+5),(16*3));\ else\ memcpy(((image).pal),((array)+1),(16*3)) +*/ #endif diff --git a/PR/src/include/palette.h b/PR/src/include/palette.h new file mode 100644 index 0000000..df286f3 --- /dev/null +++ b/PR/src/include/palette.h @@ -0,0 +1,63 @@ +/* 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.h: Princed Resources : JASC PAL files support headers +\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 _PALETTE_H_ +#define _PALETTE_H_ + +#include "compress.h" /* tPalette, tImage */ + +#define SAMPLE_PAL16 {\ + {0x00,0x00,0x00},\ + {0x00,0x00,0xa0},\ + {0x00,0xa7,0x00},\ + {0x00,0xa7,0xa0},\ + {0xa0,0x00,0x00},\ + {0xa0,0x00,0xa0},\ + {0xa0,0x50,0x00},\ + {0xa0,0xa7,0xa0},\ + {0x50,0x50,0x50},\ + {0x50,0x50,0xff},\ + {0x50,0xf8,0x50},\ + {0x50,0xf8,0xff},\ + {0xff,0x50,0x50},\ + {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); + +#endif diff --git a/PR/src/include/pallist.h b/PR/src/include/pallist.h new file mode 100644 index 0000000..323d53c --- /dev/null +++ b/PR/src/include/pallist.h @@ -0,0 +1,52 @@ +/* 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 +*/ + +/* +.h: Princed Resources : Resource list prototypes +\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf + Copyright 2006 Princed Development Team + Created: 05 Jun 2005 + + Author: Enrique Calot <ecalot.cod@princed.com.ar> + Version: 1.00 (2005-Jun-05) + + Note: + DO NOT remove this copyright notice +*/ + +#ifndef _PALLIST_H_ +#define _PALLIST_H_ + +#include "list.h" /* tList */ +typedef tList tPaletteList; + +#include "palette.h" /* Item Types */ +#include "reslist.h" /* tResourceId */ + +/* types */ +typedef struct { + tResourceId id; + tPalette pal; + int bits; +}tPaletteListItem; + +tPaletteList paletteListCreate(); + +#endif diff --git a/PR/src/include/plv.h b/PR/src/include/plv.h index 779c887..4844741 100644 --- a/PR/src/include/plv.h +++ b/PR/src/include/plv.h @@ -70,9 +70,9 @@ int mFormatExportPlv(const unsigned char* data, const char *vFileext,unsigned lo #define DATE_MONTHS "Jan\0Feb\0Mar\0Apr\0May\0Jun\0Jul\0Aug\0Sep\0Oct\0Nov\0Dec" /* Format stuff */ -#define PLV_HEADER_A "POP_LVL\x01\x01" -#define PLV_HEADER_A_SIZE 9 -#define PLV_HEADER_B "\x09\0\0" +#define PLV_HEADER_A "POP_LVL" +#define PLV_HEADER_A_SIZE 7 + #define PLV_HEADER_B_SIZE 4 #define PLV_FOOT_EDITOR "Editor Name\0PR\0Editor Version\0"PR_VERSION"\0Level Author" diff --git a/PR/src/lib/actions/export.c b/PR/src/lib/actions/export.c index ed6831c..2b37f11 100644 --- a/PR/src/lib/actions/export.c +++ b/PR/src/lib/actions/export.c @@ -44,7 +44,7 @@ export.c: Princed Resources : DAT Extractor #include "disk.h" #include "idlist.h" #include "memory.h" -#include "reslist.h" /* resIdcmp, resourceList primitives for the palette */ +#include "pallist.h" #include "unknown.h" #include "palette.h" @@ -75,7 +75,7 @@ int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int opti int ok; tImage image; /* this is used to make a persistent palette */ unsigned short int numberOfItems; - tResourceList paletteBuffer; + tPaletteList paletteBuffer; tResourceId bufferedPalette={0,"",0}; tResource res; int count=0; @@ -85,9 +85,9 @@ int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int opti ok=1; /* initialize palette buffer */ - paletteBuffer=resourceListCreate(1); + paletteBuffer=paletteListCreate(); /* initialize the default palette */ - image.pal=createPalette(); + image.pal=createPalette(); /* TODO: add the default palette ad 0,"",0 */ /* main loop */ for (indexNumber=0;ok&&(indexNumber<numberOfItems);indexNumber++) { @@ -114,15 +114,18 @@ int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int opti case eResTypeRaw: /* Raw files */ ok=writeData(res.data,1,vFileext,res.size,optionflag,backupExtension); /* Ignore checksum */ break; - case eResTypePalette: /* save and remember palette file */ + case eResTypePalette: { /* save and remember palette file */ + tPaletteListItem e; /* Remember the palette for the next images * (because it's more probable to get all the images after its palette) */ - applyPaletteFromData(res.data,res.size,&image); + e.bits=readPalette(&e.pal,res.data,res.size); + applyPalette(&e.pal,&image); bufferedPalette=res.id; - resourceListAdd(&paletteBuffer,&res); + e.id=res.id; + list_insert(&paletteBuffer,(void*)&e); /* Export the palette */ - ok=mFormatExportPal(res.data,vFileext,res.size,optionflag,backupExtension); - break; + ok=mFormatExportPal(&e.pal,e.bits,vFileext,optionflag,backupExtension); + } break; case eResTypePcspeaker: /* save pcs file */ case eResTypeMidi: /* save midi file */ ok=mFormatExportMid(res.data,vFileext,res.size,optionflag,backupExtension); @@ -133,14 +136,17 @@ int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int opti case eResTypeImage: /* save image */ /* Palette handling */ if (resourceListCompareId(res.palette,bufferedPalette)) { /* The palette isn't in the buffer */ - tResource readPalette; - readPalette.id=res.palette; + tResource otherPalette; + otherPalette.id=res.palette; /* Read the palette and load it into memory */ - if (mReadFileInDatFileId(&readPalette)) { + if (mReadFileInDatFileId(&otherPalette)) { /* All right, it's not so bad, I can handle it! I'll buffer the new palette */ - bufferedPalette=readPalette.id; - applyPaletteFromData(readPalette.data,readPalette.size,&image); - resourceListAdd(&paletteBuffer,&readPalette); + tPaletteListItem e; + e.bits=readPalette(&e.pal,otherPalette.data,otherPalette.size); + applyPalette(&e.pal,&image); + bufferedPalette=otherPalette.id; + e.id=res.id; + list_insert(&paletteBuffer,(void*)&e); } /* else, that's bad, I'll have to use the previous palette, even if it is the default */ } /* else, good, the palette is buffered */ /* Export bitmap */ @@ -168,7 +174,7 @@ int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int opti /* Free allocated resources, dynamic strings and the index */ resourceListDrop(r); mReadCloseDatFile(); - resourceListDrop(&paletteBuffer); + list_drop(&paletteBuffer); /* Close unknownXML */ return ok?count:PR_RESULT_ERR_EXTRACTION; diff --git a/PR/src/lib/actions/import.c b/PR/src/lib/actions/import.c index b523e43..4b4230c 100644 --- a/PR/src/lib/actions/import.c +++ b/PR/src/lib/actions/import.c @@ -72,7 +72,7 @@ int mAddCompiledFileToDatFile(tResource* res,const char* vFile) { case eResTypePcspeaker: return mFormatImportMid(res); case eResTypePalette: - return mFormatImportPal(res,vFile); + /* return mFormatImportPal(res,vFile); TODO: fix */ case eResTypeBinary: default: mWriteFileInDatFile(res); diff --git a/PR/src/lib/compression/lzg_decompress.c b/PR/src/lib/compression/lzg_decompress.c index 20a8319..976b6cf 100644 --- a/PR/src/lib/compression/lzg_decompress.c +++ b/PR/src/lib/compression/lzg_decompress.c @@ -60,12 +60,12 @@ int expandLzg(const unsigned char* input, int inputSize, /* main loop */ while (iCursor<inputSize&&oCursor<(*outputSize)) { -printf("i=%d o=%d\n",iCursor,oCursor); +/*printf("i=%d o=%d\n",iCursor,oCursor);*/ maskbyte=input[iCursor++]; for (k=8;k&&(iCursor<inputSize);k--) { if (popBit(&maskbyte)) { output[oCursor++]=input[iCursor++]; /* copy input to output */ -printf("%02x ",output[oCursor-1]); +/*printf("%02x ",output[oCursor-1]);*/ } else { /* * loc: @@ -83,7 +83,7 @@ printf("%02x ",output[oCursor-1]); while (rep--) { /* repeat pattern in output */ output[oCursor]=output[oCursor-loc]; -printf("%02x ",output[oCursor]); +/*printf("%02x ",output[oCursor]);*/ oCursor++; } } @@ -97,7 +97,7 @@ printf("%02x ",output[oCursor]); for(iCursor=LZG_WINDOW_SIZE;iCursor<oCursor;iCursor++) (*output2)[iCursor-LZG_WINDOW_SIZE]=output[iCursor]; -printf("oc=%d os=%d ic=%d is=%d\n",oCursor,(*outputSize),iCursor,inputSize); +/*printf("oc=%d os=%d ic=%d is=%d\n",oCursor,(*outputSize),iCursor,inputSize);*/ if (oCursor>=(*outputSize)) return inputSize; diff --git a/PR/src/lib/compression/rlev_decompress.c b/PR/src/lib/compression/rlev_decompress.c index 6bae68b..989efd1 100644 --- a/PR/src/lib/compression/rlev_decompress.c +++ b/PR/src/lib/compression/rlev_decompress.c @@ -40,7 +40,7 @@ rlec_uncompress.c: Princed Resources : Image Compression Library : /* Expands RLE algorithm */ int expandRleC(const unsigned char* input, int inputSize, unsigned char** output, int *outputSize,int verif) { - register unsigned char rep; + register unsigned char rep=0; int oCursor=0; int iCursor=0; int done=0; @@ -57,7 +57,7 @@ printf("o=%d i=%d\n",oCursor,iCursor); if ((done)||(oCursor%verif)) { done=0; if (rep&0x80) { /* repeat */ - //rep&=~0x80; + /*rep&=~0x80;*/ rep-=0x80; rep++; while (rep--) (*output)[oCursor++]=input[iCursor]; @@ -69,13 +69,11 @@ printf("o=%d i=%d\n",oCursor,iCursor); } } } else { -//printf("aux=%d lineSize=%d (iCursor-aux)=%d\n",aux,lineSize,(iCursor-aux)); if (aux) if (lineSize!=(iCursor-aux)) printf("Error, line size is wrong: lineSize=%d got=%d\n",lineSize,(iCursor-aux)); lineSize=rep+256*input[iCursor]+1; -//printf("i=%d aux=%d o=%d\n",iCursor,aux,oCursor); iCursor++; done=1; aux=iCursor; diff --git a/PR/src/lib/formats/bmp.c b/PR/src/lib/formats/bmp.c index 65cd9d0..f0e96f4 100644 --- a/PR/src/lib/formats/bmp.c +++ b/PR/src/lib/formats/bmp.c @@ -97,7 +97,7 @@ int mWriteBitMap(tImage img,const char* vFile,int optionflag,const char* backupE unsigned long int width; const unsigned long int zero=0; char lineSerialization; - tColor* palette; + const tColor* palette; FILE* bitmap; /* open file */ diff --git a/PR/src/lib/formats/pal.c b/PR/src/lib/formats/pal.c index 445fd0e..5ac5a5a 100644 --- a/PR/src/lib/formats/pal.c +++ b/PR/src/lib/formats/pal.c @@ -43,64 +43,68 @@ pal.c: Princed Resources : JASC PAL files support | JASC Palette handling functions | \***************************************************************/ -static const char* enter="\r\n"; +/*static const char* enter="\r\n";*/ /* Public functions */ -int mFormatExportPal(const unsigned char* data, char *vFileext,unsigned long int size,int optionflag,const char* backupExtension ) { - unsigned char* pal=malloc(256*4+50); +int mFormatExportPal(const tPalette* p, int bits, char *vFileext, int optionflag, const char* backupExtension) { +/* unsigned char* pal=malloc(256*4+50);*/ unsigned char* aux=malloc(MAX_FILENAME_SIZE); + const tColor* palette; int i; + FILE* fd; /* Export extra palette information */ - sprintf((char*)aux,"%s.more",vFileext); - writeData(data,1,(char*)aux,size,optionflag,backupExtension); - - /* Convert palette from POP format to JASC format */ - sprintf((char*)pal,"JASC-PAL\r\n%04d\r\n%d\r\n",100,16); - for (i=0;i<16;i++) { - strcpy((char*)aux,(char*)pal); - sprintf((char*)pal,"%s%d %d %d%s", - aux, - data[(i*3)+5]<<2, - data[(i*3)+6]<<2, - data[(i*3)+7]<<2, - enter + /*sprintf((char*)aux,"%s.more",vFileext); + writeData(data,1,(char*)aux,size,optionflag,backupExtension); TODO fix that */ + + /* open file */ + if (!writeOpen(vFileext,&fd,optionflag)) return 0; /* false */ + + /* Convert palette from tPalette format to JASC format */ + getPalette(p, bits, &palette); + + fprintf(fd,"JASC-PAL\r\n%04d\r\n%d\r\n",100,1<<bits); + for (i=0;i<(1<<bits);i++) { + fprintf(fd,"%d %d %d\r\n", + palette[i].r, + palette[i].g, + palette[i].b ); } - for (i=0;pal[i];i++); - size=i-1; + /*for (i=0;pal[i];i++); + size=i-1;*/ /* save JASC palette */ - i=writeData(pal,0,vFileext,size,optionflag,backupExtension); +/* i=writeData(pal,0,vFileext,size,optionflag,backupExtension);*/ + writeCloseOk(fd,optionflag,backupExtension); - free(pal); +/* free(pal);*/ free(aux); return i; } -int mFormatImportPal(tResource *res,const char* vFile) { - +int mFormatImportPal(tPalette* p,int* bits, const char* vFile) { /* declare variables */ unsigned char* pals; unsigned char* pals1; - unsigned char pals2[]=PAL_SAMPLE; + unsigned char pals2[400]/*PAL_SAMPLE*/; unsigned char palh [30]; unsigned char* pal; unsigned char* pal2; - char* data2; +/* char* data2;*/ char aux[MAX_FILENAME_SIZE]; - int r; +/* int r; int g; - int b; + int b;*/ int i=0; - int k=16; +/* int k=16;*/ int sample1; /* check size */ - if ((res->size)<130) return 0; /* false */ + /*if ((res->size)<130) return 0; * false */ /* TODO: fix, pal 256 support. verify JASC pal header */ - while (palh[i]==(res->data)[i++]); + /*while (palh[i]==(res->data)[i++]);*/ if (i!=sizeof(palh)) return 0; /* false: palette differs with headers */ /* Read sample */ @@ -123,22 +127,22 @@ int mFormatImportPal(tResource *res,const char* vFile) { if (sample1) free(pals1); /* set current values */ - data2=strtok((char*)(res->data)+sizeof(palh)-1,enter); + /*data2=strtok((char*)(res->data)+sizeof(palh)-1,enter); while (k--) { - if (!sscanf(data2,"%d %d %d",&r,&g,&b)) return 0; /* false */ - /* Those lines mean a loss of data (palette colours are saved in the nearest multiple of 4) */ + if (!sscanf(data2,"%d %d %d",&r,&g,&b)) return 0; * false * + * Those lines mean a loss of data (palette colours are saved in the nearest multiple of 4) * *(pal2++)=(unsigned char)((r+2)>>2); *(pal2++)=(unsigned char)((g+2)>>2); *(pal2++)=(unsigned char)((b+2)>>2); data2=strtok(NULL,enter); } - +*/ /* save and free palette */ - res->size=100; +/* res->size=100; free(res->data); res->data=pal; mWriteFileInDatFile(res); - +*/ return 1; /* true */ } diff --git a/PR/src/lib/layers/autodetect.c b/PR/src/lib/layers/autodetect.c index 9bafb5b..2a4cd18 100644 --- a/PR/src/lib/layers/autodetect.c +++ b/PR/src/lib/layers/autodetect.c @@ -37,6 +37,11 @@ autodetect.c: Princed Resources : Automatic detection resource types #include "autodetect.h" +int isA64kPalette(const unsigned char* d, int s) { + while (s--) if (d[s]>>6) return 0; /* false */ + return 1; /* true */ +} + /***************************************************************\ | Item Type Detector | \***************************************************************/ @@ -56,8 +61,11 @@ int verifyImageHeader(const unsigned char *array, int size) { } int verifyPaletteHeader(const unsigned char *array, int size) { - /* this is only pop2 palette */ - return ((size==101)&&(!array[2])&&(!array[3])&&(array[4]==0x10)); + return ( + ((size==101)&&(!array[2])&&(!array[3])&&(array[4]==0x10)) + || + ((size==(256*3))&&isA64kPalette(array,size)) + ); } int verifySpeakerHeader(const unsigned char *array, int size) { diff --git a/PR/src/lib/layers/disk.c b/PR/src/lib/layers/disk.c index 25931a9..a2c7791 100644 --- a/PR/src/lib/layers/disk.c +++ b/PR/src/lib/layers/disk.c @@ -52,26 +52,26 @@ disk.c: Princed Resources : Disk Access & File handling functions #endif #ifndef WIN32 - #define defmkdir(a) mkdir (a,(mode_t)0755) +#define defmkdir(a) mkdir (a,(mode_t)0755) /* Recursive directory scanning needs <dirent> for POSIX or "direntwin" for windows */ - #ifdef DISK_DIR_SCANING - #include <dirent.h> - #endif +#ifdef DISK_DIR_SCANING +#include <dirent.h> +#endif /* Terminal manipulation for UNIX (to avoid the enter after selecting an option) */ - #ifdef DISK_TERM_MANIPULATION - #include <termios.h> - #include <unistd.h> - #include <fcntl.h> - #endif - #define osIndepGetCharacter() getchar() +#ifdef DISK_TERM_MANIPULATION +#include <termios.h> +#include <unistd.h> +#include <fcntl.h> +#endif +#define osIndepGetCharacter() getchar() #else - #include <direct.h> /* mkdir */ - #define defmkdir(a) mkdir (a) - #ifdef DISK_DIR_SCANING - #include "direntwin.h" - #endif - #include <conio.h> /* getche */ - #define osIndepGetCharacter() getche() +#include <direct.h> /* mkdir */ +#define defmkdir(a) mkdir (a) +#ifdef DISK_DIR_SCANING +#include "direntwin.h" +#endif +#include <conio.h> /* getche */ +#define osIndepGetCharacter() getche() #endif #ifndef DISK_ALLWAYS_FORCE diff --git a/PR/src/lib/layers/pallist.c b/PR/src/lib/layers/pallist.c new file mode 100644 index 0000000..7d8d62f --- /dev/null +++ b/PR/src/lib/layers/pallist.c @@ -0,0 +1,46 @@ +/* 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 +*/ + +/* +pallist.c: Princed Resources : Palette list layer implementation +\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf + Copyright 2006 Princed Development Team + Created: 09 Feb 2006 + + Author: Enrique Calot <ecalot.cod@princed.com.ar> + Version: 1.00 (2006-Feb-09) + + Note: + DO NOT remove this copyright notice +*/ + +/* Defines */ +#include "pallist.h" + +/* palette list layer (that uses the abstract list layer primitives) */ + +int pallist_compare(const void* a,const void* b) { + return resourceListCompareId(((tPaletteListItem*)a)->id,((tPaletteListItem*)b)->id); +} + +tPaletteList paletteListCreate() { + return list_create(sizeof(tPaletteListItem),pallist_compare,NULL); +} + diff --git a/PR/src/lib/object/image/image16.c b/PR/src/lib/object/image/image16.c index ec9f6cb..eeb84e3 100644 --- a/PR/src/lib/object/image/image16.c +++ b/PR/src/lib/object/image/image16.c @@ -21,7 +21,7 @@ /* compress.c: Princed Resources : Image Compression Library \xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf - Copyright 2003, 2004 Princed Development Team + Copyright 2003, 2004, 2005, 2006 Princed Development Team Created: 24 Aug 2003 Author: Enrique Calot <ecalot.cod@princed.com.ar> @@ -43,8 +43,8 @@ compress.c: Princed Resources : Image Compression Library * Definitions: * no compression is called RAW * there are 2 algorithms types: RLE and LZG - * we can use the modifier: cmp_transpose and not cmp_transpose (t) - * we can use the LZG modifier: Higher (checks more extensively the LZG window + * we can use the modifier: not transposed and transposed (t) + * we can use the LZG modifier: higher (checks more extensively the LZG window * without ignoring less probable patterns) (+) * * So the possible compression algorithm variants are: @@ -101,6 +101,8 @@ int expandLzg(const unsigned char* input, int inputSize, unsigned char** output, int *outputSize); int expandRle(const unsigned char* input, int inputSize, unsigned char** output, int *outputSize); +int expandRleC(const unsigned char* input, int inputSize, + unsigned char** output, int *outputSize,int verif); /***************************************************************\ | Compression Level Manager | @@ -114,7 +116,7 @@ void setCompressionLevel(int cl) { } /***************************************************************\ -| Image cmp_transpose | +| Image transpose | \***************************************************************/ /* Determines where the transposed byte must be saved */ @@ -162,7 +164,7 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) * returns the next image address or -1 in case of error */ - int imageSizeInBytes; + int imageSizeInBytes=0; int result; data++; @@ -241,7 +243,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { /* COMPRESS_RAW * The allocation size is the image size. * The algorithm is hard-coded. - * There is no need to code a cmp_transposed version because + * There is no need to code a transposed version because * we have no compression to improve. */ compressed[COMPRESS_RAW]=getMemory(imageSizeInBytes); @@ -355,3 +357,47 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { for (i=COMPRESS_RAW;i<max_alg;i++) free(compressed[i]); return 1; /* true */ } + +void pop2decompress(const char* from, const char* rle, const char* pix) { + /* This function is in an experimental state and hasn't yet been linked to the program */ + unsigned char* input; + unsigned char* output; + unsigned char* output2; + + int width; + int is,os,os2,os3; + int osCheck; + FILE* out; + + is=mLoadFileArray(from,&input); + if (!is) { + printf("Error\n"); + return; + } + osCheck=input[7]<<8|input[6]; + + printf("w=%d h=%d\n",width=input[3]<<8|input[2],input[1]<<8|input[0]); + + + out=fopen(rle,"wb"); + os=osCheck; + printf("lzg=%d\n", os3=expandLzg(input+8,is-8,&output,&os)); + fwrite(output,os,1,out); + fclose(out); + + out=fopen(pix,"wb"); + printf("rle=%d\n", expandRleC(output,os,&output2,&os2,width)); + fwrite(output2,os2,1,out); + + printf("lzg=%d\n", os3=expandLzg(input+8+is-8-os3+2,os3-2,&output,&os)); + osCheck=input[7+is-8-os3+2]<<8|input[6+is-8-os3+2]; + + printf("rle=%d osCheck=%d\n", expandRleC(output,os,&output2,&os2,width), osCheck); + fwrite(output2,os2,1,out); + + fclose(out); + + printf("os=%d oscheck=%d\n",os,osCheck); + return; +} + diff --git a/PR/src/lib/object/image/image2.c b/PR/src/lib/object/image/image2.c index ec9f6cb..eeb84e3 100644 --- a/PR/src/lib/object/image/image2.c +++ b/PR/src/lib/object/image/image2.c @@ -21,7 +21,7 @@ /* compress.c: Princed Resources : Image Compression Library \xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf - Copyright 2003, 2004 Princed Development Team + Copyright 2003, 2004, 2005, 2006 Princed Development Team Created: 24 Aug 2003 Author: Enrique Calot <ecalot.cod@princed.com.ar> @@ -43,8 +43,8 @@ compress.c: Princed Resources : Image Compression Library * Definitions: * no compression is called RAW * there are 2 algorithms types: RLE and LZG - * we can use the modifier: cmp_transpose and not cmp_transpose (t) - * we can use the LZG modifier: Higher (checks more extensively the LZG window + * we can use the modifier: not transposed and transposed (t) + * we can use the LZG modifier: higher (checks more extensively the LZG window * without ignoring less probable patterns) (+) * * So the possible compression algorithm variants are: @@ -101,6 +101,8 @@ int expandLzg(const unsigned char* input, int inputSize, unsigned char** output, int *outputSize); int expandRle(const unsigned char* input, int inputSize, unsigned char** output, int *outputSize); +int expandRleC(const unsigned char* input, int inputSize, + unsigned char** output, int *outputSize,int verif); /***************************************************************\ | Compression Level Manager | @@ -114,7 +116,7 @@ void setCompressionLevel(int cl) { } /***************************************************************\ -| Image cmp_transpose | +| Image transpose | \***************************************************************/ /* Determines where the transposed byte must be saved */ @@ -162,7 +164,7 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) * returns the next image address or -1 in case of error */ - int imageSizeInBytes; + int imageSizeInBytes=0; int result; data++; @@ -241,7 +243,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { /* COMPRESS_RAW * The allocation size is the image size. * The algorithm is hard-coded. - * There is no need to code a cmp_transposed version because + * There is no need to code a transposed version because * we have no compression to improve. */ compressed[COMPRESS_RAW]=getMemory(imageSizeInBytes); @@ -355,3 +357,47 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { for (i=COMPRESS_RAW;i<max_alg;i++) free(compressed[i]); return 1; /* true */ } + +void pop2decompress(const char* from, const char* rle, const char* pix) { + /* This function is in an experimental state and hasn't yet been linked to the program */ + unsigned char* input; + unsigned char* output; + unsigned char* output2; + + int width; + int is,os,os2,os3; + int osCheck; + FILE* out; + + is=mLoadFileArray(from,&input); + if (!is) { + printf("Error\n"); + return; + } + osCheck=input[7]<<8|input[6]; + + printf("w=%d h=%d\n",width=input[3]<<8|input[2],input[1]<<8|input[0]); + + + out=fopen(rle,"wb"); + os=osCheck; + printf("lzg=%d\n", os3=expandLzg(input+8,is-8,&output,&os)); + fwrite(output,os,1,out); + fclose(out); + + out=fopen(pix,"wb"); + printf("rle=%d\n", expandRleC(output,os,&output2,&os2,width)); + fwrite(output2,os2,1,out); + + printf("lzg=%d\n", os3=expandLzg(input+8+is-8-os3+2,os3-2,&output,&os)); + osCheck=input[7+is-8-os3+2]<<8|input[6+is-8-os3+2]; + + printf("rle=%d osCheck=%d\n", expandRleC(output,os,&output2,&os2,width), osCheck); + fwrite(output2,os2,1,out); + + fclose(out); + + printf("os=%d oscheck=%d\n",os,osCheck); + return; +} + diff --git a/PR/src/lib/object/image/image256.c b/PR/src/lib/object/image/image256.c index ec9f6cb..eeb84e3 100644 --- a/PR/src/lib/object/image/image256.c +++ b/PR/src/lib/object/image/image256.c @@ -21,7 +21,7 @@ /* compress.c: Princed Resources : Image Compression Library \xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf - Copyright 2003, 2004 Princed Development Team + Copyright 2003, 2004, 2005, 2006 Princed Development Team Created: 24 Aug 2003 Author: Enrique Calot <ecalot.cod@princed.com.ar> @@ -43,8 +43,8 @@ compress.c: Princed Resources : Image Compression Library * Definitions: * no compression is called RAW * there are 2 algorithms types: RLE and LZG - * we can use the modifier: cmp_transpose and not cmp_transpose (t) - * we can use the LZG modifier: Higher (checks more extensively the LZG window + * we can use the modifier: not transposed and transposed (t) + * we can use the LZG modifier: higher (checks more extensively the LZG window * without ignoring less probable patterns) (+) * * So the possible compression algorithm variants are: @@ -101,6 +101,8 @@ int expandLzg(const unsigned char* input, int inputSize, unsigned char** output, int *outputSize); int expandRle(const unsigned char* input, int inputSize, unsigned char** output, int *outputSize); +int expandRleC(const unsigned char* input, int inputSize, + unsigned char** output, int *outputSize,int verif); /***************************************************************\ | Compression Level Manager | @@ -114,7 +116,7 @@ void setCompressionLevel(int cl) { } /***************************************************************\ -| Image cmp_transpose | +| Image transpose | \***************************************************************/ /* Determines where the transposed byte must be saved */ @@ -162,7 +164,7 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) * returns the next image address or -1 in case of error */ - int imageSizeInBytes; + int imageSizeInBytes=0; int result; data++; @@ -241,7 +243,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { /* COMPRESS_RAW * The allocation size is the image size. * The algorithm is hard-coded. - * There is no need to code a cmp_transposed version because + * There is no need to code a transposed version because * we have no compression to improve. */ compressed[COMPRESS_RAW]=getMemory(imageSizeInBytes); @@ -355,3 +357,47 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { for (i=COMPRESS_RAW;i<max_alg;i++) free(compressed[i]); return 1; /* true */ } + +void pop2decompress(const char* from, const char* rle, const char* pix) { + /* This function is in an experimental state and hasn't yet been linked to the program */ + unsigned char* input; + unsigned char* output; + unsigned char* output2; + + int width; + int is,os,os2,os3; + int osCheck; + FILE* out; + + is=mLoadFileArray(from,&input); + if (!is) { + printf("Error\n"); + return; + } + osCheck=input[7]<<8|input[6]; + + printf("w=%d h=%d\n",width=input[3]<<8|input[2],input[1]<<8|input[0]); + + + out=fopen(rle,"wb"); + os=osCheck; + printf("lzg=%d\n", os3=expandLzg(input+8,is-8,&output,&os)); + fwrite(output,os,1,out); + fclose(out); + + out=fopen(pix,"wb"); + printf("rle=%d\n", expandRleC(output,os,&output2,&os2,width)); + fwrite(output2,os2,1,out); + + printf("lzg=%d\n", os3=expandLzg(input+8+is-8-os3+2,os3-2,&output,&os)); + osCheck=input[7+is-8-os3+2]<<8|input[6+is-8-os3+2]; + + printf("rle=%d osCheck=%d\n", expandRleC(output,os,&output2,&os2,width), osCheck); + fwrite(output2,os2,1,out); + + fclose(out); + + printf("os=%d oscheck=%d\n",os,osCheck); + return; +} + diff --git a/PR/src/lib/object/image/image_common.c b/PR/src/lib/object/image/image_common.c index ec9f6cb..eeb84e3 100644 --- a/PR/src/lib/object/image/image_common.c +++ b/PR/src/lib/object/image/image_common.c @@ -21,7 +21,7 @@ /* compress.c: Princed Resources : Image Compression Library \xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf - Copyright 2003, 2004 Princed Development Team + Copyright 2003, 2004, 2005, 2006 Princed Development Team Created: 24 Aug 2003 Author: Enrique Calot <ecalot.cod@princed.com.ar> @@ -43,8 +43,8 @@ compress.c: Princed Resources : Image Compression Library * Definitions: * no compression is called RAW * there are 2 algorithms types: RLE and LZG - * we can use the modifier: cmp_transpose and not cmp_transpose (t) - * we can use the LZG modifier: Higher (checks more extensively the LZG window + * we can use the modifier: not transposed and transposed (t) + * we can use the LZG modifier: higher (checks more extensively the LZG window * without ignoring less probable patterns) (+) * * So the possible compression algorithm variants are: @@ -101,6 +101,8 @@ int expandLzg(const unsigned char* input, int inputSize, unsigned char** output, int *outputSize); int expandRle(const unsigned char* input, int inputSize, unsigned char** output, int *outputSize); +int expandRleC(const unsigned char* input, int inputSize, + unsigned char** output, int *outputSize,int verif); /***************************************************************\ | Compression Level Manager | @@ -114,7 +116,7 @@ void setCompressionLevel(int cl) { } /***************************************************************\ -| Image cmp_transpose | +| Image transpose | \***************************************************************/ /* Determines where the transposed byte must be saved */ @@ -162,7 +164,7 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) * returns the next image address or -1 in case of error */ - int imageSizeInBytes; + int imageSizeInBytes=0; int result; data++; @@ -241,7 +243,7 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { /* COMPRESS_RAW * The allocation size is the image size. * The algorithm is hard-coded. - * There is no need to code a cmp_transposed version because + * There is no need to code a transposed version because * we have no compression to improve. */ compressed[COMPRESS_RAW]=getMemory(imageSizeInBytes); @@ -355,3 +357,47 @@ int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { for (i=COMPRESS_RAW;i<max_alg;i++) free(compressed[i]); return 1; /* true */ } + +void pop2decompress(const char* from, const char* rle, const char* pix) { + /* This function is in an experimental state and hasn't yet been linked to the program */ + unsigned char* input; + unsigned char* output; + unsigned char* output2; + + int width; + int is,os,os2,os3; + int osCheck; + FILE* out; + + is=mLoadFileArray(from,&input); + if (!is) { + printf("Error\n"); + return; + } + osCheck=input[7]<<8|input[6]; + + printf("w=%d h=%d\n",width=input[3]<<8|input[2],input[1]<<8|input[0]); + + + out=fopen(rle,"wb"); + os=osCheck; + printf("lzg=%d\n", os3=expandLzg(input+8,is-8,&output,&os)); + fwrite(output,os,1,out); + fclose(out); + + out=fopen(pix,"wb"); + printf("rle=%d\n", expandRleC(output,os,&output2,&os2,width)); + fwrite(output2,os2,1,out); + + printf("lzg=%d\n", os3=expandLzg(input+8+is-8-os3+2,os3-2,&output,&os)); + osCheck=input[7+is-8-os3+2]<<8|input[6+is-8-os3+2]; + + printf("rle=%d osCheck=%d\n", expandRleC(output,os,&output2,&os2,width), osCheck); + fwrite(output2,os2,1,out); + + fclose(out); + + printf("os=%d oscheck=%d\n",os,osCheck); + return; +} + diff --git a/PR/src/lib/object/palette/pop1_16c.c b/PR/src/lib/object/palette/pop1_16c.c index 71f872b..f4a87b3 100644 --- a/PR/src/lib/object/palette/pop1_16c.c +++ b/PR/src/lib/object/palette/pop1_16c.c @@ -37,6 +37,7 @@ palette.c: Princed Resources : The palette object implementation #include <stdlib.h> #include <string.h> +#include <stdio.h> #include "palette.h" /***************************************************************\ @@ -48,13 +49,13 @@ static tColor sample_pal4[]={{0,0,0},{4,4,4}}; /*SAMPLE_PAL16;*/ int setPalette(tPalette* p, int bits, tColor* palette) { switch(bits) { case 1: - memcpy(p->p1,palette,2); + memcpy(p->p1,palette,2*sizeof(tColor)); break; case 4: - memcpy(p->p4,palette,16); + memcpy(p->p4,palette,16*sizeof(tColor)); break; case 8: - memcpy(p->p8,palette,256); + memcpy(p->p8,palette,256*sizeof(tColor)); break; default: return -1; /* unsupported bit rate */ @@ -62,16 +63,16 @@ int setPalette(tPalette* p, int bits, tColor* palette) { return 0; } -int getPalette(tPalette* p, int bits, tColor** apalette) { +int getPalette(const tPalette* p, int bits, const tColor** apalette) { switch(bits) { case 1: - *apalette=&(p->p1); + *apalette=p->p1; break; case 4: - *apalette=&(p->p4); + *apalette=p->p4; break; case 8: - *apalette=&(p->p8); + *apalette=p->p8; break; default: return -1; /* unsupported bit rate */ @@ -83,7 +84,7 @@ tPalette createPalette() { tPalette r; int i; - //Palette 1 bit + /* Palette 1 bit */ r.p1[0].r=0; r.p1[0].g=0; r.p1[0].b=0; @@ -91,10 +92,10 @@ tPalette createPalette() { r.p1[1].g=255; r.p1[1].b=255; - //Palette 4 bits + /* Palette 4 bits */ memcpy(r.p4, sample_pal4, 16); - //Palette 8 bits + /* Palette 8 bits */ for (i=0;i<256;i++) { r.p8[i].r=i; r.p8[i].g=i; @@ -105,12 +106,42 @@ tPalette createPalette() { /* middle layer */ +#define to8bits_A(a) (((a)<<2)|((a)>>4)) +#define to8bits_B(a) (((a)<<2) ) +#define to8bits_C(a) (((a)<<2)+2 ) /* reads the information in data and tries to remember it in the palette */ int readPalette(tPalette* p, unsigned char* data, int dataSize) { - + tColor c[256]; + int i,bits=0; + *p=createPalette(); + printf("reading a palette from data (%d)\n",dataSize); + + switch (dataSize) { + case 101: + for (i=0;i<16;i++) { + c[i].r=data[(i*3)+5]<<2; + c[i].g=data[(i*3)+6]<<2; + c[i].b=data[(i*3)+7]<<2; + } + bits=4; + break; + case 3*256: + for (i=0;i<256;i++) { + c[i].r=data[(i*3)+0]<<2; + c[i].g=data[(i*3)+1]<<2; + c[i].b=data[(i*3)+2]<<2; + } + bits=8; + break; + } + + if (bits) setPalette(p,bits,c); + return bits; } int applyPalette(tPalette* p,tImage *i) { i->pal=*p; + return 0; } + diff --git a/PR/src/lib/object/palette/pop2_256c.c b/PR/src/lib/object/palette/pop2_256c.c index 71f872b..f4a87b3 100644 --- a/PR/src/lib/object/palette/pop2_256c.c +++ b/PR/src/lib/object/palette/pop2_256c.c @@ -37,6 +37,7 @@ palette.c: Princed Resources : The palette object implementation #include <stdlib.h> #include <string.h> +#include <stdio.h> #include "palette.h" /***************************************************************\ @@ -48,13 +49,13 @@ static tColor sample_pal4[]={{0,0,0},{4,4,4}}; /*SAMPLE_PAL16;*/ int setPalette(tPalette* p, int bits, tColor* palette) { switch(bits) { case 1: - memcpy(p->p1,palette,2); + memcpy(p->p1,palette,2*sizeof(tColor)); break; case 4: - memcpy(p->p4,palette,16); + memcpy(p->p4,palette,16*sizeof(tColor)); break; case 8: - memcpy(p->p8,palette,256); + memcpy(p->p8,palette,256*sizeof(tColor)); break; default: return -1; /* unsupported bit rate */ @@ -62,16 +63,16 @@ int setPalette(tPalette* p, int bits, tColor* palette) { return 0; } -int getPalette(tPalette* p, int bits, tColor** apalette) { +int getPalette(const tPalette* p, int bits, const tColor** apalette) { switch(bits) { case 1: - *apalette=&(p->p1); + *apalette=p->p1; break; case 4: - *apalette=&(p->p4); + *apalette=p->p4; break; case 8: - *apalette=&(p->p8); + *apalette=p->p8; break; default: return -1; /* unsupported bit rate */ @@ -83,7 +84,7 @@ tPalette createPalette() { tPalette r; int i; - //Palette 1 bit + /* Palette 1 bit */ r.p1[0].r=0; r.p1[0].g=0; r.p1[0].b=0; @@ -91,10 +92,10 @@ tPalette createPalette() { r.p1[1].g=255; r.p1[1].b=255; - //Palette 4 bits + /* Palette 4 bits */ memcpy(r.p4, sample_pal4, 16); - //Palette 8 bits + /* Palette 8 bits */ for (i=0;i<256;i++) { r.p8[i].r=i; r.p8[i].g=i; @@ -105,12 +106,42 @@ tPalette createPalette() { /* middle layer */ +#define to8bits_A(a) (((a)<<2)|((a)>>4)) +#define to8bits_B(a) (((a)<<2) ) +#define to8bits_C(a) (((a)<<2)+2 ) /* reads the information in data and tries to remember it in the palette */ int readPalette(tPalette* p, unsigned char* data, int dataSize) { - + tColor c[256]; + int i,bits=0; + *p=createPalette(); + printf("reading a palette from data (%d)\n",dataSize); + + switch (dataSize) { + case 101: + for (i=0;i<16;i++) { + c[i].r=data[(i*3)+5]<<2; + c[i].g=data[(i*3)+6]<<2; + c[i].b=data[(i*3)+7]<<2; + } + bits=4; + break; + case 3*256: + for (i=0;i<256;i++) { + c[i].r=data[(i*3)+0]<<2; + c[i].g=data[(i*3)+1]<<2; + c[i].b=data[(i*3)+2]<<2; + } + bits=8; + break; + } + + if (bits) setPalette(p,bits,c); + return bits; } int applyPalette(tPalette* p,tImage *i) { i->pal=*p; + return 0; } + diff --git a/PR/src/lib/object/palette/pop2_4bit.c b/PR/src/lib/object/palette/pop2_4bit.c index 71f872b..f4a87b3 100644 --- a/PR/src/lib/object/palette/pop2_4bit.c +++ b/PR/src/lib/object/palette/pop2_4bit.c @@ -37,6 +37,7 @@ palette.c: Princed Resources : The palette object implementation #include <stdlib.h> #include <string.h> +#include <stdio.h> #include "palette.h" /***************************************************************\ @@ -48,13 +49,13 @@ static tColor sample_pal4[]={{0,0,0},{4,4,4}}; /*SAMPLE_PAL16;*/ int setPalette(tPalette* p, int bits, tColor* palette) { switch(bits) { case 1: - memcpy(p->p1,palette,2); + memcpy(p->p1,palette,2*sizeof(tColor)); break; case 4: - memcpy(p->p4,palette,16); + memcpy(p->p4,palette,16*sizeof(tColor)); break; case 8: - memcpy(p->p8,palette,256); + memcpy(p->p8,palette,256*sizeof(tColor)); break; default: return -1; /* unsupported bit rate */ @@ -62,16 +63,16 @@ int setPalette(tPalette* p, int bits, tColor* palette) { return 0; } -int getPalette(tPalette* p, int bits, tColor** apalette) { +int getPalette(const tPalette* p, int bits, const tColor** apalette) { switch(bits) { case 1: - *apalette=&(p->p1); + *apalette=p->p1; break; case 4: - *apalette=&(p->p4); + *apalette=p->p4; break; case 8: - *apalette=&(p->p8); + *apalette=p->p8; break; default: return -1; /* unsupported bit rate */ @@ -83,7 +84,7 @@ tPalette createPalette() { tPalette r; int i; - //Palette 1 bit + /* Palette 1 bit */ r.p1[0].r=0; r.p1[0].g=0; r.p1[0].b=0; @@ -91,10 +92,10 @@ tPalette createPalette() { r.p1[1].g=255; r.p1[1].b=255; - //Palette 4 bits + /* Palette 4 bits */ memcpy(r.p4, sample_pal4, 16); - //Palette 8 bits + /* Palette 8 bits */ for (i=0;i<256;i++) { r.p8[i].r=i; r.p8[i].g=i; @@ -105,12 +106,42 @@ tPalette createPalette() { /* middle layer */ +#define to8bits_A(a) (((a)<<2)|((a)>>4)) +#define to8bits_B(a) (((a)<<2) ) +#define to8bits_C(a) (((a)<<2)+2 ) /* reads the information in data and tries to remember it in the palette */ int readPalette(tPalette* p, unsigned char* data, int dataSize) { - + tColor c[256]; + int i,bits=0; + *p=createPalette(); + printf("reading a palette from data (%d)\n",dataSize); + + switch (dataSize) { + case 101: + for (i=0;i<16;i++) { + c[i].r=data[(i*3)+5]<<2; + c[i].g=data[(i*3)+6]<<2; + c[i].b=data[(i*3)+7]<<2; + } + bits=4; + break; + case 3*256: + for (i=0;i<256;i++) { + c[i].r=data[(i*3)+0]<<2; + c[i].g=data[(i*3)+1]<<2; + c[i].b=data[(i*3)+2]<<2; + } + bits=8; + break; + } + + if (bits) setPalette(p,bits,c); + return bits; } int applyPalette(tPalette* p,tImage *i) { i->pal=*p; + return 0; } +