PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

adding .tga files as resource for EastCE use...

Hi all, I've managed to add a binary file (tga) as a resource to my program,

the generated code looks like:

Code:

//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by resource.rc
//
#define IDI_ICON1 102
#define IDR_BINARY1 103




anyhow I'd now like to "load" the contents of this using the tgaload command in easyce. how do I go it? any ideas? Ive tried and keep getting.... things like:

E:\Squish3\sample.cpp(226) : error C2664: 'memcpy' : cannot convert parameter 2 from 'const int' to 'const void *'

or

E:\Squish3\sample.cpp(183) : error C2665: 'tgaload' : none of the 2 overloads can convert parameter 1 from type 'const int'


or

E:\Squish3\sample.cpp(183) : error C2665: 'tgaload' : none of the 2 overloads can convert parameter 1 from type 'unsigned short *'


help, this must be "doo-able"

-thanks brendan
B.T.W the icon works fine :)
Hey,

this code shows how to obtain a pointer to a TGA that was added to the .EXE as a resource of custom type "TGA". The name in lpResourceName has to be passed using the MAKEINTRESOURCE() macro.

Code:

//
// FUNCTION: moveGetRawResourcePointer()
//
// PURPOSE: Returns a pointer to a TGA file in the resource file.
//
// COMMENTS:
//
// Returns a pointer to a TGA file in the resource file. Note that the memory
// taken by the LoadResource function has to be freed by the calling function.
//
unsigned short * moveGetRawResourcePointer( LPCTSTR lpResourceName )
{
// Find the resource in this module.
HRSRC hRsrc = FindResource( GetModuleHandle(NULL), lpResourceName, TEXT("TGA") );
if( hRsrc == NULL )
return NULL;

// Load the resource into memory and get a pointer to the memory location.
HGLOBAL hGlobal = LoadResource( GetModuleHandle(NULL), hRsrc );
if( hGlobal == NULL )
return NULL;

// Now skip the header bytes.
return (unsigned short *)hGlobal+9;
}


cryo
what about if it's gzipped, is the header information (+9) still the same ?
don't know, you will have to check the TGA file format. But i compared the first 18 bytes of both a compressed and an uncompressed 16bit TGA file, and they are the same except for byte 2:

compressed TGA header:
00 00 0A 00 00 00 00 00 00 00 00 00 5F 00 9F 01 10 00

uncompressed:
00 00 02 00 00 00 00 00 00 00 00 00 5F 00 9F 01 10 00

of course, form the same image.

cryo
brendan · 06 May 2002, 00:20 UTC — maybe
I've used the code, and it sort of works.... I get the image upside down on the screen, with the colors distorted..... wierd.... what are you ment to send to the function, I assume it's the name of the file?, or the resource handle, but these fails, it expects an unsigned short?

can you give me a simple peice of code to call the function :)

-thanks, brendan

then all I have to do is somehow ungip the data......... fun
the image is upside down because that's how it is stored on file. Before showing the picture, you must decode it from bottom to top and you must adapt each pixel to the RGB setup of the machine you're running it on. I.e., if you have an 36xx iPAQ, it has a 565 pixel format, and you must do something like this for each pixel:
Code:

int red = (*(src + x) & (31 << 10)) >> 10;
int green = (*(src + x) & (31 << 5)) >> 5;
int blue = *(src + x) & 31;

*(dst + x) = (red << 11) + (green << 5) + blue;


And the function expects something like moveGetRawResourcePointer( MAKEINTRESOURCE(IDS_TGA)...

cryo
I think this was discussed in another post, it must be a photoshop thing to write it upside down.... other apps don't seem to do that, PSP etc. might be easyer to write it out in another app.... ;)

-Brendan