]> git.cworth.org Git - apitrace/blob - thirdparty/directxtex/DirectXTex/DirectXTexP.h
directxtex: Fix include filename case.
[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 #ifndef NOMINMAX
21 #define NOMINMAX
22 #endif
23 #include <windows.h>
24
25 #ifdef USE_XNAMATH
26 #include <xnamath.h>
27 #else
28 #include <directxmath.h>
29 #include <directxpackedvector.h>
30 #endif
31
32 #include <assert.h>
33
34 #include <malloc.h>
35 #include <memory>
36
37 #include <vector>
38
39 #include <stdlib.h>
40 #include <search.h>
41
42 #include <ole2.h>
43
44 #if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) || defined(_WIN7_PLATFORM_UPDATE)
45 #include <d2d1.h>
46 #endif
47
48 #pragma warning(push)
49 #pragma warning(disable : 4005)
50 #include <wincodec.h>
51 #pragma warning(pop)
52
53 #if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) && !defined(DXGI_1_2_FORMATS)
54 #define DXGI_1_2_FORMATS
55 #endif
56
57 #include "DirectXTex.h"
58
59 #include "scoped.h"
60
61 struct IWICImagingFactory;
62
63 #define TEX_FILTER_MASK 0xF00000
64
65 namespace DirectX
66 {
67     //---------------------------------------------------------------------------------
68     // WIC helper functions
69     DXGI_FORMAT _WICToDXGI( _In_ const GUID& guid );
70     bool _DXGIToWIC( _In_ DXGI_FORMAT format, _Out_ GUID& guid );
71
72     IWICImagingFactory* _GetWIC();
73
74     bool _IsWIC2();
75
76     inline WICBitmapDitherType _GetWICDither( _In_ DWORD flags )
77     {
78         static_assert( TEX_FILTER_DITHER == 0x10000, "TEX_FILTER_DITHER* flag values don't match mask" );
79
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*" );
82
83         switch( flags & 0xF0000 )
84         {
85         case TEX_FILTER_DITHER:
86             return WICBitmapDitherTypeOrdered4x4;
87
88         case TEX_FILTER_DITHER_DIFFUSION:
89             return WICBitmapDitherTypeErrorDiffusion;
90
91         default:
92             return WICBitmapDitherTypeNone;
93         }
94     }
95
96     inline WICBitmapInterpolationMode _GetWICInterp( _In_ DWORD flags )
97     {
98         static_assert( TEX_FILTER_POINT == 0x100000, "TEX_FILTER_ flag values don't match TEX_FILTER_MASK" );
99
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_*"  );
104
105         switch( flags & TEX_FILTER_MASK )
106         {
107         case TEX_FILTER_POINT:
108             return WICBitmapInterpolationModeNearestNeighbor;
109
110         case TEX_FILTER_LINEAR:
111             return WICBitmapInterpolationModeLinear;
112
113         case TEX_FILTER_CUBIC:
114             return WICBitmapInterpolationModeCubic;
115
116         case TEX_FILTER_FANT:
117         default:
118             return WICBitmapInterpolationModeFant;
119         }
120     }
121
122     //---------------------------------------------------------------------------------
123     // Image helper functions
124     void _DetermineImageArray( _In_ const TexMetadata& metadata, _In_ DWORD cpFlags,
125                                _Out_ size_t& nImages, _Out_ size_t& pixelSize );
126
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 );
130
131     //---------------------------------------------------------------------------------
132     // Conversion helper functions
133
134     enum TEXP_SCANLINE_FLAGS
135     {
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
139     };
140
141     enum CONVERT_FLAGS
142     {
143         CONVF_FLOAT     = 0x1,
144         CONVF_UNORM     = 0x2,
145         CONVF_UINT      = 0x4,
146         CONVF_SNORM     = 0x8, 
147         CONVF_SINT      = 0x10,
148         CONVF_DEPTH     = 0x20,
149         CONVF_STENCIL   = 0x40,
150         CONVF_SHAREDEXP = 0x80,
151         CONVF_BGR       = 0x100,
152         CONVF_X2        = 0x200,
153         CONVF_PACKED    = 0x400,
154         CONVF_BC        = 0x800,
155         CONVF_R         = 0x10000,
156         CONVF_G         = 0x20000,
157         CONVF_B         = 0x40000,
158         CONVF_A         = 0x80000,
159         CONVF_RGB_MASK  = 0x70000,
160         CONVF_RGBA_MASK = 0xF0000,
161     };
162
163     DWORD _GetConvertFlags( _In_ DXGI_FORMAT format );
164
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 );
168
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 );
172
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 );
177
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 );
180
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 );
183
184     HRESULT _ConvertToR32G32B32A32( _In_ const Image& srcImage, _Inout_ ScratchImage& image );
185
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 );
190
191     void _ConvertScanline( _Inout_count_(count) XMVECTOR* pBuffer, _In_ size_t count,
192                            _In_ DXGI_FORMAT outFormat, _In_ DXGI_FORMAT inFormat, _In_ DWORD flags );
193
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 );
198
199 }; // namespace