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) {} HDRColorA(const HDRColorA& c) : r(c.r), g(c.g), b(c.b), a(c.a) {}
// binary operators // 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); 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); 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); 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; float fInv = 1.0f / f;
return HDRColorA(r * fInv, g * fInv, b * fInv, a * fInv); 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; return r * c.r + g * c.g + b * c.b + a * c.a;
} }
// assignment operators // assignment operators
HDRColorA& operator += ( const HDRColorA& c ) HDRColorA& operator += (const HDRColorA& c)
{ {
r += c.r; r += c.r;
g += c.g; g += c.g;
@ -90,7 +90,7 @@ public:
return *this; return *this;
} }
HDRColorA& operator -= ( const HDRColorA& c ) HDRColorA& operator -= (const HDRColorA& c)
{ {
r -= c.r; r -= c.r;
g -= c.g; g -= c.g;
@ -99,7 +99,7 @@ public:
return *this; return *this;
} }
HDRColorA& operator *= ( float f ) HDRColorA& operator *= (float f)
{ {
r *= f; r *= f;
g *= f; g *= f;
@ -108,7 +108,7 @@ public:
return *this; return *this;
} }
HDRColorA& operator /= ( float f ) HDRColorA& operator /= (float f)
{ {
float fInv = 1.0f / f; float fInv = 1.0f / f;
r *= fInv; r *= fInv;

View File

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

View File

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

View File

@ -12,20 +12,20 @@
namespace DirectX namespace DirectX
{ {
class GPUCompressBC class GPUCompressBC
{ {
public: public:
GPUCompressBC(); 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: private:
DXGI_FORMAT m_bcformat; DXGI_FORMAT m_bcformat;
DXGI_FORMAT m_srcformat; DXGI_FORMAT m_srcformat;
float m_alphaWeight; float m_alphaWeight;
@ -59,6 +59,6 @@ private:
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC7_tryMode137CS; Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC7_tryMode137CS;
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC7_tryMode02CS; Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC7_tryMode02CS;
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC7_encodeBlockCS; Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC7_encodeBlockCS;
}; };
} // namespace } // namespace

View File

@ -41,21 +41,21 @@ namespace DirectX
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
// DXGI Format Utilities // DXGI Format Utilities
bool __cdecl IsValid( _In_ DXGI_FORMAT fmt ); bool __cdecl IsValid(_In_ DXGI_FORMAT fmt);
bool __cdecl IsCompressed( _In_ DXGI_FORMAT fmt ); bool __cdecl IsCompressed(_In_ DXGI_FORMAT fmt);
bool __cdecl IsPacked( _In_ DXGI_FORMAT fmt ); bool __cdecl IsPacked(_In_ DXGI_FORMAT fmt);
bool __cdecl IsVideo( _In_ DXGI_FORMAT fmt ); bool __cdecl IsVideo(_In_ DXGI_FORMAT fmt);
bool __cdecl IsPlanar( _In_ DXGI_FORMAT fmt ); bool __cdecl IsPlanar(_In_ DXGI_FORMAT fmt);
bool __cdecl IsPalettized( _In_ DXGI_FORMAT fmt ); bool __cdecl IsPalettized(_In_ DXGI_FORMAT fmt);
bool __cdecl IsDepthStencil(_In_ DXGI_FORMAT fmt ); bool __cdecl IsDepthStencil(_In_ DXGI_FORMAT fmt);
bool __cdecl IsSRGB( _In_ DXGI_FORMAT fmt ); bool __cdecl IsSRGB(_In_ DXGI_FORMAT fmt);
bool __cdecl IsTypeless( _In_ DXGI_FORMAT fmt, _In_ bool partialTypeless = true ); 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 enum CP_FLAGS
{ {
@ -71,15 +71,16 @@ namespace DirectX
CP_FLAGS_8BPP = 0x40000, // Override with a legacy 8 bits-per-pixel format size 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, void __cdecl ComputePitch(
_Out_ size_t& rowPitch, _Out_ size_t& slicePitch, _In_ DWORD flags = CP_FLAGS_NONE ); _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 MakeSRGB(_In_ DXGI_FORMAT fmt);
DXGI_FORMAT __cdecl MakeTypeless( _In_ DXGI_FORMAT fmt ); DXGI_FORMAT __cdecl MakeTypeless(_In_ DXGI_FORMAT fmt);
DXGI_FORMAT __cdecl MakeTypelessUNORM( _In_ DXGI_FORMAT fmt ); DXGI_FORMAT __cdecl MakeTypelessUNORM(_In_ DXGI_FORMAT fmt);
DXGI_FORMAT __cdecl MakeTypelessFLOAT( _In_ DXGI_FORMAT fmt ); DXGI_FORMAT __cdecl MakeTypelessFLOAT(_In_ DXGI_FORMAT fmt);
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
// Texture metadata // Texture metadata
@ -124,14 +125,14 @@ namespace DirectX
DXGI_FORMAT format; DXGI_FORMAT format;
TEX_DIMENSION dimension; 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 // Returns size_t(-1) to indicate an out-of-range error
bool __cdecl IsCubemap() const { return (miscFlags & TEX_MISC_TEXTURECUBE) != 0; } bool __cdecl IsCubemap() const { return (miscFlags & TEX_MISC_TEXTURECUBE) != 0; }
// Helper for miscFlags // Helper for miscFlags
bool __cdecl IsPMAlpha() const { return ((miscFlags2 & TEX_MISC2_ALPHA_MODE_MASK) == TEX_ALPHA_MODE_PREMULTIPLIED) != 0; } 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); } TEX_ALPHA_MODE __cdecl GetAlphaMode() const { return static_cast<TEX_ALPHA_MODE>(miscFlags2 & TEX_MISC2_ALPHA_MODE_MASK); }
// Helpers for miscFlags2 // Helpers for miscFlags2
@ -206,26 +207,38 @@ namespace DirectX
// Filtering mode to use for any required image resizing (only needed when loading arrays of differently sized images; defaults to Fant) // 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, HRESULT __cdecl GetMetadataFromDDSMemory(
_Out_ TexMetadata& metadata ); _In_reads_bytes_(size) const void* pSource, _In_ size_t size,
HRESULT __cdecl GetMetadataFromDDSFile( _In_z_ const wchar_t* szFile, _In_ DWORD flags, _In_ DWORD flags,
_Out_ TexMetadata& metadata ); _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, HRESULT __cdecl GetMetadataFromHDRMemory(
_Out_ TexMetadata& metadata ); _In_reads_bytes_(size) const void* pSource, _In_ size_t size,
HRESULT __cdecl GetMetadataFromHDRFile( _In_z_ const wchar_t* szFile, _Out_ TexMetadata& metadata);
_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, HRESULT __cdecl GetMetadataFromTGAMemory(
_Out_ TexMetadata& metadata ); _In_reads_bytes_(size) const void* pSource, _In_ size_t size,
HRESULT __cdecl GetMetadataFromTGAFile( _In_z_ const wchar_t* szFile, _Out_ TexMetadata& metadata);
_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, HRESULT __cdecl GetMetadataFromWICMemory(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_In_ DWORD flags,
_Out_ TexMetadata& metadata, _Out_ TexMetadata& metadata,
_In_opt_ std::function<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr); _In_opt_ std::function<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr);
HRESULT __cdecl GetMetadataFromWICFile( _In_z_ const wchar_t* szFile, _In_ DWORD flags, HRESULT __cdecl GetMetadataFromWICFile(
_In_z_ const wchar_t* szFile,
_In_ DWORD flags,
_Out_ TexMetadata& metadata, _Out_ TexMetadata& metadata,
_In_opt_ std::function<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr); _In_opt_ std::function<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr);
@ -255,21 +268,21 @@ namespace DirectX
ScratchImage(const ScratchImage&) = delete; ScratchImage(const ScratchImage&) = delete;
ScratchImage& operator=(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 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 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 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 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 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 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 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 Initialize3DFromImages(_In_reads_(depth) const Image* images, _In_ size_t depth, _In_ DWORD flags = CP_FLAGS_NONE);
void __cdecl Release(); 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 TexMetadata& __cdecl GetMetadata() const { return m_metadata; }
const Image* __cdecl GetImage(_In_ size_t mip, _In_ size_t item, _In_ size_t slice) const; 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(const Blob&) = delete;
Blob& operator=(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(); void __cdecl Release();
@ -322,58 +335,81 @@ namespace DirectX
// Image I/O // Image I/O
// DDS operations // DDS operations
HRESULT __cdecl LoadFromDDSMemory( _In_reads_bytes_(size) const void* pSource, _In_ size_t size, _In_ DWORD flags, HRESULT __cdecl LoadFromDDSMemory(
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image ); _In_reads_bytes_(size) const void* pSource, _In_ size_t size,
HRESULT __cdecl LoadFromDDSFile( _In_z_ const wchar_t* szFile, _In_ DWORD flags, _In_ DWORD flags,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image ); _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, HRESULT __cdecl SaveToDDSMemory(
_Out_ Blob& blob ); _In_ const Image& image,
HRESULT __cdecl SaveToDDSMemory( _In_reads_(nimages) const Image* images, _In_ size_t nimages, _In_ const TexMetadata& metadata, _In_ DWORD flags, _In_ DWORD flags,
_Out_ Blob& blob ); _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_ 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_reads_(nimages) const Image* images, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DWORD flags, _In_z_ const wchar_t* szFile);
// HDR operations // HDR operations
HRESULT __cdecl LoadFromHDRMemory( _In_reads_bytes_(size) const void* pSource, _In_ size_t size, HRESULT __cdecl LoadFromHDRMemory(
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image ); _In_reads_bytes_(size) const void* pSource, _In_ size_t size,
HRESULT __cdecl LoadFromHDRFile( _In_z_ const wchar_t* szFile, _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image);
_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 SaveToHDRMemory(_In_ const Image& image, _Out_ Blob& blob);
HRESULT __cdecl SaveToHDRFile( _In_ const Image& image, _In_z_ const wchar_t* szFile ); HRESULT __cdecl SaveToHDRFile(_In_ const Image& image, _In_z_ const wchar_t* szFile);
// TGA operations // TGA operations
HRESULT __cdecl LoadFromTGAMemory( _In_reads_bytes_(size) const void* pSource, _In_ size_t size, HRESULT __cdecl LoadFromTGAMemory(
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image ); _In_reads_bytes_(size) const void* pSource, _In_ size_t size,
HRESULT __cdecl LoadFromTGAFile( _In_z_ const wchar_t* szFile, _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image);
_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 SaveToTGAMemory(_In_ const Image& image, _Out_ Blob& blob);
HRESULT __cdecl SaveToTGAFile( _In_ const Image& image, _In_z_ const wchar_t* szFile ); HRESULT __cdecl SaveToTGAFile(_In_ const Image& image, _In_z_ const wchar_t* szFile);
// WIC operations // WIC operations
HRESULT __cdecl LoadFromWICMemory( _In_reads_bytes_(size) const void* pSource, _In_ size_t size, _In_ DWORD flags, HRESULT __cdecl LoadFromWICMemory(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_In_ DWORD flags,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image, _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image,
_In_opt_ std::function<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr); _In_opt_ std::function<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr);
HRESULT __cdecl LoadFromWICFile( _In_z_ const wchar_t* szFile, _In_ DWORD flags, HRESULT __cdecl LoadFromWICFile(
_In_z_ const wchar_t* szFile, _In_ DWORD flags,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image, _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image,
_In_opt_ std::function<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr); _In_opt_ std::function<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr);
HRESULT __cdecl SaveToWICMemory( _In_ const Image& image, _In_ DWORD flags, _In_ REFGUID guidContainerFormat, HRESULT __cdecl SaveToWICMemory(
_In_ const Image& image, _In_ DWORD flags, _In_ REFGUID guidContainerFormat,
_Out_ Blob& blob, _In_opt_ const GUID* targetFormat = nullptr, _Out_ Blob& blob, _In_opt_ const GUID* targetFormat = nullptr,
_In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = 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, 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, _Out_ Blob& blob, _In_opt_ const GUID* targetFormat = nullptr,
_In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = nullptr ); _In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = nullptr);
HRESULT __cdecl SaveToWICFile( _In_ const Image& image, _In_ DWORD flags, _In_ REFGUID guidContainerFormat, 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_z_ const wchar_t* szFile, _In_opt_ const GUID* targetFormat = nullptr,
_In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = 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, 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_z_ const wchar_t* szFile, _In_opt_ const GUID* targetFormat = nullptr,
_In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = nullptr ); _In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = nullptr);
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
// Texture conversion, resizing, mipmap generation, and block compression // Texture conversion, resizing, mipmap generation, and block compression
@ -388,9 +424,10 @@ namespace DirectX
TEX_FR_FLIP_VERTICAL = 0x10, TEX_FR_FLIP_VERTICAL = 0x10,
}; };
HRESULT __cdecl FlipRotate( _In_ const Image& srcImage, _In_ DWORD flags, _Out_ ScratchImage& image ); 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, HRESULT __cdecl FlipRotate(
_In_ DWORD flags, _Out_ ScratchImage& result ); _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 // Flip and/or rotate image
enum TEX_FILTER_FLAGS enum TEX_FILTER_FLAGS
@ -400,11 +437,11 @@ namespace DirectX
TEX_FILTER_WRAP_U = 0x1, TEX_FILTER_WRAP_U = 0x1,
TEX_FILTER_WRAP_V = 0x2, TEX_FILTER_WRAP_V = 0x2,
TEX_FILTER_WRAP_W = 0x4, 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_U = 0x10,
TEX_FILTER_MIRROR_V = 0x20, TEX_FILTER_MIRROR_V = 0x20,
TEX_FILTER_MIRROR_W = 0x40, 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 // Wrap vs. Mirror vs. Clamp filtering options
TEX_FILTER_SEPARATE_ALPHA = 0x100, TEX_FILTER_SEPARATE_ALPHA = 0x100,
@ -434,7 +471,7 @@ namespace DirectX
TEX_FILTER_SRGB_IN = 0x1000000, TEX_FILTER_SRGB_IN = 0x1000000,
TEX_FILTER_SRGB_OUT = 0x2000000, 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 // sRGB <-> RGB for use in conversion operations
// if the input format type is IsSRGB(), then SRGB_IN is on by default // 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 // 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 // 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, HRESULT __cdecl Resize(
_Out_ ScratchImage& image ); _In_ const Image& srcImage, _In_ size_t width, _In_ size_t height,
HRESULT __cdecl Resize( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, _In_ DWORD filter,
_In_ size_t width, _In_ size_t height, _In_ DWORD filter, _Out_ ScratchImage& result ); _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. // Resize the image to width x height. Defaults to Fant filtering.
// Note for a complex resize, the result will always have mipLevels == 1 // Note for a complex resize, the result will always have mipLevels == 1
const float TEX_THRESHOLD_DEFAULT = 0.5f; const float TEX_THRESHOLD_DEFAULT = 0.5f;
// Default value for alpha threshold used when converting to 1-bit alpha // 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, HRESULT __cdecl Convert(
_Out_ ScratchImage& image ); _In_ const Image& srcImage, _In_ DXGI_FORMAT format, _In_ DWORD filter, _In_ float threshold,
HRESULT __cdecl Convert( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, _Out_ ScratchImage& image);
_In_ DXGI_FORMAT format, _In_ DWORD filter, _In_ float threshold, _Out_ ScratchImage& result ); 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 // Convert the image to a new format
HRESULT __cdecl ConvertToSinglePlane( _In_ const Image& srcImage, _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, HRESULT __cdecl ConvertToSinglePlane(
_Out_ ScratchImage& image ); _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 // 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, HRESULT __cdecl GenerateMipMaps(
_Inout_ ScratchImage& mipChain, _In_ bool allow1D = false ); _In_ const Image& baseImage, _In_ DWORD filter, _In_ size_t levels,
HRESULT __cdecl GenerateMipMaps( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, _Inout_ ScratchImage& mipChain, _In_ bool allow1D = false);
_In_ DWORD filter, _In_ size_t levels, _Inout_ ScratchImage& mipChain ); 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) // 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 // 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, HRESULT __cdecl GenerateMipMaps3D(
_Out_ ScratchImage& mipChain ); _In_reads_(depth) const Image* baseImages, _In_ size_t depth, _In_ DWORD filter, _In_ size_t levels,
HRESULT __cdecl GenerateMipMaps3D( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, _Out_ ScratchImage& mipChain);
_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) // 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 // 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_IN = 0x1000000,
TEX_PMALPHA_SRGB_OUT = 0x2000000, 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 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 // 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_ 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, HRESULT __cdecl PremultiplyAlpha(
_In_ DWORD flags, _Out_ ScratchImage& result ); _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 // Converts to/from a premultiplied alpha version of the texture
enum TEX_COMPRESS_FLAGS enum TEX_COMPRESS_FLAGS
@ -527,7 +575,7 @@ namespace DirectX
TEX_COMPRESS_SRGB_IN = 0x1000000, TEX_COMPRESS_SRGB_IN = 0x1000000,
TEX_COMPRESS_SRGB_OUT = 0x2000000, 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 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 // 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) // 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, HRESULT __cdecl Compress(
_Out_ ScratchImage& cImage ); _In_ const Image& srcImage, _In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float threshold,
HRESULT __cdecl Compress( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, _Out_ ScratchImage& cImage);
_In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float threshold, _Out_ ScratchImage& cImages ); 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 // 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__) #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, HRESULT __cdecl Compress(
_In_ float alphaWeight, _Out_ ScratchImage& image ); _In_ ID3D11Device* pDevice, _In_ const Image& srcImage, _In_ DXGI_FORMAT format, _In_ DWORD compress,
HRESULT __cdecl Compress( _In_ ID3D11Device* pDevice, _In_ const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, _In_ float alphaWeight, _Out_ ScratchImage& image);
_In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float alphaWeight, _Out_ ScratchImage& cImages ); 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) // DirectCompute-based compression (alphaWeight is only used by BC7. 1.0 is the typical value to use)
#endif #endif
HRESULT __cdecl Decompress( _In_ const Image& cImage, _In_ DXGI_FORMAT format, _Out_ ScratchImage& image ); 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, HRESULT __cdecl Decompress(
_In_ DXGI_FORMAT format, _Out_ ScratchImage& images ); _In_reads_(nimages) const Image* cImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DXGI_FORMAT format, _Out_ ScratchImage& images);
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
// Normal map operations // Normal map operations
@ -580,10 +633,12 @@ namespace DirectX
// Computes a crude occlusion term stored in the alpha channel // Computes a crude occlusion term stored in the alpha channel
}; };
HRESULT __cdecl ComputeNormalMap( _In_ const Image& srcImage, _In_ DWORD flags, _In_ float amplitude, HRESULT __cdecl ComputeNormalMap(
_In_ DXGI_FORMAT format, _Out_ ScratchImage& normalMap ); _In_ const Image& srcImage, _In_ DWORD flags, _In_ float amplitude,
HRESULT __cdecl ComputeNormalMap( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, _In_ DXGI_FORMAT format, _Out_ ScratchImage& normalMap);
_In_ DWORD flags, _In_ float amplitude, _In_ DXGI_FORMAT format, _Out_ ScratchImage& normalMaps ); 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 // Misc image operations
@ -596,11 +651,12 @@ namespace DirectX
size_t h; size_t h;
Rect() = default; 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, HRESULT __cdecl CopyRectangle(
_In_ DWORD filter, _In_ size_t xOffset, _In_ size_t yOffset ); _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 enum CMSE_FLAGS
{ {
@ -621,21 +677,25 @@ namespace DirectX
// Indicates that image should be scaled and biased before comparison (i.e. UNORM -> SNORM) // 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, HRESULT __cdecl EvaluateImage(
_In_ std::function<void __cdecl(_In_reads_(width) const XMVECTOR* pixels, size_t width, size_t y)> pixelFunc ); _In_ const Image& image,
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);
_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, HRESULT __cdecl TransformImage(
_In_ const Image& image,
_In_ std::function<void __cdecl(_Out_writes_(width) XMVECTOR* outPixels, _In_ std::function<void __cdecl(_Out_writes_(width) XMVECTOR* outPixels,
_In_reads_(width) const XMVECTOR* inPixels, size_t width, size_t y)> pixelFunc, _In_reads_(width) const XMVECTOR* inPixels, size_t width, size_t y)> pixelFunc,
ScratchImage& result ); ScratchImage& result);
HRESULT __cdecl TransformImage( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, 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_ std::function<void __cdecl(_Out_writes_(width) XMVECTOR* outPixels,
_In_reads_(width) const XMVECTOR* inPixels, size_t width, size_t y)> pixelFunc, _In_reads_(width) const XMVECTOR* inPixels, size_t width, size_t y)> pixelFunc,
ScratchImage& result ); ScratchImage& result);
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
// WIC utility code // WIC utility code
@ -653,51 +713,59 @@ namespace DirectX
REFGUID __cdecl GetWICCodec(_In_ WICCodecs codec); REFGUID __cdecl GetWICCodec(_In_ WICCodecs codec);
IWICImagingFactory* __cdecl GetWICFactory( bool& iswic2 ); IWICImagingFactory* __cdecl GetWICFactory(bool& iswic2);
void __cdecl SetWICFactory( _In_opt_ IWICImagingFactory* pWIC); void __cdecl SetWICFactory(_In_opt_ IWICImagingFactory* pWIC);
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
// Direct3D 11 functions // Direct3D 11 functions
#if defined(__d3d11_h__) || defined(__d3d11_x_h__) #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, HRESULT __cdecl CreateTexture(
_Outptr_ ID3D11Resource** ppResource ); _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, HRESULT __cdecl CreateShaderResourceView(
_Outptr_ ID3D11ShaderResourceView** ppSRV ); _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, 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, _In_ D3D11_USAGE usage, _In_ unsigned int bindFlags, _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags, _In_ bool forceSRGB,
_Outptr_ ID3D11Resource** ppResource ); _Outptr_ ID3D11Resource** ppResource);
HRESULT __cdecl CreateShaderResourceViewEx( _In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, 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, _In_ D3D11_USAGE usage, _In_ unsigned int bindFlags, _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags, _In_ bool forceSRGB,
_Outptr_ ID3D11ShaderResourceView** ppSRV ); _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 #endif
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
// Direct3D 12 functions // Direct3D 12 functions
#if defined(__d3d12_h__) || defined(__d3d12_x_h__) #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, HRESULT __cdecl CreateTexture(
_Outptr_ ID3D12Resource** ppResource ); _In_ ID3D12Device* pDevice, _In_ const TexMetadata& metadata,
_Outptr_ ID3D12Resource** ppResource);
HRESULT __cdecl CreateTextureEx( _In_ ID3D12Device* pDevice, _In_ const TexMetadata& metadata, HRESULT __cdecl CreateTextureEx(
_In_ ID3D12Device* pDevice, _In_ const TexMetadata& metadata,
_In_ D3D12_RESOURCE_FLAGS resFlags, _In_ bool forceSRGB, _In_ D3D12_RESOURCE_FLAGS resFlags, _In_ bool forceSRGB,
_Outptr_ ID3D12Resource** ppResource ); _Outptr_ ID3D12Resource** ppResource);
HRESULT __cdecl PrepareUpload( _In_ ID3D12Device* pDevice, HRESULT __cdecl PrepareUpload(
_In_ ID3D12Device* pDevice,
_In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
std::vector<D3D12_SUBRESOURCE_DATA>& subresources ); std::vector<D3D12_SUBRESOURCE_DATA>& subresources);
HRESULT __cdecl CaptureTexture( _In_ ID3D12CommandQueue* pCommandQueue, _In_ ID3D12Resource* pSource, _In_ bool isCubeMap, HRESULT __cdecl CaptureTexture(
_In_ ID3D12CommandQueue* pCommandQueue, _In_ ID3D12Resource* pSource, _In_ bool isCubeMap,
_Out_ ScratchImage& result, _Out_ ScratchImage& result,
_In_ D3D12_RESOURCE_STATES beforeState = D3D12_RESOURCE_STATE_RENDER_TARGET, _In_ D3D12_RESOURCE_STATES beforeState = D3D12_RESOURCE_STATE_RENDER_TARGET,
_In_ D3D12_RESOURCE_STATES afterState = D3D12_RESOURCE_STATE_RENDER_TARGET ); _In_ D3D12_RESOURCE_STATES afterState = D3D12_RESOURCE_STATE_RENDER_TARGET);
#endif #endif
#include "DirectXTex.inl" #include "DirectXTex.inl"

View File

@ -16,15 +16,15 @@
//===================================================================================== //=====================================================================================
_Use_decl_annotations_ _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_ _Use_decl_annotations_
inline bool __cdecl IsCompressed(DXGI_FORMAT fmt) inline bool __cdecl IsCompressed(DXGI_FORMAT fmt)
{ {
switch ( fmt ) switch (fmt)
{ {
case DXGI_FORMAT_BC1_TYPELESS: case DXGI_FORMAT_BC1_TYPELESS:
case DXGI_FORMAT_BC1_UNORM: case DXGI_FORMAT_BC1_UNORM:
@ -57,7 +57,7 @@ inline bool __cdecl IsCompressed(DXGI_FORMAT fmt)
_Use_decl_annotations_ _Use_decl_annotations_
inline bool __cdecl IsPalettized(DXGI_FORMAT fmt) inline bool __cdecl IsPalettized(DXGI_FORMAT fmt)
{ {
switch( fmt ) switch (fmt)
{ {
case DXGI_FORMAT_AI44: case DXGI_FORMAT_AI44:
case DXGI_FORMAT_IA44: case DXGI_FORMAT_IA44:
@ -73,7 +73,7 @@ inline bool __cdecl IsPalettized(DXGI_FORMAT fmt)
_Use_decl_annotations_ _Use_decl_annotations_
inline bool __cdecl IsSRGB(DXGI_FORMAT fmt) inline bool __cdecl IsSRGB(DXGI_FORMAT fmt)
{ {
switch( fmt ) switch (fmt)
{ {
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
case DXGI_FORMAT_BC1_UNORM_SRGB: case DXGI_FORMAT_BC1_UNORM_SRGB:
@ -105,7 +105,7 @@ inline HRESULT __cdecl SaveToDDSMemory(const Image& image, DWORD flags, Blob& bl
mdata.format = image.format; mdata.format = image.format;
mdata.dimension = TEX_DIMENSION_TEXTURE2D; mdata.dimension = TEX_DIMENSION_TEXTURE2D;
return SaveToDDSMemory( &image, 1, mdata, flags, blob ); return SaveToDDSMemory(&image, 1, mdata, flags, blob);
} }
_Use_decl_annotations_ _Use_decl_annotations_
@ -120,5 +120,5 @@ inline HRESULT __cdecl SaveToDDSFile(const Image& image, DWORD flags, const wcha
mdata.format = image.format; mdata.format = image.format;
mdata.dimension = TEX_DIMENSION_TEXTURE2D; 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 // Loads an image row into standard RGBA XMVECTOR (aligned) array
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#define LOAD_SCANLINE( type, func )\ #define LOAD_SCANLINE( type, func )\
if ( size >= sizeof(type) )\ if (size >= sizeof(type))\
{\ {\
const type * __restrict sPtr = reinterpret_cast<const type*>(pSource);\ 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;\ if (dPtr >= ePtr) break;\
*(dPtr++) = func( sPtr++ );\ *(dPtr++) = func(sPtr++);\
}\ }\
return true;\ return true;\
}\ }\
return false; return false;
#define LOAD_SCANLINE3( type, func, defvec )\ #define LOAD_SCANLINE3( type, func, defvec )\
if ( size >= sizeof(type) )\ if (size >= sizeof(type))\
{\ {\
const type * __restrict sPtr = reinterpret_cast<const type*>(pSource);\ 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++ );\ XMVECTOR v = func(sPtr++);\
if ( dPtr >= ePtr ) break;\ if (dPtr >= ePtr) break;\
*(dPtr++) = XMVectorSelect( defvec, v, g_XMSelect1110 );\ *(dPtr++) = XMVectorSelect(defvec, v, g_XMSelect1110);\
}\ }\
return true;\ return true;\
}\ }\
return false; return false;
#define LOAD_SCANLINE2( type, func, defvec )\ #define LOAD_SCANLINE2( type, func, defvec )\
if ( size >= sizeof(type) )\ if (size >= sizeof(type))\
{\ {\
const type * __restrict sPtr = reinterpret_cast<const type*>(pSource);\ 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++ );\ XMVECTOR v = func(sPtr++);\
if ( dPtr >= ePtr ) break;\ if (dPtr >= ePtr) break;\
*(dPtr++) = XMVectorSelect( defvec, v, g_XMSelect1100 );\ *(dPtr++) = XMVectorSelect(defvec, v, g_XMSelect1100);\
}\ }\
return true;\ return true;\
}\ }\
@ -1590,13 +1590,13 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline(
// Stores an image row from standard RGBA XMVECTOR (aligned) array // Stores an image row from standard RGBA XMVECTOR (aligned) array
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#define STORE_SCANLINE( type, func )\ #define STORE_SCANLINE( type, func )\
if ( size >= sizeof(type) )\ if (size >= sizeof(type))\
{\ {\
type * __restrict dPtr = reinterpret_cast<type*>(pDestination);\ 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;\ if (sPtr >= ePtr) break;\
func( dPtr++, *sPtr++ );\ func(dPtr++, *sPtr++);\
}\ }\
return true; \ 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 } } }; 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 ) \ #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); \ 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 index = static_cast<ptrdiff_t>((row & 1) ? (count - i - 1) : i ); \
ptrdiff_t delta = ( row & 1 ) ? -2 : 0; \ ptrdiff_t delta = (row & 1) ? -2 : 0; \
\ \
XMVECTOR v = sPtr[ index ]; \ XMVECTOR v = sPtr[ index ]; \
if ( bgr ) { v = XMVectorSwizzle<2, 1, 0, 3>( v ); } \ if (bgr) { v = XMVectorSwizzle<2, 1, 0, 3>(v); } \
if ( norm && clampzero ) v = XMVectorSaturate( v ) ; \ if (norm && clampzero) v = XMVectorSaturate(v) ; \
else if ( clampzero ) v = XMVectorClamp( v, g_XMZero, scalev ); \ else if (clampzero) v = XMVectorClamp(v, g_XMZero, scalev); \
else if ( norm ) v = XMVectorClamp( v, g_XMNegativeOne, g_XMOne ); \ else if (norm) v = XMVectorClamp(v, g_XMNegativeOne, g_XMOne); \
else v = XMVectorClamp( v, XMVectorAdd( XMVectorNegate( scalev ), g_XMOne ), scalev ); \ else v = XMVectorClamp(v, XMVectorAdd(XMVectorNegate(scalev), g_XMOne), scalev); \
v = XMVectorAdd( v, vError ); \ v = XMVectorAdd(v, vError); \
if ( norm ) v = XMVectorMultiply( v, scalev ); \ if (norm) v = XMVectorMultiply(v, scalev); \
\ \
XMVECTOR target; \ XMVECTOR target; \
if ( pDiffusionErrors ) \ if (pDiffusionErrors) \
{ \ { \
target = XMVectorRound( v ); \ target = XMVectorRound(v); \
vError = XMVectorSubtract( v, target ); \ vError = XMVectorSubtract(v, target); \
if (norm) vError = XMVectorDivide( vError, scalev ); \ if (norm) vError = XMVectorDivide(vError, scalev); \
\ \
/* Distribute error to next scanline and next pixel */ \ /* Distribute error to next scanline and next pixel */ \
pDiffusionErrors[ index-delta ] = XMVectorMultiplyAdd( g_ErrorWeight3, vError, pDiffusionErrors[ index-delta ] ); \ pDiffusionErrors[ index-delta ] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[ index-delta ]); \
pDiffusionErrors[ index+1 ] = XMVectorMultiplyAdd( g_ErrorWeight5, vError, pDiffusionErrors[ index+1 ] ); \ pDiffusionErrors[ index+1 ] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[ index+1 ]); \
pDiffusionErrors[ index+2+delta ] = XMVectorMultiplyAdd( g_ErrorWeight1, vError, pDiffusionErrors[ index+2+delta ] ); \ pDiffusionErrors[ index+2+delta ] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[ index+2+delta ]); \
vError = XMVectorMultiply( vError, g_ErrorWeight7 ); \ vError = XMVectorMultiply(vError, g_ErrorWeight7); \
} \ } \
else \ else \
{ \ { \
/* Applied ordered dither */ \ /* Applied ordered dither */ \
target = XMVectorAdd( v, ordered[ index & 3 ] ); \ target = XMVectorAdd(v, ordered[ index & 3 ]); \
target = XMVectorRound( target ); \ target = XMVectorRound(target); \
} \ } \
\ \
target = XMVectorMin( scalev, target ); \ target = XMVectorMin(scalev, target); \
target = XMVectorMax( (clampzero) ? g_XMZero : ( XMVectorAdd( XMVectorNegate( scalev ), g_XMOne ) ), target ); \ target = XMVectorMax((clampzero) ? g_XMZero : (XMVectorAdd(XMVectorNegate(scalev), g_XMOne)), target); \
\ \
XMFLOAT4A tmp; \ XMFLOAT4A tmp; \
XMStoreFloat4A( &tmp, target ); \ XMStoreFloat4A(&tmp, target); \
\ \
auto dPtr = &dest[ index ]; \ auto dPtr = &dest[ index ]; \
if (dPtr >= ePtr) break; \ if (dPtr >= ePtr) break; \
dPtr->x = static_cast<itype>( tmp.x ) & mask; \ dPtr->x = static_cast<itype>(tmp.x) & mask; \
dPtr->y = static_cast<itype>( tmp.y ) & mask; \ dPtr->y = static_cast<itype>(tmp.y) & mask; \
dPtr->z = static_cast<itype>( tmp.z ) & mask; \ dPtr->z = static_cast<itype>(tmp.z) & mask; \
dPtr->w = static_cast<itype>( tmp.w ) & mask; \ dPtr->w = static_cast<itype>(tmp.w) & mask; \
} \ } \
return true; \ return true; \
} \ } \
@ -3688,52 +3688,52 @@ namespace
#define STORE_SCANLINE2( type, scalev, clampzero, norm, itype, mask, row ) \ #define STORE_SCANLINE2( type, scalev, clampzero, norm, itype, mask, row ) \
/* The 2 component cases are always bgr=false */ \ /* The 2 component cases are always bgr=false */ \
if ( size >= sizeof(type) ) \ if (size >= sizeof(type)) \
{ \ { \
type * __restrict dest = reinterpret_cast<type*>(pDestination); \ 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 index = static_cast<ptrdiff_t>((row & 1) ? (count - i - 1) : i ); \
ptrdiff_t delta = ( row & 1 ) ? -2 : 0; \ ptrdiff_t delta = (row & 1) ? -2 : 0; \
\ \
XMVECTOR v = sPtr[ index ]; \ XMVECTOR v = sPtr[ index ]; \
if ( norm && clampzero ) v = XMVectorSaturate( v ) ; \ if (norm && clampzero) v = XMVectorSaturate(v) ; \
else if ( clampzero ) v = XMVectorClamp( v, g_XMZero, scalev ); \ else if (clampzero) v = XMVectorClamp(v, g_XMZero, scalev); \
else if ( norm ) v = XMVectorClamp( v, g_XMNegativeOne, g_XMOne ); \ else if (norm) v = XMVectorClamp(v, g_XMNegativeOne, g_XMOne); \
else v = XMVectorClamp( v, XMVectorAdd( XMVectorNegate( scalev ), g_XMOne ), scalev ); \ else v = XMVectorClamp(v, XMVectorAdd(XMVectorNegate(scalev), g_XMOne), scalev); \
v = XMVectorAdd( v, vError ); \ v = XMVectorAdd(v, vError); \
if ( norm ) v = XMVectorMultiply( v, scalev ); \ if (norm) v = XMVectorMultiply(v, scalev); \
\ \
XMVECTOR target; \ XMVECTOR target; \
if ( pDiffusionErrors ) \ if (pDiffusionErrors) \
{ \ { \
target = XMVectorRound( v ); \ target = XMVectorRound(v); \
vError = XMVectorSubtract( v, target ); \ vError = XMVectorSubtract(v, target); \
if (norm) vError = XMVectorDivide( vError, scalev ); \ if (norm) vError = XMVectorDivide(vError, scalev); \
\ \
/* Distribute error to next scanline and next pixel */ \ /* Distribute error to next scanline and next pixel */ \
pDiffusionErrors[ index-delta ] = XMVectorMultiplyAdd( g_ErrorWeight3, vError, pDiffusionErrors[ index-delta ] ); \ pDiffusionErrors[ index-delta ] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[ index-delta ]); \
pDiffusionErrors[ index+1 ] = XMVectorMultiplyAdd( g_ErrorWeight5, vError, pDiffusionErrors[ index+1 ] ); \ pDiffusionErrors[ index+1 ] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[ index+1 ]); \
pDiffusionErrors[ index+2+delta ] = XMVectorMultiplyAdd( g_ErrorWeight1, vError, pDiffusionErrors[ index+2+delta ] ); \ pDiffusionErrors[ index+2+delta ] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[ index+2+delta ]); \
vError = XMVectorMultiply( vError, g_ErrorWeight7 ); \ vError = XMVectorMultiply(vError, g_ErrorWeight7); \
} \ } \
else \ else \
{ \ { \
/* Applied ordered dither */ \ /* Applied ordered dither */ \
target = XMVectorAdd( v, ordered[ index & 3 ] ); \ target = XMVectorAdd(v, ordered[ index & 3 ]); \
target = XMVectorRound( target ); \ target = XMVectorRound(target); \
} \ } \
\ \
target = XMVectorMin( scalev, target ); \ target = XMVectorMin(scalev, target); \
target = XMVectorMax( (clampzero) ? g_XMZero : ( XMVectorAdd( XMVectorNegate( scalev ), g_XMOne ) ), target ); \ target = XMVectorMax((clampzero) ? g_XMZero : (XMVectorAdd(XMVectorNegate(scalev), g_XMOne)), target); \
\ \
XMFLOAT4A tmp; \ XMFLOAT4A tmp; \
XMStoreFloat4A( &tmp, target ); \ XMStoreFloat4A(&tmp, target); \
\ \
auto dPtr = &dest[ index ]; \ auto dPtr = &dest[ index ]; \
if (dPtr >= ePtr) break; \ if (dPtr >= ePtr) break; \
dPtr->x = static_cast<itype>( tmp.x ) & mask; \ dPtr->x = static_cast<itype>(tmp.x) & mask; \
dPtr->y = static_cast<itype>( tmp.y ) & mask; \ dPtr->y = static_cast<itype>(tmp.y) & mask; \
} \ } \
return true; \ return true; \
} \ } \
@ -3741,48 +3741,48 @@ namespace
#define STORE_SCANLINE1( type, scalev, clampzero, norm, mask, row, selectw ) \ #define STORE_SCANLINE1( type, scalev, clampzero, norm, mask, row, selectw ) \
/* The 1 component cases are always bgr=false */ \ /* The 1 component cases are always bgr=false */ \
if ( size >= sizeof(type) ) \ if (size >= sizeof(type)) \
{ \ { \
type * __restrict dest = reinterpret_cast<type*>(pDestination); \ 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 index = static_cast<ptrdiff_t>((row & 1) ? (count - i - 1) : i ); \
ptrdiff_t delta = ( row & 1 ) ? -2 : 0; \ ptrdiff_t delta = (row & 1) ? -2 : 0; \
\ \
XMVECTOR v = sPtr[ index ]; \ XMVECTOR v = sPtr[ index ]; \
if ( norm && clampzero ) v = XMVectorSaturate( v ) ; \ if (norm && clampzero) v = XMVectorSaturate(v) ; \
else if ( clampzero ) v = XMVectorClamp( v, g_XMZero, scalev ); \ else if (clampzero) v = XMVectorClamp(v, g_XMZero, scalev); \
else if ( norm ) v = XMVectorClamp( v, g_XMNegativeOne, g_XMOne ); \ else if (norm) v = XMVectorClamp(v, g_XMNegativeOne, g_XMOne); \
else v = XMVectorClamp( v, XMVectorAdd( XMVectorNegate( scalev ), g_XMOne ), scalev ); \ else v = XMVectorClamp(v, XMVectorAdd(XMVectorNegate(scalev), g_XMOne), scalev); \
v = XMVectorAdd( v, vError ); \ v = XMVectorAdd(v, vError); \
if ( norm ) v = XMVectorMultiply( v, scalev ); \ if (norm) v = XMVectorMultiply(v, scalev); \
\ \
XMVECTOR target; \ XMVECTOR target; \
if ( pDiffusionErrors ) \ if (pDiffusionErrors) \
{ \ { \
target = XMVectorRound( v ); \ target = XMVectorRound(v); \
vError = XMVectorSubtract( v, target ); \ vError = XMVectorSubtract(v, target); \
if (norm) vError = XMVectorDivide( vError, scalev ); \ if (norm) vError = XMVectorDivide(vError, scalev); \
\ \
/* Distribute error to next scanline and next pixel */ \ /* Distribute error to next scanline and next pixel */ \
pDiffusionErrors[ index-delta ] = XMVectorMultiplyAdd( g_ErrorWeight3, vError, pDiffusionErrors[ index-delta ] ); \ pDiffusionErrors[ index-delta ] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[ index-delta ]); \
pDiffusionErrors[ index+1 ] = XMVectorMultiplyAdd( g_ErrorWeight5, vError, pDiffusionErrors[ index+1 ] ); \ pDiffusionErrors[ index+1 ] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[ index+1 ]); \
pDiffusionErrors[ index+2+delta ] = XMVectorMultiplyAdd( g_ErrorWeight1, vError, pDiffusionErrors[ index+2+delta ] ); \ pDiffusionErrors[ index+2+delta ] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[ index+2+delta ]); \
vError = XMVectorMultiply( vError, g_ErrorWeight7 ); \ vError = XMVectorMultiply(vError, g_ErrorWeight7); \
} \ } \
else \ else \
{ \ { \
/* Applied ordered dither */ \ /* Applied ordered dither */ \
target = XMVectorAdd( v, ordered[ index & 3 ] ); \ target = XMVectorAdd(v, ordered[ index & 3 ]); \
target = XMVectorRound( target ); \ target = XMVectorRound(target); \
} \ } \
\ \
target = XMVectorMin( scalev, target ); \ target = XMVectorMin(scalev, target); \
target = XMVectorMax( (clampzero) ? g_XMZero : ( XMVectorAdd( XMVectorNegate( scalev ), g_XMOne ) ), target ); \ target = XMVectorMax((clampzero) ? g_XMZero : (XMVectorAdd(XMVectorNegate(scalev), g_XMOne)), target); \
\ \
auto dPtr = &dest[ index ]; \ auto dPtr = &dest[ index ]; \
if (dPtr >= ePtr) break; \ 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; \ return true; \
} \ } \
@ -4563,21 +4563,21 @@ namespace
{\ {\
size_t rowPitch = srcImage.rowPitch;\ size_t rowPitch = srcImage.rowPitch;\
\ \
auto sourceE = reinterpret_cast<const srcType*>( pSrc + srcImage.slicePitch );\ auto sourceE = reinterpret_cast<const srcType*>(pSrc + srcImage.slicePitch);\
auto pSrcUV = pSrc + ( srcImage.height * rowPitch );\ 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 sPtrY0 = reinterpret_cast<const srcType*>(pSrc);\
auto sPtrY2 = reinterpret_cast<const srcType*>( pSrc + rowPitch );\ auto sPtrY2 = reinterpret_cast<const srcType*>(pSrc + rowPitch);\
auto sPtrUV = reinterpret_cast<const srcType*>( pSrcUV );\ auto sPtrUV = reinterpret_cast<const srcType*>(pSrcUV);\
\ \
destType * __restrict dPtr0 = reinterpret_cast<destType*>(pDest);\ destType * __restrict dPtr0 = reinterpret_cast<destType*>(pDest);\
destType * __restrict dPtr1 = reinterpret_cast<destType*>(pDest + destImage.rowPitch);\ 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 u = *(sPtrUV++);\
srcType v = *(sPtrUV++);\ srcType v = *(sPtrUV++);\

View File

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

View File

@ -126,19 +126,19 @@ namespace DirectX
{ {
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
// WIC helper functions // WIC helper functions
DXGI_FORMAT __cdecl _WICToDXGI( _In_ const GUID& guid ); DXGI_FORMAT __cdecl _WICToDXGI(_In_ const GUID& guid);
bool __cdecl _DXGIToWIC( _In_ DXGI_FORMAT format, _Out_ GUID& guid, _In_ bool ignoreRGBvsBGR = false ); 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) == 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*"); 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: case TEX_FILTER_DITHER:
return WICBitmapDitherTypeOrdered4x4; return WICBitmapDitherTypeOrdered4x4;
@ -151,16 +151,16 @@ namespace DirectX
} }
} }
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_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_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_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_*"); 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: case TEX_FILTER_POINT:
return WICBitmapInterpolationModeNearestNeighbor; return WICBitmapInterpolationModeNearestNeighbor;
@ -179,13 +179,14 @@ namespace DirectX
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
// Image helper functions // Image helper functions
void __cdecl _DetermineImageArray( _In_ const TexMetadata& metadata, _In_ DWORD cpFlags, void __cdecl _DetermineImageArray(
_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, _In_ const TexMetadata& metadata, _In_ DWORD cpFlags,
_Out_writes_(nImages) Image* images, _In_ size_t nImages ); _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);
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
// Conversion helper functions // Conversion helper functions
@ -221,60 +222,65 @@ namespace DirectX
CONVF_RGBA_MASK = 0xF0000, 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)) void __cdecl _CopyScanline(
_When_(pDestination == pSource, _Inout_updates_bytes_(outSize))
_When_(pDestination != pSource, _Out_writes_bytes_(outSize)) _When_(pDestination != pSource, _Out_writes_bytes_(outSize))
void* pDestination, _In_ size_t outSize, void* pDestination, _In_ size_t outSize,
_In_reads_bytes_(inSize) const void* pSource, _In_ size_t inSize, _In_reads_bytes_(inSize) const void* pSource, _In_ size_t inSize,
_In_ DXGI_FORMAT format, _In_ DWORD flags ); _In_ DXGI_FORMAT format, _In_ DWORD flags);
void __cdecl _SwizzleScanline( _When_(pDestination == pSource, _In_) void __cdecl _SwizzleScanline(
_When_(pDestination == pSource, _In_)
_When_(pDestination != pSource, _Out_writes_bytes_(outSize)) _When_(pDestination != pSource, _Out_writes_bytes_(outSize))
void* pDestination, _In_ size_t outSize, void* pDestination, _In_ size_t outSize,
_In_reads_bytes_(inSize) const void* pSource, _In_ size_t inSize, _In_reads_bytes_(inSize) const void* pSource, _In_ size_t inSize,
_In_ DXGI_FORMAT format, _In_ DWORD flags ); _In_ DXGI_FORMAT format, _In_ DWORD flags);
_Success_(return != false) _Success_(return != false) bool __cdecl _ExpandScanline(
bool __cdecl _ExpandScanline( _Out_writes_bytes_(outSize) void* pDestination, _In_ size_t outSize, _Out_writes_bytes_(outSize) void* pDestination, _In_ size_t outSize,
_In_ DXGI_FORMAT outFormat, _In_ DXGI_FORMAT outFormat,
_In_reads_bytes_(inSize) const void* pSource, _In_ size_t inSize, _In_reads_bytes_(inSize) const void* pSource, _In_ size_t inSize,
_In_ DXGI_FORMAT inFormat, _In_ DWORD flags ); _In_ DXGI_FORMAT inFormat, _In_ DWORD flags);
_Success_(return != false) _Success_(return != false) bool __cdecl _LoadScanline(
bool __cdecl _LoadScanline( _Out_writes_(count) XMVECTOR* pDestination, _In_ size_t count, _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_reads_bytes_(size) const void* pSource, _In_ size_t size, _In_ DXGI_FORMAT format);
_Success_(return != false) _Success_(return != false) bool __cdecl _LoadScanlineLinear(
bool __cdecl _LoadScanlineLinear( _Out_writes_(count) XMVECTOR* pDestination, _In_ size_t count, _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 ); _In_reads_bytes_(size) const void* pSource, _In_ size_t size, _In_ DXGI_FORMAT format, _In_ DWORD flags);
_Success_(return != false) _Success_(return != false) bool __cdecl _StoreScanline(
bool __cdecl _StoreScanline( _Out_writes_bytes_(size) void* pDestination, _In_ size_t size, _In_ DXGI_FORMAT format, _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 ); _In_reads_(count) const XMVECTOR* pSource, _In_ size_t count, _In_ float threshold = 0);
_Success_(return != false) _Success_(return != false) bool __cdecl _StoreScanlineLinear(
bool __cdecl _StoreScanlineLinear( _Out_writes_bytes_(size) void* pDestination, _In_ size_t size, _In_ DXGI_FORMAT format, _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 ); _Inout_updates_all_(count) XMVECTOR* pSource, _In_ size_t count, _In_ DWORD flags, _In_ float threshold = 0);
_Success_(return != false) _Success_(return != false) bool __cdecl _StoreScanlineDither(
bool __cdecl _StoreScanlineDither( _Out_writes_bytes_(size) void* pDestination, _In_ size_t size, _In_ DXGI_FORMAT format, _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_(count) XMVECTOR* pSource, _In_ size_t count, _In_ float threshold, size_t y, size_t z,
_Inout_updates_all_opt_(count+2) XMVECTOR* pDiffusionErrors ); _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_ const Image& destImage);
HRESULT __cdecl _ConvertFromR32G32B32A32( _In_ const Image& srcImage, _In_ DXGI_FORMAT format, _Inout_ ScratchImage& image ); 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, HRESULT __cdecl _ConvertFromR32G32B32A32(
_In_ DXGI_FORMAT format, _Out_ ScratchImage& result ); _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, void __cdecl _ConvertScanline(
_In_ DXGI_FORMAT outFormat, _In_ DXGI_FORMAT inFormat, _In_ DWORD flags ); _Inout_updates_all_(count) XMVECTOR* pBuffer, _In_ size_t count,
_In_ DXGI_FORMAT outFormat, _In_ DXGI_FORMAT inFormat, _In_ DWORD flags);
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
// DDS helper functions // DDS helper functions
HRESULT __cdecl _EncodeDDSHeader( _In_ const TexMetadata& metadata, DWORD flags, HRESULT __cdecl _EncodeDDSHeader(
_Out_writes_bytes_to_opt_(maxsize, required) void* pDestination, _In_ size_t maxsize, _Out_ size_t& required ); _In_ const TexMetadata& metadata, DWORD flags,
_Out_writes_bytes_to_opt_(maxsize, required) void* pDestination, _In_ size_t maxsize, _Out_ size_t& required);
} // namespace } // namespace

View File

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

View File

@ -99,63 +99,63 @@ DXGI_FORMAT DirectX::_WICToDXGI(const GUID& guid)
} }
_Use_decl_annotations_ _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:
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
if ( ignoreRGBvsBGR ) if (ignoreRGBvsBGR)
{ {
// If we are not doing conversion so don't really care about BGR vs RGB color-order, // 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 // 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) ); memcpy(&guid, &GUID_WICPixelFormat32bppBGRA, sizeof(GUID));
} }
else else
{ {
memcpy( &guid, &GUID_WICPixelFormat32bppRGBA, sizeof(GUID) ); memcpy(&guid, &GUID_WICPixelFormat32bppRGBA, sizeof(GUID));
} }
return true; return true;
case DXGI_FORMAT_D32_FLOAT: case DXGI_FORMAT_D32_FLOAT:
memcpy( &guid, &GUID_WICPixelFormat32bppGrayFloat, sizeof(GUID) ); memcpy(&guid, &GUID_WICPixelFormat32bppGrayFloat, sizeof(GUID));
return true; return true;
case DXGI_FORMAT_D16_UNORM: case DXGI_FORMAT_D16_UNORM:
memcpy( &guid, &GUID_WICPixelFormat16bppGray, sizeof(GUID) ); memcpy(&guid, &GUID_WICPixelFormat16bppGray, sizeof(GUID));
return true; return true;
case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
memcpy( &guid, &GUID_WICPixelFormat32bppBGRA, sizeof(GUID) ); memcpy(&guid, &GUID_WICPixelFormat32bppBGRA, sizeof(GUID));
return true; return true;
case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
memcpy( &guid, &GUID_WICPixelFormat32bppBGR, sizeof(GUID) ); memcpy(&guid, &GUID_WICPixelFormat32bppBGR, sizeof(GUID));
return true; return true;
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE) #if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
case DXGI_FORMAT_R32G32B32_FLOAT: case DXGI_FORMAT_R32G32B32_FLOAT:
if ( g_WIC2 ) if (g_WIC2)
{ {
memcpy( &guid, &GUID_WICPixelFormat96bppRGBFloat, sizeof(GUID) ); memcpy(&guid, &GUID_WICPixelFormat96bppRGBFloat, sizeof(GUID));
return true; return true;
} }
break; break;
#endif #endif
default: default:
for( size_t i=0; i < _countof(g_WICFormats); ++i ) for (size_t i = 0; i < _countof(g_WICFormats); ++i)
{ {
if ( g_WICFormats[i].format == format ) if (g_WICFormats[i].format == format)
{ {
memcpy( &guid, &g_WICFormats[i].wic, sizeof(GUID) ); memcpy(&guid, &g_WICFormats[i].wic, sizeof(GUID));
return true; return true;
} }
} }
break; break;
} }
memcpy( &guid, &GUID_NULL, sizeof(GUID) ); memcpy(&guid, &GUID_NULL, sizeof(GUID));
return false; return false;
} }

View File

@ -22,10 +22,10 @@
#ifdef __cplusplus_winrt #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(); auto randomAccessStream = ref new ::Windows::Storage::Streams::InMemoryRandomAccessStream();
return CreateStreamOverRandomAccessStream( randomAccessStream, IID_PPV_ARGS( stream ) ); return CreateStreamOverRandomAccessStream(randomAccessStream, IID_PPV_ARGS(stream));
} }
#else #else
@ -41,16 +41,16 @@
#include <windows.storage.streams.h> #include <windows.storage.streams.h>
#pragma warning(pop) #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; Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IRandomAccessStream> abiStream;
HRESULT hr = Windows::Foundation::ActivateInstance( HRESULT hr = Windows::Foundation::ActivateInstance(
Microsoft::WRL::Wrappers::HStringReference( RuntimeClass_Windows_Storage_Streams_InMemoryRandomAccessStream ).Get(), Microsoft::WRL::Wrappers::HStringReference(RuntimeClass_Windows_Storage_Streams_InMemoryRandomAccessStream).Get(),
abiStream.GetAddressOf() ); abiStream.GetAddressOf());
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = CreateStreamOverRandomAccessStream( abiStream.Get(), IID_PPV_ARGS( stream ) ); hr = CreateStreamOverRandomAccessStream(abiStream.Get(), IID_PPV_ARGS(stream));
} }
return hr; return hr;
} }
@ -60,9 +60,9 @@
#else #else
#pragma prefast(suppress:6387 28196, "a simple wrapper around an existing annotated function" ); #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 #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 ) \ #define AVERAGE4( res, p0, p1, p2, p3 ) \
{ \ { \
XMVECTOR v = XMVectorAdd( (p0), (p1) ); \ XMVECTOR v = XMVectorAdd((p0), (p1)); \
v = XMVectorAdd( v, (p2) ); \ v = XMVectorAdd(v, (p2)); \
v = XMVectorAdd( v, (p3) ); \ v = XMVectorAdd(v, (p3)); \
res = XMVectorMultiply( v, g_boxScale ); \ res = XMVectorMultiply(v, g_boxScale); \
} }
#define AVERAGE8( res, p0, p1, p2, p3, p4, p5, p6, p7) \ #define AVERAGE8( res, p0, p1, p2, p3, p4, p5, p6, p7) \
{ \ { \
XMVECTOR v = XMVectorAdd( (p0), (p1) ); \ XMVECTOR v = XMVectorAdd((p0), (p1)); \
v = XMVectorAdd( v, (p2) ); \ v = XMVectorAdd(v, (p2)); \
v = XMVectorAdd( v, (p3) ); \ v = XMVectorAdd(v, (p3)); \
v = XMVectorAdd( v, (p4) ); \ v = XMVectorAdd(v, (p4)); \
v = XMVectorAdd( v, (p5) ); \ v = XMVectorAdd(v, (p5)); \
v = XMVectorAdd( v, (p6) ); \ v = XMVectorAdd(v, (p6)); \
v = XMVectorAdd( v, (p7) ); \ v = XMVectorAdd(v, (p7)); \
res = XMVectorMultiply( v, g_boxScale3D ); \ 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 ) \ #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 ), \ 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 ) ) 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 ) \ #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 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 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 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 ); \ 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 ) ); \ 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 ) \ #define CUBIC_INTERPOLATE( res, dx, p0, p1, p2, p3 ) \
{ \ { \
XMVECTOR a0 = (p1); \ XMVECTOR a0 = (p1); \
XMVECTOR d0 = XMVectorSubtract( p0, a0 ); \ XMVECTOR d0 = XMVectorSubtract(p0, a0); \
XMVECTOR d2 = XMVectorSubtract( p2, a0 ); \ XMVECTOR d2 = XMVectorSubtract(p2, a0); \
XMVECTOR d3 = XMVectorSubtract( p3, a0 ); \ XMVECTOR d3 = XMVectorSubtract(p3, a0); \
XMVECTOR a1 = XMVectorSubtract( d2, XMVectorMultiply( g_cubicThird, d0 ) ); \ XMVECTOR a1 = XMVectorSubtract(d2, XMVectorMultiply(g_cubicThird, d0)); \
a1 = XMVectorSubtract( a1, XMVectorMultiply( g_cubicSixth, d3 ) ); \ a1 = XMVectorSubtract(a1, XMVectorMultiply(g_cubicSixth, d3)); \
XMVECTOR a2 = XMVectorAdd( XMVectorMultiply( g_cubicHalf, d0 ), XMVectorMultiply( g_cubicHalf, d2 ) ); \ XMVECTOR a2 = XMVectorAdd(XMVectorMultiply(g_cubicHalf, d0), XMVectorMultiply(g_cubicHalf, d2)); \
XMVECTOR a3 = XMVectorSubtract( XMVectorMultiply( g_cubicSixth, d3 ), XMVectorMultiply( g_cubicSixth, d0 ) ); \ XMVECTOR a3 = XMVectorSubtract(XMVectorMultiply(g_cubicSixth, d3), XMVectorMultiply(g_cubicSixth, d0)); \
a3 = XMVectorSubtract( a3, XMVectorMultiply( g_cubicHalf, d2 ) ); \ a3 = XMVectorSubtract(a3, XMVectorMultiply(g_cubicHalf, d2)); \
XMVECTOR vdx = XMVectorReplicate( dx ); \ XMVECTOR vdx = XMVectorReplicate(dx); \
XMVECTOR vdx2 = XMVectorMultiply( vdx, vdx ); \ XMVECTOR vdx2 = XMVectorMultiply(vdx, vdx); \
XMVECTOR vdx3 = XMVectorMultiply( vdx2, vdx ); \ XMVECTOR vdx3 = XMVectorMultiply(vdx2, vdx); \
res = XMVectorAdd( XMVectorAdd( XMVectorAdd( a0, XMVectorMultiply( a1, vdx ) ), XMVectorMultiply( a2, vdx2 ) ), XMVectorMultiply( a3, vdx3 ) ); \ 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; 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); } }; struct find_closer { void operator()(HANDLE h) { assert(h != INVALID_HANDLE_VALUE); if (h) FindClose(h); } };