diff --git a/DirectXTex/DirectXTex.h b/DirectXTex/DirectXTex.h index d9fc97e..9a44038 100644 --- a/DirectXTex/DirectXTex.h +++ b/DirectXTex/DirectXTex.h @@ -549,6 +549,10 @@ namespace DirectX CMSE_IGNORE_BLUE = 0x40, CMSE_IGNORE_ALPHA = 0x80, // Ignore the channel when computing MSE + + CMSE_IMAGE1_X2_BIAS = 0x100, + CMSE_IMAGE2_X2_BIAS = 0x200, + // Indicates that image should be scaled and biased before comparison (i.e. UNORM -> SNORM) }; HRESULT ComputeMSE( _In_ const Image& image1, _In_ const Image& image2, _Out_ float& mse, _Out_writes_opt_(4) float* mseV, _In_ DWORD flags = 0 ); diff --git a/DirectXTex/DirectXTexMisc.cpp b/DirectXTex/DirectXTexMisc.cpp index ac29864..6f7b99f 100644 --- a/DirectXTex/DirectXTexMisc.cpp +++ b/DirectXTex/DirectXTexMisc.cpp @@ -84,6 +84,7 @@ static HRESULT _ComputeMSE( _In_ const Image& image1, _In_ const Image& image2, const size_t rowPitch2 = image2.rowPitch; XMVECTOR acc = g_XMZero; + static XMVECTORF32 two = { 2.0f, 2.0f, 2.0f, 2.0f }; for( size_t h = 0; h < image1.height; ++h ) { @@ -102,12 +103,20 @@ static HRESULT _ComputeMSE( _In_ const Image& image1, _In_ const Image& image2, { v1 = XMVectorPow( v1, g_Gamma22 ); } + if ( flags & CMSE_IMAGE1_X2_BIAS ) + { + v1 = XMVectorMultiplyAdd( v1, two, g_XMNegativeOne ); + } XMVECTOR v2 = *(ptr2++); if ( flags & CMSE_IMAGE2_SRGB ) { v2 = XMVectorPow( v2, g_Gamma22 ); } + if ( flags & CMSE_IMAGE2_X2_BIAS ) + { + v1 = XMVectorMultiplyAdd( v2, two, g_XMNegativeOne ); + } // sum[ (I1 - I2)^2 ] XMVECTOR v = XMVectorSubtract( v1, v2 );