Advertisement

TGA converters

Started by November 10, 2000 08:58 PM
8 comments, last by slartibartfast00 24 years ago
Does anyone know of any freeware converters that support TGA. I use the GIMP to brew my images, but the TGA support is incompatable with NeHe''s. I need one which supports transparancy, so the one I sugested a while ago, here wont work. Can anyone help? SLARTIBARTFAST00 PLEASE SELECT WITTY .SIG: NoneWho is General Failure and why is he reading my disk?Microwave: Signal from a friendly micro...Multitasking: Screwing up several things at once...How do I set my laser printer on stun?Sarr! The spellchecker kinna take this abuse!
SLARTIBARTFAST00 PLEASE SELECT WITTY .SIG: NoneWho is General Failure and why is he reading my disk?Microwave: Signal from a friendly micro...Multitasking: Screwing up several things at once...How do I set my laser printer on stun?Sarr! The spellchecker kinna take this abuse!
Goto www.wotsit.org and get the TGA spec. Then you can write code that supports anything you need.
Advertisement
Hmmn... I was thinking of doing this later, but for the time I want to be able to do it without any extra code. Thanks anyway.


SLARTIBARTFAST00 PLEASE SELECT WITTY .SIG:
NoneWho is General Failure and why is he reading my disk?Microwave: Signal from a friendly micro...Multitasking: Screwing up several things at once...How do I set my laser printer on stun?Sarr! The spellchecker kinna take this abuse!
SLARTIBARTFAST00 PLEASE SELECT WITTY .SIG: NoneWho is General Failure and why is he reading my disk?Microwave: Signal from a friendly micro...Multitasking: Screwing up several things at once...How do I set my laser printer on stun?Sarr! The spellchecker kinna take this abuse!
Have a look on tucows or even go look for paint shop pro. it''s an amazing program that gives you full features with a 30 day time limit. of course, there''s nothing stopping you from reinstalling after that time...

S.
Hmm. I once had a demo of paintshop pro 4 that didn''t expire. The days counter kept on going up and up. Nifty bug that was.


SLARTIBARTFAST00 PLEASE SELECT WITTY .SIG:
NoneWho is General Failure and why is he reading my disk?Microwave: Signal from a friendly micro...Multitasking: Screwing up several things at once...How do I set my laser printer on stun?Sarr! The spellchecker kinna take this abuse!
SLARTIBARTFAST00 PLEASE SELECT WITTY .SIG: NoneWho is General Failure and why is he reading my disk?Microwave: Signal from a friendly micro...Multitasking: Screwing up several things at once...How do I set my laser printer on stun?Sarr! The spellchecker kinna take this abuse!
BTW, Tucows sucked. Of course, I have tried most of those sites anyway. Does anyone have an actual URL or program name?


SLARTIBARTFAST00 PLEASE SELECT WITTY .SIG:
NoneWho is General Failure and why is he reading my disk?Microwave: Signal from a friendly micro...Multitasking: Screwing up several things at once...How do I set my laser printer on stun?Sarr! The spellchecker kinna take this abuse!
SLARTIBARTFAST00 PLEASE SELECT WITTY .SIG: NoneWho is General Failure and why is he reading my disk?Microwave: Signal from a friendly micro...Multitasking: Screwing up several things at once...How do I set my laser printer on stun?Sarr! The spellchecker kinna take this abuse!
Advertisement
I''m using an ancient version of Photoshop. I''ve noticed that Paint Shop Pro incorrectly exports greyscale images as 8-bit paletted images - that causes some headaches.

Try:

http://home.clara.net/paulyg/tgaload.zip

from my site, it supports alpha and a whole bunch of other stuff.

Paul Groves
pauls opengl page
Paul Grovespauls opengl page
Photoshop (okok it''s expensive) does it quite ok, but as you are on a Linux platform I think you can do it with a trick:

Write the 24bit TGA picture in file A and an 8 bit ''alphamap'' in file B. (that''s the transparency layer). Then, you first load the TGA file A into a 32bitsperpixel array and for the alphabytes you load the file B, and merge the data into the array that already contains the 24bitpp TGA file.

below is my TGA loader. I''ve also mailed this source to NeHe, so he''ll probably include it in his libs somewhere in time.
  // Purpose: Loads a file from disk. returns pointer to file in memory or NULL if it failed// In: sFilename	: string with filename to load// Out: pointer to buffer.//// Note: I included this routine to make it complete. This is not the DemoGL fileloader <img src="wink.gif" width=15 height=15 align=middle>//byte*FLoadFile(const char *sFilename){	FILE	*fpFile;	byte	*pBuffer;	long	lFileLength;	fpFile=fopen(sFilename,"rb");	if(!fpFile)	{		return NULL;	}	fseek(fpFile,0,SEEK_END);	lFileLength=ftell(fpFile);	fseek(fpFile,0,SEEK_SET);	pBuffer=(byte *)malloc(lFileLength * sizeof(byte));	fread(pBuffer,lFileLength,1,fpFile);	fclose(fpFile);	return pBuffer;}// Purpose: loads a tga file into the passed texture object txTexture.// In: pTexture     : pointer to pointervariable wherein the address of the buffer which contains the texturedata should be stored//     sFilename    : tga file to load//     iMaxWidth    : maxwidth in pixels of destination texture.//     iMaxHeight   : maxheight in pixels of destination texture//     bCreateAlphaFromColor: if true, the greyvalue of RGB is used to create the A(lpha) value// Out: SYS_OK   : txTexture is filled.//      Errorcode: if something went wrong.// Additional Info: - Will clear texture in txTexture first, if present//                  - Converts all bitmap data to 24bit RGB triplets (because OpenGL wants that)//                  - Uses integers for width and height in pixels. Because hardware can''t use textures//                    larger than 2048x2048 (which is large), an integer can hold up to 32768x32768 (which is insane)//                    If updates are needed, we can swap to longs. Now this is not needed.//					- Only true color (24 bit/32 bit) are supported. (type 2) TGA is added for alphareading purposes.//                  - When bCreateAlphaFromColor is true, the eventually available alphabyte is ignored.//					- XYorigin is ignored. (0,0) is left lower corner) //// Uses ConvertTGAtoRGBA() for dataconversion.intDoImportTGA(byte **pTexture, const char *sFilename, int iMaxWidth, int iMaxHeight, bool bCreateAlphaFromColor){	int					iHeight, iWidth, iResult;	byte				*pTextureBuffer, *pTGAFile;	// load file.	pTGAFile = FLoadFile(sFilename);	if(!pTGAFile)	{		// open didn''t succeed		return SYS_TGA_LOAD_FAILED;	}	// Check if we have the right type of file.	if(pTGAFile[2] !=2)	{		// invalid format		free(pTGAFile);		return SYS_TGA_INVALID_FORMAT;	}	// SHITMACINTELCRAP. An integer is 4 bytes. lo-hi shit is reversed due to intel weirdness.	iWidth = int(pTGAFile[12] | ((int)pTGAFile[13] << 8));	iHeight = int(pTGAFile[14] | ((int)pTGAFile[15] << 8));	if((iMaxWidth < iWidth)||(iMaxHeight < iHeight))	{		// too large.		free(pTGAFile);		return SYS_TGA_INVALID_SIZE;	}	pTextureBuffer = (byte *)malloc(sizeof(byte) * iWidth * iHeight * 4);	// check if creation did go well...	if(!pTextureBuffer)	{		free(pTGAFile);		return SYS_MEM_ALLOC_FAIL;	}	iResult=ConvertTGAtoRGBA(pTGAFile, pTextureBuffer,iWidth, iHeight, bCreateAlphaFromColor);	*pTexture=NULL;	if(iResult==SYS_OK)	{		*pTexture=pTextureBuffer;	}	// clean up	free(pTGAFile);	return iResult;}// Purpose: converts a buffer that contains a TGA file to RGBA data.// Gets: pTGAFile, bytepointer, pointer to the TGAfile in memory// Gets: pRGBABuffer, bytepointer, pointer to pre-allocated RGBAbuffer. Should be of the size iWidth*iHeight*4//                    No boundary checks are made!// Gets: iWidth, iHeight, ints, with and height of picture// Gets: bCreateAlphaFromColor, bool, if true the color of the pixel will be used to create the alphabyte, otherwise// the alphabyte in the pixelitself is used, if present, otherwise 0xFF is used.// Returns: SYS_OK if all went well, SYS_NOK otherwiseintConvertTGAtoRGBA(byte *pTGAFile, byte *pRGBABuffer, int iWidth, int iHeight, bool bCreateAlphaFromColor){	int					i,j,ibytesPerPixel;	bool				bAlpha;	byte				*pPixelData;	byte				byR, byG, byB, byAlpha;	if(!pRGBABuffer)	{		return SYS_NOK;	}	if(!pTGAFile)	{		return SYS_NOK;	}	ibytesPerPixel = pTGAFile[16] / 8;	bAlpha = ((pTGAFile[17] & 0x0F) == 8);	// now we have to skip the colormap and identification IF present.	pPixelData = pTGAFile;	if(pTGAFile[1]!=0)	{		// there is a colormap. Ignore it. Get the length and add this to pPixelData		pPixelData += (int)(pTGAFile[3] | ((int)pTGAFile[4] << 8)) + ((int)(pTGAFile[5] | ((int)pTGAFile[6] << 8)) * pTGAFile[7]);	}	else	{		// there is no colormap. perhaps an identification. skip it.		pPixelData = pTGAFile + pTGAFile[0] + 18;	}		// reverse the order of the data by copying the data reverse to the texturememory reserved in the	// texture object. Copy pixel for pixel the data towards the texture space in the texture object	// because we don''t support 1 and 4 color tga files, we don''t have to worry about alignbits.	for(i=0; i<iHeight;i++)	{		for(j=0;j<iWidth;j++)		{			// is stored as BGRA			byR = pPixelData[(i * iWidth*ibytesPerPixel) + (j * ibytesPerPixel)+2];	// R			byG = pPixelData[(i * iWidth*ibytesPerPixel) + (j * ibytesPerPixel)+1];	// G			byB = pPixelData[(i * iWidth*ibytesPerPixel) + (j * ibytesPerPixel)];	// B			pRGBABuffer[(i * iWidth * 4) + (j * 4)] = byR;	// R			pRGBABuffer[(i * iWidth * 4) + (j * 4)+1] = byG;	// G			pRGBABuffer[(i * iWidth * 4) + (j * 4)+2] = byB;	// B			if(bCreateAlphaFromColor)			{				byAlpha = (byte)((0.35f * byR) + (0.45f * byG) + (0.20 * byB));			}			else			{				if(bAlpha)				{					byAlpha = pPixelData[(i * iWidth * ibytesPerPixel) + (j * ibytesPerPixel)+3];				}				else				{					byAlpha = 0xFF;				}			}			pRGBABuffer[(i * iWidth * 4) + (j * 4)+3] = byAlpha;		}	}	return SYS_OK;}  



--

Get productive, Get DemoGL: http://www.demogl.com
--
Get productive, Get DemoGL: http://www.demogl.com
Of course I forgot the .h stuff

(put this in a .h file you include in the sourcefile where you use the tga loader)

(arg... this source converter has serious bugs)

      ///////////////////////////////////////////////////////                  TYPEDEFS/////////////////////////////////////////////////////#ifndef bytetypedef unsigned char byte;#endif///////////////////////////////////////////////////////					DEFINES/////////////////////////////////////////////////////// DoImportTGA specific:#define SYS_TGA_LOAD_FAILED	11#define	SYS_TGA_EMPTY_FILE	12#define SYS_TGA_INVALID_FORMAT	13#define	SYS_TGA_INVALID_SIZE	14#define SYS_OK			0#define SYS_NOK			1#define SYS_MEM_ALLOC_FAIL	2///////////////////////////////////////////////////////					EXTERNS/////////////////////////////////////////////////////extern	int	DoImportTGA(byte *pTexture, const char *sFilename, int iMaxWidth, int iMaxHeight, bool bCreateAlphaFromColor);///////////////////////////////////////////////////////					other functiondefs/////////////////////////////////////////////////////int	ConvertTGAtoRGBA(byte *pTGAFile, byte *pRGBABuffer, int iWidth, int iHeight, bool bCreateAlphaFromColor);      


--

Get productive, Get DemoGL: http://www.demogl.com

Edited by - Otis on November 11, 2000 4:31:56 AM

Edited by - Otis on November 11, 2000 4:34:56 AM
--
Get productive, Get DemoGL: http://www.demogl.com
(BTW, I actualy usualy use Windows for my development. I have the Windows port of the GIMP)

I have fixed the problem, I have made a program that can have the exported C-source of the GIMP copied into it, and compiled to produce a file I call a simple texture (*.stx)

Basicly it saves width, hight, depth and the image data.

Then I did a little modification of the TGA code to load in my textures.

If anyone wants the code, just e-mail me.
Thanks for the help though,


SLARTIBARTFAST00 PLEASE SELECT WITTY .SIG:
NoneWho is General Failure and why is he reading my disk?Microwave: Signal from a friendly micro...Multitasking: Screwing up several things at once...How do I set my laser printer on stun?Sarr! The spellchecker kinna take this abuse!
SLARTIBARTFAST00 PLEASE SELECT WITTY .SIG: NoneWho is General Failure and why is he reading my disk?Microwave: Signal from a friendly micro...Multitasking: Screwing up several things at once...How do I set my laser printer on stun?Sarr! The spellchecker kinna take this abuse!

This topic is closed to new replies.

Advertisement