1 //-------------------------------------------------------------------------------------
4 // DirectX Texture Library - Private header
6 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
7 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
8 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
11 // Copyright (c) Microsoft Corporation. All rights reserved.
13 // http://go.microsoft.com/fwlink/?LinkId=248926
14 //-------------------------------------------------------------------------------------
16 #if defined(_MSC_VER) && (_MSC_VER > 1000)
26 #include <directxmath.h>
27 #include <directxpackedvector.h>
42 #if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) || defined(_WIN7_PLATFORM_UPDATE)
47 #pragma warning(disable : 4005)
51 #if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) && !defined(DXGI_1_2_FORMATS)
52 #define DXGI_1_2_FORMATS
55 #include "directxtex.h"
59 struct IWICImagingFactory;
61 #define TEX_FILTER_MASK 0xF00000
65 //---------------------------------------------------------------------------------
66 // WIC helper functions
67 DXGI_FORMAT _WICToDXGI( _In_ const GUID& guid );
68 bool _DXGIToWIC( _In_ DXGI_FORMAT format, _Out_ GUID& guid );
70 IWICImagingFactory* _GetWIC();
74 inline WICBitmapDitherType _GetWICDither( _In_ DWORD flags )
76 static_assert( TEX_FILTER_DITHER == 0x10000, "TEX_FILTER_DITHER* flag values don't match mask" );
78 static_assert( TEX_FILTER_DITHER == WIC_FLAGS_DITHER, "TEX_FILTER_DITHER* should match WIC_FLAGS_DITHER*" );
79 static_assert( TEX_FILTER_DITHER_DIFFUSION == WIC_FLAGS_DITHER_DIFFUSION, "TEX_FILTER_DITHER* should match WIC_FLAGS_DITHER*" );
81 switch( flags & 0xF0000 )
83 case TEX_FILTER_DITHER:
84 return WICBitmapDitherTypeOrdered4x4;
86 case TEX_FILTER_DITHER_DIFFUSION:
87 return WICBitmapDitherTypeErrorDiffusion;
90 return WICBitmapDitherTypeNone;
94 inline WICBitmapInterpolationMode _GetWICInterp( _In_ DWORD flags )
96 static_assert( TEX_FILTER_POINT == 0x100000, "TEX_FILTER_ flag values don't match TEX_FILTER_MASK" );
98 static_assert( TEX_FILTER_POINT == WIC_FLAGS_FILTER_POINT, "TEX_FILTER_* flags should match WIC_FLAGS_FILTER_*" );
99 static_assert( TEX_FILTER_LINEAR == WIC_FLAGS_FILTER_LINEAR, "TEX_FILTER_* flags should match WIC_FLAGS_FILTER_*" );
100 static_assert( TEX_FILTER_CUBIC == WIC_FLAGS_FILTER_CUBIC, "TEX_FILTER_* flags should match WIC_FLAGS_FILTER_*" );
101 static_assert( TEX_FILTER_FANT == WIC_FLAGS_FILTER_FANT, "TEX_FILTER_* flags should match WIC_FLAGS_FILTER_*" );
103 switch( flags & TEX_FILTER_MASK )
105 case TEX_FILTER_POINT:
106 return WICBitmapInterpolationModeNearestNeighbor;
108 case TEX_FILTER_LINEAR:
109 return WICBitmapInterpolationModeLinear;
111 case TEX_FILTER_CUBIC:
112 return WICBitmapInterpolationModeCubic;
114 case TEX_FILTER_FANT:
116 return WICBitmapInterpolationModeFant;
120 //---------------------------------------------------------------------------------
121 // Image helper functions
122 void _DetermineImageArray( _In_ const TexMetadata& metadata, _In_ DWORD cpFlags,
123 _Out_ size_t& nImages, _Out_ size_t& pixelSize );
125 bool _SetupImageArray( _In_bytecount_(pixelSize) uint8_t *pMemory, _In_ size_t pixelSize,
126 _In_ const TexMetadata& metadata, _In_ DWORD cpFlags,
127 _Out_cap_(nImages) Image* images, _In_ size_t nImages );
129 //---------------------------------------------------------------------------------
130 // Conversion helper functions
132 enum TEXP_SCANLINE_FLAGS
134 TEXP_SCANLINE_NONE = 0,
135 TEXP_SCANLINE_SETALPHA = 0x1, // Set alpha channel to known opaque value
136 TEXP_SCANLINE_LEGACY = 0x2, // Enables specific legacy format conversion cases
147 CONVF_STENCIL = 0x40,
148 CONVF_SHAREDEXP = 0x80,
151 CONVF_PACKED = 0x400,
157 CONVF_RGB_MASK = 0x70000,
158 CONVF_RGBA_MASK = 0xF0000,
161 DWORD _GetConvertFlags( _In_ DXGI_FORMAT format );
163 void _CopyScanline( _Out_bytecap_(outSize) LPVOID pDestination, _In_ size_t outSize,
164 _In_bytecount_(inSize) LPCVOID pSource, _In_ size_t inSize,
165 _In_ DXGI_FORMAT format, _In_ DWORD flags );
167 void _SwizzleScanline( _Out_bytecap_(outSize) LPVOID pDestination, _In_ size_t outSize,
168 _In_bytecount_(inSize) LPCVOID pSource, _In_ size_t inSize,
169 _In_ DXGI_FORMAT format, _In_ DWORD flags );
171 bool _ExpandScanline( _Out_bytecap_(outSize) LPVOID pDestination, _In_ size_t outSize,
172 _In_ DXGI_FORMAT outFormat,
173 _In_bytecount_(inSize) LPCVOID pSource, _In_ size_t inSize,
174 _In_ DXGI_FORMAT inFormat, _In_ DWORD flags );
176 bool _LoadScanline( _Out_cap_(count) XMVECTOR* pDestination, _In_ size_t count,
177 _In_bytecount_(size) LPCVOID pSource, _In_ size_t size, _In_ DXGI_FORMAT format );
179 bool _StoreScanline( _Out_bytecap_(size) LPVOID pDestination, _In_ size_t size, _In_ DXGI_FORMAT format,
180 _In_count_(count) const XMVECTOR* pSource, _In_ size_t count );
182 HRESULT _ConvertToR32G32B32A32( _In_ const Image& srcImage, _Inout_ ScratchImage& image );
184 HRESULT _ConvertFromR32G32B32A32( _In_ const Image& srcImage, _In_ const Image& destImage );
185 HRESULT _ConvertFromR32G32B32A32( _In_ const Image& srcImage, _In_ DXGI_FORMAT format, _Inout_ ScratchImage& image );
186 HRESULT _ConvertFromR32G32B32A32( _In_count_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
187 _In_ DXGI_FORMAT format, _Out_ ScratchImage& result );
189 void _ConvertScanline( _Inout_count_(count) XMVECTOR* pBuffer, _In_ size_t count,
190 _In_ DXGI_FORMAT outFormat, _In_ DXGI_FORMAT inFormat, _In_ DWORD flags );
192 //---------------------------------------------------------------------------------
193 // DDS helper functions
194 HRESULT _EncodeDDSHeader( _In_ const TexMetadata& metadata, DWORD flags,
195 _Out_opt_cap_x_(maxsize) LPVOID pDestination, _In_ size_t maxsize, _Out_ size_t& required );