author | ecalot
<ecalot> 2006-03-08 09:58:05 UTC |
committer | ecalot
<ecalot> 2006-03-08 09:58:05 UTC |
parent | 21e1e8e316eea7a7d6f76e390f0ba4ed6c4b5080 |
PR/src/Makefile | +5 | -1 |
PR/src/include/autodetect.h | +0 | -1 |
PR/src/include/auxiliary.h | +39 | -0 |
PR/src/include/disk.h | +2 | -2 |
PR/src/lib/actions/export.c | +1 | -0 |
PR/src/lib/layers/autodetect.c | +2 | -6 |
PR/src/lib/layers/auxiliary.c | +81 | -0 |
PR/src/lib/object/image/image256.c | +3 | -4 |
PR/src/lib/object/object.c | +0 | -1 |
PR/src/lib/object/palette/pop2_256c.c | +3 | -3 |
diff --git a/PR/src/Makefile b/PR/src/Makefile index 02e2cba..6477b3b 100644 --- a/PR/src/Makefile +++ b/PR/src/Makefile @@ -54,7 +54,7 @@ endif ACTIONS = .import.o .export.o .classify.o XML = .parse.o .search.o .unknown.o .translate.o .tree.o COMPRESS = .lzg_compress.o .lzg_uncompress.o .rle_compress.o .rle_uncompress.o .rlec_uncompress.o -LAYERS = .dat.o .memory.o .list.o .reslist.o .pallist.o .disk.o .idlist.o .autodetect.o .stringformat.o .resourcematch.o +LAYERS = .dat.o .memory.o .list.o .reslist.o .pallist.o .disk.o .idlist.o .autodetect.o .stringformat.o .resourcematch.o .auxiliary.o FORMAT = .bmp.o .mid.o .pal.o .wav.o .plv.o OBJECT = .object.o .pop2_256c.o .pop1_4bit.o .image2.o .image16.o .image256.o .binary.o .sounds.o .level.o CONSOLE = .main.o .filedir.o @@ -254,6 +254,10 @@ $(XMLFILE): xml/resources.xml $(INFO) Compiling resource list parsing feature... $(CC) $(OPTIONS) -c lib/layers/resourcematch.c -o $@ +.auxiliary.o: lib/layers/auxiliary.c include/memory.h include/auxiliary.h + $(INFO) Compiling object auxiliary routines... + $(CC) $(OPTIONS) -c lib/layers/auxiliary.c -o $@ + .bmp.o: lib/formats/bmp.c include/bmp.h include/common.h include/dat.h include/disk.h include/memory.h $(INFO) Compiling bitmap files support \(bmp\)... $(CC) $(OPTIONS) -c lib/formats/bmp.c -o $@ diff --git a/PR/src/include/autodetect.h b/PR/src/include/autodetect.h index 24fd4f5..29c04ff 100644 --- a/PR/src/include/autodetect.h +++ b/PR/src/include/autodetect.h @@ -40,6 +40,5 @@ autodetect.h: Princed Resources : Resource automatic detection headers /* Verify header */ tResourceType verifyHeader(tBinary c); -int isA64kPalette(tBinary c); #endif diff --git a/PR/src/include/auxiliary.h b/PR/src/include/auxiliary.h new file mode 100644 index 0000000..1966407 --- /dev/null +++ b/PR/src/include/auxiliary.h @@ -0,0 +1,39 @@ +/* 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 +*/ + +/* +auxiliary.h: Princed Resources : Memory handling & comparison prototypes +\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf + Copyright 2006 Princed Development Team + Created: 8 Mar 2006 + + Author: Enrique Calot <ecalot.cod@princed.com.ar> + + Note: + DO NOT remove this copyright notice +*/ + +#ifndef _AUXILIARY_H_ +#define _AUXILIARY_H_ + +#include "binary.h" +int isA64kPalette(tBinary c); + +#endif diff --git a/PR/src/include/disk.h b/PR/src/include/disk.h index 984651e..c0be71f 100644 --- a/PR/src/include/disk.h +++ b/PR/src/include/disk.h @@ -77,8 +77,8 @@ int recurseDirectory(const char* path,int recursive, void* pass, void (*function /* array2vars*/ -#define array2short(a) (((*(a)))+((*((a)+1))<<8)) -#define array2long(a) (((*(a)))+((*((a)+1))<<8)+((*((a)+2))<<16)+((*((a)+3))<<24)) +#define array2short(a) (((*(a)))|((*((a)+1))<<8)) +#define array2long(a) (((*(a)))|((*((a)+1))<<8)|((*((a)+2))<<16)|((*((a)+3))<<24)) #ifdef MACOS #define freadshort(var,file) macfreads ((var),file) diff --git a/PR/src/lib/actions/export.c b/PR/src/lib/actions/export.c index 2a31695..c07038c 100644 --- a/PR/src/lib/actions/export.c +++ b/PR/src/lib/actions/export.c @@ -115,6 +115,7 @@ int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int opti /* handle palette linking */ switch (res.type) { /* TODO: use if and elsif */ case eResTypePop2Palette4bits: + case eResTypePop2PaletteNColors: case eResTypePop1Palette4bits: { /* save and remember palette file */ tPaletteListItem e; /* TODO: decide if the palette list has to be erased from the code */ o=e.pal=currentPalette=getObject(&res,&ok); diff --git a/PR/src/lib/layers/autodetect.c b/PR/src/lib/layers/autodetect.c index d072e8e..1752e77 100644 --- a/PR/src/lib/layers/autodetect.c +++ b/PR/src/lib/layers/autodetect.c @@ -36,11 +36,7 @@ autodetect.c: Princed Resources : Automatic detection resource types \***************************************************************/ #include "autodetect.h" - -int isA64kPalette(tBinary c) { - while (c.size--) if (c.data[c.size]>>6) return 0; /* false */ - return 1; /* true */ -} +#include "auxiliary.h" /***************************************************************\ | Item Type Detector | @@ -83,7 +79,7 @@ int verifyPaletteHeaderPop2_256(tBinary c) { c2.size=c.size-1; c2.data=c.data+1;*/ return ( - ((c.size==(256*3)||c.size==(320*3))&&isA64kPalette(c)) + ((c.size==(256*3+1)||c.size==(320*3))&&isA64kPalette(c)) /* TODO: the +1 is for debug purposes, it must be eliminated */ ); } diff --git a/PR/src/lib/layers/auxiliary.c b/PR/src/lib/layers/auxiliary.c new file mode 100644 index 0000000..86d469e --- /dev/null +++ b/PR/src/lib/layers/auxiliary.c @@ -0,0 +1,81 @@ +/* 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 +*/ + +/* +auxiliary.c: Princed Resources : Auxiliary common routines to help the object layer +\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf They DO know all the format inside each binary resource, + but they don't know the .dat format itself. + + Copyright 2006 Princed Development Team + Created: 7 Mar 2006 + + Author: Enrique Calot <ecalot.cod@princed.com.ar> + + Note: + DO NOT remove this copyright notice +*/ + +/***************************************************************\ +| I M P L E M E N T A T I O N | +\***************************************************************/ + +#include "auxiliary.h" +#include "disk.h" /* array2short */ + +/* Palette helper */ + +int isA64kPalette(tBinary c) { + while (c.size--) if (c.data[c.size]>>6) return 0; /* false */ + return 1; /* true */ +} + +/* Image helper */ + +/* + * Header info: + * 2 bytes - height little endian short int + * 2 bytes - width little endian short int + * 1 byte - doubleLayered boolean char (0 or 1) + * 1 byte - mask byte composed by: + * bit 0 - paletted boolean bit + * bits 1,2,3 - color bits-1 octal number, add 1 to get the value + * bits 4,5,6,7 - compression type hex number (from 0 to 4) + */ + +void getHeader(const unsigned char* header, int *w, int *h, int *paletted, int *doubleLayered, int *bits, int *algorithm) { + *w=array2short(header+0); + *h=array2short(header+2); + *doubleLayered=header[4]; + *paletted=header[5]>>7; + *bits=(header[5]>>4)&7; + *algorithm=header[5]&15; + (*bits)++; +} + +void setHeader(unsigned char* header, int w, int h, int paletted, int doubleLayered, int bits, int algorithm) { + bits--; + header[0]=w&0xff; + header[1]=(w>>8)&0xff; + header[2]=h&0xff; + header[3]=(h>>8)&0xff; + header[4]=doubleLayered; + header[5]= ((paletted&1)<<7) | ((bits&7)<<4) | ((algorithm&15)<<0); +} + diff --git a/PR/src/lib/object/image/image256.c b/PR/src/lib/object/image/image256.c index b83f12c..bf04f04 100644 --- a/PR/src/lib/object/image/image256.c +++ b/PR/src/lib/object/image/image256.c @@ -275,7 +275,7 @@ int objImage256Write(void* img,const char* file,int optionflag,const char* backu int bits; int colors; tColor* colorArray; - + if (i->pal.type!=eResTypeNone) { bits=paletteGetBits(i->pal); colors=paletteGetColors(i->pal); @@ -333,12 +333,11 @@ void* objImage256Read(const char* file,tObject palette, int *result) { int objImage256Set(void* o,tResource* res) { tImage* img=o; tBinary decompressed,compressed; - int algorithm; decompressed.data=img->pix; decompressed.size=img->widthInBytes*img->height; - algorithm=mCompressGraphic256(&decompressed,&compressed,6,img->widthInBytes,img->height); + mCompressGraphic256(&decompressed,&compressed,6,img->widthInBytes,img->height); /* * Write header @@ -352,7 +351,7 @@ int objImage256Set(void* o,tResource* res) { compressed.data[3]=img->width>>8; /* (8 bits)00000000+(4 bits)palette type+(4 bits)algorithm */ compressed.data[4]=0; - compressed.data[5]=(img->bits==4?0xb0:0x00)|algorithm; + compressed.data[5]=0xf3; res->content=compressed; mWriteFileInDatFile(res); diff --git a/PR/src/lib/object/object.c b/PR/src/lib/object/object.c index 2eb1ff9..b26f16d 100644 --- a/PR/src/lib/object/object.c +++ b/PR/src/lib/object/object.c @@ -122,7 +122,6 @@ int writeObject(tObject o, const char* file, int optionflag, const char* backupE error=objImage16Write(o.obj,file,optionflag,backupExtension); break; case eResTypeImage256: /* save image */ -printf("hello\n"); error=objImage256Write(o.obj,file,optionflag,backupExtension); break; default: diff --git a/PR/src/lib/object/palette/pop2_256c.c b/PR/src/lib/object/palette/pop2_256c.c index 0432a27..42b84e1 100644 --- a/PR/src/lib/object/palette/pop2_256c.c +++ b/PR/src/lib/object/palette/pop2_256c.c @@ -42,7 +42,7 @@ palette.c: Princed Resources : The palette object implementation #include "memory.h" #include "dat.h" #include "disk.h" /* writeData */ -#include "autodetect.h" /* isA64kPalette */ +#include "auxiliary.h" /* isA64kPalette */ #include "pal.h" @@ -54,7 +54,7 @@ typedef struct { void* objPop2PaletteNColorsCreate(tBinary cont, int *error) { tGenericPalette* r; int i,j; - + *error=PR_RESULT_SUCCESS; if (!isA64kPalette(cont)) { @@ -69,7 +69,7 @@ void* objPop2PaletteNColorsCreate(tBinary cont, int *error) { r->colorArray[j].g=to8bits_B(cont.data[i+1]); r->colorArray[j].b=to8bits_B(cont.data[i+2]); } - if (j!=256 || j!=320) return NULL; /*TODO: add free */ + if (j!=256 && j!=320) return NULL; /*TODO: add free */ r->size=j; return (void*)r;