Hi all, my last project pointed me to a few bugs with easyce that you may wish to know about. I was having it crash when ram usage was getting low... here are a few things that you should look at:
the tgazload (tgaload) functions use a buffer to place your file in to process it (strip headers etc), there is no checking the mem allocation for this!
The function does not do a check to see if your file exists first either... also handy.
It is also handy to have the function check the destination location is ok.
here is my "moded" code:
I wonder if someone could re-write this function to not require the buffer? For big files it requires your buffer as well as its temp buffer.... i.e to load a 2Mb image, you need 4Mb of ram.
-Brendan
the tgazload (tgaload) functions use a buffer to place your file in to process it (strip headers etc), there is no checking the mem allocation for this!
The function does not do a check to see if your file exists first either... also handy.
It is also handy to have the function check the destination location is ok.
here is my "moded" code:
- Code:
bool tgazload( char* file, int w, int h, IPIXEL* dest, PIXEL* pal )
{
//load
FILE *fp1=fopen(fullpath(file),"r");
if ((fp1) && (dest))
{
fclose(fp1);
int size = w * h + 20 + 768;
BYTE* tgabuff = new BYTE[size];
if (tgabuff)
{
gzFile tga = gzopen( fullpath( file ), "rb" );
gzread( tga, tgabuff, size );
gzclose( tga );
parseheader( tgabuff );
// Store the data at the specified target address
if (pal)
{
for ( int i = 0; i < 256; i++ )
{
int b = *(tgabuff + 18 + i * 3);
int g = *(tgabuff + 18 + i * 3 + 1);
int r = *(tgabuff + 18 + i * 3 + 2);
pal[i] = (PIXEL)(((r >> 3) << 11) + ((g >> 2) << 5) + (b >> 3));
}
}
IPIXEL* src = tgabuff + 18 + 768 + (h - 1) * w;
IPIXEL* dst = (IPIXEL*)dest;
for ( int y = 0; y < h; y++ )
{
memcpy( dst, src, w );
dst += w;
src -= w;
}
// Release temporary storage
delete tgabuff;
return true;
}
else return false;
}
else return false;
}
I wonder if someone could re-write this function to not require the buffer? For big files it requires your buffer as well as its temp buffer.... i.e to load a 2Mb image, you need 4Mb of ram.
-Brendan