Skip to content

Commit

Permalink
Switched to c++20 standard, added IsHDR function test
Browse files Browse the repository at this point in the history
  • Loading branch information
drzhn committed Oct 12, 2023
1 parent 68fcb77 commit 815d55c
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 22 deletions.
2 changes: 1 addition & 1 deletion DirectXTex/DirectXTex_Desktop_2022_Win10.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
<ExternalWarningLevel>Level4</ExternalWarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<SupportJustMyCode>false</SupportJustMyCode>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down
4 changes: 2 additions & 2 deletions Texconv/Blob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include "Blob.h"

#include <cstring>
#include <cstdlib>

#include "Winerror.h"

#include "winerror.h"

Blob& Blob::operator= (Blob&& moveFrom) noexcept
{
Expand Down
2 changes: 1 addition & 1 deletion Texconv/Texconv_Desktop_2022_Win10.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<DisableSpecificWarnings>26812</DisableSpecificWarnings>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<AdditionalDependencies>ole32.lib;windowscodecs.lib;uuid.lib;version.lib;%(AdditionalDependencies)</AdditionalDependencies>
Expand Down
36 changes: 36 additions & 0 deletions Texconv/texconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3537,6 +3537,16 @@ int Convert(
const size_t nimg = image->GetImageCount();

PrintInfo(info);

outMetadata = {
.width = info.width,
.height = info.height,
.depth = info.depth,
.arraySize = info.arraySize,
.mipLevels = info.mipLevels,
.format = info.format
};

wprintf(L"\n");

// Figure out dest filename
Expand Down Expand Up @@ -3764,4 +3774,30 @@ int Convert(
return retVal;
}

bool IsHDR(const char* filePath)
{
FILE* f;
bool res = false;
const char* test1 = "#?RADIANCE";
const char* test2 = "#?RGBE";
if (fopen_s(&f, filePath, "r") == 0)
{
auto CheckHdr = [](const char* testStr, FILE* file)
{
char buf[16];

size_t len = strlen(testStr);
fseek(file, 0, 0);
fread_s(buf, len, 1, len, file);
return strncmp(testStr, buf, len) == 0;
};

if (CheckHdr(test1, f) || CheckHdr(test2, f))
{
res = true;
}
fclose(f);
}
return res;
}
}
2 changes: 1 addition & 1 deletion TexconvTests/TexconvTests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir)include</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
Binary file added TexconvTests/hdrTexture.dds
Binary file not shown.
Binary file added TexconvTests/pngTexture.dds
Binary file not shown.
41 changes: 31 additions & 10 deletions TexconvTests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,45 @@ int main()
{
AssetConversion::TextureConversionParams params;

params.format = DXGI_FORMAT_BC1_UNORM;

const uint64_t options =
(1ull << OPT_MIPLEVELS) |
(1ull << OPT_FORMAT) |
(1ull << OPT_FIT_POWEROF2);
(1ull << OPT_FIT_POWEROF2) |
(1ull << OPT_USE_DX10);


{
params.format = DXGI_FORMAT_BC1_UNORM;

AssetConversion::TextureMetadata metadata;
Blob blob;

AssetConversion::Convert(params, options, "pngTexture.png", metadata, blob);
bool isHDR = AssetConversion::IsHDR("pngTexture.png");
std::ofstream fout;
fout.open("pngTexture.dds", std::ios::binary | std::ios::out);

fout.write(static_cast<char*>(blob.GetBufferPointer()), blob.GetBufferSize());

fout.close();
}

{
params.format = DXGI_FORMAT_BC6H_UF16;

AssetConversion::TextureMetadata metadata;
Blob blob;
AssetConversion::TextureMetadata metadata;
Blob blob;

AssetConversion::Convert(params, options, "hdrTexture.hdr", metadata, blob);
bool isHDR = AssetConversion::IsHDR("hdrTexture.hdr");

AssetConversion::Convert(params, options, "pngTexture.png", metadata, blob);
std::ofstream fout;
fout.open("hdrTexture.dds", std::ios::binary | std::ios::out);

std::ofstream fout;
fout.open("pngTexture.dds", std::ios::binary | std::ios::out);
fout.write(static_cast<char*>(blob.GetBufferPointer()), blob.GetBufferSize());

fout.write(static_cast<char*>(blob.GetBufferPointer()), blob.GetBufferSize());
fout.close();
}

fout.close();
return 0;
}
16 changes: 9 additions & 7 deletions include/Texconv.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Blob;

namespace
namespace
{
enum OPTIONS : uint64_t
{
Expand Down Expand Up @@ -75,12 +75,12 @@ namespace AssetConversion
{
struct TextureMetadata
{
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;
DXGI_FORMAT format;
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;
DXGI_FORMAT format;
};

struct TextureConversionParams
Expand All @@ -98,5 +98,7 @@ namespace AssetConversion
TextureMetadata& outMetadata,
Blob& outBlob
);

bool IsHDR(const char* filePath);
}
#endif // TEXCONV_H
Binary file modified lib/x64/Debug/texconv.lib
Binary file not shown.
Binary file modified lib/x64/Release/texconv.lib
Binary file not shown.

0 comments on commit 815d55c

Please sign in to comment.