Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
DirectXTex.h
Go to the documentation of this file.
1 //-------------------------------------------------------------------------------------
2 // DirectXTex.h
3 //
4 // DirectX Texture Library
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 #if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) && (_WIN32_WINNT <= _WIN32_WINNT_WIN8)
21 #error WIC is not supported on Windows Phone 8.0
22 #endif
23 
24 // VS 2010's stdint.h conflicts with intsafe.h
25 #pragma warning(push)
26 #pragma warning(disable : 4005)
27 #include <stdint.h>
28 #pragma warning(pop)
29 
30 #include <algorithm>
31 #include <functional>
32 
33 #if defined(_XBOX_ONE) && defined(_TITLE) && MONOLITHIC
34 #include <d3d11_x.h>
35 #define DCOMMON_H_INCLUDED
36 #else
37 #include <d3d11_1.h>
38 #endif
39 
40 #include <ocidl.h>
41 
42 #define DIRECTX_TEX_VERSION 130
43 
44 namespace DirectX
45 {
46 
47  //---------------------------------------------------------------------------------
48  // DXGI Format Utilities
49  bool IsValid( _In_ DXGI_FORMAT fmt );
50  bool IsCompressed( _In_ DXGI_FORMAT fmt );
51  bool IsPacked( _In_ DXGI_FORMAT fmt );
52  bool IsVideo( _In_ DXGI_FORMAT fmt );
53  bool IsPlanar( _In_ DXGI_FORMAT fmt );
54  bool IsPalettized( _In_ DXGI_FORMAT fmt );
55  bool IsDepthStencil(_In_ DXGI_FORMAT fmt );
56  bool IsSRGB( _In_ DXGI_FORMAT fmt );
57  bool IsTypeless( _In_ DXGI_FORMAT fmt, _In_ bool partialTypeless = true );
58 
59  bool HasAlpha( _In_ DXGI_FORMAT fmt );
60 
61  size_t BitsPerPixel( _In_ DXGI_FORMAT fmt );
62 
63  size_t BitsPerColor( _In_ DXGI_FORMAT fmt );
64 
65  enum CP_FLAGS
66  {
67  CP_FLAGS_NONE = 0x0, // Normal operation
68  CP_FLAGS_LEGACY_DWORD = 0x1, // Assume pitch is DWORD aligned instead of BYTE aligned
69  CP_FLAGS_PARAGRAPH = 0x2, // Assume pitch is 16-byte aligned instead of BYTE aligned
70  CP_FLAGS_24BPP = 0x10000, // Override with a legacy 24 bits-per-pixel format size
71  CP_FLAGS_16BPP = 0x20000, // Override with a legacy 16 bits-per-pixel format size
72  CP_FLAGS_8BPP = 0x40000, // Override with a legacy 8 bits-per-pixel format size
73  };
74 
75  void ComputePitch( _In_ DXGI_FORMAT fmt, _In_ size_t width, _In_ size_t height,
76  _Out_ size_t& rowPitch, _Out_ size_t& slicePitch, _In_ DWORD flags = CP_FLAGS_NONE );
77 
78  size_t ComputeScanlines( _In_ DXGI_FORMAT fmt, _In_ size_t height );
79 
80  DXGI_FORMAT MakeSRGB( _In_ DXGI_FORMAT fmt );
81  DXGI_FORMAT MakeTypeless( _In_ DXGI_FORMAT fmt );
82  DXGI_FORMAT MakeTypelessUNORM( _In_ DXGI_FORMAT fmt );
83  DXGI_FORMAT MakeTypelessFLOAT( _In_ DXGI_FORMAT fmt );
84 
85  //---------------------------------------------------------------------------------
86  // Texture metadata
88  // Subset here matches D3D10_RESOURCE_DIMENSION and D3D11_RESOURCE_DIMENSION
89  {
93  };
94 
96  // Subset here matches D3D10_RESOURCE_MISC_FLAG and D3D11_RESOURCE_MISC_FLAG
97  {
99  };
100 
102  {
104  };
107  // Matches DDS_ALPHA_MODE, encoded in MISC_FLAGS2
108  {
114  };
115 
116  struct TexMetadata
117  {
118  size_t width;
119  size_t height; // Should be 1 for 1D textures
120  size_t depth; // Should be 1 for 1D or 2D textures
121  size_t arraySize; // For cubemap, this is a multiple of 6
122  size_t mipLevels;
123  uint32_t miscFlags;
124  uint32_t miscFlags2;
125  DXGI_FORMAT format;
127 
128  size_t ComputeIndex( _In_ size_t mip, _In_ size_t item, _In_ size_t slice ) const;
129  // Returns size_t(-1) to indicate an out-of-range error
130 
131  bool IsCubemap() const { return (miscFlags & TEX_MISC_TEXTURECUBE) != 0; }
132  // Helper for miscFlags
133 
135  void SetAlphaMode( TEX_ALPHA_MODE mode ) { miscFlags2 = (miscFlags2 & ~TEX_MISC2_ALPHA_MODE_MASK) | static_cast<uint32_t>(mode); }
136  // Helpers for miscFlags2
137 
138  bool IsVolumemap() const { return (dimension == TEX_DIMENSION_TEXTURE3D); }
139  // Helper for dimension
140  };
141 
143  {
145 
147  // Assume pitch is DWORD aligned instead of BYTE aligned (used by some legacy DDS files)
148 
150  // Do not implicitly convert legacy formats that result in larger pixel sizes (24 bpp, 3:3:2, A8L8, A4L4, P8, A8P8)
153  // Do not use work-around for long-standing D3DX DDS file format issue which reversed the 10:10:10:2 color order masks
154 
156  // Convert DXGI 1.1 BGR formats to DXGI_FORMAT_R8G8B8A8_UNORM to avoid use of optional WDDM 1.1 formats
157 
159  // Conversions avoid use of 565, 5551, and 4444 formats and instead expand to 8888 to avoid use of optional WDDM 1.2 formats
160 
162  // When loading legacy luminance formats expand replicating the color channels rather than leaving them packed (L8, L16, A8L8)
163 
165  // Always use the 'DX10' header extension for DDS writer (i.e. don't try to write DX9 compatible DDS files)
166 
168  // DDS_FLAGS_FORCE_DX10_EXT including miscFlags2 information (result may not be compatible with D3DX10 or D3DX11)
169  };
170 
172  {
176  // Loads DXGI 1.1 BGR formats as DXGI_FORMAT_R8G8B8A8_UNORM to avoid use of optional WDDM 1.1 formats
177 
179  // Loads DXGI 1.1 X2 10:10:10:2 format as DXGI_FORMAT_R10G10B10A2_UNORM
180 
182  // Loads 565, 5551, and 4444 formats as 8888 to avoid use of optional WDDM 1.2 formats
183 
185  // Loads 1-bit monochrome (black & white) as R1_UNORM rather than 8-bit grayscale
186 
188  // Loads all images in a multi-frame file, converting/resizing to match the first frame as needed, defaults to 0th frame otherwise
189 
191  // Ignores sRGB metadata if present in the file
192 
193  WIC_FLAGS_DITHER = 0x10000,
194  // Use ordered 4x4 dithering for any required conversions
195 
197  // Use error-diffusion dithering for any required conversions
198 
202  WIC_FLAGS_FILTER_FANT = 0x400000, // Combination of Linear and Box filter
203  // Filtering mode to use for any required image resizing (only needed when loading arrays of differently sized images; defaults to Fant)
204  };
205 
206  HRESULT GetMetadataFromDDSMemory( _In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size, _In_ DWORD flags,
207  _Out_ TexMetadata& metadata );
208  HRESULT GetMetadataFromDDSFile( _In_z_ LPCWSTR szFile, _In_ DWORD flags,
209  _Out_ TexMetadata& metadata );
210 
211  HRESULT GetMetadataFromTGAMemory( _In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size,
212  _Out_ TexMetadata& metadata );
213  HRESULT GetMetadataFromTGAFile( _In_z_ LPCWSTR szFile,
214  _Out_ TexMetadata& metadata );
215 
216  HRESULT GetMetadataFromWICMemory( _In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size, _In_ DWORD flags,
217  _Out_ TexMetadata& metadata );
218  HRESULT GetMetadataFromWICFile( _In_z_ LPCWSTR szFile, _In_ DWORD flags,
219  _Out_ TexMetadata& metadata );
220 
221  //---------------------------------------------------------------------------------
222  // Bitmap image container
223  struct Image
224  {
225  size_t width;
226  size_t height;
227  DXGI_FORMAT format;
228  size_t rowPitch;
229  size_t slicePitch;
231  };
232 
234  {
235  public:
237  : _nimages(0), _size(0), _image(nullptr), _memory(nullptr) {}
239  : _nimages(0), _size(0), _image(nullptr), _memory(nullptr) { *this = std::move(moveFrom); }
241 
242  ScratchImage& operator= (ScratchImage&& moveFrom);
243 
244  HRESULT Initialize( _In_ const TexMetadata& mdata, _In_ DWORD flags = CP_FLAGS_NONE );
245 
246  HRESULT Initialize1D( _In_ DXGI_FORMAT fmt, _In_ size_t length, _In_ size_t arraySize, _In_ size_t mipLevels, _In_ DWORD flags = CP_FLAGS_NONE );
247  HRESULT 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 );
248  HRESULT 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 );
249  HRESULT 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 );
250 
251  HRESULT InitializeFromImage( _In_ const Image& srcImage, _In_ bool allow1D = false, _In_ DWORD flags = CP_FLAGS_NONE );
252  HRESULT InitializeArrayFromImages( _In_reads_(nImages) const Image* images, _In_ size_t nImages, _In_ bool allow1D = false, _In_ DWORD flags = CP_FLAGS_NONE );
253  HRESULT InitializeCubeFromImages( _In_reads_(nImages) const Image* images, _In_ size_t nImages, _In_ DWORD flags = CP_FLAGS_NONE );
254  HRESULT Initialize3DFromImages( _In_reads_(depth) const Image* images, _In_ size_t depth, _In_ DWORD flags = CP_FLAGS_NONE );
255 
256  void Release();
257 
258  bool OverrideFormat( _In_ DXGI_FORMAT f );
259 
260  const TexMetadata& GetMetadata() const { return _metadata; }
261  const Image* GetImage(_In_ size_t mip, _In_ size_t item, _In_ size_t slice) const;
262 
263  const Image* GetImages() const { return _image; }
264  size_t GetImageCount() const { return _nimages; }
265 
266  uint8_t* GetPixels() const { return _memory; }
267  size_t GetPixelsSize() const { return _size; }
268 
269  bool IsAlphaAllOpaque() const;
270 
271  private:
272  size_t _nimages;
273  size_t _size;
274  TexMetadata _metadata;
275  Image* _image;
276  uint8_t* _memory;
277 
278  // Hide copy constructor and assignment operator
279  ScratchImage( const ScratchImage& );
281  };
282 
283  //---------------------------------------------------------------------------------
284  // Memory blob (allocated buffer pointer is always 16-byte aligned)
285  class Blob
286  {
287  public:
288  Blob() : _buffer(nullptr), _size(0) {}
289  Blob(Blob&& moveFrom) : _buffer(nullptr), _size(0) { *this = std::move(moveFrom); }
290  ~Blob() { Release(); }
291 
292  Blob& operator= (Blob&& moveFrom);
293 
294  HRESULT Initialize( _In_ size_t size );
295 
296  void Release();
297 
298  void *GetBufferPointer() const { return _buffer; }
299  size_t GetBufferSize() const { return _size; }
300 
301  private:
302  void* _buffer;
303  size_t _size;
304 
305  // Hide copy constructor and assignment operator
306  Blob( const Blob& );
307  Blob& operator=( const Blob& );
308  };
309 
310  //---------------------------------------------------------------------------------
311  // Image I/O
312 
313  // DDS operations
314  HRESULT LoadFromDDSMemory( _In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size, _In_ DWORD flags,
315  _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image );
316  HRESULT LoadFromDDSFile( _In_z_ LPCWSTR szFile, _In_ DWORD flags,
317  _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image );
318 
319  HRESULT SaveToDDSMemory( _In_ const Image& image, _In_ DWORD flags,
320  _Out_ Blob& blob );
321  HRESULT SaveToDDSMemory( _In_reads_(nimages) const Image* images, _In_ size_t nimages, _In_ const TexMetadata& metadata, _In_ DWORD flags,
322  _Out_ Blob& blob );
323 
324  HRESULT SaveToDDSFile( _In_ const Image& image, _In_ DWORD flags, _In_z_ LPCWSTR szFile );
325  HRESULT SaveToDDSFile( _In_reads_(nimages) const Image* images, _In_ size_t nimages, _In_ const TexMetadata& metadata, _In_ DWORD flags, _In_z_ LPCWSTR szFile );
326 
327  // TGA operations
328  HRESULT LoadFromTGAMemory( _In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size,
329  _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image );
330  HRESULT LoadFromTGAFile( _In_z_ LPCWSTR szFile,
331  _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image );
332 
333  HRESULT SaveToTGAMemory( _In_ const Image& image, _Out_ Blob& blob );
334  HRESULT SaveToTGAFile( _In_ const Image& image, _In_z_ LPCWSTR szFile );
335 
336  // WIC operations
337  HRESULT LoadFromWICMemory( _In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size, _In_ DWORD flags,
338  _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image );
339  HRESULT LoadFromWICFile( _In_z_ LPCWSTR szFile, _In_ DWORD flags,
340  _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image );
341 
342  HRESULT SaveToWICMemory( _In_ const Image& image, _In_ DWORD flags, _In_ REFGUID guidContainerFormat,
343  _Out_ Blob& blob, _In_opt_ const GUID* targetFormat = nullptr, _In_opt_ std::function<void(IPropertyBag2*)> setCustomProps = nullptr );
344  HRESULT SaveToWICMemory( _In_count_(nimages) const Image* images, _In_ size_t nimages, _In_ DWORD flags, _In_ REFGUID guidContainerFormat,
345  _Out_ Blob& blob, _In_opt_ const GUID* targetFormat = nullptr, _In_opt_ std::function<void(IPropertyBag2*)> setCustomProps = nullptr );
346 
347  HRESULT SaveToWICFile( _In_ const Image& image, _In_ DWORD flags, _In_ REFGUID guidContainerFormat,
348  _In_z_ LPCWSTR szFile, _In_opt_ const GUID* targetFormat = nullptr, _In_opt_ std::function<void(IPropertyBag2*)> setCustomProps = nullptr );
349  HRESULT SaveToWICFile( _In_count_(nimages) const Image* images, _In_ size_t nimages, _In_ DWORD flags, _In_ REFGUID guidContainerFormat,
350  _In_z_ LPCWSTR szFile, _In_opt_ const GUID* targetFormat = nullptr, _In_opt_ std::function<void(IPropertyBag2*)> setCustomProps = nullptr );
351 
353  {
354  WIC_CODEC_BMP =1, // Windows Bitmap (.bmp)
355  WIC_CODEC_JPEG, // Joint Photographic Experts Group (.jpg, .jpeg)
356  WIC_CODEC_PNG, // Portable Network Graphics (.png)
357  WIC_CODEC_TIFF, // Tagged Image File Format (.tif, .tiff)
358  WIC_CODEC_GIF, // Graphics Interchange Format (.gif)
359  WIC_CODEC_WMP, // Windows Media Photo / HD Photo / JPEG XR (.hdp, .jxr, .wdp)
360  WIC_CODEC_ICO, // Windows Icon (.ico)
361  };
362 
363  REFGUID GetWICCodec( _In_ WICCodecs codec );
364 
365  //---------------------------------------------------------------------------------
366  // Texture conversion, resizing, mipmap generation, and block compression
367 
369  {
376  };
377 
378  HRESULT FlipRotate( _In_ const Image& srcImage, _In_ DWORD flags, _Out_ ScratchImage& image );
379  HRESULT FlipRotate( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
380  _In_ DWORD flags, _Out_ ScratchImage& result );
381  // Flip and/or rotate image
382 
384  {
386 
395  // Wrap vs. Mirror vs. Clamp filtering options
396 
398  // Resize color and alpha channel independently
399 
403  // When converting RGB to R, defaults to using grayscale. These flags indicate copying a specific channel instead
404  // When converting RGB to RG, defaults to copying RED | GREEN. These flags control which channels are selected instead.
405 
406  TEX_FILTER_DITHER = 0x10000,
407  // Use ordered 4x4 dithering for any required conversions
409  // Use error-diffusion dithering for any required conversions
410 
411  TEX_FILTER_POINT = 0x100000,
412  TEX_FILTER_LINEAR = 0x200000,
413  TEX_FILTER_CUBIC = 0x300000,
414  TEX_FILTER_BOX = 0x400000,
415  TEX_FILTER_FANT = 0x400000, // Equiv to Box filtering for mipmap generation
417  // Filtering mode to use for any required image resizing
418 
419  TEX_FILTER_SRGB_IN = 0x1000000,
420  TEX_FILTER_SRGB_OUT = 0x2000000,
422  // sRGB <-> RGB for use in conversion operations
423  // if the input format type is IsSRGB(), then SRGB_IN is on by default
424  // if the output format type is IsSRGB(), then SRGB_OUT is on by default
425 
427  // Forces use of the non-WIC path when both are an option
428 
429  TEX_FILTER_FORCE_WIC = 0x20000000,
430  // Forces use of the WIC path even when logic would have picked a non-WIC path when both are an option
431  };
432 
433  HRESULT Resize( _In_ const Image& srcImage, _In_ size_t width, _In_ size_t height, _In_ DWORD filter,
434  _Out_ ScratchImage& image );
435  HRESULT Resize( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
436  _In_ size_t width, _In_ size_t height, _In_ DWORD filter, _Out_ ScratchImage& result );
437  // Resize the image to width x height. Defaults to Fant filtering.
438  // Note for a complex resize, the result will always have mipLevels == 1
439 
440  HRESULT Convert( _In_ const Image& srcImage, _In_ DXGI_FORMAT format, _In_ DWORD filter, _In_ float threshold,
441  _Out_ ScratchImage& image );
442  HRESULT Convert( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
443  _In_ DXGI_FORMAT format, _In_ DWORD filter, _In_ float threshold, _Out_ ScratchImage& result );
444  // Convert the image to a new format
445 
446  HRESULT ConvertToSinglePlane( _In_ const Image& srcImage, _Out_ ScratchImage& image );
447  HRESULT ConvertToSinglePlane( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
448  _Out_ ScratchImage& image );
449  // Converts the image from a planar format to an equivalent non-planar format
450 
451  HRESULT GenerateMipMaps( _In_ const Image& baseImage, _In_ DWORD filter, _In_ size_t levels,
452  _Inout_ ScratchImage& mipChain, _In_ bool allow1D = false );
453  HRESULT GenerateMipMaps( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
454  _In_ DWORD filter, _In_ size_t levels, _Inout_ ScratchImage& mipChain );
455  // levels of '0' indicates a full mipchain, otherwise is generates that number of total levels (including the source base image)
456  // Defaults to Fant filtering which is equivalent to a box filter
457 
458  HRESULT GenerateMipMaps3D( _In_reads_(depth) const Image* baseImages, _In_ size_t depth, _In_ DWORD filter, _In_ size_t levels,
459  _Out_ ScratchImage& mipChain );
460  HRESULT GenerateMipMaps3D( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
461  _In_ DWORD filter, _In_ size_t levels, _Out_ ScratchImage& mipChain );
462  // levels of '0' indicates a full mipchain, otherwise is generates that number of total levels (including the source base image)
463  // Defaults to Fant filtering which is equivalent to a box filter
464 
466  {
468 
470  // ignores sRGB colorspace conversions
471 
472  TEX_PMALPHA_SRGB_IN = 0x1000000,
473  TEX_PMALPHA_SRGB_OUT = 0x2000000,
475  // if the input format type is IsSRGB(), then SRGB_IN is on by default
476  // if the output format type is IsSRGB(), then SRGB_OUT is on by default
477  };
478 
479  HRESULT PremultiplyAlpha( _In_ const Image& srcImage, _In_ DWORD flags, _Out_ ScratchImage& image );
480  HRESULT PremultiplyAlpha( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, _In_ DWORD flags, _Out_ ScratchImage& result );
481  // Converts to a premultiplied alpha version of the texture
482 
484  {
486 
488  // Enables dithering RGB colors for BC1-3 compression
489 
491  // Enables dithering alpha for BC1-3 compression
492 
494  // Enables both RGB and alpha dithering for BC1-3 compression
495 
497  // Uniform color weighting for BC1-3 compression; by default uses perceptual weighting
498 
499  TEX_COMPRESS_SRGB_IN = 0x1000000,
502  // if the input format type is IsSRGB(), then SRGB_IN is on by default
503  // if the output format type is IsSRGB(), then SRGB_OUT is on by default
504 
505  TEX_COMPRESS_PARALLEL = 0x10000000,
506  // Compress is free to use multithreading to improve performance (by default it does not use multithreading)
507  };
508 
509  HRESULT Compress( _In_ const Image& srcImage, _In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float alphaRef,
510  _Out_ ScratchImage& cImage );
511  HRESULT Compress( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
512  _In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float alphaRef, _Out_ ScratchImage& cImages );
513  // Note that alphaRef is only used by BC1. 0.5f is a typical value to use
514 
515  HRESULT Compress( _In_ ID3D11Device* pDevice, _In_ const Image& srcImage, _In_ DXGI_FORMAT format, _In_ DWORD compress,
516  _In_ float alphaWeight, _Out_ ScratchImage& image );
517  HRESULT Compress( _In_ ID3D11Device* pDevice, _In_ const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
518  _In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float alphaWeight, _Out_ ScratchImage& cImages );
519  // DirectCompute-based compression (alphaWeight is only used by BC7. 1.0 is the typical value to use)
520 
521  HRESULT Decompress( _In_ const Image& cImage, _In_ DXGI_FORMAT format, _Out_ ScratchImage& image );
522  HRESULT Decompress( _In_reads_(nimages) const Image* cImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
523  _In_ DXGI_FORMAT format, _Out_ ScratchImage& images );
524 
525  //---------------------------------------------------------------------------------
526  // Normal map operations
527 
529  {
531 
537  // Channel selection when evaluting color value for height
538  // Luminance is a combination of red, green, and blue
539 
540  CNMAP_MIRROR_U = 0x1000,
541  CNMAP_MIRROR_V = 0x2000,
542  CNMAP_MIRROR = 0x3000,
543  // Use mirror semantics for scanline references (defaults to wrap)
544 
546  // Inverts normal sign
547 
549  // Computes a crude occlusion term stored in the alpha channel
550  };
551 
552  HRESULT ComputeNormalMap( _In_ const Image& srcImage, _In_ DWORD flags, _In_ float amplitude,
553  _In_ DXGI_FORMAT format, _Out_ ScratchImage& normalMap );
554  HRESULT ComputeNormalMap( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
555  _In_ DWORD flags, _In_ float amplitude, _In_ DXGI_FORMAT format, _Out_ ScratchImage& normalMaps );
556 
557  //---------------------------------------------------------------------------------
558  // Misc image operations
559  struct Rect
560  {
561  size_t x;
562  size_t y;
563  size_t w;
564  size_t h;
565 
566  Rect() {}
567  Rect( size_t _x, size_t _y, size_t _w, size_t _h ) : x(_x), y(_y), w(_w), h(_h) {}
568  };
569 
570  HRESULT CopyRectangle( _In_ const Image& srcImage, _In_ const Rect& srcRect, _In_ const Image& dstImage,
571  _In_ DWORD filter, _In_ size_t xOffset, _In_ size_t yOffset );
572 
574  {
576 
579  // Indicates that image needs gamma correction before comparision
580 
585  // Ignore the channel when computing MSE
586 
589  // Indicates that image should be scaled and biased before comparison (i.e. UNORM -> SNORM)
590  };
591 
592  HRESULT ComputeMSE( _In_ const Image& image1, _In_ const Image& image2, _Out_ float& mse, _Out_writes_opt_(4) float* mseV, _In_ DWORD flags = 0 );
593 
594  //---------------------------------------------------------------------------------
595  // Direct3D 11 functions
596  bool IsSupportedTexture( _In_ ID3D11Device* pDevice, _In_ const TexMetadata& metadata );
597 
598  HRESULT CreateTexture( _In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
599  _Outptr_ ID3D11Resource** ppResource );
600 
601  HRESULT CreateShaderResourceView( _In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
602  _Outptr_ ID3D11ShaderResourceView** ppSRV );
603 
604  HRESULT CreateTextureEx( _In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
605  _In_ D3D11_USAGE usage, _In_ unsigned int bindFlags, _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags, _In_ bool forceSRGB,
606  _Outptr_ ID3D11Resource** ppResource );
607 
608  HRESULT CreateShaderResourceViewEx( _In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
609  _In_ D3D11_USAGE usage, _In_ unsigned int bindFlags, _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags, _In_ bool forceSRGB,
610  _Outptr_ ID3D11ShaderResourceView** ppSRV );
611 
612  HRESULT CaptureTexture( _In_ ID3D11Device* pDevice, _In_ ID3D11DeviceContext* pContext, _In_ ID3D11Resource* pSource, _Out_ ScratchImage& result );
613 
614 #include "DirectXTex.inl"
615 
616 }; // namespace
TEX_DIMENSION
Definition: DirectXTex.h:87
bool IsCubemap() const
Definition: DirectXTex.h:131
HRESULT LoadFromTGAFile(_In_z_ LPCWSTR szFile, _Out_opt_ TexMetadata *metadata, _Out_ ScratchImage &image)
HRESULT 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, _Outptr_ ID3D11ShaderResourceView **ppSRV)
HRESULT GetMetadataFromTGAFile(_In_z_ LPCWSTR szFile, _Out_ TexMetadata &metadata)
const Image * GetImage(_In_ size_t mip, _In_ size_t item, _In_ size_t slice) const
bool IsVideo(_In_ DXGI_FORMAT fmt)
uint8_t * pixels
Definition: DirectXTex.h:230
bool HasAlpha(_In_ DXGI_FORMAT fmt)
Blob(Blob &&moveFrom)
Definition: DirectXTex.h:289
HRESULT 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)
bool IsVolumemap() const
Definition: DirectXTex.h:138
bool OverrideFormat(_In_ DXGI_FORMAT f)
HRESULT SaveToWICFile(_In_ const Image &image, _In_ DWORD flags, _In_ REFGUID guidContainerFormat, _In_z_ LPCWSTR szFile, _In_opt_ const GUID *targetFormat=nullptr, _In_opt_ std::function< void(IPropertyBag2 *)> setCustomProps=nullptr)
size_t BitsPerColor(_In_ DXGI_FORMAT fmt)
_In_ size_t _In_ const TexMetadata _In_ DWORD _In_ size_t nImages
Definition: DirectXTexP.h:118
bool IsPlanar(_In_ DXGI_FORMAT fmt)
HRESULT Resize(_In_ const Image &srcImage, _In_ size_t width, _In_ size_t height, _In_ DWORD filter, _Out_ ScratchImage &image)
TEX_MISC_FLAG2
Definition: DirectXTex.h:101
HRESULT Initialize3DFromImages(_In_reads_(depth) const Image *images, _In_ size_t depth, _In_ DWORD flags=CP_FLAGS_NONE)
DXGI_FORMAT format
Definition: DirectXTex.h:125
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ DXGI_FORMAT _In_ DWORD flags
Definition: DirectXTexP.h:170
size_t GetPixelsSize() const
Definition: DirectXTex.h:267
bool IsPacked(_In_ DXGI_FORMAT fmt)
HRESULT Initialize(_In_ size_t size)
HRESULT FlipRotate(_In_ const Image &srcImage, _In_ DWORD flags, _Out_ ScratchImage &image)
bool IsAlphaAllOpaque() const
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float threshold
Definition: DirectXTexP.h:183
HRESULT Initialize(_In_ const TexMetadata &mdata, _In_ DWORD flags=CP_FLAGS_NONE)
HRESULT 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)
void * GetBufferPointer() const
Definition: DirectXTex.h:298
HRESULT LoadFromDDSFile(_In_z_ LPCWSTR szFile, _In_ DWORD flags, _Out_opt_ TexMetadata *metadata, _Out_ ScratchImage &image)
HRESULT ConvertToSinglePlane(_In_ const Image &srcImage, _Out_ ScratchImage &image)
HRESULT CaptureTexture(_In_ ID3D11Device *pDevice, _In_ ID3D11DeviceContext *pContext, _In_ ID3D11Resource *pSource, _Out_ ScratchImage &result)
size_t ComputeIndex(_In_ size_t mip, _In_ size_t item, _In_ size_t slice) const
bool IsCompressed(_In_ DXGI_FORMAT fmt)
size_t rowPitch
Definition: DirectXTex.h:228
HRESULT SaveToTGAMemory(_In_ const Image &image, _Out_ Blob &blob)
size_t GetImageCount() const
Definition: DirectXTex.h:264
HRESULT InitializeCubeFromImages(_In_reads_(nImages) const Image *images, _In_ size_t nImages, _In_ DWORD flags=CP_FLAGS_NONE)
HRESULT 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 GenerateMipMaps(_In_ const Image &baseImage, _In_ DWORD filter, _In_ size_t levels, _Inout_ ScratchImage &mipChain, _In_ bool allow1D=false)
HRESULT LoadFromTGAMemory(_In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size, _Out_opt_ TexMetadata *metadata, _Out_ ScratchImage &image)
_In_ size_t _In_ const TexMetadata & metadata
Definition: DirectXTexP.h:116
HRESULT InitializeFromImage(_In_ const Image &srcImage, _In_ bool allow1D=false, _In_ DWORD flags=CP_FLAGS_NONE)
void ComputePitch(_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)
bool IsDepthStencil(_In_ DXGI_FORMAT fmt)
TEX_ALPHA_MODE
Definition: DirectXTex.h:106
DXGI_FORMAT MakeTypelessUNORM(_In_ DXGI_FORMAT fmt)
bool IsValid(_In_ DXGI_FORMAT fmt)
HRESULT CreateTexture(_In_ ID3D11Device *pDevice, _In_reads_(nimages) const Image *srcImages, _In_ size_t nimages, _In_ const TexMetadata &metadata, _Outptr_ ID3D11Resource **ppResource)
TEX_PMALPHA_FLAGS
Definition: DirectXTex.h:465
TEX_COMPRESS_FLAGS
Definition: DirectXTex.h:483
bool IsPalettized(_In_ DXGI_FORMAT fmt)
HRESULT GenerateMipMaps3D(_In_reads_(depth) const Image *baseImages, _In_ size_t depth, _In_ DWORD filter, _In_ size_t levels, _Out_ ScratchImage &mipChain)
HRESULT SaveToDDSFile(_In_ const Image &image, _In_ DWORD flags, _In_z_ LPCWSTR szFile)
TEX_FILTER_FLAGS
Definition: DirectXTex.h:383
HRESULT LoadFromWICFile(_In_z_ LPCWSTR szFile, _In_ DWORD flags, _Out_opt_ TexMetadata *metadata, _Out_ ScratchImage &image)
Rect(size_t _x, size_t _y, size_t _w, size_t _h)
Definition: DirectXTex.h:567
HRESULT ComputeMSE(_In_ const Image &image1, _In_ const Image &image2, _Out_ float &mse, _Out_writes_opt_(4) float *mseV, _In_ DWORD flags=0)
HRESULT LoadFromWICMemory(_In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size, _In_ DWORD flags, _Out_opt_ TexMetadata *metadata, _Out_ ScratchImage &image)
void SetAlphaMode(TEX_ALPHA_MODE mode)
Definition: DirectXTex.h:135
HRESULT Initialize1D(_In_ DXGI_FORMAT fmt, _In_ size_t length, _In_ size_t arraySize, _In_ size_t mipLevels, _In_ DWORD flags=CP_FLAGS_NONE)
HRESULT CreateShaderResourceView(_In_ ID3D11Device *pDevice, _In_reads_(nimages) const Image *srcImages, _In_ size_t nimages, _In_ const TexMetadata &metadata, _Outptr_ ID3D11ShaderResourceView **ppSRV)
size_t _In_ DXGI_FORMAT _In_reads_bytes_(inSize) LPCVOID pSource
HRESULT Convert(_In_ const Image &srcImage, _In_ DXGI_FORMAT format, _In_ DWORD filter, _In_ float threshold, _Out_ ScratchImage &image)
HRESULT Decompress(_In_ const Image &cImage, _In_ DXGI_FORMAT format, _Out_ ScratchImage &image)
_In_ size_t _In_ DXGI_FORMAT _In_reads_(count) const XMVECTOR *pSource
bool IsTypeless(_In_ DXGI_FORMAT fmt, _In_ bool partialTypeless=true)
TEX_DIMENSION dimension
Definition: DirectXTex.h:126
DXGI_FORMAT MakeSRGB(_In_ DXGI_FORMAT fmt)
HRESULT SaveToTGAFile(_In_ const Image &image, _In_z_ LPCWSTR szFile)
DXGI_FORMAT MakeTypelessFLOAT(_In_ DXGI_FORMAT fmt)
REFGUID GetWICCodec(_In_ WICCodecs codec)
DXGI_FORMAT MakeTypeless(_In_ DXGI_FORMAT fmt)
uint8_t * GetPixels() const
Definition: DirectXTex.h:266
bool IsSRGB(_In_ DXGI_FORMAT fmt)
HRESULT ComputeNormalMap(_In_ const Image &srcImage, _In_ DWORD flags, _In_ float amplitude, _In_ DXGI_FORMAT format, _Out_ ScratchImage &normalMap)
HRESULT InitializeArrayFromImages(_In_reads_(nImages) const Image *images, _In_ size_t nImages, _In_ bool allow1D=false, _In_ DWORD flags=CP_FLAGS_NONE)
HRESULT SaveToDDSMemory(_In_ const Image &image, _In_ DWORD flags, _Out_ Blob &blob)
DXGI_FORMAT format
Definition: DirectXTex.h:227
_In_ size_t _In_ size_t _In_ DXGI_FORMAT format
Definition: DirectXTexP.h:175
HRESULT GetMetadataFromWICMemory(_In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size, _In_ DWORD flags, _Out_ TexMetadata &metadata)
HRESULT GetMetadataFromDDSFile(_In_z_ LPCWSTR szFile, _In_ DWORD flags, _Out_ TexMetadata &metadata)
ScratchImage & operator=(ScratchImage &&moveFrom)
HRESULT CopyRectangle(_In_ const Image &srcImage, _In_ const Rect &srcRect, _In_ const Image &dstImage, _In_ DWORD filter, _In_ size_t xOffset, _In_ size_t yOffset)
const Image * GetImages() const
Definition: DirectXTex.h:263
size_t BitsPerPixel(_In_ DXGI_FORMAT fmt)
HRESULT SaveToWICMemory(_In_ const Image &image, _In_ DWORD flags, _In_ REFGUID guidContainerFormat, _Out_ Blob &blob, _In_opt_ const GUID *targetFormat=nullptr, _In_opt_ std::function< void(IPropertyBag2 *)> setCustomProps=nullptr)
_In_ size_t _In_ size_t size
Definition: DirectXTexP.h:175
const TexMetadata & GetMetadata() const
Definition: DirectXTex.h:260
HRESULT 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, _Outptr_ ID3D11Resource **ppResource)
HRESULT Compress(_In_ const Image &srcImage, _In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float alphaRef, _Out_ ScratchImage &cImage)
HRESULT GetMetadataFromDDSMemory(_In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size, _In_ DWORD flags, _Out_ TexMetadata &metadata)
HRESULT GetMetadataFromWICFile(_In_z_ LPCWSTR szFile, _In_ DWORD flags, _Out_ TexMetadata &metadata)
size_t slicePitch
Definition: DirectXTex.h:229
Blob & operator=(Blob &&moveFrom)
bool IsPMAlpha() const
Definition: DirectXTex.h:134
HRESULT GetMetadataFromTGAMemory(_In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size, _Out_ TexMetadata &metadata)
HRESULT LoadFromDDSMemory(_In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size, _In_ DWORD flags, _Out_opt_ TexMetadata *metadata, _Out_ ScratchImage &image)
size_t GetBufferSize() const
Definition: DirectXTex.h:299
HRESULT PremultiplyAlpha(_In_ const Image &srcImage, _In_ DWORD flags, _Out_ ScratchImage &image)
TEX_MISC_FLAG
Definition: DirectXTex.h:95
bool IsSupportedTexture(_In_ ID3D11Device *pDevice, _In_ const TexMetadata &metadata)
size_t ComputeScanlines(_In_ DXGI_FORMAT fmt, _In_ size_t height)