2016-08-22 18:26:36 +00:00
//-------------------------------------------------------------------------------------
// DirectXTexp.h
//
// DirectX Texture Library - Private header
//
// Copyright (c) Microsoft Corporation. All rights reserved.
2018-02-24 06:24:46 +00:00
// Licensed under the MIT License.
2016-08-22 18:26:36 +00:00
//
// http://go.microsoft.com/fwlink/?LinkId=248926
//-------------------------------------------------------------------------------------
# pragma once
2017-07-14 23:44:44 +00:00
// Off by default warnings
2019-10-24 23:55:13 +00:00
# pragma warning(disable : 4619 4616 4061 4265 4365 4571 4623 4625 4626 4628 4668 4710 4711 4746 4774 4820 4987 5026 5027 5031 5032 5039 5045 26812)
2018-05-02 00:34:54 +00:00
// C4619/4616 #pragma warning warnings
2017-07-14 23:44:44 +00:00
// C4061 enumerator 'X' in switch of enum 'X' is not explicitly handled by a case label
// C4265 class has virtual functions, but destructor is not virtual
// C4365 signed/unsigned mismatch
// C4571 behavior change
// C4623 default constructor was implicitly defined as deleted
// C4625 copy constructor was implicitly defined as deleted
// C4626 assignment operator was implicitly defined as deleted
2018-01-17 23:59:33 +00:00
// C4628 digraphs not supported
2017-07-14 23:44:44 +00:00
// C4668 not defined as a preprocessor macro
// C4710 function not inlined
// C4711 selected for automatic inline expansion
// C4746 volatile access of '<expression>' is subject to /volatile:<iso|ms> setting
// C4774 format string expected in argument 3 is not a string literal
// C4820 padding added after data member
// C4987 nonstandard extension used
// C5026 move constructor was implicitly defined as deleted
// C5027 move assignment operator was implicitly defined as deleted
// C5031/5032 push/pop mismatches in windows headers
2017-12-05 22:04:26 +00:00
// C5039 pointer or reference to potentially throwing function passed to extern C function under - EHc
2018-04-24 07:30:12 +00:00
// C5045 Spectre mitigation warning
2019-10-24 23:55:13 +00:00
// 26812: The enum type 'x' is unscoped. Prefer 'enum class' over 'enum' (Enum.3).
2017-07-14 23:44:44 +00:00
// Windows 8.1 SDK related Off by default warnings
# pragma warning(disable : 4471 4917 4986 5029)
// C4471 forward declaration of an unscoped enumeration must have an underlying type
// C4917 a GUID can only be associated with a class, interface or namespace
// C4986 exception specification does not match previous declaration
// C5029 nonstandard extension used
2018-06-27 20:10:19 +00:00
// Xbox One XDK related Off by default warnings
# pragma warning(disable : 4643)
// C4643 Forward declaring in namespace std is not permitted by the C++ Standard
2018-06-05 21:34:26 +00:00
# ifdef __INTEL_COMPILER
# pragma warning(disable : 161)
// warning #161: unrecognized #pragma
# endif
2019-05-25 23:00:32 +00:00
# ifdef __clang__
# pragma clang diagnostic ignored "-Wc++98-compat"
# pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
# pragma clang diagnostic ignored "-Wc++98-compat-local-type-template-args"
# pragma clang diagnostic ignored "-Wcovered-switch-default"
# pragma clang diagnostic ignored "-Wfloat-equal"
# pragma clang diagnostic ignored "-Wglobal-constructors"
# pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
# pragma clang diagnostic ignored "-Wlanguage-extension-token"
# pragma clang diagnostic ignored "-Wmissing-variable-declarations"
# pragma clang diagnostic ignored "-Wnested-anon-types"
# pragma clang diagnostic ignored "-Wreserved-id-macro"
# pragma clang diagnostic ignored "-Wswitch-enum"
# pragma clang diagnostic ignored "-Wtautological-type-limit-compare"
# pragma clang diagnostic ignored "-Wunknown-pragmas"
# endif
2019-06-13 00:36:18 +00:00
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
2016-08-22 18:26:36 +00:00
# pragma warning(push)
# pragma warning(disable : 4005)
# define NOMINMAX
# define NODRAWTEXT
# define NOGDI
# define NOBITMAP
# define NOMCX
# define NOSERVICE
# define NOHELP
# pragma warning(pop)
# ifndef _WIN32_WINNT_WIN10
# define _WIN32_WINNT_WIN10 0x0A00
# endif
2019-04-17 00:38:37 +00:00
# include <Windows.h>
2017-01-26 18:23:36 +00:00
# if defined(_XBOX_ONE) && defined(_TITLE)
# include <d3d12_x.h>
# include <d3d11_x.h>
# elif (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
# include <d3d12.h>
# include <d3d11_4.h>
# else
# include <d3d11_1.h>
# endif
2018-06-13 01:07:34 +00:00
# define _XM_NO_XMVECTOR_OVERLOADS_
2019-04-17 00:38:37 +00:00
# include <DirectXMath.h>
# include <DirectXPackedVector.h>
2016-08-22 18:26:36 +00:00
# include <assert.h>
# include <malloc.h>
# include <memory>
# include <vector>
2019-10-04 20:25:44 +00:00
# include <time.h>
2016-08-22 18:26:36 +00:00
# include <stdlib.h>
# include <search.h>
2019-04-17 00:38:37 +00:00
# include <Ole2.h>
2016-08-22 18:26:36 +00:00
2019-04-17 00:38:37 +00:00
# include "DirectXTex.h"
2016-08-22 18:26:36 +00:00
# include <wincodec.h>
# include <wrl\client.h>
# include "scoped.h"
# define TEX_FILTER_MASK 0xF00000
# define XBOX_DXGI_FORMAT_R10G10B10_7E3_A2_FLOAT DXGI_FORMAT(116)
# define XBOX_DXGI_FORMAT_R10G10B10_6E4_A2_FLOAT DXGI_FORMAT(117)
# define XBOX_DXGI_FORMAT_D16_UNORM_S8_UINT DXGI_FORMAT(118)
# define XBOX_DXGI_FORMAT_R16_UNORM_X8_TYPELESS DXGI_FORMAT(119)
# define XBOX_DXGI_FORMAT_X16_TYPELESS_G8_UINT DXGI_FORMAT(120)
# define WIN10_DXGI_FORMAT_P208 DXGI_FORMAT(130)
# define WIN10_DXGI_FORMAT_V208 DXGI_FORMAT(131)
# define WIN10_DXGI_FORMAT_V408 DXGI_FORMAT(132)
# ifndef XBOX_DXGI_FORMAT_R10G10B10_SNORM_A2_UNORM
# define XBOX_DXGI_FORMAT_R10G10B10_SNORM_A2_UNORM DXGI_FORMAT(189)
# endif
# define XBOX_DXGI_FORMAT_R4G4_UNORM DXGI_FORMAT(190)
namespace DirectX
{
//---------------------------------------------------------------------------------
// WIC helper functions
2019-12-13 08:01:17 +00:00
DXGI_FORMAT __cdecl _WICToDXGI ( _In_ const GUID & guid ) noexcept ;
bool __cdecl _DXGIToWIC ( _In_ DXGI_FORMAT format , _Out_ GUID & guid , _In_ bool ignoreRGBvsBGR = false ) noexcept ;
2016-08-22 18:26:36 +00:00
2019-12-13 08:01:17 +00:00
DWORD __cdecl _CheckWICColorSpace ( _In_ const GUID & sourceGUID , _In_ const GUID & targetGUID ) noexcept ;
2016-08-22 18:26:36 +00:00
2019-12-13 08:01:17 +00:00
inline WICBitmapDitherType __cdecl _GetWICDither ( _In_ DWORD flags ) noexcept
2016-08-22 18:26:36 +00:00
{
2018-03-16 19:52:21 +00:00
static_assert ( TEX_FILTER_DITHER = = 0x10000 , " TEX_FILTER_DITHER* flag values don't match mask " ) ;
2016-08-22 18:26:36 +00:00
2017-07-12 07:56:51 +00:00
static_assert ( static_cast < int > ( TEX_FILTER_DITHER ) = = static_cast < int > ( WIC_FLAGS_DITHER ) , " TEX_FILTER_DITHER* should match WIC_FLAGS_DITHER* " ) ;
static_assert ( static_cast < int > ( TEX_FILTER_DITHER_DIFFUSION ) = = static_cast < int > ( WIC_FLAGS_DITHER_DIFFUSION ) , " TEX_FILTER_DITHER* should match WIC_FLAGS_DITHER* " ) ;
2016-08-22 18:26:36 +00:00
2018-03-16 19:52:21 +00:00
switch ( flags & 0xF0000 )
2016-08-22 18:26:36 +00:00
{
2018-03-16 19:52:21 +00:00
case TEX_FILTER_DITHER :
return WICBitmapDitherTypeOrdered4x4 ;
2016-08-22 18:26:36 +00:00
2018-03-16 19:52:21 +00:00
case TEX_FILTER_DITHER_DIFFUSION :
return WICBitmapDitherTypeErrorDiffusion ;
2016-08-22 18:26:36 +00:00
2018-03-16 19:52:21 +00:00
default :
return WICBitmapDitherTypeNone ;
2016-08-22 18:26:36 +00:00
}
}
2019-12-13 08:01:17 +00:00
inline WICBitmapInterpolationMode __cdecl _GetWICInterp ( _In_ DWORD flags ) noexcept
2016-08-22 18:26:36 +00:00
{
2018-03-16 19:52:21 +00:00
static_assert ( TEX_FILTER_POINT = = 0x100000 , " TEX_FILTER_ flag values don't match TEX_FILTER_MASK " ) ;
2016-08-22 18:26:36 +00:00
2017-07-12 07:56:51 +00:00
static_assert ( static_cast < int > ( TEX_FILTER_POINT ) = = static_cast < int > ( WIC_FLAGS_FILTER_POINT ) , " TEX_FILTER_* flags should match WIC_FLAGS_FILTER_* " ) ;
static_assert ( static_cast < int > ( TEX_FILTER_LINEAR ) = = static_cast < int > ( WIC_FLAGS_FILTER_LINEAR ) , " TEX_FILTER_* flags should match WIC_FLAGS_FILTER_* " ) ;
static_assert ( static_cast < int > ( TEX_FILTER_CUBIC ) = = static_cast < int > ( WIC_FLAGS_FILTER_CUBIC ) , " TEX_FILTER_* flags should match WIC_FLAGS_FILTER_* " ) ;
static_assert ( static_cast < int > ( TEX_FILTER_FANT ) = = static_cast < int > ( WIC_FLAGS_FILTER_FANT ) , " TEX_FILTER_* flags should match WIC_FLAGS_FILTER_* " ) ;
2016-08-22 18:26:36 +00:00
2018-03-16 19:52:21 +00:00
switch ( flags & TEX_FILTER_MASK )
2016-08-22 18:26:36 +00:00
{
2018-03-16 19:52:21 +00:00
case TEX_FILTER_POINT :
return WICBitmapInterpolationModeNearestNeighbor ;
2016-08-22 18:26:36 +00:00
2018-03-16 19:52:21 +00:00
case TEX_FILTER_LINEAR :
return WICBitmapInterpolationModeLinear ;
2016-08-22 18:26:36 +00:00
2018-03-16 19:52:21 +00:00
case TEX_FILTER_CUBIC :
return WICBitmapInterpolationModeCubic ;
2016-08-22 18:26:36 +00:00
2018-03-16 19:52:21 +00:00
case TEX_FILTER_FANT :
default :
return WICBitmapInterpolationModeFant ;
2016-08-22 18:26:36 +00:00
}
}
//---------------------------------------------------------------------------------
// Image helper functions
2018-08-03 23:49:30 +00:00
_Success_ ( return ! = false ) bool __cdecl _DetermineImageArray (
2018-03-16 19:52:21 +00:00
_In_ const TexMetadata & metadata , _In_ DWORD cpFlags ,
2019-12-13 08:01:17 +00:00
_Out_ size_t & nImages , _Out_ size_t & pixelSize ) noexcept ;
2016-08-22 18:26:36 +00:00
2018-03-16 19:52:21 +00:00
_Success_ ( return ! = false ) bool __cdecl _SetupImageArray (
_In_reads_bytes_ ( pixelSize ) uint8_t * pMemory , _In_ size_t pixelSize ,
_In_ const TexMetadata & metadata , _In_ DWORD cpFlags ,
2019-12-13 08:01:17 +00:00
_Out_writes_ ( nImages ) Image * images , _In_ size_t nImages ) noexcept ;
2016-08-22 18:26:36 +00:00
//---------------------------------------------------------------------------------
// Conversion helper functions
enum TEXP_SCANLINE_FLAGS
{
TEXP_SCANLINE_NONE = 0 ,
TEXP_SCANLINE_SETALPHA = 0x1 , // Set alpha channel to known opaque value
TEXP_SCANLINE_LEGACY = 0x2 , // Enables specific legacy format conversion cases
} ;
enum CONVERT_FLAGS
{
CONVF_FLOAT = 0x1 ,
CONVF_UNORM = 0x2 ,
CONVF_UINT = 0x4 ,
CONVF_SNORM = 0x8 ,
CONVF_SINT = 0x10 ,
CONVF_DEPTH = 0x20 ,
CONVF_STENCIL = 0x40 ,
CONVF_SHAREDEXP = 0x80 ,
CONVF_BGR = 0x100 ,
CONVF_XR = 0x200 ,
CONVF_PACKED = 0x400 ,
CONVF_BC = 0x800 ,
CONVF_YUV = 0x1000 ,
2016-09-30 07:16:56 +00:00
CONVF_POS_ONLY = 0x2000 ,
2016-08-22 18:26:36 +00:00
CONVF_R = 0x10000 ,
CONVF_G = 0x20000 ,
CONVF_B = 0x40000 ,
CONVF_A = 0x80000 ,
CONVF_RGB_MASK = 0x70000 ,
CONVF_RGBA_MASK = 0xF0000 ,
} ;
2019-12-13 08:01:17 +00:00
DWORD __cdecl _GetConvertFlags ( _In_ DXGI_FORMAT format ) noexcept ;
2018-03-16 19:52:21 +00:00
void __cdecl _CopyScanline (
_When_ ( pDestination = = pSource , _Inout_updates_bytes_ ( outSize ) )
_When_ ( pDestination ! = pSource , _Out_writes_bytes_ ( outSize ) )
void * pDestination , _In_ size_t outSize ,
_In_reads_bytes_ ( inSize ) const void * pSource , _In_ size_t inSize ,
2019-12-13 08:01:17 +00:00
_In_ DXGI_FORMAT format , _In_ DWORD flags ) noexcept ;
2018-03-16 19:52:21 +00:00
void __cdecl _SwizzleScanline (
_When_ ( pDestination = = pSource , _In_ )
_When_ ( pDestination ! = pSource , _Out_writes_bytes_ ( outSize ) )
void * pDestination , _In_ size_t outSize ,
_In_reads_bytes_ ( inSize ) const void * pSource , _In_ size_t inSize ,
2019-12-13 08:01:17 +00:00
_In_ DXGI_FORMAT format , _In_ DWORD flags ) noexcept ;
2016-08-22 18:26:36 +00:00
2018-03-16 19:52:21 +00:00
_Success_ ( return ! = false ) bool __cdecl _ExpandScanline (
_Out_writes_bytes_ ( outSize ) void * pDestination , _In_ size_t outSize ,
_In_ DXGI_FORMAT outFormat ,
_In_reads_bytes_ ( inSize ) const void * pSource , _In_ size_t inSize ,
2019-12-13 08:01:17 +00:00
_In_ DXGI_FORMAT inFormat , _In_ DWORD flags ) noexcept ;
2016-08-22 18:26:36 +00:00
2018-03-16 19:52:21 +00:00
_Success_ ( return ! = false ) bool __cdecl _LoadScanline (
_Out_writes_ ( count ) XMVECTOR * pDestination , _In_ size_t count ,
2019-12-13 08:01:17 +00:00
_In_reads_bytes_ ( size ) const void * pSource , _In_ size_t size , _In_ DXGI_FORMAT format ) noexcept ;
2016-08-22 18:26:36 +00:00
2018-03-16 19:52:21 +00:00
_Success_ ( return ! = false ) bool __cdecl _LoadScanlineLinear (
_Out_writes_ ( count ) XMVECTOR * pDestination , _In_ size_t count ,
2019-12-13 08:01:17 +00:00
_In_reads_bytes_ ( size ) const void * pSource , _In_ size_t size , _In_ DXGI_FORMAT format , _In_ DWORD flags ) noexcept ;
2016-08-22 18:26:36 +00:00
2018-03-16 19:52:21 +00:00
_Success_ ( return ! = false ) bool __cdecl _StoreScanline (
_Out_writes_bytes_ ( size ) void * pDestination , _In_ size_t size , _In_ DXGI_FORMAT format ,
2019-12-13 08:01:17 +00:00
_In_reads_ ( count ) const XMVECTOR * pSource , _In_ size_t count , _In_ float threshold = 0 ) noexcept ;
2016-08-22 18:26:36 +00:00
2018-03-16 19:52:21 +00:00
_Success_ ( return ! = false ) bool __cdecl _StoreScanlineLinear (
_Out_writes_bytes_ ( size ) void * pDestination , _In_ size_t size , _In_ DXGI_FORMAT format ,
2019-12-13 08:01:17 +00:00
_Inout_updates_all_ ( count ) XMVECTOR * pSource , _In_ size_t count , _In_ DWORD flags , _In_ float threshold = 0 ) noexcept ;
2016-08-22 18:26:36 +00:00
2018-03-16 19:52:21 +00:00
_Success_ ( return ! = false ) bool __cdecl _StoreScanlineDither (
_Out_writes_bytes_ ( size ) void * pDestination , _In_ size_t size , _In_ DXGI_FORMAT format ,
_Inout_updates_all_ ( count ) XMVECTOR * pSource , _In_ size_t count , _In_ float threshold , size_t y , size_t z ,
2019-12-13 08:01:17 +00:00
_Inout_updates_all_opt_ ( count + 2 ) XMVECTOR * pDiffusionErrors ) noexcept ;
2016-08-22 18:26:36 +00:00
2019-12-13 08:01:17 +00:00
HRESULT __cdecl _ConvertToR32G32B32A32 ( _In_ const Image & srcImage , _Inout_ ScratchImage & image ) noexcept ;
2016-08-22 18:26:36 +00:00
2019-12-13 08:01:17 +00:00
HRESULT __cdecl _ConvertFromR32G32B32A32 ( _In_ const Image & srcImage , _In_ const Image & destImage ) noexcept ;
HRESULT __cdecl _ConvertFromR32G32B32A32 ( _In_ const Image & srcImage , _In_ DXGI_FORMAT format , _Inout_ ScratchImage & image ) noexcept ;
2018-03-16 19:52:21 +00:00
HRESULT __cdecl _ConvertFromR32G32B32A32 (
_In_reads_ ( nimages ) const Image * srcImages , _In_ size_t nimages , _In_ const TexMetadata & metadata ,
2019-12-13 08:01:17 +00:00
_In_ DXGI_FORMAT format , _Out_ ScratchImage & result ) noexcept ;
2016-08-22 18:26:36 +00:00
2019-12-13 08:01:17 +00:00
HRESULT __cdecl _ConvertToR16G16B16A16 ( _In_ const Image & srcImage , _Inout_ ScratchImage & image ) noexcept ;
2018-08-02 19:31:20 +00:00
2019-12-13 08:01:17 +00:00
HRESULT __cdecl _ConvertFromR16G16B16A16 ( _In_ const Image & srcImage , _In_ const Image & destImage ) noexcept ;
2018-08-02 19:31:20 +00:00
2018-03-16 19:52:21 +00:00
void __cdecl _ConvertScanline (
_Inout_updates_all_ ( count ) XMVECTOR * pBuffer , _In_ size_t count ,
_In_ DXGI_FORMAT outFormat , _In_ DXGI_FORMAT inFormat , _In_ DWORD flags ) ;
2016-08-22 18:26:36 +00:00
//---------------------------------------------------------------------------------
// DDS helper functions
2018-03-16 19:52:21 +00:00
HRESULT __cdecl _EncodeDDSHeader (
_In_ const TexMetadata & metadata , DWORD flags ,
2019-12-13 08:01:17 +00:00
_Out_writes_bytes_to_opt_ ( maxsize , required ) void * pDestination , _In_ size_t maxsize , _Out_ size_t & required ) noexcept ;
2016-08-22 18:26:36 +00:00
2018-02-24 06:42:26 +00:00
} // namespace