April 20, 2012 source

This commit is contained in:
walbourn_cp 2012-05-01 13:00:24 -07:00
parent 7ac24de683
commit a6c5c5939a
59 changed files with 26299 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,45 @@
//--------------------------------------------------------------------------------------
// File: DDSTextureLoader.h
//
// Function for loading a DDS texture and creating a Direct3D 11 runtime resource for it
//
// Note these functions are useful as a light-weight runtime loader for DDS files. For
// a full-featured DDS file reader, writer, and texture processing pipeline see
// the 'Texconv' sample and the 'DirectXTex' 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
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#ifdef _MSC_VER
#pragma once
#endif
#include <d3d11.h>
#pragma warning(push)
#pragma warning(disable : 4005)
#include <stdint.h>
#pragma warning(pop)
HRESULT CreateDDSTextureFromMemory( _In_ ID3D11Device* d3dDevice,
_In_bytecount_(ddsDataSize) const uint8_t* ddsData,
_In_ size_t ddsDataSize,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0
);
HRESULT CreateDDSTextureFromFile( _In_ ID3D11Device* d3dDevice,
_In_z_ const wchar_t* szFileName,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0
);

75
DDSView/DDSView.rc Normal file
View File

@ -0,0 +1,75 @@
// Microsoft Visual C++ generated resource script.
//
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#define IDC_STATIC -1
#define IDI_MAIN_ICON 100
#include <WinResRc.h>
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_MAIN_ICON ICON "directx.ico"
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#define IDC_STATIC -1\r\n"
"#include <winresrc.h>\r\n"
"\r\n"
"\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@ -0,0 +1,45 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DDSView", "DDSView_11_Desktop.vcxproj", "{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DirectXTex", "..\DirectXTex\DirectXTex_11_Desktop.vcxproj", "{371B9FA9-4C90-4AC6-A123-ACED756D6C77}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Profile|Win32 = Profile|Win32
Profile|x64 = Profile|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Debug|Win32.ActiveCfg = Debug|Win32
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Debug|Win32.Build.0 = Debug|Win32
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Debug|x64.ActiveCfg = Debug|x64
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Debug|x64.Build.0 = Debug|x64
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Profile|Win32.ActiveCfg = Profile|Win32
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Profile|Win32.Build.0 = Profile|Win32
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Profile|x64.ActiveCfg = Profile|x64
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Profile|x64.Build.0 = Profile|x64
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Release|Win32.ActiveCfg = Release|Win32
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Release|Win32.Build.0 = Release|Win32
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Release|x64.ActiveCfg = Release|x64
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Release|x64.Build.0 = Release|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|Win32.ActiveCfg = Debug|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|Win32.Build.0 = Debug|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|x64.ActiveCfg = Debug|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|x64.Build.0 = Debug|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|Win32.ActiveCfg = Profile|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|Win32.Build.0 = Profile|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|x64.ActiveCfg = Profile|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|x64.Build.0 = Profile|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|Win32.ActiveCfg = Release|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|Win32.Build.0 = Release|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|x64.ActiveCfg = Release|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,390 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Profile|Win32">
<Configuration>Profile</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Profile|x64">
<Configuration>Profile</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>DDSView</ProjectName>
<ProjectGuid>{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}</ProjectGuid>
<RootNamespace>DDSView</RootNamespace>
<Keyword>Win32Proj</Keyword>
<VCTargetsPath Condition="'$(VCTargetsPath11)' != '' and '$(VSVersion)' == '' and $(VisualStudioVersion) == ''">$(VCTargetsPath11)</VCTargetsPath>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|X64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|X64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings" />
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Profile|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">
<LinkIncremental>true</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|X64'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|X64'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;_DEBUG;DEBUG;PROFILE;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>d3d11.lib;ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;_DEBUG;DEBUG;PROFILE;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>d3d11.lib;ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>d3d11.lib;ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|X64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>d3d11.lib;ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;PROFILE;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>d3d11.lib;ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Profile|X64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;PROFILE;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>d3d11.lib;ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="DDSView.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="DDSView.rc" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DirectXTex\DirectXTex_11_Desktop.vcxproj">
<Project>{371b9fa9-4c90-4ac6-a123-aced756d6c77}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="ddsview.fx" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
</Project>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns:atg="http://atg.xbox.com" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Resource Files">
<UniqueIdentifier>{8e114980-c1a3-4ada-ad7c-83caadf5daeb}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="DDSView.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="DDSView.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<None Include="ddsview.fx" />
</ItemGroup>
</Project>

45
DDSView/DDSView_2010.sln Normal file
View File

@ -0,0 +1,45 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DDSView", "DDSView_2010.vcxproj", "{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DirectXTex", "..\DirectXTex\DirectXTex_2010.vcxproj", "{371B9FA9-4C90-4AC6-A123-ACED756D6C77}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Profile|Win32 = Profile|Win32
Profile|x64 = Profile|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Debug|Win32.ActiveCfg = Debug|Win32
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Debug|Win32.Build.0 = Debug|Win32
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Debug|x64.ActiveCfg = Debug|x64
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Debug|x64.Build.0 = Debug|x64
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Profile|Win32.ActiveCfg = Profile|Win32
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Profile|Win32.Build.0 = Profile|Win32
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Profile|x64.ActiveCfg = Profile|x64
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Profile|x64.Build.0 = Profile|x64
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Release|Win32.ActiveCfg = Release|Win32
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Release|Win32.Build.0 = Release|Win32
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Release|x64.ActiveCfg = Release|x64
{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}.Release|x64.Build.0 = Release|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|Win32.ActiveCfg = Debug|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|Win32.Build.0 = Debug|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|x64.ActiveCfg = Debug|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|x64.Build.0 = Debug|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|Win32.ActiveCfg = Profile|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|Win32.Build.0 = Profile|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|x64.ActiveCfg = Profile|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|x64.Build.0 = Profile|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|Win32.ActiveCfg = Release|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|Win32.Build.0 = Release|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|x64.ActiveCfg = Release|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,383 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Profile|Win32">
<Configuration>Profile</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Profile|x64">
<Configuration>Profile</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>DDSView</ProjectName>
<ProjectGuid>{9D3EDCAD-A800-43F0-B77F-FE6E4DFA3D84}</ProjectGuid>
<RootNamespace>DDSView</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|X64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|X64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings" />
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Profile|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath)</ExecutablePath>
<IncludePath>$(DXSDK_DIR)Include;$(IncludePath)</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\x86;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">
<LinkIncremental>true</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath)</ExecutablePath>
<IncludePath>$(DXSDK_DIR)Include;$(IncludePath)</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\x64;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath)</ExecutablePath>
<IncludePath>$(DXSDK_DIR)Include;$(IncludePath)</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\x86;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|X64'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath)</ExecutablePath>
<IncludePath>$(DXSDK_DIR)Include;$(IncludePath)</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\x64;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath)</ExecutablePath>
<IncludePath>$(DXSDK_DIR)Include;$(IncludePath)</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\x86;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|X64'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath)</ExecutablePath>
<IncludePath>$(DXSDK_DIR)Include;$(IncludePath)</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\x64;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;_DEBUG;DEBUG;PROFILE;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;USE_XNAMATH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>d3d11.lib;ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;_DEBUG;DEBUG;PROFILE;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;USE_XNAMATH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>d3d11.lib;ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;USE_XNAMATH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>d3d11.lib;ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|X64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;USE_XNAMATH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>d3d11.lib;ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;PROFILE;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;USE_XNAMATH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>d3d11.lib;ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Profile|X64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;PROFILE;_WINDOWS;D3DXFX_LARGEADDRESS_HANDLE;USE_XNAMATH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>d3d11.lib;ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="DDSView.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="DDSView.rc" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DirectXTex\DirectXTex_2010.vcxproj">
<Project>{371b9fa9-4c90-4ac6-a123-aced756d6c77}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="ddsview.fx" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
</Project>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns:atg="http://atg.xbox.com" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Resource Files">
<UniqueIdentifier>{8e114980-c1a3-4ada-ad7c-83caadf5daeb}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="DDSView.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="DDSView.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<None Include="ddsview.fx" />
</ItemGroup>
</Project>

736
DDSView/ddsview.cpp Normal file
View File

@ -0,0 +1,736 @@
//--------------------------------------------------------------------------------------
// File: DDSView.cpp
//
// DirectX 11 DDS File Viewer
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#include <assert.h>
#include <windows.h>
#include <stdio.h>
#include <dxgiformat.h>
#include <d3d11.h>
#include "xnamath.h"
#include "DirectXTex.h"
using namespace DirectX;
//--------------------------------------------------------------------------------------
#define IDI_MAIN_ICON 100
//--------------------------------------------------------------------------------------
#pragma pack(push,1)
struct SimpleVertex
{
XMFLOAT4 Pos;
XMFLOAT4 Tex;
};
struct CBArrayControl
{
float Index;
float pad[3];
};
#pragma pack(pop)
//--------------------------------------------------------------------------------------
// fxc ddsview.fx /nologo /EVS /Tvs_4_1 /Fhshaders\vs.h
#include "shaders\vs.h"
// fxc ddsview.fx /nologo /EPS_1D /Tps_4_1 /Fhshaders\ps1D.h
#include "shaders\ps1D.h"
// fxc ddsview.fx /nologo /EPS_1DArray /Tps_4_1 /Fhshaders\ps1Darray.h
#include "shaders\\ps1Darray.h"
// fxc ddsview.fx /nologo /EPS_2D /Tps_4_1 /Fhshaders\ps2D.h
#include "shaders\\ps2D.h"
// fxc ddsview.fx /nologo /EPS_2DArray /Tps_4_1 /Fhshaders\ps2Darray.h
#include "shaders\ps2Darray.h"
// fxc ddsview.fx /nologo /EPS_3D /Tps_4_1 /Fhshaders\ps3D.h
#include "shaders\ps3D.h"
// fxc ddsview.fx /nologo /EPS_Cube /Tps_4_1 /Fhshaders\psCube.h
#include "shaders\psCube.h"
//--------------------------------------------------------------------------------------
HINSTANCE g_hInst = NULL;
HWND g_hWnd = NULL;
D3D_DRIVER_TYPE g_driverType = D3D_DRIVER_TYPE_NULL;
D3D_FEATURE_LEVEL g_featureLevel = D3D_FEATURE_LEVEL_11_0;
ID3D11Device* g_pd3dDevice = NULL;
ID3D11DeviceContext* g_pImmediateContext = NULL;
IDXGISwapChain* g_pSwapChain = NULL;
ID3D11RenderTargetView* g_pRenderTargetView = NULL;
ID3D11Texture2D* g_pDepthStencil = NULL;
ID3D11DepthStencilView* g_pDepthStencilView = NULL;
ID3D11VertexShader* g_pVertexShader = NULL;
ID3D11PixelShader* g_pPixelShader = NULL;
ID3D11InputLayout* g_pVertexLayout = NULL;
ID3D11Buffer* g_pVertexBuffer = NULL;
ID3D11Buffer* g_pIndexBuffer = NULL;
ID3D11Buffer* g_pCBArrayControl = NULL;
ID3D11ShaderResourceView* g_pSRV = NULL;
ID3D11BlendState* g_AlphaBlendState = NULL;
ID3D11SamplerState* g_pSamplerLinear = NULL;
UINT g_iCurrentIndex = 0;
UINT g_iMaxIndex = 1;
UINT g_iIndices = 0;
//--------------------------------------------------------------------------------------
HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow, const TexMetadata& mdata );
HRESULT InitDevice( const TexMetadata& mdata );
void CleanupDevice();
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
void Render();
//--------------------------------------------------------------------------------------
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow )
{
UNREFERENCED_PARAMETER( hPrevInstance );
UNREFERENCED_PARAMETER( lpCmdLine );
if ( !*lpCmdLine )
{
MessageBox( NULL, L"Usage: ddsview <filename>", L"DDSView", MB_OK | MB_ICONEXCLAMATION );
return 0;
}
TexMetadata mdata;
HRESULT hr = GetMetadataFromDDSFile( lpCmdLine, DDS_FLAGS_NONE, mdata );
if ( FAILED(hr) )
{
WCHAR buff[2048];
swprintf_s( buff, L"Failed to open texture file\n\nFilename = %s\nHRESULT %08X", lpCmdLine, hr );
MessageBox( NULL, buff, L"DDSView", MB_OK | MB_ICONEXCLAMATION );
return 0;
}
if( FAILED( InitWindow( hInstance, nCmdShow, mdata ) ) )
return 0;
if( FAILED( InitDevice( mdata ) ) )
{
CleanupDevice();
return 0;
}
if (mdata.dimension == TEX_DIMENSION_TEXTURE3D)
{
if ( mdata.arraySize > 1 )
{
WCHAR buff[2048];
swprintf_s( buff, L"Arrays of volume textures are not supported\n\nFilename = %s\nArray size %d", lpCmdLine, mdata.arraySize );
MessageBox( NULL, buff, L"DDSView", MB_OK | MB_ICONEXCLAMATION );
return 0;
}
g_iMaxIndex = static_cast<UINT>( mdata.depth );
}
else
{
g_iMaxIndex = static_cast<UINT>( mdata.arraySize );
}
switch( mdata.format )
{
case DXGI_FORMAT_BC6H_TYPELESS:
case DXGI_FORMAT_BC6H_UF16:
case DXGI_FORMAT_BC6H_SF16:
case DXGI_FORMAT_BC7_TYPELESS:
case DXGI_FORMAT_BC7_UNORM:
case DXGI_FORMAT_BC7_UNORM_SRGB:
if ( g_featureLevel < D3D_FEATURE_LEVEL_11_0 )
{
WCHAR buff[2048];
swprintf_s( buff, L"BC6H/BC7 requires DirectX 11 hardware\n\nFilename = %s\nDXGI Format %d\nFeature Level %d", lpCmdLine, mdata.format, g_featureLevel );
MessageBox( NULL, buff, L"DDSView", MB_OK | MB_ICONEXCLAMATION );
return 0;
}
break;
default:
{
UINT flags = 0;
hr = g_pd3dDevice->CheckFormatSupport ( mdata.format, &flags );
if ( FAILED(hr) || !(flags & (D3D11_FORMAT_SUPPORT_TEXTURE1D|D3D11_FORMAT_SUPPORT_TEXTURE2D|D3D11_FORMAT_SUPPORT_TEXTURE3D)) )
{
WCHAR buff[2048];
swprintf_s( buff, L"Format not supported by DirectX hardware\n\nFilename = %s\nDXGI Format %d\nFeature Level %d\nHRESULT = %08X", lpCmdLine, mdata.format, g_featureLevel, hr );
MessageBox( NULL, buff, L"DDSView", MB_OK | MB_ICONEXCLAMATION );
return 0;
}
}
break;
}
ScratchImage image;
hr = LoadFromDDSFile( lpCmdLine, DDS_FLAGS_NONE, &mdata, image );
if ( FAILED(hr) )
{
WCHAR buff[2048];
swprintf_s( buff, L"Failed to load texture file\n\nFilename = %s\nHRESULT %08X", lpCmdLine, hr );
MessageBox( NULL, buff, L"DDSView", MB_OK | MB_ICONEXCLAMATION );
return 0;
}
// Special case to make sure Texture cubes remain arrays
mdata.miscFlags &= ~TEX_MISC_TEXTURECUBE;
hr = CreateShaderResourceView( g_pd3dDevice, image.GetImages(), image.GetImageCount(), mdata, &g_pSRV );
if ( FAILED(hr) )
{
WCHAR buff[2048];
swprintf_s( buff, L"Failed creating texture from file\n\nFilename = %s\nHRESULT = %08X", lpCmdLine, hr );
MessageBox( NULL, buff, L"DDSView", MB_OK | MB_ICONEXCLAMATION );
return 0;
}
// Main message loop
MSG msg = {0};
while( WM_QUIT != msg.message )
{
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
Render();
}
}
CleanupDevice();
return ( int )msg.wParam;
}
//--------------------------------------------------------------------------------------
HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow, const TexMetadata& mdata )
{
// Register class
WNDCLASSEX wcex;
wcex.cbSize = sizeof( WNDCLASSEX );
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon( hInstance, ( LPCTSTR )IDI_MAIN_ICON );
wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
wcex.hbrBackground = ( HBRUSH )( COLOR_WINDOW + 1 );
wcex.lpszMenuName = NULL;
wcex.lpszClassName = L"DDSViewWindowClass";
wcex.hIconSm = LoadIcon( wcex.hInstance, ( LPCTSTR )IDI_MAIN_ICON );
if( !RegisterClassEx( &wcex ) )
return E_FAIL;
// Create window
g_hInst = hInstance;
RECT rc = { 0, 0, 640, 480 };
int cxborder = GetSystemMetrics( SM_CXBORDER );
int cxedge = GetSystemMetrics( SM_CXEDGE );
int screenX = GetSystemMetrics( SM_CXSCREEN ) - max( cxborder, cxedge );
if( rc.right < (LONG)mdata.width )
rc.right = (LONG)mdata.height;
if ( rc.right > screenX )
rc.right = screenX;
int cyborder = GetSystemMetrics( SM_CYBORDER );
int cyedge = GetSystemMetrics( SM_CYEDGE );
int screenY = GetSystemMetrics( SM_CYSCREEN ) - max( cyborder, cyedge );
if ( rc.bottom < (LONG)mdata.height )
rc.bottom = (LONG)mdata.height;
if ( rc.bottom > screenY )
rc.bottom = screenY;
AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );
g_hWnd = CreateWindow( L"DDSViewWindowClass", L"DDS View", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, hInstance,
NULL );
if( !g_hWnd )
return E_FAIL;
ShowWindow( g_hWnd, nCmdShow );
return S_OK;
}
//--------------------------------------------------------------------------------------
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
PAINTSTRUCT ps;
HDC hdc;
switch( message )
{
case WM_PAINT:
hdc = BeginPaint( hWnd, &ps );
EndPaint( hWnd, &ps );
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
case WM_KEYDOWN:
if ( wParam == VK_RIGHT )
{
if ( g_iCurrentIndex < g_iMaxIndex-1 )
++g_iCurrentIndex;
}
else if ( wParam == VK_LEFT )
{
if ( g_iCurrentIndex > 0 )
{
--g_iCurrentIndex;
}
}
else if ( wParam >= '0' && wParam <= '9' )
{
UINT index = (wParam == '0') ? 10 : ((UINT) (wParam - '1'));
if ( index < g_iMaxIndex )
g_iCurrentIndex = index;
}
InvalidateRect( hWnd, NULL, FALSE );
break;
default:
return DefWindowProc( hWnd, message, wParam, lParam );
}
return 0;
}
//--------------------------------------------------------------------------------------
HRESULT InitDevice( const TexMetadata& mdata )
{
HRESULT hr = S_OK;
RECT rc;
GetClientRect( g_hWnd, &rc );
UINT width = rc.right - rc.left;
UINT height = rc.bottom - rc.top;
UINT createDeviceFlags = 0;
#if defined( DEBUG ) || defined( _DEBUG )
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
D3D_DRIVER_TYPE driverTypes[] =
{
D3D_DRIVER_TYPE_HARDWARE,
D3D_DRIVER_TYPE_WARP,
D3D_DRIVER_TYPE_REFERENCE,
};
UINT numDriverTypes = ARRAYSIZE( driverTypes );
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
};
UINT numFeatureLevels = ARRAYSIZE( featureLevels );
DXGI_SWAP_CHAIN_DESC sd;
ZeroMemory( &sd, sizeof( sd ) );
sd.BufferCount = 1;
sd.BufferDesc.Width = width;
sd.BufferDesc.Height = height;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.RefreshRate.Numerator = 60;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.OutputWindow = g_hWnd;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.Windowed = TRUE;
for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
{
g_driverType = driverTypes[driverTypeIndex];
hr = D3D11CreateDeviceAndSwapChain( NULL, g_driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels,
D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext );
if( SUCCEEDED( hr ) )
break;
}
if( FAILED( hr ) )
return hr;
// Create a render target view
ID3D11Texture2D* pBackBuffer = NULL;
hr = g_pSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&pBackBuffer );
if( FAILED( hr ) )
return hr;
hr = g_pd3dDevice->CreateRenderTargetView( pBackBuffer, NULL, &g_pRenderTargetView );
pBackBuffer->Release();
if( FAILED( hr ) )
return hr;
// Create depth stencil texture
D3D11_TEXTURE2D_DESC descDepth;
ZeroMemory( &descDepth, sizeof(descDepth) );
descDepth.Width = width;
descDepth.Height = height;
descDepth.MipLevels = 1;
descDepth.ArraySize = 1;
descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
descDepth.SampleDesc.Count = 1;
descDepth.SampleDesc.Quality = 0;
descDepth.Usage = D3D11_USAGE_DEFAULT;
descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
descDepth.CPUAccessFlags = 0;
descDepth.MiscFlags = 0;
hr = g_pd3dDevice->CreateTexture2D( &descDepth, NULL, &g_pDepthStencil );
if( FAILED( hr ) )
return hr;
// Create the depth stencil view
D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
ZeroMemory( &descDSV, sizeof(descDSV) );
descDSV.Format = descDepth.Format;
descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
descDSV.Texture2D.MipSlice = 0;
hr = g_pd3dDevice->CreateDepthStencilView( g_pDepthStencil, &descDSV, &g_pDepthStencilView );
if( FAILED( hr ) )
return hr;
g_pImmediateContext->OMSetRenderTargets( 1, &g_pRenderTargetView, g_pDepthStencilView );
// Setup the viewport
D3D11_VIEWPORT vp;
vp.Width = (FLOAT)width;
vp.Height = (FLOAT)height;
vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f;
vp.TopLeftX = 0;
vp.TopLeftY = 0;
g_pImmediateContext->RSSetViewports( 1, &vp );
// Create the vertex shader
hr = g_pd3dDevice->CreateVertexShader( g_VS, sizeof(g_VS), NULL, &g_pVertexShader );
if( FAILED( hr ) )
return hr;
// Define the input layout
D3D11_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, sizeof(XMFLOAT4), D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
UINT numElements = ARRAYSIZE( layout );
// Create the input layout
hr = g_pd3dDevice->CreateInputLayout( layout, numElements, g_VS, sizeof(g_VS), &g_pVertexLayout );
if( FAILED( hr ) )
return hr;
// Set the input layout
g_pImmediateContext->IASetInputLayout( g_pVertexLayout );
// Select the pixel shader
bool isCubeMap = false;
bool is1D = false;
const BYTE* pshader = NULL;
size_t pshader_size = 0;
switch ( mdata.dimension )
{
case TEX_DIMENSION_TEXTURE1D:
if ( mdata.arraySize > 1)
{
pshader = g_PS_1DArray;
pshader_size = sizeof(g_PS_1DArray);
}
else
{
pshader = g_PS_1D;
pshader_size = sizeof(g_PS_1D);
}
is1D = true;
break;
case TEX_DIMENSION_TEXTURE2D:
if ( mdata.miscFlags & TEX_MISC_TEXTURECUBE )
{
pshader = g_PS_Cube;
pshader_size = sizeof(g_PS_Cube);
isCubeMap = true;
}
else if ( mdata.arraySize > 1 )
{
pshader = g_PS_2DArray;
pshader_size = sizeof(g_PS_2DArray);
}
else
{
pshader = g_PS_2D;
pshader_size = sizeof(g_PS_2D);
}
break;
case TEX_DIMENSION_TEXTURE3D:
pshader = g_PS_3D;
pshader_size = sizeof(g_PS_3D);
break;
default:
return E_FAIL;
}
assert( pshader && pshader_size > 0 );
// Create the pixel shader
hr = g_pd3dDevice->CreatePixelShader( pshader, pshader_size, NULL, &g_pPixelShader );
if( FAILED( hr ) )
return hr;
// Create vertex buffer
UINT nverts;
D3D11_SUBRESOURCE_DATA InitData;
ZeroMemory( &InitData, sizeof(InitData) );
static const SimpleVertex verticesCube[] =
{
// Render cubemaps as horizontal cross
// XPOS
{ XMFLOAT4( .5f, .25f, 0.f, 1.f ), XMFLOAT4( 0.f, 0.f, 0.f, 0.f ) },
{ XMFLOAT4( 1.f, .25f, 0.f, 1.f ), XMFLOAT4( 1.f, 0.f, 0.f, 0.f ) },
{ XMFLOAT4( .5f, -.25f, 0.f, 1.f ), XMFLOAT4( 0.f, 1.f, 0.f, 0.f ) },
{ XMFLOAT4( 1.f, -.25f, 0.f, 1.f ), XMFLOAT4( 1.f, 1.f, 0.f, 0.f ) },
// XNEG
{ XMFLOAT4( -.5f, .25f, 0.f, 1.f ), XMFLOAT4( 0.f, 0.f, 1.f, 0.f ) },
{ XMFLOAT4( 0.f, .25f, 0.f, 1.f ), XMFLOAT4( 1.f, 0.f, 1.f, 0.f ) },
{ XMFLOAT4( -.5f, -.25f, 0.f, 1.f ), XMFLOAT4( 0.f, 1.f, 1.f, 0.f ) },
{ XMFLOAT4( 0.f, -.25f, 0.f, 1.f ), XMFLOAT4( 1.f, 1.f, 1.f, 0.f ) },
// YPOS
{ XMFLOAT4( -.5f, .75f, 0.f, 1.f ), XMFLOAT4( 0.f, 0.f, 2.f, 0.f ) },
{ XMFLOAT4( 0.f, .75f, 0.f, 1.f ), XMFLOAT4( 1.f, 0.f, 2.f, 0.f ) },
{ XMFLOAT4( -.5f, .25f, 0.f, 1.f ), XMFLOAT4( 0.f, 1.f, 2.f, 0.f ) },
{ XMFLOAT4( 0.f, .25f, 0.f, 1.f ), XMFLOAT4( 1.f, 1.f, 2.f, 0.f ) },
// YNEG
{ XMFLOAT4( -.5f, -.25f, 0.f, 1.f ), XMFLOAT4( 0.f, 0.f, 3.f, 0.f ) },
{ XMFLOAT4( 0.f, -.25f, 0.f, 1.f ), XMFLOAT4( 1.f, 0.f, 3.f, 0.f ) },
{ XMFLOAT4( -.5f, -.75f, 0.f, 1.f ), XMFLOAT4( 0.f, 1.f, 3.f, 0.f ) },
{ XMFLOAT4( 0.f, -.75f, 0.f, 1.f ), XMFLOAT4( 1.f, 1.f, 3.f, 0.f ) },
// ZPOS
{ XMFLOAT4( 0.f, .25f, 0.f, 1.f ), XMFLOAT4( 0.f, 0.f, 4.f, 0.f ) },
{ XMFLOAT4( .5f, .25f, 0.f, 1.f ), XMFLOAT4( 1.f, 0.f, 4.f, 0.f ) },
{ XMFLOAT4( 0.f, -.25f, 0.f, 1.f ), XMFLOAT4( 0.f, 1.f, 4.f, 0.f ) },
{ XMFLOAT4( .5f, -.25f, 0.f, 1.f ), XMFLOAT4( 1.f, 1.f, 4.f, 0.f ) },
// ZNEG
{ XMFLOAT4( -1.f, .25f, 0.f, 1.f ), XMFLOAT4( 0.f, 0.f, 5.f, 0.f ) },
{ XMFLOAT4( -.5f, .25f, 0.f, 1.f ), XMFLOAT4( 1.f, 0.f, 5.f, 0.f ) },
{ XMFLOAT4( -1.f, -.25f, 0.f, 1.f ), XMFLOAT4( 0.f, 1.f, 5.f, 0.f ) },
{ XMFLOAT4( -.5f, -.25f, 0.f, 1.f ), XMFLOAT4( 1.f, 1.f, 5.f, 0.f ) },
};
static const SimpleVertex vertices[] =
{
{ XMFLOAT4( -1.f, 1.f, 0.f, 1.f ), XMFLOAT4( 0.f, 0.f, 0.f, 0.f ) },
{ XMFLOAT4( 1.f, 1.f, 0.f, 1.f ), XMFLOAT4( 1.f, 0.f, 0.f, 0.f ) },
{ XMFLOAT4( -1.f, -1.f, 0.f, 1.f ), XMFLOAT4( 0.f, 1.f, 0.f, 0.f ) },
{ XMFLOAT4( 1.f, -1.f, 0.f, 1.f ), XMFLOAT4( 1.f, 1.f, 0.f, 0.f ) },
};
static const SimpleVertex vertices1D[] =
{
{ XMFLOAT4( -1.f, .05f, 0.f, 1.f ), XMFLOAT4( 0.f, 0.f, 0.f, 0.f ) },
{ XMFLOAT4( 1.f, .05f, 0.f, 1.f ), XMFLOAT4( 1.f, 0.f, 0.f, 0.f ) },
{ XMFLOAT4( -1.f, -.05f, 0.f, 1.f ), XMFLOAT4( 0.f, 0.f, 0.f, 0.f ) },
{ XMFLOAT4( 1.f, -.05f, 0.f, 1.f ), XMFLOAT4( 1.f, 0.f, 0.f, 0.f ) },
};
if ( isCubeMap )
{
nverts = _countof(verticesCube);
InitData.pSysMem = verticesCube;
}
else if ( is1D )
{
nverts = _countof(vertices1D);
InitData.pSysMem = vertices1D;
}
else
{
nverts = _countof(vertices);
InitData.pSysMem = vertices;
}
D3D11_BUFFER_DESC bd;
ZeroMemory( &bd, sizeof(bd) );
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = sizeof( SimpleVertex ) * nverts;
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = 0;
hr = g_pd3dDevice->CreateBuffer( &bd, &InitData, &g_pVertexBuffer );
if( FAILED( hr ) )
return hr;
// Set vertex buffer
UINT stride = sizeof( SimpleVertex );
UINT offset = 0;
g_pImmediateContext->IASetVertexBuffers( 0, 1, &g_pVertexBuffer, &stride, &offset );
// Create index buffer
static const WORD indicesCube[] =
{
0, 1, 2,
2, 1, 3,
4, 5, 6,
6, 5, 7,
8, 9, 10,
10, 9, 11,
12, 13, 14,
14, 13, 15,
16, 17, 18,
18, 17, 19,
20, 21, 22,
22, 21, 23
};
static const WORD indices[] =
{
0, 1, 2,
2, 1, 3
};
if ( isCubeMap )
{
g_iIndices = _countof(indicesCube);
InitData.pSysMem = indicesCube;
}
else
{
g_iIndices = _countof(indices);
InitData.pSysMem = indices;
}
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = g_iIndices * sizeof(WORD);
bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
bd.CPUAccessFlags = 0;
hr = g_pd3dDevice->CreateBuffer( &bd, &InitData, &g_pIndexBuffer );
if( FAILED( hr ) )
return hr;
// Set index buffer
g_pImmediateContext->IASetIndexBuffer( g_pIndexBuffer, DXGI_FORMAT_R16_UINT, 0 );
// Set primitive topology
g_pImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
// Create the constant buffers
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = sizeof(CBArrayControl);
bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
bd.CPUAccessFlags = 0;
hr = g_pd3dDevice->CreateBuffer( &bd, NULL, &g_pCBArrayControl );
if( FAILED( hr ) )
return hr;
// Create the state objects
D3D11_SAMPLER_DESC sampDesc;
ZeroMemory( &sampDesc, sizeof(sampDesc) );
sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
sampDesc.MinLOD = 0;
sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
hr = g_pd3dDevice->CreateSamplerState( &sampDesc, &g_pSamplerLinear );
if( FAILED( hr ) )
return hr;
D3D11_BLEND_DESC dsc =
{
false,
false,
{
true,
D3D11_BLEND_SRC_ALPHA,
D3D11_BLEND_INV_SRC_ALPHA,
D3D11_BLEND_OP_ADD,
D3D11_BLEND_ZERO,
D3D11_BLEND_ZERO,
D3D11_BLEND_OP_ADD,
D3D11_COLOR_WRITE_ENABLE_ALL
}
};
hr = g_pd3dDevice->CreateBlendState(&dsc, &g_AlphaBlendState );
if( FAILED(hr) )
return hr;
return S_OK;
}
//--------------------------------------------------------------------------------------
void Render()
{
float ClearColor[4] = { 0.f, 1.f, 1.f, 1.0f }; //red,green,blue,alpha
g_pImmediateContext->ClearRenderTargetView( g_pRenderTargetView, ClearColor );
g_pImmediateContext->ClearDepthStencilView( g_pDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0 );
float bf [4] = {1.0f, 1.0f, 1.0f, 1.0f};
g_pImmediateContext->OMSetBlendState( g_AlphaBlendState, bf, 0xffffffff );
CBArrayControl cb;
cb.Index = (float)g_iCurrentIndex;
g_pImmediateContext->UpdateSubresource( g_pCBArrayControl, 0, NULL, &cb, 0, 0 );
g_pImmediateContext->VSSetShader( g_pVertexShader, NULL, 0 );
g_pImmediateContext->PSSetShader( g_pPixelShader, NULL, 0 );
g_pImmediateContext->PSSetConstantBuffers( 0, 1, &g_pCBArrayControl );
g_pImmediateContext->PSSetShaderResources( 0, 1, &g_pSRV );
g_pImmediateContext->PSSetSamplers( 0, 1, &g_pSamplerLinear );
g_pImmediateContext->DrawIndexed( g_iIndices, 0, 0 );
g_pSwapChain->Present( 0, 0 );
}
//--------------------------------------------------------------------------------------
void CleanupDevice()
{
if( g_pImmediateContext ) g_pImmediateContext->ClearState();
if( g_pSamplerLinear ) g_pSamplerLinear->Release();
if( g_AlphaBlendState ) g_AlphaBlendState->Release();
if( g_pSRV ) g_pSRV->Release();
if( g_pVertexBuffer ) g_pVertexBuffer->Release();
if( g_pIndexBuffer ) g_pIndexBuffer->Release();
if( g_pCBArrayControl ) g_pCBArrayControl->Release();
if( g_pVertexLayout ) g_pVertexLayout->Release();
if( g_pVertexShader ) g_pVertexShader->Release();
if( g_pPixelShader ) g_pPixelShader->Release();
if( g_pDepthStencil ) g_pDepthStencil->Release();
if( g_pDepthStencilView ) g_pDepthStencilView->Release();
if( g_pRenderTargetView ) g_pRenderTargetView->Release();
if( g_pSwapChain ) g_pSwapChain->Release();
if( g_pImmediateContext ) g_pImmediateContext->Release();
if( g_pd3dDevice ) g_pd3dDevice->Release();
}

85
DDSView/ddsview.fx Normal file
View File

@ -0,0 +1,85 @@
//--------------------------------------------------------------------------------------
// File: ddsview.fx
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
// Constant Buffer Variables
//--------------------------------------------------------------------------------------
Texture1D tx1D : register( t0 );
Texture1DArray tx1DArray : register( t0 );
Texture2D tx2D : register( t0 );
Texture2DArray tx2DArray : register( t0 );
Texture3D tx3D : register( t0 );
SamplerState samLinear : register( s0 );
cbuffer cbArrayControl : register( b0 )
{
float Index;
};
//--------------------------------------------------------------------------------------
struct VS_INPUT
{
float4 Pos : POSITION;
float4 Tex : TEXCOORD0;
};
struct PS_INPUT
{
float4 Pos : SV_POSITION;
float4 Tex : TEXCOORD0;
};
//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
PS_INPUT VS( VS_INPUT input )
{
PS_INPUT output = (PS_INPUT)0;
output.Pos = input.Pos;
output.Tex = input.Tex;
return output;
}
//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS_1D( PS_INPUT input) : SV_Target
{
return tx1D.Sample( samLinear, input.Tex.x );
}
float4 PS_1DArray( PS_INPUT input) : SV_Target
{
return tx1DArray.Sample( samLinear, float2(input.Tex.x, Index) );
}
float4 PS_2D( PS_INPUT input) : SV_Target
{
return tx2D.Sample( samLinear, input.Tex.xy );
}
float4 PS_2DArray( PS_INPUT input) : SV_Target
{
return tx2DArray.Sample( samLinear, float3(input.Tex.xy, Index) );
}
float4 PS_3D( PS_INPUT input) : SV_Target
{
int Width, Height, Depth;
tx3D.GetDimensions( Width, Height, Depth);
return tx3D.Sample( samLinear, float3(input.Tex.xy, Index / Depth) );
}
float4 PS_Cube( PS_INPUT input) : SV_Target
{
return tx2DArray.Sample( samLinear, float3(input.Tex.xy, input.Tex.z + (6*Index)) );
}

BIN
DDSView/directx.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

8
DDSView/hlsl.cmd Normal file
View File

@ -0,0 +1,8 @@
%DXSDK_DIR%\Utilities\bin\x86\fxc ddsview.fx /nologo /EVS /Tvs_4_1 /Fhshaders\vs.h
%DXSDK_DIR%\Utilities\bin\x86\fxc ddsview.fx /nologo /EPS_1D /Tps_4_1 /Fhshaders\ps1D.h
%DXSDK_DIR%\Utilities\bin\x86\fxc ddsview.fx /nologo /EPS_1DArray /Tps_4_1 /Fhshaders\ps1Darray.h
%DXSDK_DIR%\Utilities\bin\x86\fxc ddsview.fx /nologo /EPS_2D /Tps_4_1 /Fhshaders\ps2D.h
%DXSDK_DIR%\Utilities\bin\x86\fxc ddsview.fx /nologo /EPS_2DArray /Tps_4_1 /Fhshaders\ps2Darray.h
%DXSDK_DIR%\Utilities\bin\x86\fxc ddsview.fx /nologo /EPS_3D /Tps_4_1 /Fhshaders\ps3D.h
%DXSDK_DIR%\Utilities\bin\x86\fxc ddsview.fx /nologo /EPS_Cube /Tps_4_1 /Fhshaders\psCube.h

179
DDSView/shaders/ps1D.h Normal file
View File

@ -0,0 +1,179 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//
// fxc ddsview.fx /nologo /EPS_1D /Tps_4_1 /Fhshaders\ps1D.h
//
//
// Buffer Definitions:
//
// cbuffer cbArrayControl
// {
//
// float Index; // Offset: 0 Size: 4 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name Type Format Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// samLinear sampler NA NA 0 1
// tx1D texture float4 1d 0 1
// cbArrayControl cbuffer NA NA 0 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_POSITION 0 xyzw 0 POS float
// TEXCOORD 0 xyzw 1 NONE float x
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_Target 0 xyzw 0 TARGET float xyzw
//
ps_4_1
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[1], immediateIndexed
dcl_sampler s0, mode_default
dcl_resource_texture1d (float,float,float,float) t0
dcl_input_ps linear v1.x
dcl_output o0.xyzw
sample o0.xyzw, v1.xxxx, t0.xyzw, s0
ret
// Approximately 2 instruction slots used
#endif
const BYTE g_PS_1D[] =
{
68, 88, 66, 67, 71, 33,
105, 235, 206, 215, 61, 110,
190, 73, 39, 172, 36, 251,
31, 148, 1, 0, 0, 0,
220, 2, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
84, 1, 0, 0, 172, 1,
0, 0, 224, 1, 0, 0,
96, 2, 0, 0, 82, 68,
69, 70, 24, 1, 0, 0,
1, 0, 0, 0, 156, 0,
0, 0, 3, 0, 0, 0,
28, 0, 0, 0, 1, 4,
255, 255, 0, 1, 0, 0,
228, 0, 0, 0, 124, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 1, 0, 0, 0,
134, 0, 0, 0, 2, 0,
0, 0, 5, 0, 0, 0,
2, 0, 0, 0, 255, 255,
255, 255, 0, 0, 0, 0,
1, 0, 0, 0, 13, 0,
0, 0, 139, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
1, 0, 0, 0, 115, 97,
109, 76, 105, 110, 101, 97,
114, 0, 116, 120, 49, 68,
0, 99, 98, 65, 114, 114,
97, 121, 67, 111, 110, 116,
114, 111, 108, 0, 171, 171,
139, 0, 0, 0, 1, 0,
0, 0, 180, 0, 0, 0,
16, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
204, 0, 0, 0, 0, 0,
0, 0, 4, 0, 0, 0,
0, 0, 0, 0, 212, 0,
0, 0, 0, 0, 0, 0,
73, 110, 100, 101, 120, 0,
171, 171, 0, 0, 3, 0,
1, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
77, 105, 99, 114, 111, 115,
111, 102, 116, 32, 40, 82,
41, 32, 72, 76, 83, 76,
32, 83, 104, 97, 100, 101,
114, 32, 67, 111, 109, 112,
105, 108, 101, 114, 32, 57,
46, 50, 57, 46, 57, 53,
50, 46, 51, 49, 49, 49,
0, 171, 171, 171, 73, 83,
71, 78, 80, 0, 0, 0,
2, 0, 0, 0, 8, 0,
0, 0, 56, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 15, 0,
0, 0, 68, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 3, 0, 0, 0,
1, 0, 0, 0, 15, 1,
0, 0, 83, 86, 95, 80,
79, 83, 73, 84, 73, 79,
78, 0, 84, 69, 88, 67,
79, 79, 82, 68, 0, 171,
171, 171, 79, 83, 71, 78,
44, 0, 0, 0, 1, 0,
0, 0, 8, 0, 0, 0,
32, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 15, 0, 0, 0,
83, 86, 95, 84, 97, 114,
103, 101, 116, 0, 171, 171,
83, 72, 68, 82, 120, 0,
0, 0, 65, 0, 0, 0,
30, 0, 0, 0, 106, 8,
0, 1, 89, 0, 0, 4,
70, 142, 32, 0, 0, 0,
0, 0, 1, 0, 0, 0,
90, 0, 0, 3, 0, 96,
16, 0, 0, 0, 0, 0,
88, 16, 0, 4, 0, 112,
16, 0, 0, 0, 0, 0,
85, 85, 0, 0, 98, 16,
0, 3, 18, 16, 16, 0,
1, 0, 0, 0, 101, 0,
0, 3, 242, 32, 16, 0,
0, 0, 0, 0, 69, 0,
0, 9, 242, 32, 16, 0,
0, 0, 0, 0, 6, 16,
16, 0, 1, 0, 0, 0,
70, 126, 16, 0, 0, 0,
0, 0, 0, 96, 16, 0,
0, 0, 0, 0, 62, 0,
0, 1, 83, 84, 65, 84,
116, 0, 0, 0, 2, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 2, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0
};

192
DDSView/shaders/ps1Darray.h Normal file
View File

@ -0,0 +1,192 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//
// fxc ddsview.fx /nologo /EPS_1DArray /Tps_4_1 /Fhshaders\ps1Darray.h
//
//
// Buffer Definitions:
//
// cbuffer cbArrayControl
// {
//
// float Index; // Offset: 0 Size: 4
//
// }
//
//
// Resource Bindings:
//
// Name Type Format Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// samLinear sampler NA NA 0 1
// tx1DArray texture float4 1darray 0 1
// cbArrayControl cbuffer NA NA 0 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_POSITION 0 xyzw 0 POS float
// TEXCOORD 0 xyzw 1 NONE float x
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_Target 0 xyzw 0 TARGET float xyzw
//
ps_4_1
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[1], immediateIndexed
dcl_sampler s0, mode_default
dcl_resource_texture1darray (float,float,float,float) t0
dcl_input_ps linear v1.x
dcl_output o0.xyzw
dcl_temps 1
mov r0.x, v1.x
mov r0.y, cb0[0].x
sample o0.xyzw, r0.xyxx, t0.xyzw, s0
ret
// Approximately 4 instruction slots used
#endif
const BYTE g_PS_1DArray[] =
{
68, 88, 66, 67, 210, 249,
153, 123, 172, 65, 50, 100,
250, 1, 76, 219, 67, 149,
143, 209, 1, 0, 0, 0,
20, 3, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
88, 1, 0, 0, 176, 1,
0, 0, 228, 1, 0, 0,
152, 2, 0, 0, 82, 68,
69, 70, 28, 1, 0, 0,
1, 0, 0, 0, 160, 0,
0, 0, 3, 0, 0, 0,
28, 0, 0, 0, 1, 4,
255, 255, 0, 1, 0, 0,
232, 0, 0, 0, 124, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 1, 0, 0, 0,
134, 0, 0, 0, 2, 0,
0, 0, 5, 0, 0, 0,
3, 0, 0, 0, 255, 255,
255, 255, 0, 0, 0, 0,
1, 0, 0, 0, 13, 0,
0, 0, 144, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
1, 0, 0, 0, 115, 97,
109, 76, 105, 110, 101, 97,
114, 0, 116, 120, 49, 68,
65, 114, 114, 97, 121, 0,
99, 98, 65, 114, 114, 97,
121, 67, 111, 110, 116, 114,
111, 108, 0, 171, 144, 0,
0, 0, 1, 0, 0, 0,
184, 0, 0, 0, 16, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 208, 0,
0, 0, 0, 0, 0, 0,
4, 0, 0, 0, 2, 0,
0, 0, 216, 0, 0, 0,
0, 0, 0, 0, 73, 110,
100, 101, 120, 0, 171, 171,
0, 0, 3, 0, 1, 0,
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 77, 105,
99, 114, 111, 115, 111, 102,
116, 32, 40, 82, 41, 32,
72, 76, 83, 76, 32, 83,
104, 97, 100, 101, 114, 32,
67, 111, 109, 112, 105, 108,
101, 114, 32, 57, 46, 50,
57, 46, 57, 53, 50, 46,
51, 49, 49, 49, 0, 171,
171, 171, 73, 83, 71, 78,
80, 0, 0, 0, 2, 0,
0, 0, 8, 0, 0, 0,
56, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 15, 0, 0, 0,
68, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 1, 0,
0, 0, 15, 1, 0, 0,
83, 86, 95, 80, 79, 83,
73, 84, 73, 79, 78, 0,
84, 69, 88, 67, 79, 79,
82, 68, 0, 171, 171, 171,
79, 83, 71, 78, 44, 0,
0, 0, 1, 0, 0, 0,
8, 0, 0, 0, 32, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0,
15, 0, 0, 0, 83, 86,
95, 84, 97, 114, 103, 101,
116, 0, 171, 171, 83, 72,
68, 82, 172, 0, 0, 0,
65, 0, 0, 0, 43, 0,
0, 0, 106, 8, 0, 1,
89, 0, 0, 4, 70, 142,
32, 0, 0, 0, 0, 0,
1, 0, 0, 0, 90, 0,
0, 3, 0, 96, 16, 0,
0, 0, 0, 0, 88, 56,
0, 4, 0, 112, 16, 0,
0, 0, 0, 0, 85, 85,
0, 0, 98, 16, 0, 3,
18, 16, 16, 0, 1, 0,
0, 0, 101, 0, 0, 3,
242, 32, 16, 0, 0, 0,
0, 0, 104, 0, 0, 2,
1, 0, 0, 0, 54, 0,
0, 5, 18, 0, 16, 0,
0, 0, 0, 0, 10, 16,
16, 0, 1, 0, 0, 0,
54, 0, 0, 6, 34, 0,
16, 0, 0, 0, 0, 0,
10, 128, 32, 0, 0, 0,
0, 0, 0, 0, 0, 0,
69, 0, 0, 9, 242, 32,
16, 0, 0, 0, 0, 0,
70, 0, 16, 0, 0, 0,
0, 0, 70, 126, 16, 0,
0, 0, 0, 0, 0, 96,
16, 0, 0, 0, 0, 0,
62, 0, 0, 1, 83, 84,
65, 84, 116, 0, 0, 0,
4, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
2, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 2, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0
};

144
DDSView/shaders/ps2D.h Normal file
View File

@ -0,0 +1,144 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//
// fxc ddsview.fx /nologo /EPS_2D /Tps_4_1 /Fhshaders\ps2D.h
//
//
// Resource Bindings:
//
// Name Type Format Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// samLinear sampler NA NA 0 1
// tx2D texture float4 2d 0 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_POSITION 0 xyzw 0 POS float
// TEXCOORD 0 xyzw 1 NONE float xy
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_Target 0 xyzw 0 TARGET float xyzw
//
ps_4_1
dcl_globalFlags refactoringAllowed
dcl_sampler s0, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_input_ps linear v1.xy
dcl_output o0.xyzw
sample o0.xyzw, v1.xyxx, t0.xyzw, s0
ret
// Approximately 2 instruction slots used
#endif
const BYTE g_PS_2D[] =
{
68, 88, 66, 67, 45, 73,
251, 77, 247, 44, 253, 34,
100, 41, 211, 74, 100, 236,
72, 69, 1, 0, 0, 0,
80, 2, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
216, 0, 0, 0, 48, 1,
0, 0, 100, 1, 0, 0,
212, 1, 0, 0, 82, 68,
69, 70, 156, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 2, 0, 0, 0,
28, 0, 0, 0, 1, 4,
255, 255, 0, 1, 0, 0,
107, 0, 0, 0, 92, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 1, 0, 0, 0,
102, 0, 0, 0, 2, 0,
0, 0, 5, 0, 0, 0,
4, 0, 0, 0, 255, 255,
255, 255, 0, 0, 0, 0,
1, 0, 0, 0, 13, 0,
0, 0, 115, 97, 109, 76,
105, 110, 101, 97, 114, 0,
116, 120, 50, 68, 0, 77,
105, 99, 114, 111, 115, 111,
102, 116, 32, 40, 82, 41,
32, 72, 76, 83, 76, 32,
83, 104, 97, 100, 101, 114,
32, 67, 111, 109, 112, 105,
108, 101, 114, 32, 57, 46,
50, 57, 46, 57, 53, 50,
46, 51, 49, 49, 49, 0,
73, 83, 71, 78, 80, 0,
0, 0, 2, 0, 0, 0,
8, 0, 0, 0, 56, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0,
15, 0, 0, 0, 68, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 1, 0, 0, 0,
15, 3, 0, 0, 83, 86,
95, 80, 79, 83, 73, 84,
73, 79, 78, 0, 84, 69,
88, 67, 79, 79, 82, 68,
0, 171, 171, 171, 79, 83,
71, 78, 44, 0, 0, 0,
1, 0, 0, 0, 8, 0,
0, 0, 32, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 15, 0,
0, 0, 83, 86, 95, 84,
97, 114, 103, 101, 116, 0,
171, 171, 83, 72, 68, 82,
104, 0, 0, 0, 65, 0,
0, 0, 26, 0, 0, 0,
106, 8, 0, 1, 90, 0,
0, 3, 0, 96, 16, 0,
0, 0, 0, 0, 88, 24,
0, 4, 0, 112, 16, 0,
0, 0, 0, 0, 85, 85,
0, 0, 98, 16, 0, 3,
50, 16, 16, 0, 1, 0,
0, 0, 101, 0, 0, 3,
242, 32, 16, 0, 0, 0,
0, 0, 69, 0, 0, 9,
242, 32, 16, 0, 0, 0,
0, 0, 70, 16, 16, 0,
1, 0, 0, 0, 70, 126,
16, 0, 0, 0, 0, 0,
0, 96, 16, 0, 0, 0,
0, 0, 62, 0, 0, 1,
83, 84, 65, 84, 116, 0,
0, 0, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0
};

192
DDSView/shaders/ps2Darray.h Normal file
View File

@ -0,0 +1,192 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//
// fxc ddsview.fx /nologo /EPS_2DArray /Tps_4_1 /Fhshaders\ps2Darray.h
//
//
// Buffer Definitions:
//
// cbuffer cbArrayControl
// {
//
// float Index; // Offset: 0 Size: 4
//
// }
//
//
// Resource Bindings:
//
// Name Type Format Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// samLinear sampler NA NA 0 1
// tx2DArray texture float4 2darray 0 1
// cbArrayControl cbuffer NA NA 0 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_POSITION 0 xyzw 0 POS float
// TEXCOORD 0 xyzw 1 NONE float xy
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_Target 0 xyzw 0 TARGET float xyzw
//
ps_4_1
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[1], immediateIndexed
dcl_sampler s0, mode_default
dcl_resource_texture2darray (float,float,float,float) t0
dcl_input_ps linear v1.xy
dcl_output o0.xyzw
dcl_temps 1
mov r0.xy, v1.xyxx
mov r0.z, cb0[0].x
sample o0.xyzw, r0.xyzx, t0.xyzw, s0
ret
// Approximately 4 instruction slots used
#endif
const BYTE g_PS_2DArray[] =
{
68, 88, 66, 67, 55, 138,
65, 43, 181, 212, 29, 116,
142, 112, 89, 51, 193, 95,
148, 33, 1, 0, 0, 0,
20, 3, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
88, 1, 0, 0, 176, 1,
0, 0, 228, 1, 0, 0,
152, 2, 0, 0, 82, 68,
69, 70, 28, 1, 0, 0,
1, 0, 0, 0, 160, 0,
0, 0, 3, 0, 0, 0,
28, 0, 0, 0, 1, 4,
255, 255, 0, 1, 0, 0,
232, 0, 0, 0, 124, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 1, 0, 0, 0,
134, 0, 0, 0, 2, 0,
0, 0, 5, 0, 0, 0,
5, 0, 0, 0, 255, 255,
255, 255, 0, 0, 0, 0,
1, 0, 0, 0, 13, 0,
0, 0, 144, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
1, 0, 0, 0, 115, 97,
109, 76, 105, 110, 101, 97,
114, 0, 116, 120, 50, 68,
65, 114, 114, 97, 121, 0,
99, 98, 65, 114, 114, 97,
121, 67, 111, 110, 116, 114,
111, 108, 0, 171, 144, 0,
0, 0, 1, 0, 0, 0,
184, 0, 0, 0, 16, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 208, 0,
0, 0, 0, 0, 0, 0,
4, 0, 0, 0, 2, 0,
0, 0, 216, 0, 0, 0,
0, 0, 0, 0, 73, 110,
100, 101, 120, 0, 171, 171,
0, 0, 3, 0, 1, 0,
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 77, 105,
99, 114, 111, 115, 111, 102,
116, 32, 40, 82, 41, 32,
72, 76, 83, 76, 32, 83,
104, 97, 100, 101, 114, 32,
67, 111, 109, 112, 105, 108,
101, 114, 32, 57, 46, 50,
57, 46, 57, 53, 50, 46,
51, 49, 49, 49, 0, 171,
171, 171, 73, 83, 71, 78,
80, 0, 0, 0, 2, 0,
0, 0, 8, 0, 0, 0,
56, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 15, 0, 0, 0,
68, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 1, 0,
0, 0, 15, 3, 0, 0,
83, 86, 95, 80, 79, 83,
73, 84, 73, 79, 78, 0,
84, 69, 88, 67, 79, 79,
82, 68, 0, 171, 171, 171,
79, 83, 71, 78, 44, 0,
0, 0, 1, 0, 0, 0,
8, 0, 0, 0, 32, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0,
15, 0, 0, 0, 83, 86,
95, 84, 97, 114, 103, 101,
116, 0, 171, 171, 83, 72,
68, 82, 172, 0, 0, 0,
65, 0, 0, 0, 43, 0,
0, 0, 106, 8, 0, 1,
89, 0, 0, 4, 70, 142,
32, 0, 0, 0, 0, 0,
1, 0, 0, 0, 90, 0,
0, 3, 0, 96, 16, 0,
0, 0, 0, 0, 88, 64,
0, 4, 0, 112, 16, 0,
0, 0, 0, 0, 85, 85,
0, 0, 98, 16, 0, 3,
50, 16, 16, 0, 1, 0,
0, 0, 101, 0, 0, 3,
242, 32, 16, 0, 0, 0,
0, 0, 104, 0, 0, 2,
1, 0, 0, 0, 54, 0,
0, 5, 50, 0, 16, 0,
0, 0, 0, 0, 70, 16,
16, 0, 1, 0, 0, 0,
54, 0, 0, 6, 66, 0,
16, 0, 0, 0, 0, 0,
10, 128, 32, 0, 0, 0,
0, 0, 0, 0, 0, 0,
69, 0, 0, 9, 242, 32,
16, 0, 0, 0, 0, 0,
70, 2, 16, 0, 0, 0,
0, 0, 70, 126, 16, 0,
0, 0, 0, 0, 0, 96,
16, 0, 0, 0, 0, 0,
62, 0, 0, 1, 83, 84,
65, 84, 116, 0, 0, 0,
4, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
2, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 2, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0
};

198
DDSView/shaders/ps3D.h Normal file
View File

@ -0,0 +1,198 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//
// fxc ddsview.fx /nologo /EPS_3D /Tps_4_1 /Fhshaders\ps3D.h
//
//
// Buffer Definitions:
//
// cbuffer cbArrayControl
// {
//
// float Index; // Offset: 0 Size: 4
//
// }
//
//
// Resource Bindings:
//
// Name Type Format Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// samLinear sampler NA NA 0 1
// tx3D texture float4 3d 0 1
// cbArrayControl cbuffer NA NA 0 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_POSITION 0 xyzw 0 POS float
// TEXCOORD 0 xyzw 1 NONE float xy
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_Target 0 xyzw 0 TARGET float xyzw
//
ps_4_1
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[1], immediateIndexed
dcl_sampler s0, mode_default
dcl_resource_texture3d (float,float,float,float) t0
dcl_input_ps linear v1.xy
dcl_output o0.xyzw
dcl_temps 1
resinfo r0.x, l(0), t0.zxyw
div r0.z, cb0[0].x, r0.x
mov r0.xy, v1.xyxx
sample o0.xyzw, r0.xyzx, t0.xyzw, s0
ret
// Approximately 5 instruction slots used
#endif
const BYTE g_PS_3D[] =
{
68, 88, 66, 67, 119, 18,
113, 52, 66, 105, 65, 45,
139, 58, 175, 102, 69, 213,
121, 186, 1, 0, 0, 0,
52, 3, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
84, 1, 0, 0, 172, 1,
0, 0, 224, 1, 0, 0,
184, 2, 0, 0, 82, 68,
69, 70, 24, 1, 0, 0,
1, 0, 0, 0, 156, 0,
0, 0, 3, 0, 0, 0,
28, 0, 0, 0, 1, 4,
255, 255, 0, 1, 0, 0,
228, 0, 0, 0, 124, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 1, 0, 0, 0,
134, 0, 0, 0, 2, 0,
0, 0, 5, 0, 0, 0,
8, 0, 0, 0, 255, 255,
255, 255, 0, 0, 0, 0,
1, 0, 0, 0, 13, 0,
0, 0, 139, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
1, 0, 0, 0, 115, 97,
109, 76, 105, 110, 101, 97,
114, 0, 116, 120, 51, 68,
0, 99, 98, 65, 114, 114,
97, 121, 67, 111, 110, 116,
114, 111, 108, 0, 171, 171,
139, 0, 0, 0, 1, 0,
0, 0, 180, 0, 0, 0,
16, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
204, 0, 0, 0, 0, 0,
0, 0, 4, 0, 0, 0,
2, 0, 0, 0, 212, 0,
0, 0, 0, 0, 0, 0,
73, 110, 100, 101, 120, 0,
171, 171, 0, 0, 3, 0,
1, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
77, 105, 99, 114, 111, 115,
111, 102, 116, 32, 40, 82,
41, 32, 72, 76, 83, 76,
32, 83, 104, 97, 100, 101,
114, 32, 67, 111, 109, 112,
105, 108, 101, 114, 32, 57,
46, 50, 57, 46, 57, 53,
50, 46, 51, 49, 49, 49,
0, 171, 171, 171, 73, 83,
71, 78, 80, 0, 0, 0,
2, 0, 0, 0, 8, 0,
0, 0, 56, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 15, 0,
0, 0, 68, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 3, 0, 0, 0,
1, 0, 0, 0, 15, 3,
0, 0, 83, 86, 95, 80,
79, 83, 73, 84, 73, 79,
78, 0, 84, 69, 88, 67,
79, 79, 82, 68, 0, 171,
171, 171, 79, 83, 71, 78,
44, 0, 0, 0, 1, 0,
0, 0, 8, 0, 0, 0,
32, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 15, 0, 0, 0,
83, 86, 95, 84, 97, 114,
103, 101, 116, 0, 171, 171,
83, 72, 68, 82, 208, 0,
0, 0, 65, 0, 0, 0,
52, 0, 0, 0, 106, 8,
0, 1, 89, 0, 0, 4,
70, 142, 32, 0, 0, 0,
0, 0, 1, 0, 0, 0,
90, 0, 0, 3, 0, 96,
16, 0, 0, 0, 0, 0,
88, 40, 0, 4, 0, 112,
16, 0, 0, 0, 0, 0,
85, 85, 0, 0, 98, 16,
0, 3, 50, 16, 16, 0,
1, 0, 0, 0, 101, 0,
0, 3, 242, 32, 16, 0,
0, 0, 0, 0, 104, 0,
0, 2, 1, 0, 0, 0,
61, 0, 0, 7, 18, 0,
16, 0, 0, 0, 0, 0,
1, 64, 0, 0, 0, 0,
0, 0, 38, 125, 16, 0,
0, 0, 0, 0, 14, 0,
0, 8, 66, 0, 16, 0,
0, 0, 0, 0, 10, 128,
32, 0, 0, 0, 0, 0,
0, 0, 0, 0, 10, 0,
16, 0, 0, 0, 0, 0,
54, 0, 0, 5, 50, 0,
16, 0, 0, 0, 0, 0,
70, 16, 16, 0, 1, 0,
0, 0, 69, 0, 0, 9,
242, 32, 16, 0, 0, 0,
0, 0, 70, 2, 16, 0,
0, 0, 0, 0, 70, 126,
16, 0, 0, 0, 0, 0,
0, 96, 16, 0, 0, 0,
0, 0, 62, 0, 0, 1,
83, 84, 65, 84, 116, 0,
0, 0, 5, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 0, 2, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0
};

194
DDSView/shaders/psCube.h Normal file
View File

@ -0,0 +1,194 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//
// fxc ddsview.fx /nologo /EPS_Cube /Tps_4_1 /Fhshaders\psCube.h
//
//
// Buffer Definitions:
//
// cbuffer cbArrayControl
// {
//
// float Index; // Offset: 0 Size: 4
//
// }
//
//
// Resource Bindings:
//
// Name Type Format Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// samLinear sampler NA NA 0 1
// tx2DArray texture float4 2darray 0 1
// cbArrayControl cbuffer NA NA 0 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_POSITION 0 xyzw 0 POS float
// TEXCOORD 0 xyzw 1 NONE float xyz
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_Target 0 xyzw 0 TARGET float xyzw
//
ps_4_1
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[1], immediateIndexed
dcl_sampler s0, mode_default
dcl_resource_texture2darray (float,float,float,float) t0
dcl_input_ps linear v1.xyz
dcl_output o0.xyzw
dcl_temps 1
mad r0.z, cb0[0].x, l(6.000000), v1.z
mov r0.xy, v1.xyxx
sample o0.xyzw, r0.xyzx, t0.xyzw, s0
ret
// Approximately 4 instruction slots used
#endif
const BYTE g_PS_Cube[] =
{
68, 88, 66, 67, 255, 88,
222, 202, 51, 233, 113, 192,
119, 52, 43, 119, 92, 83,
243, 127, 1, 0, 0, 0,
36, 3, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
88, 1, 0, 0, 176, 1,
0, 0, 228, 1, 0, 0,
168, 2, 0, 0, 82, 68,
69, 70, 28, 1, 0, 0,
1, 0, 0, 0, 160, 0,
0, 0, 3, 0, 0, 0,
28, 0, 0, 0, 1, 4,
255, 255, 0, 1, 0, 0,
232, 0, 0, 0, 124, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 1, 0, 0, 0,
134, 0, 0, 0, 2, 0,
0, 0, 5, 0, 0, 0,
5, 0, 0, 0, 255, 255,
255, 255, 0, 0, 0, 0,
1, 0, 0, 0, 13, 0,
0, 0, 144, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
1, 0, 0, 0, 115, 97,
109, 76, 105, 110, 101, 97,
114, 0, 116, 120, 50, 68,
65, 114, 114, 97, 121, 0,
99, 98, 65, 114, 114, 97,
121, 67, 111, 110, 116, 114,
111, 108, 0, 171, 144, 0,
0, 0, 1, 0, 0, 0,
184, 0, 0, 0, 16, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 208, 0,
0, 0, 0, 0, 0, 0,
4, 0, 0, 0, 2, 0,
0, 0, 216, 0, 0, 0,
0, 0, 0, 0, 73, 110,
100, 101, 120, 0, 171, 171,
0, 0, 3, 0, 1, 0,
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 77, 105,
99, 114, 111, 115, 111, 102,
116, 32, 40, 82, 41, 32,
72, 76, 83, 76, 32, 83,
104, 97, 100, 101, 114, 32,
67, 111, 109, 112, 105, 108,
101, 114, 32, 57, 46, 50,
57, 46, 57, 53, 50, 46,
51, 49, 49, 49, 0, 171,
171, 171, 73, 83, 71, 78,
80, 0, 0, 0, 2, 0,
0, 0, 8, 0, 0, 0,
56, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 15, 0, 0, 0,
68, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 1, 0,
0, 0, 15, 7, 0, 0,
83, 86, 95, 80, 79, 83,
73, 84, 73, 79, 78, 0,
84, 69, 88, 67, 79, 79,
82, 68, 0, 171, 171, 171,
79, 83, 71, 78, 44, 0,
0, 0, 1, 0, 0, 0,
8, 0, 0, 0, 32, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0,
15, 0, 0, 0, 83, 86,
95, 84, 97, 114, 103, 101,
116, 0, 171, 171, 83, 72,
68, 82, 188, 0, 0, 0,
65, 0, 0, 0, 47, 0,
0, 0, 106, 8, 0, 1,
89, 0, 0, 4, 70, 142,
32, 0, 0, 0, 0, 0,
1, 0, 0, 0, 90, 0,
0, 3, 0, 96, 16, 0,
0, 0, 0, 0, 88, 64,
0, 4, 0, 112, 16, 0,
0, 0, 0, 0, 85, 85,
0, 0, 98, 16, 0, 3,
114, 16, 16, 0, 1, 0,
0, 0, 101, 0, 0, 3,
242, 32, 16, 0, 0, 0,
0, 0, 104, 0, 0, 2,
1, 0, 0, 0, 50, 0,
0, 10, 66, 0, 16, 0,
0, 0, 0, 0, 10, 128,
32, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 64,
0, 0, 0, 0, 192, 64,
42, 16, 16, 0, 1, 0,
0, 0, 54, 0, 0, 5,
50, 0, 16, 0, 0, 0,
0, 0, 70, 16, 16, 0,
1, 0, 0, 0, 69, 0,
0, 9, 242, 32, 16, 0,
0, 0, 0, 0, 70, 2,
16, 0, 0, 0, 0, 0,
70, 126, 16, 0, 0, 0,
0, 0, 0, 96, 16, 0,
0, 0, 0, 0, 62, 0,
0, 1, 83, 84, 65, 84,
116, 0, 0, 0, 4, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 2, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0
};

131
DDSView/shaders/vs.h Normal file
View File

@ -0,0 +1,131 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//
// fxc ddsview.fx /nologo /EVS /Tvs_4_1 /Fhshaders\vs.h
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// POSITION 0 xyzw 0 NONE float xyzw
// TEXCOORD 0 xyzw 1 NONE float xyzw
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_POSITION 0 xyzw 0 POS float xyzw
// TEXCOORD 0 xyzw 1 NONE float xyzw
//
vs_4_1
dcl_globalFlags refactoringAllowed
dcl_input v0.xyzw
dcl_input v1.xyzw
dcl_output_siv o0.xyzw, position
dcl_output o1.xyzw
mov o0.xyzw, v0.xyzw
mov o1.xyzw, v1.xyzw
ret
// Approximately 3 instruction slots used
#endif
const BYTE g_VS[] =
{
68, 88, 66, 67, 243, 4,
207, 4, 72, 185, 125, 253,
86, 236, 11, 103, 199, 128,
83, 243, 1, 0, 0, 0,
40, 2, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
140, 0, 0, 0, 224, 0,
0, 0, 56, 1, 0, 0,
172, 1, 0, 0, 82, 68,
69, 70, 80, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
28, 0, 0, 0, 1, 4,
254, 255, 0, 1, 0, 0,
28, 0, 0, 0, 77, 105,
99, 114, 111, 115, 111, 102,
116, 32, 40, 82, 41, 32,
72, 76, 83, 76, 32, 83,
104, 97, 100, 101, 114, 32,
67, 111, 109, 112, 105, 108,
101, 114, 32, 57, 46, 50,
57, 46, 57, 53, 50, 46,
51, 49, 49, 49, 0, 171,
171, 171, 73, 83, 71, 78,
76, 0, 0, 0, 2, 0,
0, 0, 8, 0, 0, 0,
56, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 15, 15, 0, 0,
65, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 1, 0,
0, 0, 15, 15, 0, 0,
80, 79, 83, 73, 84, 73,
79, 78, 0, 84, 69, 88,
67, 79, 79, 82, 68, 0,
171, 171, 79, 83, 71, 78,
80, 0, 0, 0, 2, 0,
0, 0, 8, 0, 0, 0,
56, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 15, 0, 0, 0,
68, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 1, 0,
0, 0, 15, 0, 0, 0,
83, 86, 95, 80, 79, 83,
73, 84, 73, 79, 78, 0,
84, 69, 88, 67, 79, 79,
82, 68, 0, 171, 171, 171,
83, 72, 68, 82, 108, 0,
0, 0, 65, 0, 1, 0,
27, 0, 0, 0, 106, 8,
0, 1, 95, 0, 0, 3,
242, 16, 16, 0, 0, 0,
0, 0, 95, 0, 0, 3,
242, 16, 16, 0, 1, 0,
0, 0, 103, 0, 0, 4,
242, 32, 16, 0, 0, 0,
0, 0, 1, 0, 0, 0,
101, 0, 0, 3, 242, 32,
16, 0, 1, 0, 0, 0,
54, 0, 0, 5, 242, 32,
16, 0, 0, 0, 0, 0,
70, 30, 16, 0, 0, 0,
0, 0, 54, 0, 0, 5,
242, 32, 16, 0, 1, 0,
0, 0, 70, 30, 16, 0,
1, 0, 0, 0, 62, 0,
0, 1, 83, 84, 65, 84,
116, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 4, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0
};

1131
DirectXTex/BC.cpp Normal file

File diff suppressed because it is too large Load Diff

897
DirectXTex/BC.h Normal file
View File

@ -0,0 +1,897 @@
//-------------------------------------------------------------------------------------
// BC.h
//
// Block-compression (BC) functionality
//
// 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
#include <assert.h>
#ifdef USE_XNAMATH
#include <xnamath.h>
#else
#include <directxmath.h>
#include <directxpackedvector.h>
#endif
#include <float.h>
#pragma warning(push)
#pragma warning(disable : 4005)
#include <stdint.h>
#pragma warning(pop)
namespace DirectX
{
#ifndef USE_XNAMATH
typedef PackedVector::HALF HALF;
typedef PackedVector::XMHALF4 XMHALF4;
typedef PackedVector::XMU565 XMU565;
#endif
//-------------------------------------------------------------------------------------
// Constants
//-------------------------------------------------------------------------------------
const uint16_t F16S_MASK = 0x8000; // f16 sign mask
const uint16_t F16EM_MASK = 0x7fff; // f16 exp & mantissa mask
const uint16_t F16MAX = 0x7bff; // MAXFLT bit pattern for XMHALF
#define SIGN_EXTEND(x,nb) ((((x)&(1<<((nb)-1)))?((~0)<<(nb)):0)|(x))
// Because these are used in SAL annotations, they need to remain macros rather than const values
#define NUM_PIXELS_PER_BLOCK 16
#define BC6H_MAX_REGIONS 2
#define BC6H_MAX_INDICES 16
#define BC7_MAX_REGIONS 3
#define BC7_MAX_INDICES 16
const size_t BC6H_NUM_CHANNELS = 3;
const size_t BC6H_MAX_SHAPES = 32;
const size_t BC7_NUM_CHANNELS = 4;
const size_t BC7_MAX_SHAPES = 64;
const uint32_t BC67_WEIGHT_MAX = 64;
const uint32_t BC67_WEIGHT_SHIFT = 6;
const uint32_t BC67_WEIGHT_ROUND = 32;
extern const int g_aWeights2[4];
extern const int g_aWeights3[8];
extern const int g_aWeights4[16];
enum BC_FLAGS
{
BC_FLAGS_NONE = 0x0,
BC_FLAGS_DITHER_RGB = 0x10000, // Enables dithering for RGB colors for BC1-3
BC_FLAGS_DITHER_A = 0x20000, // Enables dithering for Alpha channel for BC1-3
BC_FLAGS_UNIFORM = 0x40000, // By default, uses perceptual weighting for BC1-3; this flag makes it a uniform weighting
};
//-------------------------------------------------------------------------------------
// Structures
//-------------------------------------------------------------------------------------
class HDRColorA;
class LDRColorA
{
public:
uint8_t r, g, b, a;
LDRColorA() {}
LDRColorA(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a) : r(_r), g(_g), b(_b), a(_a) {}
const uint8_t& operator [] (_In_range_(0,3) size_t uElement) const
{
switch(uElement)
{
case 0: return r;
case 1: return g;
case 2: return b;
case 3: return a;
default: assert(false); return r;
}
}
uint8_t& operator [] (_In_range_(0,3) size_t uElement)
{
switch(uElement)
{
case 0: return r;
case 1: return g;
case 2: return b;
case 3: return a;
default: assert(false); return r;
}
}
LDRColorA operator = (_In_ const HDRColorA& c);
static void InterpolateRGB(_In_ const LDRColorA& c0, _In_ const LDRColorA& c1, _In_ size_t wc, _In_ size_t wcprec, _Out_ LDRColorA& out)
{
const int* aWeights = nullptr;
switch(wcprec)
{
case 2: aWeights = g_aWeights2; assert( wc < 4 ); __analysis_assume( wc < 4 ); break;
case 3: aWeights = g_aWeights3; assert( wc < 8 ); __analysis_assume( wc < 8 ); break;
case 4: aWeights = g_aWeights4; assert( wc < 16 ); __analysis_assume( wc < 16 ); break;
default: assert(false); out.r = out.g = out.b = 0; return;
}
out.r = uint8_t((uint32_t(c0.r) * uint32_t(BC67_WEIGHT_MAX - aWeights[wc]) + uint32_t(c1.r) * uint32_t(aWeights[wc]) + BC67_WEIGHT_ROUND) >> BC67_WEIGHT_SHIFT);
out.g = uint8_t((uint32_t(c0.g) * uint32_t(BC67_WEIGHT_MAX - aWeights[wc]) + uint32_t(c1.g) * uint32_t(aWeights[wc]) + BC67_WEIGHT_ROUND) >> BC67_WEIGHT_SHIFT);
out.b = uint8_t((uint32_t(c0.b) * uint32_t(BC67_WEIGHT_MAX - aWeights[wc]) + uint32_t(c1.b) * uint32_t(aWeights[wc]) + BC67_WEIGHT_ROUND) >> BC67_WEIGHT_SHIFT);
}
static void InterpolateA(_In_ const LDRColorA& c0, _In_ const LDRColorA& c1, _In_ size_t wa, _In_ size_t waprec, _Out_ LDRColorA& out)
{
const int* aWeights = nullptr;
switch(waprec)
{
case 2: aWeights = g_aWeights2; assert( wa < 4 ); __analysis_assume( wa < 4 ); break;
case 3: aWeights = g_aWeights3; assert( wa < 8 ); __analysis_assume( wa < 8 ); break;
case 4: aWeights = g_aWeights4; assert( wa < 16 ); __analysis_assume( wa < 16 ); break;
default: assert(false); out.a = 0; return;
}
out.a = uint8_t((uint32_t(c0.a) * uint32_t(BC67_WEIGHT_MAX - aWeights[wa]) + uint32_t(c1.a) * uint32_t(aWeights[wa]) + BC67_WEIGHT_ROUND) >> BC67_WEIGHT_SHIFT);
}
static void Interpolate(_In_ const LDRColorA& c0, _In_ const LDRColorA& c1, _In_ size_t wc, _In_ size_t wa, _In_ size_t wcprec, _In_ size_t waprec, _Out_ LDRColorA& out)
{
InterpolateRGB(c0, c1, wc, wcprec, out);
InterpolateA(c0, c1, wa, waprec, out);
}
};
class HDRColorA
{
public:
float r, g, b, a;
public:
HDRColorA() {}
HDRColorA(float _r, float _g, float _b, float _a) : r(_r), g(_g), b(_b), a(_a) {}
HDRColorA(const HDRColorA& c) : r(c.r), g(c.g), b(c.b), a(c.a) {}
HDRColorA(const LDRColorA& c)
{
r = float(c.r) * (1.0f/255.0f);
g = float(c.g) * (1.0f/255.0f);
b = float(c.b) * (1.0f/255.0f);
a = float(c.a) * (1.0f/255.0f);
}
// binary operators
HDRColorA operator + ( _In_ const HDRColorA& c ) const
{
return HDRColorA(r + c.r, g + c.g, b + c.b, a + c.a);
}
HDRColorA operator - ( _In_ const HDRColorA& c ) const
{
return HDRColorA(r - c.r, g - c.g, b - c.b, a - c.a);
}
HDRColorA operator * ( _In_ float f ) const
{
return HDRColorA(r * f, g * f, b * f, a * f);
}
HDRColorA operator / ( _In_ float f ) const
{
float fInv = 1.0f / f;
return HDRColorA(r * fInv, g * fInv, b * fInv, a * fInv);
}
float operator * ( _In_ const HDRColorA& c ) const
{
return r * c.r + g * c.g + b * c.b + a * c.a;
}
// assignment operators
HDRColorA& operator += ( _In_ const HDRColorA& c )
{
r += c.r;
g += c.g;
b += c.b;
a += c.a;
return *this;
}
HDRColorA& operator -= ( _In_ const HDRColorA& c )
{
r -= c.r;
g -= c.g;
b -= c.b;
a -= c.a;
return *this;
}
HDRColorA& operator *= ( _In_ float f )
{
r *= f;
g *= f;
b *= f;
a *= f;
return *this;
}
HDRColorA& operator /= ( _In_ float f )
{
float fInv = 1.0f / f;
r *= fInv;
g *= fInv;
b *= fInv;
a *= fInv;
return *this;
}
HDRColorA& operator = (_In_ const LDRColorA& c)
{
r = (float) c.r;
g = (float) c.g;
b = (float) c.b;
a = (float) c.a;
return *this;
}
HDRColorA& Clamp(_In_ float fMin, _In_ float fMax)
{
r = std::min<float>(fMax, std::max<float>(fMin, r));
g = std::min<float>(fMax, std::max<float>(fMin, g));
b = std::min<float>(fMax, std::max<float>(fMin, b));
a = std::min<float>(fMax, std::max<float>(fMin, a));
return *this;
}
LDRColorA ToLDRColorA() const
{
return LDRColorA((uint8_t) (r + 0.01f), (uint8_t) (g + 0.01f), (uint8_t) (b + 0.01f), (uint8_t) (a + 0.01f));
}
};
inline LDRColorA LDRColorA::operator = (_In_ const HDRColorA& c)
{
LDRColorA ret;
HDRColorA tmp(c);
tmp = tmp.Clamp(0.0f, 1.0f) * 255.0f;
ret.r = uint8_t(tmp.r + 0.001f);
ret.g = uint8_t(tmp.g + 0.001f);
ret.b = uint8_t(tmp.b + 0.001f);
ret.a = uint8_t(tmp.a + 0.001f);
return ret;
}
struct LDREndPntPair
{
LDRColorA A;
LDRColorA B;
};
struct HDREndPntPair
{
HDRColorA A;
HDRColorA B;
};
inline HDRColorA* HDRColorALerp(_Out_ HDRColorA *pOut, _In_ const HDRColorA *pC1, _In_ const HDRColorA *pC2, _In_ float s)
{
pOut->r = pC1->r + s * (pC2->r - pC1->r);
pOut->g = pC1->g + s * (pC2->g - pC1->g);
pOut->b = pC1->b + s * (pC2->b - pC1->b);
pOut->a = pC1->a + s * (pC2->a - pC1->a);
return pOut;
}
#pragma pack(push,1)
// BC1/DXT1 compression (4 bits per texel)
struct D3DX_BC1
{
uint16_t rgb[2]; // 565 colors
uint32_t bitmap; // 2bpp rgb bitmap
};
// BC2/DXT2/3 compression (8 bits per texel)
struct D3DX_BC2
{
uint32_t bitmap[2]; // 4bpp alpha bitmap
D3DX_BC1 bc1; // BC1 rgb data
};
// BC3/DXT4/5 compression (8 bits per texel)
struct D3DX_BC3
{
uint8_t alpha[2]; // alpha values
uint8_t bitmap[6]; // 3bpp alpha bitmap
D3DX_BC1 bc1; // BC1 rgb data
};
#pragma pack(pop)
class INTColor
{
public:
int r, g, b;
public:
INTColor() {}
INTColor(int nr, int ng, int nb) {r = nr; g = ng; b = nb;}
INTColor(const INTColor& c) {r = c.r; g = c.g; b = c.b;}
INTColor operator - ( _In_ const INTColor& c ) const
{
return INTColor(r - c.r, g - c.g, b - c.b);
}
INTColor& operator += ( _In_ const INTColor& c )
{
r += c.r;
g += c.g;
b += c.b;
return *this;
}
INTColor& operator -= ( _In_ const INTColor& c )
{
r -= c.r;
g -= c.g;
b -= c.b;
return *this;
}
INTColor& operator &= ( _In_ const INTColor& c )
{
r &= c.r;
g &= c.g;
b &= c.b;
return *this;
}
int& operator [] ( _In_ uint8_t i )
{
assert(i < sizeof(INTColor) / sizeof(int));
__analysis_assume(i < sizeof(INTColor) / sizeof(int));
return ((int*) this)[i];
}
void Set(_In_ const HDRColorA& c, _In_ bool bSigned)
{
XMHALF4 aF16;
XMVECTOR v = XMLoadFloat4( (const XMFLOAT4*)& c );
XMStoreHalf4( &aF16, v );
r = F16ToINT(aF16.x, bSigned);
g = F16ToINT(aF16.y, bSigned);
b = F16ToINT(aF16.z, bSigned);
}
INTColor& Clamp(_In_ int iMin, _In_ int iMax)
{
r = std::min<int>(iMax, std::max<int>(iMin, r));
g = std::min<int>(iMax, std::max<int>(iMin, g));
b = std::min<int>(iMax, std::max<int>(iMin, b));
return *this;
}
INTColor& SignExtend(_In_ const LDRColorA& Prec)
{
r = SIGN_EXTEND(r, Prec.r);
g = SIGN_EXTEND(g, Prec.g);
b = SIGN_EXTEND(b, Prec.b);
return *this;
}
void ToF16(_Out_cap_c_(3) HALF aF16[3], _In_ bool bSigned) const
{
aF16[0] = INT2F16(r, bSigned);
aF16[1] = INT2F16(g, bSigned);
aF16[2] = INT2F16(b, bSigned);
}
private:
static int F16ToINT(_In_ const HALF& f, _In_ bool bSigned)
{
uint16_t input = *((const uint16_t*) &f);
int out, s;
if(bSigned)
{
s = input & F16S_MASK;
input &= F16EM_MASK;
if(input > F16MAX) out = F16MAX;
else out = input;
out = s ? -out : out;
}
else
{
if(input & F16S_MASK) out = 0;
else out = input;
}
return out;
}
static HALF INT2F16(_In_ int input, _In_ bool bSigned)
{
HALF h;
uint16_t out;
if(bSigned)
{
int s = 0;
if(input < 0)
{
s = F16S_MASK;
input = -input;
}
out = uint16_t(s | input);
}
else
{
assert(input >= 0 && input <= F16MAX);
out = (uint16_t) input;
}
*((uint16_t*) &h) = out;
return h;
}
};
struct INTEndPntPair
{
INTColor A;
INTColor B;
};
template< size_t SizeInBytes >
class CBits
{
public:
uint8_t GetBit(_Inout_ size_t& uStartBit) const
{
assert(uStartBit < 128);
__analysis_assume(uStartBit < 128);
size_t uIndex = uStartBit >> 3;
uint8_t ret = (m_uBits[uIndex] >> (uStartBit - (uIndex << 3))) & 0x01;
uStartBit++;
return ret;
}
uint8_t GetBits(_Inout_ size_t& uStartBit, _In_ size_t uNumBits) const
{
if(uNumBits == 0) return 0;
assert(uStartBit + uNumBits <= 128 && uNumBits <= 8);
__analysis_assume(uStartBit + uNumBits <= 128 && uNumBits <= 8);
uint8_t ret;
size_t uIndex = uStartBit >> 3;
size_t uBase = uStartBit - (uIndex << 3);
if(uBase + uNumBits > 8)
{
size_t uFirstIndexBits = 8 - uBase;
size_t uNextIndexBits = uNumBits - uFirstIndexBits;
ret = (m_uBits[uIndex] >> uBase) | ((m_uBits[uIndex+1] & ((1 << uNextIndexBits) - 1)) << uFirstIndexBits);
}
else
{
ret = (m_uBits[uIndex] >> uBase) & ((1 << uNumBits) - 1);
}
assert(ret < (1 << uNumBits));
uStartBit += uNumBits;
return ret;
}
void SetBit(_Inout_ size_t& uStartBit, _In_ uint8_t uValue)
{
assert(uStartBit < 128 && uValue < 2);
__analysis_assume(uStartBit < 128 && uValue < 2);
size_t uIndex = uStartBit >> 3;
size_t uBase = uStartBit - (uIndex << 3);
m_uBits[uIndex] &= ~(1 << uBase);
m_uBits[uIndex] |= uValue << uBase;
uStartBit++;
}
void SetBits(_Inout_ size_t& uStartBit, _In_ size_t uNumBits, _In_ uint8_t uValue)
{
if(uNumBits == 0)
return;
assert(uStartBit + uNumBits <= 128 && uNumBits <= 8);
__analysis_assume(uStartBit + uNumBits <= 128 && uNumBits <= 8);
assert(uValue < (1 << uNumBits));
size_t uIndex = uStartBit >> 3;
size_t uBase = uStartBit - (uIndex << 3);
if(uBase + uNumBits > 8)
{
size_t uFirstIndexBits = 8 - uBase;
size_t uNextIndexBits = uNumBits - uFirstIndexBits;
m_uBits[uIndex] &= ~(((1 << uFirstIndexBits) - 1) << uBase);
m_uBits[uIndex] |= uValue << uBase;
m_uBits[uIndex+1] &= ~((1 << uNextIndexBits) - 1);
m_uBits[uIndex+1] |= uValue >> uFirstIndexBits;
}
else
{
m_uBits[uIndex] &= ~(((1 << uNumBits) - 1) << uBase);
m_uBits[uIndex] |= uValue << uBase;
}
uStartBit += uNumBits;
}
private:
uint8_t m_uBits[ SizeInBytes ];
};
#pragma warning(push)
#pragma warning(disable : 4127 4480 4512)
// BC6H compression (16 bits per texel)
class D3DX_BC6H : private CBits< 16 >
{
public:
void Decode(_In_ bool bSigned, _Out_cap_c_(NUM_PIXELS_PER_BLOCK) HDRColorA* pOut) const;
void Encode(_In_ bool bSigned, _In_count_c_(NUM_PIXELS_PER_BLOCK) const HDRColorA* const pIn);
private:
enum EField : uint8_t
{
NA, // N/A
M, // Mode
D, // Shape
RW,
RX,
RY,
RZ,
GW,
GX,
GY,
GZ,
BW,
BX,
BY,
BZ,
};
struct ModeDescriptor
{
EField m_eField;
uint8_t m_uBit;
};
struct ModeInfo
{
uint8_t uMode;
uint8_t uPartitions;
bool bTransformed;
uint8_t uIndexPrec;
LDRColorA RGBAPrec[BC6H_MAX_REGIONS][2];
};
struct EncodeParams
{
float fBestErr;
const bool bSigned;
uint8_t uMode;
uint8_t uShape;
const HDRColorA* const aHDRPixels;
INTEndPntPair aUnqEndPts[BC6H_MAX_SHAPES][BC6H_MAX_REGIONS];
INTColor aIPixels[NUM_PIXELS_PER_BLOCK];
EncodeParams(const HDRColorA* const aOriginal, bool bSignedFormat) :
aHDRPixels(aOriginal), fBestErr(FLT_MAX), bSigned(bSignedFormat)
{
for(size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
{
aIPixels[i].Set(aOriginal[i], bSigned);
}
}
};
static int Quantize(_In_ int iValue, _In_ int prec, _In_ bool bSigned);
static int Unquantize(_In_ int comp, _In_ uint8_t uBitsPerComp, _In_ bool bSigned);
static int FinishUnquantize(_In_ int comp, _In_ bool bSigned);
static bool EndPointsFit(_In_ const EncodeParams* pEP, _In_count_c_(BC6H_MAX_REGIONS) const INTEndPntPair aEndPts[]);
void GeneratePaletteQuantized(_In_ const EncodeParams* pEP, _In_ const INTEndPntPair& endPts,
_Out_cap_c_(BC6H_MAX_INDICES) INTColor aPalette[]) const;
float MapColorsQuantized(_In_ const EncodeParams* pEP, _In_count_(np) const INTColor aColors[], _In_ size_t np, _In_ const INTEndPntPair &endPts) const;
float PerturbOne(_In_ const EncodeParams* pEP, _In_count_(np) const INTColor aColors[], _In_ size_t np, _In_ uint8_t ch,
_In_ const INTEndPntPair& oldEndPts, _Out_ INTEndPntPair& newEndPts, _In_ float fOldErr, _In_ int do_b) const;
void OptimizeOne(_In_ const EncodeParams* pEP, _In_count_(np) const INTColor aColors[], _In_ size_t np, _In_ float aOrgErr,
_In_ const INTEndPntPair &aOrgEndPts, _Out_ INTEndPntPair &aOptEndPts) const;
void OptimizeEndPoints(_In_ const EncodeParams* pEP, _In_count_c_(BC6H_MAX_REGIONS) const float aOrgErr[],
_In_count_c_(BC6H_MAX_REGIONS) const INTEndPntPair aOrgEndPts[],
_Inout_count_c_(BC6H_MAX_REGIONS) INTEndPntPair aOptEndPts[]) const;
static void SwapIndices(_In_ const EncodeParams* pEP, _Inout_count_c_(BC6H_MAX_REGIONS) INTEndPntPair aEndPts[],
_In_count_c_(NUM_PIXELS_PER_BLOCK) size_t aIndices[]);
void AssignIndices(_In_ const EncodeParams* pEP, _In_count_c_(BC6H_MAX_REGIONS) const INTEndPntPair aEndPts[],
_Out_cap_c_(NUM_PIXELS_PER_BLOCK) size_t aIndices[],
_Out_cap_c_(BC6H_MAX_REGIONS) float aTotErr[]) const;
void QuantizeEndPts(_In_ const EncodeParams* pEP, _Out_cap_c_(BC6H_MAX_REGIONS) INTEndPntPair* qQntEndPts) const;
void EmitBlock(_In_ const EncodeParams* pEP, _In_count_c_(BC6H_MAX_REGIONS) const INTEndPntPair aEndPts[],
_In_count_c_(NUM_PIXELS_PER_BLOCK) const size_t aIndices[]);
void Refine(_Inout_ EncodeParams* pEP);
static void GeneratePaletteUnquantized(_In_ const EncodeParams* pEP, _In_ size_t uRegion, _Out_cap_c_(BC6H_MAX_INDICES) INTColor aPalette[]);
float MapColors(_In_ const EncodeParams* pEP, _In_ size_t uRegion, _In_ size_t np, _In_count_(np) const size_t* auIndex) const;
float RoughMSE(_Inout_ EncodeParams* pEP) const;
private:
const static ModeDescriptor ms_aDesc[][82];
const static ModeInfo ms_aInfo[];
const static int ms_aModeToInfo[];
};
// BC67 compression (16b bits per texel)
class D3DX_BC7 : private CBits< 16 >
{
public:
void Decode(_Out_cap_c_(NUM_PIXELS_PER_BLOCK) HDRColorA* pOut) const;
void Encode(_In_count_c_(NUM_PIXELS_PER_BLOCK) const HDRColorA* const pIn);
private:
struct ModeInfo
{
uint8_t uPartitions;
uint8_t uPartitionBits;
uint8_t uPBits;
uint8_t uRotationBits;
uint8_t uIndexModeBits;
uint8_t uIndexPrec;
uint8_t uIndexPrec2;
LDRColorA RGBAPrec;
LDRColorA RGBAPrecWithP;
};
struct EncodeParams
{
uint8_t uMode;
LDREndPntPair aEndPts[BC7_MAX_SHAPES][BC7_MAX_REGIONS];
LDRColorA aLDRPixels[NUM_PIXELS_PER_BLOCK];
const HDRColorA* const aHDRPixels;
EncodeParams(const HDRColorA* const aOriginal) : aHDRPixels(aOriginal) {}
};
static uint8_t Quantize(_In_ uint8_t comp, _In_ uint8_t uPrec)
{
assert(0 < uPrec && uPrec <= 8);
uint8_t rnd = (uint8_t) std::min<uint16_t>(255, uint16_t(comp) + (1 << (7 - uPrec)));
return rnd >> (8 - uPrec);
}
static LDRColorA Quantize(_In_ const LDRColorA& c, _In_ const LDRColorA& RGBAPrec)
{
LDRColorA q;
q.r = Quantize(c.r, RGBAPrec.r);
q.g = Quantize(c.g, RGBAPrec.g);
q.b = Quantize(c.b, RGBAPrec.b);
if(RGBAPrec.a)
q.a = Quantize(c.a, RGBAPrec.a);
else
q.a = 255;
return q;
}
static uint8_t Unquantize(_In_ uint8_t comp, _In_ size_t uPrec)
{
assert(0 < uPrec && uPrec <= 8);
comp = comp << (8 - uPrec);
return comp | (comp >> uPrec);
}
static LDRColorA Unquantize(_In_ const LDRColorA& c, _In_ const LDRColorA& RGBAPrec)
{
LDRColorA q;
q.r = Unquantize(c.r, RGBAPrec.r);
q.g = Unquantize(c.g, RGBAPrec.g);
q.b = Unquantize(c.b, RGBAPrec.b);
q.a = RGBAPrec.a > 0 ? Unquantize(c.a, RGBAPrec.a) : 255;
return q;
}
void GeneratePaletteQuantized(_In_ const EncodeParams* pEP, _In_ size_t uIndexMode, _In_ const LDREndPntPair& endpts,
_Out_cap_c_(BC7_MAX_INDICES) LDRColorA aPalette[]) const;
float PerturbOne(_In_ const EncodeParams* pEP, _In_count_(np) const LDRColorA colors[], _In_ size_t np, _In_ size_t uIndexMode,
_In_ size_t ch, _In_ const LDREndPntPair &old_endpts,
_Out_ LDREndPntPair &new_endpts, _In_ float old_err, _In_ uint8_t do_b) const;
void Exhaustive(_In_ const EncodeParams* pEP, _In_count_(np) const LDRColorA aColors[], _In_ size_t np, _In_ size_t uIndexMode,
_In_ size_t ch, _Inout_ float& fOrgErr, _Inout_ LDREndPntPair& optEndPt) const;
void OptimizeOne(_In_ const EncodeParams* pEP, _In_count_(np) const LDRColorA colors[], _In_ size_t np, _In_ size_t uIndexMode,
_In_ float orig_err, _In_ const LDREndPntPair &orig_endpts, _Out_ LDREndPntPair &opt_endpts) const;
void OptimizeEndPoints(_In_ const EncodeParams* pEP, _In_ size_t uShape, _In_ size_t uIndexMode,
_In_count_c_(BC7_MAX_REGIONS) const float orig_err[],
_In_count_c_(BC7_MAX_REGIONS) const LDREndPntPair orig_endpts[],
_Out_cap_c_(BC7_MAX_REGIONS) LDREndPntPair opt_endpts[]) const;
void AssignIndices(_In_ const EncodeParams* pEP, _In_ size_t uShape, _In_ size_t uIndexMode,
_In_count_c_(BC7_MAX_REGIONS) LDREndPntPair endpts[],
_Out_cap_c_(NUM_PIXELS_PER_BLOCK) size_t aIndices[], _Out_cap_c_(NUM_PIXELS_PER_BLOCK) size_t aIndices2[],
_Out_cap_c_(BC7_MAX_REGIONS) float afTotErr[]) const;
void EmitBlock(_In_ const EncodeParams* pEP, _In_ size_t uShape, _In_ size_t uRotation, _In_ size_t uIndexMode,
_In_count_c_(BC7_MAX_REGIONS) const LDREndPntPair aEndPts[],
_In_count_c_(NUM_PIXELS_PER_BLOCK) const size_t aIndex[],
_In_count_c_(NUM_PIXELS_PER_BLOCK) const size_t aIndex2[]);
float Refine(_In_ const EncodeParams* pEP, _In_ size_t uShape, _In_ size_t uRotation, _In_ size_t uIndexMode);
float MapColors(_In_ const EncodeParams* pEP, _In_count_(np) const LDRColorA aColors[], _In_ size_t np, _In_ size_t uIndexMode,
_In_ const LDREndPntPair& endPts, _In_ float fMinErr) const;
static float RoughMSE(_Inout_ EncodeParams* pEP, _In_ size_t uShape, _In_ size_t uIndexMode);
private:
const static ModeInfo ms_aInfo[];
};
//-------------------------------------------------------------------------------------
template <bool bRange> void OptimizeAlpha(float *pX, float *pY, const float *pPoints, size_t cSteps)
{
static const float pC6[] = { 5.0f/5.0f, 4.0f/5.0f, 3.0f/5.0f, 2.0f/5.0f, 1.0f/5.0f, 0.0f/5.0f };
static const float pD6[] = { 0.0f/5.0f, 1.0f/5.0f, 2.0f/5.0f, 3.0f/5.0f, 4.0f/5.0f, 5.0f/5.0f };
static const float pC8[] = { 7.0f/7.0f, 6.0f/7.0f, 5.0f/7.0f, 4.0f/7.0f, 3.0f/7.0f, 2.0f/7.0f, 1.0f/7.0f, 0.0f/7.0f };
static const float pD8[] = { 0.0f/7.0f, 1.0f/7.0f, 2.0f/7.0f, 3.0f/7.0f, 4.0f/7.0f, 5.0f/7.0f, 6.0f/7.0f, 7.0f/7.0f };
const float *pC = (6 == cSteps) ? pC6 : pC8;
const float *pD = (6 == cSteps) ? pD6 : pD8;
float MAX_VALUE = 1.0f;
float MIN_VALUE;
if (bRange)
{
MIN_VALUE = -1.0f;
}
else
{
MIN_VALUE = 0.0f;
}
// Find Min and Max points, as starting point
float fX = MAX_VALUE;
float fY = MIN_VALUE;
if(8 == cSteps)
{
for(size_t iPoint = 0; iPoint < NUM_PIXELS_PER_BLOCK; iPoint++)
{
if(pPoints[iPoint] < fX)
fX = pPoints[iPoint];
if(pPoints[iPoint] > fY)
fY = pPoints[iPoint];
}
}
else
{
for(size_t iPoint = 0; iPoint < NUM_PIXELS_PER_BLOCK; iPoint++)
{
if(pPoints[iPoint] < fX && pPoints[iPoint] > MIN_VALUE)
fX = pPoints[iPoint];
if(pPoints[iPoint] > fY && pPoints[iPoint] < MAX_VALUE)
fY = pPoints[iPoint];
}
if (fX == fY)
{
fY = MAX_VALUE;
}
}
// Use Newton's Method to find local minima of sum-of-squares error.
float fSteps = (float) (cSteps - 1);
for(size_t iIteration = 0; iIteration < 8; iIteration++)
{
float fScale;
if((fY - fX) < (1.0f / 256.0f))
break;
fScale = fSteps / (fY - fX);
// Calculate new steps
float pSteps[8];
for(size_t iStep = 0; iStep < cSteps; iStep++)
pSteps[iStep] = pC[iStep] * fX + pD[iStep] * fY;
if(6 == cSteps)
{
pSteps[6] = MIN_VALUE;
pSteps[7] = MAX_VALUE;
}
// Evaluate function, and derivatives
float dX = 0.0f;
float dY = 0.0f;
float d2X = 0.0f;
float d2Y = 0.0f;
for(size_t iPoint = 0; iPoint < NUM_PIXELS_PER_BLOCK; iPoint++)
{
float fDot = (pPoints[iPoint] - fX) * fScale;
size_t iStep;
if(fDot <= 0.0f)
iStep = ((6 == cSteps) && (pPoints[iPoint] <= fX * 0.5f)) ? 6 : 0;
else if(fDot >= fSteps)
iStep = ((6 == cSteps) && (pPoints[iPoint] >= (fY + 1.0f) * 0.5f)) ? 7 : (cSteps - 1);
else
iStep = static_cast<int32_t>(fDot + 0.5f);
if(iStep < cSteps)
{
// D3DX had this computation backwards (pPoints[iPoint] - pSteps[iStep])
// this fix improves RMS of the alpha component
float fDiff = pSteps[iStep] - pPoints[iPoint];
dX += pC[iStep] * fDiff;
d2X += pC[iStep] * pC[iStep];
dY += pD[iStep] * fDiff;
d2Y += pD[iStep] * pD[iStep];
}
}
// Move endpoints
if(d2X > 0.0f)
fX -= dX / d2X;
if(d2Y > 0.0f)
fY -= dY / d2Y;
if(fX > fY)
{
float f = fX; fX = fY; fY = f;
}
if((dX * dX < (1.0f / 64.0f)) && (dY * dY < (1.0f / 64.0f)))
break;
}
*pX = (fX < MIN_VALUE) ? MIN_VALUE : (fX > MAX_VALUE) ? MAX_VALUE : fX;
*pY = (fY < MIN_VALUE) ? MIN_VALUE : (fY > MAX_VALUE) ? MAX_VALUE : fY;
}
#pragma warning(pop)
//-------------------------------------------------------------------------------------
// Functions
//-------------------------------------------------------------------------------------
typedef void (*BC_DECODE)(XMVECTOR *pColor, const uint8_t *pBC);
typedef void (*BC_ENCODE)(uint8_t *pDXT, const XMVECTOR *pColor, DWORD flags);
void D3DXDecodeBC1(_Out_cap_c_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_count_c_(8) const uint8_t *pBC);
void D3DXDecodeBC2(_Out_cap_c_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_count_c_(16) const uint8_t *pBC);
void D3DXDecodeBC3(_Out_cap_c_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_count_c_(16) const uint8_t *pBC);
void D3DXDecodeBC4U(_Out_cap_c_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_count_c_(8) const uint8_t *pBC);
void D3DXDecodeBC4S(_Out_cap_c_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_count_c_(8) const uint8_t *pBC);
void D3DXDecodeBC5U(_Out_cap_c_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_count_c_(16) const uint8_t *pBC);
void D3DXDecodeBC5S(_Out_cap_c_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_count_c_(16) const uint8_t *pBC);
void D3DXDecodeBC6HU(_Out_cap_c_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_count_c_(16) const uint8_t *pBC);
void D3DXDecodeBC6HS(_Out_cap_c_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_count_c_(16) const uint8_t *pBC);
void D3DXDecodeBC7(_Out_cap_c_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_count_c_(16) const uint8_t *pBC);
void D3DXEncodeBC1(_Out_cap_c_(8) uint8_t *pBC, _In_count_c_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ float alphaRef, _In_ DWORD flags);
// BC1 requires one additional parameter, so it doesn't match signature of BC_ENCODE above
void D3DXEncodeBC2(_Out_cap_c_(16) uint8_t *pBC, _In_count_c_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ DWORD flags);
void D3DXEncodeBC3(_Out_cap_c_(16) uint8_t *pBC, _In_count_c_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ DWORD flags);
void D3DXEncodeBC4U(_Out_cap_c_(8) uint8_t *pBC, _In_count_c_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ DWORD flags);
void D3DXEncodeBC4S(_Out_cap_c_(8) uint8_t *pBC, _In_count_c_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ DWORD flags);
void D3DXEncodeBC5U(_Out_cap_c_(16) uint8_t *pBC, _In_count_c_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ DWORD flags);
void D3DXEncodeBC5S(_Out_cap_c_(16) uint8_t *pBC, _In_count_c_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ DWORD flags);
void D3DXEncodeBC6HU(_Out_cap_c_(16) uint8_t *pBC, _In_count_c_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ DWORD flags);
void D3DXEncodeBC6HS(_Out_cap_c_(16) uint8_t *pBC, _In_count_c_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ DWORD flags);
void D3DXEncodeBC7(_Out_cap_c_(16) uint8_t *pBC, _In_count_c_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ DWORD flags);
}; // namespace

534
DirectXTex/BC4BC5.cpp Normal file
View File

@ -0,0 +1,534 @@
//-------------------------------------------------------------------------------------
// BC4BC5.cpp
//
// Block-compression (BC) functionality for BC4 and BC5 (DirectX 10 texture compression)
//
// 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
//-------------------------------------------------------------------------------------
#include "directxtexp.h"
#include "BC.h"
#pragma warning(disable : 4201)
namespace DirectX
{
//------------------------------------------------------------------------------------
// Constants
//------------------------------------------------------------------------------------
// Because these are used in SAL annotations, they need to remain macros rather than const values
#define BLOCK_LEN 4
// length of each block in texel
#define BLOCK_SIZE (BLOCK_LEN * BLOCK_LEN)
// total texels in a 4x4 block.
//------------------------------------------------------------------------------------
// Structures
//-------------------------------------------------------------------------------------
// BC4U/BC5U
struct BC4_UNORM
{
float R(size_t uOffset) const
{
size_t uIndex = GetIndex(uOffset);
return DecodeFromIndex(uIndex);
}
float DecodeFromIndex(size_t uIndex) const
{
if (uIndex == 0)
return red_0 / 255.0f;
if (uIndex == 1)
return red_1 / 255.0f;
float fred_0 = red_0 / 255.0f;
float fred_1 = red_1 / 255.0f;
if (red_0 > red_1)
{
uIndex -= 1;
return (fred_0 * (7-uIndex) + fred_1 * uIndex) / 7.0f;
}
else
{
if (uIndex == 6)
return 0.0f;
if (uIndex == 7)
return 1.0f;
uIndex -= 1;
return (fred_0 * (5-uIndex) + fred_1 * uIndex) / 5.0f;
}
}
size_t GetIndex(size_t uOffset) const
{
return (size_t) ((data >> (3*uOffset + 16)) & 0x07);
}
void SetIndex(size_t uOffset, size_t uIndex)
{
data &= ~((uint64_t) 0x07 << (3*uOffset + 16));
data |= ((uint64_t) uIndex << (3*uOffset + 16));
}
union
{
struct
{
uint8_t red_0;
uint8_t red_1;
uint8_t indices[6];
};
uint64_t data;
};
};
// BC4S/BC5S
struct BC4_SNORM
{
float R(size_t uOffset) const
{
size_t uIndex = GetIndex(uOffset);
return DecodeFromIndex(uIndex);
}
float DecodeFromIndex(size_t uIndex) const
{
int8_t sred_0 = (red_0 == -128)? -127 : red_0;
int8_t sred_1 = (red_1 == -128)? -127 : red_1;
if (uIndex == 0)
return sred_0 / 127.0f;
if (uIndex == 1)
return sred_1 / 127.0f;
float fred_0 = sred_0 / 127.0f;
float fred_1 = sred_1 / 127.0f;
if (red_0 > red_1)
{
uIndex -= 1;
return (fred_0 * (7-uIndex) + fred_1 * uIndex) / 7.0f;
}
else
{
if (uIndex == 6)
return -1.0f;
if (uIndex == 7)
return 1.0f;
uIndex -= 1;
return (fred_0 * (5-uIndex) + fred_1 * uIndex) / 5.0f;
}
}
size_t GetIndex(size_t uOffset) const
{
return (size_t) ((data >> (3*uOffset + 16)) & 0x07);
}
void SetIndex(size_t uOffset, size_t uIndex)
{
data &= ~((uint64_t) 0x07 << (3*uOffset + 16));
data |= ((uint64_t) uIndex << (3*uOffset + 16));
}
union
{
struct
{
int8_t red_0;
int8_t red_1;
uint8_t indices[6];
};
uint64_t data;
};
};
//-------------------------------------------------------------------------------------
// Convert a floating point value to an 8-bit SNORM
//-------------------------------------------------------------------------------------
static void inline FloatToSNorm( _In_ float fVal, _Out_ int8_t *piSNorm )
{
const uint32_t dwMostNeg = ( 1 << ( 8 * sizeof( int8_t ) - 1 ) );
if( _isnan( fVal ) )
fVal = 0;
else
if( fVal > 1 )
fVal = 1; // Clamp to 1
else
if( fVal < -1 )
fVal = -1; // Clamp to -1
fVal = fVal * (int8_t) ( dwMostNeg - 1 );
if( fVal >= 0 )
fVal += .5f;
else
fVal -= .5f;
*piSNorm = (int8_t) (fVal);
}
//------------------------------------------------------------------------------
static void FindEndPointsBC4U( _In_count_c_(BLOCK_SIZE) const float theTexelsU[], _Out_ uint8_t &endpointU_0, _Out_ uint8_t &endpointU_1)
{
// The boundary of codec for signed/unsigned format
float MIN_NORM;
float MAX_NORM = 1.0f;
int8_t iStart, iEnd;
size_t i;
MIN_NORM = 0.0f;
// Find max/min of input texels
float fBlockMax = theTexelsU[0];
float fBlockMin = theTexelsU[0];
for (i = 0; i < BLOCK_SIZE; ++i)
{
if (theTexelsU[i]<fBlockMin)
{
fBlockMin = theTexelsU[i];
}
else if (theTexelsU[i]>fBlockMax)
{
fBlockMax = theTexelsU[i];
}
}
// If there are boundary values in input texels, Should use 4 block-codec to guarantee
// the exact code of the boundary values.
bool bUsing4BlockCodec = ( MIN_NORM == fBlockMin || MAX_NORM == fBlockMax );
// Using Optimize
float fStart, fEnd;
if (!bUsing4BlockCodec)
{
OptimizeAlpha<false>(&fStart, &fEnd, theTexelsU, 8);
iStart = (uint8_t) (fStart * 255.0f);
iEnd = (uint8_t) (fEnd * 255.0f);
endpointU_0 = iEnd;
endpointU_1 = iStart;
}
else
{
OptimizeAlpha<false>(&fStart, &fEnd, theTexelsU, 6);
iStart = (uint8_t) (fStart * 255.0f);
iEnd = (uint8_t) (fEnd * 255.0f);
endpointU_1 = iEnd;
endpointU_0 = iStart;
}
}
static void FindEndPointsBC4S(_In_count_c_(BLOCK_SIZE) const float theTexelsU[], _Out_ int8_t &endpointU_0, _Out_ int8_t &endpointU_1)
{
// The boundary of codec for signed/unsigned format
float MIN_NORM;
float MAX_NORM = 1.0f;
int8_t iStart, iEnd;
size_t i;
MIN_NORM = -1.0f;
// Find max/min of input texels
float fBlockMax = theTexelsU[0];
float fBlockMin = theTexelsU[0];
for (i = 0; i < BLOCK_SIZE; ++i)
{
if (theTexelsU[i]<fBlockMin)
{
fBlockMin = theTexelsU[i];
}
else if (theTexelsU[i]>fBlockMax)
{
fBlockMax = theTexelsU[i];
}
}
// If there are boundary values in input texels, Should use 4 block-codec to guarantee
// the exact code of the boundary values.
bool bUsing4BlockCodec = ( MIN_NORM == fBlockMin || MAX_NORM == fBlockMax );
// Using Optimize
float fStart, fEnd;
if (!bUsing4BlockCodec)
{
OptimizeAlpha<true>(&fStart, &fEnd, theTexelsU, 8);
FloatToSNorm(fStart, &iStart);
FloatToSNorm(fEnd, &iEnd);
endpointU_0 = iEnd;
endpointU_1 = iStart;
}
else
{
OptimizeAlpha<true>(&fStart, &fEnd, theTexelsU, 6);
FloatToSNorm(fStart, &iStart);
FloatToSNorm(fEnd, &iEnd);
endpointU_1 = iEnd;
endpointU_0 = iStart;
}
}
//------------------------------------------------------------------------------
static inline void FindEndPointsBC5U( _In_count_c_(BLOCK_SIZE) const float theTexelsU[], _In_count_c_(BLOCK_SIZE) const float theTexelsV[],
_Out_ uint8_t &endpointU_0, _Out_ uint8_t &endpointU_1, _Out_ uint8_t &endpointV_0, _Out_ uint8_t &endpointV_1)
{
//Encoding the U and V channel by BC4 codec separately.
FindEndPointsBC4U( theTexelsU, endpointU_0, endpointU_1);
FindEndPointsBC4U( theTexelsV, endpointV_0, endpointV_1);
}
static inline void FindEndPointsBC5S( _In_count_c_(BLOCK_SIZE) const float theTexelsU[], _In_count_c_(BLOCK_SIZE) const float theTexelsV[],
_Out_ int8_t &endpointU_0, _Out_ int8_t &endpointU_1, _Out_ int8_t &endpointV_0, _Out_ int8_t &endpointV_1)
{
//Encoding the U and V channel by BC4 codec separately.
FindEndPointsBC4S( theTexelsU, endpointU_0, endpointU_1);
FindEndPointsBC4S( theTexelsV, endpointV_0, endpointV_1);
}
//------------------------------------------------------------------------------
static void FindClosestUNORM(_Inout_ BC4_UNORM* pBC, _In_count_c_(NUM_PIXELS_PER_BLOCK) const float theTexelsU[])
{
float rGradient[8];
int i;
for (i = 0; i < 8; ++i)
{
rGradient[i] = pBC->DecodeFromIndex(i);
}
for (i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
{
size_t uBestIndex = 0;
float fBestDelta = 100000;
for (size_t uIndex = 0; uIndex < 8; uIndex++)
{
float fCurrentDelta = fabsf(rGradient[uIndex]-theTexelsU[i]);
if (fCurrentDelta < fBestDelta)
{
uBestIndex = uIndex;
fBestDelta = fCurrentDelta;
}
}
pBC->SetIndex(i, uBestIndex);
}
}
static void FindClosestSNORM(_Inout_ BC4_SNORM* pBC, _In_count_c_(NUM_PIXELS_PER_BLOCK) const float theTexelsU[])
{
float rGradient[8];
int i;
for (i = 0; i < 8; ++i)
{
rGradient[i] = pBC->DecodeFromIndex(i);
}
for (i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
{
size_t uBestIndex = 0;
float fBestDelta = 100000;
for (size_t uIndex = 0; uIndex < 8; uIndex++)
{
float fCurrentDelta = fabsf(rGradient[uIndex]-theTexelsU[i]);
if (fCurrentDelta < fBestDelta)
{
uBestIndex = uIndex;
fBestDelta = fCurrentDelta;
}
}
pBC->SetIndex(i, uBestIndex);
}
}
//=====================================================================================
// Entry points
//=====================================================================================
//-------------------------------------------------------------------------------------
// BC4 Compression
//-------------------------------------------------------------------------------------
void D3DXDecodeBC4U( XMVECTOR *pColor, const uint8_t *pBC )
{
assert( pColor && pBC );
static_assert( sizeof(BC4_UNORM) == 8, "BC4_UNORM should be 8 bytes" );
const BC4_UNORM * pBC4 = reinterpret_cast<const BC4_UNORM*>(pBC);
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
{
pColor[i] = XMVectorSet( pBC4->R(i), 0, 0, 1.0f);
}
}
void D3DXDecodeBC4S(XMVECTOR *pColor, const uint8_t *pBC)
{
assert( pColor && pBC );
static_assert( sizeof(BC4_SNORM) == 8, "BC4_SNORM should be 8 bytes" );
const BC4_SNORM * pBC4 = reinterpret_cast<const BC4_SNORM*>(pBC);
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
{
pColor[i] = XMVectorSet( pBC4->R(i), 0, 0, 1.0f);
}
}
void D3DXEncodeBC4U( uint8_t *pBC, const XMVECTOR *pColor, DWORD flags )
{
UNREFERENCED_PARAMETER( flags );
assert( pBC && pColor );
static_assert( sizeof(BC4_UNORM) == 8, "BC4_UNORM should be 8 bytes" );
memset(pBC, 0, sizeof(BC4_UNORM));
BC4_UNORM * pBC4 = reinterpret_cast<BC4_UNORM*>(pBC);
float theTexelsU[NUM_PIXELS_PER_BLOCK];
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
{
theTexelsU[i] = XMVectorGetX( pColor[i] );
}
FindEndPointsBC4U(theTexelsU, pBC4->red_0, pBC4->red_1);
FindClosestUNORM(pBC4, theTexelsU);
}
void D3DXEncodeBC4S( uint8_t *pBC, const XMVECTOR *pColor, DWORD flags )
{
UNREFERENCED_PARAMETER( flags );
assert( pBC && pColor );
static_assert( sizeof(BC4_SNORM) == 8, "BC4_SNORM should be 8 bytes" );
memset(pBC, 0, sizeof(BC4_UNORM));
BC4_SNORM * pBC4 = reinterpret_cast<BC4_SNORM*>(pBC);
float theTexelsU[NUM_PIXELS_PER_BLOCK];
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
{
theTexelsU[i] = XMVectorGetX( pColor[i] );
}
FindEndPointsBC4S(theTexelsU, pBC4->red_0, pBC4->red_1);
FindClosestSNORM(pBC4, theTexelsU);
}
//-------------------------------------------------------------------------------------
// BC5 Compression
//-------------------------------------------------------------------------------------
void D3DXDecodeBC5U(XMVECTOR *pColor, const uint8_t *pBC)
{
assert( pColor && pBC );
static_assert( sizeof(BC4_UNORM) == 8, "BC4_UNORM should be 8 bytes" );
const BC4_UNORM * pBCR = reinterpret_cast<const BC4_UNORM*>(pBC);
const BC4_UNORM * pBCG = reinterpret_cast<const BC4_UNORM*>(pBC+sizeof(BC4_UNORM));
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
{
pColor[i] = XMVectorSet(pBCR->R(i), pBCG->R(i), 0, 1.0f);
}
}
void D3DXDecodeBC5S(XMVECTOR *pColor, const uint8_t *pBC)
{
assert( pColor && pBC );
static_assert( sizeof(BC4_SNORM) == 8, "BC4_SNORM should be 8 bytes" );
const BC4_SNORM * pBCR = reinterpret_cast<const BC4_SNORM*>(pBC);
const BC4_SNORM * pBCG = reinterpret_cast<const BC4_SNORM*>(pBC+sizeof(BC4_SNORM));
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
{
pColor[i] = XMVectorSet(pBCR->R(i), pBCG->R(i), 0, 1.0f);
}
}
void D3DXEncodeBC5U( uint8_t *pBC, const XMVECTOR *pColor, DWORD flags )
{
UNREFERENCED_PARAMETER( flags );
assert( pBC && pColor );
static_assert( sizeof(BC4_UNORM) == 8, "BC4_UNORM should be 8 bytes" );
memset(pBC, 0, sizeof(BC4_UNORM)*2);
BC4_UNORM * pBCR = reinterpret_cast<BC4_UNORM*>(pBC);
BC4_UNORM * pBCG = reinterpret_cast<BC4_UNORM*>(pBC+sizeof(BC4_UNORM));
float theTexelsU[NUM_PIXELS_PER_BLOCK];
float theTexelsV[NUM_PIXELS_PER_BLOCK];
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
{
XMFLOAT4A clr;
XMStoreFloat4A( &clr, pColor[i] );
theTexelsU[i] = clr.x;
theTexelsV[i] = clr.y;
}
FindEndPointsBC5U(
theTexelsU,
theTexelsV,
pBCR->red_0,
pBCR->red_1,
pBCG->red_0,
pBCG->red_1);
FindClosestUNORM(pBCR, theTexelsU);
FindClosestUNORM(pBCG, theTexelsV);
}
void D3DXEncodeBC5S( uint8_t *pBC, const XMVECTOR *pColor, DWORD flags )
{
UNREFERENCED_PARAMETER( flags );
assert( pBC && pColor );
static_assert( sizeof(BC4_SNORM) == 8, "BC4_SNORM should be 8 bytes" );
memset(pBC, 0, sizeof(BC4_UNORM)*2);
BC4_SNORM * pBCR = reinterpret_cast<BC4_SNORM*>(pBC);
BC4_SNORM * pBCG = reinterpret_cast<BC4_SNORM*>(pBC+sizeof(BC4_SNORM));
float theTexelsU[NUM_PIXELS_PER_BLOCK];
float theTexelsV[NUM_PIXELS_PER_BLOCK];
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
{
XMFLOAT4A clr;
XMStoreFloat4A( &clr, pColor[i] );
theTexelsU[i] = clr.x;
theTexelsV[i] = clr.y;
}
FindEndPointsBC5S(
theTexelsU,
theTexelsV,
pBCR->red_0,
pBCR->red_1,
pBCG->red_0,
pBCG->red_1);
FindClosestSNORM(pBCR, theTexelsU);
FindClosestSNORM(pBCG, theTexelsV);
}
} // namespace

2819
DirectXTex/BC6HBC7.cpp Normal file

File diff suppressed because it is too large Load Diff

214
DirectXTex/DDS.h Normal file
View File

@ -0,0 +1,214 @@
//--------------------------------------------------------------------------------------
// dds.h
//
// This header defines constants and structures that are useful when parsing
// DDS files. DDS files were originally designed to use several structures
// and constants that are native to DirectDraw and are defined in ddraw.h,
// such as DDSURFACEDESC2 and DDSCAPS2. This file defines similar
// (compatible) constants and structures so that one can use DDS files
// without needing to include ddraw.h.
//
// 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
#include <dxgiformat.h>
#pragma warning(push)
#pragma warning(disable : 4005)
#include <stdint.h>
#pragma warning(pop)
namespace DirectX
{
#pragma pack(push,1)
const uint32_t DDS_MAGIC = 0x20534444; // "DDS "
struct DDS_PIXELFORMAT
{
uint32_t dwSize;
uint32_t dwFlags;
uint32_t dwFourCC;
uint32_t dwRGBBitCount;
uint32_t dwRBitMask;
uint32_t dwGBitMask;
uint32_t dwBBitMask;
uint32_t dwABitMask;
};
#define DDS_FOURCC 0x00000004 // DDPF_FOURCC
#define DDS_RGB 0x00000040 // DDPF_RGB
#define DDS_RGBA 0x00000041 // DDPF_RGB | DDPF_ALPHAPIXELS
#define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE
#define DDS_LUMINANCEA 0x00020001 // DDPF_LUMINANCE | DDPF_ALPHAPIXELS
#define DDS_ALPHA 0x00000002 // DDPF_ALPHA
#define DDS_PAL8 0x00000020 // DDPF_PALETTEINDEXED8
#ifndef MAKEFOURCC
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
((uint32_t)(uint8_t)(ch0) | ((uint32_t)(uint8_t)(ch1) << 8) | \
((uint32_t)(uint8_t)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 ))
#endif /* defined(MAKEFOURCC) */
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_DXT1 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_DXT2 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','2'), 0, 0, 0, 0, 0 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_DXT3 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','3'), 0, 0, 0, 0, 0 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_DXT4 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','4'), 0, 0, 0, 0, 0 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_DXT5 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','5'), 0, 0, 0, 0, 0 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_BC4_UNORM =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B','C','4','U'), 0, 0, 0, 0, 0 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_BC4_SNORM =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B','C','4','S'), 0, 0, 0, 0, 0 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_BC5_UNORM =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B','C','5','U'), 0, 0, 0, 0, 0 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_BC5_SNORM =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B','C','5','S'), 0, 0, 0, 0, 0 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_R8G8_B8G8 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('R','G','B','G'), 0, 0, 0, 0, 0 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_G8R8_G8B8 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('G','R','G','B'), 0, 0, 0, 0, 0 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_A8R8G8B8 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_X8R8G8B8 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_A8B8G8R8 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_X8B8G8R8 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_G16R16 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_R5G6B5 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 16, 0x0000f800, 0x000007e0, 0x0000001f, 0x00000000 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_A1R5G5B5 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x00007c00, 0x000003e0, 0x0000001f, 0x00008000 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_A4R4G4B4 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x00000f00, 0x000000f0, 0x0000000f, 0x0000f000 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_R8G8B8 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_L8 =
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 8, 0xff, 0x00, 0x00, 0x00 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_L16 =
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 16, 0xffff, 0x0000, 0x0000, 0x0000 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_A8L8 =
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCEA, 0, 16, 0x00ff, 0x0000, 0x0000, 0xff00 };
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_A8 =
{ sizeof(DDS_PIXELFORMAT), DDS_ALPHA, 0, 8, 0x00, 0x00, 0x00, 0xff };
// D3DFMT_A2R10G10B10/D3DFMT_A2B10G10R10 should be written using DX10 extension to avoid D3DX 10:10:10:2 reversal issue
// This indicates the DDS_HEADER_DXT10 extension is present (the format is in dxgiFormat)
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_DX10 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','1','0'), 0, 0, 0, 0, 0 };
#define DDS_HEADER_FLAGS_TEXTURE 0x00001007 // DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT
#define DDS_HEADER_FLAGS_MIPMAP 0x00020000 // DDSD_MIPMAPCOUNT
#define DDS_HEADER_FLAGS_VOLUME 0x00800000 // DDSD_DEPTH
#define DDS_HEADER_FLAGS_PITCH 0x00000008 // DDSD_PITCH
#define DDS_HEADER_FLAGS_LINEARSIZE 0x00080000 // DDSD_LINEARSIZE
#define DDS_HEIGHT 0x00000002 // DDSD_HEIGHT
#define DDS_WIDTH 0x00000004 // DDSD_WIDTH
#define DDS_SURFACE_FLAGS_TEXTURE 0x00001000 // DDSCAPS_TEXTURE
#define DDS_SURFACE_FLAGS_MIPMAP 0x00400008 // DDSCAPS_COMPLEX | DDSCAPS_MIPMAP
#define DDS_SURFACE_FLAGS_CUBEMAP 0x00000008 // DDSCAPS_COMPLEX
#define DDS_CUBEMAP_POSITIVEX 0x00000600 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEX
#define DDS_CUBEMAP_NEGATIVEX 0x00000a00 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX
#define DDS_CUBEMAP_POSITIVEY 0x00001200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEY
#define DDS_CUBEMAP_NEGATIVEY 0x00002200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEY
#define DDS_CUBEMAP_POSITIVEZ 0x00004200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEZ
#define DDS_CUBEMAP_NEGATIVEZ 0x00008200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEZ
#define DDS_CUBEMAP_ALLFACES ( DDS_CUBEMAP_POSITIVEX | DDS_CUBEMAP_NEGATIVEX |\
DDS_CUBEMAP_POSITIVEY | DDS_CUBEMAP_NEGATIVEY |\
DDS_CUBEMAP_POSITIVEZ | DDS_CUBEMAP_NEGATIVEZ )
#define DDS_CUBEMAP 0x00000200 // DDSCAPS2_CUBEMAP
#define DDS_FLAGS_VOLUME 0x00200000 // DDSCAPS2_VOLUME
// Subset here matches D3D10_RESOURCE_DIMENSION and D3D11_RESOURCE_DIMENSION
typedef enum DDS_RESOURCE_DIMENSION
{
DDS_DIMENSION_TEXTURE1D = 2,
DDS_DIMENSION_TEXTURE2D = 3,
DDS_DIMENSION_TEXTURE3D = 4,
} DDS_RESOURCE_DIMENSION;
// Subset here matches D3D10_RESOURCE_MISC_FLAG and D3D11_RESOURCE_MISC_FLAG
typedef enum DDS_RESOURCE_MISC_FLAG
{
DDS_RESOURCE_MISC_TEXTURECUBE = 0x4L,
} DDS_RESOURCE_MISC_FLAG;
typedef struct
{
uint32_t dwSize;
uint32_t dwFlags;
uint32_t dwHeight;
uint32_t dwWidth;
uint32_t dwPitchOrLinearSize;
uint32_t dwDepth; // only if DDS_HEADER_FLAGS_VOLUME is set in dwFlags
uint32_t dwMipMapCount;
uint32_t dwReserved1[11];
DDS_PIXELFORMAT ddspf;
uint32_t dwCaps;
uint32_t dwCaps2;
uint32_t dwCaps3;
uint32_t dwCaps4;
uint32_t dwReserved2;
} DDS_HEADER;
typedef struct
{
DXGI_FORMAT dxgiFormat;
uint32_t resourceDimension;
uint32_t miscFlag; // see DDS_RESOURCE_MISC_FLAG
uint32_t arraySize;
uint32_t reserved;
} DDS_HEADER_DXT10;
#pragma pack(pop)
}; // namespace

458
DirectXTex/DirectXTex.h Normal file
View File

@ -0,0 +1,458 @@
//-------------------------------------------------------------------------------------
// 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>
#include <dxgiformat.h>
#include <d3d11.h>
#define DIRECTX_TEX_VERSION 100
namespace DirectX
{
//---------------------------------------------------------------------------------
// 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 );
bool IsTypeless( _In_ DXGI_FORMAT fmt );
size_t BitsPerPixel( _In_ DXGI_FORMAT fmt );
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 );
//---------------------------------------------------------------------------------
// Texture metadata
enum TEX_DIMENSION
// Subset here matches D3D10_RESOURCE_DIMENSION and D3D11_RESOURCE_DIMENSION
{
TEX_DIMENSION_TEXTURE1D = 2,
TEX_DIMENSION_TEXTURE2D = 3,
TEX_DIMENSION_TEXTURE3D = 4,
};
enum TEX_MISC_FLAG
// Subset here matches D3D10_RESOURCE_MISC_FLAG and D3D11_RESOURCE_MISC_FLAG
{
TEX_MISC_TEXTURECUBE = 0x4L,
};
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;
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
};
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
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)
};
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,
// Loads 1-bit monochrome (black & white) as R1_UNORM rather than 8-bit greyscale
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)
};
HRESULT GetMetadataFromDDSMemory( _In_bytecount_(size) LPCVOID pSource, _In_ size_t size, _In_ DWORD flags,
_Out_ TexMetadata& metadata );
HRESULT GetMetadataFromDDSFile( _In_z_ LPCWSTR szFile, DWORD flags,
_Out_ TexMetadata& metadata );
HRESULT GetMetadataFromTGAMemory( _In_bytecount_(size) LPCVOID pSource, _In_ size_t size,
_Out_ TexMetadata& metadata );
HRESULT GetMetadataFromTGAFile( _In_z_ LPCWSTR szFile,
_Out_ TexMetadata& metadata );
HRESULT GetMetadataFromWICMemory( _In_bytecount_(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 );
//---------------------------------------------------------------------------------
// 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 );
HRESULT InitializeArrayFromImages( _In_count_(nImages) const Image* images, _In_ size_t nImages, _In_ bool allow1D = false );
HRESULT InitializeCubeFromImages( _In_count_(nImages) const Image* images, _In_ size_t nImages );
HRESULT Initialize3DFromImages( _In_count_(depth) const Image* images, _In_ size_t depth );
void Release();
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; }
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
HRESULT LoadFromDDSMemory( _In_bytecount_(size) LPCVOID pSource, _In_ size_t size, _In_ DWORD flags,
_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 );
HRESULT SaveToDDSMemory( _In_count_(nimages) const Image* images, _In_ size_t nimages, _In_ const TexMetadata& metadata, _In_ DWORD flags,
_Out_ Blob& blob );
HRESULT SaveToDDSFile( _In_ const Image& image, _In_ DWORD flags, _In_z_ LPCWSTR szFile );
HRESULT SaveToDDSFile( _In_count_(nimages) const Image* images, _In_ size_t nimages, _In_ const TexMetadata& metadata, _In_ DWORD flags, _In_z_ LPCWSTR szFile );
// TGA operations
HRESULT LoadFromTGAMemory( _In_bytecount_(size) LPCVOID pSource, _In_ size_t size,
_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
HRESULT LoadFromWICMemory( _In_bytecount_(size) LPCVOID pSource, _In_ size_t size, _In_ DWORD flags,
_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,
_Out_ Blob& blob );
HRESULT SaveToWICMemory( _In_count_(nimages) const Image* images, _In_ size_t nimages, _In_ DWORD flags, _In_ REFGUID guidContainerFormat, _Out_ Blob& blob );
HRESULT SaveToWICFile( _In_ const Image& image, _In_ DWORD flags, _In_ REFGUID guidContainerFormat, _In_z_ LPCWSTR szFile );
HRESULT SaveToWICFile( _In_count_(nimages) const Image* images, _In_ size_t nimages, _In_ DWORD flags, _In_ REFGUID guidContainerFormat, _In_z_ LPCWSTR szFile );
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 );
HRESULT FlipRotate( _In_count_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DWORD flags, _Out_ ScratchImage& result );
// Flip and/or rotate image
enum TEX_FILTER_FLAGS
{
TEX_FILTER_DEFAULT = 0,
// Clamp filtering only
TEX_FILTER_SEPARATE_ALPHA = 0x100,
// Resize color and alpha channel independently
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,
TEX_FILTER_FANT = 0x400000, // Equiv to Box filtering for mipmap generation
// Filtering mode to use for any required image resizing
TEX_FILTER_SRGB_IN = 0x1000000,
TEX_FILTER_SRGB_OUT = 0x2000000,
TEX_FILTER_SRGB = 0x3000000,
// 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
};
HRESULT Resize( _In_ const Image& srcImage, _In_ size_t width, _In_ size_t height, _In_ DWORD filter,
_Out_ ScratchImage& image );
HRESULT Resize( _In_count_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_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 );
HRESULT Convert( _In_count_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_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,
_Out_ ScratchImage& mipChain, bool allow1D = false );
HRESULT GenerateMipMaps( _In_count_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_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
HRESULT GenerateMipMaps3D( _In_count_(depth) const Image* baseImages, _In_ size_t depth, _In_ DWORD filter, _In_ size_t levels,
_Out_ ScratchImage& mipChain );
HRESULT GenerateMipMaps3D( _In_count_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_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
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 );
HRESULT Compress( _In_count_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_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 );
HRESULT Decompress( _In_count_(nimages) const Image* cImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_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 );
HRESULT ComputeNormalMap( _In_count_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_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 );
HRESULT ComputeMSE( _In_ const Image& image1, _In_ const Image& image2, _Out_ float& mse, _Out_opt_cap_c_(4) float* mseV );
//---------------------------------------------------------------------------------
// Direct3D 11 functions
bool IsSupportedTexture( _In_ ID3D11Device* pDevice, _In_ const TexMetadata& metadata );
HRESULT CreateTexture( _In_ ID3D11Device* pDevice, _In_count_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_Deref_out_ ID3D11Resource** ppResource );
HRESULT CreateShaderResourceView( _In_ ID3D11Device* pDevice, _In_count_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_Deref_out_ ID3D11ShaderResourceView** ppSRV );
HRESULT CaptureTexture( _In_ ID3D11Device* pDevice, _In_ ID3D11DeviceContext* pContext, _In_ ID3D11Resource* pSource, _Out_ ScratchImage& result );
#include "DirectXTex.inl"
}; // namespace

223
DirectXTex/DirectXTex.inl Normal file
View File

@ -0,0 +1,223 @@
//-------------------------------------------------------------------------------------
// DirectXTex.inl
//
// 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
//=====================================================================================
// DXGI Format Utilities
//=====================================================================================
inline bool IsValid( DXGI_FORMAT fmt )
{
#ifdef DXGI_1_2_FORMATS
return ( static_cast<size_t>(fmt) >= 1 && static_cast<size_t>(fmt) <= 115 );
#else
return ( static_cast<size_t>(fmt) >= 1 && static_cast<size_t>(fmt) <= 99 );
#endif
}
inline bool IsCompressed( DXGI_FORMAT fmt )
{
switch ( fmt )
{
case DXGI_FORMAT_BC1_TYPELESS:
case DXGI_FORMAT_BC1_UNORM:
case DXGI_FORMAT_BC1_UNORM_SRGB:
case DXGI_FORMAT_BC2_TYPELESS:
case DXGI_FORMAT_BC2_UNORM:
case DXGI_FORMAT_BC2_UNORM_SRGB:
case DXGI_FORMAT_BC3_TYPELESS:
case DXGI_FORMAT_BC3_UNORM:
case DXGI_FORMAT_BC3_UNORM_SRGB:
case DXGI_FORMAT_BC4_TYPELESS:
case DXGI_FORMAT_BC4_UNORM:
case DXGI_FORMAT_BC4_SNORM:
case DXGI_FORMAT_BC5_TYPELESS:
case DXGI_FORMAT_BC5_UNORM:
case DXGI_FORMAT_BC5_SNORM:
case DXGI_FORMAT_BC6H_TYPELESS:
case DXGI_FORMAT_BC6H_UF16:
case DXGI_FORMAT_BC6H_SF16:
case DXGI_FORMAT_BC7_TYPELESS:
case DXGI_FORMAT_BC7_UNORM:
case DXGI_FORMAT_BC7_UNORM_SRGB:
return true;
default:
return false;
}
}
inline bool IsPacked( DXGI_FORMAT fmt )
{
return ( (fmt == DXGI_FORMAT_R8G8_B8G8_UNORM) || (fmt == DXGI_FORMAT_G8R8_G8B8_UNORM) );
}
inline bool IsVideo( DXGI_FORMAT fmt )
{
#ifdef DXGI_1_2_FORMATS
switch ( fmt )
{
case DXGI_FORMAT_AYUV:
case DXGI_FORMAT_Y410:
case DXGI_FORMAT_Y416:
case DXGI_FORMAT_NV12:
case DXGI_FORMAT_P010:
case DXGI_FORMAT_P016:
case DXGI_FORMAT_YUY2:
case DXGI_FORMAT_Y210:
case DXGI_FORMAT_Y216:
case DXGI_FORMAT_NV11:
// These video formats can be used with the 3D pipeline through special view mappings
return true;
case DXGI_FORMAT_420_OPAQUE:
case DXGI_FORMAT_AI44:
case DXGI_FORMAT_IA44:
case DXGI_FORMAT_P8:
case DXGI_FORMAT_A8P8:
// These are limited use video formats not usable in any way by the 3D pipeline
return true;
default:
return false;
}
#else // !DXGI_1_2_FORMATS
UNREFERENCED_PARAMETER(fmt);
return false;
#endif
}
inline bool IsSRGB( DXGI_FORMAT fmt )
{
switch( fmt )
{
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
case DXGI_FORMAT_BC1_UNORM_SRGB:
case DXGI_FORMAT_BC2_UNORM_SRGB:
case DXGI_FORMAT_BC3_UNORM_SRGB:
case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
case DXGI_FORMAT_BC7_UNORM_SRGB:
return true;
default:
return false;
}
}
inline bool IsTypeless( DXGI_FORMAT fmt )
{
switch( fmt )
{
case DXGI_FORMAT_R32G32B32A32_TYPELESS:
case DXGI_FORMAT_R32G32B32_TYPELESS:
case DXGI_FORMAT_R16G16B16A16_TYPELESS:
case DXGI_FORMAT_R32G32_TYPELESS:
case DXGI_FORMAT_R32G8X24_TYPELESS:
case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS:
case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT:
case DXGI_FORMAT_R10G10B10A2_TYPELESS:
case DXGI_FORMAT_R8G8B8A8_TYPELESS:
case DXGI_FORMAT_R16G16_TYPELESS:
case DXGI_FORMAT_R32_TYPELESS:
case DXGI_FORMAT_R24G8_TYPELESS:
case DXGI_FORMAT_R24_UNORM_X8_TYPELESS:
case DXGI_FORMAT_X24_TYPELESS_G8_UINT:
case DXGI_FORMAT_R8G8_TYPELESS:
case DXGI_FORMAT_R16_TYPELESS:
case DXGI_FORMAT_R8_TYPELESS:
case DXGI_FORMAT_BC1_TYPELESS:
case DXGI_FORMAT_BC2_TYPELESS:
case DXGI_FORMAT_BC3_TYPELESS:
case DXGI_FORMAT_BC4_TYPELESS:
case DXGI_FORMAT_BC5_TYPELESS:
case DXGI_FORMAT_B8G8R8A8_TYPELESS:
case DXGI_FORMAT_B8G8R8X8_TYPELESS:
case DXGI_FORMAT_BC6H_TYPELESS:
case DXGI_FORMAT_BC7_TYPELESS:
return true;
default:
return false;
}
}
inline size_t ComputeScanlines( _In_ DXGI_FORMAT fmt, _In_ size_t height )
{
switch ( fmt )
{
case DXGI_FORMAT_BC1_TYPELESS:
case DXGI_FORMAT_BC1_UNORM:
case DXGI_FORMAT_BC1_UNORM_SRGB:
case DXGI_FORMAT_BC2_TYPELESS:
case DXGI_FORMAT_BC2_UNORM:
case DXGI_FORMAT_BC2_UNORM_SRGB:
case DXGI_FORMAT_BC3_TYPELESS:
case DXGI_FORMAT_BC3_UNORM:
case DXGI_FORMAT_BC3_UNORM_SRGB:
case DXGI_FORMAT_BC4_TYPELESS:
case DXGI_FORMAT_BC4_UNORM:
case DXGI_FORMAT_BC4_SNORM:
case DXGI_FORMAT_BC5_TYPELESS:
case DXGI_FORMAT_BC5_UNORM:
case DXGI_FORMAT_BC5_SNORM:
case DXGI_FORMAT_BC6H_TYPELESS:
case DXGI_FORMAT_BC6H_UF16:
case DXGI_FORMAT_BC6H_SF16:
case DXGI_FORMAT_BC7_TYPELESS:
case DXGI_FORMAT_BC7_UNORM:
case DXGI_FORMAT_BC7_UNORM_SRGB:
return std::max<size_t>( 1, (height + 3) / 4 );
default:
return height;
}
}
//=====================================================================================
// Image I/O
//=====================================================================================
inline HRESULT SaveToDDSMemory( const Image& image, DWORD flags, Blob& blob )
{
TexMetadata mdata;
memset( &mdata, 0, sizeof(mdata) );
mdata.width = image.width;
mdata.height = image.height;
mdata.depth = 1;
mdata.arraySize = 1;
mdata.mipLevels = 1;
mdata.format = image.format;
mdata.dimension = TEX_DIMENSION_TEXTURE2D;
return SaveToDDSMemory( &image, 1, mdata, flags, blob );
}
inline HRESULT SaveToDDSFile( const Image& image, DWORD flags, LPCWSTR szFile )
{
TexMetadata mdata;
memset( &mdata, 0, sizeof(mdata) );
mdata.width = image.width;
mdata.height = image.height;
mdata.depth = 1;
mdata.arraySize = 1;
mdata.mipLevels = 1;
mdata.format = image.format;
mdata.dimension = TEX_DIMENSION_TEXTURE2D;
return SaveToDDSFile( &image, 1, mdata, flags, szFile );
}

View File

@ -0,0 +1,697 @@
//-------------------------------------------------------------------------------------
// DirectXTexCompress.cpp
//
// DirectX Texture Library - Texture compression
//
// 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
//-------------------------------------------------------------------------------------
#include "directxtexp.h"
#ifdef _OPENMP
#include <omp.h>
#pragma warning(disable : 4616 6001 6993)
#endif
#include "bc.h"
namespace DirectX
{
inline static DWORD _GetBCFlags( _In_ DWORD compress )
{
static_assert( TEX_COMPRESS_RGB_DITHER == BC_FLAGS_DITHER_RGB, "TEX_COMPRESS_* flags should match BC_FLAGS_*" );
static_assert( TEX_COMPRESS_A_DITHER == BC_FLAGS_DITHER_A, "TEX_COMPRESS_* flags should match BC_FLAGS_*" );
static_assert( TEX_COMPRESS_DITHER == (BC_FLAGS_DITHER_RGB | BC_FLAGS_DITHER_A), "TEX_COMPRESS_* flags should match BC_FLAGS_*" );
static_assert( TEX_COMPRESS_UNIFORM == BC_FLAGS_UNIFORM, "TEX_COMPRESS_* flags should match BC_FLAGS_*" );
return ( compress & (BC_FLAGS_DITHER_RGB|BC_FLAGS_DITHER_A|BC_FLAGS_UNIFORM) );
}
//-------------------------------------------------------------------------------------
static HRESULT _CompressBC( _In_ const Image& image, _In_ const Image& result, _In_ DWORD bcflags,
_In_ float alphaRef, _In_ bool degenerate )
{
if ( !image.pixels || !result.pixels )
return E_POINTER;
assert( image.width == result.width );
assert( image.height == result.height );
const DXGI_FORMAT format = image.format;
size_t sbpp = BitsPerPixel( format );
if ( !sbpp )
return E_FAIL;
if ( sbpp < 8 )
{
// We don't support compressing from monochrome (DXGI_FORMAT_R1_UNORM)
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
}
// Round to bytes
sbpp = ( sbpp + 7 ) / 8;
uint8_t *pDest = result.pixels;
// Determine BC format encoder
BC_ENCODE pfEncode;
size_t blocksize;
switch(result.format)
{
case DXGI_FORMAT_BC1_UNORM:
case DXGI_FORMAT_BC1_UNORM_SRGB: pfEncode = nullptr; blocksize = 8; break;
case DXGI_FORMAT_BC2_UNORM:
case DXGI_FORMAT_BC2_UNORM_SRGB: pfEncode = D3DXEncodeBC2; blocksize = 16; break;
case DXGI_FORMAT_BC3_UNORM:
case DXGI_FORMAT_BC3_UNORM_SRGB: pfEncode = D3DXEncodeBC3; blocksize = 16; break;
case DXGI_FORMAT_BC4_UNORM: pfEncode = D3DXEncodeBC4U; blocksize = 8; break;
case DXGI_FORMAT_BC4_SNORM: pfEncode = D3DXEncodeBC4S; blocksize = 8; break;
case DXGI_FORMAT_BC5_UNORM: pfEncode = D3DXEncodeBC5U; blocksize = 16; break;
case DXGI_FORMAT_BC5_SNORM: pfEncode = D3DXEncodeBC5S; blocksize = 16; break;
case DXGI_FORMAT_BC6H_UF16: pfEncode = D3DXEncodeBC6HU; blocksize = 16; break;
case DXGI_FORMAT_BC6H_SF16: pfEncode = D3DXEncodeBC6HS; blocksize = 16; break;
case DXGI_FORMAT_BC7_UNORM:
case DXGI_FORMAT_BC7_UNORM_SRGB: pfEncode = D3DXEncodeBC7; blocksize = 16; break;
default:
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
}
XMVECTOR temp[16];
const uint8_t *pSrc = image.pixels;
const size_t rowPitch = image.rowPitch;
for( size_t h=0; h < image.height; h += 4 )
{
const uint8_t *sptr = pSrc;
uint8_t* dptr = pDest;
for( size_t count = 0; count < rowPitch; count += sbpp*4 )
{
if ( !_LoadScanline( &temp[0], 4, sptr, rowPitch, format ) )
return E_FAIL;
if ( image.height > 1 )
{
if ( !_LoadScanline( &temp[4], 4, sptr + rowPitch, rowPitch, format ) )
return E_FAIL;
if ( image.height > 2 )
{
if ( !_LoadScanline( &temp[8], 4, sptr + rowPitch*2, rowPitch, format ) )
return E_FAIL;
if ( !_LoadScanline( &temp[12], 4, sptr + rowPitch*3, rowPitch, format ) )
return E_FAIL;
}
}
if ( degenerate )
{
assert( image.width < 4 || image.height < 4 );
const size_t uSrc[] = { 0, 0, 0, 1 };
if ( image.width < 4 )
{
for( size_t t=0; t < image.height && t < 4; ++t )
{
for( size_t s = image.width; s < 4; ++s )
{
temp[ t*4 + s ] = temp[ t*4 + uSrc[s] ];
}
}
}
if ( image.height < 4 )
{
for( size_t t=image.height; t < 4; ++t )
{
for( size_t s =0; s < 4; ++s )
{
temp[ t*4 + s ] = temp[ uSrc[t]*4 + s ];
}
}
}
}
_ConvertScanline( temp, 16, result.format, format, 0 );
if ( pfEncode )
pfEncode( dptr, temp, bcflags );
else
D3DXEncodeBC1( dptr, temp, alphaRef, bcflags );
sptr += sbpp*4;
dptr += blocksize;
}
pSrc += rowPitch*4;
pDest += result.rowPitch;
}
return S_OK;
}
//-------------------------------------------------------------------------------------
#ifdef _OPENMP
static HRESULT _CompressBC_Parallel( _In_ const Image& image, _In_ const Image& result, _In_ DWORD bcflags,
_In_ float alphaRef )
{
if ( !image.pixels || !result.pixels )
return E_POINTER;
// Parallel version doesn't support degenerate case
assert( ((image.width % 4) == 0) && ((image.height % 4) == 0 ) );
assert( image.width == result.width );
assert( image.height == result.height );
const DXGI_FORMAT format = image.format;
size_t sbpp = BitsPerPixel( format );
if ( !sbpp )
return E_FAIL;
if ( sbpp < 8 )
{
// We don't support compressing from monochrome (DXGI_FORMAT_R1_UNORM)
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
}
// Round to bytes
sbpp = ( sbpp + 7 ) / 8;
// Determine BC format encoder
BC_ENCODE pfEncode;
size_t blocksize;
switch(result.format)
{
case DXGI_FORMAT_BC1_UNORM:
case DXGI_FORMAT_BC1_UNORM_SRGB: pfEncode = nullptr; blocksize = 8; break;
case DXGI_FORMAT_BC2_UNORM:
case DXGI_FORMAT_BC2_UNORM_SRGB: pfEncode = D3DXEncodeBC2; blocksize = 16; break;
case DXGI_FORMAT_BC3_UNORM:
case DXGI_FORMAT_BC3_UNORM_SRGB: pfEncode = D3DXEncodeBC3; blocksize = 16; break;
case DXGI_FORMAT_BC4_UNORM: pfEncode = D3DXEncodeBC4U; blocksize = 8; break;
case DXGI_FORMAT_BC4_SNORM: pfEncode = D3DXEncodeBC4S; blocksize = 8; break;
case DXGI_FORMAT_BC5_UNORM: pfEncode = D3DXEncodeBC5U; blocksize = 16; break;
case DXGI_FORMAT_BC5_SNORM: pfEncode = D3DXEncodeBC5S; blocksize = 16; break;
case DXGI_FORMAT_BC6H_UF16: pfEncode = D3DXEncodeBC6HU; blocksize = 16; break;
case DXGI_FORMAT_BC6H_SF16: pfEncode = D3DXEncodeBC6HS; blocksize = 16; break;
case DXGI_FORMAT_BC7_UNORM:
case DXGI_FORMAT_BC7_UNORM_SRGB: pfEncode = D3DXEncodeBC7; blocksize = 16; break;
default:
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
}
// Refactored version of loop to support parallel independance
const size_t nBlocks = std::max<size_t>(1, image.width / 4) * std::max<size_t>(1, image.height / 4);
bool fail = false;
#pragma omp parallel for
for( int nb=0; nb < static_cast<int>( nBlocks ); ++nb )
{
const size_t nbWidth = std::max<size_t>(1, image.width / 4);
const size_t y = nb / nbWidth;
const size_t x = nb - (y*nbWidth);
assert( x < image.width && y < image.height );
size_t rowPitch = image.rowPitch;
const uint8_t *pSrc = image.pixels + (y*4*rowPitch) + (x*4*sbpp);
uint8_t *pDest = result.pixels + (nb*blocksize);
XMVECTOR temp[16];
if ( !_LoadScanline( &temp[0], 4, pSrc, rowPitch, format ) )
fail = true;
if ( !_LoadScanline( &temp[4], 4, pSrc + rowPitch, rowPitch, format ) )
fail = true;
if ( !_LoadScanline( &temp[8], 4, pSrc + rowPitch*2, rowPitch, format ) )
fail = true;
if ( !_LoadScanline( &temp[12], 4, pSrc + rowPitch*3, rowPitch, format ) )
fail = true;
_ConvertScanline( temp, 16, result.format, format, 0 );
if ( pfEncode )
pfEncode( pDest, temp, bcflags );
else
D3DXEncodeBC1( pDest, temp, alphaRef, bcflags );
}
return (fail) ? E_FAIL : S_OK;
}
#endif // _OPENMP
//-------------------------------------------------------------------------------------
static DXGI_FORMAT _DefaultDecompress( _In_ DXGI_FORMAT format )
{
switch( format )
{
case DXGI_FORMAT_BC1_TYPELESS:
case DXGI_FORMAT_BC1_UNORM:
case DXGI_FORMAT_BC2_TYPELESS:
case DXGI_FORMAT_BC2_UNORM:
case DXGI_FORMAT_BC3_TYPELESS:
case DXGI_FORMAT_BC3_UNORM:
case DXGI_FORMAT_BC7_TYPELESS:
case DXGI_FORMAT_BC7_UNORM:
return DXGI_FORMAT_R8G8B8A8_UNORM;
case DXGI_FORMAT_BC1_UNORM_SRGB:
case DXGI_FORMAT_BC2_UNORM_SRGB:
case DXGI_FORMAT_BC3_UNORM_SRGB:
case DXGI_FORMAT_BC7_UNORM_SRGB:
return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
case DXGI_FORMAT_BC4_TYPELESS:
case DXGI_FORMAT_BC4_UNORM:
return DXGI_FORMAT_R8_UNORM;
case DXGI_FORMAT_BC4_SNORM:
return DXGI_FORMAT_R8_SNORM;
case DXGI_FORMAT_BC5_TYPELESS:
case DXGI_FORMAT_BC5_UNORM:
return DXGI_FORMAT_R8G8_UNORM;
case DXGI_FORMAT_BC5_SNORM:
return DXGI_FORMAT_R8G8_SNORM;
case DXGI_FORMAT_BC6H_TYPELESS:
case DXGI_FORMAT_BC6H_UF16:
case DXGI_FORMAT_BC6H_SF16:
// We could use DXGI_FORMAT_R32G32B32_FLOAT here since BC6H is always Alpha 1.0,
// but this format is more supported by viewers
return DXGI_FORMAT_R32G32B32A32_FLOAT;
default:
return DXGI_FORMAT_UNKNOWN;
}
}
//-------------------------------------------------------------------------------------
static HRESULT _DecompressBC( _In_ const Image& cImage, _In_ const Image& result )
{
if ( !cImage.pixels || !result.pixels )
return E_POINTER;
assert( cImage.width == result.width );
assert( cImage.height == result.height );
// Image must be a multiple of 4 (degenerate cases of 1x1, 1x2, 2x1, and 2x2 are allowed)
size_t width = cImage.width;
if ( (width % 4) != 0 )
{
if ( width != 1 && width != 2 )
return E_INVALIDARG;
}
size_t height = cImage.height;
if ( (height % 4) != 0 )
{
if ( height != 1 && height != 2 )
return E_INVALIDARG;
}
const DXGI_FORMAT format = result.format;
size_t dbpp = BitsPerPixel( format );
if ( !dbpp )
return E_FAIL;
if ( dbpp < 8 )
{
// We don't support decompressing to monochrome (DXGI_FORMAT_R1_UNORM)
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
}
// Round to bytes
dbpp = ( dbpp + 7 ) / 8;
uint8_t *pDest = result.pixels;
if ( !pDest )
return E_POINTER;
// Promote "typeless" BC formats
DXGI_FORMAT cformat;
switch( cImage.format )
{
case DXGI_FORMAT_BC1_TYPELESS: cformat = DXGI_FORMAT_BC1_UNORM; break;
case DXGI_FORMAT_BC2_TYPELESS: cformat = DXGI_FORMAT_BC2_UNORM; break;
case DXGI_FORMAT_BC3_TYPELESS: cformat = DXGI_FORMAT_BC3_UNORM; break;
case DXGI_FORMAT_BC4_TYPELESS: cformat = DXGI_FORMAT_BC4_UNORM; break;
case DXGI_FORMAT_BC5_TYPELESS: cformat = DXGI_FORMAT_BC5_UNORM; break;
case DXGI_FORMAT_BC6H_TYPELESS: cformat = DXGI_FORMAT_BC6H_UF16; break;
case DXGI_FORMAT_BC7_TYPELESS: cformat = DXGI_FORMAT_BC7_UNORM; break;
default: cformat = cImage.format; break;
}
// Determine BC format decoder
BC_DECODE pfDecode;
size_t sbpp;
switch(cformat)
{
case DXGI_FORMAT_BC1_UNORM:
case DXGI_FORMAT_BC1_UNORM_SRGB: pfDecode = D3DXDecodeBC1; sbpp = 8; break;
case DXGI_FORMAT_BC2_UNORM:
case DXGI_FORMAT_BC2_UNORM_SRGB: pfDecode = D3DXDecodeBC2; sbpp = 16; break;
case DXGI_FORMAT_BC3_UNORM:
case DXGI_FORMAT_BC3_UNORM_SRGB: pfDecode = D3DXDecodeBC3; sbpp = 16; break;
case DXGI_FORMAT_BC4_UNORM: pfDecode = D3DXDecodeBC4U; sbpp = 8; break;
case DXGI_FORMAT_BC4_SNORM: pfDecode = D3DXDecodeBC4S; sbpp = 8; break;
case DXGI_FORMAT_BC5_UNORM: pfDecode = D3DXDecodeBC5U; sbpp = 16; break;
case DXGI_FORMAT_BC5_SNORM: pfDecode = D3DXDecodeBC5S; sbpp = 16; break;
case DXGI_FORMAT_BC6H_UF16: pfDecode = D3DXDecodeBC6HU; sbpp = 16; break;
case DXGI_FORMAT_BC6H_SF16: pfDecode = D3DXDecodeBC6HS; sbpp = 16; break;
case DXGI_FORMAT_BC7_UNORM:
case DXGI_FORMAT_BC7_UNORM_SRGB: pfDecode = D3DXDecodeBC7; sbpp = 16; break;
default:
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
}
XMVECTOR temp[16];
const uint8_t *pSrc = cImage.pixels;
const size_t rowPitch = result.rowPitch;
for( size_t h=0; h < cImage.height; h += 4 )
{
const uint8_t *sptr = pSrc;
uint8_t* dptr = pDest;
for( size_t count = 0; count < cImage.rowPitch; count += sbpp )
{
pfDecode( temp, sptr );
_ConvertScanline( temp, 16, format, cformat, 0 );
if ( !_StoreScanline( dptr, rowPitch, format, &temp[0], 4 ) )
return E_FAIL;
if ( result.height > 1 )
{
if ( !_StoreScanline( dptr + rowPitch, rowPitch, format, &temp[4], 4 ) )
return E_FAIL;
if ( result.height > 2 )
{
if ( !_StoreScanline( dptr + rowPitch*2, rowPitch, format, &temp[8], 4 ) )
return E_FAIL;
if ( !_StoreScanline( dptr + rowPitch*3, rowPitch, format, &temp[12], 4 ) )
return E_FAIL;
}
}
sptr += sbpp;
dptr += dbpp*4;
}
pSrc += cImage.rowPitch;
pDest += rowPitch*4;
}
return S_OK;
}
//=====================================================================================
// Entry-points
//=====================================================================================
//-------------------------------------------------------------------------------------
// Compression
//-------------------------------------------------------------------------------------
HRESULT Compress( const Image& srcImage, DXGI_FORMAT format, DWORD compress, float alphaRef, ScratchImage& image )
{
if ( IsCompressed(srcImage.format) || !IsCompressed(format) || IsTypeless(format) )
return E_INVALIDARG;
// Image size must be a multiple of 4 (degenerate cases for mipmaps are allowed)
bool degenerate = false;
size_t width = srcImage.width;
if ( (width % 4) != 0 )
{
if ( width != 1 && width != 2 )
return E_INVALIDARG;
degenerate = true;
}
size_t height = srcImage.height;
if ( (height % 4) != 0 )
{
if ( height != 1 && height != 2 )
return E_INVALIDARG;
degenerate = true;
}
// Create compressed image
HRESULT hr = image.Initialize2D( format, width, height, 1, 1 );
if ( FAILED(hr) )
return hr;
const Image *img = image.GetImage( 0, 0, 0 );
if ( !img )
{
image.Release();
return E_POINTER;
}
// Compress single image
if ( (compress & TEX_COMPRESS_PARALLEL) && !degenerate )
{
#ifndef _OPENMP
return E_NOTIMPL;
#else
hr = _CompressBC_Parallel( srcImage, *img, _GetBCFlags( compress ), alphaRef );
#endif // _OPENMP
}
else
{
hr = _CompressBC( srcImage, *img, _GetBCFlags( compress ), alphaRef, degenerate );
}
if ( FAILED(hr) )
image.Release();
return hr;
}
HRESULT Compress( const Image* srcImages, size_t nimages, const TexMetadata& metadata,
DXGI_FORMAT format, DWORD compress, float alphaRef, ScratchImage& cImages )
{
if ( !srcImages || !nimages )
return E_INVALIDARG;
if ( !IsCompressed(format) || IsTypeless(format) )
return E_INVALIDARG;
// Image size must be a multiple of 4 (degenerate cases for mipmaps are allowed)
size_t width = srcImages[0].width;
if ( (width % 4) != 0 )
{
if ( width != 1 && width != 2 )
return E_INVALIDARG;
}
size_t height = srcImages[0].height;
if ( (height % 4) != 0 )
{
if ( height != 1 && height != 2 )
return E_INVALIDARG;
}
cImages.Release();
TexMetadata mdata2 = metadata;
mdata2.format = format;
HRESULT hr = cImages.Initialize( mdata2 );
if ( FAILED(hr) )
return hr;
if ( nimages != cImages.GetImageCount() )
{
cImages.Release();
return E_FAIL;
}
const Image* dest = cImages.GetImages();
if ( !dest )
{
cImages.Release();
return E_POINTER;
}
for( size_t index=0; index < nimages; ++index )
{
assert( dest[ index ].format == format );
const Image& src = srcImages[ index ];
height = src.height;
width = src.width;
if ( width != dest[ index ].width || height != dest[ index ].height )
{
cImages.Release();
return E_FAIL;
}
bool degenerate = ((height < 4) || (width < 4)) != 0;
if ( (compress & TEX_COMPRESS_PARALLEL) && !degenerate)
{
#ifndef _OPENMP
return E_NOTIMPL;
#else
if ( compress & TEX_COMPRESS_PARALLEL )
{
hr = _CompressBC_Parallel( src, dest[ index ], _GetBCFlags( compress ), alphaRef );
if ( FAILED(hr) )
{
cImages.Release();
return hr;
}
}
#endif // _OPENMP
}
else
{
hr = _CompressBC( src, dest[ index ], _GetBCFlags( compress ), alphaRef, degenerate );
if ( FAILED(hr) )
{
cImages.Release();
return hr;
}
}
}
return S_OK;
}
//-------------------------------------------------------------------------------------
// Decompression
//-------------------------------------------------------------------------------------
HRESULT Decompress( const Image& cImage, DXGI_FORMAT format, ScratchImage& image )
{
if ( IsCompressed(format) || IsTypeless(format) )
return E_INVALIDARG;
if ( format == DXGI_FORMAT_UNKNOWN )
{
// Pick a default decompressed format based on BC input format
format = _DefaultDecompress( cImage.format );
if ( format == DXGI_FORMAT_UNKNOWN )
{
// Input is not a compressed format
return E_INVALIDARG;
}
}
else if ( !IsCompressed(cImage.format) || !IsValid(format) )
return E_INVALIDARG;
// Create decompressed image
HRESULT hr = image.Initialize2D( format, cImage.width, cImage.height, 1, 1 );
if ( FAILED(hr) )
return hr;
const Image *img = image.GetImage( 0, 0, 0 );
if ( !img )
{
image.Release();
return E_POINTER;
}
// Decompress single image
hr = _DecompressBC( cImage, *img );
if ( FAILED(hr) )
image.Release();
return hr;
}
HRESULT Decompress( const Image* cImages, size_t nimages, const TexMetadata& metadata,
DXGI_FORMAT format, ScratchImage& images )
{
if ( !cImages || !nimages )
return E_INVALIDARG;
if ( IsCompressed(format) || IsTypeless(format) )
return E_INVALIDARG;
if ( format == DXGI_FORMAT_UNKNOWN )
{
// Pick a default decompressed format based on BC input format
format = _DefaultDecompress( cImages[0].format );
if ( format == DXGI_FORMAT_UNKNOWN )
{
// Input is not a compressed format
return E_FAIL;
}
}
else if ( !IsValid(format) )
return E_INVALIDARG;
images.Release();
TexMetadata mdata2 = metadata;
mdata2.format = format;
HRESULT hr = images.Initialize( mdata2 );
if ( FAILED(hr) )
return hr;
if ( nimages != images.GetImageCount() )
{
images.Release();
return E_FAIL;
}
const Image* dest = images.GetImages();
if ( !dest )
{
images.Release();
return E_POINTER;
}
for( size_t index=0; index < nimages; ++index )
{
assert( dest[ index ].format == format );
const Image& src = cImages[ index ];
if ( !IsCompressed( src.format ) )
{
images.Release();
return E_FAIL;
}
if ( src.width != dest[ index ].width || src.height != dest[ index ].height )
{
images.Release();
return E_FAIL;
}
hr = _DecompressBC( src, dest[ index ] );
if ( FAILED(hr) )
{
images.Release();
return hr;
}
}
return S_OK;
}
}; // namespace

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,800 @@
//-------------------------------------------------------------------------------------
// DirectXTexD3D11.cpp
//
// DirectX Texture Library - Direct3D 11 helpers
//
// 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
//-------------------------------------------------------------------------------------
#include "directxtexp.h"
#include <d3d10.h>
namespace DirectX
{
static HRESULT _Capture( _In_ ID3D11DeviceContext* pContext, _In_ ID3D11Resource* pSource, _In_ const TexMetadata& metadata,
_In_ const ScratchImage& result )
{
if ( !pContext || !pSource || !result.GetPixels() )
return E_POINTER;
if ( metadata.dimension == TEX_DIMENSION_TEXTURE3D )
{
//--- Volume texture ----------------------------------------------------------
assert( metadata.arraySize == 1 );
size_t height = metadata.height;
size_t depth = metadata.depth;
for( size_t level = 0; level < metadata.mipLevels; ++level )
{
UINT dindex = D3D11CalcSubresource( static_cast<UINT>( level ), 0, static_cast<UINT>( metadata.mipLevels ) );
D3D11_MAPPED_SUBRESOURCE mapped;
HRESULT hr = pContext->Map( pSource, dindex, D3D11_MAP_READ, 0, &mapped );
if ( FAILED(hr) )
return hr;
const uint8_t* pslice = reinterpret_cast<const uint8_t*>( mapped.pData );
if ( !pslice )
{
pContext->Unmap( pSource, dindex );
return E_POINTER;
}
size_t lines = ComputeScanlines( metadata.format, height );
for( size_t slice = 0; slice < depth; ++slice )
{
const Image* img = result.GetImage( level, 0, slice );
if ( !img )
{
pContext->Unmap( pSource, dindex );
return E_FAIL;
}
if ( !img->pixels )
{
pContext->Unmap( pSource, dindex );
return E_POINTER;
}
const uint8_t* sptr = pslice;
uint8_t* dptr = img->pixels;
for( size_t h = 0; h < lines; ++h )
{
size_t msize = std::min<size_t>( img->rowPitch, mapped.RowPitch );
memcpy_s( dptr, img->rowPitch, sptr, msize );
sptr += mapped.RowPitch;
dptr += img->rowPitch;
}
pslice += mapped.DepthPitch;
}
pContext->Unmap( pSource, dindex );
if ( height > 1 )
height >>= 1;
if ( depth > 1 )
depth >>= 1;
}
}
else
{
//--- 1D or 2D texture --------------------------------------------------------
assert( metadata.depth == 1 );
for( size_t item = 0; item < metadata.arraySize; ++item )
{
size_t height = metadata.height;
for( size_t level = 0; level < metadata.mipLevels; ++level )
{
UINT dindex = D3D11CalcSubresource( static_cast<UINT>( level ), static_cast<UINT>( item ), static_cast<UINT>( metadata.mipLevels ) );
D3D11_MAPPED_SUBRESOURCE mapped;
HRESULT hr = pContext->Map( pSource, dindex, D3D11_MAP_READ, 0, &mapped );
if ( FAILED(hr) )
return hr;
const Image* img = result.GetImage( level, item, 0 );
if ( !img )
{
pContext->Unmap( pSource, dindex );
return E_FAIL;
}
if ( !img->pixels )
{
pContext->Unmap( pSource, dindex );
return E_POINTER;
}
size_t lines = ComputeScanlines( metadata.format, height );
const uint8_t* sptr = reinterpret_cast<const uint8_t*>( mapped.pData );
uint8_t* dptr = img->pixels;
for( size_t h = 0; h < lines; ++h )
{
size_t msize = std::min<size_t>( img->rowPitch, mapped.RowPitch );
memcpy_s( dptr, img->rowPitch, sptr, msize );
sptr += mapped.RowPitch;
dptr += img->rowPitch;
}
pContext->Unmap( pSource, dindex );
if ( height > 1 )
height >>= 1;
}
}
}
return S_OK;
}
//=====================================================================================
// Entry-points
//=====================================================================================
//-------------------------------------------------------------------------------------
// Determine if given texture metadata is supported on the given device
//-------------------------------------------------------------------------------------
bool IsSupportedTexture( ID3D11Device* pDevice, const TexMetadata& metadata )
{
if ( !pDevice )
return false;
D3D_FEATURE_LEVEL fl = pDevice->GetFeatureLevel();
// Validate format
DXGI_FORMAT fmt = metadata.format;
if ( !IsValid( fmt ) )
return false;
if ( IsVideo(fmt) )
return false;
switch( fmt )
{
case DXGI_FORMAT_BC4_TYPELESS:
case DXGI_FORMAT_BC4_UNORM:
case DXGI_FORMAT_BC4_SNORM:
case DXGI_FORMAT_BC5_TYPELESS:
case DXGI_FORMAT_BC5_UNORM:
case DXGI_FORMAT_BC5_SNORM:
if ( fl < D3D_FEATURE_LEVEL_10_0 )
return false;
break;
case DXGI_FORMAT_BC6H_TYPELESS:
case DXGI_FORMAT_BC6H_UF16:
case DXGI_FORMAT_BC6H_SF16:
case DXGI_FORMAT_BC7_TYPELESS:
case DXGI_FORMAT_BC7_UNORM:
case DXGI_FORMAT_BC7_UNORM_SRGB:
if ( fl < D3D_FEATURE_LEVEL_11_0 )
return false;
break;
}
// Validate miplevel count
if ( metadata.mipLevels > D3D11_REQ_MIP_LEVELS )
return false;
// Validate array size, dimension, and width/height
size_t arraySize = metadata.arraySize;
size_t iWidth = metadata.width;
size_t iHeight = metadata.height;
size_t iDepth = metadata.depth;
// Most cases are known apriori based on feature level, but we use this for robustness to handle the few optional cases
UINT formatSupport = 0;
pDevice->CheckFormatSupport( fmt, &formatSupport );
switch ( metadata.dimension )
{
case TEX_DIMENSION_TEXTURE1D:
if ( !(formatSupport & D3D11_FORMAT_SUPPORT_TEXTURE1D) )
return false;
if ( (arraySize > D3D11_REQ_TEXTURE1D_ARRAY_AXIS_DIMENSION)
|| (iWidth > D3D11_REQ_TEXTURE1D_U_DIMENSION) )
return false;
if ( fl < D3D_FEATURE_LEVEL_11_0 )
{
if ( (arraySize > D3D10_REQ_TEXTURE1D_ARRAY_AXIS_DIMENSION)
|| (iWidth > D3D10_REQ_TEXTURE1D_U_DIMENSION) )
return false;
if ( fl < D3D_FEATURE_LEVEL_10_0 )
{
if ( (arraySize > 1) || (iWidth > 4096 /*D3D_FL9_3_REQ_TEXTURE1D_U_DIMENSION*/) )
return false;
if ( (fl < D3D_FEATURE_LEVEL_9_3) && (iWidth > 2048 /*D3D_FL9_1_REQ_TEXTURE1D_U_DIMENSION*/ ) )
return false;
}
}
break;
case TEX_DIMENSION_TEXTURE2D:
if ( metadata.miscFlags & TEX_MISC_TEXTURECUBE )
{
if ( !(formatSupport & D3D11_FORMAT_SUPPORT_TEXTURECUBE) )
return false;
if ( (arraySize > D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION)
|| (iWidth > D3D11_REQ_TEXTURECUBE_DIMENSION)
|| (iHeight > D3D11_REQ_TEXTURECUBE_DIMENSION))
return false;
if ( fl < D3D_FEATURE_LEVEL_11_0 )
{
if ( (arraySize > D3D10_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION)
|| (iWidth > D3D10_REQ_TEXTURECUBE_DIMENSION)
|| (iHeight > D3D10_REQ_TEXTURECUBE_DIMENSION))
return false;
if ( (fl < D3D_FEATURE_LEVEL_10_1) && (arraySize != 6) )
return false;
if ( fl < D3D_FEATURE_LEVEL_10_0 )
{
if ( (iWidth > 4096 /*D3D_FL9_3_REQ_TEXTURECUBE_DIMENSION*/ )
|| (iHeight > 4096 /*D3D_FL9_3_REQ_TEXTURECUBE_DIMENSION*/ ) )
return false;
if ( (fl < D3D_FEATURE_LEVEL_9_3)
&& ( (iWidth > 512 /*D3D_FL9_1_REQ_TEXTURECUBE_DIMENSION*/)
|| (iHeight > 512 /*D3D_FL9_1_REQ_TEXTURECUBE_DIMENSION*/) ) )
return false;
}
}
}
else // Not a cube map
{
if ( !(formatSupport & D3D11_FORMAT_SUPPORT_TEXTURE2D) )
return false;
if ( (arraySize > D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION)
|| (iWidth > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION)
|| (iHeight > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION))
return false;
if ( fl < D3D_FEATURE_LEVEL_11_0 )
{
if ( (arraySize > D3D10_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION)
|| (iWidth > D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION)
|| (iHeight > D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION))
return false;
if ( fl < D3D_FEATURE_LEVEL_10_0 )
{
if ( (arraySize > 1)
|| (iWidth > 4096 /*D3D_FL9_3_REQ_TEXTURE2D_U_OR_V_DIMENSION*/)
|| (iHeight > 4096 /*D3D_FL9_3_REQ_TEXTURE2D_U_OR_V_DIMENSION*/) )
return false;
if ( (fl < D3D_FEATURE_LEVEL_9_3)
&& ( (iWidth > 2048 /*D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION*/)
|| (iHeight > 2048 /*D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION*/) ) )
return false;
}
}
}
break;
case TEX_DIMENSION_TEXTURE3D:
if ( !(formatSupport & D3D11_FORMAT_SUPPORT_TEXTURE3D) )
return false;
if ( (arraySize > 1)
|| (iWidth > D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION)
|| (iHeight > D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION)
|| (iDepth > D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION) )
return false;
if ( fl < D3D_FEATURE_LEVEL_11_0 )
{
if ( (iWidth > D3D10_REQ_TEXTURE3D_U_V_OR_W_DIMENSION)
|| (iHeight > D3D10_REQ_TEXTURE3D_U_V_OR_W_DIMENSION)
|| (iDepth > D3D10_REQ_TEXTURE3D_U_V_OR_W_DIMENSION) )
return false;
if ( fl < D3D_FEATURE_LEVEL_10_0 )
{
if ( (iWidth > 256 /*D3D_FL9_1_REQ_TEXTURE3D_U_V_OR_W_DIMENSION*/)
|| (iHeight > 256 /*D3D_FL9_1_REQ_TEXTURE3D_U_V_OR_W_DIMENSION*/)
|| (iDepth > 256 /*D3D_FL9_1_REQ_TEXTURE3D_U_V_OR_W_DIMENSION*/) )
return false;
}
}
break;
default:
// Not a supported dimension
return false;
}
return true;
}
//-------------------------------------------------------------------------------------
// Create a texture resource
//-------------------------------------------------------------------------------------
HRESULT CreateTexture( ID3D11Device* pDevice, const Image* srcImages, size_t nimages, const TexMetadata& metadata,
ID3D11Resource** ppResource )
{
if ( !pDevice || !srcImages || !nimages || !ppResource )
return E_INVALIDARG;
if ( !metadata.mipLevels || !metadata.arraySize )
return E_INVALIDARG;
#ifdef _AMD64_
if ( (metadata.width > 0xFFFFFFFF) || (metadata.height > 0xFFFFFFFF)
|| (metadata.mipLevels > 0xFFFFFFFF) || (metadata.arraySize > 0xFFFFFFFF) )
return E_INVALIDARG;
#endif
std::unique_ptr<D3D11_SUBRESOURCE_DATA[]> initData( new D3D11_SUBRESOURCE_DATA[ metadata.mipLevels * metadata.arraySize ] );
if ( !initData )
return E_OUTOFMEMORY;
// Fill out subresource array
if ( metadata.dimension == TEX_DIMENSION_TEXTURE3D )
{
//--- Volume case -------------------------------------------------------------
if ( !metadata.depth )
return E_INVALIDARG;
#ifdef _AMD64_
if ( metadata.depth > 0xFFFFFFFF )
return E_INVALIDARG;
#endif
if ( metadata.arraySize > 1 )
// Direct3D 11 doesn't support arrays of 3D textures
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
size_t depth = metadata.depth;
size_t idx = 0;
for( size_t level = 0; level < metadata.mipLevels; ++level )
{
size_t index = metadata.ComputeIndex( level, 0, 0 );
if ( index >= nimages )
return E_FAIL;
const Image& img = srcImages[ index ];
if ( img.format != metadata.format )
return E_FAIL;
if ( !img.pixels )
return E_POINTER;
// Verify pixels in image 1 .. (depth-1) are exactly image->slicePitch apart
// For 3D textures, this relies on all slices of the same miplevel being continous in memory
// (this is how ScratchImage lays them out), which is why we just give the 0th slice to Direct3D 11
const uint8_t* pSlice = img.pixels + img.slicePitch;
for( size_t slice = 1; slice < depth; ++slice )
{
size_t tindex = metadata.ComputeIndex( level, 0, slice );
if ( tindex >= nimages )
return E_FAIL;
const Image& timg = srcImages[ tindex ];
if ( !timg.pixels )
return E_POINTER;
if ( timg.pixels != pSlice
|| timg.format != metadata.format
|| timg.rowPitch != img.rowPitch
|| timg.slicePitch != img.slicePitch )
return E_FAIL;
pSlice = timg.pixels + img.slicePitch;
}
assert( idx < (metadata.mipLevels * metadata.arraySize) );
initData[idx].pSysMem = img.pixels;
initData[idx].SysMemPitch = static_cast<DWORD>( img.rowPitch );
initData[idx].SysMemSlicePitch = static_cast<DWORD>( img.slicePitch );
++idx;
if ( depth > 1 )
depth >>= 1;
}
}
else
{
//--- 1D or 2D texture case ---------------------------------------------------
size_t idx = 0;
for( size_t item = 0; item < metadata.arraySize; ++item )
{
for( size_t level = 0; level < metadata.mipLevels; ++level )
{
size_t index = metadata.ComputeIndex( level, item, 0 );
if ( index >= nimages )
return E_FAIL;
const Image& img = srcImages[ index ];
if ( img.format != metadata.format )
return E_FAIL;
if ( !img.pixels )
return E_POINTER;
assert( idx < (metadata.mipLevels * metadata.arraySize) );
initData[idx].pSysMem = img.pixels;
initData[idx].SysMemPitch = static_cast<DWORD>( img.rowPitch );
initData[idx].SysMemSlicePitch = static_cast<DWORD>( img.slicePitch );
++idx;
}
}
}
// Create texture using static initialization data
HRESULT hr = E_FAIL;
switch ( metadata.dimension )
{
case TEX_DIMENSION_TEXTURE1D:
{
D3D11_TEXTURE1D_DESC desc;
desc.Width = static_cast<UINT>( metadata.width );
desc.MipLevels = static_cast<UINT>( metadata.mipLevels );
desc.ArraySize = static_cast<UINT>( metadata.arraySize );
desc.Format = metadata.format;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc.CPUAccessFlags = 0;
desc.MiscFlags = 0;
hr = pDevice->CreateTexture1D( &desc, initData.get(), reinterpret_cast<ID3D11Texture1D**>(ppResource) );
}
break;
case TEX_DIMENSION_TEXTURE2D:
{
D3D11_TEXTURE2D_DESC desc;
desc.Width = static_cast<UINT>( metadata.width );
desc.Height = static_cast<UINT>( metadata.height );
desc.MipLevels = static_cast<UINT>( metadata.mipLevels );
desc.ArraySize = static_cast<UINT>( metadata.arraySize );
desc.Format = metadata.format;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc.CPUAccessFlags = 0;
desc.MiscFlags = (metadata.miscFlags & TEX_MISC_TEXTURECUBE) ? D3D11_RESOURCE_MISC_TEXTURECUBE : 0;
hr = pDevice->CreateTexture2D( &desc, initData.get(), reinterpret_cast<ID3D11Texture2D**>(ppResource) );
}
break;
case TEX_DIMENSION_TEXTURE3D:
{
D3D11_TEXTURE3D_DESC desc;
desc.Width = static_cast<UINT>( metadata.width );
desc.Height = static_cast<UINT>( metadata.height );
desc.Depth = static_cast<UINT>( metadata.depth );
desc.MipLevels = static_cast<UINT>( metadata.mipLevels );
desc.Format = metadata.format;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc.CPUAccessFlags = 0;
desc.MiscFlags = 0;
hr = pDevice->CreateTexture3D( &desc, initData.get(), reinterpret_cast<ID3D11Texture3D**>(ppResource) );
}
break;
}
return hr;
}
//-------------------------------------------------------------------------------------
// Create a shader resource view and associated texture
//-------------------------------------------------------------------------------------
HRESULT CreateShaderResourceView( ID3D11Device* pDevice, const Image* srcImages, size_t nimages, const TexMetadata& metadata,
ID3D11ShaderResourceView** ppSRV )
{
if ( !ppSRV )
return E_INVALIDARG;
ScopedObject<ID3D11Resource> resource;
HRESULT hr = CreateTexture( pDevice, srcImages, nimages, metadata, &resource );
if ( FAILED(hr) )
return hr;
assert( !resource.IsNull() );
D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc;
memset( &SRVDesc, 0, sizeof(SRVDesc) );
SRVDesc.Format = metadata.format;
switch ( metadata.dimension )
{
case TEX_DIMENSION_TEXTURE1D:
if ( metadata.arraySize > 1 )
{
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1DARRAY;
SRVDesc.Texture1DArray.MipLevels = static_cast<UINT>( metadata.mipLevels );
SRVDesc.Texture1DArray.ArraySize = static_cast<UINT>( metadata.arraySize );
}
else
{
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D;
SRVDesc.Texture1D.MipLevels = static_cast<UINT>( metadata.mipLevels );
}
break;
case TEX_DIMENSION_TEXTURE2D:
if ( metadata.miscFlags & TEX_MISC_TEXTURECUBE )
{
if (metadata.arraySize > 6)
{
assert( (metadata.arraySize % 6) == 0 );
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBEARRAY;
SRVDesc.TextureCubeArray.MipLevels = static_cast<UINT>( metadata.mipLevels );
SRVDesc.TextureCubeArray.NumCubes = static_cast<UINT>( metadata.arraySize / 6 );
}
else
{
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
SRVDesc.TextureCube.MipLevels = static_cast<UINT>( metadata.mipLevels );
}
}
else if ( metadata.arraySize > 1 )
{
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
SRVDesc.Texture2DArray.MipLevels = static_cast<UINT>( metadata.mipLevels );
SRVDesc.Texture2DArray.ArraySize = static_cast<UINT>( metadata.arraySize );
}
else
{
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
SRVDesc.Texture2D.MipLevels = static_cast<UINT>( metadata.mipLevels );
}
break;
case TEX_DIMENSION_TEXTURE3D:
assert( metadata.arraySize == 1 );
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
SRVDesc.Texture3D.MipLevels = static_cast<UINT>( metadata.mipLevels );
break;
default:
return E_FAIL;
}
hr = pDevice->CreateShaderResourceView( resource.Get(), &SRVDesc, ppSRV );
if ( FAILED(hr) )
return hr;
assert( *ppSRV );
return S_OK;
}
//-------------------------------------------------------------------------------------
// Save a texture resource to a DDS file in memory/on disk
//-------------------------------------------------------------------------------------
HRESULT CaptureTexture( ID3D11Device* pDevice, ID3D11DeviceContext* pContext, ID3D11Resource* pSource, ScratchImage& result )
{
if ( !pDevice || !pContext || !pSource )
return E_INVALIDARG;
D3D11_RESOURCE_DIMENSION resType = D3D11_RESOURCE_DIMENSION_UNKNOWN;
pSource->GetType( &resType );
HRESULT hr;
switch( resType )
{
case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
{
ScopedObject<ID3D11Texture1D> pTexture;
hr = pSource->QueryInterface( __uuidof(ID3D11Texture1D), (void**) &pTexture );
if ( FAILED(hr) )
break;
assert( pTexture.Get() );
D3D11_TEXTURE1D_DESC desc;
pTexture->GetDesc( &desc );
desc.BindFlags = 0;
desc.MiscFlags = 0;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.Usage = D3D11_USAGE_STAGING;
ScopedObject<ID3D11Texture1D> pStaging;
hr = pDevice->CreateTexture1D( &desc, 0, &pStaging );
if ( FAILED(hr) )
break;
assert( pStaging.Get() );
pContext->CopyResource( pStaging.Get(), pSource );
TexMetadata mdata;
mdata.width = desc.Width;
mdata.height = mdata.depth = 1;
mdata.arraySize = desc.ArraySize;
mdata.mipLevels = desc.MipLevels;
mdata.miscFlags = 0;
mdata.format = desc.Format;
mdata.dimension = TEX_DIMENSION_TEXTURE1D;
hr = result.Initialize( mdata );
if ( FAILED(hr) )
break;
hr = _Capture( pContext, pStaging.Get(), mdata, result );
}
break;
case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
{
ScopedObject<ID3D11Texture2D> pTexture;
hr = pSource->QueryInterface( __uuidof(ID3D11Texture2D), (void**) &pTexture );
if ( FAILED(hr) )
break;
assert( pTexture.Get() );
D3D11_TEXTURE2D_DESC desc;
pTexture->GetDesc( &desc );
ScopedObject<ID3D11Texture2D> pStaging;
if ( desc.SampleDesc.Count > 1 )
{
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
ScopedObject<ID3D11Texture2D> pTemp;
hr = pDevice->CreateTexture2D( &desc, 0, &pTemp );
if ( FAILED(hr) )
break;
assert( pTemp.Get() );
for( UINT item = 0; item < desc.ArraySize; ++item )
{
for( UINT level = 0; level < desc.MipLevels; ++level )
{
UINT index = D3D11CalcSubresource( level, item, desc.MipLevels );
pContext->ResolveSubresource( pTemp.Get(), index, pSource, index, desc.Format );
}
}
desc.BindFlags = 0;
desc.MiscFlags &= D3D11_RESOURCE_MISC_TEXTURECUBE;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.Usage = D3D11_USAGE_STAGING;
hr = pDevice->CreateTexture2D( &desc, 0, &pStaging );
if ( FAILED(hr) )
break;
assert( pStaging.Get() );
pContext->CopyResource( pStaging.Get(), pTemp.Get() );
}
else
{
desc.BindFlags = 0;
desc.MiscFlags &= D3D11_RESOURCE_MISC_TEXTURECUBE;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.Usage = D3D11_USAGE_STAGING;
hr = pDevice->CreateTexture2D( &desc, 0, &pStaging );
if ( FAILED(hr) )
break;
assert( pStaging.Get() );
pContext->CopyResource( pStaging.Get(), pSource );
}
TexMetadata mdata;
mdata.width = desc.Width;
mdata.height = desc.Height;
mdata.depth = 1;
mdata.arraySize = desc.ArraySize;
mdata.mipLevels = desc.MipLevels;
mdata.miscFlags = (desc.MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE) ? TEX_MISC_TEXTURECUBE : 0;
mdata.format = desc.Format;
mdata.dimension = TEX_DIMENSION_TEXTURE2D;
hr = result.Initialize( mdata );
if ( FAILED(hr) )
break;
hr = _Capture( pContext, pStaging.Get(), mdata, result );
}
break;
case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
{
ScopedObject<ID3D11Texture3D> pTexture;
hr = pSource->QueryInterface( __uuidof(ID3D11Texture3D), (void**) &pTexture );
if ( FAILED(hr) )
break;
assert( pTexture.Get() );
D3D11_TEXTURE3D_DESC desc;
pTexture->GetDesc( &desc );
desc.BindFlags = 0;
desc.MiscFlags = 0;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.Usage = D3D11_USAGE_STAGING;
ScopedObject<ID3D11Texture3D> pStaging;
hr = pDevice->CreateTexture3D( &desc, 0, &pStaging );
if ( FAILED(hr) )
break;
assert( pStaging.Get() );
pContext->CopyResource( pStaging.Get(), pSource );
TexMetadata mdata;
mdata.width = desc.Width;
mdata.height = desc.Height;
mdata.depth = desc.Depth;
mdata.arraySize = 1;
mdata.mipLevels = desc.MipLevels;
mdata.miscFlags = 0;
mdata.format = desc.Format;
mdata.dimension = TEX_DIMENSION_TEXTURE3D;
hr = result.Initialize( mdata );
if ( FAILED(hr) )
break;
hr = _Capture( pContext, pStaging.Get(), mdata, result );
}
break;
default:
hr = E_FAIL;
break;
}
if ( FAILED(hr) )
{
result.Release();
return hr;
}
return S_OK;
}
}; // namespace

1683
DirectXTex/DirectXTexDDS.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,327 @@
//-------------------------------------------------------------------------------------
// DirectXTexFlipRotate.cpp
//
// DirectX Texture Library - Image flip/rotate operations
//
// 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
//-------------------------------------------------------------------------------------
#include "directxtexp.h"
namespace DirectX
{
//-------------------------------------------------------------------------------------
// Do flip/rotate operation using WIC
//-------------------------------------------------------------------------------------
static HRESULT _PerformFlipRotateUsingWIC( _In_ const Image& srcImage, _In_ DWORD flags,
_In_ const WICPixelFormatGUID& pfGUID, _In_ const Image& destImage )
{
if ( !srcImage.pixels || !destImage.pixels )
return E_POINTER;
assert( srcImage.format == destImage.format );
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return E_NOINTERFACE;
ScopedObject<IWICBitmap> source;
HRESULT hr = pWIC->CreateBitmapFromMemory( static_cast<UINT>( srcImage.width ), static_cast<UINT>( srcImage.height ), pfGUID,
static_cast<UINT>( srcImage.rowPitch ), static_cast<UINT>( srcImage.slicePitch ),
srcImage.pixels, &source );
if ( FAILED(hr) )
return hr;
ScopedObject<IWICBitmapFlipRotator> FR;
hr = pWIC->CreateBitmapFlipRotator( &FR );
if ( FAILED(hr) )
return hr;
hr = FR->Initialize( source.Get(), static_cast<WICBitmapTransformOptions>( flags ) );
if ( FAILED(hr) )
return hr;
WICPixelFormatGUID pfFR;
hr = FR->GetPixelFormat( &pfFR );
if ( FAILED(hr) )
return hr;
if ( memcmp( &pfFR, &pfGUID, sizeof(GUID) ) != 0 )
{
// Flip/rotate should return the same format as the source...
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
}
UINT nwidth, nheight;
hr = FR->GetSize( &nwidth, &nheight );
if ( FAILED(hr) )
return hr;
if ( destImage.width != nwidth || destImage.height != nheight )
return E_FAIL;
hr = FR->CopyPixels( 0, static_cast<UINT>( destImage.rowPitch ), static_cast<UINT>( destImage.slicePitch ), destImage.pixels );
if ( FAILED(hr) )
return hr;
return S_OK;
}
//-------------------------------------------------------------------------------------
// Do conversion, flip/rotate using WIC, conversion cycle
//-------------------------------------------------------------------------------------
static HRESULT _PerformFlipRotateViaF32( _In_ const Image& srcImage, _In_ DWORD flags, _In_ const Image& destImage )
{
if ( !srcImage.pixels || !destImage.pixels )
return E_POINTER;
assert( srcImage.format != DXGI_FORMAT_R32G32B32A32_FLOAT );
assert( srcImage.format == destImage.format );
ScratchImage temp;
HRESULT hr = _ConvertToR32G32B32A32( srcImage, temp );
if ( FAILED(hr) )
return hr;
const Image *tsrc = temp.GetImage( 0, 0, 0 );
if ( !tsrc )
return E_POINTER;
ScratchImage rtemp;
hr = rtemp.Initialize2D( DXGI_FORMAT_R32G32B32A32_FLOAT, destImage.width, destImage.height, 1, 1 );
if ( FAILED(hr) )
return hr;
const Image *tdest = rtemp.GetImage( 0, 0, 0 );
if ( !tdest )
return E_POINTER;
hr = _PerformFlipRotateUsingWIC( *tsrc, flags, GUID_WICPixelFormat128bppRGBAFloat, *tdest );
if ( FAILED(hr) )
return hr;
temp.Release();
hr = _ConvertFromR32G32B32A32( *tdest, destImage );
if ( FAILED(hr) )
return hr;
return S_OK;
}
//=====================================================================================
// Entry-points
//=====================================================================================
//-------------------------------------------------------------------------------------
// Flip/rotate image
//-------------------------------------------------------------------------------------
HRESULT FlipRotate( const Image& srcImage, DWORD flags, ScratchImage& image )
{
if ( !srcImage.pixels )
return E_POINTER;
if ( !flags )
return E_INVALIDARG;
#ifdef _AMD64_
if ( (srcImage.width > 0xFFFFFFFF) || (srcImage.height > 0xFFFFFFFF) )
return E_INVALIDARG;
#endif
if ( IsCompressed( srcImage.format ) )
{
// We don't support flip/rotate operations on compressed images
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
}
static_assert( TEX_FR_ROTATE0 == WICBitmapTransformRotate0, "TEX_FR_ROTATE0 no longer matches WIC" );
static_assert( TEX_FR_ROTATE90 == WICBitmapTransformRotate90, "TEX_FR_ROTATE90 no longer matches WIC" );
static_assert( TEX_FR_ROTATE180 == WICBitmapTransformRotate180, "TEX_FR_ROTATE180 no longer matches WIC" );
static_assert( TEX_FR_ROTATE270 == WICBitmapTransformRotate270, "TEX_FR_ROTATE270 no longer matches WIC" );
static_assert( TEX_FR_FLIP_HORIZONTAL == WICBitmapTransformFlipHorizontal, "TEX_FR_FLIP_HORIZONTAL no longer matches WIC" );
static_assert( TEX_FR_FLIP_VERTICAL == WICBitmapTransformFlipVertical, "TEX_FR_FLIP_VERTICAL no longer matches WIC" );
// Only supports 90, 180, 270, or no rotation flags... not a combination of rotation flags
switch ( flags & (TEX_FR_ROTATE90|TEX_FR_ROTATE180|TEX_FR_ROTATE270) )
{
case 0:
case TEX_FR_ROTATE90:
case TEX_FR_ROTATE180:
case TEX_FR_ROTATE270:
break;
default:
return E_INVALIDARG;
}
size_t nwidth = srcImage.width;
size_t nheight = srcImage.height;
if (flags & (TEX_FR_ROTATE90|TEX_FR_ROTATE270))
{
nwidth = srcImage.height;
nheight = srcImage.width;
}
HRESULT hr = image.Initialize2D( srcImage.format, nwidth, nheight, 1, 1 );
if ( FAILED(hr) )
return hr;
const Image *rimage = image.GetImage( 0, 0, 0 );
if ( !rimage )
return E_POINTER;
WICPixelFormatGUID pfGUID;
if ( _DXGIToWIC( srcImage.format, pfGUID ) )
{
// Case 1: Source format is supported by Windows Imaging Component
hr = _PerformFlipRotateUsingWIC( srcImage, flags, pfGUID, *rimage );
}
else
{
// Case 2: Source format is not supported by WIC, so we have to convert, flip/rotate, and convert back
hr = _PerformFlipRotateViaF32( srcImage, flags, *rimage );
}
if ( FAILED(hr) )
{
image.Release();
return hr;
}
return S_OK;
}
//-------------------------------------------------------------------------------------
// Flip/rotate image (complex)
//-------------------------------------------------------------------------------------
HRESULT FlipRotate( const Image* srcImages, size_t nimages, const TexMetadata& metadata,
DWORD flags, ScratchImage& result )
{
if ( !srcImages || !nimages )
return E_INVALIDARG;
if ( IsCompressed( metadata.format ) )
{
// We don't support flip/rotate operations on compressed images
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
}
static_assert( TEX_FR_ROTATE0 == WICBitmapTransformRotate0, "TEX_FR_ROTATE0 no longer matches WIC" );
static_assert( TEX_FR_ROTATE90 == WICBitmapTransformRotate90, "TEX_FR_ROTATE90 no longer matches WIC" );
static_assert( TEX_FR_ROTATE180 == WICBitmapTransformRotate180, "TEX_FR_ROTATE180 no longer matches WIC" );
static_assert( TEX_FR_ROTATE270 == WICBitmapTransformRotate270, "TEX_FR_ROTATE270 no longer matches WIC" );
static_assert( TEX_FR_FLIP_HORIZONTAL == WICBitmapTransformFlipHorizontal, "TEX_FR_FLIP_HORIZONTAL no longer matches WIC" );
static_assert( TEX_FR_FLIP_VERTICAL == WICBitmapTransformFlipVertical, "TEX_FR_FLIP_VERTICAL no longer matches WIC" );
// Only supports 90, 180, 270, or no rotation flags... not a combination of rotation flags
switch ( flags & (TEX_FR_ROTATE90|TEX_FR_ROTATE180|TEX_FR_ROTATE270) )
{
case 0:
case TEX_FR_ROTATE90:
case TEX_FR_ROTATE180:
case TEX_FR_ROTATE270:
break;
default:
return E_INVALIDARG;
}
TexMetadata mdata2 = metadata;
bool flipwh = false;
if (flags & (TEX_FR_ROTATE90|TEX_FR_ROTATE270))
{
flipwh = true;
mdata2.width = metadata.height;
mdata2.height = metadata.width;
}
HRESULT hr = result.Initialize( mdata2 );
if ( FAILED(hr) )
return hr;
if ( nimages != result.GetImageCount() )
{
result.Release();
return E_FAIL;
}
const Image* dest = result.GetImages();
if ( !dest )
{
result.Release();
return E_POINTER;
}
WICPixelFormatGUID pfGUID;
bool wicpf = _DXGIToWIC( metadata.format, pfGUID );
for( size_t index=0; index < nimages; ++index )
{
const Image& src = srcImages[ index ];
if ( src.format != metadata.format )
{
result.Release();
return E_FAIL;
}
#ifdef _AMD64_
if ( (src.width > 0xFFFFFFFF) || (src.height > 0xFFFFFFFF) )
return E_FAIL;
#endif
const Image& dst = dest[ index ];
assert( dst.format == metadata.format );
if ( flipwh )
{
if ( src.width != dst.height || src.height != dst.width )
{
result.Release();
return E_FAIL;
}
}
else
{
if ( src.width != dst.width || src.height != dst.height )
{
result.Release();
return E_FAIL;
}
}
if (wicpf)
{
// Case 1: Source format is supported by Windows Imaging Component
hr = _PerformFlipRotateUsingWIC( src, flags, pfGUID, dst );
}
else
{
// Case 2: Source format is not supported by WIC, so we have to convert, flip/rotate, and convert back
hr = _PerformFlipRotateViaF32( src, flags, dst );
}
if ( FAILED(hr) )
{
result.Release();
return hr;
}
}
return S_OK;
}
}; // namespace

View File

@ -0,0 +1,638 @@
//-------------------------------------------------------------------------------------
// DirectXTexImage.cpp
//
// DirectX Texture Library - Image container
//
// 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
//-------------------------------------------------------------------------------------
#include "directxtexp.h"
namespace DirectX
{
extern bool _CalculateMipLevels( _In_ size_t width, _In_ size_t height, _Inout_ size_t& mipLevels );
extern bool _CalculateMipLevels3D( _In_ size_t width, _In_ size_t height, _In_ size_t depth, _Inout_ size_t& mipLevels );
//-------------------------------------------------------------------------------------
// Determines number of image array entries and pixel size
//-------------------------------------------------------------------------------------
void _DetermineImageArray( const TexMetadata& metadata, DWORD cpFlags,
size_t& nImages, size_t& pixelSize )
{
assert( metadata.width > 0 && metadata.height > 0 && metadata.depth > 0 );
assert( metadata.arraySize > 0 );
assert( metadata.mipLevels > 0 );
size_t _pixelSize = 0;
size_t _nimages = 0;
switch( metadata.dimension )
{
case TEX_DIMENSION_TEXTURE1D:
case TEX_DIMENSION_TEXTURE2D:
for( size_t item = 0; item < metadata.arraySize; ++item )
{
size_t w = metadata.width;
size_t h = metadata.height;
for( size_t level=0; level < metadata.mipLevels; ++level )
{
size_t rowPitch, slicePitch;
ComputePitch( metadata.format, w, h, rowPitch, slicePitch, cpFlags );
_pixelSize += slicePitch;
++_nimages;
if ( h > 1 )
h >>= 1;
if ( w > 1 )
w >>= 1;
}
}
break;
case TEX_DIMENSION_TEXTURE3D:
{
size_t w = metadata.width;
size_t h = metadata.height;
size_t d = metadata.depth;
for( size_t level=0; level < metadata.mipLevels; ++level )
{
size_t rowPitch, slicePitch;
ComputePitch( metadata.format, w, h, rowPitch, slicePitch, cpFlags );
for( size_t slice=0; slice < d; ++slice )
{
_pixelSize += slicePitch;
++_nimages;
}
if ( h > 1 )
h >>= 1;
if ( w > 1 )
w >>= 1;
if ( d > 1 )
d >>= 1;
}
}
break;
default:
assert( false );
break;
}
nImages = _nimages;
pixelSize = _pixelSize;
}
//-------------------------------------------------------------------------------------
// Fills in the image array entries
//-------------------------------------------------------------------------------------
bool _SetupImageArray( uint8_t *pMemory, size_t pixelSize,
const TexMetadata& metadata, DWORD cpFlags,
Image* images, size_t nImages )
{
assert( pMemory );
assert( pixelSize > 0 );
assert( nImages > 0 );
if ( !images )
return false;
size_t index = 0;
uint8_t* pixels = pMemory;
const uint8_t* pEndBits = pMemory + pixelSize;
switch( metadata.dimension )
{
case TEX_DIMENSION_TEXTURE1D:
case TEX_DIMENSION_TEXTURE2D:
for( size_t item = 0; item < metadata.arraySize; ++item )
{
size_t w = metadata.width;
size_t h = metadata.height;
for( size_t level=0; level < metadata.mipLevels; ++level )
{
if ( index >= nImages )
{
return false;
}
size_t rowPitch, slicePitch;
ComputePitch( metadata.format, w, h, rowPitch, slicePitch, cpFlags );
images[index].width = w;
images[index].height = h;
images[index].format = metadata.format;
images[index].rowPitch = rowPitch;
images[index].slicePitch = slicePitch;
images[index].pixels = pixels;
++index;
pixels += slicePitch;
if ( pixels > pEndBits )
{
return false;
}
if ( h > 1 )
h >>= 1;
if ( w > 1 )
w >>= 1;
}
}
return true;
case TEX_DIMENSION_TEXTURE3D:
{
size_t w = metadata.width;
size_t h = metadata.height;
size_t d = metadata.depth;
for( size_t level=0; level < metadata.mipLevels; ++level )
{
size_t rowPitch, slicePitch;
ComputePitch( metadata.format, w, h, rowPitch, slicePitch, cpFlags );
for( size_t slice=0; slice < d; ++slice )
{
if ( index >= nImages )
{
return false;
}
// We use the same memory organization that Direct3D 11 needs for D3D11_SUBRESOURCE_DATA
// with all slices of a given miplevel being continuous in memory
images[index].width = w;
images[index].height = h;
images[index].format = metadata.format;
images[index].rowPitch = rowPitch;
images[index].slicePitch = slicePitch;
images[index].pixels = pixels;
++index;
pixels += slicePitch;
if ( pixels > pEndBits )
{
return false;
}
}
if ( h > 1 )
h >>= 1;
if ( w > 1 )
w >>= 1;
if ( d > 1 )
d >>= 1;
}
}
return true;
default:
return false;
}
}
//=====================================================================================
// ScratchImage - Bitmap image container
//=====================================================================================
//-------------------------------------------------------------------------------------
// Methods
//-------------------------------------------------------------------------------------
HRESULT ScratchImage::Initialize( const TexMetadata& mdata )
{
if ( !IsValid(mdata.format) || IsVideo(mdata.format) )
return E_INVALIDARG;
size_t mipLevels = mdata.mipLevels;
switch( mdata.dimension )
{
case TEX_DIMENSION_TEXTURE1D:
if ( !mdata.width || mdata.height != 1 || mdata.depth != 1 || !mdata.arraySize )
return E_INVALIDARG;
if ( !_CalculateMipLevels(mdata.width,1,mipLevels) )
return E_INVALIDARG;
break;
case TEX_DIMENSION_TEXTURE2D:
if ( !mdata.width || !mdata.height || mdata.depth != 1 || !mdata.arraySize )
return E_INVALIDARG;
if ( mdata.miscFlags & TEX_MISC_TEXTURECUBE )
{
if ( (mdata.arraySize % 6) != 0 )
return E_INVALIDARG;
}
if ( !_CalculateMipLevels(mdata.width,mdata.height,mipLevels) )
return E_INVALIDARG;
break;
case TEX_DIMENSION_TEXTURE3D:
if ( !mdata.width || !mdata.height || !mdata.depth || mdata.arraySize != 1 )
return E_INVALIDARG;
if ( !_CalculateMipLevels3D(mdata.width,mdata.height,mdata.depth,mipLevels) )
return E_INVALIDARG;
break;
default:
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
}
Release();
_metadata.width = mdata.width;
_metadata.height = mdata.height;
_metadata.depth = mdata.depth;
_metadata.arraySize = mdata.arraySize;
_metadata.mipLevels = mipLevels;
_metadata.miscFlags = mdata.miscFlags & TEX_MISC_TEXTURECUBE;
_metadata.format = mdata.format;
_metadata.dimension = mdata.dimension;
size_t pixelSize, nimages;
_DetermineImageArray( _metadata, CP_FLAGS_NONE, nimages, pixelSize );
_image = new Image[ nimages ];
if ( !_image )
return E_OUTOFMEMORY;
_nimages = nimages;
memset( _image, 0, sizeof(Image) * nimages );
_memory = reinterpret_cast<uint8_t*>( _aligned_malloc( pixelSize, 16 ) );
if ( !_memory )
{
Release();
return E_OUTOFMEMORY;
}
_size = pixelSize;
if ( !_SetupImageArray( _memory, pixelSize, _metadata, CP_FLAGS_NONE, _image, nimages ) )
{
Release();
return E_FAIL;
}
return S_OK;
}
HRESULT ScratchImage::Initialize1D( DXGI_FORMAT fmt, size_t length, size_t arraySize, size_t mipLevels )
{
if ( !IsValid(fmt) || IsVideo(fmt) || !length || !arraySize )
return E_INVALIDARG;
// 1D is a special case of the 2D case
HRESULT hr = Initialize2D( fmt, length, 1, arraySize, mipLevels );
if ( FAILED(hr) )
return hr;
_metadata.dimension = TEX_DIMENSION_TEXTURE1D;
return S_OK;
}
HRESULT ScratchImage::Initialize2D( DXGI_FORMAT fmt, size_t width, size_t height, size_t arraySize, size_t mipLevels )
{
if ( !IsValid(fmt) || IsVideo(fmt) || !width || !height || !arraySize )
return E_INVALIDARG;
if ( !_CalculateMipLevels(width,height,mipLevels) )
return E_INVALIDARG;
Release();
_metadata.width = width;
_metadata.height = height;
_metadata.depth = 1;
_metadata.arraySize = arraySize;
_metadata.mipLevels = mipLevels;
_metadata.miscFlags = 0;
_metadata.format = fmt;
_metadata.dimension = TEX_DIMENSION_TEXTURE2D;
size_t pixelSize, nimages;
_DetermineImageArray( _metadata, CP_FLAGS_NONE, nimages, pixelSize );
_image = new Image[ nimages ];
if ( !_image )
return E_OUTOFMEMORY;
_nimages = nimages;
memset( _image, 0, sizeof(Image) * nimages );
_memory = reinterpret_cast<uint8_t*>( _aligned_malloc( pixelSize, 16 ) );
if ( !_memory )
{
Release();
return E_OUTOFMEMORY;
}
_size = pixelSize;
if ( !_SetupImageArray( _memory, pixelSize, _metadata, CP_FLAGS_NONE, _image, nimages ) )
{
Release();
return E_FAIL;
}
return S_OK;
}
HRESULT ScratchImage::Initialize3D( DXGI_FORMAT fmt, size_t width, size_t height, size_t depth, size_t mipLevels )
{
if ( !IsValid(fmt) || IsVideo(fmt) || !width || !height || !depth )
return E_INVALIDARG;
if ( !_CalculateMipLevels3D(width,height,depth,mipLevels) )
return E_INVALIDARG;
Release();
_metadata.width = width;
_metadata.height = height;
_metadata.depth = depth;
_metadata.arraySize = 1; // Direct3D 10.x/11 does not support arrays of 3D textures
_metadata.mipLevels = mipLevels;
_metadata.miscFlags = 0;
_metadata.format = fmt;
_metadata.dimension = TEX_DIMENSION_TEXTURE3D;
size_t pixelSize, nimages;
_DetermineImageArray( _metadata, CP_FLAGS_NONE, nimages, pixelSize );
_image = new Image[ nimages ];
if ( !_image )
{
Release();
return E_OUTOFMEMORY;
}
_nimages = nimages;
memset( _image, 0, sizeof(Image) * nimages );
_memory = reinterpret_cast<uint8_t*>( _aligned_malloc( pixelSize, 16 ) );
if ( !_memory )
{
Release();
return E_OUTOFMEMORY;
}
_size = pixelSize;
if ( !_SetupImageArray( _memory, pixelSize, _metadata, CP_FLAGS_NONE, _image, nimages ) )
{
Release();
return E_FAIL;
}
return S_OK;
}
HRESULT ScratchImage::InitializeCube( DXGI_FORMAT fmt, size_t width, size_t height, size_t nCubes, size_t mipLevels )
{
if ( !IsValid(fmt) || IsVideo(fmt) || !width || !height || !nCubes )
return E_INVALIDARG;
// A DirectX11 cubemap is just a 2D texture array that is a multiple of 6 for each cube
HRESULT hr = Initialize2D( fmt, width, height, nCubes * 6, mipLevels );
if ( FAILED(hr) )
return hr;
_metadata.miscFlags |= TEX_MISC_TEXTURECUBE;
return S_OK;
}
HRESULT ScratchImage::InitializeFromImage( const Image& srcImage, bool allow1D )
{
HRESULT hr = ( srcImage.height > 1 || !allow1D )
? Initialize2D( srcImage.format, srcImage.width, srcImage.height, 1, 1 )
: Initialize1D( srcImage.format, srcImage.width, 1, 1 );
if ( FAILED(hr) )
return hr;
const uint8_t* sptr = reinterpret_cast<const uint8_t*>( srcImage.pixels );
if ( !sptr )
return E_POINTER;
uint8_t* dptr = reinterpret_cast<uint8_t*>( _image[0].pixels );
if ( !dptr )
return E_POINTER;
for( size_t y = 0; y < srcImage.height; ++y )
{
_CopyScanline( dptr, _image[0].rowPitch, sptr, srcImage.rowPitch, srcImage.format, TEXP_SCANLINE_NONE );
sptr += srcImage.rowPitch;
dptr += _image[0].rowPitch;
}
return S_OK;
}
HRESULT ScratchImage::InitializeArrayFromImages( const Image* images, size_t nImages, bool allow1D )
{
if ( !images || !nImages )
return E_INVALIDARG;
DXGI_FORMAT format = images[0].format;
size_t width = images[0].width;
size_t height = images[0].height;
for( size_t index=0; index < nImages; ++index )
{
if ( !images[index].pixels )
return E_POINTER;
if ( images[index].format != format || images[index].width != width || images[index].height != height )
{
// All images must be the same format, width, and height
return E_FAIL;
}
}
HRESULT hr = ( height > 1 || !allow1D )
? Initialize2D( format, width, height, nImages, 1 )
: Initialize1D( format, width, nImages, 1 );
if ( FAILED(hr) )
return hr;
for( size_t index=0; index < nImages; ++index )
{
const uint8_t* sptr = reinterpret_cast<const uint8_t*>( images[index].pixels );
if ( !sptr )
return E_POINTER;
assert( index < _nimages );
uint8_t* dptr = reinterpret_cast<uint8_t*>( _image[index].pixels );
if ( !dptr )
return E_POINTER;
for( size_t y = 0; y < height; ++y )
{
_CopyScanline( dptr, _image[index].rowPitch, sptr, images[index].rowPitch, format, TEXP_SCANLINE_NONE );
sptr += images[index].rowPitch;
dptr += _image[index].rowPitch;
}
}
return S_OK;
}
HRESULT ScratchImage::InitializeCubeFromImages( const Image* images, size_t nImages )
{
if ( !images || !nImages )
return E_INVALIDARG;
// A DirectX11 cubemap is just a 2D texture array that is a multiple of 6 for each cube
if ( ( nImages % 6 ) != 0 )
return E_INVALIDARG;
HRESULT hr = InitializeArrayFromImages( images, nImages, false );
if ( FAILED(hr) )
return hr;
_metadata.miscFlags |= TEX_MISC_TEXTURECUBE;
return S_OK;
}
HRESULT ScratchImage::Initialize3DFromImages( const Image* images, size_t depth )
{
if ( !images || !depth )
return E_INVALIDARG;
DXGI_FORMAT format = images[0].format;
size_t width = images[0].width;
size_t height = images[0].height;
for( size_t slice=0; slice < depth; ++slice )
{
if ( !images[slice].pixels )
return E_POINTER;
if ( images[slice].format != format || images[slice].width != width || images[slice].height != height )
{
// All images must be the same format, width, and height
return E_FAIL;
}
}
HRESULT hr = Initialize3D( format, width, height, depth, 1 );
if ( FAILED(hr) )
return hr;
for( size_t slice=0; slice < depth; ++slice )
{
const uint8_t* sptr = reinterpret_cast<const uint8_t*>( images[slice].pixels );
if ( !sptr )
return E_POINTER;
assert( slice < _nimages );
uint8_t* dptr = reinterpret_cast<uint8_t*>( _image[slice].pixels );
if ( !dptr )
return E_POINTER;
for( size_t y = 0; y < height; ++y )
{
_CopyScanline( dptr, _image[slice].rowPitch, sptr, images[slice].rowPitch, format, TEXP_SCANLINE_NONE );
sptr += images[slice].rowPitch;
dptr += _image[slice].rowPitch;
}
}
return S_OK;
}
void ScratchImage::Release()
{
_nimages = 0;
_size = 0;
if ( _image )
{
delete [] _image;
_image = 0;
}
if ( _memory )
{
_aligned_free( _memory );
_memory = 0;
}
memset(&_metadata, 0, sizeof(_metadata));
}
const Image* ScratchImage::GetImage(size_t mip, size_t item, size_t slice) const
{
if ( mip >= _metadata.mipLevels )
return nullptr;
size_t index = 0;
switch( _metadata.dimension )
{
case TEX_DIMENSION_TEXTURE1D:
case TEX_DIMENSION_TEXTURE2D:
if ( slice > 0 )
return nullptr;
if ( item >= _metadata.arraySize )
return nullptr;
index = item*( _metadata.mipLevels ) + mip;
break;
case TEX_DIMENSION_TEXTURE3D:
if ( item > 0 )
{
// No support for arrays of volumes
return nullptr;
}
else
{
size_t d = _metadata.depth;
for( size_t level = 0; level < mip; ++level )
{
index += d;
if ( d > 1 )
d >>= 1;
}
if ( slice >= d )
return nullptr;
index += slice;
}
break;
default:
return nullptr;
}
return &_image[index];
}
}; // namespace

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,265 @@
//-------------------------------------------------------------------------------------
// DirectXTexMisc.cpp
//
// DirectX Texture Library - Misc image operations
//
// 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
//-------------------------------------------------------------------------------------
#include "directxtexp.h"
namespace DirectX
{
//-------------------------------------------------------------------------------------
static HRESULT _ComputeMSE( _In_ const Image& image1, _In_ const Image& image2,
_Out_ float& mse, _Out_opt_cap_c_(4) float* mseV )
{
if ( !image1.pixels || !image2.pixels )
return E_POINTER;
assert( image1.width == image2.width && image1.height == image2.height );
assert( !IsCompressed( image1.format ) && !IsCompressed( image2.format ) );
const size_t width = image1.width;
ScopedAlignedArrayXMVECTOR scanline( reinterpret_cast<XMVECTOR*>( _aligned_malloc( (sizeof(XMVECTOR)*width)*2, 16 ) ) );
if ( !scanline )
return E_OUTOFMEMORY;
const uint8_t *pSrc1 = image1.pixels;
const size_t rowPitch1 = image1.rowPitch;
const uint8_t *pSrc2 = image2.pixels;
const size_t rowPitch2 = image2.rowPitch;
XMVECTOR acc = XMVectorZero();
for( size_t h = 0; h < image1.height; ++h )
{
XMVECTOR* ptr1 = scanline.get();
if ( !_LoadScanline( ptr1, width, pSrc1, rowPitch1, image1.format ) )
return E_FAIL;
XMVECTOR* ptr2 = scanline.get() + width;
if ( !_LoadScanline( ptr2, width, pSrc2, rowPitch2, image2.format ) )
return E_FAIL;
for( size_t i = 0; i < width; ++i, ++ptr1, ++ptr2 )
{
// sum[ (I1 - I2)^2 ]
XMVECTOR v = XMVectorSubtract( *ptr1, *ptr2 );
acc = XMVectorMultiplyAdd( v, v, acc );
}
pSrc1 += rowPitch1;
pSrc2 += rowPitch2;
}
// MSE = sum[ (I1 - I2)^2 ] / w*h
XMVECTOR d = XMVectorReplicate( float(image1.width * image1.height) );
XMVECTOR v = XMVectorDivide( acc, d );
if ( mseV )
{
XMStoreFloat4( reinterpret_cast<XMFLOAT4*>( mseV ), v );
mse = mseV[0] + mseV[1] + mseV[2] + mseV[3];
}
else
{
XMFLOAT4 _mseV;
XMStoreFloat4( &_mseV, v );
mse = _mseV.x + _mseV.y + _mseV.z + _mseV.w;
}
return S_OK;
}
//=====================================================================================
// Entry points
//=====================================================================================
//-------------------------------------------------------------------------------------
// Copies a rectangle from one image into another
//-------------------------------------------------------------------------------------
HRESULT CopyRectangle( const Image& srcImage, const Rect& srcRect, const Image& dstImage, DWORD filter, size_t xOffset, size_t yOffset )
{
if ( !srcImage.pixels || !dstImage.pixels )
return E_POINTER;
if ( IsCompressed( srcImage.format ) || IsCompressed( dstImage.format ) )
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
// Validate rectangle/offset
if ( !srcRect.w || !srcRect.h || ( (srcRect.x + srcRect.w) > srcImage.width ) || ( (srcRect.y + srcRect.h) > srcImage.height ) )
{
return E_INVALIDARG;
}
if ( ( (xOffset + srcRect.w) > dstImage.width ) || ( (yOffset + srcRect.h) > dstImage.height ) )
{
return E_INVALIDARG;
}
// Compute source bytes-per-pixel
size_t sbpp = BitsPerPixel( srcImage.format );
if ( !sbpp )
return E_FAIL;
if ( sbpp < 8 )
{
// We don't support monochrome (DXGI_FORMAT_R1_UNORM)
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
}
const uint8_t* pEndSrc = srcImage.pixels + srcImage.rowPitch*srcImage.height;
const uint8_t* pEndDest = dstImage.pixels + dstImage.rowPitch*dstImage.height;
// Round to bytes
sbpp = ( sbpp + 7 ) / 8;
const uint8_t* pSrc = srcImage.pixels + (srcRect.y * srcImage.rowPitch) + (srcRect.x * sbpp);
if ( srcImage.format == dstImage.format )
{
// Direct copy case (avoid intermediate conversions)
uint8_t* pDest = dstImage.pixels + (yOffset * dstImage.rowPitch) + (xOffset * sbpp);
const size_t copyW = srcRect.w * sbpp;
for( size_t h=0; h < srcRect.h; ++h )
{
if ( ( (pSrc+copyW) > pEndSrc ) || (pDest > pEndDest) )
return E_FAIL;
memcpy_s( pDest, pEndDest - pDest, pSrc, copyW );
pSrc += srcImage.rowPitch;
pDest += dstImage.rowPitch;
}
return S_OK;
}
// Compute destination bytes-per-pixel (not the same format as source)
size_t dbpp = BitsPerPixel( dstImage.format );
if ( !dbpp )
return E_FAIL;
if ( dbpp < 8 )
{
// We don't support monochrome (DXGI_FORMAT_R1_UNORM)
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
}
// Round to bytes
dbpp = ( dbpp + 7 ) / 8;
uint8_t* pDest = dstImage.pixels + (yOffset * dstImage.rowPitch) + (xOffset * dbpp);
ScopedAlignedArrayXMVECTOR scanline( reinterpret_cast<XMVECTOR*>( _aligned_malloc( (sizeof(XMVECTOR)*srcRect.w), 16 ) ) );
if ( !scanline )
return E_OUTOFMEMORY;
const size_t copyS = srcRect.w * sbpp;
const size_t copyD = srcRect.w * dbpp;
for( size_t h=0; h < srcRect.h; ++h )
{
if ( ( (pSrc+copyS) > pEndSrc) || ((pDest+copyD) > pEndDest) )
return E_FAIL;
if ( !_LoadScanline( scanline.get(), srcRect.w, pSrc, copyS, srcImage.format ) )
return E_FAIL;
_ConvertScanline( scanline.get(), srcRect.w, dstImage.format, srcImage.format, filter );
if ( !_StoreScanline( pDest, copyD, dstImage.format, scanline.get(), srcRect.w ) )
return E_FAIL;
pSrc += srcImage.rowPitch;
pDest += dstImage.rowPitch;
}
return S_OK;
}
//-------------------------------------------------------------------------------------
// Computes the Mean-Squared-Error (MSE) between two images
//-------------------------------------------------------------------------------------
HRESULT ComputeMSE( const Image& image1, const Image& image2, float& mse, float* mseV )
{
if ( !image1.pixels || !image2.pixels )
return E_POINTER;
if ( image1.width != image2.width || image1.height != image2.height )
return E_INVALIDARG;
if ( IsCompressed(image1.format) )
{
if ( IsCompressed(image2.format) )
{
// Case 1: both images are compressed, expand to RGBA32F
ScratchImage temp1;
HRESULT hr = Decompress( image1, DXGI_FORMAT_R32G32B32A32_FLOAT, temp1 );
if ( FAILED(hr) )
return hr;
ScratchImage temp2;
hr = Decompress( image2, DXGI_FORMAT_R32G32B32A32_FLOAT, temp2 );
if ( FAILED(hr) )
return hr;
const Image* img1 = temp1.GetImage(0,0,0);
const Image* img2 = temp2.GetImage(0,0,0);
if ( !img1 || !img2 )
return E_POINTER;
return _ComputeMSE( *img1, *img2, mse, mseV );
}
else
{
// Case 2: image1 is compressed, expand to RGBA32F
ScratchImage temp;
HRESULT hr = Decompress( image1, DXGI_FORMAT_R32G32B32A32_FLOAT, temp );
if ( FAILED(hr) )
return hr;
const Image* img = temp.GetImage(0,0,0);
if ( !img )
return E_POINTER;
return _ComputeMSE( *img, image2, mse, mseV );
}
}
else
{
if ( IsCompressed(image2.format) )
{
// Case 3: image2 is compressed, expand to RGBA32F
ScratchImage temp;
HRESULT hr = Decompress( image2, DXGI_FORMAT_R32G32B32A32_FLOAT, temp );
if ( FAILED(hr) )
return hr;
const Image* img = temp.GetImage(0,0,0);
if ( !img )
return E_POINTER;
return _ComputeMSE( image1, *img, mse, mseV );
}
else
{
// Case 4: neither image is compressed
return _ComputeMSE( image1, image2, mse, mseV );
}
}
}
}; // namespace

View File

@ -0,0 +1,377 @@
//-------------------------------------------------------------------------------------
// DirectXTexNormalMaps.cpp
//
// DirectX Texture Library - Normal map operations
//
// 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
//-------------------------------------------------------------------------------------
#include "directxtexp.h"
namespace DirectX
{
#pragma prefast(suppress : 25000, "FXMVECTOR is 16 bytes")
static inline float _EvaluateColor( _In_ FXMVECTOR val, _In_ DWORD flags )
{
XMFLOAT4A f;
static XMVECTORF32 lScale = { 0.2125f, 0.7154f, 0.0721f, 1.f };
static_assert( CNMAP_CHANNEL_RED == 0x1, "CNMAP_CHANNEL_ flag values don't match mask" );
switch( flags & 0xf )
{
case 0:
case CNMAP_CHANNEL_RED: return XMVectorGetX( val );
case CNMAP_CHANNEL_GREEN: return XMVectorGetY( val );
case CNMAP_CHANNEL_BLUE: return XMVectorGetZ( val );
case CNMAP_CHANNEL_ALPHA: return XMVectorGetW( val );
case CNMAP_CHANNEL_LUMINANCE:
{
XMVECTOR v = XMVectorMultiply( val, lScale );
XMStoreFloat4A( &f, v );
return f.x + f.y + f.z;
}
break;
default:
assert(false);
return 0.f;
}
}
static void _EvaluateRow( _In_count_(width) const XMVECTOR* pSource, _Out_cap_(width+2) float* pDest,
_In_ size_t width, _In_ DWORD flags )
{
assert( pSource && pDest );
assert( width > 0 );
for( size_t x = 0; x < width; ++x )
{
pDest[x+1] = _EvaluateColor( pSource[x], flags );
}
if ( flags & CNMAP_MIRROR_U )
{
// Mirror in U
pDest[0] = _EvaluateColor( pSource[0], flags );
pDest[width+1] = _EvaluateColor( pSource[width-1], flags );
}
else
{
// Wrap in U
pDest[0] = _EvaluateColor( pSource[width-1], flags );
pDest[width+1] = _EvaluateColor( pSource[0], flags );
}
}
static HRESULT _ComputeNMap( _In_ const Image& srcImage, _In_ DWORD flags, _In_ float amplitude,
_In_ DXGI_FORMAT format, _In_ const Image& normalMap )
{
if ( !srcImage.pixels || !normalMap.pixels )
return E_INVALIDARG;
assert( !IsCompressed(format) && !IsTypeless( format ) );
const DWORD convFlags = _GetConvertFlags( format );
if ( !convFlags )
return E_FAIL;
if ( !( convFlags & (CONVF_UNORM | CONVF_SNORM | CONVF_FLOAT) ) )
HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
const size_t width = srcImage.width;
const size_t height = srcImage.height;
if ( width != normalMap.width || height != normalMap.height )
return E_FAIL;
// Allocate temporary space (4 scanlines and 3 evaluated rows)
ScopedAlignedArrayXMVECTOR scanline( reinterpret_cast<XMVECTOR*>( _aligned_malloc( (sizeof(XMVECTOR)*width*4), 16 ) ) );
if ( !scanline )
return E_OUTOFMEMORY;
ScopedAlignedArrayFloat buffer( reinterpret_cast<float*>( _aligned_malloc( ( ( sizeof(float) * ( width + 2 ) ) * 3 ), 16 ) ) );
if ( !buffer )
return E_OUTOFMEMORY;
uint8_t* pDest = normalMap.pixels;
if ( !pDest )
return E_POINTER;
XMVECTOR* row0 = scanline.get();
XMVECTOR* row1 = row0 + width;
XMVECTOR* row2 = row1 + width;
XMVECTOR* target = row2 + width;
float* val0 = buffer.get();
float* val1 = val0 + width + 2;
float* val2 = val1 + width + 2;
const size_t rowPitch = srcImage.rowPitch;
const uint8_t* pSrc = srcImage.pixels;
// Read first scanline row into 'row1'
if ( !_LoadScanline( row1, width, pSrc, rowPitch, srcImage.format ) )
return E_FAIL;
// Setup 'row0'
if ( flags & CNMAP_MIRROR_V )
{
// Mirror first row
memcpy_s( row0, rowPitch, row1, rowPitch );
}
else
{
// Read last row (Wrap V)
if ( !_LoadScanline( row0, width, pSrc + (rowPitch * (height-1)), rowPitch, srcImage.format ) )
return E_FAIL;
}
// Evaluate the initial rows
_EvaluateRow( row0, val0, width, flags );
_EvaluateRow( row1, val1, width, flags );
pSrc += rowPitch;
for( size_t y = 0; y < height; ++y )
{
// Load next scanline of source image
if ( y < (height-1) )
{
if ( !_LoadScanline( row2, width, pSrc, rowPitch, srcImage.format ) )
return E_FAIL;
}
else
{
if ( flags & CNMAP_MIRROR_V )
{
// Use last row of source image
if ( !_LoadScanline( row2, width, srcImage.pixels + (rowPitch * (height-1)), rowPitch, srcImage.format ) )
return E_FAIL;
}
else
{
// Use first row of source image (Wrap V)
if ( !_LoadScanline( row2, width, srcImage.pixels, rowPitch, srcImage.format ) )
return E_FAIL;
}
}
// Evaluate row
_EvaluateRow( row2, val2, width, flags );
// Generate target scanline
XMVECTOR *dptr = target;
for( size_t x = 0; x < width; ++x )
{
// Compute normal via central differencing
float totDelta = ( val0[x] - val0[x+2] ) + ( val1[x] - val1[x+2] ) + ( val2[x] - val2[x+2] );
float deltaZX = totDelta * amplitude / 6.f;
totDelta = ( val0[x] - val2[x] ) + ( val0[x+1] - val2[x+1] ) + ( val0[x+2] - val2[x+2] );
float deltaZY = totDelta * amplitude / 6.f;
XMVECTOR vx = XMVectorSetZ( g_XMNegIdentityR0, deltaZX ); // (-1.0f, 0.0f, deltaZX)
XMVECTOR vy = XMVectorSetZ( g_XMNegIdentityR1, deltaZY ); // (0.0f, -1.0f, deltaZY)
XMVECTOR normal = XMVector3Normalize( XMVector3Cross( vx, vy ) );
// Compute alpha (1.0 or an occlusion term)
float alpha = 1.f;
if ( flags & CNMAP_COMPUTE_OCCLUSION )
{
float delta = 0.f;
float c = val1[x+1];
float t = val0[x] - c; if ( t > 0.f ) delta += t;
t = val0[x+1] - c; if ( t > 0.f ) delta += t;
t = val0[x+2] - c; if ( t > 0.f ) delta += t;
t = val1[x] - c; if ( t > 0.f ) delta += t;
// Skip current pixel
t = val1[x+2] - c; if ( t > 0.f ) delta += t;
t = val2[x] - c; if ( t > 0.f ) delta += t;
t = val2[x+1] - c; if ( t > 0.f ) delta += t;
t = val2[x+2] - c; if ( t > 0.f ) delta += t;
// Average delta (divide by 8, scale by amplitude factor)
delta *= 0.125f * amplitude;
if ( delta > 0.f )
{
// If < 0, then no occlusion
float r = sqrtf( 1.f + delta*delta );
alpha = (r - delta) / r;
}
}
// Encode based on target format
if ( convFlags & CONVF_UNORM )
{
// 0.5f*normal + 0.5f -or- invert sign case: -0.5f*normal + 0.5f
XMVECTOR n1 = XMVectorMultiplyAdd( (flags & CNMAP_INVERT_SIGN) ? g_XMNegativeOneHalf : g_XMOneHalf, normal, g_XMOneHalf );
*dptr++ = XMVectorSetW( n1, alpha );
}
else if ( flags & CNMAP_INVERT_SIGN )
{
*dptr++ = XMVectorSetW( XMVectorNegate( normal ), alpha );
}
else
{
*dptr++ = XMVectorSetW( normal, alpha );
}
}
if ( !_StoreScanline( pDest, normalMap.rowPitch, format, target, width ) )
return E_FAIL;
// Cycle buffers
float* temp = val0;
val0 = val1;
val1 = val2;
val2 = temp;
pSrc += rowPitch;
pDest += normalMap.rowPitch;
}
return S_OK;
}
//=====================================================================================
// Entry points
//=====================================================================================
//-------------------------------------------------------------------------------------
// Generates a normal map from a height-map
//-------------------------------------------------------------------------------------
HRESULT ComputeNormalMap( const Image& srcImage, DWORD flags, float amplitude,
DXGI_FORMAT format, ScratchImage& normalMap )
{
if ( !srcImage.pixels || !IsValid(format) || IsCompressed( format ) || IsTypeless( format ) )
return E_INVALIDARG;
static_assert( CNMAP_CHANNEL_RED == 0x1, "CNMAP_CHANNEL_ flag values don't match mask" );
switch( flags & 0xf )
{
case 0:
case CNMAP_CHANNEL_RED:
case CNMAP_CHANNEL_GREEN:
case CNMAP_CHANNEL_BLUE:
case CNMAP_CHANNEL_ALPHA:
case CNMAP_CHANNEL_LUMINANCE:
break;
default:
return E_INVALIDARG;
}
if ( IsCompressed( srcImage.format ) || IsTypeless( srcImage.format ) )
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
// Setup target image
normalMap.Release();
HRESULT hr = normalMap.Initialize2D( format, srcImage.width, srcImage.height, 1, 1 );
if ( FAILED(hr) )
return hr;
const Image *img = normalMap.GetImage( 0, 0, 0 );
if ( !img )
{
normalMap.Release();
return E_POINTER;
}
hr = _ComputeNMap( srcImage, flags, amplitude, format, *img );
if ( FAILED(hr) )
{
normalMap.Release();
return hr;
}
return S_OK;
}
HRESULT ComputeNormalMap( const Image* srcImages, size_t nimages, const TexMetadata& metadata,
DWORD flags, float amplitude, DXGI_FORMAT format, ScratchImage& normalMaps )
{
if ( !srcImages || !nimages )
return E_INVALIDARG;
if ( !IsValid(format) || IsCompressed(format) || IsTypeless(format) )
return E_INVALIDARG;
static_assert( CNMAP_CHANNEL_RED == 0x1, "CNMAP_CHANNEL_ flag values don't match mask" );
switch( flags & 0xf )
{
case 0:
case CNMAP_CHANNEL_RED:
case CNMAP_CHANNEL_GREEN:
case CNMAP_CHANNEL_BLUE:
case CNMAP_CHANNEL_ALPHA:
case CNMAP_CHANNEL_LUMINANCE:
break;
default:
return E_INVALIDARG;
}
normalMaps.Release();
TexMetadata mdata2 = metadata;
mdata2.format = format;
HRESULT hr = normalMaps.Initialize( mdata2 );
if ( FAILED(hr) )
return hr;
if ( nimages != normalMaps.GetImageCount() )
{
normalMaps.Release();
return E_FAIL;
}
const Image* dest = normalMaps.GetImages();
if ( !dest )
{
normalMaps.Release();
return E_POINTER;
}
for( size_t index=0; index < nimages; ++index )
{
assert( dest[ index ].format == format );
const Image& src = srcImages[ index ];
if ( IsCompressed( src.format ) || IsTypeless( src.format ) )
{
normalMaps.Release();
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
}
if ( src.width != dest[ index ].width || src.height != dest[ index ].height )
{
normalMaps.Release();
return E_FAIL;
}
hr = _ComputeNMap( src, flags, amplitude, format, dest[ index ] );
if ( FAILED(hr) )
{
normalMaps.Release();
return hr;
}
}
return S_OK;
}
}; // namespace

209
DirectXTex/DirectXTexP.h Normal file
View File

@ -0,0 +1,209 @@
//-------------------------------------------------------------------------------------
// DirectXTexp.h
//
// DirectX Texture Library - Private header
//
// 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
#define NOMINMAX
#include <windows.h>
#ifdef USE_XNAMATH
#include <xnamath.h>
#else
#include <directxmath.h>
#include <directxpackedvector.h>
#endif
#include <assert.h>
#include <malloc.h>
#include <memory>
#include <vector>
#include <stdlib.h>
#include <search.h>
#include <ole2.h>
#pragma warning(push)
#pragma warning(disable : 4005)
#include <wincodec.h>
#pragma warning(pop)
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) && !defined(DXGI_1_2_FORMATS)
#define DXGI_1_2_FORMATS
#endif
#include "directxtex.h"
#include "scoped.h"
struct IWICImagingFactory;
#define TEX_FILTER_MASK 0xF00000
namespace DirectX
{
#ifdef USE_XNAMATH
template<uint32_t SwizzleX, uint32_t SwizzleY, uint32_t SwizzleZ, uint32_t SwizzleW>
inline XMVECTOR XMVectorSwizzle(FXMVECTOR V)
{
return XMVectorSwizzle( V, SwizzleX, SwizzleY, SwizzleZ, SwizzleW );
}
template<uint32_t PermuteX, uint32_t PermuteY, uint32_t PermuteZ, uint32_t PermuteW>
inline XMVECTOR XMVectorPermute(FXMVECTOR V1, FXMVECTOR V2)
{
static XMVECTORI32 control = { PermuteX, PermuteY, PermuteZ, PermuteW };
return XMVectorPermute( V1, V2, control );
}
#endif // USE_XNAMATH
//---------------------------------------------------------------------------------
// WIC helper functions
DXGI_FORMAT _WICToDXGI( _In_ const GUID& guid );
bool _DXGIToWIC( _In_ DXGI_FORMAT format, _Out_ GUID& guid );
size_t _WICBitsPerPixel( _In_ REFGUID targetGuid );
IWICImagingFactory* _GetWIC();
inline WICBitmapDitherType _GetWICDither( _In_ DWORD flags )
{
static_assert( TEX_FILTER_DITHER == 0x10000, "TEX_FILTER_DITHER* flag values don't match mask" );
static_assert( TEX_FILTER_DITHER == WIC_FLAGS_DITHER, "TEX_FILTER_DITHER* should match WIC_FLAGS_DITHER*" );
static_assert( TEX_FILTER_DITHER_DIFFUSION == WIC_FLAGS_DITHER_DIFFUSION, "TEX_FILTER_DITHER* should match WIC_FLAGS_DITHER*" );
switch( flags & 0xF0000 )
{
case TEX_FILTER_DITHER:
return WICBitmapDitherTypeOrdered4x4;
case TEX_FILTER_DITHER_DIFFUSION:
return WICBitmapDitherTypeErrorDiffusion;
default:
return WICBitmapDitherTypeNone;
}
}
inline WICBitmapInterpolationMode _GetWICInterp( _In_ DWORD flags )
{
static_assert( TEX_FILTER_POINT == 0x100000, "TEX_FILTER_ flag values don't match TEX_FILTER_MASK" );
static_assert( TEX_FILTER_POINT == WIC_FLAGS_FILTER_POINT, "TEX_FILTER_* flags should match WIC_FLAGS_FILTER_*" );
static_assert( TEX_FILTER_LINEAR == WIC_FLAGS_FILTER_LINEAR, "TEX_FILTER_* flags should match WIC_FLAGS_FILTER_*" );
static_assert( TEX_FILTER_CUBIC == WIC_FLAGS_FILTER_CUBIC, "TEX_FILTER_* flags should match WIC_FLAGS_FILTER_*" );
static_assert( TEX_FILTER_FANT == WIC_FLAGS_FILTER_FANT, "TEX_FILTER_* flags should match WIC_FLAGS_FILTER_*" );
switch( flags & TEX_FILTER_MASK )
{
case TEX_FILTER_POINT:
return WICBitmapInterpolationModeNearestNeighbor;
case TEX_FILTER_LINEAR:
return WICBitmapInterpolationModeLinear;
case TEX_FILTER_CUBIC:
return WICBitmapInterpolationModeCubic;
case TEX_FILTER_FANT:
default:
return WICBitmapInterpolationModeFant;
}
}
//---------------------------------------------------------------------------------
// Image helper functions
void _DetermineImageArray( _In_ const TexMetadata& metadata, _In_ DWORD cpFlags,
_Out_ size_t& nImages, _Out_ size_t& pixelSize );
bool _SetupImageArray( _In_bytecount_(pixelSize) uint8_t *pMemory, _In_ size_t pixelSize,
_In_ const TexMetadata& metadata, _In_ DWORD cpFlags,
_Out_cap_(nImages) Image* images, _In_ size_t nImages );
//---------------------------------------------------------------------------------
// Conversion helper functions
enum TEXP_SCANLINE_FLAGS
{
TEXP_SCANLINE_NONE = 0,
TEXP_SCANLINE_SETALPHA = 0x1, // Set alpha channel to known opaque value
TEXP_SCANLINE_LEGACY = 0x2, // Enables specific legacy format conversion cases
};
enum CONVERT_FLAGS
{
CONVF_FLOAT = 0x1,
CONVF_UNORM = 0x2,
CONVF_UINT = 0x4,
CONVF_SNORM = 0x8,
CONVF_SINT = 0x10,
CONVF_DEPTH = 0x20,
CONVF_STENCIL = 0x40,
CONVF_SHAREDEXP = 0x80,
CONVF_BGR = 0x100,
CONVF_X2 = 0x200,
CONVF_PACKED = 0x400,
CONVF_BC = 0x800,
CONVF_R = 0x10000,
CONVF_G = 0x20000,
CONVF_B = 0x40000,
CONVF_A = 0x80000,
CONVF_RGB_MASK = 0x70000,
CONVF_RGBA_MASK = 0xF0000,
};
DWORD _GetConvertFlags( _In_ DXGI_FORMAT format );
void _CopyScanline( _Out_bytecap_(outSize) LPVOID pDestination, _In_ size_t outSize,
_In_bytecount_(inSize) LPCVOID pSource, _In_ size_t inSize,
_In_ DXGI_FORMAT format, _In_ DWORD flags );
void _SwizzleScanline( _Out_bytecap_(outSize) LPVOID pDestination, _In_ size_t outSize,
_In_bytecount_(inSize) LPCVOID pSource, _In_ size_t inSize,
_In_ DXGI_FORMAT format, _In_ DWORD flags );
bool _ExpandScanline( _Out_bytecap_(outSize) LPVOID pDestination, _In_ size_t outSize,
_In_ DXGI_FORMAT outFormat,
_In_bytecount_(inSize) LPCVOID pSource, _In_ size_t inSize,
_In_ DXGI_FORMAT inFormat, _In_ DWORD flags );
bool _LoadScanline( _Out_cap_(count) XMVECTOR* pDestination, _In_ size_t count,
_In_bytecount_(size) LPCVOID pSource, _In_ size_t size, _In_ DXGI_FORMAT format );
bool _StoreScanline( _Out_bytecap_(size) LPVOID pDestination, _In_ size_t size, _In_ DXGI_FORMAT format,
_In_count_(count) const XMVECTOR* pSource, _In_ size_t count );
HRESULT _ConvertToR32G32B32A32( _In_ const Image& srcImage, _Inout_ ScratchImage& image );
HRESULT _ConvertFromR32G32B32A32( _In_ const Image& srcImage, _In_ const Image& destImage );
HRESULT _ConvertFromR32G32B32A32( _In_ const Image& srcImage, _In_ DXGI_FORMAT format, _Inout_ ScratchImage& image );
HRESULT _ConvertFromR32G32B32A32( _In_count_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DXGI_FORMAT format, _Out_ ScratchImage& result );
void _ConvertScanline( _Inout_count_(count) XMVECTOR* pBuffer, _In_ size_t count,
_In_ DXGI_FORMAT outFormat, _In_ DXGI_FORMAT inFormat, _In_ DWORD flags );
//---------------------------------------------------------------------------------
// DDS helper functions
HRESULT _EncodeDDSHeader( _In_ const TexMetadata& metadata, DWORD flags,
_Out_opt_cap_x_(maxsize) LPVOID pDestination, _In_ size_t maxsize, _Out_ size_t& required );
}; // namespace

View File

@ -0,0 +1,358 @@
//-------------------------------------------------------------------------------------
// DirectXTexResize.cpp
//
// DirectX Texture Library - Image resizing operations
//
// 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
//-------------------------------------------------------------------------------------
#include "directxtexp.h"
namespace DirectX
{
extern HRESULT _ResizeSeparateColorAndAlpha( _In_ IWICImagingFactory* pWIC, _In_ IWICBitmap* original,
_In_ size_t newWidth, _In_ size_t newHeight, _In_ DWORD filter, _Inout_ const Image* img );
//-------------------------------------------------------------------------------------
// Do image resize using WIC
//-------------------------------------------------------------------------------------
static HRESULT _PerformResizeUsingWIC( _In_ const Image& srcImage, _In_ DWORD filter,
_In_ const WICPixelFormatGUID& pfGUID, _In_ const Image& destImage )
{
if ( !srcImage.pixels || !destImage.pixels )
return E_POINTER;
assert( srcImage.format == destImage.format );
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return E_NOINTERFACE;
ScopedObject<IWICComponentInfo> componentInfo;
HRESULT hr = pWIC->CreateComponentInfo( pfGUID, &componentInfo );
if ( FAILED(hr) )
return hr;
ScopedObject<IWICPixelFormatInfo2> pixelFormatInfo;
hr = componentInfo->QueryInterface( __uuidof(IWICPixelFormatInfo2), (void**)&pixelFormatInfo );
if ( FAILED(hr) )
return hr;
BOOL supportsTransparency = FALSE;
hr = pixelFormatInfo->SupportsTransparency( &supportsTransparency );
if ( FAILED(hr) )
return hr;
ScopedObject<IWICBitmap> source;
hr = pWIC->CreateBitmapFromMemory( static_cast<UINT>( srcImage.width ), static_cast<UINT>( srcImage.height ), pfGUID,
static_cast<UINT>( srcImage.rowPitch ), static_cast<UINT>( srcImage.slicePitch ),
srcImage.pixels, &source );
if ( FAILED(hr) )
return hr;
if ( (filter & TEX_FILTER_SEPARATE_ALPHA) && supportsTransparency )
{
hr = _ResizeSeparateColorAndAlpha( pWIC, source.Get(), destImage.width, destImage.height, filter, &destImage );
if ( FAILED(hr) )
return hr;
}
else
{
ScopedObject<IWICBitmapScaler> scaler;
hr = pWIC->CreateBitmapScaler( &scaler );
if ( FAILED(hr) )
return hr;
hr = scaler->Initialize( source.Get(), static_cast<UINT>( destImage.width ), static_cast<UINT>( destImage.height ), _GetWICInterp( filter ) );
if ( FAILED(hr) )
return hr;
WICPixelFormatGUID pfScaler;
hr = scaler->GetPixelFormat( &pfScaler );
if ( FAILED(hr) )
return hr;
if ( memcmp( &pfScaler, &pfGUID, sizeof(WICPixelFormatGUID) ) == 0 )
{
hr = scaler->CopyPixels( 0, static_cast<UINT>( destImage.rowPitch ), static_cast<UINT>( destImage.slicePitch ), destImage.pixels );
if ( FAILED(hr) )
return hr;
}
else
{
// The WIC bitmap scaler is free to return a different pixel format than the source image, so here we
// convert it back
ScopedObject<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( &FC );
if ( FAILED(hr) )
return hr;
hr = FC->Initialize( scaler.Get(), pfGUID, _GetWICDither( filter ), 0, 0, WICBitmapPaletteTypeCustom );
if ( FAILED(hr) )
return hr;
hr = FC->CopyPixels( 0, static_cast<UINT>( destImage.rowPitch ), static_cast<UINT>( destImage.slicePitch ), destImage.pixels );
if ( FAILED(hr) )
return hr;
}
}
return S_OK;
}
//-------------------------------------------------------------------------------------
// Do conversion, resize using WIC, conversion cycle
//-------------------------------------------------------------------------------------
static HRESULT _PerformResizeViaF32( _In_ const Image& srcImage, _In_ DWORD filter, _In_ const Image& destImage )
{
if ( !srcImage.pixels || !destImage.pixels )
return E_POINTER;
assert( srcImage.format != DXGI_FORMAT_R32G32B32A32_FLOAT );
assert( srcImage.format == destImage.format );
ScratchImage temp;
HRESULT hr = _ConvertToR32G32B32A32( srcImage, temp );
if ( FAILED(hr) )
return hr;
const Image *tsrc = temp.GetImage( 0, 0, 0 );
if ( !tsrc )
return E_POINTER;
ScratchImage rtemp;
hr = rtemp.Initialize2D( DXGI_FORMAT_R32G32B32A32_FLOAT, destImage.width, destImage.height, 1, 1 );
if ( FAILED(hr) )
return hr;
const Image *tdest = rtemp.GetImage( 0, 0, 0 );
if ( !tdest )
return E_POINTER;
hr = _PerformResizeUsingWIC( *tsrc, filter, GUID_WICPixelFormat128bppRGBAFloat, *tdest );
if ( FAILED(hr) )
return hr;
temp.Release();
hr = _ConvertFromR32G32B32A32( *tdest, destImage );
if ( FAILED(hr) )
return hr;
return S_OK;
}
//=====================================================================================
// Entry-points
//=====================================================================================
//-------------------------------------------------------------------------------------
// Resize image
//-------------------------------------------------------------------------------------
HRESULT Resize( const Image& srcImage, size_t width, size_t height, DWORD filter, ScratchImage& image )
{
if ( width == 0 || height == 0 )
return E_INVALIDARG;
#ifdef _AMD64_
if ( (srcImage.width > 0xFFFFFFFF) || (srcImage.height > 0xFFFFFFFF) )
return E_INVALIDARG;
if ( (width > 0xFFFFFFFF) || (height > 0xFFFFFFFF) )
return E_INVALIDARG;
#endif
if ( !srcImage.pixels )
return E_POINTER;
if ( IsCompressed( srcImage.format ) )
{
// We don't support resizing compressed images
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
}
HRESULT hr = image.Initialize2D( srcImage.format, width, height, 1, 1 );
if ( FAILED(hr) )
return hr;
const Image *rimage = image.GetImage( 0, 0, 0 );
if ( !rimage )
return E_POINTER;
// WIC only supports CLAMP
WICPixelFormatGUID pfGUID;
if ( _DXGIToWIC( srcImage.format, pfGUID ) )
{
// Case 1: Source format is supported by Windows Imaging Component
hr = _PerformResizeUsingWIC( srcImage, filter, pfGUID, *rimage );
}
else
{
// Case 2: Source format is not supported by WIC, so we have to convert, resize, and convert back
hr = _PerformResizeViaF32( srcImage, filter, *rimage );
}
if ( FAILED(hr) )
{
image.Release();
return hr;
}
return S_OK;
}
//-------------------------------------------------------------------------------------
// Resize image (complex)
//-------------------------------------------------------------------------------------
HRESULT Resize( const Image* srcImages, size_t nimages, const TexMetadata& metadata,
size_t width, size_t height, DWORD filter, ScratchImage& result )
{
if ( !srcImages || !nimages || width == 0 || height == 0 )
return E_INVALIDARG;
#ifdef _AMD64_
if ( (width > 0xFFFFFFFF) || (height > 0xFFFFFFFF) )
return E_INVALIDARG;
#endif
TexMetadata mdata2 = metadata;
mdata2.width = width;
mdata2.height = height;
mdata2.mipLevels = 1;
HRESULT hr = result.Initialize( mdata2 );
if ( FAILED(hr) )
return hr;
WICPixelFormatGUID pfGUID;
bool wicpf = _DXGIToWIC( metadata.format, pfGUID );
switch ( metadata.dimension )
{
case TEX_DIMENSION_TEXTURE1D:
case TEX_DIMENSION_TEXTURE2D:
assert( metadata.depth == 1 );
for( size_t item = 0; item < metadata.arraySize; ++item )
{
size_t srcIndex = metadata.ComputeIndex( 0, item, 0 );
if ( srcIndex >= nimages )
{
result.Release();
return E_FAIL;
}
const Image* srcimg = &srcImages[ srcIndex ];
const Image* destimg = result.GetImage( 0, item, 0 );
if ( !srcimg || !destimg )
{
result.Release();
return E_POINTER;
}
if ( srcimg->format != metadata.format )
{
result.Release();
return E_FAIL;
}
#ifdef _AMD64_
if ( (srcimg->width > 0xFFFFFFFF) || (srcimg->height > 0xFFFFFFFF) )
{
result.Release();
return E_FAIL;
}
#endif
if ( wicpf )
{
// Case 1: Source format is supported by Windows Imaging Component
hr = _PerformResizeUsingWIC( *srcimg, filter, pfGUID, *destimg );
}
else
{
// Case 2: Source format is not supported by WIC, so we have to convert, resize, and convert back
hr = _PerformResizeViaF32( *srcimg, filter, *destimg );
}
if ( FAILED(hr) )
{
result.Release();
return hr;
}
}
break;
case TEX_DIMENSION_TEXTURE3D:
assert( metadata.arraySize == 1 );
for( size_t slice = 0; slice < metadata.depth; ++slice )
{
size_t srcIndex = metadata.ComputeIndex( 0, 0, slice );
if ( srcIndex >= nimages )
{
result.Release();
return E_FAIL;
}
const Image* srcimg = &srcImages[ srcIndex ];
const Image* destimg = result.GetImage( 0, 0, slice );
if ( !srcimg || !destimg )
{
result.Release();
return E_POINTER;
}
if ( srcimg->format != metadata.format )
{
result.Release();
return E_FAIL;
}
#ifdef _AMD64_
if ( (srcimg->width > 0xFFFFFFFF) || (srcimg->height > 0xFFFFFFFF) )
{
result.Release();
return E_FAIL;
}
#endif
if ( wicpf )
{
// Case 1: Source format is supported by Windows Imaging Component
hr = _PerformResizeUsingWIC( *srcimg, filter, pfGUID, *destimg );
}
else
{
// Case 2: Source format is not supported by WIC, so we have to convert, resize, and convert back
hr = _PerformResizeViaF32( *srcimg, filter, *destimg );
}
if ( FAILED(hr) )
{
result.Release();
return hr;
}
}
break;
default:
result.Release();
return E_FAIL;
}
return S_OK;
}
}; // namespace

1386
DirectXTex/DirectXTexTGA.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,525 @@
//-------------------------------------------------------------------------------------
// DirectXTexUtil.cpp
//
// DirectX Texture Library - Utilities
//
// 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
//-------------------------------------------------------------------------------------
#include "directxtexp.h"
//-------------------------------------------------------------------------------------
// WIC Pixel Format Translation Data
//-------------------------------------------------------------------------------------
struct WICTranslate
{
GUID wic;
DXGI_FORMAT format;
};
static WICTranslate g_WICFormats[] =
{
{ GUID_WICPixelFormat128bppRGBAFloat, DXGI_FORMAT_R32G32B32A32_FLOAT },
{ GUID_WICPixelFormat64bppRGBAHalf, DXGI_FORMAT_R16G16B16A16_FLOAT },
{ GUID_WICPixelFormat64bppRGBA, DXGI_FORMAT_R16G16B16A16_UNORM },
{ GUID_WICPixelFormat32bppRGBA, DXGI_FORMAT_R8G8B8A8_UNORM },
{ GUID_WICPixelFormat32bppBGRA, DXGI_FORMAT_B8G8R8A8_UNORM }, // DXGI 1.1
{ GUID_WICPixelFormat32bppBGR, DXGI_FORMAT_B8G8R8X8_UNORM }, // DXGI 1.1
{ GUID_WICPixelFormat32bppRGBA1010102XR, DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM }, // DXGI 1.1
{ GUID_WICPixelFormat32bppRGBA1010102, DXGI_FORMAT_R10G10B10A2_UNORM },
{ GUID_WICPixelFormat32bppRGBE, DXGI_FORMAT_R9G9B9E5_SHAREDEXP },
{ GUID_WICPixelFormat16bppBGRA5551, DXGI_FORMAT_B5G5R5A1_UNORM },
{ GUID_WICPixelFormat16bppBGR565, DXGI_FORMAT_B5G6R5_UNORM },
{ GUID_WICPixelFormat32bppGrayFloat, DXGI_FORMAT_R32_FLOAT },
{ GUID_WICPixelFormat16bppGrayHalf, DXGI_FORMAT_R16_FLOAT },
{ GUID_WICPixelFormat16bppGray, DXGI_FORMAT_R16_UNORM },
{ GUID_WICPixelFormat8bppGray, DXGI_FORMAT_R8_UNORM },
{ GUID_WICPixelFormat8bppAlpha, DXGI_FORMAT_A8_UNORM },
{ GUID_WICPixelFormatBlackWhite, DXGI_FORMAT_R1_UNORM },
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
{ GUID_WICPixelFormat96bppRGBFloat, DXGI_FORMAT_R32G32B32_FLOAT },
#endif
};
namespace DirectX
{
//=====================================================================================
// WIC Utilities
//=====================================================================================
DXGI_FORMAT _WICToDXGI( const GUID& guid )
{
for( size_t i=0; i < _countof(g_WICFormats); ++i )
{
if ( memcmp( &g_WICFormats[i].wic, &guid, sizeof(GUID) ) == 0 )
return g_WICFormats[i].format;
}
return DXGI_FORMAT_UNKNOWN;
}
bool _DXGIToWIC( DXGI_FORMAT format, GUID& guid )
{
for( size_t i=0; i < _countof(g_WICFormats); ++i )
{
if ( g_WICFormats[i].format == format )
{
memcpy( &guid, &g_WICFormats[i].wic, sizeof(GUID) );
return true;
}
}
// Special cases
switch( format )
{
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
memcpy( &guid, &GUID_WICPixelFormat32bppRGBA, sizeof(GUID) );
return true;
case DXGI_FORMAT_D32_FLOAT:
memcpy( &guid, &GUID_WICPixelFormat32bppGrayFloat, sizeof(GUID) );
return true;
case DXGI_FORMAT_D16_UNORM:
memcpy( &guid, &GUID_WICPixelFormat16bppGray, sizeof(GUID) );
return true;
case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
memcpy( &guid, &GUID_WICPixelFormat32bppBGRA, sizeof(GUID) );
return true;
case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
memcpy( &guid, &GUID_WICPixelFormat32bppBGR, sizeof(GUID) );
return true;
}
memcpy( &guid, &GUID_NULL, sizeof(GUID) );
return false;
}
size_t _WICBitsPerPixel( REFGUID targetGuid )
{
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return 0;
ScopedObject<IWICComponentInfo> cinfo;
if ( FAILED( pWIC->CreateComponentInfo( targetGuid, &cinfo ) ) )
return 0;
WICComponentType type;
if ( FAILED( cinfo->GetComponentType( &type ) ) )
return 0;
if ( type != WICPixelFormat )
return 0;
ScopedObject<IWICPixelFormatInfo> pfinfo;
if ( FAILED( cinfo->QueryInterface( __uuidof(IWICPixelFormatInfo), reinterpret_cast<void**>( &pfinfo ) ) ) )
return 0;
UINT bpp;
if ( FAILED( pfinfo->GetBitsPerPixel( &bpp ) ) )
return 0;
return bpp;
}
IWICImagingFactory* _GetWIC()
{
static IWICImagingFactory* s_Factory = nullptr;
if ( s_Factory )
return s_Factory;
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory),
(LPVOID*)&s_Factory
);
if ( FAILED(hr) )
{
s_Factory = nullptr;
return nullptr;
}
return s_Factory;
}
//-------------------------------------------------------------------------------------
// Public helper function to get common WIC codec GUIDs
//-------------------------------------------------------------------------------------
REFGUID GetWICCodec( _In_ WICCodecs codec )
{
switch( codec )
{
case WIC_CODEC_BMP:
return GUID_ContainerFormatBmp;
case WIC_CODEC_JPEG:
return GUID_ContainerFormatJpeg;
case WIC_CODEC_PNG:
return GUID_ContainerFormatPng;
case WIC_CODEC_TIFF:
return GUID_ContainerFormatTiff;
case WIC_CODEC_GIF:
return GUID_ContainerFormatGif;
case WIC_CODEC_WMP:
return GUID_ContainerFormatWmp;
case WIC_CODEC_ICO:
return GUID_ContainerFormatIco;
default:
return GUID_NULL;
}
}
//=====================================================================================
// DXGI Format Utilities
//=====================================================================================
//-------------------------------------------------------------------------------------
// Returns bits-per-pixel for a given DXGI format, or 0 on failure
//-------------------------------------------------------------------------------------
size_t BitsPerPixel( DXGI_FORMAT fmt )
{
switch( fmt )
{
case DXGI_FORMAT_R32G32B32A32_TYPELESS:
case DXGI_FORMAT_R32G32B32A32_FLOAT:
case DXGI_FORMAT_R32G32B32A32_UINT:
case DXGI_FORMAT_R32G32B32A32_SINT:
return 128;
case DXGI_FORMAT_R32G32B32_TYPELESS:
case DXGI_FORMAT_R32G32B32_FLOAT:
case DXGI_FORMAT_R32G32B32_UINT:
case DXGI_FORMAT_R32G32B32_SINT:
return 96;
case DXGI_FORMAT_R16G16B16A16_TYPELESS:
case DXGI_FORMAT_R16G16B16A16_FLOAT:
case DXGI_FORMAT_R16G16B16A16_UNORM:
case DXGI_FORMAT_R16G16B16A16_UINT:
case DXGI_FORMAT_R16G16B16A16_SNORM:
case DXGI_FORMAT_R16G16B16A16_SINT:
case DXGI_FORMAT_R32G32_TYPELESS:
case DXGI_FORMAT_R32G32_FLOAT:
case DXGI_FORMAT_R32G32_UINT:
case DXGI_FORMAT_R32G32_SINT:
case DXGI_FORMAT_R32G8X24_TYPELESS:
case DXGI_FORMAT_D32_FLOAT_S8X24_UINT:
case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS:
case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT:
return 64;
case DXGI_FORMAT_R10G10B10A2_TYPELESS:
case DXGI_FORMAT_R10G10B10A2_UNORM:
case DXGI_FORMAT_R10G10B10A2_UINT:
case DXGI_FORMAT_R11G11B10_FLOAT:
case DXGI_FORMAT_R8G8B8A8_TYPELESS:
case DXGI_FORMAT_R8G8B8A8_UNORM:
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
case DXGI_FORMAT_R8G8B8A8_UINT:
case DXGI_FORMAT_R8G8B8A8_SNORM:
case DXGI_FORMAT_R8G8B8A8_SINT:
case DXGI_FORMAT_R16G16_TYPELESS:
case DXGI_FORMAT_R16G16_FLOAT:
case DXGI_FORMAT_R16G16_UNORM:
case DXGI_FORMAT_R16G16_UINT:
case DXGI_FORMAT_R16G16_SNORM:
case DXGI_FORMAT_R16G16_SINT:
case DXGI_FORMAT_R32_TYPELESS:
case DXGI_FORMAT_D32_FLOAT:
case DXGI_FORMAT_R32_FLOAT:
case DXGI_FORMAT_R32_UINT:
case DXGI_FORMAT_R32_SINT:
case DXGI_FORMAT_R24G8_TYPELESS:
case DXGI_FORMAT_D24_UNORM_S8_UINT:
case DXGI_FORMAT_R24_UNORM_X8_TYPELESS:
case DXGI_FORMAT_X24_TYPELESS_G8_UINT:
case DXGI_FORMAT_R9G9B9E5_SHAREDEXP:
case DXGI_FORMAT_R8G8_B8G8_UNORM:
case DXGI_FORMAT_G8R8_G8B8_UNORM:
case DXGI_FORMAT_B8G8R8A8_UNORM:
case DXGI_FORMAT_B8G8R8X8_UNORM:
case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM:
case DXGI_FORMAT_B8G8R8A8_TYPELESS:
case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
case DXGI_FORMAT_B8G8R8X8_TYPELESS:
case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
return 32;
case DXGI_FORMAT_R8G8_TYPELESS:
case DXGI_FORMAT_R8G8_UNORM:
case DXGI_FORMAT_R8G8_UINT:
case DXGI_FORMAT_R8G8_SNORM:
case DXGI_FORMAT_R8G8_SINT:
case DXGI_FORMAT_R16_TYPELESS:
case DXGI_FORMAT_R16_FLOAT:
case DXGI_FORMAT_D16_UNORM:
case DXGI_FORMAT_R16_UNORM:
case DXGI_FORMAT_R16_UINT:
case DXGI_FORMAT_R16_SNORM:
case DXGI_FORMAT_R16_SINT:
case DXGI_FORMAT_B5G6R5_UNORM:
case DXGI_FORMAT_B5G5R5A1_UNORM:
return 16;
case DXGI_FORMAT_R8_TYPELESS:
case DXGI_FORMAT_R8_UNORM:
case DXGI_FORMAT_R8_UINT:
case DXGI_FORMAT_R8_SNORM:
case DXGI_FORMAT_R8_SINT:
case DXGI_FORMAT_A8_UNORM:
return 8;
case DXGI_FORMAT_R1_UNORM:
return 1;
case DXGI_FORMAT_BC1_TYPELESS:
case DXGI_FORMAT_BC1_UNORM:
case DXGI_FORMAT_BC1_UNORM_SRGB:
case DXGI_FORMAT_BC4_TYPELESS:
case DXGI_FORMAT_BC4_UNORM:
case DXGI_FORMAT_BC4_SNORM:
return 4;
case DXGI_FORMAT_BC2_TYPELESS:
case DXGI_FORMAT_BC2_UNORM:
case DXGI_FORMAT_BC2_UNORM_SRGB:
case DXGI_FORMAT_BC3_TYPELESS:
case DXGI_FORMAT_BC3_UNORM:
case DXGI_FORMAT_BC3_UNORM_SRGB:
case DXGI_FORMAT_BC5_TYPELESS:
case DXGI_FORMAT_BC5_UNORM:
case DXGI_FORMAT_BC5_SNORM:
case DXGI_FORMAT_BC6H_TYPELESS:
case DXGI_FORMAT_BC6H_UF16:
case DXGI_FORMAT_BC6H_SF16:
case DXGI_FORMAT_BC7_TYPELESS:
case DXGI_FORMAT_BC7_UNORM:
case DXGI_FORMAT_BC7_UNORM_SRGB:
return 8;
#ifdef DXGI_1_2_FORMATS
case DXGI_FORMAT_B4G4R4A4_UNORM:
return 16;
// We don't support the video formats ( see IsVideo function )
#endif // DXGI_1_2_FORMATS
default:
return 0;
}
}
//-------------------------------------------------------------------------------------
// Computes the image row pitch in bytes, and the slice ptich (size in bytes of the image)
// based on DXGI format, width, and height
//-------------------------------------------------------------------------------------
void ComputePitch( DXGI_FORMAT fmt, size_t width, size_t height,
size_t& rowPitch, size_t& slicePitch, DWORD flags )
{
assert( IsValid(fmt) && !IsVideo(fmt) );
if ( IsCompressed(fmt) )
{
size_t bpb = ( fmt == DXGI_FORMAT_BC1_TYPELESS
|| fmt == DXGI_FORMAT_BC1_UNORM
|| fmt == DXGI_FORMAT_BC1_UNORM_SRGB
|| fmt == DXGI_FORMAT_BC4_TYPELESS
|| fmt == DXGI_FORMAT_BC4_UNORM
|| fmt == DXGI_FORMAT_BC4_SNORM) ? 8 : 16;
size_t nbw = std::max<size_t>( 1, (width + 3) / 4 );
size_t nbh = std::max<size_t>( 1, (height + 3) / 4 );
rowPitch = nbw * bpb;
slicePitch = rowPitch * nbh;
}
else if ( IsPacked(fmt) )
{
rowPitch = ( ( width + 1 ) >> 1) * 4;
slicePitch = rowPitch * height;
}
else
{
size_t bpp;
if ( flags & CP_FLAGS_24BPP )
bpp = 24;
else if ( flags & CP_FLAGS_16BPP )
bpp = 16;
else if ( flags & CP_FLAGS_8BPP )
bpp = 8;
else
bpp = BitsPerPixel( fmt );
if ( flags & CP_FLAGS_LEGACY_DWORD )
{
// Special computation for some incorrectly created DDS files based on
// legacy DirectDraw assumptions about pitch alignment
rowPitch = ( ( width * bpp + 31 ) / 32 ) * sizeof(uint32_t);
slicePitch = rowPitch * height;
}
else
{
rowPitch = ( width * bpp + 7 ) / 8;
slicePitch = rowPitch * height;
}
}
}
//-------------------------------------------------------------------------------------
// Converts to an SRGB equivalent type if available
//-------------------------------------------------------------------------------------
DXGI_FORMAT MakeSRGB( _In_ DXGI_FORMAT fmt )
{
switch( fmt )
{
case DXGI_FORMAT_R8G8B8A8_UNORM:
return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
case DXGI_FORMAT_BC1_UNORM:
return DXGI_FORMAT_BC1_UNORM_SRGB;
case DXGI_FORMAT_BC2_UNORM:
return DXGI_FORMAT_BC2_UNORM_SRGB;
case DXGI_FORMAT_BC3_UNORM:
return DXGI_FORMAT_BC3_UNORM_SRGB;
case DXGI_FORMAT_B8G8R8A8_UNORM:
return DXGI_FORMAT_B8G8R8A8_UNORM_SRGB;
case DXGI_FORMAT_B8G8R8X8_UNORM:
return DXGI_FORMAT_B8G8R8X8_UNORM_SRGB;
case DXGI_FORMAT_BC7_UNORM:
return DXGI_FORMAT_BC7_UNORM_SRGB;
default:
return fmt;
}
}
//=====================================================================================
// TexMetadata
//=====================================================================================
size_t TexMetadata::ComputeIndex( _In_ size_t mip, _In_ size_t item, _In_ size_t slice ) const
{
if ( mip >= mipLevels )
return size_t(-1);
switch( dimension )
{
case TEX_DIMENSION_TEXTURE1D:
case TEX_DIMENSION_TEXTURE2D:
if ( slice > 0 )
return size_t(-1);
if ( item >= arraySize )
return size_t(-1);
return (item*( mipLevels ) + mip);
case TEX_DIMENSION_TEXTURE3D:
if ( item > 0 )
{
// No support for arrays of volumes
return size_t(-1);
}
else
{
size_t index = 0;
size_t d = depth;
for( size_t level = 0; level < mip; ++level )
{
index += d;
if ( d > 1 )
d >>= 1;
}
if ( slice >= d )
return size_t(-1);
index += slice;
return index;
}
break;
default:
return size_t(-1);
}
}
//=====================================================================================
// Blob - Bitmap image container
//=====================================================================================
void Blob::Release()
{
if ( _buffer )
{
_aligned_free( _buffer );
_buffer = nullptr;
}
_size = 0;
}
HRESULT Blob::Initialize( size_t size )
{
if ( !size )
return E_INVALIDARG;
Release();
_buffer = _aligned_malloc( size, 16 );
if ( !_buffer )
{
Release();
return E_OUTOFMEMORY;
}
_size = size;
return S_OK;
}
}; // namespace

View File

@ -0,0 +1,941 @@
//-------------------------------------------------------------------------------------
// DirectXTexWIC.cpp
//
// DirectX Texture Library - WIC-based file reader/writer
//
// 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
//-------------------------------------------------------------------------------------
#include "directxtexp.h"
//-------------------------------------------------------------------------------------
// WIC Pixel Format nearest conversion table
//-------------------------------------------------------------------------------------
struct WICConvert
{
GUID source;
GUID target;
};
static WICConvert g_WICConvert[] =
{
// Directly support the formats listed in XnaTexUtil::g_WICFormats, so no conversion required
// Note target GUID in this conversion table must be one of those directly supported formats.
{ GUID_WICPixelFormat1bppIndexed, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat2bppIndexed, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat4bppIndexed, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat8bppIndexed, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat2bppGray, GUID_WICPixelFormat8bppGray }, // DXGI_FORMAT_R8_UNORM
{ GUID_WICPixelFormat4bppGray, GUID_WICPixelFormat8bppGray }, // DXGI_FORMAT_R8_UNORM
{ GUID_WICPixelFormat16bppGrayFixedPoint, GUID_WICPixelFormat16bppGrayHalf }, // DXGI_FORMAT_R16_FLOAT
{ GUID_WICPixelFormat32bppGrayFixedPoint, GUID_WICPixelFormat32bppGrayFloat }, // DXGI_FORMAT_R32_FLOAT
{ GUID_WICPixelFormat16bppBGR555, GUID_WICPixelFormat16bppBGRA5551 }, // DXGI_FORMAT_B5G5R5A1_UNORM
{ GUID_WICPixelFormat32bppBGR101010, GUID_WICPixelFormat32bppRGBA1010102 }, // DXGI_FORMAT_R10G10B10A2_UNORM
{ GUID_WICPixelFormat24bppBGR, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat24bppRGB, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat32bppPBGRA, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat32bppPRGBA, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat48bppRGB, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat48bppBGR, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat64bppBGRA, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat64bppPRGBA, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat64bppPBGRA, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat48bppRGBFixedPoint, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat48bppBGRFixedPoint, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat64bppRGBAFixedPoint, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat64bppBGRAFixedPoint, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat64bppRGBFixedPoint, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat64bppRGBHalf, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat48bppRGBHalf, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat96bppRGBFixedPoint, GUID_WICPixelFormat128bppRGBAFloat }, // DXGI_FORMAT_R32G32B32A32_FLOAT
{ GUID_WICPixelFormat128bppPRGBAFloat, GUID_WICPixelFormat128bppRGBAFloat }, // DXGI_FORMAT_R32G32B32A32_FLOAT
{ GUID_WICPixelFormat128bppRGBFloat, GUID_WICPixelFormat128bppRGBAFloat }, // DXGI_FORMAT_R32G32B32A32_FLOAT
{ GUID_WICPixelFormat128bppRGBAFixedPoint, GUID_WICPixelFormat128bppRGBAFloat }, // DXGI_FORMAT_R32G32B32A32_FLOAT
{ GUID_WICPixelFormat128bppRGBFixedPoint, GUID_WICPixelFormat128bppRGBAFloat }, // DXGI_FORMAT_R32G32B32A32_FLOAT
{ GUID_WICPixelFormat32bppCMYK, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat64bppCMYK, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat40bppCMYKAlpha, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat80bppCMYKAlpha, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
{ GUID_WICPixelFormat32bppRGB, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat64bppRGB, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat64bppPRGBAHalf, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
#endif
// We don't support n-channel formats
};
namespace DirectX
{
//-------------------------------------------------------------------------------------
// Returns the DXGI format and optionally the WIC pixel GUID to convert to
//-------------------------------------------------------------------------------------
static DXGI_FORMAT _DetermineFormat( _In_ const WICPixelFormatGUID& pixelFormat, _In_ DWORD flags,
_Out_opt_ WICPixelFormatGUID* pConvert )
{
if ( pConvert )
memset( pConvert, 0, sizeof(WICPixelFormatGUID) );
DXGI_FORMAT format = _WICToDXGI( pixelFormat );
if ( format == DXGI_FORMAT_UNKNOWN )
{
for( size_t i=0; i < _countof(g_WICConvert); ++i )
{
if ( memcmp( &g_WICConvert[i].source, &pixelFormat, sizeof(WICPixelFormatGUID) ) == 0 )
{
if ( pConvert )
memcpy( pConvert, &g_WICConvert[i].target, sizeof(WICPixelFormatGUID) );
format = _WICToDXGI( g_WICConvert[i].target );
assert( format != DXGI_FORMAT_UNKNOWN );
break;
}
}
}
// Handle special cases based on flags
switch (format)
{
case DXGI_FORMAT_B8G8R8A8_UNORM: // BGRA
case DXGI_FORMAT_B8G8R8X8_UNORM: // BGRX
if ( flags & WIC_FLAGS_FORCE_RGB )
{
format = DXGI_FORMAT_R8G8B8A8_UNORM;
if ( pConvert )
memcpy( pConvert, &GUID_WICPixelFormat32bppRGBA, sizeof(WICPixelFormatGUID) );
}
break;
case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM:
if ( flags & WIC_FLAGS_NO_X2_BIAS )
{
format = DXGI_FORMAT_R10G10B10A2_UNORM;
if ( pConvert )
memcpy( pConvert, &GUID_WICPixelFormat32bppRGBA1010102, sizeof(WICPixelFormatGUID) );
}
break;
case DXGI_FORMAT_B5G5R5A1_UNORM:
case DXGI_FORMAT_B5G6R5_UNORM:
if ( flags & WIC_FLAGS_NO_16BPP )
{
format = DXGI_FORMAT_R8G8B8A8_UNORM;
if ( pConvert )
memcpy( pConvert, &GUID_WICPixelFormat32bppRGBA, sizeof(WICPixelFormatGUID) );
}
break;
case DXGI_FORMAT_R1_UNORM:
if ( !(flags & WIC_FLAGS_ALLOW_MONO ) )
{
// By default we want to promote a black & white to gresycale since R1 is not a generally supported D3D format
format = DXGI_FORMAT_R8_UNORM;
if ( pConvert )
memcpy( pConvert, &GUID_WICPixelFormat8bppGray, sizeof(WICPixelFormatGUID) );
}
}
return format;
}
//-------------------------------------------------------------------------------------
// Determines metadata for image
//-------------------------------------------------------------------------------------
static HRESULT _DecodeMetadata( _In_ DWORD flags,
_In_ IWICBitmapDecoder *decoder, _In_ IWICBitmapFrameDecode *frame,
_Out_ TexMetadata& metadata, _Out_opt_ WICPixelFormatGUID* pConvert )
{
if ( !decoder || !frame )
return E_POINTER;
memset( &metadata, 0, sizeof(TexMetadata) );
metadata.depth = 1;
metadata.mipLevels = 1;
metadata.dimension = TEX_DIMENSION_TEXTURE2D;
UINT w, h;
HRESULT hr = frame->GetSize( &w, &h );
if ( FAILED(hr) )
return hr;
metadata.width = w;
metadata.height = h;
if ( flags & WIC_FLAGS_ALL_FRAMES )
{
UINT fcount;
hr = decoder->GetFrameCount( &fcount );
if ( FAILED(hr) )
return hr;
metadata.arraySize = fcount;
}
else
metadata.arraySize = 1;
WICPixelFormatGUID pixelFormat;
hr = frame->GetPixelFormat( &pixelFormat );
if ( FAILED(hr) )
return hr;
metadata.format = _DetermineFormat( pixelFormat, flags, pConvert );
if ( metadata.format == DXGI_FORMAT_UNKNOWN )
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
return S_OK;
}
//-------------------------------------------------------------------------------------
// Decodes a single frame
//-------------------------------------------------------------------------------------
static HRESULT _DecodeSingleFrame( _In_ DWORD flags, _In_ const TexMetadata& metadata, _In_ const WICPixelFormatGUID& convertGUID,
_In_ IWICBitmapFrameDecode *frame, _Inout_ ScratchImage& image )
{
if ( !frame )
return E_POINTER;
HRESULT hr = image.Initialize2D( metadata.format, metadata.width, metadata.height, 1, 1 );
if ( FAILED(hr) )
return hr;
const Image *img = image.GetImage( 0, 0, 0 );
if ( !img )
return E_POINTER;
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return E_NOINTERFACE;
if ( memcmp( &convertGUID, &GUID_NULL, sizeof(GUID) ) == 0 )
{
hr = frame->CopyPixels( 0, static_cast<UINT>( img->rowPitch ), static_cast<UINT>( img->slicePitch ), img->pixels );
if ( FAILED(hr) )
return hr;
}
else
{
ScopedObject<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( &FC );
if ( FAILED(hr) )
return hr;
hr = FC->Initialize( frame, convertGUID, _GetWICDither( flags ), 0, 0, WICBitmapPaletteTypeCustom );
if ( FAILED(hr) )
return hr;
hr = FC->CopyPixels( 0, static_cast<UINT>( img->rowPitch ), static_cast<UINT>( img->slicePitch ), img->pixels );
if ( FAILED(hr) )
return hr;
}
return S_OK;
}
//-------------------------------------------------------------------------------------
// Decodes an image array, resizing/format converting as needed
//-------------------------------------------------------------------------------------
static HRESULT _DecodeMultiframe( _In_ DWORD flags, _In_ const TexMetadata& metadata,
_In_ IWICBitmapDecoder *decoder, _Inout_ ScratchImage& image )
{
if ( !decoder )
return E_POINTER;
HRESULT hr = image.Initialize2D( metadata.format, metadata.width, metadata.height, metadata.arraySize, 1 );
if ( FAILED(hr) )
return hr;
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return E_NOINTERFACE;
WICPixelFormatGUID sourceGUID;
if ( !_DXGIToWIC( metadata.format, sourceGUID ) )
return E_FAIL;
for( size_t index = 0; index < metadata.arraySize; ++index )
{
const Image* img = image.GetImage( 0, index, 0 );
if ( !img )
return E_POINTER;
ScopedObject<IWICBitmapFrameDecode> frame;
hr = decoder->GetFrame( static_cast<UINT>( index ), &frame );
if ( FAILED(hr) )
return hr;
WICPixelFormatGUID pfGuid;
hr = frame->GetPixelFormat( &pfGuid );
if ( FAILED(hr) )
return hr;
UINT w, h;
hr = frame->GetSize( &w, &h );
if ( FAILED(hr) )
return hr;
if ( memcmp( &pfGuid, &sourceGUID, sizeof(WICPixelFormatGUID) ) == 0 )
{
if ( w == metadata.width && h == metadata.height )
{
// This frame does not need resized or format converted, just copy...
hr = frame->CopyPixels( 0, static_cast<UINT>( img->rowPitch ), static_cast<UINT>( img->slicePitch ), img->pixels );
if ( FAILED(hr) )
return hr;
}
else
{
// This frame needs resizing, but not format converted
ScopedObject<IWICBitmapScaler> scaler;
hr = pWIC->CreateBitmapScaler( &scaler );
if ( FAILED(hr) )
return hr;
hr = scaler->Initialize( frame.Get(), static_cast<UINT>( metadata.width ), static_cast<UINT>( metadata.height ), _GetWICInterp( flags ) );
if ( FAILED(hr) )
return hr;
hr = scaler->CopyPixels( 0, static_cast<UINT>( img->rowPitch ), static_cast<UINT>( img->slicePitch ), img->pixels );
if ( FAILED(hr) )
return hr;
}
}
else
{
// This frame required format conversion
ScopedObject<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( &FC );
if ( FAILED(hr) )
return hr;
hr = FC->Initialize( frame.Get(), pfGuid, _GetWICDither( flags ), 0, 0, WICBitmapPaletteTypeCustom );
if ( FAILED(hr) )
return hr;
if ( w == metadata.width && h == metadata.height )
{
// This frame is the same size, no need to scale
hr = FC->CopyPixels( 0, static_cast<UINT>( img->rowPitch ), static_cast<UINT>( img->slicePitch ), img->pixels );
if ( FAILED(hr) )
return hr;
}
else
{
// This frame needs resizing and format converted
ScopedObject<IWICBitmapScaler> scaler;
hr = pWIC->CreateBitmapScaler( &scaler );
if ( FAILED(hr) )
return hr;
hr = scaler->Initialize( FC.Get(), static_cast<UINT>( metadata.width ), static_cast<UINT>( metadata.height ), _GetWICInterp( flags ) );
if ( FAILED(hr) )
return hr;
hr = scaler->CopyPixels( 0, static_cast<UINT>( img->rowPitch ), static_cast<UINT>( img->slicePitch ), img->pixels );
if ( FAILED(hr) )
return hr;
}
}
}
return S_OK;
}
//-------------------------------------------------------------------------------------
// Encodes a single frame
//-------------------------------------------------------------------------------------
static HRESULT _EncodeImage( _In_ const Image& image, _In_ DWORD flags, _In_ IWICBitmapFrameEncode* frame, _In_opt_ IPropertyBag2* props )
{
if ( !frame )
return E_INVALIDARG;
if ( !image.pixels )
return E_POINTER;
WICPixelFormatGUID pfGuid;
if ( !_DXGIToWIC( image.format, pfGuid ) )
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
HRESULT hr = frame->Initialize( props );
if ( FAILED(hr) )
return hr;
#ifdef _AMD64_
if ( (image.width > 0xFFFFFFFF) || (image.height > 0xFFFFFFFF) )
return E_INVALIDARG;
#endif
hr = frame->SetSize( static_cast<UINT>( image.width ), static_cast<UINT>( image.height ) );
if ( FAILED(hr) )
return hr;
hr = frame->SetResolution( 72, 72 );
if ( FAILED(hr) )
return hr;
WICPixelFormatGUID targetGuid = pfGuid;
hr = frame->SetPixelFormat( &targetGuid );
if ( FAILED(hr) )
return hr;
if ( memcmp( &targetGuid, &pfGuid, sizeof(WICPixelFormatGUID) ) != 0 )
{
// Conversion required to write
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return E_NOINTERFACE;
ScopedObject<IWICBitmap> source;
hr = pWIC->CreateBitmapFromMemory( static_cast<UINT>( image.width ), static_cast<UINT>( image.height ), pfGuid,
static_cast<UINT>( image.rowPitch ), static_cast<UINT>( image.slicePitch ),
image.pixels, &source );
if ( FAILED(hr) )
return hr;
ScopedObject<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( &FC );
if ( FAILED(hr) )
return hr;
hr = FC->Initialize( source.Get(), targetGuid, _GetWICDither( flags ), 0, 0, WICBitmapPaletteTypeCustom );
if ( FAILED(hr) )
return hr;
size_t bpp = _WICBitsPerPixel( targetGuid );
if ( bpp == 0 )
return E_FAIL;
size_t rowPitch = ( image.width * bpp + 7 ) / 8;
size_t slicePitch = rowPitch * image.height;
std::unique_ptr<uint8_t[]> temp( new uint8_t[ slicePitch ] );
if ( !temp )
return E_OUTOFMEMORY;
hr = FC->CopyPixels( 0, static_cast<UINT>( rowPitch ), static_cast<UINT>( slicePitch ), temp.get() );
if ( FAILED(hr) )
return hr;
hr = frame->WritePixels( static_cast<UINT>( image.height ), static_cast<UINT>( rowPitch ), static_cast<UINT>( slicePitch ), temp.get() );
if ( FAILED(hr) )
return hr;
}
else
{
// No conversion required
hr = frame->WritePixels( static_cast<UINT>( image.height ), static_cast<UINT>( image.rowPitch ), static_cast<UINT>( image.slicePitch ),
reinterpret_cast<uint8_t*>( image.pixels ) );
if ( FAILED(hr) )
return hr;
}
hr = frame->Commit();
if ( FAILED(hr) )
return hr;
return S_OK;
}
static HRESULT _EncodeSingleFrame( _In_ const Image& image, _In_ DWORD flags,
_In_ REFGUID guidContainerFormat, _Inout_ IStream* stream )
{
if ( !stream )
return E_INVALIDARG;
// Initialize WIC
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return E_NOINTERFACE;
ScopedObject<IWICBitmapEncoder> encoder;
HRESULT hr = pWIC->CreateEncoder( guidContainerFormat, 0, &encoder );
if ( FAILED(hr) )
return hr;
hr = encoder->Initialize( stream, WICBitmapEncoderNoCache );
if ( FAILED(hr) )
return hr;
ScopedObject<IWICBitmapFrameEncode> frame;
ScopedObject<IPropertyBag2> props;
hr = encoder->CreateNewFrame( &frame, &props );
if ( FAILED(hr) )
return hr;
if ( memcmp( &guidContainerFormat, &GUID_ContainerFormatBmp, sizeof(WICPixelFormatGUID) ) == 0 )
{
// Opt-in to the Windows 8 support for writing 32-bit Windows BMP files with an alpha channel if supported
PROPBAG2 option = { 0 };
option.pstrName = L"EnableV5Header32bppBGRA";
VARIANT varValue;
varValue.vt = VT_BOOL;
varValue.boolVal = VARIANT_TRUE;
hr = props->Write( 1, &option, &varValue );
if ( FAILED(hr) )
{
// Fails on older versions of WIC, so we default to the null property bag
props.Reset();
}
}
hr = _EncodeImage( image, flags, frame.Get(), props.Get() );
if ( FAILED(hr) )
return hr;
hr = encoder->Commit();
if ( FAILED(hr) )
return hr;
return S_OK;
}
//-------------------------------------------------------------------------------------
// Encodes an image array
//-------------------------------------------------------------------------------------
static HRESULT _EncodeMultiframe( _In_count_(nimages) const Image* images, _In_ size_t nimages, _In_ DWORD flags,
_In_ REFGUID guidContainerFormat, _Inout_ IStream* stream )
{
if ( !stream || nimages < 2 )
return E_INVALIDARG;
if ( !images )
return E_POINTER;
// Initialize WIC
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return E_NOINTERFACE;
ScopedObject<IWICBitmapEncoder> encoder;
HRESULT hr = pWIC->CreateEncoder( guidContainerFormat, 0, &encoder );
if ( FAILED(hr) )
return hr;
ScopedObject<IWICBitmapEncoderInfo> einfo;
hr = encoder->GetEncoderInfo( &einfo );
if ( FAILED(hr) )
return hr;
BOOL mframe = FALSE;
hr = einfo->DoesSupportMultiframe( &mframe );
if ( FAILED(hr) )
return hr;
if ( !mframe )
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
hr = encoder->Initialize( stream, WICBitmapEncoderNoCache );
if ( FAILED(hr) )
return hr;
for( size_t index=0; index < nimages; ++index )
{
ScopedObject<IWICBitmapFrameEncode> frame;
hr = encoder->CreateNewFrame( &frame, nullptr );
if ( FAILED(hr) )
return hr;
hr = _EncodeImage( images[index], flags, frame.Get(), nullptr );
if ( FAILED(hr) )
return hr;
}
hr = encoder->Commit();
if ( FAILED(hr) )
return hr;
return S_OK;
}
//=====================================================================================
// Entry-points
//=====================================================================================
//-------------------------------------------------------------------------------------
// Obtain metadata from WIC-supported file in memory
//-------------------------------------------------------------------------------------
HRESULT GetMetadataFromWICMemory( LPCVOID pSource, size_t size, DWORD flags, TexMetadata& metadata )
{
if ( !pSource || size == 0 )
return E_INVALIDARG;
#ifdef _AMD64_
if ( size > 0xFFFFFFFF )
return HRESULT_FROM_WIN32( ERROR_FILE_TOO_LARGE );
#endif
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return E_NOINTERFACE;
// Create input stream for memory
ScopedObject<IWICStream> stream;
HRESULT hr = pWIC->CreateStream( &stream );
if ( FAILED(hr) )
return hr;
hr = stream->InitializeFromMemory( reinterpret_cast<BYTE*>( const_cast<void*>( pSource ) ),
static_cast<UINT>( size ) );
if ( FAILED(hr) )
return hr;
// Initialize WIC
ScopedObject<IWICBitmapDecoder> decoder;
hr = pWIC->CreateDecoderFromStream( stream.Get(), 0, WICDecodeMetadataCacheOnDemand, &decoder );
if ( FAILED(hr) )
return hr;
ScopedObject<IWICBitmapFrameDecode> frame;
hr = decoder->GetFrame( 0, &frame );
if ( FAILED(hr) )
return hr;
// Get metadata
hr = _DecodeMetadata( flags, decoder.Get(), frame.Get(), metadata, 0 );
if ( FAILED(hr) )
return hr;
return S_OK;
}
//-------------------------------------------------------------------------------------
// Obtain metadata from WIC-supported file on disk
//-------------------------------------------------------------------------------------
HRESULT GetMetadataFromWICFile( LPCWSTR szFile, DWORD flags, TexMetadata& metadata )
{
if ( !szFile )
return E_INVALIDARG;
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return E_NOINTERFACE;
// Initialize WIC
ScopedObject<IWICBitmapDecoder> decoder;
HRESULT hr = pWIC->CreateDecoderFromFilename( szFile, 0, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &decoder );
if ( FAILED(hr) )
return hr;
ScopedObject<IWICBitmapFrameDecode> frame;
hr = decoder->GetFrame( 0, &frame );
if ( FAILED(hr) )
return hr;
// Get metadata
hr = _DecodeMetadata( flags, decoder.Get(), frame.Get(), metadata, 0 );
if ( FAILED(hr) )
return hr;
return S_OK;
}
//-------------------------------------------------------------------------------------
// Load a WIC-supported file in memory
//-------------------------------------------------------------------------------------
HRESULT LoadFromWICMemory( LPCVOID pSource, size_t size, DWORD flags, TexMetadata* metadata, ScratchImage& image )
{
if ( !pSource || size == 0 )
return E_INVALIDARG;
#ifdef _AMD64_
if ( size > 0xFFFFFFFF )
return HRESULT_FROM_WIN32( ERROR_FILE_TOO_LARGE );
#endif
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return E_NOINTERFACE;
image.Release();
// Create input stream for memory
ScopedObject<IWICStream> stream;
HRESULT hr = pWIC->CreateStream( &stream );
if ( FAILED(hr) )
return hr;
hr = stream->InitializeFromMemory( reinterpret_cast<uint8_t*>( const_cast<void*>( pSource ) ), static_cast<DWORD>( size ) );
if ( FAILED(hr) )
return hr;
// Initialize WIC
ScopedObject<IWICBitmapDecoder> decoder;
hr = pWIC->CreateDecoderFromStream( stream.Get(), 0, WICDecodeMetadataCacheOnDemand, &decoder );
if ( FAILED(hr) )
return hr;
ScopedObject<IWICBitmapFrameDecode> frame;
hr = decoder->GetFrame( 0, &frame );
if ( FAILED(hr) )
return hr;
// Get metadata
TexMetadata mdata;
WICPixelFormatGUID convertGUID = {0};
hr = _DecodeMetadata( flags, decoder.Get(), frame.Get(), mdata, &convertGUID );
if ( FAILED(hr) )
return hr;
if ( (mdata.arraySize > 1) && (flags & WIC_FLAGS_ALL_FRAMES) )
{
hr = _DecodeMultiframe( flags, mdata, decoder.Get(), image );
}
else
{
hr = _DecodeSingleFrame( flags, mdata, convertGUID, frame.Get(), image );
}
if ( FAILED(hr) )
{
image.Release();
return hr;
}
if ( metadata )
memcpy( metadata, &mdata, sizeof(TexMetadata) );
return S_OK;
}
//-------------------------------------------------------------------------------------
// Load a WIC-supported file from disk
//-------------------------------------------------------------------------------------
HRESULT LoadFromWICFile( LPCWSTR szFile, DWORD flags, TexMetadata* metadata, ScratchImage& image )
{
if ( !szFile )
return E_INVALIDARG;
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return E_NOINTERFACE;
image.Release();
// Initialize WIC
ScopedObject<IWICBitmapDecoder> decoder;
HRESULT hr = pWIC->CreateDecoderFromFilename( szFile, 0, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &decoder );
if ( FAILED(hr) )
return hr;
ScopedObject<IWICBitmapFrameDecode> frame;
hr = decoder->GetFrame( 0, &frame );
if ( FAILED(hr) )
return hr;
// Get metadata
TexMetadata mdata;
WICPixelFormatGUID convertGUID = {0};
hr = _DecodeMetadata( flags, decoder.Get(), frame.Get(), mdata, &convertGUID );
if ( FAILED(hr) )
return hr;
if ( (mdata.arraySize > 1) && (flags & WIC_FLAGS_ALL_FRAMES) )
{
hr = _DecodeMultiframe( flags, mdata, decoder.Get(), image );
}
else
{
hr = _DecodeSingleFrame( flags, mdata, convertGUID, frame.Get(), image );
}
if ( FAILED(hr) )
{
image.Release();
return hr;
}
if ( metadata )
memcpy( metadata, &mdata, sizeof(TexMetadata) );
return S_OK;
}
//-------------------------------------------------------------------------------------
// Save a WIC-supported file to memory
//-------------------------------------------------------------------------------------
HRESULT SaveToWICMemory( const Image& image, DWORD flags, REFGUID guidContainerFormat, Blob& blob )
{
if ( !image.pixels )
return E_POINTER;
blob.Release();
ScopedObject<IStream> stream;
HRESULT hr = CreateStreamOnHGlobal( 0, TRUE, &stream );
if ( FAILED(hr) )
return hr;
hr = _EncodeSingleFrame( image, flags, guidContainerFormat, stream.Get() );
if ( FAILED(hr) )
return hr;
// Copy stream data into blob
STATSTG stat;
hr = stream->Stat( &stat, STATFLAG_NONAME );
if ( FAILED(hr) )
return hr;
if ( stat.cbSize.HighPart > 0 )
return HRESULT_FROM_WIN32( ERROR_FILE_TOO_LARGE );
hr = blob.Initialize( stat.cbSize.LowPart );
if ( FAILED(hr) )
return hr;
LARGE_INTEGER li = { 0 };
hr = stream->Seek( li, STREAM_SEEK_SET, 0 );
if ( FAILED(hr) )
return hr;
DWORD bytesRead;
hr = stream->Read( blob.GetBufferPointer(), static_cast<ULONG>( blob.GetBufferSize() ), &bytesRead );
if ( FAILED(hr) )
return hr;
if ( bytesRead != blob.GetBufferSize() )
return E_FAIL;
return S_OK;
}
HRESULT SaveToWICMemory( const Image* images, size_t nimages, DWORD flags, REFGUID guidContainerFormat, Blob& blob )
{
if ( !images || nimages == 0 )
return E_INVALIDARG;
blob.Release();
ScopedObject<IStream> stream;
HRESULT hr = CreateStreamOnHGlobal( 0, TRUE, &stream );
if ( FAILED(hr) )
return hr;
if ( nimages > 1 )
hr = _EncodeMultiframe( images, nimages, flags, guidContainerFormat, stream.Get() );
else
hr = _EncodeSingleFrame( images[0], flags, guidContainerFormat, stream.Get() );
if ( FAILED(hr) )
return hr;
// Copy stream data into blob
STATSTG stat;
hr = stream->Stat( &stat, STATFLAG_NONAME );
if ( FAILED(hr) )
return hr;
if ( stat.cbSize.HighPart > 0 )
return HRESULT_FROM_WIN32( ERROR_FILE_TOO_LARGE );
hr = blob.Initialize( stat.cbSize.LowPart );
if ( FAILED(hr) )
return hr;
LARGE_INTEGER li = { 0 };
hr = stream->Seek( li, STREAM_SEEK_SET, 0 );
if ( FAILED(hr) )
return hr;
DWORD bytesRead;
hr = stream->Read( blob.GetBufferPointer(), static_cast<ULONG>( blob.GetBufferSize() ), &bytesRead );
if ( FAILED(hr) )
return hr;
if ( bytesRead != blob.GetBufferSize() )
return E_FAIL;
return S_OK;
}
//-------------------------------------------------------------------------------------
// Save a WIC-supported file to disk
//-------------------------------------------------------------------------------------
HRESULT SaveToWICFile( const Image& image, DWORD flags, REFGUID guidContainerFormat, LPCWSTR szFile )
{
if ( !szFile )
return E_INVALIDARG;
if ( !image.pixels )
return E_POINTER;
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return E_NOINTERFACE;
ScopedObject<IWICStream> stream;
HRESULT hr = pWIC->CreateStream( &stream );
if ( FAILED(hr) )
return hr;
hr = stream->InitializeFromFilename( szFile, GENERIC_WRITE );
if ( FAILED(hr) )
return hr;
hr = _EncodeSingleFrame( image, flags, guidContainerFormat, stream.Get() );
if ( FAILED(hr) )
return hr;
return S_OK;
}
HRESULT SaveToWICFile( const Image* images, size_t nimages, DWORD flags, REFGUID guidContainerFormat, LPCWSTR szFile )
{
if ( !szFile || !images || nimages == 0 )
return E_INVALIDARG;
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return E_NOINTERFACE;
ScopedObject<IWICStream> stream;
HRESULT hr = pWIC->CreateStream( &stream );
if ( FAILED(hr) )
return hr;
hr = stream->InitializeFromFilename( szFile, GENERIC_WRITE );
if ( FAILED(hr) )
return hr;
if ( nimages > 1 )
hr = _EncodeMultiframe( images, nimages, flags, guidContainerFormat, stream.Get() );
else
hr = _EncodeSingleFrame( images[0], flags, guidContainerFormat, stream.Get() );
if ( FAILED(hr) )
return hr;
return S_OK;
}
}; // namespace

View File

@ -0,0 +1,31 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DirectXTex", "DirectXTex_11_Desktop.vcxproj", "{371B9FA9-4C90-4AC6-A123-ACED756D6C77}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Profile|Win32 = Profile|Win32
Profile|x64 = Profile|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|Win32.ActiveCfg = Debug|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|Win32.Build.0 = Debug|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|x64.ActiveCfg = Debug|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|x64.Build.0 = Debug|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|Win32.ActiveCfg = Profile|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|Win32.Build.0 = Profile|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|x64.ActiveCfg = Profile|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|x64.Build.0 = Profile|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|Win32.ActiveCfg = Release|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|Win32.Build.0 = Release|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|x64.ActiveCfg = Release|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,428 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Profile|Win32">
<Configuration>Profile</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Profile|x64">
<Configuration>Profile</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>DirectXTex</ProjectName>
<ProjectGuid>{371B9FA9-4C90-4AC6-A123-ACED756D6C77}</ProjectGuid>
<RootNamespace>DirectXTex</RootNamespace>
<Keyword>Win32Proj</Keyword>
<VCTargetsPath Condition="'$(VCTargetsPath11)' != '' and '$(VSVersion)' == '' and $(VisualStudioVersion) == ''">$(VCTargetsPath11)</VCTargetsPath>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|X64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|X64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings" />
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Profile|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">
<LinkIncremental>true</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|X64'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|X64'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<OpenMPSupport>true</OpenMPSupport>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;_DEBUG;DEBUG;PROFILE;_WINDOWS;_LIB;D3DXFX_LARGEADDRESS_HANDLE;DXGI_1_2_FORMATS;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>DirectXTexP.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<OpenMPSupport>true</OpenMPSupport>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;_DEBUG;DEBUG;PROFILE;_WINDOWS;_LIB;D3DXFX_LARGEADDRESS_HANDLE;DXGI_1_2_FORMATS;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>DirectXTexP.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>true</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_LIB;D3DXFX_LARGEADDRESS_HANDLE;DXGI_1_2_FORMATS;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>DirectXTexP.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|X64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>true</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_LIB;D3DXFX_LARGEADDRESS_HANDLE;DXGI_1_2_FORMATS;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>DirectXTexP.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>true</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;PROFILE;_WINDOWS;_LIB;D3DXFX_LARGEADDRESS_HANDLE;DXGI_1_2_FORMATS;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>DirectXTexP.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Profile|X64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>true</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;PROFILE;_WINDOWS;_LIB;D3DXFX_LARGEADDRESS_HANDLE;DXGI_1_2_FORMATS;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>DirectXTexP.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup />
<ItemGroup>
<CLInclude Include="BC.h" />
<ClCompile Include="BC.cpp" />
<ClCompile Include="BC4BC5.cpp" />
<ClCompile Include="BC6HBC7.cpp" />
<CLInclude Include="DDS.h" />
<CLInclude Include="scoped.h" />
<CLInclude Include="DirectXTex.h" />
<CLInclude Include="DirectXTexp.h" />
<CLInclude Include="DirectXTex.inl" />
<ClCompile Include="DirectXTexCompress.cpp" />
<ClCompile Include="DirectXTexConvert.cpp" />
<ClCompile Include="DirectXTexD3D11.cpp" />
<ClCompile Include="DirectXTexDDS.cpp" />
<ClCompile Include="DirectXTexFlipRotate.cpp" />
<ClCompile Include="DirectXTexImage.cpp" />
<ClCompile Include="DirectXTexMipMaps.cpp" />
<ClCompile Include="DirectXTexMisc.cpp" />
<ClCompile Include="DirectXTexNormalMaps.cpp" />
<ClCompile Include="DirectXTexResize.cpp" />
<ClCompile Include="DirectXTexTGA.cpp" />
<ClCompile Include="DirectXTexUtil.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="DirectXTexWIC.cpp" />
</ItemGroup>
<ItemGroup>
</ItemGroup>
<ItemGroup>
</ItemGroup>
<ItemGroup>
</ItemGroup>
<ItemGroup>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
</Project>

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns:atg="http://atg.xbox.com" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Resource Files">
<UniqueIdentifier>{8e114980-c1a3-4ada-ad7c-83caadf5daeb}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe</Extensions>
</Filter>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<CLInclude Include="BC.h" />
<ClCompile Include="BC.cpp" />
<ClCompile Include="BC4BC5.cpp" />
<ClCompile Include="BC6HBC7.cpp" />
<CLInclude Include="DDS.h" />
<CLInclude Include="scoped.h" />
<CLInclude Include="DirectXTex.h" />
<CLInclude Include="DirectXTexp.h" />
<CLInclude Include="DirectXTex.inl" />
<ClCompile Include="DirectXTexCompress.cpp" />
<ClCompile Include="DirectXTexConvert.cpp" />
<ClCompile Include="DirectXTexD3D11.cpp" />
<ClCompile Include="DirectXTexDDS.cpp" />
<ClCompile Include="DirectXTexFlipRotate.cpp" />
<ClCompile Include="DirectXTexImage.cpp" />
<ClCompile Include="DirectXTexMipMaps.cpp" />
<ClCompile Include="DirectXTexMisc.cpp" />
<ClCompile Include="DirectXTexNormalMaps.cpp" />
<ClCompile Include="DirectXTexResize.cpp" />
<ClCompile Include="DirectXTexTGA.cpp" />
<ClCompile Include="DirectXTexUtil.cpp" />
<ClCompile Include="DirectXTexWIC.cpp" />
</ItemGroup>
<ItemGroup></ItemGroup>
<ItemGroup></ItemGroup>
<ItemGroup></ItemGroup>
</Project>

View File

@ -0,0 +1,31 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DirectXTex", "DirectXTex_2010.vcxproj", "{371B9FA9-4C90-4AC6-A123-ACED756D6C77}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Profile|Win32 = Profile|Win32
Profile|x64 = Profile|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|Win32.ActiveCfg = Debug|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|Win32.Build.0 = Debug|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|x64.ActiveCfg = Debug|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|x64.Build.0 = Debug|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|Win32.ActiveCfg = Profile|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|Win32.Build.0 = Profile|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|x64.ActiveCfg = Profile|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|x64.Build.0 = Profile|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|Win32.ActiveCfg = Release|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|Win32.Build.0 = Release|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|x64.ActiveCfg = Release|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,421 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Profile|Win32">
<Configuration>Profile</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Profile|x64">
<Configuration>Profile</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>DirectXTex</ProjectName>
<ProjectGuid>{371B9FA9-4C90-4AC6-A123-ACED756D6C77}</ProjectGuid>
<RootNamespace>DirectXTex</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|X64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|X64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings" />
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Profile|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath)</ExecutablePath>
<IncludePath>$(DXSDK_DIR)Include;$(IncludePath)</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\x86;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">
<LinkIncremental>true</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath)</ExecutablePath>
<IncludePath>$(DXSDK_DIR)Include;$(IncludePath)</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\x64;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath)</ExecutablePath>
<IncludePath>$(DXSDK_DIR)Include;$(IncludePath)</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\x86;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|X64'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath)</ExecutablePath>
<IncludePath>$(DXSDK_DIR)Include;$(IncludePath)</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\x64;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath)</ExecutablePath>
<IncludePath>$(DXSDK_DIR)Include;$(IncludePath)</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\x86;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|X64'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath)</ExecutablePath>
<IncludePath>$(DXSDK_DIR)Include;$(IncludePath)</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\x64;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<OpenMPSupport>true</OpenMPSupport>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;_DEBUG;DEBUG;PROFILE;_WINDOWS;_LIB;D3DXFX_LARGEADDRESS_HANDLE;USE_XNAMATH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>DirectXTexP.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<OpenMPSupport>true</OpenMPSupport>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;_DEBUG;DEBUG;PROFILE;_WINDOWS;_LIB;D3DXFX_LARGEADDRESS_HANDLE;USE_XNAMATH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>DirectXTexP.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>true</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_LIB;D3DXFX_LARGEADDRESS_HANDLE;USE_XNAMATH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>DirectXTexP.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|X64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>true</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_LIB;D3DXFX_LARGEADDRESS_HANDLE;USE_XNAMATH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>DirectXTexP.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>true</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;PROFILE;_WINDOWS;_LIB;D3DXFX_LARGEADDRESS_HANDLE;USE_XNAMATH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>DirectXTexP.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Profile|X64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>true</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;PROFILE;_WINDOWS;_LIB;D3DXFX_LARGEADDRESS_HANDLE;USE_XNAMATH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>DirectXTexP.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup />
<ItemGroup>
<CLInclude Include="BC.h" />
<ClCompile Include="BC.cpp" />
<ClCompile Include="BC4BC5.cpp" />
<ClCompile Include="BC6HBC7.cpp" />
<CLInclude Include="DDS.h" />
<CLInclude Include="scoped.h" />
<CLInclude Include="DirectXTex.h" />
<CLInclude Include="DirectXTexp.h" />
<CLInclude Include="DirectXTex.inl" />
<ClCompile Include="DirectXTexCompress.cpp" />
<ClCompile Include="DirectXTexConvert.cpp" />
<ClCompile Include="DirectXTexD3D11.cpp" />
<ClCompile Include="DirectXTexDDS.cpp" />
<ClCompile Include="DirectXTexFlipRotate.cpp" />
<ClCompile Include="DirectXTexImage.cpp" />
<ClCompile Include="DirectXTexMipMaps.cpp" />
<ClCompile Include="DirectXTexMisc.cpp" />
<ClCompile Include="DirectXTexNormalMaps.cpp" />
<ClCompile Include="DirectXTexResize.cpp" />
<ClCompile Include="DirectXTexTGA.cpp" />
<ClCompile Include="DirectXTexUtil.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="DirectXTexWIC.cpp" />
</ItemGroup>
<ItemGroup>
</ItemGroup>
<ItemGroup>
</ItemGroup>
<ItemGroup>
</ItemGroup>
<ItemGroup>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
</Project>

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns:atg="http://atg.xbox.com" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Resource Files">
<UniqueIdentifier>{8e114980-c1a3-4ada-ad7c-83caadf5daeb}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe</Extensions>
</Filter>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<CLInclude Include="BC.h" />
<ClCompile Include="BC.cpp" />
<ClCompile Include="BC4BC5.cpp" />
<ClCompile Include="BC6HBC7.cpp" />
<CLInclude Include="DDS.h" />
<CLInclude Include="scoped.h" />
<CLInclude Include="DirectXTex.h" />
<CLInclude Include="DirectXTexp.h" />
<CLInclude Include="DirectXTex.inl" />
<ClCompile Include="DirectXTexCompress.cpp" />
<ClCompile Include="DirectXTexConvert.cpp" />
<ClCompile Include="DirectXTexD3D11.cpp" />
<ClCompile Include="DirectXTexDDS.cpp" />
<ClCompile Include="DirectXTexFlipRotate.cpp" />
<ClCompile Include="DirectXTexImage.cpp" />
<ClCompile Include="DirectXTexMipMaps.cpp" />
<ClCompile Include="DirectXTexMisc.cpp" />
<ClCompile Include="DirectXTexNormalMaps.cpp" />
<ClCompile Include="DirectXTexResize.cpp" />
<ClCompile Include="DirectXTexTGA.cpp" />
<ClCompile Include="DirectXTexUtil.cpp" />
<ClCompile Include="DirectXTexWIC.cpp" />
</ItemGroup>
<ItemGroup></ItemGroup>
<ItemGroup></ItemGroup>
<ItemGroup></ItemGroup>
</Project>

70
DirectXTex/scoped.h Normal file
View File

@ -0,0 +1,70 @@
//-------------------------------------------------------------------------------------
// scoped.h
//
// Utility header with helper classes for exception-safe handling of resources
//
// 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.
//-------------------------------------------------------------------------------------
#if defined(_MSC_VER) && (_MSC_VER > 1000)
#pragma once
#endif
#include <assert.h>
#include <memory>
#include <malloc.h>
//---------------------------------------------------------------------------------
struct aligned_deleter { void operator()(void* p) { _aligned_free(p); } };
typedef std::unique_ptr<float, aligned_deleter> ScopedAlignedArrayFloat;
#ifdef USE_XNAMATH
typedef std::unique_ptr<XMVECTOR, aligned_deleter> ScopedAlignedArrayXMVECTOR;
#else
typedef std::unique_ptr<DirectX::XMVECTOR, aligned_deleter> ScopedAlignedArrayXMVECTOR;
#endif
//---------------------------------------------------------------------------------
struct handle_closer { void operator()(HANDLE h) { assert(h != INVALID_HANDLE_VALUE); if (h) CloseHandle(h); } };
typedef public std::unique_ptr<void, handle_closer> ScopedHandle;
inline HANDLE safe_handle( HANDLE h ) { return (h == INVALID_HANDLE_VALUE) ? 0 : h; }
//---------------------------------------------------------------------------------
template<class T> class ScopedObject
{
public:
explicit ScopedObject( T *p = 0 ) : _pointer(p) {}
~ScopedObject()
{
if ( _pointer )
{
_pointer->Release();
_pointer = nullptr;
}
}
bool IsNull() const { return (!_pointer); }
T& operator*() { return *_pointer; }
T* operator->() { return _pointer; }
T** operator&() { return &_pointer; }
void Reset(T *p = 0) { if ( _pointer ) { _pointer->Release(); } _pointer = p; }
T* Get() const { return _pointer; }
private:
ScopedObject(const ScopedObject&);
ScopedObject& operator=(const ScopedObject&);
T* _pointer;
};

76
Texconv/Texconv.rc Normal file
View File

@ -0,0 +1,76 @@
// Microsoft Visual C++ generated resource script.
//
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#define IDC_STATIC -1
#include <WinResRc.h>
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_MAIN_ICON ICON "directx.ico"
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#define IDC_STATIC -1\r\n"
"#include <winresrc.h>\r\n"
"\r\n"
"\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@ -0,0 +1,45 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "texconv", "Texconv_11_Desktop.vcxproj", "{C3A65381-8FD3-4F69-B29E-654B4B0ED136}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DirectXTex", "..\DirectXTex\DirectXTex_11_Desktop.vcxproj", "{371B9FA9-4C90-4AC6-A123-ACED756D6C77}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Profile|Win32 = Profile|Win32
Profile|x64 = Profile|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Debug|Win32.ActiveCfg = Debug|Win32
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Debug|Win32.Build.0 = Debug|Win32
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Debug|x64.ActiveCfg = Debug|x64
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Debug|x64.Build.0 = Debug|x64
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Profile|Win32.ActiveCfg = Profile|Win32
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Profile|Win32.Build.0 = Profile|Win32
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Profile|x64.ActiveCfg = Profile|x64
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Profile|x64.Build.0 = Profile|x64
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Release|Win32.ActiveCfg = Release|Win32
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Release|Win32.Build.0 = Release|Win32
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Release|x64.ActiveCfg = Release|x64
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Release|x64.Build.0 = Release|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|Win32.ActiveCfg = Debug|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|Win32.Build.0 = Debug|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|x64.ActiveCfg = Debug|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|x64.Build.0 = Debug|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|Win32.ActiveCfg = Profile|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|Win32.Build.0 = Profile|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|x64.ActiveCfg = Profile|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|x64.Build.0 = Profile|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|Win32.ActiveCfg = Release|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|Win32.Build.0 = Release|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|x64.ActiveCfg = Release|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,389 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Profile|Win32">
<Configuration>Profile</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Profile|x64">
<Configuration>Profile</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>texconv</ProjectName>
<ProjectGuid>{C3A65381-8FD3-4F69-B29E-654B4B0ED136}</ProjectGuid>
<RootNamespace>texconv</RootNamespace>
<Keyword>Win32Proj</Keyword>
<VCTargetsPath Condition="'$(VCTargetsPath11)' != '' and '$(VSVersion)' == '' and $(VisualStudioVersion) == ''">$(VCTargetsPath11)</VCTargetsPath>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|X64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|X64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings" />
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Profile|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">
<LinkIncremental>true</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|X64'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|X64'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;_DEBUG;DEBUG;PROFILE;_CONSOLE;D3DXFX_LARGEADDRESS_HANDLE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;_DEBUG;DEBUG;PROFILE;_CONSOLE;D3DXFX_LARGEADDRESS_HANDLE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;D3DXFX_LARGEADDRESS_HANDLE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|X64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;D3DXFX_LARGEADDRESS_HANDLE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;PROFILE;_CONSOLE;D3DXFX_LARGEADDRESS_HANDLE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Profile|X64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;PROFILE;_CONSOLE;D3DXFX_LARGEADDRESS_HANDLE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Texconv.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Texconv.rc" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DirectXTex\DirectXTex_11_Desktop.vcxproj">
<Project>{371b9fa9-4c90-4ac6-a123-aced756d6c77}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
</Project>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns:atg="http://atg.xbox.com" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Resource Files">
<UniqueIdentifier>{8e114980-c1a3-4ada-ad7c-83caadf5daeb}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Texconv.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Texconv.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>

BIN
Texconv/directx.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

1001
Texconv/texconv.cpp Normal file

File diff suppressed because it is too large Load Diff

45
Texconv/texconv_2010.sln Normal file
View File

@ -0,0 +1,45 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "texconv", "texconv_2010.vcxproj", "{C3A65381-8FD3-4F69-B29E-654B4B0ED136}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DirectXTex", "..\DirectXTex\DirectXTex_2010.vcxproj", "{371B9FA9-4C90-4AC6-A123-ACED756D6C77}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Profile|Win32 = Profile|Win32
Profile|x64 = Profile|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Debug|Win32.ActiveCfg = Debug|Win32
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Debug|Win32.Build.0 = Debug|Win32
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Debug|x64.ActiveCfg = Debug|x64
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Debug|x64.Build.0 = Debug|x64
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Profile|Win32.ActiveCfg = Profile|Win32
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Profile|Win32.Build.0 = Profile|Win32
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Profile|x64.ActiveCfg = Profile|x64
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Profile|x64.Build.0 = Profile|x64
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Release|Win32.ActiveCfg = Release|Win32
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Release|Win32.Build.0 = Release|Win32
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Release|x64.ActiveCfg = Release|x64
{C3A65381-8FD3-4F69-B29E-654B4B0ED136}.Release|x64.Build.0 = Release|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|Win32.ActiveCfg = Debug|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|Win32.Build.0 = Debug|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|x64.ActiveCfg = Debug|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Debug|x64.Build.0 = Debug|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|Win32.ActiveCfg = Profile|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|Win32.Build.0 = Profile|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|x64.ActiveCfg = Profile|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Profile|x64.Build.0 = Profile|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|Win32.ActiveCfg = Release|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|Win32.Build.0 = Release|Win32
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|x64.ActiveCfg = Release|x64
{371B9FA9-4C90-4AC6-A123-ACED756D6C77}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,382 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Profile|Win32">
<Configuration>Profile</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Profile|x64">
<Configuration>Profile</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>texconv</ProjectName>
<ProjectGuid>{C3A65381-8FD3-4F69-B29E-654B4B0ED136}</ProjectGuid>
<RootNamespace>texconv</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|X64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|X64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings" />
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Profile|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath)</ExecutablePath>
<IncludePath>$(DXSDK_DIR)Include;$(IncludePath)</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\x86;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">
<LinkIncremental>true</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath)</ExecutablePath>
<IncludePath>$(DXSDK_DIR)Include;$(IncludePath)</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\x64;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath)</ExecutablePath>
<IncludePath>$(DXSDK_DIR)Include;$(IncludePath)</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\x86;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|X64'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath)</ExecutablePath>
<IncludePath>$(DXSDK_DIR)Include;$(IncludePath)</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\x64;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath)</ExecutablePath>
<IncludePath>$(DXSDK_DIR)Include;$(IncludePath)</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\x86;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|X64'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<ExecutablePath>$(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86;$(ExecutablePath)</ExecutablePath>
<IncludePath>$(DXSDK_DIR)Include;$(IncludePath)</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\x64;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;_DEBUG;DEBUG;PROFILE;_CONSOLE;D3DXFX_LARGEADDRESS_HANDLE;USE_XNAMATH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;_DEBUG;DEBUG;PROFILE;_CONSOLE;D3DXFX_LARGEADDRESS_HANDLE;USE_XNAMATH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;D3DXFX_LARGEADDRESS_HANDLE;USE_XNAMATH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|X64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;D3DXFX_LARGEADDRESS_HANDLE;USE_XNAMATH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;PROFILE;_CONSOLE;D3DXFX_LARGEADDRESS_HANDLE;USE_XNAMATH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Profile|X64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OpenMPSupport>false</OpenMPSupport>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>..\XNAMath;..\DirectXTex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;PROFILE;_CONSOLE;D3DXFX_LARGEADDRESS_HANDLE;USE_XNAMATH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>ole32.lib;windowscodecs.lib;uuid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Manifest>
<EnableDPIAwareness>false</EnableDPIAwareness>
</Manifest>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Texconv.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Texconv.rc" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DirectXTex\DirectXTex_2010.vcxproj">
<Project>{371b9fa9-4c90-4ac6-a123-aced756d6c77}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
</Project>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns:atg="http://atg.xbox.com" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Resource Files">
<UniqueIdentifier>{8e114980-c1a3-4ada-ad7c-83caadf5daeb}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Texconv.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Texconv.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,691 @@
//--------------------------------------------------------------------------------------
// File: WICTextureLoader.cpp
//
// Function for loading a WIC image and creating a Direct3D 11 runtime texture for it
// (auto-generating mipmaps if possible)
//
// Note: Assumes application has already called CoInitializeEx
//
// Warning: CreateWICTexture* functions are not thread-safe if given a d3dContext instance for
// auto-gen mipmap support.
//
// Note these functions are useful for images created as simple 2D textures. For
// more complex resources, DDSTextureLoader is an excellent light-weight runtime loader.
// For a full-featured DDS file reader, writer, and texture processing pipeline see
// the 'Texconv' sample and the 'DirectXTex' 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
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
// We could load multi-frame images (TIFF/GIF) into a texture array.
// For now, we just load the first frame (note: DirectXTex supports multi-frame images)
#include <dxgiformat.h>
#include <assert.h>
#pragma warning(push)
#pragma warning(disable : 4005)
#include <wincodec.h>
#pragma warning(pop)
#include <memory>
#include "WICTextureLoader.h"
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) && !defined(DXGI_1_2_FORMATS)
#define DXGI_1_2_FORMATS
#endif
//---------------------------------------------------------------------------------
template<class T> class ScopedObject
{
public:
explicit ScopedObject( T *p = 0 ) : _pointer(p) {}
~ScopedObject()
{
if ( _pointer )
{
_pointer->Release();
_pointer = nullptr;
}
}
bool IsNull() const { return (!_pointer); }
T& operator*() { return *_pointer; }
T* operator->() { return _pointer; }
T** operator&() { return &_pointer; }
void Reset(T *p = 0) { if ( _pointer ) { _pointer->Release(); } _pointer = p; }
T* Get() const { return _pointer; }
private:
ScopedObject(const ScopedObject&);
ScopedObject& operator=(const ScopedObject&);
T* _pointer;
};
//-------------------------------------------------------------------------------------
// WIC Pixel Format Translation Data
//-------------------------------------------------------------------------------------
struct WICTranslate
{
GUID wic;
DXGI_FORMAT format;
};
static WICTranslate g_WICFormats[] =
{
{ GUID_WICPixelFormat128bppRGBAFloat, DXGI_FORMAT_R32G32B32A32_FLOAT },
{ GUID_WICPixelFormat64bppRGBAHalf, DXGI_FORMAT_R16G16B16A16_FLOAT },
{ GUID_WICPixelFormat64bppRGBA, DXGI_FORMAT_R16G16B16A16_UNORM },
{ GUID_WICPixelFormat32bppRGBA, DXGI_FORMAT_R8G8B8A8_UNORM },
{ GUID_WICPixelFormat32bppBGRA, DXGI_FORMAT_B8G8R8A8_UNORM }, // DXGI 1.1
{ GUID_WICPixelFormat32bppBGR, DXGI_FORMAT_B8G8R8X8_UNORM }, // DXGI 1.1
{ GUID_WICPixelFormat32bppRGBA1010102XR, DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM }, // DXGI 1.1
{ GUID_WICPixelFormat32bppRGBA1010102, DXGI_FORMAT_R10G10B10A2_UNORM },
{ GUID_WICPixelFormat32bppRGBE, DXGI_FORMAT_R9G9B9E5_SHAREDEXP },
#ifdef DXGI_1_2_FORMATS
{ GUID_WICPixelFormat16bppBGRA5551, DXGI_FORMAT_B5G5R5A1_UNORM },
{ GUID_WICPixelFormat16bppBGR565, DXGI_FORMAT_B5G6R5_UNORM },
#endif // DXGI_1_2_FORMATS
{ GUID_WICPixelFormat32bppGrayFloat, DXGI_FORMAT_R32_FLOAT },
{ GUID_WICPixelFormat16bppGrayHalf, DXGI_FORMAT_R16_FLOAT },
{ GUID_WICPixelFormat16bppGray, DXGI_FORMAT_R16_UNORM },
{ GUID_WICPixelFormat8bppGray, DXGI_FORMAT_R8_UNORM },
{ GUID_WICPixelFormat8bppAlpha, DXGI_FORMAT_A8_UNORM },
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
{ GUID_WICPixelFormat96bppRGBFloat, DXGI_FORMAT_R32G32B32_FLOAT },
#endif
};
//-------------------------------------------------------------------------------------
// WIC Pixel Format nearest conversion table
//-------------------------------------------------------------------------------------
struct WICConvert
{
GUID source;
GUID target;
};
static WICConvert g_WICConvert[] =
{
// Note target GUID in this conversion table must be one of those directly supported formats (above).
{ GUID_WICPixelFormatBlackWhite, GUID_WICPixelFormat8bppGray }, // DXGI_FORMAT_R8_UNORM
{ GUID_WICPixelFormat1bppIndexed, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat2bppIndexed, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat4bppIndexed, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat8bppIndexed, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat2bppGray, GUID_WICPixelFormat8bppGray }, // DXGI_FORMAT_R8_UNORM
{ GUID_WICPixelFormat4bppGray, GUID_WICPixelFormat8bppGray }, // DXGI_FORMAT_R8_UNORM
{ GUID_WICPixelFormat16bppGrayFixedPoint, GUID_WICPixelFormat16bppGrayHalf }, // DXGI_FORMAT_R16_FLOAT
{ GUID_WICPixelFormat32bppGrayFixedPoint, GUID_WICPixelFormat32bppGrayFloat }, // DXGI_FORMAT_R32_FLOAT
#ifdef DXGI_1_2_FORMATS
{ GUID_WICPixelFormat16bppBGR555, GUID_WICPixelFormat16bppBGRA5551 }, // DXGI_FORMAT_B5G5R5A1_UNORM
#else
{ GUID_WICPixelFormat16bppBGR555, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat16bppBGRA5551, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat16bppBGR565, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
#endif // DXGI_1_2_FORMATS
{ GUID_WICPixelFormat32bppBGR101010, GUID_WICPixelFormat32bppRGBA1010102 }, // DXGI_FORMAT_R10G10B10A2_UNORM
{ GUID_WICPixelFormat24bppBGR, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat24bppRGB, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat32bppPBGRA, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat32bppPRGBA, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat48bppRGB, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat48bppBGR, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat64bppBGRA, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat64bppPRGBA, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat64bppPBGRA, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat48bppRGBFixedPoint, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat48bppBGRFixedPoint, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat64bppRGBAFixedPoint, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat64bppBGRAFixedPoint, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat64bppRGBFixedPoint, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat64bppRGBHalf, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat48bppRGBHalf, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat96bppRGBFixedPoint, GUID_WICPixelFormat128bppRGBAFloat }, // DXGI_FORMAT_R32G32B32A32_FLOAT
{ GUID_WICPixelFormat128bppPRGBAFloat, GUID_WICPixelFormat128bppRGBAFloat }, // DXGI_FORMAT_R32G32B32A32_FLOAT
{ GUID_WICPixelFormat128bppRGBFloat, GUID_WICPixelFormat128bppRGBAFloat }, // DXGI_FORMAT_R32G32B32A32_FLOAT
{ GUID_WICPixelFormat128bppRGBAFixedPoint, GUID_WICPixelFormat128bppRGBAFloat }, // DXGI_FORMAT_R32G32B32A32_FLOAT
{ GUID_WICPixelFormat128bppRGBFixedPoint, GUID_WICPixelFormat128bppRGBAFloat }, // DXGI_FORMAT_R32G32B32A32_FLOAT
{ GUID_WICPixelFormat32bppCMYK, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat64bppCMYK, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat40bppCMYKAlpha, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat80bppCMYKAlpha, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
{ GUID_WICPixelFormat32bppRGB, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat64bppRGB, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat64bppPRGBAHalf, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
#endif
// We don't support n-channel formats
};
//--------------------------------------------------------------------------------------
static IWICImagingFactory* _GetWIC()
{
static IWICImagingFactory* s_Factory = nullptr;
if ( s_Factory )
return s_Factory;
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory),
(LPVOID*)&s_Factory
);
if ( FAILED(hr) )
{
s_Factory = nullptr;
return nullptr;
}
return s_Factory;
}
//---------------------------------------------------------------------------------
static DXGI_FORMAT _WICToDXGI( const GUID& guid )
{
for( size_t i=0; i < _countof(g_WICFormats); ++i )
{
if ( memcmp( &g_WICFormats[i].wic, &guid, sizeof(GUID) ) == 0 )
return g_WICFormats[i].format;
}
return DXGI_FORMAT_UNKNOWN;
}
//---------------------------------------------------------------------------------
static size_t _WICBitsPerPixel( REFGUID targetGuid )
{
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return 0;
ScopedObject<IWICComponentInfo> cinfo;
if ( FAILED( pWIC->CreateComponentInfo( targetGuid, &cinfo ) ) )
return 0;
WICComponentType type;
if ( FAILED( cinfo->GetComponentType( &type ) ) )
return 0;
if ( type != WICPixelFormat )
return 0;
ScopedObject<IWICPixelFormatInfo> pfinfo;
if ( FAILED( cinfo->QueryInterface( __uuidof(IWICPixelFormatInfo), reinterpret_cast<void**>( &pfinfo ) ) ) )
return 0;
UINT bpp;
if ( FAILED( pfinfo->GetBitsPerPixel( &bpp ) ) )
return 0;
return bpp;
}
//---------------------------------------------------------------------------------
static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
_In_ IWICBitmapFrameDecode *frame,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize )
{
UINT width, height;
HRESULT hr = frame->GetSize( &width, &height );
if ( FAILED(hr) )
return hr;
assert( width > 0 && height > 0 );
if ( !maxsize )
{
// This is a bit conservative because the hardware could support larger textures than
// the Feature Level defined minimums, but doing it this way is much easier and more
// performant for WIC than the 'fail and retry' model used by DDSTextureLoader
switch( d3dDevice->GetFeatureLevel() )
{
case D3D_FEATURE_LEVEL_9_1:
case D3D_FEATURE_LEVEL_9_2:
maxsize = 2048 /*D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION*/;
break;
case D3D_FEATURE_LEVEL_9_3:
maxsize = 4096 /*D3D_FL9_3_REQ_TEXTURE2D_U_OR_V_DIMENSION*/;
break;
case D3D_FEATURE_LEVEL_10_0:
case D3D_FEATURE_LEVEL_10_1:
maxsize = 8192 /*D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION*/;
break;
default:
maxsize = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION;
break;
}
}
assert( maxsize > 0 );
UINT twidth, theight;
if ( width > maxsize || height > maxsize )
{
float ar = static_cast<float>(height) / static_cast<float>(width);
if ( width > height )
{
twidth = static_cast<UINT>( maxsize );
theight = static_cast<UINT>( static_cast<float>(maxsize) * ar );
}
else
{
theight = static_cast<UINT>( maxsize );
twidth = static_cast<UINT>( static_cast<float>(maxsize) / ar );
}
assert( twidth <= maxsize && theight <= maxsize );
}
else
{
twidth = width;
theight = height;
}
// Determine format
WICPixelFormatGUID pixelFormat;
hr = frame->GetPixelFormat( &pixelFormat );
if ( FAILED(hr) )
return hr;
WICPixelFormatGUID convertGUID;
memcpy( &convertGUID, &pixelFormat, sizeof(WICPixelFormatGUID) );
size_t bpp = 0;
DXGI_FORMAT format = _WICToDXGI( pixelFormat );
if ( format == DXGI_FORMAT_UNKNOWN )
{
for( size_t i=0; i < _countof(g_WICConvert); ++i )
{
if ( memcmp( &g_WICConvert[i].source, &pixelFormat, sizeof(WICPixelFormatGUID) ) == 0 )
{
memcpy( &convertGUID, &g_WICConvert[i].target, sizeof(WICPixelFormatGUID) );
format = _WICToDXGI( g_WICConvert[i].target );
assert( format != DXGI_FORMAT_UNKNOWN );
bpp = _WICBitsPerPixel( convertGUID );
break;
}
}
if ( format == DXGI_FORMAT_UNKNOWN )
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
}
else
{
bpp = _WICBitsPerPixel( pixelFormat );
}
if ( !bpp )
return E_FAIL;
// Verify our target format is supported by the current device
// (handles WDDM 1.0 or WDDM 1.1 device driver cases as well as DirectX 11.0 Runtime without 16bpp format support)
UINT support = 0;
hr = d3dDevice->CheckFormatSupport( format, &support );
if ( FAILED(hr) || !(support & D3D11_FORMAT_SUPPORT_TEXTURE2D) )
{
// Fallback to RGBA 32-bit format which is supported by all devices
memcpy( &convertGUID, &GUID_WICPixelFormat32bppRGBA, sizeof(WICPixelFormatGUID) );
format = DXGI_FORMAT_R8G8B8A8_UNORM;
bpp = 32;
}
// Allocate temporary memory for image
size_t rowPitch = ( twidth * bpp + 7 ) / 8;
size_t imageSize = rowPitch * theight;
std::unique_ptr<uint8_t[]> temp( new uint8_t[ imageSize ] );
// Load image data
if ( memcmp( &convertGUID, &pixelFormat, sizeof(GUID) ) == 0
&& twidth == width
&& theight == height )
{
// No format conversion or resize needed
hr = frame->CopyPixels( 0, static_cast<UINT>( rowPitch ), static_cast<UINT>( imageSize ), temp.get() );
if ( FAILED(hr) )
return hr;
}
else if ( twidth != width || theight != height )
{
// Resize
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return E_NOINTERFACE;
ScopedObject<IWICBitmapScaler> scaler;
hr = pWIC->CreateBitmapScaler( &scaler );
if ( FAILED(hr) )
return hr;
hr = scaler->Initialize( frame, twidth, theight, WICBitmapInterpolationModeFant );
if ( FAILED(hr) )
return hr;
WICPixelFormatGUID pfScaler;
hr = scaler->GetPixelFormat( &pfScaler );
if ( FAILED(hr) )
return hr;
if ( memcmp( &convertGUID, &pfScaler, sizeof(GUID) ) == 0 )
{
// No format conversion needed
hr = scaler->CopyPixels( 0, static_cast<UINT>( rowPitch ), static_cast<UINT>( imageSize ), temp.get() );
if ( FAILED(hr) )
return hr;
}
else
{
ScopedObject<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( &FC );
if ( FAILED(hr) )
return hr;
hr = FC->Initialize( scaler.Get(), convertGUID, WICBitmapDitherTypeErrorDiffusion, 0, 0, WICBitmapPaletteTypeCustom );
if ( FAILED(hr) )
return hr;
hr = FC->CopyPixels( 0, static_cast<UINT>( rowPitch ), static_cast<UINT>( imageSize ), temp.get() );
if ( FAILED(hr) )
return hr;
}
}
else
{
// Format conversion but no resize
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return E_NOINTERFACE;
ScopedObject<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( &FC );
if ( FAILED(hr) )
return hr;
hr = FC->Initialize( frame, convertGUID, WICBitmapDitherTypeErrorDiffusion, 0, 0, WICBitmapPaletteTypeCustom );
if ( FAILED(hr) )
return hr;
hr = FC->CopyPixels( 0, static_cast<UINT>( rowPitch ), static_cast<UINT>( imageSize ), temp.get() );
if ( FAILED(hr) )
return hr;
}
// See if format is supported for auto-gen mipmaps (varies by feature level)
bool autogen = false;
if ( d3dContext != 0 && textureView != 0 ) // Must have context and shader-view to auto generate mipmaps
{
UINT fmtSupport = 0;
hr = d3dDevice->CheckFormatSupport( format, &fmtSupport );
if ( SUCCEEDED(hr) && ( fmtSupport & D3D11_FORMAT_SUPPORT_MIP_AUTOGEN ) )
{
autogen = true;
}
}
// Create texture
D3D11_TEXTURE2D_DESC desc;
desc.Width = twidth;
desc.Height = theight;
desc.MipLevels = (autogen) ? 0 : 1;
desc.ArraySize = 1;
desc.Format = format;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = (autogen) ? (D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET) : (D3D11_BIND_SHADER_RESOURCE);
desc.CPUAccessFlags = 0;
desc.MiscFlags = (autogen) ? D3D11_RESOURCE_MISC_GENERATE_MIPS : 0;
D3D11_SUBRESOURCE_DATA initData;
initData.pSysMem = temp.get();
initData.SysMemPitch = static_cast<UINT>( rowPitch );
initData.SysMemSlicePitch = static_cast<UINT>( imageSize );
ID3D11Texture2D* tex = nullptr;
hr = d3dDevice->CreateTexture2D( &desc, (autogen) ? nullptr : &initData, &tex );
if ( SUCCEEDED(hr) && tex != 0 )
{
if (textureView != 0)
{
D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc;
memset( &SRVDesc, 0, sizeof( SRVDesc ) );
SRVDesc.Format = format;
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
SRVDesc.Texture2D.MipLevels = (autogen) ? -1 : 1;
hr = d3dDevice->CreateShaderResourceView( tex, &SRVDesc, textureView );
if ( FAILED(hr) )
{
tex->Release();
return hr;
}
if ( autogen )
{
assert( d3dContext != 0 );
d3dContext->UpdateSubresource( tex, 0, nullptr, temp.get(), static_cast<UINT>(rowPitch), static_cast<UINT>(imageSize) );
d3dContext->GenerateMips( *textureView );
}
}
if (texture != 0)
{
*texture = tex;
}
else
{
#if defined(DEBUG) || defined(PROFILE)
tex->SetPrivateData( WKPDID_D3DDebugObjectName,
sizeof("WICTextureLoader")-1,
"WICTextureLoader"
);
#endif
tex->Release();
}
}
return hr;
}
//--------------------------------------------------------------------------------------
HRESULT CreateWICTextureFromMemory( _In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
_In_bytecount_(wicDataSize) const uint8_t* wicData,
_In_ size_t wicDataSize,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize
)
{
if (!d3dDevice || !wicData || (!texture && !textureView))
{
return E_INVALIDARG;
}
if ( !wicDataSize )
{
return E_FAIL;
}
#ifdef _M_AMD64
if ( wicDataSize > 0xFFFFFFFF )
return HRESULT_FROM_WIN32( ERROR_FILE_TOO_LARGE );
#endif
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return E_NOINTERFACE;
// Create input stream for memory
ScopedObject<IWICStream> stream;
HRESULT hr = pWIC->CreateStream( &stream );
if ( FAILED(hr) )
return hr;
hr = stream->InitializeFromMemory( const_cast<uint8_t*>( wicData ), static_cast<DWORD>( wicDataSize ) );
if ( FAILED(hr) )
return hr;
// Initialize WIC
ScopedObject<IWICBitmapDecoder> decoder;
hr = pWIC->CreateDecoderFromStream( stream.Get(), 0, WICDecodeMetadataCacheOnDemand, &decoder );
if ( FAILED(hr) )
return hr;
ScopedObject<IWICBitmapFrameDecode> frame;
hr = decoder->GetFrame( 0, &frame );
if ( FAILED(hr) )
return hr;
hr = CreateTextureFromWIC( d3dDevice, d3dContext, frame.Get(), texture, textureView, maxsize );
if ( FAILED(hr))
return hr;
#if defined(DEBUG) || defined(PROFILE)
if (texture != 0 && *texture != 0)
{
(*texture)->SetPrivateData( WKPDID_D3DDebugObjectName,
sizeof("WICTextureLoader")-1,
"WICTextureLoader"
);
}
if (textureView != 0 && *textureView != 0)
{
(*textureView)->SetPrivateData( WKPDID_D3DDebugObjectName,
sizeof("WICTextureLoader")-1,
"WICTextureLoader"
);
}
#endif
return hr;
}
//--------------------------------------------------------------------------------------
HRESULT CreateWICTextureFromFile( _In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
_In_z_ const wchar_t* fileName,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize )
{
if (!d3dDevice || !fileName || (!texture && !textureView))
{
return E_INVALIDARG;
}
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return E_NOINTERFACE;
// Initialize WIC
ScopedObject<IWICBitmapDecoder> decoder;
HRESULT hr = pWIC->CreateDecoderFromFilename( fileName, 0, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &decoder );
if ( FAILED(hr) )
return hr;
ScopedObject<IWICBitmapFrameDecode> frame;
hr = decoder->GetFrame( 0, &frame );
if ( FAILED(hr) )
return hr;
hr = CreateTextureFromWIC( d3dDevice, d3dContext, frame.Get(), texture, textureView, maxsize );
if ( FAILED(hr))
return hr;
#if defined(DEBUG) || defined(PROFILE)
if (texture != 0 || textureView != 0)
{
CHAR strFileA[MAX_PATH];
WideCharToMultiByte( CP_ACP,
WC_NO_BEST_FIT_CHARS,
fileName,
-1,
strFileA,
MAX_PATH,
nullptr,
FALSE
);
const CHAR* pstrName = strrchr( strFileA, '\\' );
if (!pstrName)
{
pstrName = strFileA;
}
else
{
pstrName++;
}
if (texture != 0 && *texture != 0)
{
(*texture)->SetPrivateData( WKPDID_D3DDebugObjectName,
lstrlenA(pstrName),
pstrName
);
}
if (textureView != 0 && *textureView != 0 )
{
(*textureView)->SetPrivateData( WKPDID_D3DDebugObjectName,
lstrlenA(pstrName),
pstrName
);
}
}
#endif
return hr;
}

View File

@ -0,0 +1,54 @@
//--------------------------------------------------------------------------------------
// File: WICTextureLoader.h
//
// Function for loading a WIC image and creating a Direct3D 11 runtime texture for it
// (auto-generating mipmaps if possible)
//
// Note: Assumes application has already called CoInitializeEx
//
// Warning: CreateWICTexture* functions are not thread-safe if given a d3dContext instance for
// auto-gen mipmap support.
//
// Note these functions are useful for images created as simple 2D textures. For
// more complex resources, DDSTextureLoader is an excellent light-weight runtime loader.
// For a full-featured DDS file reader, writer, and texture processing pipeline see
// the 'Texconv' sample and the 'DirectXTex' 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
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#ifdef _MSC_VER
#pragma once
#endif
#include <d3d11.h>
#pragma warning(push)
#pragma warning(disable : 4005)
#include <stdint.h>
#pragma warning(pop)
HRESULT CreateWICTextureFromMemory( _In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
_In_bytecount_(wicDataSize) const uint8_t* wicData,
_In_ size_t wicDataSize,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0
);
HRESULT CreateWICTextureFromFile( _In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
_In_z_ const wchar_t* szFileName,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0
);