git » fp-git.git » commit e47d92b

added cpp addon and improved pop2 256-color images

author ecalot
2006-05-30 01:57:50 UTC
committer ecalot
2006-05-30 01:57:50 UTC
parent 5c275faf37ea143963c8f969b430492d90bafc9d

added cpp addon and improved pop2 256-color images

PR/src/Makefile +23 -4
PR/src/addons/cpp/dat.cpp +223 -0
PR/src/addons/cpp/detect.cpp +238 -0
PR/src/addons/cpp/xml.cpp +62 -0
PR/src/addons/cpp/xml.h +36 -0
PR/src/include/compress.h +1 -1
PR/src/lib/compression/rlev_decompress.c +6 -5
PR/src/lib/object/image/image256.c +27 -2
PR/src/lib/object/palette/pop1_mono.c +43 -0

diff --git a/PR/src/Makefile b/PR/src/Makefile
index 6477b3b..e14b4fe 100644
--- a/PR/src/Makefile
+++ b/PR/src/Makefile
@@ -44,7 +44,8 @@ TYPE          = Debug
 # LINKERRELEASE may be:
 #  -s                              for release
 ifeq ($(TYPE),Debug)
-  RELEASE       = -g -Wall -pedantic 
+  #RELEASE       = -g -Wall -pedantic -fPIC for .so files
+  RELEASE       = -g -Wall -pedantic
   LINKERRELEASE =
 else
   RELEASE       = -O2 
@@ -84,7 +85,7 @@ $(EXEFILE): $(EXEOBJ) $(XMLFILE)
 	$(INFO)
 
 #command options
-.PHONY: clean cleanxml build all lib
+.PHONY: clean cleanxml build all libs
 
 clean:
 	$(INFO) Erasing temporary object files...
@@ -98,10 +99,10 @@ build: clean bin/pr
 
 all: $(EXEFILE)
 
-lib: $(LIBOBJ)
+libs: $(LIBOBJ)
 	$(MAKEDIR) bin
 	$(INFO) Making dynamic library...
-	$(CC) $(OPTIONS) -o bin/pr.so $(LIBOBJ) -Llibc -shared -dynamic -o $@
+	$(CC) $(OPTIONS) -o bin/pr.so $(LIBOBJ) -Llibc -shared -dynamic
 	$(INFO) Library successfully compiled
 	$(INFO)
 	$(INFO) Please read readme.coders.txt and pr.h for interfaces
@@ -300,3 +301,21 @@ pylib: .python.o $(LIBOBJ)
 	$(MAKEDIR) addons/python/bin
 	$(CC) -pthread -shared .python.o $(LIBOBJ) -o addons/python/bin/pr.so -o $@
 
+#cpp
+.cppdat.o: addons/cpp/dat.cpp include/pr.h
+	$(INFO) Building the C++ DAT handling interface
+	g++ -c addons/cpp/dat.cpp -Iinclude -o .cppdat.o
+
+.cppxml.o: addons/cpp/xml.cpp include/pr.h
+	$(INFO) Building the C++ XML handling interface
+	g++ -c addons/cpp/xml.cpp -Iinclude -o .cppxml.o
+
+cpp: .cppdat.o .cppxml.o
+
+
+
+
+
+
+
+
diff --git a/PR/src/addons/cpp/dat.cpp b/PR/src/addons/cpp/dat.cpp
new file mode 100644
index 0000000..94ade8d
--- /dev/null
+++ b/PR/src/addons/cpp/dat.cpp
@@ -0,0 +1,223 @@
+/*  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
+*/
+
+/*
+pr.c: Main source file for Princed Resources library
+\xaf\xaf\xaf\xaf
+	Princed Resources editor
+	(c) Copyright 2003-2006 Princed Development Team
+
+	Authors
+	 Coding & main routines
+	  Enrique Calot
+	  Santiago Zamora
+
+	 Graphic compression algorithms
+	  Tammo Jan Dijkema
+	  Enrique Calot
+
+	 Graphic format development
+	  Tammo Jan Dijkema
+	  Anke Balderer
+
+	 MID Sound format development
+	  Christian Lundheim
+
+	 Resources.xml edition
+	  Steven Fayers
+
+ Note:
+  DO NOT remove this copyright notice
+*/
+
+/* Headers */
+#include "pr.h"
+
+/***************************************************************\
+|                      Main working functions                   |
+\***************************************************************/
+#if 0
+FILE* outputStream=NULL;
+
+void prSetOutput(FILE* output) {
+	outputStream=output;
+}
+
+int prExportDat(const char* vDatFile, const char* vDirName, const char* vResFile) {
+	outputStream=stdout;
+	return prExportDatOpt(vDatFile,vDirName,vResFile,export_flag,NULL,NULL,NULL,NULL);
+}
+
+int prExportDatOpt(const char* vDatFile, const char* vDirName, const char* vResFile,int opt,const char* vDatFileName,const char* datAuthor, const char* backupExtension,const char* format) {
+	/*
+	 * Arguments:
+	 * 	char* vDatFile        - full Path to the DAT file
+	 * 	char* vDirName        - full Path to the extracting folder
+	 * 	                        (doesn't need to exist)
+	 * 	char* vResFile        - full Path to the resources XML file
+	 * 	                        NULL is the default file resources.xml
+	 * 	char opt              - program options, see below
+	 * 	char* vDatFileName    - name of the file to be extracted
+	 * 	                        NULL means predict it from vDatFile
+	 * 	const char* datAuthor - Author's name when extracting PLV's,
+	 * 	                        NULL is default
+	 * 	const char* backupExtension
+	 * 	                      - If backup_flag is set, the string to attach
+	 * 	                        to the backup files
+	 * 	const char* format
+	 * 	                      - Sets the format the unknown files will be created.
+	 * 	                        See stringformat.c documentation.
+	 *
+	 * Options:
+	 * 	unknown_flag   - generate the unknown file without performing
+	 *                   any extraction
+	 * 	raw_flag       - uses raw format
+	 * 	verbose_flag   - explain what is being done
+	 * 	recursive_flag - searches for all DAT files (only if vDatFile
+	 * 	                 is not a DAT file and vDatFileName is NULL)
+	 * 	force_flag     - default option, you cannot disable it,
+	 * 	                 so please make a backup of your files
+	 * 	backup_flag    - backup your files
+	 *
+	 * Return values:
+	 * 	00 Ok
+	 * 	-1 Error accessing the file DAT
+	 * 	-2 Memory error in extraction
+	 * 	-3 Invalid DAT file
+	 * 	-4 XML Parse error
+	 * 	-5 Memory error in parsing
+	 * 	-6 XML Attribute not recognized
+	 * 	-7 XML File not found
+	 */
+
+	/* Declare variables */
+	tResourceList r;
+	int a;
+	const char* aux;
+	char* currentDatFileName;
+	char* currentDatFile;
+
+	r=resourceListCreate(0);
+
+	currentDatFile=strallocandcopy(vDatFile);
+
+	if (parseGivenPath(currentDatFile)) return PR_RESULT_ERR_COMMAND_LINE_SYNTAX;
+
+	if (vDatFileName==NULL) { /* if no special DAT file was specified, a path parsed will be used */
+		aux=getFileNameFromPath(currentDatFile);
+	} else {
+		aux=vDatFileName;
+	}
+	currentDatFileName=strallocandcopy(aux);
+
+	/* Parse XML and export the file */
+	a=xmlParseFileForResource(vResFile,currentDatFileName,&r);
+	if (a==PR_RESULT_SUCCESS) {
+		/* exporting errors/no errors */
+		a=extract(currentDatFile,vDirName,&r,opt,currentDatFileName,datAuthor,backupExtension,format);
+	}
+	resourceListDrop(&r);
+	free(currentDatFileName);
+	free(currentDatFile);
+	freeItemMatchingList();
+
+	return a;
+}
+
+int prImportDat(const char* vDatFile, const char* vDirName, const char* vResFile) {
+	outputStream=stdout;
+	return prImportDatOpt(vDatFile,vDirName,vResFile,0,NULL,NULL);
+}
+
+int prImportDatOpt(const char* vDatFile, const char* vDirName, const char* vResFile,int opt,const char* vDatFileName, const char* backupExtension) {
+	/*
+	 * Arguments:
+	 * 	char* vDatFile        - full Path to the DAT file;
+	 * 	                        if file use it, if directory, perform it for
+	 * 	                        all files
+	 * 	char* vDirName        - full Path to the extracting folder
+	 * 	                        (doesn't need to exist)
+	 * 	char* vResFile        - full Path to the resources XML file
+	 * 	                        (resources.xml by default)
+	 * 	char opt              - program options, see below
+	 * 	char *vDatFileName    - name of the file to be extracted
+	 * 	                        NULL means predict it from vDatFile
+	 * 	const char* backupExtension
+	 * 	                      - If backup_flag is set, the string to attach
+	 * 	                        to the backup files
+	 *
+	 * Options:
+	 * 	raw_flag       - uses raw format
+	 * 	verbose_flag   - explain what is being done
+	 * 	recursive_flag - searches for all DAT files (only if vDatFile
+	 * 	                 is not a DAT file and vDatFileName is NULL)
+	 * 	force_flag     - If not set and the file exists it will prompt
+	 * 	                 for action
+	 * 	backup_flag    - backup your files
+	 *
+	 * Return values:
+	 * 	-1 DAT File couldn't be open for writing
+	 * 	-2 DAT file not found or invalid in partial importation
+	 * 	-3 XML Parse error
+	 * 	-4 No memory
+	 * 	-5 XML Attribute not recognized
+	 * 	-6 XML File not found
+	 * 	00 File successfully imported
+	 * 	positive number: number of missing files
+	 */
+
+	/* Declare variables */
+	tResourceList r;
+	int a;
+	const char* aux;
+	char* currentDatFileName;
+	char* currentDatFile;
+
+	r=resourceListCreate(0);
+
+	currentDatFile=strallocandcopy(vDatFile);
+
+	if (parseGivenPath(currentDatFile)) return PR_RESULT_ERR_COMMAND_LINE_SYNTAX;
+
+	if (vDatFileName==NULL) { /* if no special DAT file was specified, a path parsed will be used */
+		aux=getFileNameFromPath(currentDatFile);
+	} else {
+		aux=vDatFileName;
+	}
+	currentDatFileName=strallocandcopy(aux);
+
+	/* Parse XML and import files */
+	a=xmlParseFileForResource(vResFile,currentDatFileName,&r);
+	if (a==PR_RESULT_SUCCESS) {
+		/* importing errors/no errors */
+		a=compile (currentDatFile, vDirName,&r,opt,currentDatFileName,backupExtension);
+	}
+	resourceListDrop(&r);
+	free(currentDatFileName);
+	free(currentDatFile);
+	freeItemMatchingList();
+	return a;
+}
+
+/* When compiling in UNIX SO libraries */
+#ifndef WIN32
+void start() {}
+#endif
+#endif
diff --git a/PR/src/addons/cpp/detect.cpp b/PR/src/addons/cpp/detect.cpp
new file mode 100644
index 0000000..8e39e4a
--- /dev/null
+++ b/PR/src/addons/cpp/detect.cpp
@@ -0,0 +1,238 @@
+/*  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
+*/
+
+/*
+pr.c: Main source file for Princed Resources library
+\xaf\xaf\xaf\xaf
+	Princed Resources editor
+	(c) Copyright 2003-2006 Princed Development Team
+
+	Authors
+	 Coding & main routines
+	  Enrique Calot
+	  Santiago Zamora
+
+	 Graphic compression algorithms
+	  Tammo Jan Dijkema
+	  Enrique Calot
+
+	 Graphic format development
+	  Tammo Jan Dijkema
+	  Anke Balderer
+
+	 MID Sound format development
+	  Christian Lundheim
+
+	 Resources.xml edition
+	  Steven Fayers
+
+ Note:
+  DO NOT remove this copyright notice
+*/
+
+/* Headers */
+#include <stdio.h>
+#include <string.h>
+
+#include "common.h"
+
+#include "classify.h"
+#include "export.h"
+#include "import.h"
+
+#include "disk.h"      /* getFileNameFromPath */
+#include "idlist.h"
+#include "memory.h"    /* getMemory, free */
+#include "reslist.h"
+
+#include "search.h"    /* parse */
+#include "unknown.h"
+
+/***************************************************************\
+|                      Main working functions                   |
+\***************************************************************/
+#if 0
+FILE* outputStream=NULL;
+
+void prSetOutput(FILE* output) {
+	outputStream=output;
+}
+
+int prExportDat(const char* vDatFile, const char* vDirName, const char* vResFile) {
+	outputStream=stdout;
+	return prExportDatOpt(vDatFile,vDirName,vResFile,export_flag,NULL,NULL,NULL,NULL);
+}
+
+int prExportDatOpt(const char* vDatFile, const char* vDirName, const char* vResFile,int opt,const char* vDatFileName,const char* datAuthor, const char* backupExtension,const char* format) {
+	/*
+	 * Arguments:
+	 * 	char* vDatFile        - full Path to the DAT file
+	 * 	char* vDirName        - full Path to the extracting folder
+	 * 	                        (doesn't need to exist)
+	 * 	char* vResFile        - full Path to the resources XML file
+	 * 	                        NULL is the default file resources.xml
+	 * 	char opt              - program options, see below
+	 * 	char* vDatFileName    - name of the file to be extracted
+	 * 	                        NULL means predict it from vDatFile
+	 * 	const char* datAuthor - Author's name when extracting PLV's,
+	 * 	                        NULL is default
+	 * 	const char* backupExtension
+	 * 	                      - If backup_flag is set, the string to attach
+	 * 	                        to the backup files
+	 * 	const char* format
+	 * 	                      - Sets the format the unknown files will be created.
+	 * 	                        See stringformat.c documentation.
+	 *
+	 * Options:
+	 * 	unknown_flag   - generate the unknown file without performing
+	 *                   any extraction
+	 * 	raw_flag       - uses raw format
+	 * 	verbose_flag   - explain what is being done
+	 * 	recursive_flag - searches for all DAT files (only if vDatFile
+	 * 	                 is not a DAT file and vDatFileName is NULL)
+	 * 	force_flag     - default option, you cannot disable it,
+	 * 	                 so please make a backup of your files
+	 * 	backup_flag    - backup your files
+	 *
+	 * Return values:
+	 * 	00 Ok
+	 * 	-1 Error accessing the file DAT
+	 * 	-2 Memory error in extraction
+	 * 	-3 Invalid DAT file
+	 * 	-4 XML Parse error
+	 * 	-5 Memory error in parsing
+	 * 	-6 XML Attribute not recognized
+	 * 	-7 XML File not found
+	 */
+
+	/* Declare variables */
+	tResourceList r;
+	int a;
+	const char* aux;
+	char* currentDatFileName;
+	char* currentDatFile;
+
+	r=resourceListCreate(0);
+
+	currentDatFile=strallocandcopy(vDatFile);
+
+	if (parseGivenPath(currentDatFile)) return PR_RESULT_ERR_COMMAND_LINE_SYNTAX;
+
+	if (vDatFileName==NULL) { /* if no special DAT file was specified, a path parsed will be used */
+		aux=getFileNameFromPath(currentDatFile);
+	} else {
+		aux=vDatFileName;
+	}
+	currentDatFileName=strallocandcopy(aux);
+
+	/* Parse XML and export the file */
+	a=xmlParseFileForResource(vResFile,currentDatFileName,&r);
+	if (a==PR_RESULT_SUCCESS) {
+		/* exporting errors/no errors */
+		a=extract(currentDatFile,vDirName,&r,opt,currentDatFileName,datAuthor,backupExtension,format);
+	}
+	resourceListDrop(&r);
+	free(currentDatFileName);
+	free(currentDatFile);
+	freeItemMatchingList();
+
+	return a;
+}
+
+int prImportDat(const char* vDatFile, const char* vDirName, const char* vResFile) {
+	outputStream=stdout;
+	return prImportDatOpt(vDatFile,vDirName,vResFile,0,NULL,NULL);
+}
+
+int prImportDatOpt(const char* vDatFile, const char* vDirName, const char* vResFile,int opt,const char* vDatFileName, const char* backupExtension) {
+	/*
+	 * Arguments:
+	 * 	char* vDatFile        - full Path to the DAT file;
+	 * 	                        if file use it, if directory, perform it for
+	 * 	                        all files
+	 * 	char* vDirName        - full Path to the extracting folder
+	 * 	                        (doesn't need to exist)
+	 * 	char* vResFile        - full Path to the resources XML file
+	 * 	                        (resources.xml by default)
+	 * 	char opt              - program options, see below
+	 * 	char *vDatFileName    - name of the file to be extracted
+	 * 	                        NULL means predict it from vDatFile
+	 * 	const char* backupExtension
+	 * 	                      - If backup_flag is set, the string to attach
+	 * 	                        to the backup files
+	 *
+	 * Options:
+	 * 	raw_flag       - uses raw format
+	 * 	verbose_flag   - explain what is being done
+	 * 	recursive_flag - searches for all DAT files (only if vDatFile
+	 * 	                 is not a DAT file and vDatFileName is NULL)
+	 * 	force_flag     - If not set and the file exists it will prompt
+	 * 	                 for action
+	 * 	backup_flag    - backup your files
+	 *
+	 * Return values:
+	 * 	-1 DAT File couldn't be open for writing
+	 * 	-2 DAT file not found or invalid in partial importation
+	 * 	-3 XML Parse error
+	 * 	-4 No memory
+	 * 	-5 XML Attribute not recognized
+	 * 	-6 XML File not found
+	 * 	00 File successfully imported
+	 * 	positive number: number of missing files
+	 */
+
+	/* Declare variables */
+	tResourceList r;
+	int a;
+	const char* aux;
+	char* currentDatFileName;
+	char* currentDatFile;
+
+	r=resourceListCreate(0);
+
+	currentDatFile=strallocandcopy(vDatFile);
+
+	if (parseGivenPath(currentDatFile)) return PR_RESULT_ERR_COMMAND_LINE_SYNTAX;
+
+	if (vDatFileName==NULL) { /* if no special DAT file was specified, a path parsed will be used */
+		aux=getFileNameFromPath(currentDatFile);
+	} else {
+		aux=vDatFileName;
+	}
+	currentDatFileName=strallocandcopy(aux);
+
+	/* Parse XML and import files */
+	a=xmlParseFileForResource(vResFile,currentDatFileName,&r);
+	if (a==PR_RESULT_SUCCESS) {
+		/* importing errors/no errors */
+		a=compile (currentDatFile, vDirName,&r,opt,currentDatFileName,backupExtension);
+	}
+	resourceListDrop(&r);
+	free(currentDatFileName);
+	free(currentDatFile);
+	freeItemMatchingList();
+	return a;
+}
+
+/* When compiling in UNIX SO libraries */
+#ifndef WIN32
+void start() {}
+#endif
+#endif
diff --git a/PR/src/addons/cpp/xml.cpp b/PR/src/addons/cpp/xml.cpp
new file mode 100644
index 0000000..aa7c3c2
--- /dev/null
+++ b/PR/src/addons/cpp/xml.cpp
@@ -0,0 +1,62 @@
+/*  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
+*/
+
+/* Headers */
+#include "pr.h"
+#include "xml.h"
+
+Xml::Xml(const char* file) {
+	int error;
+	tTag* t=xmlParseFile(file,&error);
+
+	if (error) throw error;
+
+	this->structure=(void*)t;
+}
+
+void Xml::write(const char* file) { /* Bug: saving will destroy the tree */
+	tTag* tree=this->structure;
+	resourceTreeFixInheritances(&tree);
+	int r=xmlGenerateFile(file, tree);
+	if (r) throw r;
+}
+
+void Xml::optimize(TagReference t) {
+	tTag* tree=t;
+	if (tree) xmlOptimizeCommonFactor(tree->child);
+}
+
+void Xml::optimize() {
+	this->optimize(this->structure);
+}
+
+TagReference Xml::getRoot() {
+	return this->structure;
+}
+
+TagReference Xml::getChild(TagReference t) {
+	return resourceTreeGetChild((tTag*)t);
+}
+
+TagReference Xml::getNext(TagReference t) {
+	return resourceTreeGetNext((tTag*)t);
+}
+
+
diff --git a/PR/src/addons/cpp/xml.h b/PR/src/addons/cpp/xml.h
new file mode 100644
index 0000000..964f9f5
--- /dev/null
+++ b/PR/src/addons/cpp/xml.h
@@ -0,0 +1,36 @@
+#ifndef _XML_H_
+#define _XML_H_
+
+
+/* types */
+typedef void* TagReference;
+
+class Xml {
+	public:
+		Xml(const char* file);
+		~Xml();
+		void write(const char* file);
+
+		TagReference getRoot();
+		TagReference getChild(TagReference t);
+		TagReference getNext(TagReference t);
+
+		void optimize(TagReference t);
+		void optimize();
+		// POST: all TagReferences becomes invalid
+		
+
+
+		int getTag (TagReference t, char** tag, char** desc, char** path, char** file, char** type, char** name, char** palette, char** value, char** version, char** number,char** colors);
+		int setTag (TagReference t, const char* tag, const char* desc, const char* path, const char* file, const char* type, const char* name, const char* palette, const char* value, const char* version, const char* number,const char* colors);
+		
+		
+	private:
+		void* structure;
+
+
+
+};
+
+#endif
+
diff --git a/PR/src/include/compress.h b/PR/src/include/compress.h
index c8cace0..8ca70cf 100644
--- a/PR/src/include/compress.h
+++ b/PR/src/include/compress.h
@@ -73,6 +73,6 @@ int expandLzg(const unsigned char* input, int inputSize,
 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);
+               unsigned char* output, int *outputSize,int verif);
 
 #endif
diff --git a/PR/src/lib/compression/rlev_decompress.c b/PR/src/lib/compression/rlev_decompress.c
index 25c901a..27d8f11 100644
--- a/PR/src/lib/compression/rlev_decompress.c
+++ b/PR/src/lib/compression/rlev_decompress.c
@@ -39,7 +39,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) {
+               unsigned char* output, int *outputSize,int verif) {
 	register unsigned char rep=0;
 	int oCursor=0;
 	int iCursor=0;
@@ -48,24 +48,24 @@ int expandRleC(const unsigned char* input, int inputSize,
 	int lineSize;
 
 	/* reserve memory */
-	if ((*output=(unsigned char*)malloc(40000))==NULL) return COMPRESS_RESULT_FATAL;
+/*	if ((*output=(unsigned char*)malloc(40000))==NULL) return COMPRESS_RESULT_FATAL;*/
 
 	/* main loop */
 	while (iCursor<inputSize) {
 		rep=(input[iCursor++]);
 /*printf("o=%d i=%d\n",oCursor,iCursor);*/
-		if ((done)||(oCursor%verif)) {
+		if (1||(done)||(oCursor%verif)) {
 			done=0;
 			if (rep&0x80) { /* repeat */
 				/*rep&=~0x80;*/
 				rep-=0x80;
 				rep++;
-				while (rep--) (*output)[oCursor++]=input[iCursor];
+				while (rep--) (output)[oCursor++]=input[iCursor];
 				iCursor++;
 			} else { /* jump */
 				rep++;
 				while ((rep--)&&(iCursor<inputSize)) {
-					(*output)[oCursor++]=input[iCursor++];
+					(output)[oCursor++]=input[iCursor++];
 				}
 			}
 		} else {
@@ -92,6 +92,7 @@ int expandRleC(const unsigned char* input, int inputSize,
 	}
 /*printf("done=%d i=%d but=%d\n",done,iCursor,inputSize);*/
 	*outputSize=oCursor;
+	printf("rep=%d\n",rep);
 	return (rep==1)?COMPRESS_RESULT_SUCCESS:COMPRESS_RESULT_WARNING;
 }
 
diff --git a/PR/src/lib/object/image/image256.c b/PR/src/lib/object/image/image256.c
index bf04f04..67be9ed 100644
--- a/PR/src/lib/object/image/image256.c
+++ b/PR/src/lib/object/image/image256.c
@@ -200,18 +200,43 @@ int mCompressGraphic256(tBinary* input, tBinary* output, int ignoreFirstBytes, i
 int pop2decompress(const unsigned char* input, int inputSize, int verify, unsigned char** output,int* outputSize) { 
 	/* This function is in an experimental state and hasn't yet been linked to the program */
 	unsigned char* tempOutput;
+	unsigned char* lineI; /* chunk */
+	unsigned char* lineO; /* chunk */
+	int            lineSize;
+	int aux;
 
 	int tempOutputSize;
 	int osCheck;
 
+	*output=malloc(40000);
+	lineO=*output;
+	*outputSize=0;
+
 	osCheck=array2short(input)-6;
 	input+=2;
 
 	/*os=osCheck;*/
-	tempOutputSize=0;
+	/* First layer: expand the lgz */
+	/*tempOutputSize=0;*/
+	tempOutputSize=osCheck;
 	printf("lzg=%d is=%d osc=%d\n", expandLzg(input,inputSize-2,&tempOutput,&tempOutputSize),inputSize,osCheck);
 
-	printf("rle=%d\n", expandRleC(tempOutput,tempOutputSize,output,outputSize,verify));
+	/* Second layer expand each rle line */
+	lineI=tempOutput;
+	do {
+		aux=array2short(lineI);
+		lineI+=2;
+		printf("rle=%d\n", expandRleC(lineI,aux,lineO,&lineSize,1000));
+		printf("linesize=%d of %d. size=%d r=%d.\n",lineSize,verify,tempOutputSize,tempOutputSize-aux-2);
+		lineO+=lineSize;
+		outputSize+=lineSize;
+		tempOutputSize-=aux;
+		tempOutputSize-=2;
+		lineI+=aux;
+	} while (lineSize==verify && tempOutputSize>0);
+	
+
+/*	printf("rle=%d\n", expandRleC(tempOutput,tempOutputSize,output,outputSize,verify));*/
 /*
 	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];
diff --git a/PR/src/lib/object/palette/pop1_mono.c b/PR/src/lib/object/palette/pop1_mono.c
new file mode 100644
index 0000000..147222f
--- /dev/null
+++ b/PR/src/lib/object/palette/pop1_mono.c
@@ -0,0 +1,43 @@
+/*  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
+*/
+
+/*
+palette.c: Princed Resources : The palette object implementation
+\xaf\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.01 (2006-Feb-09)
+
+ Note:
+  DO NOT remove this copyright notice
+*/
+
+/***************************************************************\
+|                  I M P L E M E N T A T I O N                  |
+\***************************************************************/
+
+#include "pal.h"
+
+tColor* objPalette_pop1_monoGetColors(void* o) {
+	static tColor c[2]={{0,0,0},{255,255,255}};
+	return c;
+}