2012-05-01 20:00:24 +00:00
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
// DirectXTex.h
|
|
|
|
//
|
|
|
|
// DirectX Texture Library
|
|
|
|
//
|
|
|
|
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
|
|
|
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
|
|
|
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
|
|
|
// PARTICULAR PURPOSE.
|
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
|
|
|
// http://go.microsoft.com/fwlink/?LinkId=248926
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#if defined(_MSC_VER) && (_MSC_VER > 1000)
|
|
|
|
#pragma once
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable : 4005)
|
|
|
|
#include <stdint.h>
|
|
|
|
#pragma warning(pop)
|
|
|
|
|
|
|
|
#include <algorithm>
|
2013-06-27 18:05:15 +00:00
|
|
|
#include <functional>
|
2012-05-01 20:00:24 +00:00
|
|
|
|
|
|
|
#include <dxgiformat.h>
|
|
|
|
#include <d3d11.h>
|
|
|
|
|
2013-06-27 18:05:15 +00:00
|
|
|
#include <ocidl.h>
|
|
|
|
|
2013-06-14 23:17:16 +00:00
|
|
|
#define DIRECTX_TEX_VERSION 110
|
2012-12-08 01:30:49 +00:00
|
|
|
|
|
|
|
#if defined(_MSC_VER) && (_MSC_VER<1610) && !defined(_In_reads_)
|
|
|
|
#define _Analysis_assume_(exp)
|
|
|
|
#define _In_reads_(exp)
|
|
|
|
#define _In_reads_opt_(exp)
|
|
|
|
#define _Out_writes_(exp)
|
|
|
|
#define _Out_writes_opt_(exp)
|
|
|
|
#define _In_reads_bytes_(exp)
|
|
|
|
#define _Out_writes_bytes_(exp)
|
|
|
|
#define _Out_writes_bytes_to_opt_(a,b)
|
|
|
|
#define _Inout_updates_bytes_(exp)
|
|
|
|
#define _Inout_updates_all_(exp)
|
2013-06-11 20:18:23 +00:00
|
|
|
#define _Inout_updates_all_opt_(exp)
|
2012-12-08 01:30:49 +00:00
|
|
|
#define _Outptr_
|
|
|
|
#define _When_(a,b)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _Use_decl_annotations_
|
|
|
|
#define _Use_decl_annotations_
|
|
|
|
#endif
|
2012-05-01 20:00:24 +00:00
|
|
|
|
|
|
|
namespace DirectX
|
|
|
|
{
|
2012-12-08 01:30:49 +00:00
|
|
|
|
2012-05-01 20:00:24 +00:00
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// DXGI Format Utilities
|
|
|
|
bool IsValid( _In_ DXGI_FORMAT fmt );
|
|
|
|
bool IsCompressed( _In_ DXGI_FORMAT fmt );
|
|
|
|
bool IsPacked( _In_ DXGI_FORMAT fmt );
|
|
|
|
bool IsVideo( _In_ DXGI_FORMAT fmt );
|
|
|
|
bool IsSRGB( _In_ DXGI_FORMAT fmt );
|
2013-06-17 19:32:11 +00:00
|
|
|
bool IsTypeless( _In_ DXGI_FORMAT fmt, _In_ bool partialTypeless = true );
|
2012-05-01 20:00:24 +00:00
|
|
|
|
2012-12-13 20:12:35 +00:00
|
|
|
bool HasAlpha( _In_ DXGI_FORMAT fmt );
|
|
|
|
|
2012-05-01 20:00:24 +00:00
|
|
|
size_t BitsPerPixel( _In_ DXGI_FORMAT fmt );
|
|
|
|
|
2013-06-03 21:41:16 +00:00
|
|
|
size_t BitsPerColor( _In_ DXGI_FORMAT fmt );
|
|
|
|
|
2012-05-01 20:00:24 +00:00
|
|
|
enum CP_FLAGS
|
|
|
|
{
|
|
|
|
CP_FLAGS_NONE = 0x0, // Normal operation
|
|
|
|
CP_FLAGS_LEGACY_DWORD = 0x1, // Assume pitch is DWORD aligned instead of BYTE aligned
|
|
|
|
CP_FLAGS_24BPP = 0x10000, // Override with a legacy 24 bits-per-pixel format size
|
|
|
|
CP_FLAGS_16BPP = 0x20000, // Override with a legacy 16 bits-per-pixel format size
|
|
|
|
CP_FLAGS_8BPP = 0x40000, // Override with a legacy 8 bits-per-pixel format size
|
|
|
|
};
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
|
|
|
size_t ComputeScanlines( _In_ DXGI_FORMAT fmt, _In_ size_t height );
|
|
|
|
|
|
|
|
DXGI_FORMAT MakeSRGB( _In_ DXGI_FORMAT fmt );
|
2012-07-02 20:31:12 +00:00
|
|
|
DXGI_FORMAT MakeTypeless( _In_ DXGI_FORMAT fmt );
|
|
|
|
DXGI_FORMAT MakeTypelessUNORM( _In_ DXGI_FORMAT fmt );
|
|
|
|
DXGI_FORMAT MakeTypelessFLOAT( _In_ DXGI_FORMAT fmt );
|
2012-05-01 20:00:24 +00:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Texture metadata
|
|
|
|
enum TEX_DIMENSION
|
|
|
|
// Subset here matches D3D10_RESOURCE_DIMENSION and D3D11_RESOURCE_DIMENSION
|
|
|
|
{
|
2012-12-08 01:30:49 +00:00
|
|
|
TEX_DIMENSION_TEXTURE1D = 2,
|
|
|
|
TEX_DIMENSION_TEXTURE2D = 3,
|
|
|
|
TEX_DIMENSION_TEXTURE3D = 4,
|
2012-05-01 20:00:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum TEX_MISC_FLAG
|
|
|
|
// Subset here matches D3D10_RESOURCE_MISC_FLAG and D3D11_RESOURCE_MISC_FLAG
|
|
|
|
{
|
|
|
|
TEX_MISC_TEXTURECUBE = 0x4L,
|
|
|
|
};
|
|
|
|
|
2013-03-23 00:52:43 +00:00
|
|
|
enum TEX_MISC_FLAG2
|
|
|
|
{
|
2013-04-11 22:23:54 +00:00
|
|
|
TEX_MISC2_ALPHA_MODE_MASK = 0x7L,
|
2013-03-23 00:52:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum TEX_ALPHA_MODE
|
|
|
|
// Matches DDS_ALPHA_MODE, encoded in MISC_FLAGS2
|
|
|
|
{
|
2013-04-11 22:23:54 +00:00
|
|
|
TEX_ALPHA_MODE_UNKNOWN = 0,
|
|
|
|
TEX_ALPHA_MODE_STRAIGHT = 1,
|
|
|
|
TEX_ALPHA_MODE_PREMULTIPLIED = 2,
|
2013-03-23 00:52:43 +00:00
|
|
|
TEX_ALPHA_MODE_OPAQUE = 3,
|
2013-04-11 22:23:54 +00:00
|
|
|
TEX_ALPHA_MODE_CUSTOM = 4,
|
2013-03-23 00:52:43 +00:00
|
|
|
};
|
|
|
|
|
2012-05-01 20:00:24 +00:00
|
|
|
struct TexMetadata
|
|
|
|
{
|
|
|
|
size_t width;
|
|
|
|
size_t height; // Should be 1 for 1D textures
|
|
|
|
size_t depth; // Should be 1 for 1D or 2D textures
|
|
|
|
size_t arraySize; // For cubemap, this is a multiple of 6
|
|
|
|
size_t mipLevels;
|
|
|
|
uint32_t miscFlags;
|
2013-03-23 00:52:43 +00:00
|
|
|
uint32_t miscFlags2;
|
2012-05-01 20:00:24 +00:00
|
|
|
DXGI_FORMAT format;
|
|
|
|
TEX_DIMENSION dimension;
|
|
|
|
|
|
|
|
size_t ComputeIndex( _In_ size_t mip, _In_ size_t item, _In_ size_t slice ) const;
|
|
|
|
// Returns size_t(-1) to indicate an out-of-range error
|
2013-03-23 00:52:43 +00:00
|
|
|
|
|
|
|
bool IsCubemap() const { return (miscFlags & TEX_MISC_TEXTURECUBE) != 0; }
|
|
|
|
// Helpers for miscFlags
|
|
|
|
|
|
|
|
bool IsPMAlpha() const { return ((miscFlags2 & TEX_MISC2_ALPHA_MODE_MASK) == TEX_ALPHA_MODE_PREMULTIPLIED) != 0; }
|
|
|
|
void SetAlphaMode( TEX_ALPHA_MODE mode ) { miscFlags2 = (miscFlags2 & ~TEX_MISC2_ALPHA_MODE_MASK) | static_cast<uint32_t>(mode); }
|
|
|
|
// Helpers for miscFlags2
|
2012-05-01 20:00:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum DDS_FLAGS
|
|
|
|
{
|
|
|
|
DDS_FLAGS_NONE = 0x0,
|
|
|
|
|
|
|
|
DDS_FLAGS_LEGACY_DWORD = 0x1,
|
|
|
|
// Assume pitch is DWORD aligned instead of BYTE aligned (used by some legacy DDS files)
|
|
|
|
|
|
|
|
DDS_FLAGS_NO_LEGACY_EXPANSION = 0x2,
|
|
|
|
// Do not implicitly convert legacy formats that result in larger pixel sizes (24 bpp, 3:3:2, A8L8, A4L4, P8, A8P8)
|
|
|
|
|
|
|
|
DDS_FLAGS_NO_R10B10G10A2_FIXUP = 0x4,
|
|
|
|
// Do not use work-around for long-standing D3DX DDS file format issue which reversed the 10:10:10:2 color order masks
|
|
|
|
|
|
|
|
DDS_FLAGS_FORCE_RGB = 0x8,
|
|
|
|
// Convert DXGI 1.1 BGR formats to DXGI_FORMAT_R8G8B8A8_UNORM to avoid use of optional WDDM 1.1 formats
|
|
|
|
|
|
|
|
DDS_FLAGS_NO_16BPP = 0x10,
|
|
|
|
// Conversions avoid use of 565, 5551, and 4444 formats and instead expand to 8888 to avoid use of optional WDDM 1.2 formats
|
|
|
|
|
2013-06-10 22:14:55 +00:00
|
|
|
DDS_FLAGS_EXPAND_LUMINANCE = 0x20,
|
|
|
|
// When loading legacy luminance formats expand replicating the color channels rather than leaving them packed (L8, L16, A8L8)
|
|
|
|
|
2012-05-01 20:00:24 +00:00
|
|
|
DDS_FLAGS_FORCE_DX10_EXT = 0x10000,
|
|
|
|
// Always use the 'DX10' header extension for DDS writer (i.e. don't try to write DX9 compatible DDS files)
|
2013-03-23 00:52:43 +00:00
|
|
|
|
|
|
|
DDS_FLAGS_FORCE_DX10_EXT_MISC2 = 0x20000,
|
|
|
|
// DDS_FLAGS_FORCE_DX10_EXT including miscFlags2 information (result may not be compatible with D3DX10 or D3DX11)
|
2012-05-01 20:00:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum WIC_FLAGS
|
|
|
|
{
|
|
|
|
WIC_FLAGS_NONE = 0x0,
|
|
|
|
|
|
|
|
WIC_FLAGS_FORCE_RGB = 0x1,
|
|
|
|
// Loads DXGI 1.1 BGR formats as DXGI_FORMAT_R8G8B8A8_UNORM to avoid use of optional WDDM 1.1 formats
|
|
|
|
|
|
|
|
WIC_FLAGS_NO_X2_BIAS = 0x2,
|
|
|
|
// Loads DXGI 1.1 X2 10:10:10:2 format as DXGI_FORMAT_R10G10B10A2_UNORM
|
|
|
|
|
|
|
|
WIC_FLAGS_NO_16BPP = 0x4,
|
|
|
|
// Loads 565, 5551, and 4444 formats as 8888 to avoid use of optional WDDM 1.2 formats
|
|
|
|
|
|
|
|
WIC_FLAGS_ALLOW_MONO = 0x8,
|
2013-04-17 00:51:36 +00:00
|
|
|
// Loads 1-bit monochrome (black & white) as R1_UNORM rather than 8-bit grayscale
|
2012-05-01 20:00:24 +00:00
|
|
|
|
|
|
|
WIC_FLAGS_ALL_FRAMES = 0x10,
|
|
|
|
// Loads all images in a multi-frame file, converting/resizing to match the first frame as needed, defaults to 0th frame otherwise
|
|
|
|
|
|
|
|
WIC_FLAGS_DITHER = 0x10000,
|
|
|
|
// Use ordered 4x4 dithering for any required conversions
|
|
|
|
|
|
|
|
WIC_FLAGS_DITHER_DIFFUSION = 0x20000,
|
|
|
|
// Use error-diffusion dithering for any required conversions
|
|
|
|
|
|
|
|
WIC_FLAGS_FILTER_POINT = 0x100000,
|
|
|
|
WIC_FLAGS_FILTER_LINEAR = 0x200000,
|
|
|
|
WIC_FLAGS_FILTER_CUBIC = 0x300000,
|
|
|
|
WIC_FLAGS_FILTER_FANT = 0x400000, // Combination of Linear and Box filter
|
|
|
|
// Filtering mode to use for any required image resizing (only needed when loading arrays of differently sized images; defaults to Fant)
|
|
|
|
};
|
|
|
|
|
2012-12-08 01:30:49 +00:00
|
|
|
HRESULT GetMetadataFromDDSMemory( _In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size, _In_ DWORD flags,
|
2012-05-01 20:00:24 +00:00
|
|
|
_Out_ TexMetadata& metadata );
|
2012-12-08 01:30:49 +00:00
|
|
|
HRESULT GetMetadataFromDDSFile( _In_z_ LPCWSTR szFile, _In_ DWORD flags,
|
2012-05-01 20:00:24 +00:00
|
|
|
_Out_ TexMetadata& metadata );
|
|
|
|
|
2012-12-08 01:30:49 +00:00
|
|
|
HRESULT GetMetadataFromTGAMemory( _In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size,
|
2012-05-01 20:00:24 +00:00
|
|
|
_Out_ TexMetadata& metadata );
|
|
|
|
HRESULT GetMetadataFromTGAFile( _In_z_ LPCWSTR szFile,
|
|
|
|
_Out_ TexMetadata& metadata );
|
|
|
|
|
2012-12-08 01:30:49 +00:00
|
|
|
HRESULT GetMetadataFromWICMemory( _In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size, _In_ DWORD flags,
|
2012-05-01 20:00:24 +00:00
|
|
|
_Out_ TexMetadata& metadata );
|
|
|
|
HRESULT GetMetadataFromWICFile( _In_z_ LPCWSTR szFile, _In_ DWORD flags,
|
|
|
|
_Out_ TexMetadata& metadata );
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Bitmap image container
|
|
|
|
struct Image
|
|
|
|
{
|
|
|
|
size_t width;
|
|
|
|
size_t height;
|
|
|
|
DXGI_FORMAT format;
|
|
|
|
size_t rowPitch;
|
|
|
|
size_t slicePitch;
|
|
|
|
uint8_t* pixels;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ScratchImage
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ScratchImage() : _nimages(0), _size(0), _image(0), _memory(0) {}
|
|
|
|
~ScratchImage() { Release(); }
|
|
|
|
|
|
|
|
HRESULT Initialize( _In_ const TexMetadata& mdata );
|
|
|
|
|
|
|
|
HRESULT Initialize1D( _In_ DXGI_FORMAT fmt, _In_ size_t length, _In_ size_t arraySize, _In_ size_t mipLevels );
|
|
|
|
HRESULT Initialize2D( _In_ DXGI_FORMAT fmt, _In_ size_t width, _In_ size_t height, _In_ size_t arraySize, _In_ size_t mipLevels );
|
|
|
|
HRESULT Initialize3D( _In_ DXGI_FORMAT fmt, _In_ size_t width, _In_ size_t height, _In_ size_t depth, _In_ size_t mipLevels );
|
|
|
|
HRESULT InitializeCube( _In_ DXGI_FORMAT fmt, _In_ size_t width, _In_ size_t height, _In_ size_t nCubes, _In_ size_t mipLevels );
|
|
|
|
|
|
|
|
HRESULT InitializeFromImage( _In_ const Image& srcImage, _In_ bool allow1D = false );
|
2012-12-08 01:30:49 +00:00
|
|
|
HRESULT InitializeArrayFromImages( _In_reads_(nImages) const Image* images, _In_ size_t nImages, _In_ bool allow1D = false );
|
|
|
|
HRESULT InitializeCubeFromImages( _In_reads_(nImages) const Image* images, _In_ size_t nImages );
|
|
|
|
HRESULT Initialize3DFromImages( _In_reads_(depth) const Image* images, _In_ size_t depth );
|
2012-05-01 20:00:24 +00:00
|
|
|
|
|
|
|
void Release();
|
|
|
|
|
2012-07-02 20:31:12 +00:00
|
|
|
bool OverrideFormat( _In_ DXGI_FORMAT f );
|
|
|
|
|
2012-05-01 20:00:24 +00:00
|
|
|
const TexMetadata& GetMetadata() const { return _metadata; }
|
|
|
|
const Image* GetImage(_In_ size_t mip, _In_ size_t item, _In_ size_t slice) const;
|
|
|
|
|
|
|
|
const Image* GetImages() const { return _image; }
|
|
|
|
size_t GetImageCount() const { return _nimages; }
|
|
|
|
|
|
|
|
uint8_t* GetPixels() const { return _memory; }
|
|
|
|
size_t GetPixelsSize() const { return _size; }
|
|
|
|
|
2013-03-23 00:52:43 +00:00
|
|
|
bool IsAlphaAllOpaque() const;
|
|
|
|
|
2012-05-01 20:00:24 +00:00
|
|
|
private:
|
|
|
|
size_t _nimages;
|
|
|
|
size_t _size;
|
|
|
|
TexMetadata _metadata;
|
|
|
|
Image* _image;
|
|
|
|
uint8_t* _memory;
|
|
|
|
|
|
|
|
// Hide copy constructor and assignment operator
|
|
|
|
ScratchImage( const ScratchImage& );
|
|
|
|
ScratchImage& operator=( const ScratchImage& );
|
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Memory blob (allocated buffer pointer is always 16-byte aligned)
|
|
|
|
class Blob
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Blob() : _buffer(0), _size(0) {}
|
|
|
|
~Blob() { Release(); }
|
|
|
|
|
|
|
|
HRESULT Initialize( _In_ size_t size );
|
|
|
|
|
|
|
|
void Release();
|
|
|
|
|
|
|
|
void *GetBufferPointer() const { return _buffer; }
|
|
|
|
size_t GetBufferSize() const { return _size; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void* _buffer;
|
|
|
|
size_t _size;
|
|
|
|
|
|
|
|
// Hide copy constructor and assignment operator
|
|
|
|
Blob( const Blob& );
|
|
|
|
Blob& operator=( const Blob& );
|
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Image I/O
|
|
|
|
|
|
|
|
// DDS operations
|
2012-12-08 01:30:49 +00:00
|
|
|
HRESULT LoadFromDDSMemory( _In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size, _In_ DWORD flags,
|
2012-05-01 20:00:24 +00:00
|
|
|
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image );
|
|
|
|
HRESULT LoadFromDDSFile( _In_z_ LPCWSTR szFile, _In_ DWORD flags,
|
|
|
|
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image );
|
|
|
|
|
|
|
|
HRESULT SaveToDDSMemory( _In_ const Image& image, _In_ DWORD flags,
|
|
|
|
_Out_ Blob& blob );
|
2012-12-08 01:30:49 +00:00
|
|
|
HRESULT SaveToDDSMemory( _In_reads_(nimages) const Image* images, _In_ size_t nimages, _In_ const TexMetadata& metadata, _In_ DWORD flags,
|
2012-05-01 20:00:24 +00:00
|
|
|
_Out_ Blob& blob );
|
|
|
|
|
|
|
|
HRESULT SaveToDDSFile( _In_ const Image& image, _In_ DWORD flags, _In_z_ LPCWSTR szFile );
|
2012-12-08 01:30:49 +00:00
|
|
|
HRESULT SaveToDDSFile( _In_reads_(nimages) const Image* images, _In_ size_t nimages, _In_ const TexMetadata& metadata, _In_ DWORD flags, _In_z_ LPCWSTR szFile );
|
2012-05-01 20:00:24 +00:00
|
|
|
|
|
|
|
// TGA operations
|
2012-12-08 01:30:49 +00:00
|
|
|
HRESULT LoadFromTGAMemory( _In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size,
|
2012-05-01 20:00:24 +00:00
|
|
|
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image );
|
|
|
|
HRESULT LoadFromTGAFile( _In_z_ LPCWSTR szFile,
|
|
|
|
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image );
|
|
|
|
|
|
|
|
HRESULT SaveToTGAMemory( _In_ const Image& image, _Out_ Blob& blob );
|
|
|
|
HRESULT SaveToTGAFile( _In_ const Image& image, _In_z_ LPCWSTR szFile );
|
|
|
|
|
|
|
|
// WIC operations
|
2012-12-08 01:30:49 +00:00
|
|
|
HRESULT LoadFromWICMemory( _In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size, _In_ DWORD flags,
|
2012-05-01 20:00:24 +00:00
|
|
|
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image );
|
|
|
|
HRESULT LoadFromWICFile( _In_z_ LPCWSTR szFile, _In_ DWORD flags,
|
|
|
|
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image );
|
|
|
|
|
|
|
|
HRESULT SaveToWICMemory( _In_ const Image& image, _In_ DWORD flags, _In_ REFGUID guidContainerFormat,
|
2013-06-27 18:05:15 +00:00
|
|
|
_Out_ Blob& blob, _In_opt_ const GUID* targetFormat = nullptr, _In_opt_ std::function<void(IPropertyBag2*)> setCustomProps = nullptr );
|
2012-10-04 21:48:14 +00:00
|
|
|
HRESULT SaveToWICMemory( _In_count_(nimages) const Image* images, _In_ size_t nimages, _In_ DWORD flags, _In_ REFGUID guidContainerFormat,
|
2013-06-27 18:05:15 +00:00
|
|
|
_Out_ Blob& blob, _In_opt_ const GUID* targetFormat = nullptr, _In_opt_ std::function<void(IPropertyBag2*)> setCustomProps = nullptr );
|
2012-10-04 21:48:14 +00:00
|
|
|
|
|
|
|
HRESULT SaveToWICFile( _In_ const Image& image, _In_ DWORD flags, _In_ REFGUID guidContainerFormat,
|
2013-06-27 18:05:15 +00:00
|
|
|
_In_z_ LPCWSTR szFile, _In_opt_ const GUID* targetFormat = nullptr, _In_opt_ std::function<void(IPropertyBag2*)> setCustomProps = nullptr );
|
2012-10-04 21:48:14 +00:00
|
|
|
HRESULT SaveToWICFile( _In_count_(nimages) const Image* images, _In_ size_t nimages, _In_ DWORD flags, _In_ REFGUID guidContainerFormat,
|
2013-06-27 18:05:15 +00:00
|
|
|
_In_z_ LPCWSTR szFile, _In_opt_ const GUID* targetFormat = nullptr, _In_opt_ std::function<void(IPropertyBag2*)> setCustomProps = nullptr );
|
2012-05-01 20:00:24 +00:00
|
|
|
|
|
|
|
enum WICCodecs
|
|
|
|
{
|
|
|
|
WIC_CODEC_BMP =1, // Windows Bitmap (.bmp)
|
|
|
|
WIC_CODEC_JPEG, // Joint Photographic Experts Group (.jpg, .jpeg)
|
|
|
|
WIC_CODEC_PNG, // Portable Network Graphics (.png)
|
|
|
|
WIC_CODEC_TIFF, // Tagged Image File Format (.tif, .tiff)
|
|
|
|
WIC_CODEC_GIF, // Graphics Interchange Format (.gif)
|
|
|
|
WIC_CODEC_WMP, // Windows Media Photo / HD Photo / JPEG XR (.hdp, .jxr, .wdp)
|
|
|
|
WIC_CODEC_ICO, // Windows Icon (.ico)
|
|
|
|
};
|
|
|
|
|
|
|
|
REFGUID GetWICCodec( _In_ WICCodecs codec );
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Texture conversion, resizing, mipmap generation, and block compression
|
|
|
|
|
|
|
|
enum TEX_FR_FLAGS
|
|
|
|
{
|
|
|
|
TEX_FR_ROTATE0 = 0x0,
|
|
|
|
TEX_FR_ROTATE90 = 0x1,
|
|
|
|
TEX_FR_ROTATE180 = 0x2,
|
|
|
|
TEX_FR_ROTATE270 = 0x3,
|
|
|
|
TEX_FR_FLIP_HORIZONTAL = 0x08,
|
|
|
|
TEX_FR_FLIP_VERTICAL = 0x10,
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT FlipRotate( _In_ const Image& srcImage, _In_ DWORD flags, _Out_ ScratchImage& image );
|
2012-12-08 01:30:49 +00:00
|
|
|
HRESULT FlipRotate( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
|
2012-05-01 20:00:24 +00:00
|
|
|
_In_ DWORD flags, _Out_ ScratchImage& result );
|
|
|
|
// Flip and/or rotate image
|
|
|
|
|
|
|
|
enum TEX_FILTER_FLAGS
|
|
|
|
{
|
|
|
|
TEX_FILTER_DEFAULT = 0,
|
|
|
|
|
2013-06-06 21:02:17 +00:00
|
|
|
TEX_FILTER_WRAP_U = 0x1,
|
|
|
|
TEX_FILTER_WRAP_V = 0x2,
|
|
|
|
TEX_FILTER_WRAP_W = 0x4,
|
|
|
|
TEX_FILTER_WRAP = ( TEX_FILTER_WRAP_U | TEX_FILTER_WRAP_V | TEX_FILTER_WRAP_W ),
|
|
|
|
TEX_FILTER_MIRROR_U = 0x10,
|
|
|
|
TEX_FILTER_MIRROR_V = 0x20,
|
|
|
|
TEX_FILTER_MIRROR_W = 0x40,
|
|
|
|
TEX_FILTER_MIRROR = ( TEX_FILTER_MIRROR_U | TEX_FILTER_MIRROR_V | TEX_FILTER_MIRROR_W ),
|
|
|
|
// Wrap vs. Mirror vs. Clamp filtering options
|
2012-05-01 20:00:24 +00:00
|
|
|
|
|
|
|
TEX_FILTER_SEPARATE_ALPHA = 0x100,
|
|
|
|
// Resize color and alpha channel independently
|
|
|
|
|
2013-04-17 00:51:36 +00:00
|
|
|
TEX_FILTER_RGB_COPY_RED = 0x1000,
|
|
|
|
TEX_FILTER_RGB_COPY_GREEN = 0x2000,
|
|
|
|
TEX_FILTER_RGB_COPY_BLUE = 0x4000,
|
|
|
|
// When converting RGB to R, defaults to using grayscale. These flags indicate copying a specific channel instead
|
|
|
|
// When converting RGB to RG, defaults to copying RED | GREEN. These flags control which channels are selected instead.
|
|
|
|
|
2012-05-01 20:00:24 +00:00
|
|
|
TEX_FILTER_DITHER = 0x10000,
|
|
|
|
// Use ordered 4x4 dithering for any required conversions
|
|
|
|
TEX_FILTER_DITHER_DIFFUSION = 0x20000,
|
|
|
|
// Use error-diffusion dithering for any required conversions
|
|
|
|
|
|
|
|
TEX_FILTER_POINT = 0x100000,
|
|
|
|
TEX_FILTER_LINEAR = 0x200000,
|
|
|
|
TEX_FILTER_CUBIC = 0x300000,
|
2013-06-03 22:32:00 +00:00
|
|
|
TEX_FILTER_BOX = 0x400000,
|
2012-05-01 20:00:24 +00:00
|
|
|
TEX_FILTER_FANT = 0x400000, // Equiv to Box filtering for mipmap generation
|
2013-06-14 23:17:16 +00:00
|
|
|
TEX_FILTER_TRIANGLE = 0x500000,
|
2012-05-01 20:00:24 +00:00
|
|
|
// Filtering mode to use for any required image resizing
|
|
|
|
|
|
|
|
TEX_FILTER_SRGB_IN = 0x1000000,
|
|
|
|
TEX_FILTER_SRGB_OUT = 0x2000000,
|
2013-06-06 21:02:17 +00:00
|
|
|
TEX_FILTER_SRGB = ( TEX_FILTER_SRGB_IN | TEX_FILTER_SRGB_OUT ),
|
2012-05-01 20:00:24 +00:00
|
|
|
// sRGB <-> RGB for use in conversion operations
|
|
|
|
// if the input format type is IsSRGB(), then SRGB_IN is on by default
|
|
|
|
// if the output format type is IsSRGB(), then SRGB_OUT is on by default
|
2013-04-17 00:51:36 +00:00
|
|
|
|
|
|
|
TEX_FILTER_FORCE_NON_WIC = 0x10000000,
|
|
|
|
// Forces use of the non-WIC path when both are an option
|
|
|
|
|
|
|
|
TEX_FILTER_FORCE_WIC = 0x20000000,
|
|
|
|
// Forces use of the WIC path even when logic would have picked a non-WIC path when both are an option
|
2012-05-01 20:00:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT Resize( _In_ const Image& srcImage, _In_ size_t width, _In_ size_t height, _In_ DWORD filter,
|
|
|
|
_Out_ ScratchImage& image );
|
2012-12-08 01:30:49 +00:00
|
|
|
HRESULT Resize( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
|
2012-05-01 20:00:24 +00:00
|
|
|
_In_ size_t width, _In_ size_t height, _In_ DWORD filter, _Out_ ScratchImage& result );
|
|
|
|
// Resize the image to width x height. Defaults to Fant filtering.
|
|
|
|
// Note for a complex resize, the result will always have mipLevels == 1
|
|
|
|
|
|
|
|
HRESULT Convert( _In_ const Image& srcImage, _In_ DXGI_FORMAT format, _In_ DWORD filter, _In_ float threshold,
|
|
|
|
_Out_ ScratchImage& image );
|
2012-12-08 01:30:49 +00:00
|
|
|
HRESULT Convert( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
|
2012-05-01 20:00:24 +00:00
|
|
|
_In_ DXGI_FORMAT format, _In_ DWORD filter, _In_ float threshold, _Out_ ScratchImage& result );
|
|
|
|
// Convert the image to a new format
|
|
|
|
|
|
|
|
HRESULT GenerateMipMaps( _In_ const Image& baseImage, _In_ DWORD filter, _In_ size_t levels,
|
2012-12-08 01:30:49 +00:00
|
|
|
_Inout_ ScratchImage& mipChain, _In_ bool allow1D = false );
|
|
|
|
HRESULT GenerateMipMaps( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
|
|
|
|
_In_ DWORD filter, _In_ size_t levels, _Inout_ ScratchImage& mipChain );
|
2012-05-01 20:00:24 +00:00
|
|
|
// levels of '0' indicates a full mipchain, otherwise is generates that number of total levels (including the source base image)
|
|
|
|
// Defaults to Fant filtering which is equivalent to a box filter
|
|
|
|
|
2012-12-08 01:30:49 +00:00
|
|
|
HRESULT GenerateMipMaps3D( _In_reads_(depth) const Image* baseImages, _In_ size_t depth, _In_ DWORD filter, _In_ size_t levels,
|
2012-05-01 20:00:24 +00:00
|
|
|
_Out_ ScratchImage& mipChain );
|
2012-12-08 01:30:49 +00:00
|
|
|
HRESULT GenerateMipMaps3D( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
|
2012-05-01 20:00:24 +00:00
|
|
|
_In_ DWORD filter, _In_ size_t levels, _Out_ ScratchImage& mipChain );
|
|
|
|
// levels of '0' indicates a full mipchain, otherwise is generates that number of total levels (including the source base image)
|
|
|
|
// Defaults to Fant filtering which is equivalent to a box filter
|
|
|
|
|
2012-12-13 20:12:35 +00:00
|
|
|
HRESULT PremultiplyAlpha( _In_ const Image& srcImage, _Out_ ScratchImage& image );
|
|
|
|
HRESULT PremultiplyAlpha( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, _Out_ ScratchImage& result );
|
|
|
|
// Converts to a premultiplied alpha version of the texture
|
|
|
|
|
2012-05-01 20:00:24 +00:00
|
|
|
enum TEX_COMPRESS_FLAGS
|
|
|
|
{
|
|
|
|
TEX_COMPRESS_DEFAULT = 0,
|
|
|
|
|
|
|
|
TEX_COMPRESS_RGB_DITHER = 0x10000,
|
|
|
|
// Enables dithering RGB colors for BC1-3 compression
|
|
|
|
|
|
|
|
TEX_COMPRESS_A_DITHER = 0x20000,
|
|
|
|
// Enables dithering alpha for BC1-3 compression
|
|
|
|
|
|
|
|
TEX_COMPRESS_DITHER = 0x30000,
|
|
|
|
// Enables both RGB and alpha dithering for BC1-3 compression
|
|
|
|
|
|
|
|
TEX_COMPRESS_UNIFORM = 0x40000,
|
|
|
|
// Uniform color weighting for BC1-3 compression; by default uses perceptual weighting
|
|
|
|
|
|
|
|
TEX_COMPRESS_PARALLEL = 0x10000000,
|
|
|
|
// Compress is free to use multithreading to improve performance (by default it does not use multithreading)
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT Compress( _In_ const Image& srcImage, _In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float alphaRef,
|
|
|
|
_Out_ ScratchImage& cImage );
|
2012-12-08 01:30:49 +00:00
|
|
|
HRESULT Compress( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
|
2012-05-01 20:00:24 +00:00
|
|
|
_In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float alphaRef, _Out_ ScratchImage& cImages );
|
|
|
|
// Note that alphaRef is only used by BC1. 0.5f is a typical value to use
|
|
|
|
|
|
|
|
HRESULT Decompress( _In_ const Image& cImage, _In_ DXGI_FORMAT format, _Out_ ScratchImage& image );
|
2012-12-08 01:30:49 +00:00
|
|
|
HRESULT Decompress( _In_reads_(nimages) const Image* cImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
|
2012-05-01 20:00:24 +00:00
|
|
|
_In_ DXGI_FORMAT format, _Out_ ScratchImage& images );
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Normal map operations
|
|
|
|
|
|
|
|
enum CNMAP_FLAGS
|
|
|
|
{
|
|
|
|
CNMAP_DEFAULT = 0,
|
|
|
|
|
|
|
|
CNMAP_CHANNEL_RED = 0x1,
|
|
|
|
CNMAP_CHANNEL_GREEN = 0x2,
|
|
|
|
CNMAP_CHANNEL_BLUE = 0x3,
|
|
|
|
CNMAP_CHANNEL_ALPHA = 0x4,
|
|
|
|
CNMAP_CHANNEL_LUMINANCE = 0x5,
|
|
|
|
// Channel selection when evaluting color value for height
|
|
|
|
// Luminance is a combination of red, green, and blue
|
|
|
|
|
|
|
|
CNMAP_MIRROR_U = 0x1000,
|
|
|
|
CNMAP_MIRROR_V = 0x2000,
|
|
|
|
CNMAP_MIRROR = 0x3000,
|
|
|
|
// Use mirror semantics for scanline references (defaults to wrap)
|
|
|
|
|
|
|
|
CNMAP_INVERT_SIGN = 0x4000,
|
|
|
|
// Inverts normal sign
|
|
|
|
|
|
|
|
CNMAP_COMPUTE_OCCLUSION = 0x8000,
|
|
|
|
// Computes a crude occlusion term stored in the alpha channel
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT ComputeNormalMap( _In_ const Image& srcImage, _In_ DWORD flags, _In_ float amplitude,
|
|
|
|
_In_ DXGI_FORMAT format, _Out_ ScratchImage& normalMap );
|
2012-12-08 01:30:49 +00:00
|
|
|
HRESULT ComputeNormalMap( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
|
2012-05-01 20:00:24 +00:00
|
|
|
_In_ DWORD flags, _In_ float amplitude, _In_ DXGI_FORMAT format, _Out_ ScratchImage& normalMaps );
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Misc image operations
|
|
|
|
struct Rect
|
|
|
|
{
|
|
|
|
size_t x;
|
|
|
|
size_t y;
|
|
|
|
size_t w;
|
|
|
|
size_t h;
|
|
|
|
|
|
|
|
Rect() {}
|
|
|
|
Rect( size_t _x, size_t _y, size_t _w, size_t _h ) : x(_x), y(_y), w(_w), h(_h) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
2013-04-17 00:51:36 +00:00
|
|
|
enum CMSE_FLAGS
|
|
|
|
{
|
|
|
|
CMSE_DEFAULT = 0,
|
|
|
|
|
|
|
|
CMSE_IMAGE1_SRGB = 0x1,
|
|
|
|
CMSE_IMAGE2_SRGB = 0x2,
|
|
|
|
// Indicates that image needs gamma correction before comparision
|
|
|
|
|
|
|
|
CMSE_IGNORE_RED = 0x10,
|
|
|
|
CMSE_IGNORE_GREEN = 0x20,
|
|
|
|
CMSE_IGNORE_BLUE = 0x40,
|
|
|
|
CMSE_IGNORE_ALPHA = 0x80,
|
|
|
|
// Ignore the channel when computing MSE
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT ComputeMSE( _In_ const Image& image1, _In_ const Image& image2, _Out_ float& mse, _Out_writes_opt_(4) float* mseV, _In_ DWORD flags = 0 );
|
2012-05-01 20:00:24 +00:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Direct3D 11 functions
|
|
|
|
bool IsSupportedTexture( _In_ ID3D11Device* pDevice, _In_ const TexMetadata& metadata );
|
|
|
|
|
2012-12-08 01:30:49 +00:00
|
|
|
HRESULT CreateTexture( _In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
|
|
|
|
_Outptr_ ID3D11Resource** ppResource );
|
2012-05-01 20:00:24 +00:00
|
|
|
|
2012-12-08 01:30:49 +00:00
|
|
|
HRESULT CreateShaderResourceView( _In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
|
|
|
|
_Outptr_ ID3D11ShaderResourceView** ppSRV );
|
2012-05-01 20:00:24 +00:00
|
|
|
|
2012-12-08 01:30:49 +00:00
|
|
|
HRESULT CreateTextureEx( _In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
|
2013-01-28 22:28:46 +00:00
|
|
|
_In_ D3D11_USAGE usage, _In_ unsigned int bindFlags, _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags, _In_ bool forceSRGB,
|
2012-12-08 01:30:49 +00:00
|
|
|
_Outptr_ ID3D11Resource** ppResource );
|
2012-11-30 21:10:48 +00:00
|
|
|
|
2012-12-08 01:30:49 +00:00
|
|
|
HRESULT CreateShaderResourceViewEx( _In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
|
2012-12-11 20:24:03 +00:00
|
|
|
_In_ D3D11_USAGE usage, _In_ unsigned int bindFlags, _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags, _In_ bool forceSRGB,
|
2012-12-08 01:30:49 +00:00
|
|
|
_Outptr_ ID3D11ShaderResourceView** ppSRV );
|
2012-11-30 21:10:48 +00:00
|
|
|
|
2012-05-01 20:00:24 +00:00
|
|
|
HRESULT CaptureTexture( _In_ ID3D11Device* pDevice, _In_ ID3D11DeviceContext* pContext, _In_ ID3D11Resource* pSource, _Out_ ScratchImage& result );
|
|
|
|
|
|
|
|
#include "DirectXTex.inl"
|
|
|
|
|
|
|
|
}; // namespace
|