Пример #1
0
	/*
	* Class:     aflobby_CUnitSyncJNIBindings
	* Method:    WriteMiniMap
	* Signature: (II)I
	*/
	JNIEXPORT jboolean JNICALL Java_aflobby_CUnitSyncJNIBindings_WriteMiniMap
		(JNIEnv *env, jclass myobject, jstring mapfile, jstring imagename, jint miplevel){
			const char *filename = env->GetStringUTFChars(mapfile, 0);
			const char *bitmap_filename = env->GetStringUTFChars(imagename, 0);
			void* minimap = GetMinimap(filename, miplevel);
			if (!minimap){
				env->ReleaseStringUTFChars(mapfile, filename);
				env->ReleaseStringUTFChars(mapfile, bitmap_filename);
				return false;
			}
			int size = 1024 >> miplevel;
			CBitmap bm;
			bm.Alloc(size, size);
			unsigned short *src = (unsigned short*)minimap;
			unsigned char *dst = bm.mem;
			for (int y = 0; y < size; y++) {
				for (int x = 0; x < size; x++){
					dst[0] = RED_RGB565   ((*src)) << 3;
					dst[1] = GREEN_RGB565 ((*src)) << 2;
					dst[2] = BLUE_RGB565  ((*src)) << 3;
					dst[3] = 255;
					++src;
					dst += 4;
				}
			}
			remove(bitmap_filename); //somehow overwriting doesn't work??
			bm.Save(bitmap_filename);
			// check whether the bm.Save succeeded?
			
			
			FILE* f = fopen(bitmap_filename, "rb");
			bool success = !!f;
			if (success) {
				fclose(f);
			}
			env->ReleaseStringUTFChars(mapfile, filename);
			env->ReleaseStringUTFChars(mapfile, bitmap_filename);
			return success;
		}
Пример #2
0
void CBitmap::CreateFromDXT1(unsigned char* buf, int xsize, int ysize)
{
	delete[] mem;

	mem=new unsigned char[xsize*ysize*4];
	memset(mem,0,xsize*ysize*4);

	this->xsize=xsize;
	this->ysize=ysize;

	int numblocks = ((xsize+3)/4)*((ysize+3)/4);

	unsigned char* temp = buf;

	for ( int i = 0; i < numblocks; i++ ){

		unsigned short color0 = (*(unsigned short*)&temp[0]);
		unsigned short color1 = (*(unsigned short*)&temp[2]);

		int r0=RED_RGB565(color0)<<3;
		int g0=GREEN_RGB565(color0)<<2;
		int b0=BLUE_RGB565(color0)<<3;

		int r1=RED_RGB565(color1)<<3;
		int g1=GREEN_RGB565(color1)<<2;
		int b1=BLUE_RGB565(color1)<<3;

		unsigned int bits = (*(unsigned int*)&temp[4]);
		
		for ( int a = 0; a < 4; a++ )
		{
			for ( int b = 0; b < 4; b++ )
			{
				int x = 4*(i % ((xsize+3)/4))+b;
				int y = 4*(i / ((xsize+3)/4))+a;
				bits >>= 2;
				unsigned char code = bits & 0x3;
				
				if ( color0 > color1 )
				{
					if ( code == 0 )
					{
						mem[(y*xsize+x)*4+0]=r0;
						mem[(y*xsize+x)*4+1]=g0;
						mem[(y*xsize+x)*4+2]=b0;
					}
					else if ( code == 1 )
					{
						mem[(y*xsize+x)*4+0]=r1;
						mem[(y*xsize+x)*4+1]=g1;
						mem[(y*xsize+x)*4+2]=b1;
					}
					else if ( code == 2 )
					{
						mem[(y*xsize+x)*4+0]=(r0*2+r1)/3;
						mem[(y*xsize+x)*4+1]=(g0*2+g1)/3;
						mem[(y*xsize+x)*4+2]=(b0*2+b1)/3;
					}
					else
					{	
						mem[(y*xsize+x)*4+0]=(r0+r1*2)/3;
						mem[(y*xsize+x)*4+1]=(g0+g1*2)/3;
						mem[(y*xsize+x)*4+2]=(b0+b1*2)/3;
					}
				}
				else
				{
					if ( code == 0 )
					{
						mem[(y*xsize+x)*4+0]=r0;
						mem[(y*xsize+x)*4+1]=g0;
						mem[(y*xsize+x)*4+2]=b0;
					}
					else if ( code == 1 )
					{
						mem[(y*xsize+x)*4+0]=r1;
						mem[(y*xsize+x)*4+1]=g1;
						mem[(y*xsize+x)*4+2]=b1;
					}
					else if ( code == 2 )
					{
						mem[(y*xsize+x)*4+0]=(r0+r1)/2;
						mem[(y*xsize+x)*4+1]=(g0+g1)/2;
						mem[(y*xsize+x)*4+2]=(b0+b1)/2;
					}
					else
					{	
						mem[(y*xsize+x)*4+0]=0;
						mem[(y*xsize+x)*4+1]=0;
						mem[(y*xsize+x)*4+2]=0;
					}
				}
			}
		}
		temp += 8;
	}
}