Jump to content

Alguem pode explicar 1 c贸digo po complicado? :P


Gooden

Recommended Posts

BOm eu tou a tentar fazer 1 coisita em vb.net que le um ficheiro spr. arranjei 1 codigo para descompactar mas isto em c++ n茫o entendo. :S

se algum me poder explicar o codigo agradecia. 馃檪

aqui vai ele

unsigned char* Sprites::UnpackSprite(int which)
{
聽 unsigned char* OutputData;
聽 if (which == 0)
聽 {
聽 聽 OutputData = new unsigned char[32*32*4];
memset(OutputData, 0, 32*32*4);
return OutputData;
聽 }
聽 std::map<unsigned short, Sprite*>::iterator it = SpriteCollection.find(which);
聽 if ((it != SpriteCollection.end()) && (it->second != NULL))
聽 {
聽 聽  unsigned char r, g ,b;
聽 聽  int pos = 0;
聽 聽  int pix = 0;
聽 聽  OutputData = new unsigned char[it->second->width*it->second->height*4];
 memset(OutputData, 0xFF, it->second->width*it->second->height*4);
 while(true)
 {
聽  if(pix >= it->second->width*it->second->height)
聽 聽  break;

	r = it->second->data[pos];
	g = it->second->data[pos+1];
	b = it->second->data[pos+2];
	pos += 3;
	if(r == 0xFE) r++;
	if(g == 0xFE) g++;
	if(b == 0xFE) b++;
	OutputData[pix*4] = r;
	OutputData[pix*4+1] = g;
	OutputData[pix*4+2] = b;
	if((r == 0xFF) && (g == 0x00) && (b == 0xFF))
	{
		OutputData[pix*4] = 0;
聽 聽 聽 聽 聽 聽 OutputData[pix*4+2] = 0;
		OutputData[pix*4+3] = 0;
	}
	pix++;

	if(it->second->data[pos] == 0xFF)
	{
聽 聽 聽 聽 聽 for(unsigned char sp = 0; sp < it->second->data[pos+1]; sp++)
	聽 {
聽 聽 聽 聽 if(pix >= it->second->width*it->second->height)
聽 聽 聽 聽 聽 break;
	聽 聽 OutputData[pix*4] = r;
		OutputData[pix*4+1] = g;
		OutputData[pix*4+2] = b;
		if((r == 0xFF) && (g == 0x00) && (b == 0xFF))
		{
			OutputData[pix*4] = 0;
			OutputData[pix*4+2] = 0;
			OutputData[pix*4+3] = 0;
	聽 聽 }
		pix++;
	聽 }
聽 聽 聽 聽 聽 pos += 2;
	}
 }
 return OutputData;
聽 聽 }
聽 return NULL;
}
Link to comment
Share on other sites

脡 um pouco dificil de perceber o c贸digo sem conhecer o formato da imagem. Tu conheces?

Pelo que vejo, para cada pixel da imagem, o ficheiro tem os valores rgb (red,green,blue) da cor do pixel e valor de intensidade da cor.

Agora os "porqu锚s" de ele comparar com intensidades 255 (0xFF) ou 0, s贸 vendo o tal formato de codifica莽茫o da imagem...

"What we do for ourselves dies with us. What we do for others and the world, remains and is immortal.", Albert Pine

Blog pessoal : cont茅m alguns puzzles, algoritmos e problemas para se resolver com programa莽茫o.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.