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 /utils/tgamse | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'utils/tgamse')
| -rw-r--r-- | utils/tgamse/tgamse.cpp | 174 | ||||
| -rw-r--r-- | utils/tgamse/tgamse.vpc | 25 |
2 files changed, 199 insertions, 0 deletions
diff --git a/utils/tgamse/tgamse.cpp b/utils/tgamse/tgamse.cpp new file mode 100644 index 0000000..772987c --- /dev/null +++ b/utils/tgamse/tgamse.cpp @@ -0,0 +1,174 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// +#include <stdlib.h> +#include <stdio.h> +#include <direct.h> +#include "bitmap/tgaloader.h" +#include "mathlib/mathlib.h" +#include "tier2/tier2.h" +#include "tier1/utlbuffer.h" +#include "tier1/strtools.h" +#include "filesystem.h" + +void Usage( void ) +{ + printf( "Fuzzy compare of two tga files.\n\n" ); + printf( "Usage: tgamse src1.tga src2.tga \n" ); + printf( "Return: MSE\n\n" ); + printf( "Usage: tgamse src1.tga src2.tga threshhold \n" ); + printf( "Return: PASS\\FAIL\n" ); + exit( -1 ); +} + +int main( int argc, char **argv ) +{ + if ( argc != 3 && argc != 4 ) + { + Usage(); + } + + MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f ); + InitDefaultFileSystem(); + + char pCurrentDirectory[MAX_PATH]; + if ( _getcwd( pCurrentDirectory, sizeof(pCurrentDirectory) ) == NULL ) + { + fprintf( stderr, "Unable to get the current directory\n" ); + return -1; + } + Q_FixSlashes( pCurrentDirectory ); + Q_StripTrailingSlash( pCurrentDirectory ); + + char pBuf[3][MAX_PATH]; + const char *pFileName[2]; + for ( int i = 0; i < 2; ++i ) + { + if ( !Q_IsAbsolutePath( argv[i+1] ) ) + { + Q_snprintf( pBuf[i], sizeof(pBuf[i]), "%s\\%s", pCurrentDirectory, argv[i+1] ); + pFileName[i] = pBuf[i]; + } + else + { + pFileName[i] = argv[i+1]; + } + } + + float fMSE = 10000.0f; + + if ( argc == 4 ) + { + fMSE = atof(argv[3]); + } + + int width1, height1; + ImageFormat imageFormat1; + float gamma1; + + CUtlBuffer buf1; + if ( !g_pFullFileSystem->ReadFile( pFileName[0], NULL, buf1 ) ) + { + fprintf( stderr, "%s not found\n", pFileName[0] ); + return -1; + } + + if( !TGALoader::GetInfo( buf1, &width1, &height1, &imageFormat1, &gamma1 ) ) + { + printf( "error loading %s\n", pFileName[0] ); + exit( -1 ); + } + + int width2, height2; + ImageFormat imageFormat2; + float gamma2; + + CUtlBuffer buf2; + if ( !g_pFullFileSystem->ReadFile( pFileName[1], NULL, buf2 ) ) + { + fprintf( stderr, "%s not found\n", pFileName[1] ); + return -1; + } + + if( !TGALoader::GetInfo( buf2, &width2, &height2, &imageFormat2, &gamma2 ) ) + { + printf( "error loading %s\n", pFileName[1] ); + exit( -1 ); + } + + if( width1 != width2 || height1 != height2 ) + { + printf( "image dimensions different (%dx%d!=%dx%d): can't do diff for %s\n", + width1, height1, width2, height2, pFileName[0] ); + exit( -1 ); + } +#if 0 + // have to allow for different formats for now due to *.txt file screwup. + if( imageFormat1 != imageFormat2 ) + { + printf( "image format different (%s!=%s). . can't do diff for %s\n", + ImageLoader::GetName( imageFormat1 ), ImageLoader::GetName( imageFormat2 ), pDstFileName ); + exit( -1 ); + } +#endif + if( gamma1 != gamma2 ) + { + printf( "image gamma different (%f!=%f). . can't do diff for %s\n", gamma1, gamma2, pFileName[0] ); + exit( -1 ); + } + + unsigned char *pImage1Tmp = new unsigned char[ImageLoader::GetMemRequired( width1, height1, 1, imageFormat1, false )]; + unsigned char *pImage2Tmp = new unsigned char[ImageLoader::GetMemRequired( width2, height2, 1, imageFormat2, false )]; + + buf1.SeekGet( CUtlBuffer::SEEK_HEAD, 0 ); + if( !TGALoader::Load( pImage1Tmp, buf1, width1, height1, imageFormat1, 2.2f, false ) ) + { + printf( "error loading %s\n", pFileName[0] ); + exit( -1 ); + } + + buf2.SeekGet( CUtlBuffer::SEEK_HEAD, 0 ); + if( !TGALoader::Load( pImage2Tmp, buf2, width2, height2, imageFormat2, 2.2f, false ) ) + { + printf( "error loading %s\n", pFileName[1] ); + exit( -1 ); + } + + unsigned char *pImage1 = new unsigned char[ImageLoader::GetMemRequired( width1, height1, 1, IMAGE_FORMAT_ABGR8888, false )]; + unsigned char *pImage2 = new unsigned char[ImageLoader::GetMemRequired( width2, height2, 1, IMAGE_FORMAT_ABGR8888, false )]; + ImageLoader::ConvertImageFormat( pImage1Tmp, imageFormat1, pImage1, IMAGE_FORMAT_ABGR8888, width1, height1, 0, 0 ); + ImageLoader::ConvertImageFormat( pImage2Tmp, imageFormat2, pImage2, IMAGE_FORMAT_ABGR8888, width2, height2, 0, 0 ); + + int sizeInBytes = ImageLoader::SizeInBytes( IMAGE_FORMAT_ABGR8888 ); + float mse = 0.0f; + for( int i = 0; i < width1 * height1 * sizeInBytes; i++ ) + { + float d; + d = ( float )( pImage2[i] - pImage1[i] ); + mse += ( d * d ); + } + + mse /= ( float )( width1 * height1 * sizeInBytes ); + + if ( argc == 3 ) + { + printf( "MSE=%f\n", mse ); + } + else + { + if ( mse > fMSE ) + { + printf( "FAIL" ); + } + else + { + printf( "PASS" ); + } + } + + return 0; +} diff --git a/utils/tgamse/tgamse.vpc b/utils/tgamse/tgamse.vpc new file mode 100644 index 0000000..1d163e7 --- /dev/null +++ b/utils/tgamse/tgamse.vpc @@ -0,0 +1,25 @@ +//----------------------------------------------------------------------------- +// TGAMSE.VPC +// +// Project Script +//----------------------------------------------------------------------------- + +$Macro SRCDIR "..\.." +$Macro OUTBINDIR "$SRCDIR\..\game\bin" + +$Include "$SRCDIR\vpc_scripts\source_exe_con_base.vpc" + +$Project "Tgamse" +{ + $Folder "Source Files" + { + $File "tgamse.cpp" + } + + $Folder "Link Libraries" + { + $Lib bitmap + $Lib mathlib + $Lib tier2 + } +} |