Archived

This topic is now archived and is closed to further replies.

Processing TGA file loaded from ZIP

This topic is 5005 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have finally gotten my code to load files from a compressed ZIP and return a buffer full of unsigned char's. Im now trying to process that buffer as if it were the file in question, in this case for TGA loading. When I do:
int fileSize = CFileSystem::getSingleton().getFileSize( fileName );
		unsigned char* buffer = (unsigned char*)malloc( sizeof(unsigned char) * fileSize );
		CFileSystem::getSingleton().loadFileIntoBuffer( fileName, buffer, fileSize );
    
For now I'm testing my routines by reading the .tga as a normal file in parallel. Can I then do something like:
// Ignore the first two bytes
		fread (&uCharDummy, sizeof (unsigned char), 1, pFile);
		fread (&uCharDummy, sizeof (unsigned char), 1, pFile);


		// Pop in the header
		fread(&TgaHeader.imageTypeCode, sizeof (unsigned char), 1, pFile);
		meep = (unsigned char)(buffer+2);
     
And have meep and TgaHeader.imageTypeCode be equivalent? Thanks! EDIT: Corrected typo/ [edited by - voodoo_john on March 29, 2004 11:12:07 PM] [edited by - voodoo_john on March 29, 2004 11:28:35 PM]

Share this post


Link to post
Share on other sites
Sorry for the typo...its 6am here

Yeah I thought it should be equal, but it''s not.

Using the debugger reveals that meep=0x42 and the Tga Type is 0x02 which is correct.

I have dumped the buffer back to disk and it is the right format.....

I''m sure I must be doing something real stupid here, but I''m rushing to get this game finished before I start back at work and need help!

Share this post


Link to post
Share on other sites
You need to dereference your pointer. Right now you're adding 2 to the address of buffer and cast it to an unsigned char.

meep = &(buffer+2);

Also: couldn't help it, but since you use all kind of nice OOP features, why the hell are you using malloc and not new?

[edited by - Endurion on March 30, 2004 6:45:58 AM]

Share this post


Link to post
Share on other sites
Hi! Thanks for replying :D

Yeah I''ve tried

meep = (unsigned char)&buffer+2;

to no effect, the two are stil !=


A to Q: No real reason. I''m a C programmer of old and sometimes unless I specifically remind myself to use new etc the old ways creep in :D


Ag! I need sleep but I''m so close to getting this game finished

Share this post


Link to post
Share on other sites