Example #1
0
//Load - load a texture from a file
bool IMAGE::Load(char * filename)
{
	//Clear the data if already used
	if(data)
		delete [] data;
	data=NULL;
	bpp=0;
	width=0;
	height=0;
	format=0;

	int filenameLength=strlen(filename);

	if(	strncmp((filename+filenameLength-3), "BMP", 3)==0 ||
		strncmp((filename+filenameLength-3), "bmp", 3)==0)
		return LoadBMP(filename);
	
	if(	strncmp((filename+filenameLength-3), "PCX", 3)==0 ||
		strncmp((filename+filenameLength-3), "pcx", 3)==0)
		return LoadPCX(filename);
	
	if(	strncmp((filename+filenameLength-3), "TGA", 3)==0 ||
		strncmp((filename+filenameLength-3), "tga", 3)==0)
		return LoadTGA(filename);

	errorLog.OutputError("%s does not end in \".tga\", \".bmp\" or \"pcx\"", filename);
	return false;
}
Example #2
0
//-------------------------------------------------------------
//- Load
//- Loads an image of any supported image type
//-------------------------------------------------------------
bool CImage::Load(char * szFilename, bool bMipMap)
{
    m_bMipMap = bMipMap;
    m_szFilename = szFilename;
    FILE * f;

    if(!(f = fopen(szFilename, "rb")))
    {
        APP->Log(COLOR_RED, "Could not open %s", szFilename);
        return false;
    }

    fseek(f, 0, SEEK_END);
    int iEnd = ftell(f);
    fseek(f, 0, SEEK_SET);
    int iStart = ftell(f);
    m_uiFileLen = iEnd - iStart;

    m_ucpBuffer = new unsigned char[m_uiFileLen];

    if(!m_ucpBuffer)
    {
        APP->Log(COLOR_RED, "Could not alloc memory for %s", szFilename);
        return false;
    }

    //get data
    if(fread(m_ucpBuffer, 1, m_uiFileLen, f) != m_uiFileLen)
    {
        APP->Log(COLOR_RED, "Could not read from %s", szFilename);
        if(m_ucpBuffer)
            delete [] m_ucpBuffer;
        return false;
    }

    //Check for a valid filetype
    //Windows Bitmap
    if(memcmp(m_ucpBuffer, BMP_HEADER, 2) == 0)
    {
        return LoadBMP();
    }
    //Uncompressed TGA
    if(memcmp(m_ucpBuffer, TGA_UHEADER, 12) == 0)
    {
        return LoadTGA(false);
    }
    //Compressed TGA
    if(memcmp(m_ucpBuffer, TGA_CHEADER, 12) == 0)
    {
        return LoadTGA(true);
    }
    //PCX
    if(m_ucpBuffer[0] == 10)
    {
        return LoadPCX();
    }
    APP->Log(COLOR_RED, "Could not load %s, Invalid filetype", szFilename);
    return false;
}
Example #3
0
/*
===============
R_FindImage

Finds or loads the given image
===============
*/
image_t	*R_FindImage (char *name, imagetype_t type)
{
	image_t	*image;
	int		i, len;
	byte	*pic, *palette;
	int		width, height;
	char *ptr;
	
	if (!name)
		return NULL;	// ri.Sys_Error (ERR_DROP, "R_FindImage: NULL name");
	len = strlen(name);
	if (len<5)
		return NULL;	// ri.Sys_Error (ERR_DROP, "R_FindImage: bad name: %s", name);
	
#ifndef _WIN32
	// fix backslashes
	while ((ptr=strchr(name,'\\'))) {
	  *ptr = '/';
	}
#endif

	// look for it
	for (i=0, image=r_images ; i<numr_images ; i++,image++)
	{
		if (!strcmp(name, image->name))
		{
			image->registration_sequence = registration_sequence;
			return image;
		}
	}

	//
	// load the pic from disk
	//
	pic = NULL;
	palette = NULL;
	if (!strcmp(name+len-4, ".pcx"))
	{
		LoadPCX (name, &pic, &palette, &width, &height);
		if (!pic)
			return NULL;	// ri.Sys_Error (ERR_DROP, "R_FindImage: can't load %s", name);
		image = GL_LoadPic (name, pic, width, height, type);
	}
	else if (!strcmp(name+len-4, ".wal"))
	{
		image = R_LoadWal (name);
	}
	else if (!strcmp(name+len-4, ".tga"))
		return NULL;	// ri.Sys_Error (ERR_DROP, "R_FindImage: can't load %s in software renderer", name);
	else
		return NULL;	// ri.Sys_Error (ERR_DROP, "R_FindImage: bad extension on: %s", name);

	if (pic)
		free(pic);
	if (palette)
		free(palette);

	return image;
}
Example #4
0
/*
==========
Skin_Cache

Returns a pointer to the skin bitmap, or NULL to use the default
==========
*/
byte *
Skin_Cache ( skin_t *skin )
{
	char	name[1024];
//	byte	*raw;
	byte	*out;//, *pix;
//	pcx_t	*pcx;
//	int		x, y;
//	int		dataByte;
//	int		runLength;

	if (cls.downloadtype == dl_skin)
		return NULL;		// use base until downloaded

	if (noskins->value==1)	// JACK: So NOSKINS > 1 will show skins, but
		return NULL;		// not download new ones.

	if (skin->failedload)
		return NULL;

	out = Cache_Check (&skin->cache);
	if (out)
		return out;

//
// load the pic from disk
//

	snprintf(name, sizeof(name), "skins/%s.pcx", skin->name);
	out = LoadPCX (name, &skin->cache, 320, 200);
	if (out == NULL) {
		Con_Printf ("Couldn't load skin %s\n", name);
		snprintf(name, sizeof(name), "skins/%s.pcx", baseskin->string);
		out = LoadPCX (name, &skin->cache, 320, 200);
		if (out == NULL) {
			skin->failedload = true;
			return NULL;
		}
	}

	skin->failedload = false;
	return out;
}
Example #5
0
void CBitmap::Load(string filename)
{
	if(mem!=0)
		delete[] mem;

	if(filename.find(".jpg")!=string::npos)
		LoadJPG(filename);
	else if(filename.find(".pcx")!=string::npos)
		LoadPCX(filename);
	else
		LoadBMP(filename);
}
Example #6
0
void CGraphicsBuffer::Load(std::string aFilename, CPalette* aPalette)
{
 	ASSERT(aFilename.length()>0);

	// Translate the filename to have DATADIR before
	// calling any of the real loading functions.
	aFilename = getdatapath(aFilename);

	const char* ext = aFilename.c_str() + aFilename.find_last_of('.');

	if (strcasestr(ext,".efp2"))
	{
		LoadEFP2(aFilename,aPalette);
		return;
	}

	if (strcasestr(ext,".efp"))
	{
		LoadEFP(aFilename,aPalette);
		return;
	}

	if (strcasestr(ext,".sci"))
	{
		LoadSCI(aFilename,aPalette);
		return;
	}
	
	if (strcasestr(ext,".pcx"))
	{
		LoadPCX(aFilename,aPalette);
		return;
	}

	SDL_Surface* surf = IMG_Load(aFilename.c_str());

	if ( surf )
	{
		if (CopyFromSurface(surf ,aPalette)==0)
		{
			SDL_FreeSurface( surf );
			return;
		}
                else
                        error("CGraphicsBuffer::Load: Only 8-bit surfaces allowed (%s)!",aFilename.c_str());
	}
	
	error("CGraphicsBuffer::Load: File format not detected (%s)!",aFilename.c_str());
}
Example #7
0
/*
==============
Load256Image

Will load either an lbm or pcx, depending on extension.
Any of the return pointers can be NULL if you don't want them.
==============
*/
void Load256Image(const char *name, byte ** pixels, byte ** palette, int *width, int *height)
{
	char            ext[128];

	ExtractFileExtension(name, ext);
	if(!Q_stricmp(ext, "lbm"))
	{
		LoadLBM(name, pixels, palette);
		if(width)
			*width = bmhd.w;
		if(height)
			*height = bmhd.h;
	}
	else if(!Q_stricmp(ext, "pcx"))
	{
		LoadPCX(name, pixels, palette, width, height);
	}
	else if(!Q_stricmp(ext, "bmp"))
	{
		LoadBMP(name, pixels, palette, width, height);
	}
	else
		Error("%s doesn't have a known image extension", name);
}
Example #8
0
void main(void) 
{ 
   T_PVS l_pvsBackGround; 

   InitializeEngFontBuf();         // initial english font system 
   LoadEngFont("ENGLISH.FNT"); 

   l_pvsBackGround=InitializeVS(); // initialize virtual background screen. 
   ClearVS(l_pvsBackGround);       // clear virtual background screen. 

   SetMode13h(); 
   SetPalette( "DEFAULT.PAL" ); 
   if( LoadPCX(l_pvsBackGround,"P001.PCX")==0 ) 
Printf( g_pVRAM,10,20,"Error" ); 
   else 
PutVS( g_pVRAM,l_pvsBackGround ); 
   Printf( g_pVRAM,10,20,"Lee kang-yong." ); 
   getch(); 
   SetTextMode(); 

   RemoveEngFontBuf();             // uninstall english font system 
   RemoveVS(l_pvsBackGround);      // remove virtual background screen. 
   return; 
} 
Example #9
0
VISIBLE tex_t *
LoadImage (const char *imageFile)
{
	int         tmp;
	dstring_t  *tmpFile;
	char       *ext;
	tex_t      *tex = NULL;
	QFile      *fp;

	// Get the file name without extension
	tmpFile = dstring_new ();
	dstring_copystr (tmpFile, imageFile);
	ext = strrchr (tmpFile->str, '.');
	if (ext)
		tmp = ext - tmpFile->str;
	else
		tmp = tmpFile->size - 1;

	// Check for a .png
	dstring_replace (tmpFile, tmp, tmpFile->size, ".png", 5);
	QFS_FOpenFile (tmpFile->str, &fp);
	if (fp) {
		tex = LoadPNG (fp);
		Qclose (fp);
		dstring_delete (tmpFile);
		return (tex);
	}

	// Check for a .tga
	dstring_replace (tmpFile, tmp, tmpFile->size, ".tga", 5);
	QFS_FOpenFile (tmpFile->str, &fp);
	if (fp) {
		tex = LoadTGA (fp);
		Qclose (fp);
		dstring_delete (tmpFile);
		return (tex);
	}

/*
	// Check for a .jpg
	dstring_replace (tmpFile, tmp, tmpFile->size, ".jpg", 5);
	QFS_FOpenFile (tmpFile->str, &fp);
	if (fp) {
		tex = LoadJPG (fp);
		Qclose (fp);
		dstring_delete (tmpFile);
		return (tex);
	}
*/

	// Check for a .pcx
	dstring_replace (tmpFile, tmp, tmpFile->size, ".pcx", 5);
	QFS_FOpenFile (tmpFile->str, &fp);
	if (fp) {
		tex = LoadPCX (fp, 1, NULL); // Convert, some users don't grok paletted
		Qclose (fp);
		dstring_delete (tmpFile);
		return (tex);
	}

	dstring_delete (tmpFile);
	return (tex);
}
Example #10
0
int main (int argc, char * Files []) {

	cout << "PCX to VBM Converter Version 0.1Beta\n" << "Working . . .\n";

	if ( argc < 2 ) {
		cout << "Not Enough Arguments\n" << "Usage:\n" <<
			"\tpcx2vbm pcxfile1 pcxfile2 . . . pcxfilen" <<
			"\tWhere pcxfile1 to pcxfile2 are PCX files to be converted\n";
	}

	for (int tru = 1; tru <= (argc - 1); tru++) {

		//make names usable
      //char * thisFile = strcpy(thisFile, *(Files + tru));
      //char * writeFile = strcpy(writeFile, *(Files + tru));
      char thisFile[128];
      char writeFile[128];
      //char * thisFile = new char [12];
      //char * writeFile = new char [12];
      strcpy(thisFile, *(Files + tru));
      strcpy(writeFile, *(Files + tru));
		int repplace = 0;
		for (int tru2 = 0; tru2 < 20; tru2++) {
			char thechar = *(writeFile + tru2);
			if (thechar == '.') {
				repplace = tru2;
            break;
			}
		}
		char * vbmstr = ".vbm";
		memcpy(writeFile + repplace, vbmstr, 4);

		cout << "Converting " << thisFile <<  " to " << writeFile << "\n";

		LINEAR_BITMAP * TempBitmap = new LINEAR_BITMAP;
		UCHAR PCXPal[256][3];

		//load the pcx file
		TempBitmap = LoadPCX(thisFile, PCXPal);
		if (TempBitmap == NULL) {
			delete TempBitmap;
			cout << "\nCan't load file: " << thisFile << "\n";
			return 1;
		}

		//transfer stuff from one bitmap to another
		Bitmap * MyBitmap = new Bitmap;
		UCHAR * tPointer = (UCHAR *)&(TempBitmap->Data);
		//convert stuff
		MyBitmap->MakeNewBmp (TempBitmap->Width, TempBitmap->Height, tPointer, PCXPal);
		//save it
		MyBitmap->SaveToDisk (writeFile);
      //TheScreen->SetMode13h(); //set mode13h (don't forget)
      //MyBitmap->PutRegular (0, 0, VGAMEMORY);
      //getch();
      //TheScreen->SetTextMode(); //set mode13h (don't forget)
      delete MyBitmap;
	}

	cout << "Done";

	return 0;
}
// ----------------------------------------------
// LoadModel() - load model from file.
// ----------------------------------------------
bool MD2Loader::LoadModel( const char* filename, renderer::Mesh& obj, const char* textureFilename)
{
    std::ifstream   file;           // file stream

	// try to open filename
    file.open( filename, std::ios::in | std::ios::binary );

    if( file.fail() )
        return false;

    // read md2 header file
    Md2Header_t header;         
	file.read( reinterpret_cast<char*>(&header), sizeof( Md2Header_t ) );

    /////////////////////////////////////////////
    //      verify that this is a MD2 file

    // check for the ident and the version number
    if( (header.indent != MD2_IDENT) && (header.version != MD2_VERSION) )
    {
        // this is not a MD2 model
        file.close();
        return false;
    }

    /////////////////////////////////////////////

    // allocate memory dynamically (on heap)
	Md2Triangle_t*	pTriangles		= new Md2Triangle_t[ header.numTriangles ];
	BYTE*			pFrameBuffer	= new BYTE[ header.frameSize ];// only interested in one frame (first)
	Md2Frame_t*		pFrame			= reinterpret_cast<Md2Frame_t*>(pFrameBuffer);
	Md2TexCoord_t*	pTexCoords		= new Md2TexCoord_t[ header.numTexCoords ];

    /////////////////////////////////////////////
    //          reading file data

	// read polygon data...
	file.seekg( header.offsetTriangles, std::ios::beg );
	file.read( reinterpret_cast<char*>(pTriangles), sizeof(Md2Triangle_t) * header.numTriangles );	// read just first frame

    // read frame data...
    file.seekg( header.offsetFrames, std::ios::beg );
    file.read( reinterpret_cast<char*>(pFrame), header.frameSize );	// read just first frame

	// read texture coord data
	file.seekg( header.offsetTexCoords, std::ios::beg );
	file.read( reinterpret_cast<char*>(pTexCoords), sizeof(Md2TexCoord_t) * header.numTexCoords );

	// close the file 
    file.close();
    /////////////////////////////////////////////

	bool bHasTexture = false;

	//attempt to load texture
	if ( textureFilename != 0 ) 
	{   
		BYTE*   pTexture = new BYTE[header.skinWidth * header.skinHeight]; 
		Gdiplus::Color* pPalette = new Gdiplus::Color[256]; // rgb 256 palette 
		
		/*Note.  The texture co-ordinates that we load from the MD2 file are not normalised, but actually 
		in texture space already (scaled in range 0-255) since the texture size is fixed for MD2s at 
		256x256 textures. */

		bHasTexture = LoadPCX( textureFilename, pTexture, pPalette, &header ); 
		if ( !bHasTexture ) 
		{ 
			delete(pTexture); 
			delete(pPalette); 
			obj.m_hasTexture = false;
		} 
		else 
		{ 
			obj.m_hasTexture = true;
			obj.m_texture = pTexture; 
			obj.m_palette = pPalette; 
			obj.m_textureWidth = header.skinWidth; 
		} 
	} 

	// polygon array initialization
	obj.m_polys = new renderer::Polygon[header.numTriangles];
	for ( int i = 0; i < header.numTriangles; ++i )
	{
		renderer::Polygon p;
		
		p.Indices[0] = pTriangles[i].vertexIndex[0];
		p.Indices[1] = pTriangles[i].vertexIndex[1];
		p.Indices[2] = pTriangles[i].vertexIndex[2];

		p.UvIndices[0] = pTriangles[i].uvIndex[0];
		p.UvIndices[1] = pTriangles[i].uvIndex[1];
		p.UvIndices[2] = pTriangles[i].uvIndex[2];

		p.IsCulled = false;
		p.AverageDepth = 0.0f;
		p.Normal = Maths::Vector4();
		p.Colour = Gdiplus::Color::Black;
		obj.m_polys[i] = p;
	}
	obj.m_numPolys = header.numTriangles;

	// vertex array initialization
	obj.m_verts = boost::shared_array<Maths::Vector4>( new Maths::Vector4[ header.numVertices ] ); //new Maths::Vector4[ header.numVertices ];
	obj.m_transformed = new renderer::Vertex[ header.numVertices ];
    for( int i = 0; i < header.numVertices; ++i )
	{
		// NOTE: we have to swap Y and Z over because Z is up in Quake2 and we have Y as up-axis
		Maths::Vector4 v;
		v.X = (pFrame->verts[i].v[0] * pFrame->scale[0]) + pFrame->translate[0];
		v.Z = (pFrame->verts[i].v[1] * pFrame->scale[1]) + pFrame->translate[1];
		v.Y = (pFrame->verts[i].v[2] * pFrame->scale[2]) + pFrame->translate[2];
		v.W = 1.0f; // DON'T FORGET THIS otherwise looks 'exploded'
		obj.m_verts[i] = v;
	}
	obj.m_numVerts = header.numVertices;

	// Texture coordinates initialization
	if ( bHasTexture )
	{
		obj.m_TexUVs = new renderer::UVCoords[ header.numTexCoords ];
		for (int i = 0; i < header.numTexCoords; i++)
		{
			obj.m_TexUVs[i].U = pTexCoords[i].texCoord[0];
			obj.m_TexUVs[i].V = pTexCoords[i].texCoord[1];
		}
		obj.m_numTexUVs = header.numTexCoords;
	}
	else
	{
		obj.m_numTexUVs = 0;
	}

	// free buffer's heap memory
    delete [] pTriangles; // NOTE: this is 'array' delete must be sure to use this
	pTriangles = 0;

	delete [] pFrameBuffer;
	pFrameBuffer = 0;
	pFrame = 0;

	delete [] pTexCoords;
	pTexCoords = 0;
	return true;
}
Example #12
0
/*
 * Finds or loads the given image
 */
gl3image_t *
GL3_FindImage(char *name, imagetype_t type)
{
	gl3image_t *image;
	int i, len;
	byte *pic;
	int width, height;
	char *ptr;
	char namewe[256];
	int realwidth = 0, realheight = 0;
	const char* ext;

	if (!name)
	{
		return NULL;
	}

	ext = COM_FileExtension(name);
	if(!ext[0])
	{
		/* file has no extension */
		return NULL;
	}

	len = strlen(name);

	/* Remove the extension */
	memset(namewe, 0, 256);
	memcpy(namewe, name, len - 4);

	if (len < 5)
	{
		return NULL;
	}

	/* fix backslashes */
	while ((ptr = strchr(name, '\\')))
	{
		*ptr = '/';
	}

	/* look for it */
	for (i = 0, image = gl3textures; i < numgl3textures; i++, image++)
	{
		if (!strcmp(name, image->name))
		{
			image->registration_sequence = registration_sequence;
			return image;
		}
	}

	/* load the pic from disk */
	pic = NULL;

	if (strcmp(ext, "pcx") == 0)
	{
		if (gl_retexturing->value)
		{
			GetPCXInfo(name, &realwidth, &realheight);
			if(realwidth == 0)
			{
				/* No texture found */
				return NULL;
			}

			/* try to load a tga, png or jpg (in that order/priority) */
			if (  LoadSTB(namewe, "tga", &pic, &width, &height)
			   || LoadSTB(namewe, "png", &pic, &width, &height)
			   || LoadSTB(namewe, "jpg", &pic, &width, &height) )
			{
				/* upload tga or png or jpg */
				image = GL3_LoadPic(name, pic, width, realwidth, height,
						realheight, type, 32);
			}
			else
			{
				/* PCX if no TGA/PNG/JPEG available (exists always) */
				LoadPCX(name, &pic, NULL, &width, &height);

				if (!pic)
				{
					/* No texture found */
					return NULL;
				}

				/* Upload the PCX */
				image = GL3_LoadPic(name, pic, width, 0, height, 0, type, 8);
			}
		}
		else /* gl_retexture is not set */
		{
			LoadPCX(name, &pic, NULL, &width, &height);

			if (!pic)
			{
				return NULL;
			}

			image = GL3_LoadPic(name, pic, width, 0, height, 0, type, 8);
		}
	}
	else if (strcmp(ext, "wal") == 0)
	{
		if (gl_retexturing->value)
		{
			/* Get size of the original texture */
			GetWalInfo(name, &realwidth, &realheight);
			if(realwidth == 0)
			{
				/* No texture found */
				return NULL;
			}

			/* try to load a tga, png or jpg (in that order/priority) */
			if (  LoadSTB(namewe, "tga", &pic, &width, &height)
			   || LoadSTB(namewe, "png", &pic, &width, &height)
			   || LoadSTB(namewe, "jpg", &pic, &width, &height) )
			{
				/* upload tga or png or jpg */
				image = GL3_LoadPic(name, pic, width, realwidth, height, realheight, type, 32);
			}
			else
			{
				/* WAL if no TGA/PNG/JPEG available (exists always) */
				image = LoadWal(namewe);
			}

			if (!image)
			{
				/* No texture found */
				return NULL;
			}
		}
		else /* gl_retexture is not set */
		{
			image = LoadWal(name);

			if (!image)
			{
				/* No texture found */
				return NULL;
			}
		}
	}
	else if (strcmp(ext, "tga") == 0 || strcmp(ext, "png") == 0 || strcmp(ext, "jpg") == 0)
	{
		char tmp_name[256];

		realwidth = 0;
		realheight = 0;

		strcpy(tmp_name, namewe);
		strcat(tmp_name, ".wal");
		GetWalInfo(tmp_name, &realwidth, &realheight);

		if (realwidth == 0 || realheight == 0) {
			/* It's a sky or model skin. */
			strcpy(tmp_name, namewe);
			strcat(tmp_name, ".pcx");
			GetPCXInfo(tmp_name, &realwidth, &realheight);
		}

		/* TODO: not sure if not having realwidth/heigth is bad - a tga/png/jpg
		 * was requested, after all, so there might be no corresponding wal/pcx?
		 * if (realwidth == 0 || realheight == 0) return NULL;
		 */

		if(LoadSTB(name, ext, &pic, &width, &height))
		{
			image = GL3_LoadPic(name, pic, width, realwidth, height, realheight, type, 32);
		}
	}
	else
	{
		return NULL;
	}

	if (pic)
	{
		free(pic);
	}

	return image;
}