Example #1
0
AUI_ERRCODE TargaImageFormat::Load(MBCHAR const * filename, aui_Image *image)
{
#ifdef WIN32
    if (_access(filename, 0) != 0)
#else
    struct stat st;
    if (stat(filename, &st) != 0)
#endif
    {
		return LoadRIM(filename, image);
    }

	int		width;
    int     height;
	int		bpp;
	if (!Get_TGA_Dimension(filename, width, height, bpp)) 
    {
		return AUI_ERRCODE_LOADFAILED;
    }

	AUI_ERRCODE errcode = image->LoadEmpty( width, height, 16 );
	Assert( errcode == AUI_ERRCODE_OK );
	if ( errcode != AUI_ERRCODE_OK ) {
		MBCHAR	s[200];
		sprintf(s, "Unable to load the file '%s' (w:%d, h:%d)", filename, width, height);
		c3errors_ErrorDialog("Targa Load", s, filename);
		return AUI_ERRCODE_LOADFAILED;
	}

	aui_Surface * surface = image->TheSurface();
	if (!surface) return AUI_ERRCODE_LOADFAILED;

	AUI_ERRCODE retcode = AUI_ERRCODE_OK;
	uint16 *    buffer;
	errcode = surface->Lock( NULL, (LPVOID *)&buffer, 0 );
	
	Assert( errcode == AUI_ERRCODE_OK );
	if ( errcode == AUI_ERRCODE_OK )
	{
		if (Load_TGA_File(filename, (uint8 *)buffer, (int)surface->Pitch(), width, height, NULL, TRUE))
        {
		    errcode = surface->Unlock( buffer );

		    Assert( errcode == AUI_ERRCODE_OK );
		    if ( errcode != AUI_ERRCODE_OK )
			    retcode = AUI_ERRCODE_SURFACEUNLOCKFAILED;
        }
        else
        {
            (void) surface->Unlock(buffer);
            retcode = AUI_ERRCODE_LOADFAILED;
        }
	}

	return retcode;
}
Example #2
0
Pixel16 *tileutils_TGA2mem(char *filename, uint16 *width, uint16 *height)
{

	int		bpp;
	int		w, h;

	if (!Get_TGA_Dimension(filename, w, h, bpp)) {
		Assert(FALSE);
		*width = 0;
		*height = 0;
		return NULL;
	}

	Pixel16 *   buffer = new Pixel16[w * h];
	Load_TGA_File(filename, (uint8 *)buffer, (int)w*sizeof(Pixel16), w, h, NULL, FALSE);

	*width = (uint16)w;
	*height = (uint16)h;

	return buffer;
}