Пример #1
0
int CTileHandler::FindCloseTile(CBitmap* bm,int forbidden)
{
	FastStat fs=CalcFastStat(bm);
	for(int a=0;a<usedTiles;++a){
		if(a!=forbidden &&
			abs(fs.r-fastStats[a].r)<meanThreshold && abs(fs.g-fastStats[a].g)<meanThreshold && abs(fs.b-fastStats[a].b)<meanThreshold
		&& abs(fs.rx-fastStats[a].rx)<meanDirThreshold && abs(fs.gx-fastStats[a].gx)<meanDirThreshold && abs(fs.bx-fastStats[a].bx)<meanDirThreshold
		&& abs(fs.ry-fastStats[a].ry)<meanDirThreshold && abs(fs.gy-fastStats[a].gy)<meanDirThreshold && abs(fs.by-fastStats[a].by)<meanDirThreshold
		&& CompareTiles(bm,tiles[a]))
			return a;
	}
	fastStats[usedTiles]=fs;
	return -1;
}
Пример #2
0
void CTileHandler::ProcessTiles(float compressFactor,bool fastcompress)
{
	meanThreshold=(int)(2000*compressFactor);
	meanDirThreshold=(int)(20000*compressFactor);
	borderThreshold=(int)(80000*compressFactor);

	system("mkdir temp");

	usedTiles=0;
	unsigned char buf[SMALL_TILE_SIZE];

	for(vector<string>::iterator fi=externalFiles.begin();fi!=externalFiles.end();++fi){
		ifstream ifs(fi->c_str(),ios::in | ios::binary);
		if(!ifs.is_open()){
			printf("Couldnt find tile file %s\n",fi->c_str());
			continue;
		}
		TileFileHeader tfh;
		ifs.read((char*)&tfh,sizeof(TileFileHeader));

		if(strcmp(tfh.magic,"spring tilefile")!=0 || tfh.version!=1 || tfh.tileSize!=32){
			printf("Error opening tile file %s\n",fi->c_str());
			continue;
		}
		externalFileTileSize.push_back(tfh.numTiles);

		printf("Loading %i tiles from %s\n",tfh.numTiles,fi->c_str());
		for(int a=0;a<tfh.numTiles;++a){
			ifs.read((char*)buf,SMALL_TILE_SIZE);
			CBitmap* bm=new CBitmap();
			bm->CreateFromDXT1(buf,32,32);

			fastStats[usedTiles]=CalcFastStat(bm);
			tiles[usedTiles++]=bm;
		}
	}

	numExternalTile=usedTiles;

	unsigned char* data=new unsigned char[1024*1024*4];
	int tilex=xsize/4;
	int tiley=ysize/4;
	int bigsquaretexx=tilex/32;
	int bigsquaretexy=tiley/32;
	int a=0;
	for(int j=0;j<bigsquaretexy;j++){
		for(int i=0;i<bigsquaretexx;i++){
			int ox=1024*i;
			int oy=1024*j;
			

			for(int y2=0;y2<1024;++y2){
				for(int x2=0;x2<1024;++x2){
					data[(y2*1024 +x2)*4 +0]=bigTex.mem[(ox +(oy+y2)*xsize*8 +x2)*4 +0];
					data[(y2*1024 +x2)*4 +1]=bigTex.mem[(ox +(oy+y2)*xsize*8 +x2)*4 +1];
					data[(y2*1024 +x2)*4 +2]=bigTex.mem[(ox +(oy+y2)*xsize*8 +x2)*4 +2];
					data[(y2*1024 +x2)*4 +3]=bigTex.mem[(ox +(oy+y2)*xsize*8 +x2)*4 +3];
				}
			}

			CBitmap square(data,1024,1024);
			char name[100];
			sprintf(name,"temp/Temp%03i.tga",a);
			square.Save(name);
			printf("Writing tga files %i%%\n", (((a+1)*1024)*100)/(tilex*tiley));
			a++;
		}
	}
	int numbigsquares=(xsize/128)*(ysize/128);
	printf("Creating dds files\n");
	char execstring[512];
	if (fastcompress){
		for (int i=0;i<numbigsquares;i++){
			sprintf(execstring, "nvcompress.exe -fast -bc1a temp/Temp%03i.tga Temp%03i.dds",i,i);
			printf("%s\n", execstring);
			system(execstring);
		}
	
	}else{
		sprintf(execstring, "%s temp/Temp*.tga",stupidGlobalCompressorName.c_str());
		printf("%s\n", execstring);
		system(execstring);
	}
#ifdef WIN32
	system("del /Q temp\\Temp*.tga");
	system("del /Q temp");
#else	
	system("rm temp/Temp*.tga");
#endif

	delete[] data;
}
Пример #3
0
void CTileHandler::ProcessTiles(float compressFactor)
{
	meanThreshold=(int)(2000*compressFactor);
	meanDirThreshold=(int)(20000*compressFactor);
	borderThreshold=(int)(80000*compressFactor);

	system("mkdir temp");

	usedTiles=0;
	unsigned char buf[SMALL_TILE_SIZE];

	for(vector<string>::iterator fi=externalFiles.begin();fi!=externalFiles.end();++fi){
		ifstream ifs(fi->c_str(),ios::in | ios::binary);
		if(!ifs.is_open()){
			printf("Couldnt find tile file %s\n",fi->c_str());
			continue;
		}
		TileFileHeader tfh;
		ifs.read((char*)&tfh,sizeof(TileFileHeader));

		if(strcmp(tfh.magic,"spring tilefile")!=0 || tfh.version!=1 || tfh.tileSize!=32){
			printf("Error opening tile file %s\n",fi->c_str());
			continue;
		}
		externalFileTileSize.push_back(tfh.numTiles);

		printf("Loading %i tiles from %s\n",tfh.numTiles,fi->c_str());
		for(int a=0;a<tfh.numTiles;++a){
			ifs.read((char*)buf,SMALL_TILE_SIZE);
			CBitmap* bm=new CBitmap();
			bm->CreateFromDXT1(buf,32,32);
			
/*			char t[200];
			sprintf(t,"test%i.jpg",a);
			bm->Save(t);
*/
			fastStats[usedTiles]=CalcFastStat(bm);
			tiles[usedTiles++]=bm;
		}
	}

	numExternalTile=usedTiles;

	char execstring[512];
	sprintf(execstring, "nvdxt.exe -file temp\\*.bmp -dxt1c -dither");

	unsigned char* data=new unsigned char[1024*1024*4];
	int tilex=xsize/4;
	int tiley=ysize/4;

	for(int a=0;a<(tilex*tiley)/1024;++a){
		int startTile=a*1024;
		for(int b=0;b<1024;++b){
			int x=b%32;
			int y=b/32;
			int xb=(startTile+b)%tilex;
			int yb=(startTile+b)/tilex;
			for(int y2=0;y2<32;++y2){
				for(int x2=0;x2<32;++x2){
					data[((y*32+y2)*1024+x*32+x2)*4+0]=bigTex.mem[((yb*32+y2)*bigTex.xsize+xb*32+x2)*4+0];
					data[((y*32+y2)*1024+x*32+x2)*4+1]=bigTex.mem[((yb*32+y2)*bigTex.xsize+xb*32+x2)*4+1];
					data[((y*32+y2)*1024+x*32+x2)*4+2]=bigTex.mem[((yb*32+y2)*bigTex.xsize+xb*32+x2)*4+2];
					data[((y*32+y2)*1024+x*32+x2)*4+3]=bigTex.mem[((yb*32+y2)*bigTex.xsize+xb*32+x2)*4+3];
				}
			}
		}
		CBitmap square(data,1024,1024);
		char name[100];
		sprintf(name,"temp\\Temp%03i.bmp",a);
		square.Save(name);
		printf("Writing bmp files %i%%\n", (((a+1)*1024)*100)/(tilex*tiley));
	}

	printf("Creating dds files\n");
	system(execstring);
	system("del temp\\temp*.bmp");

	delete[] data;

/*
	for(int y=0; y<tilex; y++){
		for(int x=0; x<tiley; x++){
			CBitmap* bm=new CBitmap();
			bm->CreateFromDXT1(buf,32,32);
			int t1=tileUse[max(0,(y-1)*xsize/4+x)];
			int t2=tileUse[max(0,y*xsize/4+x-1)];
			int ct=FindCloseTile(bm,t1==t2?t1:-1);
			if(ct==-1){
				tileUse[y*xsize/4+x]=usedTiles;
				tiles[usedTiles++]=bm;
			} else {
				if(ct<numExternalTile)
					printf("used external tile");
				tileUse[y*xsize/4+x]=ct;
				delete bm;
			}
		}
		printf("Creating tiles %i/%i %i%%\n", usedTiles-numExternalTile,y*xsize/4+x,((y*xsize/4+x)*100)/(xsize/4*ysize/4));
	}
*/
}