diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /common/imageloadwrapper.cpp | |
| download | archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.tar.xz archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.zip | |
Diffstat (limited to 'common/imageloadwrapper.cpp')
| -rw-r--r-- | common/imageloadwrapper.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/common/imageloadwrapper.cpp b/common/imageloadwrapper.cpp new file mode 100644 index 0000000..39dcf2e --- /dev/null +++ b/common/imageloadwrapper.cpp @@ -0,0 +1,60 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#include "imageloadwrapper.h" + +bool ConvertImageToRGB( const byte *pubImageData, int cubImageData, CUtlBuffer &bufOutput, int &width, int &height ) +{ + bool bSuccess = false; + if ( GetJpegDimensions( pubImageData, cubImageData, (uint32&)width, (uint32&)height ) ) + { + bSuccess = ConvertJpegToRGB( pubImageData, cubImageData, bufOutput, width, height ); + } + else if ( GetPNGDimensions( pubImageData, cubImageData, (uint32&)width, (uint32&)height ) ) + { + if ( ConvertPNGToRGBA( pubImageData, cubImageData, bufOutput, width, height ) ) + bSuccess = BConvertRGBAToRGB( bufOutput, width, height ); + } + else if ( GetTGADimensions( cubImageData, (char*)pubImageData, &width, &height ) ) + { + byte *pubRGB = NULL; + int cubRGB = 0; + bSuccess = LoadTGA( cubImageData, (char*)pubImageData, &pubRGB, &cubRGB, &width, &height ); + if ( bSuccess ) + { + bufOutput.CopyBuffer( pubRGB, cubRGB ); + delete [] pubRGB; + bSuccess = BConvertRGBAToRGB( bufOutput, width, height ); + } + } + return bSuccess; +} + +bool ConvertImageToRGBA( const byte *pubImageData, int cubImageData, CUtlBuffer &bufOutput, int &width, int &height ) +{ + bool bSuccess = false; + if ( GetJpegDimensions( pubImageData, cubImageData, (uint32&)width, (uint32&)height ) ) + { + bSuccess = ConvertJpegToRGBA( pubImageData, cubImageData, bufOutput, width, height ); + } + else if ( GetPNGDimensions( pubImageData, cubImageData, (uint32&)width, (uint32&)height ) ) + { + bSuccess = ConvertPNGToRGBA( pubImageData, cubImageData, bufOutput, width, height ); + } + else if ( GetTGADimensions( cubImageData, (char*)pubImageData, &width, &height ) ) + { + byte *pubRGB = NULL; + int cubRGB = 0; + bSuccess = LoadTGA( cubImageData, (char*)pubImageData, &pubRGB, &cubRGB, &width, &height ); + if ( bSuccess ) + { + bufOutput.CopyBuffer( pubRGB, cubRGB ); + delete [] pubRGB; + } + } + return bSuccess; +} + |