Template
*
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
#include <iostream>
|
||||
#include <DirectXTex.h>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
|
||||
int Morton(int t, int sx, int sy) {
|
||||
int num1;
|
||||
int num2 = num1 = 1;
|
||||
int num3 = t;
|
||||
int num4 = sx;
|
||||
int num5 = sy;
|
||||
int num6 = 0;
|
||||
int num7 = 0;
|
||||
|
||||
while (num4 > 1 || num5 > 1) {
|
||||
if (num4 > 1) {
|
||||
num6 += num2 * (num3 & 1);
|
||||
num3 >>= 1;
|
||||
num2 *= 2;
|
||||
num4 >>= 1;
|
||||
}
|
||||
if (num5 > 1) {
|
||||
num7 += num1 * (num3 & 1);
|
||||
num3 >>= 1;
|
||||
num1 *= 2;
|
||||
num5 >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
return num7 * sx + num6;
|
||||
}
|
||||
|
||||
std::vector<std::uint8_t> DoSwizzle(std::vector<std::uint8_t> data, int width, int height, int blockSize, bool unswizzle) {
|
||||
auto processed = std::vector<std::uint8_t>();
|
||||
processed.resize(data.size());
|
||||
|
||||
auto heightTexels = height / 4;
|
||||
auto heightTexelsAligned = (heightTexels + 7) / 8;
|
||||
int widthTexels = width / 4;
|
||||
auto widthTexelsAligned = (widthTexels + 7) / 8;
|
||||
auto dataIndex = 0;
|
||||
|
||||
for (int y = 0; y < heightTexelsAligned; ++y) {
|
||||
for (int x = 0; x < widthTexelsAligned; ++x) {
|
||||
for (int t = 0; t < 64; ++t) {
|
||||
int pixelIndex = Morton(t, 8, 8);
|
||||
int num8 = pixelIndex / 8;
|
||||
int num9 = pixelIndex % 8;
|
||||
auto yOffset = (y * 8) + num8;
|
||||
auto xOffset = (x * 8) + num9;
|
||||
|
||||
if (xOffset < widthTexels && yOffset < heightTexels) {
|
||||
auto destPixelIndex = yOffset * widthTexels + xOffset;
|
||||
int destIndex = blockSize * destPixelIndex;
|
||||
|
||||
if (unswizzle)
|
||||
memcpy(processed.data() + destIndex, data.data() + dataIndex, blockSize);
|
||||
else
|
||||
memcpy(processed.data() + dataIndex, data.data() + destIndex, blockSize);
|
||||
}
|
||||
|
||||
dataIndex += blockSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return processed;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
std::vector<std::uint8_t> Swizzle(std::vector<std::uint8_t> data, int width, int height, int blockSize) {
|
||||
return DoSwizzle(data, width, height, blockSize, false);
|
||||
}
|
||||
|
||||
std::vector<std::uint8_t> UnSwizzle(std::vector<std::uint8_t> data, int width, int height, int blockSize) {
|
||||
return DoSwizzle(data, width, height, blockSize, true);
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
|
||||
DirectX::ScratchImage image;
|
||||
auto initResult = image.Initialize2D(DXGI_FORMAT::DXGI_FORMAT_BC4_UNORM, 1024, 1024, 1, 1);
|
||||
auto img = image.GetImage(0, 0, 0);
|
||||
|
||||
auto cnt = image.GetImageCount();
|
||||
|
||||
auto images = image.GetImages();
|
||||
for (int i = 0; i < cnt; ++i) {
|
||||
auto img = images + i;
|
||||
std::cout << "ID: " << i << " W: " << img->width << " H: " << img->height << " Row pitch: " << img->rowPitch << " Slice pitch: " << img->slicePitch << std::endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//2097152
|
||||
//""
|
||||
auto readSize = img->slicePitch;
|
||||
auto inFile = std::ifstream("D:/TextureExport/blt-armor-a-new-spec-mask.tga.1024_1024_unswizzled_page0_file103.dds", std::ios::binary);
|
||||
|
||||
inFile.read((char*)img->pixels, readSize);
|
||||
inFile.close();
|
||||
|
||||
/* std::vector<std::uint8_t> mem;
|
||||
mem.resize(img->slicePitch);
|
||||
memcpy(mem.data(), img->pixels, img->slicePitch);
|
||||
|
||||
auto unswizzled = UnSwizzle(mem, 1024, 1024, 8);
|
||||
|
||||
memcpy(img->pixels, unswizzled.data(), img->slicePitch);*/
|
||||
|
||||
DirectX::SaveToDDSFile(*img, DirectX::DDS_FLAGS::DDS_FLAGS_NONE, L"F:/out.dds");
|
||||
|
||||
//img->pixels
|
||||
|
||||
std::cout << "Hello World!\n";
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{41215da9-c90e-4fe0-acab-34d6673f52d2}</ProjectGuid>
|
||||
<RootNamespace>TextureConverter</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<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>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>F:\DirectXTex\DirectXTex</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>F:\DirectXTex\DirectXTex\Bin\Desktop_2019_Win10\x64\Debug</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>DirectXTex.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="TextureConverter.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user