2023-06-12 00:30:13 +02:00
|
|
|
//========= Copyright (c) 1996-2002, Valve LLC, All rights reserved. ============
|
2016-06-04 15:24:23 +02:00
|
|
|
//
|
|
|
|
// Purpose:
|
|
|
|
//
|
|
|
|
// $NoKeywords: $
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
#include "../cl_dll/wrect.h"
|
|
|
|
#include "../cl_dll/cl_dll.h"
|
2021-10-27 03:35:11 +02:00
|
|
|
#include "VGUI.h"
|
2016-06-04 15:24:23 +02:00
|
|
|
#include "vgui_loadtga.h"
|
2021-10-27 03:35:11 +02:00
|
|
|
#include "VGUI_InputStream.h"
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------- //
|
|
|
|
// Helper class for loading tga files.
|
|
|
|
// ---------------------------------------------------------------------- //
|
|
|
|
class MemoryInputStream : public vgui::InputStream
|
|
|
|
{
|
|
|
|
public:
|
2021-10-27 03:35:11 +02:00
|
|
|
MemoryInputStream()
|
|
|
|
{
|
|
|
|
m_pData = NULL;
|
|
|
|
m_DataLen = m_ReadPos = 0;
|
|
|
|
}
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2021-10-27 03:35:11 +02:00
|
|
|
virtual void seekStart( bool &success )
|
|
|
|
{
|
|
|
|
m_ReadPos = 0;
|
|
|
|
success = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void seekRelative( int count, bool &success )
|
|
|
|
{
|
|
|
|
m_ReadPos += count;
|
|
|
|
success = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void seekEnd( bool &success )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2021-10-27 03:35:11 +02:00
|
|
|
m_ReadPos = m_DataLen;
|
|
|
|
success = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int getAvailable( bool &success )
|
|
|
|
{
|
|
|
|
// This is what vgui does for files...
|
|
|
|
success = false;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual uchar readUChar( bool & success )
|
|
|
|
{
|
|
|
|
if( m_ReadPos >= 0 && m_ReadPos < m_DataLen )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2021-10-27 03:35:11 +02:00
|
|
|
success = true;
|
2016-06-04 15:24:23 +02:00
|
|
|
uchar ret = m_pData[m_ReadPos];
|
|
|
|
++m_ReadPos;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-27 03:35:11 +02:00
|
|
|
success = false;
|
2016-06-04 15:24:23 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-27 03:35:11 +02:00
|
|
|
virtual void readUChar( uchar *buf, int count, bool &success )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2021-10-27 03:35:11 +02:00
|
|
|
for( int i = 0; i < count; i++)
|
|
|
|
buf[i] = readUChar( success );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2021-10-27 03:35:11 +02:00
|
|
|
virtual void close( bool &success)
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
m_pData = NULL;
|
|
|
|
m_DataLen = m_ReadPos = 0;
|
|
|
|
}
|
|
|
|
|
2021-10-27 03:35:11 +02:00
|
|
|
uchar *m_pData;
|
|
|
|
int m_DataLen;
|
|
|
|
int m_ReadPos;
|
2016-06-04 15:24:23 +02:00
|
|
|
};
|
|
|
|
|
2021-10-27 03:35:11 +02:00
|
|
|
vgui::BitmapTGA *vgui_LoadTGA( char const *pFilename )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
MemoryInputStream stream;
|
|
|
|
|
2021-10-27 03:35:11 +02:00
|
|
|
stream.m_pData = gEngfuncs.COM_LoadFile( (char*)pFilename, 5, &stream.m_DataLen );
|
|
|
|
if( !stream.m_pData )
|
2016-06-04 15:24:23 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
stream.m_ReadPos = 0;
|
2021-10-27 03:35:11 +02:00
|
|
|
vgui::BitmapTGA *pRet = new vgui::BitmapTGA( &stream, true );
|
|
|
|
gEngfuncs.COM_FreeFile( stream.m_pData );
|
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2021-10-27 03:35:11 +02:00
|
|
|
vgui::BitmapTGA *vgui_LoadTGANoInvertAlpha( char const *pFilename )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
MemoryInputStream stream;
|
2021-10-27 03:35:11 +02:00
|
|
|
|
|
|
|
stream.m_pData = gEngfuncs.COM_LoadFile( (char*)pFilename, 5, &stream.m_DataLen );
|
|
|
|
if( !stream.m_pData )
|
2016-06-04 15:24:23 +02:00
|
|
|
return NULL;
|
2021-10-27 03:35:11 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
stream.m_ReadPos = 0;
|
2021-10-27 03:35:11 +02:00
|
|
|
vgui::BitmapTGA *pRet = new vgui::BitmapTGA( &stream, false );
|
|
|
|
gEngfuncs.COM_FreeFile( stream.m_pData );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
return pRet;
|
|
|
|
}
|