git » fp-git.git » commit 316cc6e

o Files moved

author ecalot
2003-11-04 01:03:19 UTC
committer ecalot
2003-11-04 01:03:19 UTC
parent 9de24430e63b5bce6beeb96c293a8fd29b09f990

o Files moved
o Improved directory checks before saving (unix and dos directory types)
o If directory doesn't exist it is created

PR/src/lib/formats/Attic/bmp.c +206 -0
PR/src/lib/formats/Attic/mid.c +56 -0
PR/src/lib/formats/Attic/pal.c +117 -0
PR/src/lib/formats/Attic/wav.c +73 -0

diff --git a/PR/src/lib/formats/Attic/bmp.c b/PR/src/lib/formats/Attic/bmp.c
new file mode 100644
index 0000000..4f37052
--- /dev/null
+++ b/PR/src/lib/formats/Attic/bmp.c
@@ -0,0 +1,206 @@
+/*  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>
+#include <string.h>
+#include "bmp.h"
+#include "disk.h"
+#include "memory.h"
+#include "compile.h"
+
+char mFormatExtractBmp(unsigned char* data, char *vFileext,unsigned long int size,tImage image) {
+	if ((mExpandGraphic(data,&image,size))>0) {
+		//Create base dir
+		repairFolders(vFileext);
+		makebase(vFileext);
+		//Write bitmap
+		mWriteBitMap(image,vFileext);
+		//free bitmap
+		free(image.pix);
+		return 1;
+	} else {
+		return 0;
+	}
+}
+
+
+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;
+	mCompressGraphic(aux,&img,&size);
+	free(img.pix);
+
+	mAddFileToDatFile(fp,aux,size);
+	(*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;
+}
+
+char mWriteBitMap(tImage img,char* vFile) {
+
+	//declare variables
+	unsigned char i=0;
+	unsigned char j=0;
+	char b;
+	char c;
+	char a;
+	FILE* bitmap;
+	unsigned long int filesize;
+	unsigned long int width;
+	unsigned long int height;
+	char junk[3]={0,0,0};
+
+	unsigned char header[]={
+		'B','M',
+		0x22,0x22,0x22,0x22,
+		0,0,0,0,
+		0x76,0,0,0,
+
+		40,0,0,0,
+		0x22,0x22,0,0,
+		0x22,0x22,0,0,
+		1,0,
+		4,0,
+		0,0,0,0,
+		0,0,0,0,
+		0xE8,0x03,0,0,
+		0xE8,0x03,0,0,
+		0x10,0,0,0,
+		0,0,0,0,
+
+		0x22,0x22,0x22,0,
+		0x22,0x22,0x22,0,
+		0x22,0x22,0x22,0,
+		0x22,0x22,0x22,0,
+		0x22,0x22,0x22,0,
+		0x22,0x22,0x22,0,
+		0x22,0x22,0x22,0,
+		0x22,0x22,0x22,0,
+		0x22,0x22,0x22,0,
+		0x22,0x22,0x22,0,
+		0x22,0x22,0x22,0,
+		0x22,0x22,0x22,0,
+		0x22,0x22,0x22,0,
+		0x22,0x22,0x22,0,
+		0x22,0x22,0x22,0,
+		0x22,0x22,0x22,0
+	};
+
+
+	if ((bitmap = fopen (vFile,"wb"))==NULL) return 0;
+
+	filesize=((img.size+1)/2+118);
+	width=img.width;
+	height=img.height;
+
+
+	//TODO: avoid using header array andwrite everithing in one run
+
+	header[2]=(unsigned char)(filesize);
+	header[3]=(unsigned char)(filesize>>8);
+	header[4]=(unsigned char)(filesize>>16);
+	header[5]=(unsigned char)(filesize>>24);
+
+	header[18]=(unsigned char)(width);
+	header[19]=(unsigned char)(width>>8);
+
+	header[22]=(unsigned char)(height);
+	header[23]=(unsigned char)(height>>8);
+
+	//BEGIN of format writing
+	//Write ColorTable
+	for (a=0;a<16;a++) {
+		b=a*3;
+		c=a<<2;
+		header[54+c]=(img.pal[b+2])*4;  //Red
+		header[55+c]=(img.pal[b+1])*4;  //Green
+		header[56+c]=(img.pal[b])*4;    //Blue
+	}
+	//Write header
+	fwrite(header,118,1,bitmap);
+	//Write data
+	img.width=(img.width+1)>>1;
+	while (img.height--) {
+		fwrite(img.pix+img.height*img.width,img.width,1,bitmap);
+		fwrite(junk,(-img.width)&3,1,bitmap);
+	}
+	//END of format writing
+
+	fclose(bitmap);
+	return 1;
+}
+
+
+char mReadBitMap(tImage* img,char* data, int size) {
+	char ok;
+	unsigned short int width;
+	unsigned short int height;
+	int width2;
+	int x=0;
+
+	//Validate if there is header and if it starts in BM
+	ok    = size>118;
+	ok=ok&& data[0]=='B' && data[1]=='M';
+
+	//Read sizes from header
+	width=data[18]+(data[19]<<8);
+	height=data[22]+(data[23]<<8);
+
+	//Save sizes into image
+	(*img).width=width;            //width in pixels
+	(*img).height=height;
+	(*img).size=height*width;      //total of pixels
+
+	//Calculate serialized widths
+	width=(width+1)>>1;            //raw serialized width
+	width2=width+((-width)&3);     //bmp serialized width
+
+	//Validate image and file size; get memory to allocate the image
+	ok=ok&& ( ((*img).height*width2)                == (size-118));
+	ok=ok&& (	((*img).pix=getMemory((*img).size/2)) != NULL	);
+
+	//if validations==wrong
+	if (!ok) {
+		if ((*img).pix!=NULL) free((*img).pix);
+		return 0; //this is not a valid bmp file format or memory too low
+	}
+
+	//Serialize bitmap-->raw array
+	while (height--) memcpy((*img).pix+(x++)*width,data+118+height*width2,width);
+
+	return 1;
+}
diff --git a/PR/src/lib/formats/Attic/mid.c b/PR/src/lib/formats/Attic/mid.c
new file mode 100644
index 0000000..abb59a2
--- /dev/null
+++ b/PR/src/lib/formats/Attic/mid.c
@@ -0,0 +1,56 @@
+/*  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
+*/
+
+/*
+mid.c: Princed Resources : MIDI 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 "mid.h"
+#include "disk.h"
+#include "compile.h"
+#include "memory.h"
+#include <string.h>
+
+char mFormatExtractMid(unsigned char* data, char *vFileext,unsigned long int size) {
+	//Mid files are saved as raw except you must ignore checksum & sound type
+	return writeData(data,2,vFileext,size);
+}
+
+char mFormatCompileMid(unsigned char* data, FILE* fp, tResource *res) {
+	unsigned char* file;
+
+	file=getMemory((*res).size);
+	file[0]=(*res).type-2; //Now should be 0x02 //First character must be a 0x01 (wav type in dat)
+	memcpy(file+1,data,(*res).size);
+	(*res).size++;
+	mAddFileToDatFile(fp,file,(*res).size);
+	free(file);
+	return 1;
+}
diff --git a/PR/src/lib/formats/Attic/pal.c b/PR/src/lib/formats/Attic/pal.c
new file mode 100644
index 0000000..2d6fbfa
--- /dev/null
+++ b/PR/src/lib/formats/Attic/pal.c
@@ -0,0 +1,117 @@
+/*  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>
+#include "pal.h"
+#include "memory.h"
+#include "disk.h"
+#include "parser.h"
+#include "resources.h"
+
+/***************************************************************\
+|                 Jasc Palette handling functions               |
+\***************************************************************/
+
+char mFormatExtractPal(unsigned char** data, char *vFileext,unsigned long int size) {
+	//Convert palette from POP format to JASC format
+	mExportPalette(data,&size);
+	//save JASC palette
+	return writeData(*data,0,vFileext,size);
+}
+
+char mImportPalette(unsigned char** data, unsigned short *size) {
+
+	//declare variables
+	unsigned char palh[]=PAL_HEADER;
+	unsigned char pals[]=PAL_SAMPLE;
+	unsigned char* pal;
+	unsigned short int parsed;
+	int i=0;
+	int k=0;
+
+	//check size
+	if (*size<130) return 0;
+
+	pal=getMemory(100);
+
+	//set palette with sample
+	memcpy(pal,pals,100);
+
+	//verify jasc pal header
+	while (palh[i]==(*data)[i++]);
+	if (i!=sizeof(palh)) return 0;
+
+	//set current values
+	for (;k<16;k++) {
+		getNumberToken((*data),&parsed,' ',&i,4);
+		pal[(k*3)+4]=(parsed+2)>>2;
+		getNumberToken((*data),&parsed,' ',&i,4);
+		pal[(k*3)+5]=(parsed+2)>>2;
+		getNumberToken((*data),&parsed,'\r',&i,4);
+		pal[(k*3)+6]=(parsed+2)>>2;
+		i++; //Jump \n
+	}
+
+	//free old data and set new
+	free(*data);
+	*data=pal;
+	*size=100;
+	return 1;
+}
+
+void mExportPalette(unsigned char** data, unsigned long int *size) {
+	unsigned char* pal=getMemory(240);
+	unsigned char* aux=getMemory(240);
+	unsigned char i;
+
+	sprintf(pal,PAL_HEADER);
+
+	for (i=0;i<16;i++) {
+		sprintf(aux,pal);
+		sprintf(pal,"%s%d %d %d\r\n",aux,(*data)[(i*3)+5]<<2,(*data)[(i*3)+6]<<2,(*data)[(i*3)+7]<<2);
+	}
+	for (i=0;pal[i];i++);
+	free(*data);
+	free(aux);
+	(*data)=pal;
+	*size=i-1;
+}
+
+void mLoadPalette(char* array,tImage *image) {
+	int k=0;
+	int 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
new file mode 100644
index 0000000..41d3c3c
--- /dev/null
+++ b/PR/src/lib/formats/Attic/wav.c
@@ -0,0 +1,73 @@
+/*  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) {
+	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));
+
+	return ok;
+}
+
+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; //First character must be a 0x01 (wav type in dat)
+	if (i==-1) mAddFileToDatFile(fp,data+sizeof(wav)-1,(*res).size);
+	return 1;
+}