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)
28 #include <directxmath.h>
29 #include <directxpackedvector.h>
44 #if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) || defined(_WIN7_PLATFORM_UPDATE)
49 #pragma warning(disable : 4005)
53 #if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) && !defined(DXGI_1_2_FORMATS)
54 #define DXGI_1_2_FORMATS
57 #include "DirectXTex.h"
61 struct IWICImagingFactory;
63 #define TEX_FILTER_MASK 0xF00000
67 //---------------------------------------------------------------------------------
68 // WIC helper functions
69 DXGI_FORMAT _WICToDXGI( _In_ const GUID& guid );
70 bool _DXGIToWIC( _In_ DXGI_FORMAT format, _Out_ GUID& guid );
72 IWICImagingFactory* _GetWIC();
76 inline WICBitmapDitherType _GetWICDither( _In_ DWORD flags )
78 static_assert( TEX_FILTER_DITHER == 0x10000, "TEX_FILTER_DITHER* flag values don't match mask" );
80 static_assert( TEX_FILTER_DITHER == WIC_FLAGS_DITHER, "TEX_FILTER_DITHER* should match WIC_FLAGS_DITHER*" );
81 static_assert( TEX_FILTER_DITHER_DIFFUSION == WIC_FLAGS_DITHER_DIFFUSION, "TEX_FILTER_DITHER* should match WIC_FLAGS_DITHER*" );
83 switch( flags & 0xF0000 )
85 case TEX_FILTER_DITHER:
86 return WICBitmapDitherTypeOrdered4x4;
88 case TEX_FILTER_DITHER_DIFFUSION:
89 return WICBitmapDitherTypeErrorDiffusion;
92 return WICBitmapDitherTypeNone;
96 inline WICBitmapInterpolationMode _GetWICInterp( _In_ DWORD flags )
98 static_assert( TEX_FILTER_POINT == 0x100000, "TEX_FILTER_ flag values don't match TEX_FILTER_MASK" );
100 static_assert( TEX_FILTER_POINT == WIC_FLAGS_FILTER_POINT, "TEX_FILTER_* flags should match WIC_FLAGS_FILTER_*" );
101 static_assert( TEX_FILTER_LINEAR == WIC_FLAGS_FILTER_LINEAR, "TEX_FILTER_* flags should match WIC_FLAGS_FILTER_*" );
102 static_assert( TEX_FILTER_CUBIC == WIC_FLAGS_FILTER_CUBIC, "TEX_FILTER_* flags should match WIC_FLAGS_FILTER_*" );
103 static_assert( TEX_FILTER_FANT == WIC_FLAGS_FILTER_FANT, "TEX_FILTER_* flags should match WIC_FLAGS_FILTER_*" );
105 switch( flags & TEX_FILTER_MASK )
107 case TEX_FILTER_POINT:
108 return WICBitmapInterpolationModeNearestNeighbor;
110 case TEX_FILTER_LINEAR:
111 return WICBitmapInterpolationModeLinear;
113 case TEX_FILTER_CUBIC:
114 return WICBitmapInterpolationModeCubic;
116 case TEX_FILTER_FANT:
118 return WICBitmapInterpolationModeFant;
122 //---------------------------------------------------------------------------------
123 // Image helper functions
124 void _DetermineImageArray( _In_ const TexMetadata& metadata, _In_ DWORD cpFlags,
125 _Out_ size_t& nImages, _Out_ size_t& pixelSize );
127 bool _SetupImageArray( _In_bytecount_(pixelSize) uint8_t *pMemory, _In_ size_t pixelSize,
128 _In_ const TexMetadata& metadata, _In_ DWORD cpFlags,
129 _Out_cap_(nImages) Image* images, _In_ size_t nImages );
131 //---------------------------------------------------------------------------------
132 // Conversion helper functions
134 enum TEXP_SCANLINE_FLAGS
136 TEXP_SCANLINE_NONE = 0,
137 TEXP_SCANLINE_SETALPHA = 0x1, // Set alpha channel to known opaque value
138 TEXP_SCANLINE_LEGACY = 0x2, // Enables specific legacy format conversion cases
149 CONVF_STENCIL = 0x40,
150 CONVF_SHAREDEXP = 0x80,
153 CONVF_PACKED = 0x400,
159 CONVF_RGB_MASK = 0x70000,
160 CONVF_RGBA_MASK = 0xF0000,
163 DWORD _GetConvertFlags( _In_ DXGI_FORMAT format );
165 void _CopyScanline( _Out_bytecap_(outSize) LPVOID pDestination, _In_ size_t outSize,
166 _In_bytecount_(inSize) LPCVOID pSource, _In_ size_t inSize,
167 _In_ DXGI_FORMAT format, _In_ DWORD flags );
169 void _SwizzleScanline( _Out_bytecap_(outSize) LPVOID pDestination, _In_ size_t outSize,
170 _In_bytecount_(inSize) LPCVOID pSource, _In_ size_t inSize,
171 _In_ DXGI_FORMAT format, _In_ DWORD flags );
173 bool _ExpandScanline( _Out_bytecap_(outSize) LPVOID pDestination, _In_ size_t outSize,
174 _In_ DXGI_FORMAT outFormat,
175 _In_bytecount_(inSize) LPCVOID pSource, _In_ size_t inSize,
176 _In_ DXGI_FORMAT inFormat, _In_ DWORD flags );
178 bool _LoadScanline( _Out_cap_(count) XMVECTOR* pDestination, _In_ size_t count,
179 _In_bytecount_(size) LPCVOID pSource, _In_ size_t size, _In_ DXGI_FORMAT format );
181 bool _StoreScanline( _Out_bytecap_(size) LPVOID pDestination, _In_ size_t size, _In_ DXGI_FORMAT format,
182 _In_count_(count) const XMVECTOR* pSource, _In_ size_t count );
184 HRESULT _ConvertToR32G32B32A32( _In_ const Image& srcImage, _Inout_ ScratchImage& image );
186 HRESULT _ConvertFromR32G32B32A32( _In_ const Image& srcImage, _In_ const Image& destImage );
187 HRESULT _ConvertFromR32G32B32A32( _In_ const Image& srcImage, _In_ DXGI_FORMAT format, _Inout_ ScratchImage& image );
188 HRESULT _ConvertFromR32G32B32A32( _In_count_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
189 _In_ DXGI_FORMAT format, _Out_ ScratchImage& result );
191 void _ConvertScanline( _Inout_count_(count) XMVECTOR* pBuffer, _In_ size_t count,
192 _In_ DXGI_FORMAT outFormat, _In_ DXGI_FORMAT inFormat, _In_ DWORD flags );
194 //---------------------------------------------------------------------------------
195 // DDS helper functions
196 HRESULT _EncodeDDSHeader( _In_ const TexMetadata& metadata, DWORD flags,
197 _Out_opt_cap_x_(maxsize) LPVOID pDestination, _In_ size_t maxsize, _Out_ size_t& required );