Пример #1
0
	bool Image::LoadTGA_RW(SDL_RWops *src)
	{
		SDL_Surface *temp = IMG_LoadTGA_RW(src);

		if(temp == NULL)
			return false;
		else
			m_Surface = temp;

		return true;
	}
Пример #2
0
SDL_Surface * BitmapHandler::loadBitmapFromLod(CLodHandler *lod, std::string fname, bool setKey)
{
	if(!fname.size())
	{
		tlog2 << "Call to loadBitmap with void fname!\n";
		return NULL;
	}
	if (!lod->haveFile(fname, FILE_GRAPHICS))
	{
		tlog2<<"Entry for file "<<fname<<" was not found"<<std::endl;
		return NULL;
	}

	SDL_Surface * ret=NULL;
	int size;
	unsigned char * file = 0;
	file = lod->giveFile(fname, FILE_GRAPHICS, &size);
	
	if (isPCX(file))
	{//H3-style PCX
		CPCXConv cp;
		cp.openPCX((char*)file,size);
		ret = cp.getSurface();
		if (!ret)
			tlog1<<"Failed to open "<<fname<<" as H3 PCX!\n";
		if(ret->format->BytesPerPixel == 1  &&  setKey)
		{
			const SDL_Color &c = ret->format->palette->colors[0];
			SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format, c.r, c.g, c.b));
		}
	}
	else
	{ //loading via SDL_Image
		std::string filename = lod->getFileName(fname, FILE_GRAPHICS);
		std::string ext;
		lod->convertName(filename, &ext);

		if (ext == ".TGA")//Special case - targa can't be loaded by IMG_Load_RW (no magic constants in header)
		{
			SDL_RWops *rw = SDL_RWFromMem((void*)file, size);
			ret = IMG_LoadTGA_RW( rw );
			SDL_FreeRW(rw);
		}
		else
			ret = IMG_Load_RW( SDL_RWFromMem((void*)file, size), 1);

		if (!ret)
			tlog1<<"Failed to open "<<fname<<" via SDL_Image\n";
		delete [] file;
	}
	return ret;
}