]> git.cworth.org Git - apitrace/blob - thirdparty/directxtex/DirectXTex/DirectXTexP.h
thirdparty/directxtex: Import DirectXTex library.
[apitrace] / thirdparty / directxtex / DirectXTex / DirectXTexP.h
1 //-------------------------------------------------------------------------------------
2 // DirectXTexp.h
3 //  
4 // DirectX Texture Library - Private header
5 //
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
9 // PARTICULAR PURPOSE.
10 //
11 // Copyright (c) Microsoft Corporation. All rights reserved.
12 //
13 // http://go.microsoft.com/fwlink/?LinkId=248926
14 //-------------------------------------------------------------------------------------
15
16 #if defined(_MSC_VER) && (_MSC_VER > 1000)
17 #pragma once
18 #endif
19
20 #define NOMINMAX
21 #include <windows.h>
22
23 #ifdef USE_XNAMATH
24 #include <xnamath.h>
25 #else
26 #include <directxmath.h>
27 #include <directxpackedvector.h>
28 #endif
29
30 #include <assert.h>
31
32 #include <malloc.h>
33 #include <memory>
34
35 #include <vector>
36
37 #include <stdlib.h>
38 #include <search.h>
39
40 #include <ole2.h>
41
42 #if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) || defined(_WIN7_PLATFORM_UPDATE)
43 #include <d2d1.h>
44 #endif
45
46 #pragma warning(push)
47 #pragma warning(disable : 4005)
48 #include <wincodec.h>
49 #pragma warning(pop)
50
51 #if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) && !defined(DXGI_1_2_FORMATS)
52 #define DXGI_1_2_FORMATS
53 #endif
54
55 #include "directxtex.h"
56
57 #include "scoped.h"
58
59 struct IWICImagingFactory;
60
61 #define TEX_FILTER_MASK 0xF00000
62
63 namespace DirectX
64 {
65     //---------------------------------------------------------------------------------
66     // WIC helper functions
67     DXGI_FORMAT _WICToDXGI( _In_ const GUID& guid );
68     bool _DXGIToWIC( _In_ DXGI_FORMAT format, _Out_ GUID& guid );
69
70     IWICImagingFactory* _GetWIC();
71
72     bool _IsWIC2();
73
74     inline WICBitmapDitherType _GetWICDither( _In_ DWORD flags )
75     {
76         static_assert( TEX_FILTER_DITHER == 0x10000, "TEX_FILTER_DITHER* flag values don't match mask" );
77
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*" );
80
81         switch( flags & 0xF0000 )
82         {
83         case TEX_FILTER_DITHER:
84             return WICBitmapDitherTypeOrdered4x4;
85
86         case TEX_FILTER_DITHER_DIFFUSION:
87             return WICBitmapDitherTypeErrorDiffusion;
88
89         default:
90             return WICBitmapDitherTypeNone;
91         }
92     }
93
94     inline WICBitmapInterpolationMode _GetWICInterp( _In_ DWORD flags )
95     {
96         static_assert( TEX_FILTER_POINT == 0x100000, "TEX_FILTER_ flag values don't match TEX_FILTER_MASK" );
97
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_*"  );
102
103         switch( flags & TEX_FILTER_MASK )
104         {
105         case TEX_FILTER_POINT:
106             return WICBitmapInterpolationModeNearestNeighbor;
107
108         case TEX_FILTER_LINEAR:
109             return WICBitmapInterpolationModeLinear;
110
111         case TEX_FILTER_CUBIC:
112             return WICBitmapInterpolationModeCubic;
113
114         case TEX_FILTER_FANT:
115         default:
116             return WICBitmapInterpolationModeFant;
117         }
118     }
119
120     //---------------------------------------------------------------------------------
121     // Image helper functions
122     void _DetermineImageArray( _In_ const TexMetadata& metadata, _In_ DWORD cpFlags,
123                                _Out_ size_t& nImages, _Out_ size_t& pixelSize );
124
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 );
128
129     //---------------------------------------------------------------------------------
130     // Conversion helper functions
131
132     enum TEXP_SCANLINE_FLAGS
133     {
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
137     };
138
139     enum CONVERT_FLAGS
140     {
141         CONVF_FLOAT     = 0x1,
142         CONVF_UNORM     = 0x2,
143         CONVF_UINT      = 0x4,
144         CONVF_SNORM     = 0x8, 
145         CONVF_SINT      = 0x10,
146         CONVF_DEPTH     = 0x20,
147         CONVF_STENCIL   = 0x40,
148         CONVF_SHAREDEXP = 0x80,
149         CONVF_BGR       = 0x100,
150         CONVF_X2        = 0x200,
151         CONVF_PACKED    = 0x400,
152         CONVF_BC        = 0x800,
153         CONVF_R         = 0x10000,
154         CONVF_G         = 0x20000,
155         CONVF_B         = 0x40000,
156         CONVF_A         = 0x80000,
157         CONVF_RGB_MASK  = 0x70000,
158         CONVF_RGBA_MASK = 0xF0000,
159     };
160
161     DWORD _GetConvertFlags( _In_ DXGI_FORMAT format );
162
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 );
166
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 );
170
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 );
175
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 );
178
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 );
181
182     HRESULT _ConvertToR32G32B32A32( _In_ const Image& srcImage, _Inout_ ScratchImage& image );
183
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 );
188
189     void _ConvertScanline( _Inout_count_(count) XMVECTOR* pBuffer, _In_ size_t count,
190                            _In_ DXGI_FORMAT outFormat, _In_ DXGI_FORMAT inFormat, _In_ DWORD flags );
191
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 );
196
197 }; // namespace