2014-08-03 19:38:53 +06:00
|
|
|
#include "StdAfxSA.h"
|
2014-06-06 18:59:16 +06:00
|
|
|
#include "PNGFile.h"
|
|
|
|
|
|
|
|
RwTexture* CPNGFile::ReadFromFile(const char* pFileName)
|
|
|
|
{
|
|
|
|
RwTexture* pTexture = nullptr;
|
|
|
|
|
|
|
|
if ( RwImage* pImage = RtPNGImageRead(pFileName) )
|
|
|
|
{
|
|
|
|
RwInt32 dwWidth, dwHeight, dwDepth, dwFlags;
|
|
|
|
RwImageFindRasterFormat(pImage, rwRASTERTYPETEXTURE, &dwWidth, &dwHeight, &dwDepth, &dwFlags);
|
|
|
|
if ( RwRaster* pRaster = RwRasterCreate(dwWidth, dwHeight, dwDepth, dwFlags) )
|
|
|
|
{
|
|
|
|
RwRasterSetFromImage(pRaster, pImage);
|
|
|
|
|
|
|
|
pTexture = RwTextureCreate(pRaster);
|
|
|
|
//if ( pTexture )
|
|
|
|
// RwTextureSetName(pTexture, pFileName);
|
|
|
|
}
|
|
|
|
RwImageDestroy(pImage);
|
|
|
|
}
|
|
|
|
return pTexture;
|
|
|
|
}
|
|
|
|
|
|
|
|
RwTexture* CPNGFile::ReadFromMemory(const void* pMemory, unsigned int nLen)
|
|
|
|
{
|
2014-08-22 04:10:23 +06:00
|
|
|
static BYTE* pMem = AddressByVersion<BYTE*>(0x7CF9CA, 0x7D02CA, 0x80998A);
|
2014-06-06 18:59:16 +06:00
|
|
|
RwTexture* pTexture = nullptr;
|
|
|
|
|
2014-08-04 18:30:16 +06:00
|
|
|
MemoryVP::Patch<BYTE>(pMem, rwSTREAMMEMORY);
|
2014-06-06 18:59:16 +06:00
|
|
|
|
|
|
|
RwMemory PNGMemory;
|
|
|
|
PNGMemory.start = const_cast<RwUInt8*>(static_cast<const RwUInt8*>(pMemory));
|
|
|
|
PNGMemory.length = nLen;
|
|
|
|
|
|
|
|
if ( RwImage* pImage = RtPNGImageRead(reinterpret_cast<RwChar*>(&PNGMemory)) )
|
|
|
|
{
|
|
|
|
RwInt32 dwWidth, dwHeight, dwDepth, dwFlags;
|
|
|
|
RwImageFindRasterFormat(pImage, rwRASTERTYPETEXTURE, &dwWidth, &dwHeight, &dwDepth, &dwFlags);
|
|
|
|
if ( RwRaster* pRaster = RwRasterCreate(dwWidth, dwHeight, dwDepth, dwFlags) )
|
|
|
|
{
|
|
|
|
RwRasterSetFromImage(pRaster, pImage);
|
|
|
|
|
|
|
|
pTexture = RwTextureCreate(pRaster);
|
|
|
|
//if ( pTexture )
|
|
|
|
// RwTextureSetName(pTexture, pFileName);
|
|
|
|
}
|
|
|
|
RwImageDestroy(pImage);
|
|
|
|
}
|
|
|
|
|
2014-08-04 18:30:16 +06:00
|
|
|
MemoryVP::Patch<BYTE>(pMem, rwSTREAMFILENAME);
|
2014-06-06 18:59:16 +06:00
|
|
|
|
|
|
|
return pTexture;
|
|
|
|
}
|