Reformat code

This commit is contained in:
Chuck Walbourn 2018-03-16 12:52:21 -07:00
parent 56956f817a
commit 327586970d
14 changed files with 645 additions and 571 deletions

View File

@ -54,34 +54,34 @@ public:
HDRColorA(const HDRColorA& c) : r(c.r), g(c.g), b(c.b), a(c.a) {}
// binary operators
HDRColorA operator + ( const HDRColorA& c ) const
HDRColorA operator + (const HDRColorA& c) const
{
return HDRColorA(r + c.r, g + c.g, b + c.b, a + c.a);
}
HDRColorA operator - ( const HDRColorA& c ) const
HDRColorA operator - (const HDRColorA& c) const
{
return HDRColorA(r - c.r, g - c.g, b - c.b, a - c.a);
}
HDRColorA operator * ( float f ) const
HDRColorA operator * (float f) const
{
return HDRColorA(r * f, g * f, b * f, a * f);
}
HDRColorA operator / ( float f ) const
HDRColorA operator / (float f) const
{
float fInv = 1.0f / f;
return HDRColorA(r * fInv, g * fInv, b * fInv, a * fInv);
}
float operator * ( const HDRColorA& c ) const
float operator * (const HDRColorA& c) const
{
return r * c.r + g * c.g + b * c.b + a * c.a;
}
// assignment operators
HDRColorA& operator += ( const HDRColorA& c )
HDRColorA& operator += (const HDRColorA& c)
{
r += c.r;
g += c.g;
@ -89,8 +89,8 @@ public:
a += c.a;
return *this;
}
HDRColorA& operator -= ( const HDRColorA& c )
HDRColorA& operator -= (const HDRColorA& c)
{
r -= c.r;
g -= c.g;
@ -98,8 +98,8 @@ public:
a -= c.a;
return *this;
}
HDRColorA& operator *= ( float f )
HDRColorA& operator *= (float f)
{
r *= f;
g *= f;
@ -107,8 +107,8 @@ public:
a *= f;
return *this;
}
HDRColorA& operator /= ( float f )
HDRColorA& operator /= (float f)
{
float fInv = 1.0f / f;
r *= fInv;

View File

@ -3229,14 +3229,14 @@ void D3DX_BC7::EmitBlock(const EncodeParams* pEP, size_t uShape, size_t uRotatio
_Use_decl_annotations_
float D3DX_BC7::Refine(const EncodeParams* pEP, size_t uShape, size_t uRotation, size_t uIndexMode)
{
assert( pEP );
assert( uShape < BC7_MAX_SHAPES );
_Analysis_assume_( uShape < BC7_MAX_SHAPES );
assert(pEP);
assert(uShape < BC7_MAX_SHAPES);
_Analysis_assume_(uShape < BC7_MAX_SHAPES);
const LDREndPntPair* aEndPts = pEP->aEndPts[uShape];
const size_t uPartitions = ms_aInfo[pEP->uMode].uPartitions;
assert( uPartitions < BC7_MAX_REGIONS );
_Analysis_assume_( uPartitions < BC7_MAX_REGIONS );
assert(uPartitions < BC7_MAX_REGIONS);
_Analysis_assume_(uPartitions < BC7_MAX_REGIONS);
LDREndPntPair aOrgEndPts[BC7_MAX_REGIONS];
LDREndPntPair aOptEndPts[BC7_MAX_REGIONS];
@ -3247,7 +3247,7 @@ float D3DX_BC7::Refine(const EncodeParams* pEP, size_t uShape, size_t uRotation,
float aOrgErr[BC7_MAX_REGIONS];
float aOptErr[BC7_MAX_REGIONS];
for(size_t p = 0; p <= uPartitions; p++)
for (size_t p = 0; p <= uPartitions; p++)
{
aOrgEndPts[p].A = Quantize(aEndPts[p].A, ms_aInfo[pEP->uMode].RGBAPrecWithP);
aOrgEndPts[p].B = Quantize(aEndPts[p].B, ms_aInfo[pEP->uMode].RGBAPrecWithP);
@ -3258,12 +3258,12 @@ float D3DX_BC7::Refine(const EncodeParams* pEP, size_t uShape, size_t uRotation,
AssignIndices(pEP, uShape, uIndexMode, aOptEndPts, aOptIdx, aOptIdx2, aOptErr);
float fOrgTotErr = 0, fOptTotErr = 0;
for(size_t p = 0; p <= uPartitions; p++)
for (size_t p = 0; p <= uPartitions; p++)
{
fOrgTotErr += aOrgErr[p];
fOptTotErr += aOptErr[p];
}
if(fOptTotErr < fOrgTotErr)
if (fOptTotErr < fOrgTotErr)
{
EmitBlock(pEP, uShape, uRotation, uIndexMode, aOptEndPts, aOptIdx, aOptIdx2);
return fOptTotErr;

View File

@ -45,37 +45,37 @@ namespace
UINT reserved;
};
static_assert( sizeof(ConstantsBC6HBC7) == sizeof(UINT)*8, "Constant buffer size mismatch" );
static_assert(sizeof(ConstantsBC6HBC7) == sizeof(UINT) * 8, "Constant buffer size mismatch");
inline void RunComputeShader( ID3D11DeviceContext* pContext,
ID3D11ComputeShader* shader,
ID3D11ShaderResourceView** pSRVs,
UINT srvCount,
ID3D11Buffer* pCB,
ID3D11UnorderedAccessView* pUAV,
UINT X )
inline void RunComputeShader(ID3D11DeviceContext* pContext,
ID3D11ComputeShader* shader,
ID3D11ShaderResourceView** pSRVs,
UINT srvCount,
ID3D11Buffer* pCB,
ID3D11UnorderedAccessView* pUAV,
UINT X)
{
// Force UAV to nullptr before setting SRV since we are swapping buffers
ID3D11UnorderedAccessView* nullUAV = nullptr;
pContext->CSSetUnorderedAccessViews( 0, 1, &nullUAV, nullptr );
pContext->CSSetUnorderedAccessViews(0, 1, &nullUAV, nullptr);
pContext->CSSetShader( shader, nullptr, 0 );
pContext->CSSetShaderResources( 0, srvCount, pSRVs );
pContext->CSSetUnorderedAccessViews( 0, 1, &pUAV, nullptr );
pContext->CSSetConstantBuffers( 0, 1, &pCB );
pContext->Dispatch( X, 1, 1 );
pContext->CSSetShader(shader, nullptr, 0);
pContext->CSSetShaderResources(0, srvCount, pSRVs);
pContext->CSSetUnorderedAccessViews(0, 1, &pUAV, nullptr);
pContext->CSSetConstantBuffers(0, 1, &pCB);
pContext->Dispatch(X, 1, 1);
}
inline void ResetContext( ID3D11DeviceContext* pContext )
inline void ResetContext(ID3D11DeviceContext* pContext)
{
ID3D11UnorderedAccessView* nullUAV = nullptr;
pContext->CSSetUnorderedAccessViews( 0, 1, &nullUAV, nullptr );
pContext->CSSetUnorderedAccessViews(0, 1, &nullUAV, nullptr);
ID3D11ShaderResourceView* nullSRV[3] = { nullptr, nullptr, nullptr };
pContext->CSSetShaderResources( 0, 3, nullSRV );
pContext->CSSetShaderResources(0, 3, nullSRV);
ID3D11Buffer* nullBuffer[1] = { nullptr };
pContext->CSSetConstantBuffers( 0, 1, nullBuffer );
pContext->CSSetConstantBuffers(0, 1, nullBuffer);
}
};

View File

@ -12,53 +12,53 @@
namespace DirectX
{
class GPUCompressBC
{
public:
GPUCompressBC();
class GPUCompressBC
{
public:
GPUCompressBC();
HRESULT Initialize( _In_ ID3D11Device* pDevice );
HRESULT Initialize(_In_ ID3D11Device* pDevice);
HRESULT Prepare( size_t width, size_t height, DWORD flags, DXGI_FORMAT format, float alphaWeight );
HRESULT Prepare(size_t width, size_t height, DWORD flags, DXGI_FORMAT format, float alphaWeight);
HRESULT Compress( const Image& srcImage, const Image& destImage );
HRESULT Compress(const Image& srcImage, const Image& destImage);
DXGI_FORMAT GetSourceFormat() const { return m_srcformat; }
DXGI_FORMAT GetSourceFormat() const { return m_srcformat; }
private:
DXGI_FORMAT m_bcformat;
DXGI_FORMAT m_srcformat;
float m_alphaWeight;
bool m_bc7_mode02;
bool m_bc7_mode137;
size_t m_width;
size_t m_height;
private:
DXGI_FORMAT m_bcformat;
DXGI_FORMAT m_srcformat;
float m_alphaWeight;
bool m_bc7_mode02;
bool m_bc7_mode137;
size_t m_width;
size_t m_height;
Microsoft::WRL::ComPtr<ID3D11Device> m_device;
Microsoft::WRL::ComPtr<ID3D11DeviceContext> m_context;
Microsoft::WRL::ComPtr<ID3D11Device> m_device;
Microsoft::WRL::ComPtr<ID3D11DeviceContext> m_context;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_err1;
Microsoft::WRL::ComPtr<ID3D11UnorderedAccessView> m_err1UAV;
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_err1SRV;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_err1;
Microsoft::WRL::ComPtr<ID3D11UnorderedAccessView> m_err1UAV;
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_err1SRV;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_err2;
Microsoft::WRL::ComPtr<ID3D11UnorderedAccessView> m_err2UAV;
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_err2SRV;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_err2;
Microsoft::WRL::ComPtr<ID3D11UnorderedAccessView> m_err2UAV;
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_err2SRV;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_output;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_outputCPU;
Microsoft::WRL::ComPtr<ID3D11UnorderedAccessView> m_outputUAV;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_constBuffer;
// Compute shader library
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC6H_tryModeG10CS;
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC6H_tryModeLE10CS;
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC6H_encodeBlockCS;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_output;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_outputCPU;
Microsoft::WRL::ComPtr<ID3D11UnorderedAccessView> m_outputUAV;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_constBuffer;
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC7_tryMode456CS;
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC7_tryMode137CS;
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC7_tryMode02CS;
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC7_encodeBlockCS;
};
// Compute shader library
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC6H_tryModeG10CS;
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC6H_tryModeLE10CS;
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC6H_encodeBlockCS;
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC7_tryMode456CS;
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC7_tryMode137CS;
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC7_tryMode02CS;
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC7_encodeBlockCS;
};
} // namespace

View File

@ -41,21 +41,21 @@ namespace DirectX
//---------------------------------------------------------------------------------
// DXGI Format Utilities
bool __cdecl IsValid( _In_ DXGI_FORMAT fmt );
bool __cdecl IsCompressed( _In_ DXGI_FORMAT fmt );
bool __cdecl IsPacked( _In_ DXGI_FORMAT fmt );
bool __cdecl IsVideo( _In_ DXGI_FORMAT fmt );
bool __cdecl IsPlanar( _In_ DXGI_FORMAT fmt );
bool __cdecl IsPalettized( _In_ DXGI_FORMAT fmt );
bool __cdecl IsDepthStencil(_In_ DXGI_FORMAT fmt );
bool __cdecl IsSRGB( _In_ DXGI_FORMAT fmt );
bool __cdecl IsTypeless( _In_ DXGI_FORMAT fmt, _In_ bool partialTypeless = true );
bool __cdecl IsValid(_In_ DXGI_FORMAT fmt);
bool __cdecl IsCompressed(_In_ DXGI_FORMAT fmt);
bool __cdecl IsPacked(_In_ DXGI_FORMAT fmt);
bool __cdecl IsVideo(_In_ DXGI_FORMAT fmt);
bool __cdecl IsPlanar(_In_ DXGI_FORMAT fmt);
bool __cdecl IsPalettized(_In_ DXGI_FORMAT fmt);
bool __cdecl IsDepthStencil(_In_ DXGI_FORMAT fmt);
bool __cdecl IsSRGB(_In_ DXGI_FORMAT fmt);
bool __cdecl IsTypeless(_In_ DXGI_FORMAT fmt, _In_ bool partialTypeless = true);
bool __cdecl HasAlpha( _In_ DXGI_FORMAT fmt );
bool __cdecl HasAlpha(_In_ DXGI_FORMAT fmt);
size_t __cdecl BitsPerPixel( _In_ DXGI_FORMAT fmt );
size_t __cdecl BitsPerPixel(_In_ DXGI_FORMAT fmt);
size_t __cdecl BitsPerColor( _In_ DXGI_FORMAT fmt );
size_t __cdecl BitsPerColor(_In_ DXGI_FORMAT fmt);
enum CP_FLAGS
{
@ -71,15 +71,16 @@ namespace DirectX
CP_FLAGS_8BPP = 0x40000, // Override with a legacy 8 bits-per-pixel format size
};
void __cdecl ComputePitch( _In_ DXGI_FORMAT fmt, _In_ size_t width, _In_ size_t height,
_Out_ size_t& rowPitch, _Out_ size_t& slicePitch, _In_ DWORD flags = CP_FLAGS_NONE );
void __cdecl ComputePitch(
_In_ DXGI_FORMAT fmt, _In_ size_t width, _In_ size_t height,
_Out_ size_t& rowPitch, _Out_ size_t& slicePitch, _In_ DWORD flags = CP_FLAGS_NONE);
size_t __cdecl ComputeScanlines( _In_ DXGI_FORMAT fmt, _In_ size_t height );
size_t __cdecl ComputeScanlines(_In_ DXGI_FORMAT fmt, _In_ size_t height);
DXGI_FORMAT __cdecl MakeSRGB( _In_ DXGI_FORMAT fmt );
DXGI_FORMAT __cdecl MakeTypeless( _In_ DXGI_FORMAT fmt );
DXGI_FORMAT __cdecl MakeTypelessUNORM( _In_ DXGI_FORMAT fmt );
DXGI_FORMAT __cdecl MakeTypelessFLOAT( _In_ DXGI_FORMAT fmt );
DXGI_FORMAT __cdecl MakeSRGB(_In_ DXGI_FORMAT fmt);
DXGI_FORMAT __cdecl MakeTypeless(_In_ DXGI_FORMAT fmt);
DXGI_FORMAT __cdecl MakeTypelessUNORM(_In_ DXGI_FORMAT fmt);
DXGI_FORMAT __cdecl MakeTypelessFLOAT(_In_ DXGI_FORMAT fmt);
//---------------------------------------------------------------------------------
// Texture metadata
@ -124,14 +125,14 @@ namespace DirectX
DXGI_FORMAT format;
TEX_DIMENSION dimension;
size_t __cdecl ComputeIndex( _In_ size_t mip, _In_ size_t item, _In_ size_t slice ) const;
size_t __cdecl ComputeIndex(_In_ size_t mip, _In_ size_t item, _In_ size_t slice) const;
// Returns size_t(-1) to indicate an out-of-range error
bool __cdecl IsCubemap() const { return (miscFlags & TEX_MISC_TEXTURECUBE) != 0; }
// Helper for miscFlags
bool __cdecl IsPMAlpha() const { return ((miscFlags2 & TEX_MISC2_ALPHA_MODE_MASK) == TEX_ALPHA_MODE_PREMULTIPLIED) != 0; }
void __cdecl SetAlphaMode( TEX_ALPHA_MODE mode ) { miscFlags2 = (miscFlags2 & ~TEX_MISC2_ALPHA_MODE_MASK) | static_cast<uint32_t>(mode); }
void __cdecl SetAlphaMode(TEX_ALPHA_MODE mode) { miscFlags2 = (miscFlags2 & ~TEX_MISC2_ALPHA_MODE_MASK) | static_cast<uint32_t>(mode); }
TEX_ALPHA_MODE __cdecl GetAlphaMode() const { return static_cast<TEX_ALPHA_MODE>(miscFlags2 & TEX_MISC2_ALPHA_MODE_MASK); }
// Helpers for miscFlags2
@ -206,28 +207,40 @@ namespace DirectX
// Filtering mode to use for any required image resizing (only needed when loading arrays of differently sized images; defaults to Fant)
};
HRESULT __cdecl GetMetadataFromDDSMemory( _In_reads_bytes_(size) const void* pSource, _In_ size_t size, _In_ DWORD flags,
_Out_ TexMetadata& metadata );
HRESULT __cdecl GetMetadataFromDDSFile( _In_z_ const wchar_t* szFile, _In_ DWORD flags,
_Out_ TexMetadata& metadata );
HRESULT __cdecl GetMetadataFromDDSMemory(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_In_ DWORD flags,
_Out_ TexMetadata& metadata);
HRESULT __cdecl GetMetadataFromDDSFile(
_In_z_ const wchar_t* szFile,
_In_ DWORD flags,
_Out_ TexMetadata& metadata);
HRESULT __cdecl GetMetadataFromHDRMemory( _In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_Out_ TexMetadata& metadata );
HRESULT __cdecl GetMetadataFromHDRFile( _In_z_ const wchar_t* szFile,
_Out_ TexMetadata& metadata );
HRESULT __cdecl GetMetadataFromHDRMemory(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_Out_ TexMetadata& metadata);
HRESULT __cdecl GetMetadataFromHDRFile(
_In_z_ const wchar_t* szFile,
_Out_ TexMetadata& metadata);
HRESULT __cdecl GetMetadataFromTGAMemory( _In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_Out_ TexMetadata& metadata );
HRESULT __cdecl GetMetadataFromTGAFile( _In_z_ const wchar_t* szFile,
_Out_ TexMetadata& metadata );
HRESULT __cdecl GetMetadataFromTGAMemory(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_Out_ TexMetadata& metadata);
HRESULT __cdecl GetMetadataFromTGAFile(
_In_z_ const wchar_t* szFile,
_Out_ TexMetadata& metadata);
HRESULT __cdecl GetMetadataFromWICMemory( _In_reads_bytes_(size) const void* pSource, _In_ size_t size, _In_ DWORD flags,
_Out_ TexMetadata& metadata,
_In_opt_ std::function<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr);
HRESULT __cdecl GetMetadataFromWICMemory(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_In_ DWORD flags,
_Out_ TexMetadata& metadata,
_In_opt_ std::function<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr);
HRESULT __cdecl GetMetadataFromWICFile( _In_z_ const wchar_t* szFile, _In_ DWORD flags,
_Out_ TexMetadata& metadata,
_In_opt_ std::function<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr);
HRESULT __cdecl GetMetadataFromWICFile(
_In_z_ const wchar_t* szFile,
_In_ DWORD flags,
_Out_ TexMetadata& metadata,
_In_opt_ std::function<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr);
//---------------------------------------------------------------------------------
// Bitmap image container
@ -255,21 +268,21 @@ namespace DirectX
ScratchImage(const ScratchImage&) = delete;
ScratchImage& operator=(const ScratchImage&) = delete;
HRESULT __cdecl Initialize( _In_ const TexMetadata& mdata, _In_ DWORD flags = CP_FLAGS_NONE );
HRESULT __cdecl Initialize(_In_ const TexMetadata& mdata, _In_ DWORD flags = CP_FLAGS_NONE);
HRESULT __cdecl Initialize1D( _In_ DXGI_FORMAT fmt, _In_ size_t length, _In_ size_t arraySize, _In_ size_t mipLevels, _In_ DWORD flags = CP_FLAGS_NONE );
HRESULT __cdecl Initialize2D( _In_ DXGI_FORMAT fmt, _In_ size_t width, _In_ size_t height, _In_ size_t arraySize, _In_ size_t mipLevels, _In_ DWORD flags = CP_FLAGS_NONE );
HRESULT __cdecl Initialize3D( _In_ DXGI_FORMAT fmt, _In_ size_t width, _In_ size_t height, _In_ size_t depth, _In_ size_t mipLevels, _In_ DWORD flags = CP_FLAGS_NONE );
HRESULT __cdecl InitializeCube( _In_ DXGI_FORMAT fmt, _In_ size_t width, _In_ size_t height, _In_ size_t nCubes, _In_ size_t mipLevels, _In_ DWORD flags = CP_FLAGS_NONE );
HRESULT __cdecl Initialize1D(_In_ DXGI_FORMAT fmt, _In_ size_t length, _In_ size_t arraySize, _In_ size_t mipLevels, _In_ DWORD flags = CP_FLAGS_NONE);
HRESULT __cdecl Initialize2D(_In_ DXGI_FORMAT fmt, _In_ size_t width, _In_ size_t height, _In_ size_t arraySize, _In_ size_t mipLevels, _In_ DWORD flags = CP_FLAGS_NONE);
HRESULT __cdecl Initialize3D(_In_ DXGI_FORMAT fmt, _In_ size_t width, _In_ size_t height, _In_ size_t depth, _In_ size_t mipLevels, _In_ DWORD flags = CP_FLAGS_NONE);
HRESULT __cdecl InitializeCube(_In_ DXGI_FORMAT fmt, _In_ size_t width, _In_ size_t height, _In_ size_t nCubes, _In_ size_t mipLevels, _In_ DWORD flags = CP_FLAGS_NONE);
HRESULT __cdecl InitializeFromImage( _In_ const Image& srcImage, _In_ bool allow1D = false, _In_ DWORD flags = CP_FLAGS_NONE );
HRESULT __cdecl InitializeArrayFromImages( _In_reads_(nImages) const Image* images, _In_ size_t nImages, _In_ bool allow1D = false, _In_ DWORD flags = CP_FLAGS_NONE );
HRESULT __cdecl InitializeCubeFromImages( _In_reads_(nImages) const Image* images, _In_ size_t nImages, _In_ DWORD flags = CP_FLAGS_NONE );
HRESULT __cdecl Initialize3DFromImages( _In_reads_(depth) const Image* images, _In_ size_t depth, _In_ DWORD flags = CP_FLAGS_NONE );
HRESULT __cdecl InitializeFromImage(_In_ const Image& srcImage, _In_ bool allow1D = false, _In_ DWORD flags = CP_FLAGS_NONE);
HRESULT __cdecl InitializeArrayFromImages(_In_reads_(nImages) const Image* images, _In_ size_t nImages, _In_ bool allow1D = false, _In_ DWORD flags = CP_FLAGS_NONE);
HRESULT __cdecl InitializeCubeFromImages(_In_reads_(nImages) const Image* images, _In_ size_t nImages, _In_ DWORD flags = CP_FLAGS_NONE);
HRESULT __cdecl Initialize3DFromImages(_In_reads_(depth) const Image* images, _In_ size_t depth, _In_ DWORD flags = CP_FLAGS_NONE);
void __cdecl Release();
bool __cdecl OverrideFormat( _In_ DXGI_FORMAT f );
bool __cdecl OverrideFormat(_In_ DXGI_FORMAT f);
const TexMetadata& __cdecl GetMetadata() const { return m_metadata; }
const Image* __cdecl GetImage(_In_ size_t mip, _In_ size_t item, _In_ size_t slice) const;
@ -304,7 +317,7 @@ namespace DirectX
Blob(const Blob&) = delete;
Blob& operator=(const Blob&) = delete;
HRESULT __cdecl Initialize( _In_ size_t size );
HRESULT __cdecl Initialize(_In_ size_t size);
void __cdecl Release();
@ -322,58 +335,81 @@ namespace DirectX
// Image I/O
// DDS operations
HRESULT __cdecl LoadFromDDSMemory( _In_reads_bytes_(size) const void* pSource, _In_ size_t size, _In_ DWORD flags,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image );
HRESULT __cdecl LoadFromDDSFile( _In_z_ const wchar_t* szFile, _In_ DWORD flags,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image );
HRESULT __cdecl LoadFromDDSMemory(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_In_ DWORD flags,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image);
HRESULT __cdecl LoadFromDDSFile(
_In_z_ const wchar_t* szFile,
_In_ DWORD flags,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image);
HRESULT __cdecl SaveToDDSMemory( _In_ const Image& image, _In_ DWORD flags,
_Out_ Blob& blob );
HRESULT __cdecl SaveToDDSMemory( _In_reads_(nimages) const Image* images, _In_ size_t nimages, _In_ const TexMetadata& metadata, _In_ DWORD flags,
_Out_ Blob& blob );
HRESULT __cdecl SaveToDDSMemory(
_In_ const Image& image,
_In_ DWORD flags,
_Out_ Blob& blob);
HRESULT __cdecl SaveToDDSMemory(
_In_reads_(nimages) const Image* images, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DWORD flags,
_Out_ Blob& blob);
HRESULT __cdecl SaveToDDSFile( _In_ const Image& image, _In_ DWORD flags, _In_z_ const wchar_t* szFile );
HRESULT __cdecl SaveToDDSFile( _In_reads_(nimages) const Image* images, _In_ size_t nimages, _In_ const TexMetadata& metadata, _In_ DWORD flags, _In_z_ const wchar_t* szFile );
HRESULT __cdecl SaveToDDSFile(_In_ const Image& image, _In_ DWORD flags, _In_z_ const wchar_t* szFile);
HRESULT __cdecl SaveToDDSFile(
_In_reads_(nimages) const Image* images, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DWORD flags, _In_z_ const wchar_t* szFile);
// HDR operations
HRESULT __cdecl LoadFromHDRMemory( _In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image );
HRESULT __cdecl LoadFromHDRFile( _In_z_ const wchar_t* szFile,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image );
HRESULT __cdecl LoadFromHDRMemory(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image);
HRESULT __cdecl LoadFromHDRFile(
_In_z_ const wchar_t* szFile,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image);
HRESULT __cdecl SaveToHDRMemory( _In_ const Image& image, _Out_ Blob& blob );
HRESULT __cdecl SaveToHDRFile( _In_ const Image& image, _In_z_ const wchar_t* szFile );
HRESULT __cdecl SaveToHDRMemory(_In_ const Image& image, _Out_ Blob& blob);
HRESULT __cdecl SaveToHDRFile(_In_ const Image& image, _In_z_ const wchar_t* szFile);
// TGA operations
HRESULT __cdecl LoadFromTGAMemory( _In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image );
HRESULT __cdecl LoadFromTGAFile( _In_z_ const wchar_t* szFile,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image );
HRESULT __cdecl LoadFromTGAMemory(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image);
HRESULT __cdecl LoadFromTGAFile(
_In_z_ const wchar_t* szFile,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image);
HRESULT __cdecl SaveToTGAMemory( _In_ const Image& image, _Out_ Blob& blob );
HRESULT __cdecl SaveToTGAFile( _In_ const Image& image, _In_z_ const wchar_t* szFile );
HRESULT __cdecl SaveToTGAMemory(_In_ const Image& image, _Out_ Blob& blob);
HRESULT __cdecl SaveToTGAFile(_In_ const Image& image, _In_z_ const wchar_t* szFile);
// WIC operations
HRESULT __cdecl LoadFromWICMemory( _In_reads_bytes_(size) const void* pSource, _In_ size_t size, _In_ DWORD flags,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image,
_In_opt_ std::function<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr);
HRESULT __cdecl LoadFromWICFile( _In_z_ const wchar_t* szFile, _In_ DWORD flags,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image,
_In_opt_ std::function<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr);
HRESULT __cdecl LoadFromWICMemory(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_In_ DWORD flags,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image,
_In_opt_ std::function<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr);
HRESULT __cdecl LoadFromWICFile(
_In_z_ const wchar_t* szFile, _In_ DWORD flags,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image,
_In_opt_ std::function<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr);
HRESULT __cdecl SaveToWICMemory( _In_ const Image& image, _In_ DWORD flags, _In_ REFGUID guidContainerFormat,
_Out_ Blob& blob, _In_opt_ const GUID* targetFormat = nullptr,
_In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = nullptr );
HRESULT __cdecl SaveToWICMemory( _In_count_(nimages) const Image* images, _In_ size_t nimages, _In_ DWORD flags, _In_ REFGUID guidContainerFormat,
_Out_ Blob& blob, _In_opt_ const GUID* targetFormat = nullptr,
_In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = nullptr );
HRESULT __cdecl SaveToWICMemory(
_In_ const Image& image, _In_ DWORD flags, _In_ REFGUID guidContainerFormat,
_Out_ Blob& blob, _In_opt_ const GUID* targetFormat = nullptr,
_In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = nullptr);
HRESULT __cdecl SaveToWICMemory(
_In_count_(nimages) const Image* images, _In_ size_t nimages,
_In_ DWORD flags, _In_ REFGUID guidContainerFormat,
_Out_ Blob& blob, _In_opt_ const GUID* targetFormat = nullptr,
_In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = nullptr);
HRESULT __cdecl SaveToWICFile( _In_ const Image& image, _In_ DWORD flags, _In_ REFGUID guidContainerFormat,
_In_z_ const wchar_t* szFile, _In_opt_ const GUID* targetFormat = nullptr,
_In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = nullptr );
HRESULT __cdecl SaveToWICFile( _In_count_(nimages) const Image* images, _In_ size_t nimages, _In_ DWORD flags, _In_ REFGUID guidContainerFormat,
_In_z_ const wchar_t* szFile, _In_opt_ const GUID* targetFormat = nullptr,
_In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = nullptr );
HRESULT __cdecl SaveToWICFile(
_In_ const Image& image, _In_ DWORD flags, _In_ REFGUID guidContainerFormat,
_In_z_ const wchar_t* szFile, _In_opt_ const GUID* targetFormat = nullptr,
_In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = nullptr);
HRESULT __cdecl SaveToWICFile(
_In_count_(nimages) const Image* images, _In_ size_t nimages,
_In_ DWORD flags, _In_ REFGUID guidContainerFormat,
_In_z_ const wchar_t* szFile, _In_opt_ const GUID* targetFormat = nullptr,
_In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = nullptr);
//---------------------------------------------------------------------------------
// Texture conversion, resizing, mipmap generation, and block compression
@ -388,9 +424,10 @@ namespace DirectX
TEX_FR_FLIP_VERTICAL = 0x10,
};
HRESULT __cdecl FlipRotate( _In_ const Image& srcImage, _In_ DWORD flags, _Out_ ScratchImage& image );
HRESULT __cdecl FlipRotate( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DWORD flags, _Out_ ScratchImage& result );
HRESULT __cdecl FlipRotate(_In_ const Image& srcImage, _In_ DWORD flags, _Out_ ScratchImage& image);
HRESULT __cdecl FlipRotate(
_In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DWORD flags, _Out_ ScratchImage& result);
// Flip and/or rotate image
enum TEX_FILTER_FLAGS
@ -400,11 +437,11 @@ namespace DirectX
TEX_FILTER_WRAP_U = 0x1,
TEX_FILTER_WRAP_V = 0x2,
TEX_FILTER_WRAP_W = 0x4,
TEX_FILTER_WRAP = ( TEX_FILTER_WRAP_U | TEX_FILTER_WRAP_V | TEX_FILTER_WRAP_W ),
TEX_FILTER_WRAP = (TEX_FILTER_WRAP_U | TEX_FILTER_WRAP_V | TEX_FILTER_WRAP_W),
TEX_FILTER_MIRROR_U = 0x10,
TEX_FILTER_MIRROR_V = 0x20,
TEX_FILTER_MIRROR_W = 0x40,
TEX_FILTER_MIRROR = ( TEX_FILTER_MIRROR_U | TEX_FILTER_MIRROR_V | TEX_FILTER_MIRROR_W ),
TEX_FILTER_MIRROR = (TEX_FILTER_MIRROR_U | TEX_FILTER_MIRROR_V | TEX_FILTER_MIRROR_W),
// Wrap vs. Mirror vs. Clamp filtering options
TEX_FILTER_SEPARATE_ALPHA = 0x100,
@ -434,7 +471,7 @@ namespace DirectX
TEX_FILTER_SRGB_IN = 0x1000000,
TEX_FILTER_SRGB_OUT = 0x2000000,
TEX_FILTER_SRGB = ( TEX_FILTER_SRGB_IN | TEX_FILTER_SRGB_OUT ),
TEX_FILTER_SRGB = (TEX_FILTER_SRGB_IN | TEX_FILTER_SRGB_OUT),
// sRGB <-> RGB for use in conversion operations
// if the input format type is IsSRGB(), then SRGB_IN is on by default
// if the output format type is IsSRGB(), then SRGB_OUT is on by default
@ -446,38 +483,48 @@ namespace DirectX
// Forces use of the WIC path even when logic would have picked a non-WIC path when both are an option
};
HRESULT __cdecl Resize( _In_ const Image& srcImage, _In_ size_t width, _In_ size_t height, _In_ DWORD filter,
_Out_ ScratchImage& image );
HRESULT __cdecl Resize( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ size_t width, _In_ size_t height, _In_ DWORD filter, _Out_ ScratchImage& result );
HRESULT __cdecl Resize(
_In_ const Image& srcImage, _In_ size_t width, _In_ size_t height,
_In_ DWORD filter,
_Out_ ScratchImage& image);
HRESULT __cdecl Resize(
_In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ size_t width, _In_ size_t height, _In_ DWORD filter, _Out_ ScratchImage& result);
// Resize the image to width x height. Defaults to Fant filtering.
// Note for a complex resize, the result will always have mipLevels == 1
const float TEX_THRESHOLD_DEFAULT = 0.5f;
// Default value for alpha threshold used when converting to 1-bit alpha
HRESULT __cdecl Convert( _In_ const Image& srcImage, _In_ DXGI_FORMAT format, _In_ DWORD filter, _In_ float threshold,
_Out_ ScratchImage& image );
HRESULT __cdecl Convert( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DXGI_FORMAT format, _In_ DWORD filter, _In_ float threshold, _Out_ ScratchImage& result );
HRESULT __cdecl Convert(
_In_ const Image& srcImage, _In_ DXGI_FORMAT format, _In_ DWORD filter, _In_ float threshold,
_Out_ ScratchImage& image);
HRESULT __cdecl Convert(
_In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DXGI_FORMAT format, _In_ DWORD filter, _In_ float threshold, _Out_ ScratchImage& result);
// Convert the image to a new format
HRESULT __cdecl ConvertToSinglePlane( _In_ const Image& srcImage, _Out_ ScratchImage& image );
HRESULT __cdecl ConvertToSinglePlane( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_Out_ ScratchImage& image );
HRESULT __cdecl ConvertToSinglePlane(_In_ const Image& srcImage, _Out_ ScratchImage& image);
HRESULT __cdecl ConvertToSinglePlane(
_In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_Out_ ScratchImage& image);
// Converts the image from a planar format to an equivalent non-planar format
HRESULT __cdecl GenerateMipMaps( _In_ const Image& baseImage, _In_ DWORD filter, _In_ size_t levels,
_Inout_ ScratchImage& mipChain, _In_ bool allow1D = false );
HRESULT __cdecl GenerateMipMaps( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DWORD filter, _In_ size_t levels, _Inout_ ScratchImage& mipChain );
HRESULT __cdecl GenerateMipMaps(
_In_ const Image& baseImage, _In_ DWORD filter, _In_ size_t levels,
_Inout_ ScratchImage& mipChain, _In_ bool allow1D = false);
HRESULT __cdecl GenerateMipMaps(
_In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DWORD filter, _In_ size_t levels, _Inout_ ScratchImage& mipChain);
// levels of '0' indicates a full mipchain, otherwise is generates that number of total levels (including the source base image)
// Defaults to Fant filtering which is equivalent to a box filter
HRESULT __cdecl GenerateMipMaps3D( _In_reads_(depth) const Image* baseImages, _In_ size_t depth, _In_ DWORD filter, _In_ size_t levels,
_Out_ ScratchImage& mipChain );
HRESULT __cdecl GenerateMipMaps3D( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DWORD filter, _In_ size_t levels, _Out_ ScratchImage& mipChain );
HRESULT __cdecl GenerateMipMaps3D(
_In_reads_(depth) const Image* baseImages, _In_ size_t depth, _In_ DWORD filter, _In_ size_t levels,
_Out_ ScratchImage& mipChain);
HRESULT __cdecl GenerateMipMaps3D(
_In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DWORD filter, _In_ size_t levels, _Out_ ScratchImage& mipChain);
// levels of '0' indicates a full mipchain, otherwise is generates that number of total levels (including the source base image)
// Defaults to Fant filtering which is equivalent to a box filter
@ -493,14 +540,15 @@ namespace DirectX
TEX_PMALPHA_SRGB_IN = 0x1000000,
TEX_PMALPHA_SRGB_OUT = 0x2000000,
TEX_PMALPHA_SRGB = ( TEX_PMALPHA_SRGB_IN | TEX_PMALPHA_SRGB_OUT ),
TEX_PMALPHA_SRGB = (TEX_PMALPHA_SRGB_IN | TEX_PMALPHA_SRGB_OUT),
// if the input format type is IsSRGB(), then SRGB_IN is on by default
// if the output format type is IsSRGB(), then SRGB_OUT is on by default
};
HRESULT __cdecl PremultiplyAlpha( _In_ const Image& srcImage, _In_ DWORD flags, _Out_ ScratchImage& image );
HRESULT __cdecl PremultiplyAlpha( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DWORD flags, _Out_ ScratchImage& result );
HRESULT __cdecl PremultiplyAlpha(_In_ const Image& srcImage, _In_ DWORD flags, _Out_ ScratchImage& image);
HRESULT __cdecl PremultiplyAlpha(
_In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DWORD flags, _Out_ ScratchImage& result);
// Converts to/from a premultiplied alpha version of the texture
enum TEX_COMPRESS_FLAGS
@ -527,7 +575,7 @@ namespace DirectX
TEX_COMPRESS_SRGB_IN = 0x1000000,
TEX_COMPRESS_SRGB_OUT = 0x2000000,
TEX_COMPRESS_SRGB = ( TEX_COMPRESS_SRGB_IN | TEX_COMPRESS_SRGB_OUT ),
TEX_COMPRESS_SRGB = (TEX_COMPRESS_SRGB_IN | TEX_COMPRESS_SRGB_OUT),
// if the input format type is IsSRGB(), then SRGB_IN is on by default
// if the output format type is IsSRGB(), then SRGB_OUT is on by default
@ -535,23 +583,28 @@ namespace DirectX
// Compress is free to use multithreading to improve performance (by default it does not use multithreading)
};
HRESULT __cdecl Compress( _In_ const Image& srcImage, _In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float threshold,
_Out_ ScratchImage& cImage );
HRESULT __cdecl Compress( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float threshold, _Out_ ScratchImage& cImages );
HRESULT __cdecl Compress(
_In_ const Image& srcImage, _In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float threshold,
_Out_ ScratchImage& cImage);
HRESULT __cdecl Compress(
_In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float threshold, _Out_ ScratchImage& cImages);
// Note that threshold is only used by BC1. TEX_THRESHOLD_DEFAULT is a typical value to use
#if defined(__d3d11_h__) || defined(__d3d11_x_h__)
HRESULT __cdecl Compress( _In_ ID3D11Device* pDevice, _In_ const Image& srcImage, _In_ DXGI_FORMAT format, _In_ DWORD compress,
_In_ float alphaWeight, _Out_ ScratchImage& image );
HRESULT __cdecl Compress( _In_ ID3D11Device* pDevice, _In_ const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float alphaWeight, _Out_ ScratchImage& cImages );
HRESULT __cdecl Compress(
_In_ ID3D11Device* pDevice, _In_ const Image& srcImage, _In_ DXGI_FORMAT format, _In_ DWORD compress,
_In_ float alphaWeight, _Out_ ScratchImage& image);
HRESULT __cdecl Compress(
_In_ ID3D11Device* pDevice, _In_ const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float alphaWeight, _Out_ ScratchImage& cImages);
// DirectCompute-based compression (alphaWeight is only used by BC7. 1.0 is the typical value to use)
#endif
HRESULT __cdecl Decompress( _In_ const Image& cImage, _In_ DXGI_FORMAT format, _Out_ ScratchImage& image );
HRESULT __cdecl Decompress( _In_reads_(nimages) const Image* cImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DXGI_FORMAT format, _Out_ ScratchImage& images );
HRESULT __cdecl Decompress(_In_ const Image& cImage, _In_ DXGI_FORMAT format, _Out_ ScratchImage& image);
HRESULT __cdecl Decompress(
_In_reads_(nimages) const Image* cImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DXGI_FORMAT format, _Out_ ScratchImage& images);
//---------------------------------------------------------------------------------
// Normal map operations
@ -580,10 +633,12 @@ namespace DirectX
// Computes a crude occlusion term stored in the alpha channel
};
HRESULT __cdecl ComputeNormalMap( _In_ const Image& srcImage, _In_ DWORD flags, _In_ float amplitude,
_In_ DXGI_FORMAT format, _Out_ ScratchImage& normalMap );
HRESULT __cdecl ComputeNormalMap( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DWORD flags, _In_ float amplitude, _In_ DXGI_FORMAT format, _Out_ ScratchImage& normalMaps );
HRESULT __cdecl ComputeNormalMap(
_In_ const Image& srcImage, _In_ DWORD flags, _In_ float amplitude,
_In_ DXGI_FORMAT format, _Out_ ScratchImage& normalMap);
HRESULT __cdecl ComputeNormalMap(
_In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DWORD flags, _In_ float amplitude, _In_ DXGI_FORMAT format, _Out_ ScratchImage& normalMaps);
//---------------------------------------------------------------------------------
// Misc image operations
@ -596,11 +651,12 @@ namespace DirectX
size_t h;
Rect() = default;
Rect( size_t _x, size_t _y, size_t _w, size_t _h ) : x(_x), y(_y), w(_w), h(_h) {}
Rect(size_t _x, size_t _y, size_t _w, size_t _h) : x(_x), y(_y), w(_w), h(_h) {}
};
HRESULT __cdecl CopyRectangle( _In_ const Image& srcImage, _In_ const Rect& srcRect, _In_ const Image& dstImage,
_In_ DWORD filter, _In_ size_t xOffset, _In_ size_t yOffset );
HRESULT __cdecl CopyRectangle(
_In_ const Image& srcImage, _In_ const Rect& srcRect, _In_ const Image& dstImage,
_In_ DWORD filter, _In_ size_t xOffset, _In_ size_t yOffset);
enum CMSE_FLAGS
{
@ -621,21 +677,25 @@ namespace DirectX
// Indicates that image should be scaled and biased before comparison (i.e. UNORM -> SNORM)
};
HRESULT __cdecl ComputeMSE( _In_ const Image& image1, _In_ const Image& image2, _Out_ float& mse, _Out_writes_opt_(4) float* mseV, _In_ DWORD flags = 0 );
HRESULT __cdecl ComputeMSE(_In_ const Image& image1, _In_ const Image& image2, _Out_ float& mse, _Out_writes_opt_(4) float* mseV, _In_ DWORD flags = 0);
HRESULT __cdecl EvaluateImage( _In_ const Image& image,
_In_ std::function<void __cdecl(_In_reads_(width) const XMVECTOR* pixels, size_t width, size_t y)> pixelFunc );
HRESULT __cdecl EvaluateImage( _In_reads_(nimages) const Image* images, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ std::function<void __cdecl(_In_reads_(width) const XMVECTOR* pixels, size_t width, size_t y)> pixelFunc );
HRESULT __cdecl EvaluateImage(
_In_ const Image& image,
_In_ std::function<void __cdecl(_In_reads_(width) const XMVECTOR* pixels, size_t width, size_t y)> pixelFunc);
HRESULT __cdecl EvaluateImage(
_In_reads_(nimages) const Image* images, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ std::function<void __cdecl(_In_reads_(width) const XMVECTOR* pixels, size_t width, size_t y)> pixelFunc);
HRESULT __cdecl TransformImage( _In_ const Image& image,
_In_ std::function<void __cdecl(_Out_writes_(width) XMVECTOR* outPixels,
_In_reads_(width) const XMVECTOR* inPixels, size_t width, size_t y)> pixelFunc,
ScratchImage& result );
HRESULT __cdecl TransformImage( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ std::function<void __cdecl(_Out_writes_(width) XMVECTOR* outPixels,
_In_reads_(width) const XMVECTOR* inPixels, size_t width, size_t y)> pixelFunc,
ScratchImage& result );
HRESULT __cdecl TransformImage(
_In_ const Image& image,
_In_ std::function<void __cdecl(_Out_writes_(width) XMVECTOR* outPixels,
_In_reads_(width) const XMVECTOR* inPixels, size_t width, size_t y)> pixelFunc,
ScratchImage& result);
HRESULT __cdecl TransformImage(
_In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ std::function<void __cdecl(_Out_writes_(width) XMVECTOR* outPixels,
_In_reads_(width) const XMVECTOR* inPixels, size_t width, size_t y)> pixelFunc,
ScratchImage& result);
//---------------------------------------------------------------------------------
// WIC utility code
@ -653,51 +713,59 @@ namespace DirectX
REFGUID __cdecl GetWICCodec(_In_ WICCodecs codec);
IWICImagingFactory* __cdecl GetWICFactory( bool& iswic2 );
void __cdecl SetWICFactory( _In_opt_ IWICImagingFactory* pWIC);
IWICImagingFactory* __cdecl GetWICFactory(bool& iswic2);
void __cdecl SetWICFactory(_In_opt_ IWICImagingFactory* pWIC);
//---------------------------------------------------------------------------------
// Direct3D 11 functions
#if defined(__d3d11_h__) || defined(__d3d11_x_h__)
bool __cdecl IsSupportedTexture( _In_ ID3D11Device* pDevice, _In_ const TexMetadata& metadata );
bool __cdecl IsSupportedTexture(_In_ ID3D11Device* pDevice, _In_ const TexMetadata& metadata);
HRESULT __cdecl CreateTexture( _In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_Outptr_ ID3D11Resource** ppResource );
HRESULT __cdecl CreateTexture(
_In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_Outptr_ ID3D11Resource** ppResource);
HRESULT __cdecl CreateShaderResourceView( _In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_Outptr_ ID3D11ShaderResourceView** ppSRV );
HRESULT __cdecl CreateShaderResourceView(
_In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_Outptr_ ID3D11ShaderResourceView** ppSRV);
HRESULT __cdecl CreateTextureEx( _In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ D3D11_USAGE usage, _In_ unsigned int bindFlags, _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags, _In_ bool forceSRGB,
_Outptr_ ID3D11Resource** ppResource );
HRESULT __cdecl CreateTextureEx(
_In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ D3D11_USAGE usage, _In_ unsigned int bindFlags, _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags, _In_ bool forceSRGB,
_Outptr_ ID3D11Resource** ppResource);
HRESULT __cdecl CreateShaderResourceViewEx( _In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ D3D11_USAGE usage, _In_ unsigned int bindFlags, _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags, _In_ bool forceSRGB,
_Outptr_ ID3D11ShaderResourceView** ppSRV );
HRESULT __cdecl CreateShaderResourceViewEx(
_In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ D3D11_USAGE usage, _In_ unsigned int bindFlags, _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags, _In_ bool forceSRGB,
_Outptr_ ID3D11ShaderResourceView** ppSRV);
HRESULT __cdecl CaptureTexture( _In_ ID3D11Device* pDevice, _In_ ID3D11DeviceContext* pContext, _In_ ID3D11Resource* pSource, _Out_ ScratchImage& result );
HRESULT __cdecl CaptureTexture(_In_ ID3D11Device* pDevice, _In_ ID3D11DeviceContext* pContext, _In_ ID3D11Resource* pSource, _Out_ ScratchImage& result);
#endif
//---------------------------------------------------------------------------------
// Direct3D 12 functions
#if defined(__d3d12_h__) || defined(__d3d12_x_h__)
bool __cdecl IsSupportedTexture( _In_ ID3D12Device* pDevice, _In_ const TexMetadata& metadata );
bool __cdecl IsSupportedTexture(_In_ ID3D12Device* pDevice, _In_ const TexMetadata& metadata);
HRESULT __cdecl CreateTexture( _In_ ID3D12Device* pDevice, _In_ const TexMetadata& metadata,
_Outptr_ ID3D12Resource** ppResource );
HRESULT __cdecl CreateTexture(
_In_ ID3D12Device* pDevice, _In_ const TexMetadata& metadata,
_Outptr_ ID3D12Resource** ppResource);
HRESULT __cdecl CreateTextureEx( _In_ ID3D12Device* pDevice, _In_ const TexMetadata& metadata,
_In_ D3D12_RESOURCE_FLAGS resFlags, _In_ bool forceSRGB,
_Outptr_ ID3D12Resource** ppResource );
HRESULT __cdecl CreateTextureEx(
_In_ ID3D12Device* pDevice, _In_ const TexMetadata& metadata,
_In_ D3D12_RESOURCE_FLAGS resFlags, _In_ bool forceSRGB,
_Outptr_ ID3D12Resource** ppResource);
HRESULT __cdecl PrepareUpload( _In_ ID3D12Device* pDevice,
_In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
std::vector<D3D12_SUBRESOURCE_DATA>& subresources );
HRESULT __cdecl PrepareUpload(
_In_ ID3D12Device* pDevice,
_In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
std::vector<D3D12_SUBRESOURCE_DATA>& subresources);
HRESULT __cdecl CaptureTexture( _In_ ID3D12CommandQueue* pCommandQueue, _In_ ID3D12Resource* pSource, _In_ bool isCubeMap,
_Out_ ScratchImage& result,
_In_ D3D12_RESOURCE_STATES beforeState = D3D12_RESOURCE_STATE_RENDER_TARGET,
_In_ D3D12_RESOURCE_STATES afterState = D3D12_RESOURCE_STATE_RENDER_TARGET );
HRESULT __cdecl CaptureTexture(
_In_ ID3D12CommandQueue* pCommandQueue, _In_ ID3D12Resource* pSource, _In_ bool isCubeMap,
_Out_ ScratchImage& result,
_In_ D3D12_RESOURCE_STATES beforeState = D3D12_RESOURCE_STATE_RENDER_TARGET,
_In_ D3D12_RESOURCE_STATES afterState = D3D12_RESOURCE_STATE_RENDER_TARGET);
#endif
#include "DirectXTex.inl"

View File

@ -16,76 +16,76 @@
//=====================================================================================
_Use_decl_annotations_
inline bool __cdecl IsValid( DXGI_FORMAT fmt )
inline bool __cdecl IsValid(DXGI_FORMAT fmt)
{
return ( static_cast<size_t>(fmt) >= 1 && static_cast<size_t>(fmt) <= 190 );
return (static_cast<size_t>(fmt) >= 1 && static_cast<size_t>(fmt) <= 190);
}
_Use_decl_annotations_
inline bool __cdecl IsCompressed(DXGI_FORMAT fmt)
{
switch ( fmt )
switch (fmt)
{
case DXGI_FORMAT_BC1_TYPELESS:
case DXGI_FORMAT_BC1_UNORM:
case DXGI_FORMAT_BC1_UNORM_SRGB:
case DXGI_FORMAT_BC2_TYPELESS:
case DXGI_FORMAT_BC2_UNORM:
case DXGI_FORMAT_BC2_UNORM_SRGB:
case DXGI_FORMAT_BC3_TYPELESS:
case DXGI_FORMAT_BC3_UNORM:
case DXGI_FORMAT_BC3_UNORM_SRGB:
case DXGI_FORMAT_BC4_TYPELESS:
case DXGI_FORMAT_BC4_UNORM:
case DXGI_FORMAT_BC4_SNORM:
case DXGI_FORMAT_BC5_TYPELESS:
case DXGI_FORMAT_BC5_UNORM:
case DXGI_FORMAT_BC5_SNORM:
case DXGI_FORMAT_BC6H_TYPELESS:
case DXGI_FORMAT_BC6H_UF16:
case DXGI_FORMAT_BC6H_SF16:
case DXGI_FORMAT_BC7_TYPELESS:
case DXGI_FORMAT_BC7_UNORM:
case DXGI_FORMAT_BC7_UNORM_SRGB:
return true;
case DXGI_FORMAT_BC1_TYPELESS:
case DXGI_FORMAT_BC1_UNORM:
case DXGI_FORMAT_BC1_UNORM_SRGB:
case DXGI_FORMAT_BC2_TYPELESS:
case DXGI_FORMAT_BC2_UNORM:
case DXGI_FORMAT_BC2_UNORM_SRGB:
case DXGI_FORMAT_BC3_TYPELESS:
case DXGI_FORMAT_BC3_UNORM:
case DXGI_FORMAT_BC3_UNORM_SRGB:
case DXGI_FORMAT_BC4_TYPELESS:
case DXGI_FORMAT_BC4_UNORM:
case DXGI_FORMAT_BC4_SNORM:
case DXGI_FORMAT_BC5_TYPELESS:
case DXGI_FORMAT_BC5_UNORM:
case DXGI_FORMAT_BC5_SNORM:
case DXGI_FORMAT_BC6H_TYPELESS:
case DXGI_FORMAT_BC6H_UF16:
case DXGI_FORMAT_BC6H_SF16:
case DXGI_FORMAT_BC7_TYPELESS:
case DXGI_FORMAT_BC7_UNORM:
case DXGI_FORMAT_BC7_UNORM_SRGB:
return true;
default:
return false;
default:
return false;
}
}
_Use_decl_annotations_
inline bool __cdecl IsPalettized(DXGI_FORMAT fmt)
{
switch( fmt )
switch (fmt)
{
case DXGI_FORMAT_AI44:
case DXGI_FORMAT_IA44:
case DXGI_FORMAT_P8:
case DXGI_FORMAT_A8P8:
return true;
case DXGI_FORMAT_AI44:
case DXGI_FORMAT_IA44:
case DXGI_FORMAT_P8:
case DXGI_FORMAT_A8P8:
return true;
default:
return false;
default:
return false;
}
}
_Use_decl_annotations_
inline bool __cdecl IsSRGB(DXGI_FORMAT fmt)
{
switch( fmt )
switch (fmt)
{
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
case DXGI_FORMAT_BC1_UNORM_SRGB:
case DXGI_FORMAT_BC2_UNORM_SRGB:
case DXGI_FORMAT_BC3_UNORM_SRGB:
case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
case DXGI_FORMAT_BC7_UNORM_SRGB:
return true;
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
case DXGI_FORMAT_BC1_UNORM_SRGB:
case DXGI_FORMAT_BC2_UNORM_SRGB:
case DXGI_FORMAT_BC3_UNORM_SRGB:
case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
case DXGI_FORMAT_BC7_UNORM_SRGB:
return true;
default:
return false;
default:
return false;
}
}
@ -105,7 +105,7 @@ inline HRESULT __cdecl SaveToDDSMemory(const Image& image, DWORD flags, Blob& bl
mdata.format = image.format;
mdata.dimension = TEX_DIMENSION_TEXTURE2D;
return SaveToDDSMemory( &image, 1, mdata, flags, blob );
return SaveToDDSMemory(&image, 1, mdata, flags, blob);
}
_Use_decl_annotations_
@ -120,5 +120,5 @@ inline HRESULT __cdecl SaveToDDSFile(const Image& image, DWORD flags, const wcha
mdata.format = image.format;
mdata.dimension = TEX_DIMENSION_TEXTURE2D;
return SaveToDDSFile( &image, 1, mdata, flags, szFile );
return SaveToDDSFile(&image, 1, mdata, flags, szFile);
}

View File

@ -714,41 +714,41 @@ bool DirectX::_ExpandScanline(
// Loads an image row into standard RGBA XMVECTOR (aligned) array
//-------------------------------------------------------------------------------------
#define LOAD_SCANLINE( type, func )\
if ( size >= sizeof(type) )\
if (size >= sizeof(type))\
{\
const type * __restrict sPtr = reinterpret_cast<const type*>(pSource);\
for( size_t icount = 0; icount < ( size - sizeof(type) + 1 ); icount += sizeof(type) )\
for(size_t icount = 0; icount < (size - sizeof(type) + 1); icount += sizeof(type))\
{\
if ( dPtr >= ePtr ) break;\
*(dPtr++) = func( sPtr++ );\
if (dPtr >= ePtr) break;\
*(dPtr++) = func(sPtr++);\
}\
return true;\
}\
return false;
#define LOAD_SCANLINE3( type, func, defvec )\
if ( size >= sizeof(type) )\
if (size >= sizeof(type))\
{\
const type * __restrict sPtr = reinterpret_cast<const type*>(pSource);\
for( size_t icount = 0; icount < ( size - sizeof(type) + 1 ); icount += sizeof(type) )\
for(size_t icount = 0; icount < (size - sizeof(type) + 1); icount += sizeof(type))\
{\
XMVECTOR v = func( sPtr++ );\
if ( dPtr >= ePtr ) break;\
*(dPtr++) = XMVectorSelect( defvec, v, g_XMSelect1110 );\
XMVECTOR v = func(sPtr++);\
if (dPtr >= ePtr) break;\
*(dPtr++) = XMVectorSelect(defvec, v, g_XMSelect1110);\
}\
return true;\
}\
return false;
#define LOAD_SCANLINE2( type, func, defvec )\
if ( size >= sizeof(type) )\
if (size >= sizeof(type))\
{\
const type * __restrict sPtr = reinterpret_cast<const type*>(pSource);\
for( size_t icount = 0; icount < ( size - sizeof(type) + 1 ); icount += sizeof(type) )\
for(size_t icount = 0; icount < (size - sizeof(type) + 1); icount += sizeof(type))\
{\
XMVECTOR v = func( sPtr++ );\
if ( dPtr >= ePtr ) break;\
*(dPtr++) = XMVectorSelect( defvec, v, g_XMSelect1100 );\
XMVECTOR v = func(sPtr++);\
if (dPtr >= ePtr) break;\
*(dPtr++) = XMVectorSelect(defvec, v, g_XMSelect1100);\
}\
return true;\
}\
@ -1590,13 +1590,13 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline(
// Stores an image row from standard RGBA XMVECTOR (aligned) array
//-------------------------------------------------------------------------------------
#define STORE_SCANLINE( type, func )\
if ( size >= sizeof(type) )\
if (size >= sizeof(type))\
{\
type * __restrict dPtr = reinterpret_cast<type*>(pDestination);\
for( size_t icount = 0; icount < ( size - sizeof(type) + 1 ); icount += sizeof(type) )\
for(size_t icount = 0; icount < (size - sizeof(type) + 1); icount += sizeof(type))\
{\
if ( sPtr >= ePtr ) break;\
func( dPtr++, *sPtr++ );\
if (sPtr >= ePtr) break;\
func(dPtr++, *sPtr++);\
}\
return true; \
}\
@ -3632,55 +3632,55 @@ namespace
const XMVECTORF32 g_ErrorWeight7 = { { { 7.f / 16.f, 7.f / 16.f, 7.f / 16.f, 7.f / 16.f } } };
#define STORE_SCANLINE( type, scalev, clampzero, norm, itype, mask, row, bgr ) \
if ( size >= sizeof(type) ) \
if (size >= sizeof(type)) \
{ \
type * __restrict dest = reinterpret_cast<type*>(pDestination); \
for( size_t i = 0; i < count; ++i ) \
for(size_t i = 0; i < count; ++i) \
{ \
ptrdiff_t index = static_cast<ptrdiff_t>( ( row & 1 ) ? ( count - i - 1 ) : i ); \
ptrdiff_t delta = ( row & 1 ) ? -2 : 0; \
ptrdiff_t index = static_cast<ptrdiff_t>((row & 1) ? (count - i - 1) : i ); \
ptrdiff_t delta = (row & 1) ? -2 : 0; \
\
XMVECTOR v = sPtr[ index ]; \
if ( bgr ) { v = XMVectorSwizzle<2, 1, 0, 3>( v ); } \
if ( norm && clampzero ) v = XMVectorSaturate( v ) ; \
else if ( clampzero ) v = XMVectorClamp( v, g_XMZero, scalev ); \
else if ( norm ) v = XMVectorClamp( v, g_XMNegativeOne, g_XMOne ); \
else v = XMVectorClamp( v, XMVectorAdd( XMVectorNegate( scalev ), g_XMOne ), scalev ); \
v = XMVectorAdd( v, vError ); \
if ( norm ) v = XMVectorMultiply( v, scalev ); \
if (bgr) { v = XMVectorSwizzle<2, 1, 0, 3>(v); } \
if (norm && clampzero) v = XMVectorSaturate(v) ; \
else if (clampzero) v = XMVectorClamp(v, g_XMZero, scalev); \
else if (norm) v = XMVectorClamp(v, g_XMNegativeOne, g_XMOne); \
else v = XMVectorClamp(v, XMVectorAdd(XMVectorNegate(scalev), g_XMOne), scalev); \
v = XMVectorAdd(v, vError); \
if (norm) v = XMVectorMultiply(v, scalev); \
\
XMVECTOR target; \
if ( pDiffusionErrors ) \
if (pDiffusionErrors) \
{ \
target = XMVectorRound( v ); \
vError = XMVectorSubtract( v, target ); \
if (norm) vError = XMVectorDivide( vError, scalev ); \
target = XMVectorRound(v); \
vError = XMVectorSubtract(v, target); \
if (norm) vError = XMVectorDivide(vError, scalev); \
\
/* Distribute error to next scanline and next pixel */ \
pDiffusionErrors[ index-delta ] = XMVectorMultiplyAdd( g_ErrorWeight3, vError, pDiffusionErrors[ index-delta ] ); \
pDiffusionErrors[ index+1 ] = XMVectorMultiplyAdd( g_ErrorWeight5, vError, pDiffusionErrors[ index+1 ] ); \
pDiffusionErrors[ index+2+delta ] = XMVectorMultiplyAdd( g_ErrorWeight1, vError, pDiffusionErrors[ index+2+delta ] ); \
vError = XMVectorMultiply( vError, g_ErrorWeight7 ); \
pDiffusionErrors[ index-delta ] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[ index-delta ]); \
pDiffusionErrors[ index+1 ] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[ index+1 ]); \
pDiffusionErrors[ index+2+delta ] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[ index+2+delta ]); \
vError = XMVectorMultiply(vError, g_ErrorWeight7); \
} \
else \
{ \
/* Applied ordered dither */ \
target = XMVectorAdd( v, ordered[ index & 3 ] ); \
target = XMVectorRound( target ); \
target = XMVectorAdd(v, ordered[ index & 3 ]); \
target = XMVectorRound(target); \
} \
\
target = XMVectorMin( scalev, target ); \
target = XMVectorMax( (clampzero) ? g_XMZero : ( XMVectorAdd( XMVectorNegate( scalev ), g_XMOne ) ), target ); \
target = XMVectorMin(scalev, target); \
target = XMVectorMax((clampzero) ? g_XMZero : (XMVectorAdd(XMVectorNegate(scalev), g_XMOne)), target); \
\
XMFLOAT4A tmp; \
XMStoreFloat4A( &tmp, target ); \
XMStoreFloat4A(&tmp, target); \
\
auto dPtr = &dest[ index ]; \
if (dPtr >= ePtr) break; \
dPtr->x = static_cast<itype>( tmp.x ) & mask; \
dPtr->y = static_cast<itype>( tmp.y ) & mask; \
dPtr->z = static_cast<itype>( tmp.z ) & mask; \
dPtr->w = static_cast<itype>( tmp.w ) & mask; \
dPtr->x = static_cast<itype>(tmp.x) & mask; \
dPtr->y = static_cast<itype>(tmp.y) & mask; \
dPtr->z = static_cast<itype>(tmp.z) & mask; \
dPtr->w = static_cast<itype>(tmp.w) & mask; \
} \
return true; \
} \
@ -3688,52 +3688,52 @@ namespace
#define STORE_SCANLINE2( type, scalev, clampzero, norm, itype, mask, row ) \
/* The 2 component cases are always bgr=false */ \
if ( size >= sizeof(type) ) \
if (size >= sizeof(type)) \
{ \
type * __restrict dest = reinterpret_cast<type*>(pDestination); \
for( size_t i = 0; i < count; ++i ) \
for(size_t i = 0; i < count; ++i) \
{ \
ptrdiff_t index = static_cast<ptrdiff_t>( ( row & 1 ) ? ( count - i - 1 ) : i ); \
ptrdiff_t delta = ( row & 1 ) ? -2 : 0; \
ptrdiff_t index = static_cast<ptrdiff_t>((row & 1) ? (count - i - 1) : i ); \
ptrdiff_t delta = (row & 1) ? -2 : 0; \
\
XMVECTOR v = sPtr[ index ]; \
if ( norm && clampzero ) v = XMVectorSaturate( v ) ; \
else if ( clampzero ) v = XMVectorClamp( v, g_XMZero, scalev ); \
else if ( norm ) v = XMVectorClamp( v, g_XMNegativeOne, g_XMOne ); \
else v = XMVectorClamp( v, XMVectorAdd( XMVectorNegate( scalev ), g_XMOne ), scalev ); \
v = XMVectorAdd( v, vError ); \
if ( norm ) v = XMVectorMultiply( v, scalev ); \
if (norm && clampzero) v = XMVectorSaturate(v) ; \
else if (clampzero) v = XMVectorClamp(v, g_XMZero, scalev); \
else if (norm) v = XMVectorClamp(v, g_XMNegativeOne, g_XMOne); \
else v = XMVectorClamp(v, XMVectorAdd(XMVectorNegate(scalev), g_XMOne), scalev); \
v = XMVectorAdd(v, vError); \
if (norm) v = XMVectorMultiply(v, scalev); \
\
XMVECTOR target; \
if ( pDiffusionErrors ) \
if (pDiffusionErrors) \
{ \
target = XMVectorRound( v ); \
vError = XMVectorSubtract( v, target ); \
if (norm) vError = XMVectorDivide( vError, scalev ); \
target = XMVectorRound(v); \
vError = XMVectorSubtract(v, target); \
if (norm) vError = XMVectorDivide(vError, scalev); \
\
/* Distribute error to next scanline and next pixel */ \
pDiffusionErrors[ index-delta ] = XMVectorMultiplyAdd( g_ErrorWeight3, vError, pDiffusionErrors[ index-delta ] ); \
pDiffusionErrors[ index+1 ] = XMVectorMultiplyAdd( g_ErrorWeight5, vError, pDiffusionErrors[ index+1 ] ); \
pDiffusionErrors[ index+2+delta ] = XMVectorMultiplyAdd( g_ErrorWeight1, vError, pDiffusionErrors[ index+2+delta ] ); \
vError = XMVectorMultiply( vError, g_ErrorWeight7 ); \
pDiffusionErrors[ index-delta ] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[ index-delta ]); \
pDiffusionErrors[ index+1 ] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[ index+1 ]); \
pDiffusionErrors[ index+2+delta ] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[ index+2+delta ]); \
vError = XMVectorMultiply(vError, g_ErrorWeight7); \
} \
else \
{ \
/* Applied ordered dither */ \
target = XMVectorAdd( v, ordered[ index & 3 ] ); \
target = XMVectorRound( target ); \
target = XMVectorAdd(v, ordered[ index & 3 ]); \
target = XMVectorRound(target); \
} \
\
target = XMVectorMin( scalev, target ); \
target = XMVectorMax( (clampzero) ? g_XMZero : ( XMVectorAdd( XMVectorNegate( scalev ), g_XMOne ) ), target ); \
target = XMVectorMin(scalev, target); \
target = XMVectorMax((clampzero) ? g_XMZero : (XMVectorAdd(XMVectorNegate(scalev), g_XMOne)), target); \
\
XMFLOAT4A tmp; \
XMStoreFloat4A( &tmp, target ); \
XMStoreFloat4A(&tmp, target); \
\
auto dPtr = &dest[ index ]; \
if (dPtr >= ePtr) break; \
dPtr->x = static_cast<itype>( tmp.x ) & mask; \
dPtr->y = static_cast<itype>( tmp.y ) & mask; \
dPtr->x = static_cast<itype>(tmp.x) & mask; \
dPtr->y = static_cast<itype>(tmp.y) & mask; \
} \
return true; \
} \
@ -3741,48 +3741,48 @@ namespace
#define STORE_SCANLINE1( type, scalev, clampzero, norm, mask, row, selectw ) \
/* The 1 component cases are always bgr=false */ \
if ( size >= sizeof(type) ) \
if (size >= sizeof(type)) \
{ \
type * __restrict dest = reinterpret_cast<type*>(pDestination); \
for( size_t i = 0; i < count; ++i ) \
for(size_t i = 0; i < count; ++i) \
{ \
ptrdiff_t index = static_cast<ptrdiff_t>( ( row & 1 ) ? ( count - i - 1 ) : i ); \
ptrdiff_t delta = ( row & 1 ) ? -2 : 0; \
ptrdiff_t index = static_cast<ptrdiff_t>((row & 1) ? (count - i - 1) : i ); \
ptrdiff_t delta = (row & 1) ? -2 : 0; \
\
XMVECTOR v = sPtr[ index ]; \
if ( norm && clampzero ) v = XMVectorSaturate( v ) ; \
else if ( clampzero ) v = XMVectorClamp( v, g_XMZero, scalev ); \
else if ( norm ) v = XMVectorClamp( v, g_XMNegativeOne, g_XMOne ); \
else v = XMVectorClamp( v, XMVectorAdd( XMVectorNegate( scalev ), g_XMOne ), scalev ); \
v = XMVectorAdd( v, vError ); \
if ( norm ) v = XMVectorMultiply( v, scalev ); \
if (norm && clampzero) v = XMVectorSaturate(v) ; \
else if (clampzero) v = XMVectorClamp(v, g_XMZero, scalev); \
else if (norm) v = XMVectorClamp(v, g_XMNegativeOne, g_XMOne); \
else v = XMVectorClamp(v, XMVectorAdd(XMVectorNegate(scalev), g_XMOne), scalev); \
v = XMVectorAdd(v, vError); \
if (norm) v = XMVectorMultiply(v, scalev); \
\
XMVECTOR target; \
if ( pDiffusionErrors ) \
if (pDiffusionErrors) \
{ \
target = XMVectorRound( v ); \
vError = XMVectorSubtract( v, target ); \
if (norm) vError = XMVectorDivide( vError, scalev ); \
target = XMVectorRound(v); \
vError = XMVectorSubtract(v, target); \
if (norm) vError = XMVectorDivide(vError, scalev); \
\
/* Distribute error to next scanline and next pixel */ \
pDiffusionErrors[ index-delta ] = XMVectorMultiplyAdd( g_ErrorWeight3, vError, pDiffusionErrors[ index-delta ] ); \
pDiffusionErrors[ index+1 ] = XMVectorMultiplyAdd( g_ErrorWeight5, vError, pDiffusionErrors[ index+1 ] ); \
pDiffusionErrors[ index+2+delta ] = XMVectorMultiplyAdd( g_ErrorWeight1, vError, pDiffusionErrors[ index+2+delta ] ); \
vError = XMVectorMultiply( vError, g_ErrorWeight7 ); \
pDiffusionErrors[ index-delta ] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[ index-delta ]); \
pDiffusionErrors[ index+1 ] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[ index+1 ]); \
pDiffusionErrors[ index+2+delta ] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[ index+2+delta ]); \
vError = XMVectorMultiply(vError, g_ErrorWeight7); \
} \
else \
{ \
/* Applied ordered dither */ \
target = XMVectorAdd( v, ordered[ index & 3 ] ); \
target = XMVectorRound( target ); \
target = XMVectorAdd(v, ordered[ index & 3 ]); \
target = XMVectorRound(target); \
} \
\
target = XMVectorMin( scalev, target ); \
target = XMVectorMax( (clampzero) ? g_XMZero : ( XMVectorAdd( XMVectorNegate( scalev ), g_XMOne ) ), target ); \
target = XMVectorMin(scalev, target); \
target = XMVectorMax((clampzero) ? g_XMZero : (XMVectorAdd(XMVectorNegate(scalev), g_XMOne)), target); \
\
auto dPtr = &dest[ index ]; \
if (dPtr >= ePtr) break; \
*dPtr = static_cast<type>( (selectw) ? XMVectorGetW( target ) : XMVectorGetX( target ) ) & mask; \
*dPtr = static_cast<type>((selectw) ? XMVectorGetW(target) : XMVectorGetX(target)) & mask; \
} \
return true; \
} \
@ -4563,21 +4563,21 @@ namespace
{\
size_t rowPitch = srcImage.rowPitch;\
\
auto sourceE = reinterpret_cast<const srcType*>( pSrc + srcImage.slicePitch );\
auto pSrcUV = pSrc + ( srcImage.height * rowPitch );\
auto sourceE = reinterpret_cast<const srcType*>(pSrc + srcImage.slicePitch);\
auto pSrcUV = pSrc + (srcImage.height * rowPitch);\
\
for( size_t y = 0; y < srcImage.height; y+= 2 )\
for(size_t y = 0; y < srcImage.height; y+= 2)\
{\
auto sPtrY0 = reinterpret_cast<const srcType*>( pSrc );\
auto sPtrY2 = reinterpret_cast<const srcType*>( pSrc + rowPitch );\
auto sPtrUV = reinterpret_cast<const srcType*>( pSrcUV );\
auto sPtrY0 = reinterpret_cast<const srcType*>(pSrc);\
auto sPtrY2 = reinterpret_cast<const srcType*>(pSrc + rowPitch);\
auto sPtrUV = reinterpret_cast<const srcType*>(pSrcUV);\
\
destType * __restrict dPtr0 = reinterpret_cast<destType*>(pDest);\
destType * __restrict dPtr1 = reinterpret_cast<destType*>(pDest + destImage.rowPitch);\
\
for( size_t x = 0; x < srcImage.width; x+= 2 )\
for(size_t x = 0; x < srcImage.width; x+= 2)\
{\
if ( (sPtrUV+1) >= sourceE ) break;\
if ((sPtrUV+1) >= sourceE) break;\
\
srcType u = *(sPtrUV++);\
srcType v = *(sPtrUV++);\

View File

@ -1149,7 +1149,7 @@ namespace
if (pixelSize > size)
{
return HRESULT_FROM_WIN32( ERROR_HANDLE_EOF );
return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF);
}
std::unique_ptr<Image[]> timages(new (std::nothrow) Image[nimages]);
@ -1733,7 +1733,7 @@ HRESULT DirectX::LoadFromDDSFile(
if (remaining < image.GetPixelsSize())
{
image.Release();
return HRESULT_FROM_WIN32( ERROR_HANDLE_EOF );
return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF);
}
if (!ReadFile(hFile.get(), image.GetPixels(), static_cast<DWORD>(image.GetPixelsSize()), &bytesRead, nullptr))

View File

@ -126,66 +126,67 @@ namespace DirectX
{
//---------------------------------------------------------------------------------
// WIC helper functions
DXGI_FORMAT __cdecl _WICToDXGI( _In_ const GUID& guid );
bool __cdecl _DXGIToWIC( _In_ DXGI_FORMAT format, _Out_ GUID& guid, _In_ bool ignoreRGBvsBGR = false );
DXGI_FORMAT __cdecl _WICToDXGI(_In_ const GUID& guid);
bool __cdecl _DXGIToWIC(_In_ DXGI_FORMAT format, _Out_ GUID& guid, _In_ bool ignoreRGBvsBGR = false);
DWORD __cdecl _CheckWICColorSpace( _In_ const GUID& sourceGUID, _In_ const GUID& targetGUID );
DWORD __cdecl _CheckWICColorSpace(_In_ const GUID& sourceGUID, _In_ const GUID& targetGUID);
inline WICBitmapDitherType __cdecl _GetWICDither( _In_ DWORD flags )
inline WICBitmapDitherType __cdecl _GetWICDither(_In_ DWORD flags)
{
static_assert( TEX_FILTER_DITHER == 0x10000, "TEX_FILTER_DITHER* flag values don't match mask" );
static_assert(TEX_FILTER_DITHER == 0x10000, "TEX_FILTER_DITHER* flag values don't match mask");
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*");
switch( flags & 0xF0000 )
switch (flags & 0xF0000)
{
case TEX_FILTER_DITHER:
return WICBitmapDitherTypeOrdered4x4;
case TEX_FILTER_DITHER:
return WICBitmapDitherTypeOrdered4x4;
case TEX_FILTER_DITHER_DIFFUSION:
return WICBitmapDitherTypeErrorDiffusion;
case TEX_FILTER_DITHER_DIFFUSION:
return WICBitmapDitherTypeErrorDiffusion;
default:
return WICBitmapDitherTypeNone;
default:
return WICBitmapDitherTypeNone;
}
}
inline WICBitmapInterpolationMode __cdecl _GetWICInterp( _In_ DWORD flags )
inline WICBitmapInterpolationMode __cdecl _GetWICInterp(_In_ DWORD flags)
{
static_assert( TEX_FILTER_POINT == 0x100000, "TEX_FILTER_ flag values don't match TEX_FILTER_MASK" );
static_assert(TEX_FILTER_POINT == 0x100000, "TEX_FILTER_ flag values don't match TEX_FILTER_MASK");
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_*");
switch( flags & TEX_FILTER_MASK )
switch (flags & TEX_FILTER_MASK)
{
case TEX_FILTER_POINT:
return WICBitmapInterpolationModeNearestNeighbor;
case TEX_FILTER_POINT:
return WICBitmapInterpolationModeNearestNeighbor;
case TEX_FILTER_LINEAR:
return WICBitmapInterpolationModeLinear;
case TEX_FILTER_LINEAR:
return WICBitmapInterpolationModeLinear;
case TEX_FILTER_CUBIC:
return WICBitmapInterpolationModeCubic;
case TEX_FILTER_CUBIC:
return WICBitmapInterpolationModeCubic;
case TEX_FILTER_FANT:
default:
return WICBitmapInterpolationModeFant;
case TEX_FILTER_FANT:
default:
return WICBitmapInterpolationModeFant;
}
}
//---------------------------------------------------------------------------------
// Image helper functions
void __cdecl _DetermineImageArray( _In_ const TexMetadata& metadata, _In_ DWORD cpFlags,
_Out_ size_t& nImages, _Out_ size_t& pixelSize );
void __cdecl _DetermineImageArray(
_In_ const TexMetadata& metadata, _In_ DWORD cpFlags,
_Out_ size_t& nImages, _Out_ size_t& pixelSize);
_Success_(return != false)
bool __cdecl _SetupImageArray( _In_reads_bytes_(pixelSize) uint8_t *pMemory, _In_ size_t pixelSize,
_In_ const TexMetadata& metadata, _In_ DWORD cpFlags,
_Out_writes_(nImages) Image* images, _In_ size_t nImages );
_Success_(return != false) bool __cdecl _SetupImageArray(
_In_reads_bytes_(pixelSize) uint8_t *pMemory, _In_ size_t pixelSize,
_In_ const TexMetadata& metadata, _In_ DWORD cpFlags,
_Out_writes_(nImages) Image* images, _In_ size_t nImages);
//---------------------------------------------------------------------------------
// Conversion helper functions
@ -221,60 +222,65 @@ namespace DirectX
CONVF_RGBA_MASK = 0xF0000,
};
DWORD __cdecl _GetConvertFlags( _In_ DXGI_FORMAT format );
DWORD __cdecl _GetConvertFlags(_In_ DXGI_FORMAT format);
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,
_In_ DXGI_FORMAT format, _In_ DWORD flags );
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,
_In_ DXGI_FORMAT format, _In_ DWORD flags);
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,
_In_ DXGI_FORMAT format, _In_ DWORD flags );
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,
_In_ DXGI_FORMAT format, _In_ DWORD flags);
_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,
_In_ DXGI_FORMAT inFormat, _In_ DWORD flags );
_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,
_In_ DXGI_FORMAT inFormat, _In_ DWORD flags);
_Success_(return != false)
bool __cdecl _LoadScanline( _Out_writes_(count) XMVECTOR* pDestination, _In_ size_t count,
_In_reads_bytes_(size) const void* pSource, _In_ size_t size, _In_ DXGI_FORMAT format );
_Success_(return != false) bool __cdecl _LoadScanline(
_Out_writes_(count) XMVECTOR* pDestination, _In_ size_t count,
_In_reads_bytes_(size) const void* pSource, _In_ size_t size, _In_ DXGI_FORMAT format);
_Success_(return != false)
bool __cdecl _LoadScanlineLinear( _Out_writes_(count) XMVECTOR* pDestination, _In_ size_t count,
_In_reads_bytes_(size) const void* pSource, _In_ size_t size, _In_ DXGI_FORMAT format, _In_ DWORD flags );
_Success_(return != false) bool __cdecl _LoadScanlineLinear(
_Out_writes_(count) XMVECTOR* pDestination, _In_ size_t count,
_In_reads_bytes_(size) const void* pSource, _In_ size_t size, _In_ DXGI_FORMAT format, _In_ DWORD flags);
_Success_(return != false)
bool __cdecl _StoreScanline( _Out_writes_bytes_(size) void* pDestination, _In_ size_t size, _In_ DXGI_FORMAT format,
_In_reads_(count) const XMVECTOR* pSource, _In_ size_t count, _In_ float threshold = 0 );
_Success_(return != false) bool __cdecl _StoreScanline(
_Out_writes_bytes_(size) void* pDestination, _In_ size_t size, _In_ DXGI_FORMAT format,
_In_reads_(count) const XMVECTOR* pSource, _In_ size_t count, _In_ float threshold = 0);
_Success_(return != false)
bool __cdecl _StoreScanlineLinear( _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_ DWORD flags, _In_ float threshold = 0 );
_Success_(return != false) bool __cdecl _StoreScanlineLinear(
_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_ DWORD flags, _In_ float threshold = 0);
_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,
_Inout_updates_all_opt_(count+2) XMVECTOR* pDiffusionErrors );
_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,
_Inout_updates_all_opt_(count + 2) XMVECTOR* pDiffusionErrors);
HRESULT __cdecl _ConvertToR32G32B32A32( _In_ const Image& srcImage, _Inout_ ScratchImage& image );
HRESULT __cdecl _ConvertToR32G32B32A32(_In_ const Image& srcImage, _Inout_ ScratchImage& image);
HRESULT __cdecl _ConvertFromR32G32B32A32( _In_ const Image& srcImage, _In_ const Image& destImage );
HRESULT __cdecl _ConvertFromR32G32B32A32( _In_ const Image& srcImage, _In_ DXGI_FORMAT format, _Inout_ ScratchImage& image );
HRESULT __cdecl _ConvertFromR32G32B32A32( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DXGI_FORMAT format, _Out_ ScratchImage& result );
HRESULT __cdecl _ConvertFromR32G32B32A32(_In_ const Image& srcImage, _In_ const Image& destImage);
HRESULT __cdecl _ConvertFromR32G32B32A32(_In_ const Image& srcImage, _In_ DXGI_FORMAT format, _Inout_ ScratchImage& image);
HRESULT __cdecl _ConvertFromR32G32B32A32(
_In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DXGI_FORMAT format, _Out_ ScratchImage& result);
void __cdecl _ConvertScanline( _Inout_updates_all_(count) XMVECTOR* pBuffer, _In_ size_t count,
_In_ DXGI_FORMAT outFormat, _In_ DXGI_FORMAT inFormat, _In_ DWORD flags );
void __cdecl _ConvertScanline(
_Inout_updates_all_(count) XMVECTOR* pBuffer, _In_ size_t count,
_In_ DXGI_FORMAT outFormat, _In_ DXGI_FORMAT inFormat, _In_ DWORD flags);
//---------------------------------------------------------------------------------
// DDS helper functions
HRESULT __cdecl _EncodeDDSHeader( _In_ const TexMetadata& metadata, DWORD flags,
_Out_writes_bytes_to_opt_(maxsize, required) void* pDestination, _In_ size_t maxsize, _Out_ size_t& required );
HRESULT __cdecl _EncodeDDSHeader(
_In_ const TexMetadata& metadata, DWORD flags,
_Out_writes_bytes_to_opt_(maxsize, required) void* pDestination, _In_ size_t maxsize, _Out_ size_t& required);
} // namespace

View File

@ -854,13 +854,13 @@ _Use_decl_annotations_
HRESULT DirectX::GetMetadataFromTGAMemory(
const void* pSource,
size_t size,
TexMetadata& metadata )
TexMetadata& metadata)
{
if ( !pSource || size == 0 )
if (!pSource || size == 0)
return E_INVALIDARG;
size_t offset;
return DecodeTGAHeader( pSource, size, metadata, offset, 0 );
return DecodeTGAHeader(pSource, size, metadata, offset, 0);
}
_Use_decl_annotations_

View File

@ -99,63 +99,63 @@ DXGI_FORMAT DirectX::_WICToDXGI(const GUID& guid)
}
_Use_decl_annotations_
bool DirectX::_DXGIToWIC( DXGI_FORMAT format, GUID& guid, bool ignoreRGBvsBGR )
bool DirectX::_DXGIToWIC(DXGI_FORMAT format, GUID& guid, bool ignoreRGBvsBGR)
{
switch( format )
switch (format)
{
case DXGI_FORMAT_R8G8B8A8_UNORM:
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
if ( ignoreRGBvsBGR )
{
// If we are not doing conversion so don't really care about BGR vs RGB color-order,
// we can use the canonical WIC 32bppBGRA format which avoids an extra format conversion when using the WIC scaler
memcpy( &guid, &GUID_WICPixelFormat32bppBGRA, sizeof(GUID) );
}
else
{
memcpy( &guid, &GUID_WICPixelFormat32bppRGBA, sizeof(GUID) );
}
return true;
case DXGI_FORMAT_D32_FLOAT:
memcpy( &guid, &GUID_WICPixelFormat32bppGrayFloat, sizeof(GUID) );
return true;
case DXGI_FORMAT_D16_UNORM:
memcpy( &guid, &GUID_WICPixelFormat16bppGray, sizeof(GUID) );
return true;
case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
memcpy( &guid, &GUID_WICPixelFormat32bppBGRA, sizeof(GUID) );
return true;
case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
memcpy( &guid, &GUID_WICPixelFormat32bppBGR, sizeof(GUID) );
return true;
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
case DXGI_FORMAT_R32G32B32_FLOAT:
if ( g_WIC2 )
{
memcpy( &guid, &GUID_WICPixelFormat96bppRGBFloat, sizeof(GUID) );
return true;
}
break;
#endif
default:
for( size_t i=0; i < _countof(g_WICFormats); ++i )
{
if ( g_WICFormats[i].format == format )
case DXGI_FORMAT_R8G8B8A8_UNORM:
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
if (ignoreRGBvsBGR)
{
memcpy( &guid, &g_WICFormats[i].wic, sizeof(GUID) );
// If we are not doing conversion so don't really care about BGR vs RGB color-order,
// we can use the canonical WIC 32bppBGRA format which avoids an extra format conversion when using the WIC scaler
memcpy(&guid, &GUID_WICPixelFormat32bppBGRA, sizeof(GUID));
}
else
{
memcpy(&guid, &GUID_WICPixelFormat32bppRGBA, sizeof(GUID));
}
return true;
case DXGI_FORMAT_D32_FLOAT:
memcpy(&guid, &GUID_WICPixelFormat32bppGrayFloat, sizeof(GUID));
return true;
case DXGI_FORMAT_D16_UNORM:
memcpy(&guid, &GUID_WICPixelFormat16bppGray, sizeof(GUID));
return true;
case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
memcpy(&guid, &GUID_WICPixelFormat32bppBGRA, sizeof(GUID));
return true;
case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
memcpy(&guid, &GUID_WICPixelFormat32bppBGR, sizeof(GUID));
return true;
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
case DXGI_FORMAT_R32G32B32_FLOAT:
if (g_WIC2)
{
memcpy(&guid, &GUID_WICPixelFormat96bppRGBFloat, sizeof(GUID));
return true;
}
}
break;
break;
#endif
default:
for (size_t i = 0; i < _countof(g_WICFormats); ++i)
{
if (g_WICFormats[i].format == format)
{
memcpy(&guid, &g_WICFormats[i].wic, sizeof(GUID));
return true;
}
}
break;
}
memcpy( &guid, &GUID_NULL, sizeof(GUID) );
memcpy(&guid, &GUID_NULL, sizeof(GUID));
return false;
}

View File

@ -22,10 +22,10 @@
#ifdef __cplusplus_winrt
static inline HRESULT CreateMemoryStream( _Outptr_ IStream** stream )
static inline HRESULT CreateMemoryStream(_Outptr_ IStream** stream)
{
auto randomAccessStream = ref new ::Windows::Storage::Streams::InMemoryRandomAccessStream();
return CreateStreamOverRandomAccessStream( randomAccessStream, IID_PPV_ARGS( stream ) );
return CreateStreamOverRandomAccessStream(randomAccessStream, IID_PPV_ARGS(stream));
}
#else
@ -41,16 +41,16 @@
#include <windows.storage.streams.h>
#pragma warning(pop)
static inline HRESULT CreateMemoryStream( _Outptr_ IStream** stream )
static inline HRESULT CreateMemoryStream(_Outptr_ IStream** stream)
{
Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IRandomAccessStream> abiStream;
HRESULT hr = Windows::Foundation::ActivateInstance(
Microsoft::WRL::Wrappers::HStringReference( RuntimeClass_Windows_Storage_Streams_InMemoryRandomAccessStream ).Get(),
abiStream.GetAddressOf() );
Microsoft::WRL::Wrappers::HStringReference(RuntimeClass_Windows_Storage_Streams_InMemoryRandomAccessStream).Get(),
abiStream.GetAddressOf());
if (SUCCEEDED(hr))
{
hr = CreateStreamOverRandomAccessStream( abiStream.Get(), IID_PPV_ARGS( stream ) );
hr = CreateStreamOverRandomAccessStream(abiStream.Get(), IID_PPV_ARGS(stream));
}
return hr;
}
@ -60,9 +60,9 @@
#else
#pragma prefast(suppress:6387 28196, "a simple wrapper around an existing annotated function" );
static inline HRESULT CreateMemoryStream( _Outptr_ IStream** stream )
static inline HRESULT CreateMemoryStream(_Outptr_ IStream** stream)
{
return CreateStreamOnHGlobal( 0, TRUE, stream );
return CreateStreamOnHGlobal(0, TRUE, stream);
}
#endif

View File

@ -28,22 +28,22 @@ XMGLOBALCONST XMVECTORF32 g_boxScale3D = { { { 0.125f, 0.125f, 0.125f, 0.125f }
#define AVERAGE4( res, p0, p1, p2, p3 ) \
{ \
XMVECTOR v = XMVectorAdd( (p0), (p1) ); \
v = XMVectorAdd( v, (p2) ); \
v = XMVectorAdd( v, (p3) ); \
res = XMVectorMultiply( v, g_boxScale ); \
XMVECTOR v = XMVectorAdd((p0), (p1)); \
v = XMVectorAdd(v, (p2)); \
v = XMVectorAdd(v, (p3)); \
res = XMVectorMultiply(v, g_boxScale); \
}
#define AVERAGE8( res, p0, p1, p2, p3, p4, p5, p6, p7) \
{ \
XMVECTOR v = XMVectorAdd( (p0), (p1) ); \
v = XMVectorAdd( v, (p2) ); \
v = XMVectorAdd( v, (p3) ); \
v = XMVectorAdd( v, (p4) ); \
v = XMVectorAdd( v, (p5) ); \
v = XMVectorAdd( v, (p6) ); \
v = XMVectorAdd( v, (p7) ); \
res = XMVectorMultiply( v, g_boxScale3D ); \
XMVECTOR v = XMVectorAdd((p0), (p1)); \
v = XMVectorAdd(v, (p2)); \
v = XMVectorAdd(v, (p3)); \
v = XMVectorAdd(v, (p4)); \
v = XMVectorAdd(v, (p5)); \
v = XMVectorAdd(v, (p6)); \
v = XMVectorAdd(v, (p7)); \
res = XMVectorMultiply(v, g_boxScale3D); \
}
@ -98,16 +98,16 @@ inline void _CreateLinearFilter(_In_ size_t source, _In_ size_t dest, _In_ bool
}
#define BILINEAR_INTERPOLATE( res, x, y, r0, r1 ) \
res = XMVectorAdd( XMVectorScale( XMVectorAdd( XMVectorScale( (r0)[ x.u0 ], x.weight0 ), XMVectorScale( (r0)[ x.u1 ], x.weight1 ) ), y.weight0 ), \
XMVectorScale( XMVectorAdd( XMVectorScale( (r1)[ x.u0 ], x.weight0 ), XMVectorScale( (r1)[ x.u1 ], x.weight1 ) ), y.weight1 ) )
res = XMVectorAdd(XMVectorScale(XMVectorAdd(XMVectorScale((r0)[ x.u0 ], x.weight0), XMVectorScale((r0)[ x.u1 ], x.weight1)), y.weight0), \
XMVectorScale(XMVectorAdd(XMVectorScale((r1)[ x.u0 ], x.weight0), XMVectorScale((r1)[ x.u1 ], x.weight1)), y.weight1) )
#define TRILINEAR_INTERPOLATE( res, x, y, z, r0, r1, r2, r3 ) \
{\
XMVECTOR a0 = XMVectorScale( XMVectorAdd( XMVectorScale( (r0)[ x.u0 ], x.weight0 ), XMVectorScale( (r0)[ x.u1 ], x.weight1 ) ), y.weight0 ); \
XMVECTOR a1 = XMVectorScale( XMVectorAdd( XMVectorScale( (r1)[ x.u0 ], x.weight0 ), XMVectorScale( (r1)[ x.u1 ], x.weight1 ) ), y.weight1 ); \
XMVECTOR a2 = XMVectorScale( XMVectorAdd( XMVectorScale( (r2)[ x.u0 ], x.weight0 ), XMVectorScale( (r2)[ x.u1 ], x.weight1 ) ), y.weight0 ); \
XMVECTOR a3 = XMVectorScale( XMVectorAdd( XMVectorScale( (r3)[ x.u0 ], x.weight0 ), XMVectorScale( (r3)[ x.u1 ], x.weight1 ) ), y.weight1 ); \
res = XMVectorAdd( XMVectorScale( XMVectorAdd( a0, a1 ), z.weight0 ), XMVectorScale( XMVectorAdd( a2, a3 ), z.weight1 ) ); \
XMVECTOR a0 = XMVectorScale(XMVectorAdd(XMVectorScale((r0)[ x.u0 ], x.weight0 ), XMVectorScale((r0)[ x.u1 ], x.weight1)), y.weight0); \
XMVECTOR a1 = XMVectorScale(XMVectorAdd(XMVectorScale((r1)[ x.u0 ], x.weight0 ), XMVectorScale((r1)[ x.u1 ], x.weight1)), y.weight1); \
XMVECTOR a2 = XMVectorScale(XMVectorAdd(XMVectorScale((r2)[ x.u0 ], x.weight0 ), XMVectorScale((r2)[ x.u1 ], x.weight1)), y.weight0); \
XMVECTOR a3 = XMVectorScale(XMVectorAdd(XMVectorScale((r3)[ x.u0 ], x.weight0 ), XMVectorScale((r3)[ x.u1 ], x.weight1)), y.weight1); \
res = XMVectorAdd(XMVectorScale(XMVectorAdd(a0, a1), z.weight0), XMVectorScale(XMVectorAdd(a2, a3), z.weight1)); \
}
//-------------------------------------------------------------------------------------
@ -190,18 +190,18 @@ inline void _CreateCubicFilter(_In_ size_t source, _In_ size_t dest, _In_ bool w
#define CUBIC_INTERPOLATE( res, dx, p0, p1, p2, p3 ) \
{ \
XMVECTOR a0 = (p1); \
XMVECTOR d0 = XMVectorSubtract( p0, a0 ); \
XMVECTOR d2 = XMVectorSubtract( p2, a0 ); \
XMVECTOR d3 = XMVectorSubtract( p3, a0 ); \
XMVECTOR a1 = XMVectorSubtract( d2, XMVectorMultiply( g_cubicThird, d0 ) ); \
a1 = XMVectorSubtract( a1, XMVectorMultiply( g_cubicSixth, d3 ) ); \
XMVECTOR a2 = XMVectorAdd( XMVectorMultiply( g_cubicHalf, d0 ), XMVectorMultiply( g_cubicHalf, d2 ) ); \
XMVECTOR a3 = XMVectorSubtract( XMVectorMultiply( g_cubicSixth, d3 ), XMVectorMultiply( g_cubicSixth, d0 ) ); \
a3 = XMVectorSubtract( a3, XMVectorMultiply( g_cubicHalf, d2 ) ); \
XMVECTOR vdx = XMVectorReplicate( dx ); \
XMVECTOR vdx2 = XMVectorMultiply( vdx, vdx ); \
XMVECTOR vdx3 = XMVectorMultiply( vdx2, vdx ); \
res = XMVectorAdd( XMVectorAdd( XMVectorAdd( a0, XMVectorMultiply( a1, vdx ) ), XMVectorMultiply( a2, vdx2 ) ), XMVectorMultiply( a3, vdx3 ) ); \
XMVECTOR d0 = XMVectorSubtract(p0, a0); \
XMVECTOR d2 = XMVectorSubtract(p2, a0); \
XMVECTOR d3 = XMVectorSubtract(p3, a0); \
XMVECTOR a1 = XMVectorSubtract(d2, XMVectorMultiply(g_cubicThird, d0)); \
a1 = XMVectorSubtract(a1, XMVectorMultiply(g_cubicSixth, d3)); \
XMVECTOR a2 = XMVectorAdd(XMVectorMultiply(g_cubicHalf, d0), XMVectorMultiply(g_cubicHalf, d2)); \
XMVECTOR a3 = XMVectorSubtract(XMVectorMultiply(g_cubicSixth, d3), XMVectorMultiply(g_cubicSixth, d0)); \
a3 = XMVectorSubtract(a3, XMVectorMultiply(g_cubicHalf, d2)); \
XMVECTOR vdx = XMVectorReplicate(dx); \
XMVECTOR vdx2 = XMVectorMultiply(vdx, vdx); \
XMVECTOR vdx3 = XMVectorMultiply(vdx2, vdx); \
res = XMVectorAdd(XMVectorAdd(XMVectorAdd(a0, XMVectorMultiply(a1, vdx)), XMVectorMultiply(a2, vdx2)), XMVectorMultiply(a3, vdx3)); \
}

View File

@ -25,7 +25,7 @@ struct handle_closer { void operator()(HANDLE h) { assert(h != INVALID_HANDLE_VA
typedef std::unique_ptr<void, handle_closer> ScopedHandle;
inline HANDLE safe_handle( HANDLE h ) { return (h == INVALID_HANDLE_VALUE) ? 0 : h; }
inline HANDLE safe_handle(HANDLE h) { return (h == INVALID_HANDLE_VALUE) ? 0 : h; }
//---------------------------------------------------------------------------------
struct find_closer { void operator()(HANDLE h) { assert(h != INVALID_HANDLE_VALUE); if (h) FindClose(h); } };