2016-09-25 23:04:44 +00:00
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
// File: Texdiag.cpp
|
|
|
|
//
|
|
|
|
// DirectX Texture diagnostic tool
|
|
|
|
//
|
2021-02-27 06:59:42 +00:00
|
|
|
// Copyright (c) Microsoft Corporation.
|
2018-02-24 06:24:46 +00:00
|
|
|
// Licensed under the MIT License.
|
2017-02-26 07:57:13 +00:00
|
|
|
//
|
|
|
|
// http://go.microsoft.com/fwlink/?LinkId=248926
|
2016-09-25 23:04:44 +00:00
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable : 4005)
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#define NOMINMAX
|
|
|
|
#define NODRAWTEXT
|
|
|
|
#define NOGDI
|
|
|
|
#define NOMCX
|
|
|
|
#define NOSERVICE
|
|
|
|
#define NOHELP
|
|
|
|
#pragma warning(pop)
|
|
|
|
|
2023-03-27 23:02:41 +00:00
|
|
|
#if __cplusplus < 201703L
|
|
|
|
#error Requires C++17 (and /Zc:__cplusplus with MSVC)
|
|
|
|
#endif
|
|
|
|
|
2020-12-30 02:04:51 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
2022-05-01 07:44:49 +00:00
|
|
|
#include <cstring>
|
2021-01-07 08:43:18 +00:00
|
|
|
#include <cwchar>
|
2021-06-08 22:00:22 +00:00
|
|
|
#include <cwctype>
|
2023-03-27 23:02:41 +00:00
|
|
|
#include <filesystem>
|
2017-09-19 18:13:34 +00:00
|
|
|
#include <fstream>
|
2021-01-02 22:37:52 +00:00
|
|
|
#include <iterator>
|
2016-09-25 23:04:44 +00:00
|
|
|
#include <list>
|
2021-04-28 21:33:45 +00:00
|
|
|
#include <locale>
|
2021-01-17 19:59:46 +00:00
|
|
|
#include <memory>
|
2021-10-17 18:57:07 +00:00
|
|
|
#include <new>
|
2021-06-08 22:00:22 +00:00
|
|
|
#include <set>
|
|
|
|
#include <string>
|
2021-10-17 18:57:07 +00:00
|
|
|
#include <tuple>
|
2016-09-25 23:04:44 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <dxgiformat.h>
|
|
|
|
|
2019-10-24 23:55:13 +00:00
|
|
|
#pragma warning(disable : 4619 4616 26812)
|
|
|
|
|
2019-04-17 00:38:37 +00:00
|
|
|
#include "DirectXTex.h"
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2021-06-10 00:40:17 +00:00
|
|
|
#include <DirectXPackedVector.h>
|
|
|
|
|
2016-10-02 19:44:07 +00:00
|
|
|
//Uncomment to add support for OpenEXR (.exr)
|
|
|
|
//#define USE_OPENEXR
|
|
|
|
|
|
|
|
#ifdef USE_OPENEXR
|
|
|
|
// See <https://github.com/Microsoft/DirectXTex/wiki/Adding-OpenEXR> for details
|
|
|
|
#include "DirectXTexEXR.h"
|
|
|
|
#endif
|
|
|
|
|
2016-09-25 23:04:44 +00:00
|
|
|
using namespace DirectX;
|
|
|
|
|
2021-10-17 00:31:17 +00:00
|
|
|
enum COMMANDS : uint32_t
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
|
|
|
CMD_INFO = 1,
|
|
|
|
CMD_ANALYZE,
|
|
|
|
CMD_COMPARE,
|
2016-09-27 07:24:19 +00:00
|
|
|
CMD_DIFF,
|
2016-09-25 23:04:44 +00:00
|
|
|
CMD_DUMPBC,
|
2018-02-09 22:45:34 +00:00
|
|
|
CMD_DUMPDDS,
|
2016-09-25 23:04:44 +00:00
|
|
|
CMD_MAX
|
|
|
|
};
|
|
|
|
|
2021-04-25 02:57:56 +00:00
|
|
|
enum OPTIONS : uint32_t
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
|
|
|
OPT_RECURSIVE = 1,
|
2016-09-27 07:24:19 +00:00
|
|
|
OPT_FORMAT,
|
2016-09-25 23:04:44 +00:00
|
|
|
OPT_FILTER,
|
|
|
|
OPT_DDS_DWORD_ALIGN,
|
|
|
|
OPT_DDS_BAD_DXTN_TAILS,
|
2016-09-27 07:24:19 +00:00
|
|
|
OPT_OUTPUTFILE,
|
2020-04-14 00:22:55 +00:00
|
|
|
OPT_TOLOWER,
|
2016-09-27 07:24:19 +00:00
|
|
|
OPT_OVERWRITE,
|
2018-02-09 22:45:34 +00:00
|
|
|
OPT_FILETYPE,
|
2016-09-25 23:04:44 +00:00
|
|
|
OPT_NOLOGO,
|
|
|
|
OPT_TYPELESS_UNORM,
|
|
|
|
OPT_TYPELESS_FLOAT,
|
|
|
|
OPT_EXPAND_LUMINANCE,
|
|
|
|
OPT_TARGET_PIXELX,
|
|
|
|
OPT_TARGET_PIXELY,
|
2021-06-10 00:40:17 +00:00
|
|
|
OPT_DIFF_COLOR,
|
|
|
|
OPT_THRESHOLD,
|
2017-09-19 18:13:34 +00:00
|
|
|
OPT_FILELIST,
|
2016-09-25 23:04:44 +00:00
|
|
|
OPT_MAX
|
|
|
|
};
|
|
|
|
|
2021-04-25 02:57:56 +00:00
|
|
|
static_assert(OPT_MAX <= 32, "dwOptions is a unsigned int bitfield");
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
struct SConversion
|
|
|
|
{
|
2023-06-13 22:40:45 +00:00
|
|
|
std::wstring szSrc;
|
2016-09-25 23:04:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SValue
|
|
|
|
{
|
2021-04-25 02:57:56 +00:00
|
|
|
const wchar_t* name;
|
|
|
|
uint32_t value;
|
2016-09-25 23:04:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
const SValue g_pCommands[] =
|
|
|
|
{
|
|
|
|
{ L"info", CMD_INFO },
|
|
|
|
{ L"analyze", CMD_ANALYZE },
|
|
|
|
{ L"compare", CMD_COMPARE },
|
2016-09-27 07:24:19 +00:00
|
|
|
{ L"diff", CMD_DIFF },
|
2016-09-25 23:04:44 +00:00
|
|
|
{ L"dumpbc", CMD_DUMPBC },
|
2018-02-09 22:45:34 +00:00
|
|
|
{ L"dumpdds", CMD_DUMPDDS },
|
2016-09-25 23:04:44 +00:00
|
|
|
{ nullptr, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const SValue g_pOptions[] =
|
|
|
|
{
|
|
|
|
{ L"r", OPT_RECURSIVE },
|
2016-09-27 07:24:19 +00:00
|
|
|
{ L"f", OPT_FORMAT },
|
2016-09-25 23:04:44 +00:00
|
|
|
{ L"if", OPT_FILTER },
|
|
|
|
{ L"dword", OPT_DDS_DWORD_ALIGN },
|
|
|
|
{ L"badtails", OPT_DDS_BAD_DXTN_TAILS },
|
|
|
|
{ L"nologo", OPT_NOLOGO },
|
2016-09-27 07:24:19 +00:00
|
|
|
{ L"o", OPT_OUTPUTFILE },
|
2020-04-14 00:22:55 +00:00
|
|
|
{ L"l", OPT_TOLOWER },
|
2016-09-27 07:24:19 +00:00
|
|
|
{ L"y", OPT_OVERWRITE },
|
2018-02-09 22:45:34 +00:00
|
|
|
{ L"ft", OPT_FILETYPE },
|
2016-09-25 23:04:44 +00:00
|
|
|
{ L"tu", OPT_TYPELESS_UNORM },
|
|
|
|
{ L"tf", OPT_TYPELESS_FLOAT },
|
|
|
|
{ L"xlum", OPT_EXPAND_LUMINANCE },
|
|
|
|
{ L"targetx", OPT_TARGET_PIXELX },
|
|
|
|
{ L"targety", OPT_TARGET_PIXELY },
|
2021-06-10 00:40:17 +00:00
|
|
|
{ L"c", OPT_DIFF_COLOR },
|
|
|
|
{ L"t", OPT_THRESHOLD },
|
2017-09-19 18:13:34 +00:00
|
|
|
{ L"flist", OPT_FILELIST },
|
2016-09-25 23:04:44 +00:00
|
|
|
{ nullptr, 0 }
|
|
|
|
};
|
|
|
|
|
2020-05-21 01:18:24 +00:00
|
|
|
#define DEFFMT(fmt) { L## #fmt, DXGI_FORMAT_ ## fmt }
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
const SValue g_pFormats[] =
|
|
|
|
{
|
2016-09-27 07:24:19 +00:00
|
|
|
// List does not include _TYPELESS, depth/stencil, or BC formats
|
2016-09-25 23:04:44 +00:00
|
|
|
DEFFMT(R32G32B32A32_FLOAT),
|
|
|
|
DEFFMT(R32G32B32A32_UINT),
|
|
|
|
DEFFMT(R32G32B32A32_SINT),
|
|
|
|
DEFFMT(R32G32B32_FLOAT),
|
|
|
|
DEFFMT(R32G32B32_UINT),
|
|
|
|
DEFFMT(R32G32B32_SINT),
|
|
|
|
DEFFMT(R16G16B16A16_FLOAT),
|
|
|
|
DEFFMT(R16G16B16A16_UNORM),
|
|
|
|
DEFFMT(R16G16B16A16_UINT),
|
|
|
|
DEFFMT(R16G16B16A16_SNORM),
|
|
|
|
DEFFMT(R16G16B16A16_SINT),
|
|
|
|
DEFFMT(R32G32_FLOAT),
|
|
|
|
DEFFMT(R32G32_UINT),
|
|
|
|
DEFFMT(R32G32_SINT),
|
|
|
|
DEFFMT(R10G10B10A2_UNORM),
|
|
|
|
DEFFMT(R10G10B10A2_UINT),
|
|
|
|
DEFFMT(R11G11B10_FLOAT),
|
|
|
|
DEFFMT(R8G8B8A8_UNORM),
|
|
|
|
DEFFMT(R8G8B8A8_UNORM_SRGB),
|
|
|
|
DEFFMT(R8G8B8A8_UINT),
|
|
|
|
DEFFMT(R8G8B8A8_SNORM),
|
|
|
|
DEFFMT(R8G8B8A8_SINT),
|
|
|
|
DEFFMT(R16G16_FLOAT),
|
|
|
|
DEFFMT(R16G16_UNORM),
|
|
|
|
DEFFMT(R16G16_UINT),
|
|
|
|
DEFFMT(R16G16_SNORM),
|
|
|
|
DEFFMT(R16G16_SINT),
|
|
|
|
DEFFMT(R32_FLOAT),
|
|
|
|
DEFFMT(R32_UINT),
|
|
|
|
DEFFMT(R32_SINT),
|
|
|
|
DEFFMT(R8G8_UNORM),
|
|
|
|
DEFFMT(R8G8_UINT),
|
|
|
|
DEFFMT(R8G8_SNORM),
|
|
|
|
DEFFMT(R8G8_SINT),
|
|
|
|
DEFFMT(R16_FLOAT),
|
|
|
|
DEFFMT(R16_UNORM),
|
|
|
|
DEFFMT(R16_UINT),
|
|
|
|
DEFFMT(R16_SNORM),
|
|
|
|
DEFFMT(R16_SINT),
|
|
|
|
DEFFMT(R8_UNORM),
|
|
|
|
DEFFMT(R8_UINT),
|
|
|
|
DEFFMT(R8_SNORM),
|
|
|
|
DEFFMT(R8_SINT),
|
|
|
|
DEFFMT(A8_UNORM),
|
|
|
|
DEFFMT(R9G9B9E5_SHAREDEXP),
|
|
|
|
DEFFMT(R8G8_B8G8_UNORM),
|
|
|
|
DEFFMT(G8R8_G8B8_UNORM),
|
2016-09-27 07:24:19 +00:00
|
|
|
DEFFMT(B5G6R5_UNORM),
|
|
|
|
DEFFMT(B5G5R5A1_UNORM),
|
|
|
|
|
|
|
|
// DXGI 1.1 formats
|
|
|
|
DEFFMT(B8G8R8A8_UNORM),
|
|
|
|
DEFFMT(B8G8R8X8_UNORM),
|
|
|
|
DEFFMT(R10G10B10_XR_BIAS_A2_UNORM),
|
|
|
|
DEFFMT(B8G8R8A8_UNORM_SRGB),
|
|
|
|
DEFFMT(B8G8R8X8_UNORM_SRGB),
|
|
|
|
|
|
|
|
// DXGI 1.2 formats
|
|
|
|
DEFFMT(AYUV),
|
|
|
|
DEFFMT(Y410),
|
|
|
|
DEFFMT(Y416),
|
|
|
|
DEFFMT(YUY2),
|
|
|
|
DEFFMT(Y210),
|
|
|
|
DEFFMT(Y216),
|
|
|
|
DEFFMT(B4G4R4A4_UNORM),
|
|
|
|
|
2023-05-11 16:58:28 +00:00
|
|
|
// D3D11on12 format
|
|
|
|
{ L"A4B4G4R4_UNORM", DXGI_FORMAT(191) },
|
|
|
|
|
2016-09-27 07:24:19 +00:00
|
|
|
{ nullptr, DXGI_FORMAT_UNKNOWN }
|
|
|
|
};
|
|
|
|
|
2019-09-14 00:31:09 +00:00
|
|
|
const SValue g_pFormatAliases[] =
|
2018-02-22 08:17:49 +00:00
|
|
|
{
|
2018-02-22 19:57:44 +00:00
|
|
|
{ L"RGBA", DXGI_FORMAT_R8G8B8A8_UNORM },
|
|
|
|
{ L"BGRA", DXGI_FORMAT_B8G8R8A8_UNORM },
|
2021-06-03 01:12:59 +00:00
|
|
|
{ L"BGR", DXGI_FORMAT_B8G8R8X8_UNORM },
|
2018-02-22 19:57:44 +00:00
|
|
|
|
2018-02-22 08:17:49 +00:00
|
|
|
{ L"FP16", DXGI_FORMAT_R16G16B16A16_FLOAT },
|
|
|
|
{ L"FP32", DXGI_FORMAT_R32G32B32A32_FLOAT },
|
|
|
|
|
|
|
|
{ nullptr, DXGI_FORMAT_UNKNOWN }
|
|
|
|
};
|
|
|
|
|
2016-09-27 07:24:19 +00:00
|
|
|
const SValue g_pReadOnlyFormats[] =
|
|
|
|
{
|
|
|
|
DEFFMT(R32G32B32A32_TYPELESS),
|
|
|
|
DEFFMT(R32G32B32_TYPELESS),
|
|
|
|
DEFFMT(R16G16B16A16_TYPELESS),
|
|
|
|
DEFFMT(R32G32_TYPELESS),
|
|
|
|
DEFFMT(R32G8X24_TYPELESS),
|
|
|
|
DEFFMT(D32_FLOAT_S8X24_UINT),
|
|
|
|
DEFFMT(R32_FLOAT_X8X24_TYPELESS),
|
|
|
|
DEFFMT(X32_TYPELESS_G8X24_UINT),
|
|
|
|
DEFFMT(R10G10B10A2_TYPELESS),
|
|
|
|
DEFFMT(R8G8B8A8_TYPELESS),
|
|
|
|
DEFFMT(R16G16_TYPELESS),
|
|
|
|
DEFFMT(R32_TYPELESS),
|
|
|
|
DEFFMT(D32_FLOAT),
|
|
|
|
DEFFMT(R24G8_TYPELESS),
|
|
|
|
DEFFMT(D24_UNORM_S8_UINT),
|
|
|
|
DEFFMT(R24_UNORM_X8_TYPELESS),
|
|
|
|
DEFFMT(X24_TYPELESS_G8_UINT),
|
|
|
|
DEFFMT(R8G8_TYPELESS),
|
|
|
|
DEFFMT(R16_TYPELESS),
|
|
|
|
DEFFMT(R8_TYPELESS),
|
|
|
|
DEFFMT(BC1_TYPELESS),
|
2016-09-25 23:04:44 +00:00
|
|
|
DEFFMT(BC1_UNORM),
|
|
|
|
DEFFMT(BC1_UNORM_SRGB),
|
2016-09-27 07:24:19 +00:00
|
|
|
DEFFMT(BC2_TYPELESS),
|
2016-09-25 23:04:44 +00:00
|
|
|
DEFFMT(BC2_UNORM),
|
|
|
|
DEFFMT(BC2_UNORM_SRGB),
|
2016-09-27 07:24:19 +00:00
|
|
|
DEFFMT(BC3_TYPELESS),
|
2016-09-25 23:04:44 +00:00
|
|
|
DEFFMT(BC3_UNORM),
|
|
|
|
DEFFMT(BC3_UNORM_SRGB),
|
2016-09-27 07:24:19 +00:00
|
|
|
DEFFMT(BC4_TYPELESS),
|
2016-09-25 23:04:44 +00:00
|
|
|
DEFFMT(BC4_UNORM),
|
|
|
|
DEFFMT(BC4_SNORM),
|
2016-09-27 07:24:19 +00:00
|
|
|
DEFFMT(BC5_TYPELESS),
|
2016-09-25 23:04:44 +00:00
|
|
|
DEFFMT(BC5_UNORM),
|
|
|
|
DEFFMT(BC5_SNORM),
|
|
|
|
|
|
|
|
// DXGI 1.1 formats
|
2016-09-27 07:24:19 +00:00
|
|
|
DEFFMT(B8G8R8A8_TYPELESS),
|
|
|
|
DEFFMT(B8G8R8X8_TYPELESS),
|
|
|
|
DEFFMT(BC6H_TYPELESS),
|
2016-09-25 23:04:44 +00:00
|
|
|
DEFFMT(BC6H_UF16),
|
|
|
|
DEFFMT(BC6H_SF16),
|
2016-09-27 07:24:19 +00:00
|
|
|
DEFFMT(BC7_TYPELESS),
|
2016-09-25 23:04:44 +00:00
|
|
|
DEFFMT(BC7_UNORM),
|
|
|
|
DEFFMT(BC7_UNORM_SRGB),
|
|
|
|
|
|
|
|
// DXGI 1.2 formats
|
|
|
|
DEFFMT(AI44),
|
|
|
|
DEFFMT(IA44),
|
|
|
|
DEFFMT(P8),
|
|
|
|
DEFFMT(A8P8),
|
2016-09-27 07:24:19 +00:00
|
|
|
DEFFMT(NV12),
|
|
|
|
DEFFMT(P010),
|
|
|
|
DEFFMT(P016),
|
|
|
|
DEFFMT(420_OPAQUE),
|
|
|
|
DEFFMT(NV11),
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
// DXGI 1.3 formats
|
2016-09-27 07:24:19 +00:00
|
|
|
{ L"P208", DXGI_FORMAT(130) },
|
|
|
|
{ L"V208", DXGI_FORMAT(131) },
|
|
|
|
{ L"V408", DXGI_FORMAT(132) },
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
// Xbox-specific formats
|
2016-09-27 07:24:19 +00:00
|
|
|
{ L"R10G10B10_7E3_A2_FLOAT (Xbox)", DXGI_FORMAT(116) },
|
|
|
|
{ L"R10G10B10_6E4_A2_FLOAT (Xbox)", DXGI_FORMAT(117) },
|
|
|
|
{ L"D16_UNORM_S8_UINT (Xbox)", DXGI_FORMAT(118) },
|
|
|
|
{ L"R16_UNORM_X8_TYPELESS (Xbox)", DXGI_FORMAT(119) },
|
|
|
|
{ L"X16_TYPELESS_G8_UINT (Xbox)", DXGI_FORMAT(120) },
|
|
|
|
{ L"R10G10B10_SNORM_A2_UNORM (Xbox)", DXGI_FORMAT(189) },
|
|
|
|
{ L"R4G4_UNORM (Xbox)", DXGI_FORMAT(190) },
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
{ nullptr, DXGI_FORMAT_UNKNOWN }
|
|
|
|
};
|
|
|
|
|
|
|
|
const SValue g_pFilters[] =
|
|
|
|
{
|
|
|
|
{ L"POINT", TEX_FILTER_POINT },
|
|
|
|
{ L"LINEAR", TEX_FILTER_LINEAR },
|
|
|
|
{ L"CUBIC", TEX_FILTER_CUBIC },
|
|
|
|
{ L"FANT", TEX_FILTER_FANT },
|
|
|
|
{ L"BOX", TEX_FILTER_BOX },
|
|
|
|
{ L"TRIANGLE", TEX_FILTER_TRIANGLE },
|
|
|
|
{ L"POINT_DITHER", TEX_FILTER_POINT | TEX_FILTER_DITHER },
|
|
|
|
{ L"LINEAR_DITHER", TEX_FILTER_LINEAR | TEX_FILTER_DITHER },
|
|
|
|
{ L"CUBIC_DITHER", TEX_FILTER_CUBIC | TEX_FILTER_DITHER },
|
|
|
|
{ L"FANT_DITHER", TEX_FILTER_FANT | TEX_FILTER_DITHER },
|
|
|
|
{ L"BOX_DITHER", TEX_FILTER_BOX | TEX_FILTER_DITHER },
|
|
|
|
{ L"TRIANGLE_DITHER", TEX_FILTER_TRIANGLE | TEX_FILTER_DITHER },
|
|
|
|
{ L"POINT_DITHER_DIFFUSION", TEX_FILTER_POINT | TEX_FILTER_DITHER_DIFFUSION },
|
|
|
|
{ L"LINEAR_DITHER_DIFFUSION", TEX_FILTER_LINEAR | TEX_FILTER_DITHER_DIFFUSION },
|
|
|
|
{ L"CUBIC_DITHER_DIFFUSION", TEX_FILTER_CUBIC | TEX_FILTER_DITHER_DIFFUSION },
|
|
|
|
{ L"FANT_DITHER_DIFFUSION", TEX_FILTER_FANT | TEX_FILTER_DITHER_DIFFUSION },
|
|
|
|
{ L"BOX_DITHER_DIFFUSION", TEX_FILTER_BOX | TEX_FILTER_DITHER_DIFFUSION },
|
|
|
|
{ L"TRIANGLE_DITHER_DIFFUSION", TEX_FILTER_TRIANGLE | TEX_FILTER_DITHER_DIFFUSION },
|
|
|
|
{ nullptr, TEX_FILTER_DEFAULT }
|
|
|
|
};
|
|
|
|
|
2019-09-14 00:31:09 +00:00
|
|
|
#define CODEC_DDS 0xFFFF0001
|
2016-09-27 07:24:19 +00:00
|
|
|
#define CODEC_TGA 0xFFFF0002
|
|
|
|
#define CODEC_HDR 0xFFFF0005
|
2019-07-06 06:48:39 +00:00
|
|
|
|
|
|
|
#ifdef USE_OPENEXR
|
2016-10-02 19:44:07 +00:00
|
|
|
#define CODEC_EXR 0xFFFF0006
|
2019-07-06 06:48:39 +00:00
|
|
|
#endif
|
2016-09-27 07:24:19 +00:00
|
|
|
|
2018-02-09 22:45:34 +00:00
|
|
|
const SValue g_pDumpFileTypes[] =
|
|
|
|
{
|
2021-08-01 00:03:54 +00:00
|
|
|
{ L"bmp", WIC_CODEC_BMP },
|
|
|
|
{ L"jpg", WIC_CODEC_JPEG },
|
|
|
|
{ L"jpeg", WIC_CODEC_JPEG },
|
|
|
|
{ L"png", WIC_CODEC_PNG },
|
|
|
|
{ L"tga", CODEC_TGA },
|
|
|
|
{ L"hdr", CODEC_HDR },
|
|
|
|
{ L"tif", WIC_CODEC_TIFF },
|
|
|
|
{ L"tiff", WIC_CODEC_TIFF },
|
|
|
|
{ L"jxr", WIC_CODEC_WMP },
|
2018-02-09 22:45:34 +00:00
|
|
|
#ifdef USE_OPENEXR
|
2021-08-01 00:03:54 +00:00
|
|
|
{ L"exr", CODEC_EXR },
|
2018-02-09 22:45:34 +00:00
|
|
|
#endif
|
|
|
|
{ nullptr, CODEC_DDS }
|
|
|
|
};
|
|
|
|
|
2016-09-27 07:24:19 +00:00
|
|
|
const SValue g_pExtFileTypes[] =
|
|
|
|
{
|
2021-08-01 00:03:54 +00:00
|
|
|
{ L".bmp", WIC_CODEC_BMP },
|
|
|
|
{ L".jpg", WIC_CODEC_JPEG },
|
|
|
|
{ L".jpeg", WIC_CODEC_JPEG },
|
|
|
|
{ L".png", WIC_CODEC_PNG },
|
|
|
|
{ L".dds", CODEC_DDS },
|
|
|
|
{ L".tga", CODEC_TGA },
|
|
|
|
{ L".hdr", CODEC_HDR },
|
|
|
|
{ L".tif", WIC_CODEC_TIFF },
|
|
|
|
{ L".tiff", WIC_CODEC_TIFF },
|
|
|
|
{ L".wdp", WIC_CODEC_WMP },
|
|
|
|
{ L".hdp", WIC_CODEC_WMP },
|
|
|
|
{ L".jxr", WIC_CODEC_WMP },
|
2016-10-02 19:44:07 +00:00
|
|
|
#ifdef USE_OPENEXR
|
2021-08-01 00:03:54 +00:00
|
|
|
{ L"exr", CODEC_EXR },
|
2016-10-02 19:44:07 +00:00
|
|
|
#endif
|
2016-09-27 07:24:19 +00:00
|
|
|
{ nullptr, CODEC_DDS }
|
|
|
|
};
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2020-06-05 03:07:21 +00:00
|
|
|
inline HANDLE safe_handle(HANDLE h) noexcept { return (h == INVALID_HANDLE_VALUE) ? nullptr : h; }
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2020-06-05 03:07:21 +00:00
|
|
|
struct find_closer { void operator()(HANDLE h) noexcept { assert(h != INVALID_HANDLE_VALUE); if (h) FindClose(h); } };
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2020-01-19 09:36:52 +00:00
|
|
|
using ScopedFindHandle = std::unique_ptr<void, find_closer>;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2019-07-06 06:48:39 +00:00
|
|
|
#ifdef _PREFAST_
|
2016-09-25 23:04:44 +00:00
|
|
|
#pragma prefast(disable : 26018, "Only used with static internal arrays")
|
2019-07-06 06:48:39 +00:00
|
|
|
#endif
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2021-04-25 02:57:56 +00:00
|
|
|
uint32_t LookupByName(const wchar_t *pName, const SValue *pArray)
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
2021-04-25 02:57:56 +00:00
|
|
|
while (pArray->name)
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
2021-04-25 02:57:56 +00:00
|
|
|
if (!_wcsicmp(pName, pArray->name))
|
|
|
|
return pArray->value;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
pArray++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-04-25 02:57:56 +00:00
|
|
|
const wchar_t* LookupByValue(uint32_t pValue, const SValue *pArray)
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
2021-04-25 02:57:56 +00:00
|
|
|
while (pArray->name)
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
2021-04-25 02:57:56 +00:00
|
|
|
if (pValue == pArray->value)
|
|
|
|
return pArray->name;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
pArray++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return L"";
|
|
|
|
}
|
|
|
|
|
2023-06-13 22:40:45 +00:00
|
|
|
void SearchForFiles(const std::filesystem::path& path, std::list<SConversion>& files, bool recursive)
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
|
|
|
// Process files
|
2019-02-07 22:52:57 +00:00
|
|
|
WIN32_FIND_DATAW findData = {};
|
2023-06-13 22:40:45 +00:00
|
|
|
ScopedFindHandle hFile(safe_handle(FindFirstFileExW(path.c_str(),
|
2016-09-25 23:04:44 +00:00
|
|
|
FindExInfoBasic, &findData,
|
|
|
|
FindExSearchNameMatch, nullptr,
|
|
|
|
FIND_FIRST_EX_LARGE_FETCH)));
|
|
|
|
if (hFile)
|
|
|
|
{
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (!(findData.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_DIRECTORY)))
|
|
|
|
{
|
2021-01-09 20:44:59 +00:00
|
|
|
SConversion conv = {};
|
2023-06-13 22:40:45 +00:00
|
|
|
conv.szSrc = path.parent_path().append(findData.cFileName).native();
|
2016-09-25 23:04:44 +00:00
|
|
|
files.push_back(conv);
|
|
|
|
}
|
|
|
|
|
2019-02-07 22:52:57 +00:00
|
|
|
if (!FindNextFileW(hFile.get(), &findData))
|
2016-09-25 23:04:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process directories
|
|
|
|
if (recursive)
|
|
|
|
{
|
2023-06-13 22:40:45 +00:00
|
|
|
auto searchDir = path.parent_path().append(L"*");
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2023-06-13 22:40:45 +00:00
|
|
|
hFile.reset(safe_handle(FindFirstFileExW(searchDir.c_str(),
|
2016-09-25 23:04:44 +00:00
|
|
|
FindExInfoBasic, &findData,
|
|
|
|
FindExSearchLimitToDirectories, nullptr,
|
|
|
|
FIND_FIRST_EX_LARGE_FETCH)));
|
|
|
|
if (!hFile)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
|
|
{
|
|
|
|
if (findData.cFileName[0] != L'.')
|
|
|
|
{
|
2023-06-13 22:40:45 +00:00
|
|
|
auto subdir = path.parent_path().append(findData.cFileName).append(path.filename().c_str());
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
SearchForFiles(subdir, files, recursive);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-07 22:52:57 +00:00
|
|
|
if (!FindNextFileW(hFile.get(), &findData))
|
2016-09-25 23:04:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-08 22:00:22 +00:00
|
|
|
void ProcessFileList(std::wifstream& inFile, std::list<SConversion>& files)
|
|
|
|
{
|
|
|
|
std::list<SConversion> flist;
|
|
|
|
std::set<std::wstring> excludes;
|
2023-06-13 22:40:45 +00:00
|
|
|
|
2021-06-08 22:00:22 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
2023-10-06 21:18:53 +00:00
|
|
|
std::wstring fname;
|
|
|
|
std::getline(inFile, fname);
|
2021-06-08 22:00:22 +00:00
|
|
|
if (!inFile)
|
|
|
|
break;
|
|
|
|
|
2023-06-13 22:40:45 +00:00
|
|
|
if (fname[0] == L'#')
|
2021-06-08 22:00:22 +00:00
|
|
|
{
|
|
|
|
// Comment
|
|
|
|
}
|
2023-06-13 22:40:45 +00:00
|
|
|
else if (fname[0] == L'-')
|
2021-06-08 22:00:22 +00:00
|
|
|
{
|
|
|
|
if (flist.empty())
|
|
|
|
{
|
2023-10-06 21:18:53 +00:00
|
|
|
wprintf(L"WARNING: Ignoring the line '%ls' in -flist\n", fname.c_str());
|
2021-06-08 22:00:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-06 21:18:53 +00:00
|
|
|
std::filesystem::path path(fname.c_str() + 1);
|
2023-03-27 23:02:41 +00:00
|
|
|
auto& npath = path.make_preferred();
|
2023-10-06 21:18:53 +00:00
|
|
|
if (wcspbrk(fname.c_str(), L"?*") != nullptr)
|
2021-06-08 22:00:22 +00:00
|
|
|
{
|
|
|
|
std::list<SConversion> removeFiles;
|
2023-06-13 22:40:45 +00:00
|
|
|
SearchForFiles(npath, removeFiles, false);
|
2021-06-08 22:00:22 +00:00
|
|
|
|
2023-03-27 23:02:41 +00:00
|
|
|
for (auto& it : removeFiles)
|
2021-06-08 22:00:22 +00:00
|
|
|
{
|
2023-06-13 22:40:45 +00:00
|
|
|
std::wstring name = it.szSrc;
|
|
|
|
std::transform(name.begin(), name.end(), name.begin(), towlower);
|
|
|
|
excludes.insert(name);
|
2021-06-08 22:00:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-03-27 23:02:41 +00:00
|
|
|
std::wstring name = npath.c_str();
|
2021-06-08 22:00:22 +00:00
|
|
|
std::transform(name.begin(), name.end(), name.begin(), towlower);
|
|
|
|
excludes.insert(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-10-06 21:18:53 +00:00
|
|
|
else if (wcspbrk(fname.c_str(), L"?*") != nullptr)
|
2021-06-08 22:00:22 +00:00
|
|
|
{
|
2023-10-06 21:18:53 +00:00
|
|
|
std::filesystem::path path(fname.c_str());
|
2023-06-13 22:40:45 +00:00
|
|
|
SearchForFiles(path.make_preferred(), flist, false);
|
2021-06-08 22:00:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SConversion conv = {};
|
2023-10-06 21:18:53 +00:00
|
|
|
std::filesystem::path path(fname.c_str());
|
2023-06-13 22:40:45 +00:00
|
|
|
conv.szSrc = path.make_preferred().native();
|
2021-06-08 22:00:22 +00:00
|
|
|
flist.push_back(conv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inFile.close();
|
|
|
|
|
|
|
|
if (!excludes.empty())
|
|
|
|
{
|
|
|
|
// Remove any excluded files
|
|
|
|
for (auto it = flist.begin(); it != flist.end();)
|
|
|
|
{
|
|
|
|
std::wstring name = it->szSrc;
|
|
|
|
std::transform(name.begin(), name.end(), name.begin(), towlower);
|
|
|
|
auto item = it;
|
|
|
|
++it;
|
|
|
|
if (excludes.find(name) != excludes.end())
|
|
|
|
{
|
|
|
|
flist.erase(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flist.empty())
|
|
|
|
{
|
|
|
|
wprintf(L"WARNING: No file names found in -flist\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
files.splice(files.end(), flist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-25 23:04:44 +00:00
|
|
|
void PrintFormat(DXGI_FORMAT Format)
|
|
|
|
{
|
2021-04-25 02:57:56 +00:00
|
|
|
for (auto pFormat = g_pFormats; pFormat->name; pFormat++)
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
2021-04-25 02:57:56 +00:00
|
|
|
if (static_cast<DXGI_FORMAT>(pFormat->value) == Format)
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
2021-04-25 02:57:56 +00:00
|
|
|
wprintf(L"%ls", pFormat->name);
|
2018-01-09 17:26:54 +00:00
|
|
|
return;
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-27 07:24:19 +00:00
|
|
|
|
2021-04-25 02:57:56 +00:00
|
|
|
for (auto pFormat = g_pReadOnlyFormats; pFormat->name; pFormat++)
|
2016-09-27 07:24:19 +00:00
|
|
|
{
|
2021-04-25 02:57:56 +00:00
|
|
|
if (static_cast<DXGI_FORMAT>(pFormat->value) == Format)
|
2016-09-27 07:24:19 +00:00
|
|
|
{
|
2021-04-25 02:57:56 +00:00
|
|
|
wprintf(L"%ls", pFormat->name);
|
2016-09-27 07:24:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wprintf(L"*UNKNOWN*");
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PrintList(size_t cch, const SValue *pValue)
|
|
|
|
{
|
2021-04-25 02:57:56 +00:00
|
|
|
while (pValue->name)
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
2022-03-01 22:31:55 +00:00
|
|
|
const size_t cchName = wcslen(pValue->name);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
if (cch + cchName + 2 >= 80)
|
|
|
|
{
|
|
|
|
wprintf(L"\n ");
|
|
|
|
cch = 6;
|
|
|
|
}
|
|
|
|
|
2021-04-25 02:57:56 +00:00
|
|
|
wprintf(L"%ls ", pValue->name);
|
2016-09-25 23:04:44 +00:00
|
|
|
cch += cchName + 2;
|
|
|
|
pValue++;
|
|
|
|
}
|
|
|
|
|
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
|
2023-03-27 23:02:41 +00:00
|
|
|
void PrintLogo(bool versionOnly)
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
2020-08-15 22:57:39 +00:00
|
|
|
wchar_t version[32] = {};
|
|
|
|
|
|
|
|
wchar_t appName[_MAX_PATH] = {};
|
2023-06-13 22:40:45 +00:00
|
|
|
if (GetModuleFileNameW(nullptr, appName, _MAX_PATH))
|
2020-08-15 22:57:39 +00:00
|
|
|
{
|
2022-03-01 22:31:55 +00:00
|
|
|
const DWORD size = GetFileVersionInfoSizeW(appName, nullptr);
|
2020-08-15 22:57:39 +00:00
|
|
|
if (size > 0)
|
|
|
|
{
|
|
|
|
auto verInfo = std::make_unique<uint8_t[]>(size);
|
|
|
|
if (GetFileVersionInfoW(appName, 0, size, verInfo.get()))
|
|
|
|
{
|
|
|
|
LPVOID lpstr = nullptr;
|
|
|
|
UINT strLen = 0;
|
|
|
|
if (VerQueryValueW(verInfo.get(), L"\\StringFileInfo\\040904B0\\ProductVersion", &lpstr, &strLen))
|
|
|
|
{
|
|
|
|
wcsncpy_s(version, reinterpret_cast<const wchar_t*>(lpstr), strLen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*version || wcscmp(version, L"1.0.0.0") == 0)
|
|
|
|
{
|
|
|
|
swprintf_s(version, L"%03d (library)", DIRECTX_TEX_VERSION);
|
|
|
|
}
|
|
|
|
|
2023-03-27 23:02:41 +00:00
|
|
|
if (versionOnly)
|
|
|
|
{
|
|
|
|
wprintf(L"texdiag version %ls\n", version);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wprintf(L"Microsoft (R) DirectX Texture Diagnostic Tool [DirectXTex] Version %ls\n", version);
|
|
|
|
wprintf(L"Copyright (C) Microsoft Corp.\n");
|
|
|
|
#ifdef _DEBUG
|
|
|
|
wprintf(L"*** Debug build ***\n");
|
|
|
|
#endif
|
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PrintUsage()
|
|
|
|
{
|
2023-03-27 23:02:41 +00:00
|
|
|
PrintLogo(false);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-10-25 20:18:09 +00:00
|
|
|
static const wchar_t* const s_usage =
|
2023-03-27 23:02:41 +00:00
|
|
|
L"Usage: texdiag <command> <options> [--] <files>\n"
|
2022-10-25 20:18:09 +00:00
|
|
|
L"\n"
|
|
|
|
L" info Output image metadata\n"
|
|
|
|
L" analyze Analyze and summarize image information\n"
|
|
|
|
L" compare Compare two images with MSE error metric\n"
|
|
|
|
L" diff Generate difference image from two images\n"
|
|
|
|
L" dumpbc Dump out compressed blocks (DDS BC only)\n"
|
|
|
|
L" dumpdds Dump out all the images in a complex DDS\n"
|
|
|
|
L"\n"
|
|
|
|
L" -r wildcard filename search is recursive\n"
|
|
|
|
L" -if <filter> image filtering\n"
|
|
|
|
L"\n"
|
|
|
|
L" (DDS input only)\n"
|
|
|
|
L" -t{u|f} TYPELESS format is treated as UNORM or FLOAT\n"
|
|
|
|
L" -dword Use DWORD instead of BYTE alignment\n"
|
|
|
|
L" -badtails Fix for older DXTn with bad mipchain tails\n"
|
|
|
|
L" -xlum expand legacy L8, L16, and A8P8 formats\n"
|
|
|
|
L"\n"
|
|
|
|
L" (diff only)\n"
|
|
|
|
L" -f <format> format\n"
|
|
|
|
L" -o <filename> output filename\n"
|
|
|
|
L" -l force output filename to lower case\n"
|
|
|
|
L" -y overwrite existing output file (if any)\n"
|
|
|
|
L" -c <hex-RGB> highlight difference color (defaults to off)\n"
|
|
|
|
L" -t <threshold> highlight threshold (defaults to 0.25)\n"
|
|
|
|
L"\n"
|
|
|
|
L" (dumpbc only)\n"
|
|
|
|
L" -targetx <num> dump pixels at location x (defaults to all)\n"
|
|
|
|
L" -targety <num> dump pixels at location y (defaults to all)\n"
|
|
|
|
L"\n"
|
|
|
|
L" (dumpdds only)\n"
|
|
|
|
L" -ft <filetype> output file type\n"
|
|
|
|
L"\n"
|
|
|
|
L" -nologo suppress copyright message\n"
|
2023-03-27 23:02:41 +00:00
|
|
|
L" -flist <filename> use text file with a list of input files (one per line)\n"
|
|
|
|
L"\n"
|
|
|
|
L" '-- ' is needed if any input filepath starts with the '-' or '/' character\n";
|
2022-10-25 20:18:09 +00:00
|
|
|
|
|
|
|
wprintf(L"%ls", s_usage);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2016-09-27 07:24:19 +00:00
|
|
|
wprintf(L"\n <format>: ");
|
|
|
|
PrintList(13, g_pFormats);
|
2018-02-22 08:17:49 +00:00
|
|
|
wprintf(L" ");
|
|
|
|
PrintList(13, g_pFormatAliases);
|
2016-09-27 07:24:19 +00:00
|
|
|
|
2016-09-25 23:04:44 +00:00
|
|
|
wprintf(L"\n <filter>: ");
|
|
|
|
PrintList(13, g_pFilters);
|
2018-02-09 22:45:34 +00:00
|
|
|
|
|
|
|
wprintf(L"\n <filetype>: ");
|
|
|
|
PrintList(15, g_pDumpFileTypes);
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
|
2021-04-01 07:59:57 +00:00
|
|
|
const wchar_t* GetErrorDesc(HRESULT hr)
|
|
|
|
{
|
|
|
|
static wchar_t desc[1024] = {};
|
|
|
|
|
|
|
|
LPWSTR errorText = nullptr;
|
|
|
|
|
2022-03-01 22:31:55 +00:00
|
|
|
const DWORD result = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
2021-06-02 21:36:31 +00:00
|
|
|
nullptr, static_cast<DWORD>(hr),
|
2021-04-01 07:59:57 +00:00
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPWSTR>(&errorText), 0, nullptr);
|
|
|
|
|
|
|
|
*desc = 0;
|
|
|
|
|
|
|
|
if (result > 0 && errorText)
|
|
|
|
{
|
|
|
|
swprintf_s(desc, L": %ls", errorText);
|
|
|
|
|
|
|
|
size_t len = wcslen(desc);
|
2022-03-02 22:25:27 +00:00
|
|
|
if (len >= 1)
|
2021-04-01 07:59:57 +00:00
|
|
|
{
|
|
|
|
desc[len - 1] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (errorText)
|
|
|
|
LocalFree(errorText);
|
2023-05-17 18:38:08 +00:00
|
|
|
|
|
|
|
for(wchar_t* ptr = desc; *ptr != 0; ++ptr)
|
|
|
|
{
|
|
|
|
if (*ptr == L'\r' || *ptr == L'\n')
|
|
|
|
{
|
|
|
|
*ptr = L' ';
|
|
|
|
}
|
|
|
|
}
|
2021-04-01 07:59:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
|
2020-06-05 03:07:21 +00:00
|
|
|
HRESULT LoadImage(
|
|
|
|
const wchar_t *fileName,
|
2021-04-25 02:57:56 +00:00
|
|
|
uint32_t dwOptions,
|
2020-06-05 03:07:21 +00:00
|
|
|
TEX_FILTER_FLAGS dwFilter,
|
|
|
|
TexMetadata& info,
|
|
|
|
std::unique_ptr<ScratchImage>& image)
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
|
|
|
if (!fileName)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
image.reset(new (std::nothrow) ScratchImage);
|
|
|
|
if (!image)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2023-06-13 22:40:45 +00:00
|
|
|
std::filesystem::path fname(fileName);
|
|
|
|
auto const ext = fname.extension();
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2023-06-13 22:40:45 +00:00
|
|
|
if (_wcsicmp(ext.c_str(), L".dds") == 0)
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
2020-07-09 21:13:38 +00:00
|
|
|
DDS_FLAGS ddsFlags = DDS_FLAGS_ALLOW_LARGE_FILES;
|
2016-09-25 23:04:44 +00:00
|
|
|
if (dwOptions & (1 << OPT_DDS_DWORD_ALIGN))
|
|
|
|
ddsFlags |= DDS_FLAGS_LEGACY_DWORD;
|
|
|
|
if (dwOptions & (1 << OPT_EXPAND_LUMINANCE))
|
|
|
|
ddsFlags |= DDS_FLAGS_EXPAND_LUMINANCE;
|
|
|
|
if (dwOptions & (1 << OPT_DDS_BAD_DXTN_TAILS))
|
|
|
|
ddsFlags |= DDS_FLAGS_BAD_DXTN_TAILS;
|
|
|
|
|
2016-10-02 19:44:07 +00:00
|
|
|
HRESULT hr = LoadFromDDSFile(fileName, ddsFlags, &info, *image);
|
2016-09-25 23:34:00 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
if (IsTypeless(info.format))
|
|
|
|
{
|
|
|
|
if (dwOptions & (1 << OPT_TYPELESS_UNORM))
|
|
|
|
{
|
|
|
|
info.format = MakeTypelessUNORM(info.format);
|
|
|
|
}
|
|
|
|
else if (dwOptions & (1 << OPT_TYPELESS_FLOAT))
|
|
|
|
{
|
|
|
|
info.format = MakeTypelessFLOAT(info.format);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsTypeless(info.format))
|
|
|
|
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
|
|
|
|
|
|
|
|
image->OverrideFormat(info.format);
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
2023-06-13 22:40:45 +00:00
|
|
|
else if (_wcsicmp(ext.c_str(), L".tga") == 0)
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
2020-09-30 19:37:49 +00:00
|
|
|
return LoadFromTGAFile(fileName, TGA_FLAGS_NONE, &info, *image);
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
2023-06-13 22:40:45 +00:00
|
|
|
else if (_wcsicmp(ext.c_str(), L".hdr") == 0)
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
2016-10-02 19:44:07 +00:00
|
|
|
return LoadFromHDRFile(fileName, &info, *image);
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
2022-04-04 22:03:02 +00:00
|
|
|
#ifdef USE_OPENEXR
|
2023-06-13 22:40:45 +00:00
|
|
|
else if (_wcsicmp(ext.c_str(), L".exr") == 0)
|
2016-10-02 19:44:07 +00:00
|
|
|
{
|
|
|
|
return LoadFromEXRFile(fileName, &info, *image);
|
|
|
|
}
|
2022-04-04 22:03:02 +00:00
|
|
|
#endif
|
2016-09-25 23:04:44 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// WIC shares the same filter values for mode and dither
|
2019-07-06 06:48:39 +00:00
|
|
|
static_assert(static_cast<int>(WIC_FLAGS_DITHER) == static_cast<int>(TEX_FILTER_DITHER), "WIC_FLAGS_* & TEX_FILTER_* should match");
|
|
|
|
static_assert(static_cast<int>(WIC_FLAGS_DITHER_DIFFUSION) == static_cast<int>(TEX_FILTER_DITHER_DIFFUSION), "WIC_FLAGS_* & TEX_FILTER_* should match");
|
|
|
|
static_assert(static_cast<int>(WIC_FLAGS_FILTER_POINT) == static_cast<int>(TEX_FILTER_POINT), "WIC_FLAGS_* & TEX_FILTER_* should match");
|
|
|
|
static_assert(static_cast<int>(WIC_FLAGS_FILTER_LINEAR) == static_cast<int>(TEX_FILTER_LINEAR), "WIC_FLAGS_* & TEX_FILTER_* should match");
|
|
|
|
static_assert(static_cast<int>(WIC_FLAGS_FILTER_CUBIC) == static_cast<int>(TEX_FILTER_CUBIC), "WIC_FLAGS_* & TEX_FILTER_* should match");
|
|
|
|
static_assert(static_cast<int>(WIC_FLAGS_FILTER_FANT) == static_cast<int>(TEX_FILTER_FANT), "WIC_FLAGS_* & TEX_FILTER_* should match");
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-03-02 22:25:27 +00:00
|
|
|
HRESULT hr = LoadFromWICFile(fileName, dwFilter | WIC_FLAGS_ALL_FRAMES, &info, *image);
|
|
|
|
if (hr == static_cast<HRESULT>(0xc00d5212) /* MF_E_TOPO_CODEC_NOT_FOUND */)
|
|
|
|
{
|
2023-06-13 22:40:45 +00:00
|
|
|
if (_wcsicmp(ext.c_str(), L".heic") == 0 || _wcsicmp(ext.c_str(), L".heif") == 0)
|
2022-03-02 22:25:27 +00:00
|
|
|
{
|
|
|
|
wprintf(L"\nINFO: This format requires installing the HEIF Image Extensions - https://aka.ms/heif\n");
|
|
|
|
}
|
2023-06-13 22:40:45 +00:00
|
|
|
else if (_wcsicmp(ext.c_str(), L".webp") == 0)
|
2022-03-02 22:25:27 +00:00
|
|
|
{
|
|
|
|
wprintf(L"\nINFO: This format requires installing the WEBP Image Extensions - https://www.microsoft.com/p/webp-image-extensions/9pg2dk419drg\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hr;
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-25 02:57:56 +00:00
|
|
|
HRESULT SaveImage(const Image* image, const wchar_t *fileName, uint32_t codec)
|
2016-09-27 07:24:19 +00:00
|
|
|
{
|
|
|
|
switch (codec)
|
|
|
|
{
|
|
|
|
case CODEC_DDS:
|
|
|
|
return SaveToDDSFile(*image, DDS_FLAGS_NONE, fileName);
|
|
|
|
|
|
|
|
case CODEC_TGA:
|
2020-09-30 19:37:49 +00:00
|
|
|
return SaveToTGAFile(*image, TGA_FLAGS_NONE, fileName);
|
2016-09-27 07:24:19 +00:00
|
|
|
|
|
|
|
case CODEC_HDR:
|
|
|
|
return SaveToHDRFile(*image, fileName);
|
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
#ifdef USE_OPENEXR
|
2016-10-02 19:44:07 +00:00
|
|
|
case CODEC_EXR:
|
|
|
|
return SaveToEXRFile(*image, fileName);
|
2022-04-04 22:03:02 +00:00
|
|
|
#endif
|
2016-10-02 19:44:07 +00:00
|
|
|
|
2016-09-27 07:24:19 +00:00
|
|
|
default:
|
|
|
|
return SaveToWICFile(*image, WIC_FLAGS_NONE, GetWICCodec(static_cast<WICCodecs>(codec)), fileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-25 23:04:44 +00:00
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
struct AnalyzeData
|
|
|
|
{
|
|
|
|
XMFLOAT4 imageMin;
|
|
|
|
XMFLOAT4 imageMax;
|
|
|
|
XMFLOAT4 imageAvg;
|
|
|
|
XMFLOAT4 imageVariance;
|
|
|
|
XMFLOAT4 imageStdDev;
|
2016-09-27 05:54:21 +00:00
|
|
|
float luminance;
|
2016-09-25 23:04:44 +00:00
|
|
|
size_t specials_x;
|
|
|
|
size_t specials_y;
|
|
|
|
size_t specials_z;
|
|
|
|
size_t specials_w;
|
|
|
|
|
|
|
|
void Print()
|
|
|
|
{
|
2016-09-27 05:54:21 +00:00
|
|
|
wprintf(L"\t Minimum - (%f %f %f %f)\n", imageMin.x, imageMin.y, imageMin.z, imageMin.w);
|
|
|
|
wprintf(L"\t Average - (%f %f %f %f)\n", imageAvg.x, imageAvg.y, imageAvg.z, imageAvg.w);
|
|
|
|
wprintf(L"\t Maximum - (%f %f %f %f)\n", imageMax.x, imageMax.y, imageMax.z, imageMax.w);
|
|
|
|
wprintf(L"\t Variance - (%f %f %f %f)\n", imageVariance.x, imageVariance.y, imageVariance.z, imageVariance.w);
|
|
|
|
wprintf(L"\t Std Dev - (%f %f %f %f)\n", imageStdDev.x, imageStdDev.y, imageStdDev.z, imageStdDev.w);
|
|
|
|
|
|
|
|
wprintf(L"\tLuminance - %f (maximum)\n", luminance);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
if ((specials_x > 0) || (specials_y > 0) || (specials_z > 0) || (specials_w > 0))
|
|
|
|
{
|
2018-05-02 00:34:54 +00:00
|
|
|
wprintf(L" FP specials - (%zu %zu %zu %zu)\n", specials_x, specials_y, specials_z, specials_w);
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT Analyze(const Image& image, _Out_ AnalyzeData& result)
|
|
|
|
{
|
|
|
|
memset(&result, 0, sizeof(AnalyzeData));
|
|
|
|
|
|
|
|
// First pass
|
|
|
|
XMVECTOR minv = g_XMFltMax;
|
|
|
|
XMVECTOR maxv = XMVectorNegate(g_XMFltMax);
|
|
|
|
XMVECTOR acc = g_XMZero;
|
2016-09-27 05:54:21 +00:00
|
|
|
XMVECTOR luminance = g_XMZero;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
size_t totalPixels = 0;
|
|
|
|
|
|
|
|
HRESULT hr = EvaluateImage(image, [&](const XMVECTOR * pixels, size_t width, size_t y)
|
2019-09-14 00:31:09 +00:00
|
|
|
{
|
|
|
|
static const XMVECTORF32 s_luminance = { { { 0.3f, 0.59f, 0.11f, 0.f } } };
|
2016-09-27 05:54:21 +00:00
|
|
|
|
2019-09-14 00:31:09 +00:00
|
|
|
UNREFERENCED_PARAMETER(y);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2019-09-14 00:31:09 +00:00
|
|
|
for (size_t x = 0; x < width; ++x)
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
2022-03-01 22:31:55 +00:00
|
|
|
const XMVECTOR v = *pixels++;
|
2019-09-14 00:31:09 +00:00
|
|
|
luminance = XMVectorMax(luminance, XMVector3Dot(v, s_luminance));
|
|
|
|
minv = XMVectorMin(minv, v);
|
|
|
|
maxv = XMVectorMax(maxv, v);
|
|
|
|
acc = XMVectorAdd(v, acc);
|
|
|
|
++totalPixels;
|
|
|
|
|
|
|
|
XMFLOAT4 f;
|
|
|
|
XMStoreFloat4(&f, v);
|
|
|
|
if (!isfinite(f.x))
|
|
|
|
{
|
|
|
|
++result.specials_x;
|
|
|
|
}
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2019-09-14 00:31:09 +00:00
|
|
|
if (!isfinite(f.y))
|
|
|
|
{
|
|
|
|
++result.specials_y;
|
|
|
|
}
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2019-09-14 00:31:09 +00:00
|
|
|
if (!isfinite(f.z))
|
|
|
|
{
|
|
|
|
++result.specials_z;
|
|
|
|
}
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2019-09-14 00:31:09 +00:00
|
|
|
if (!isfinite(f.w))
|
|
|
|
{
|
|
|
|
++result.specials_w;
|
|
|
|
}
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
2019-09-14 00:31:09 +00:00
|
|
|
});
|
2016-09-25 23:04:44 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
if (!totalPixels)
|
|
|
|
return S_FALSE;
|
|
|
|
|
2016-09-27 05:54:21 +00:00
|
|
|
result.luminance = XMVectorGetX(luminance);
|
2016-09-25 23:04:44 +00:00
|
|
|
XMStoreFloat4(&result.imageMin, minv);
|
|
|
|
XMStoreFloat4(&result.imageMax, maxv);
|
|
|
|
|
2022-03-01 22:31:55 +00:00
|
|
|
const XMVECTOR pixelv = XMVectorReplicate(float(totalPixels));
|
2016-09-25 23:04:44 +00:00
|
|
|
XMVECTOR avgv = XMVectorDivide(acc, pixelv);
|
|
|
|
XMStoreFloat4(&result.imageAvg, avgv);
|
|
|
|
|
|
|
|
// Second pass
|
|
|
|
acc = g_XMZero;
|
|
|
|
|
|
|
|
hr = EvaluateImage(image, [&](const XMVECTOR * pixels, size_t width, size_t y)
|
|
|
|
{
|
2019-09-14 00:31:09 +00:00
|
|
|
UNREFERENCED_PARAMETER(y);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2019-09-14 00:31:09 +00:00
|
|
|
for (size_t x = 0; x < width; ++x)
|
|
|
|
{
|
2022-03-01 22:31:55 +00:00
|
|
|
const XMVECTOR v = *pixels++;
|
2019-09-14 00:31:09 +00:00
|
|
|
|
2022-03-01 22:31:55 +00:00
|
|
|
const XMVECTOR diff = XMVectorSubtract(v, avgv);
|
2019-09-14 00:31:09 +00:00
|
|
|
acc = XMVectorMultiplyAdd(diff, diff, acc);
|
|
|
|
}
|
|
|
|
});
|
2016-09-25 23:04:44 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
XMStoreFloat4(&result.imageVariance, acc);
|
|
|
|
|
2022-03-01 22:31:55 +00:00
|
|
|
const XMVECTOR stddev = XMVectorSqrt(acc);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
XMStoreFloat4(&result.imageStdDev, stddev);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
struct AnalyzeBCData
|
|
|
|
{
|
|
|
|
size_t blocks;
|
|
|
|
size_t blockHist[15];
|
|
|
|
|
|
|
|
void Print(DXGI_FORMAT fmt)
|
|
|
|
{
|
|
|
|
wprintf(L"\t Compression - ");
|
|
|
|
PrintFormat(fmt);
|
2018-05-02 00:34:54 +00:00
|
|
|
wprintf(L"\n\t Total blocks - %zu\n", blocks);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
switch (fmt)
|
|
|
|
{
|
|
|
|
case DXGI_FORMAT_BC1_UNORM:
|
|
|
|
case DXGI_FORMAT_BC1_UNORM_SRGB:
|
2018-05-02 00:34:54 +00:00
|
|
|
wprintf(L"\t 4 color blocks - %zu\n", blockHist[0]);
|
|
|
|
wprintf(L"\t 3 color blocks - %zu\n", blockHist[1]);
|
2016-09-25 23:04:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// BC2 only has a single 'type' of block
|
|
|
|
|
|
|
|
case DXGI_FORMAT_BC3_UNORM:
|
|
|
|
case DXGI_FORMAT_BC3_UNORM_SRGB:
|
2018-05-02 00:34:54 +00:00
|
|
|
wprintf(L"\t 8 alpha blocks - %zu\n", blockHist[0]);
|
|
|
|
wprintf(L"\t 6 alpha blocks - %zu\n", blockHist[1]);
|
2016-09-25 23:04:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DXGI_FORMAT_BC4_UNORM:
|
|
|
|
case DXGI_FORMAT_BC4_SNORM:
|
2018-05-02 00:34:54 +00:00
|
|
|
wprintf(L"\t 8 red blocks - %zu\n", blockHist[0]);
|
|
|
|
wprintf(L"\t 6 red blocks - %zu\n", blockHist[1]);
|
2016-09-25 23:04:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DXGI_FORMAT_BC5_UNORM:
|
|
|
|
case DXGI_FORMAT_BC5_SNORM:
|
2018-05-02 00:34:54 +00:00
|
|
|
wprintf(L"\t 8 red blocks - %zu\n", blockHist[0]);
|
|
|
|
wprintf(L"\t 6 red blocks - %zu\n", blockHist[1]);
|
|
|
|
wprintf(L"\t 8 green blocks - %zu\n", blockHist[2]);
|
|
|
|
wprintf(L"\t 6 green blocks - %zu\n", blockHist[3]);
|
2016-09-25 23:04:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DXGI_FORMAT_BC6H_UF16:
|
|
|
|
case DXGI_FORMAT_BC6H_SF16:
|
|
|
|
for (size_t j = 1; j <= 14; ++j)
|
|
|
|
{
|
|
|
|
if (blockHist[j] > 0)
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"\t Mode %02zu blocks - %zu\n", j, blockHist[j]);
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
if (blockHist[0] > 0)
|
2018-05-02 00:34:54 +00:00
|
|
|
wprintf(L"\tReserved mode blcks - %zu\n", blockHist[0]);
|
2016-09-25 23:04:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DXGI_FORMAT_BC7_UNORM:
|
|
|
|
case DXGI_FORMAT_BC7_UNORM_SRGB:
|
|
|
|
for (size_t j = 0; j <= 7; ++j)
|
|
|
|
{
|
|
|
|
if (blockHist[j] > 0)
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"\t Mode %02zu blocks - %zu\n", j, blockHist[j]);
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
if (blockHist[8] > 0)
|
2018-05-02 00:34:54 +00:00
|
|
|
wprintf(L"\tReserved mode blcks - %zu\n", blockHist[8]);
|
2016-09-25 23:04:44 +00:00
|
|
|
break;
|
2019-07-06 06:48:39 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#pragma pack(push,1)
|
|
|
|
struct BC1Block
|
|
|
|
{
|
|
|
|
uint16_t rgb[2]; // 565 colors
|
|
|
|
uint32_t bitmap; // 2bpp rgb bitmap
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BC2Block
|
|
|
|
{
|
|
|
|
uint32_t bitmap[2]; // 4bpp alpha bitmap
|
|
|
|
BC1Block bc1; // BC1 rgb data
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BC3Block
|
|
|
|
{
|
|
|
|
uint8_t alpha[2]; // alpha values
|
|
|
|
uint8_t bitmap[6]; // 3bpp alpha bitmap
|
|
|
|
BC1Block bc1; // BC1 rgb data
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BC4UBlock
|
|
|
|
{
|
|
|
|
uint8_t red_0;
|
|
|
|
uint8_t red_1;
|
|
|
|
uint8_t indices[6];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BC4SBlock
|
|
|
|
{
|
|
|
|
int8_t red_0;
|
|
|
|
int8_t red_1;
|
|
|
|
uint8_t indices[6];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BC5UBlock
|
|
|
|
{
|
|
|
|
BC4UBlock u;
|
|
|
|
BC4UBlock v;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BC5SBlock
|
|
|
|
{
|
|
|
|
BC4SBlock u;
|
|
|
|
BC4SBlock v;
|
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
HRESULT AnalyzeBC(const Image& image, _Out_ AnalyzeBCData& result)
|
|
|
|
{
|
|
|
|
memset(&result, 0, sizeof(AnalyzeBCData));
|
|
|
|
|
|
|
|
size_t sbpp;
|
|
|
|
switch (image.format)
|
|
|
|
{
|
|
|
|
case DXGI_FORMAT_BC1_UNORM:
|
|
|
|
case DXGI_FORMAT_BC1_UNORM_SRGB:
|
|
|
|
case DXGI_FORMAT_BC4_UNORM:
|
|
|
|
case DXGI_FORMAT_BC4_SNORM:
|
|
|
|
sbpp = 8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DXGI_FORMAT_BC2_UNORM:
|
|
|
|
case DXGI_FORMAT_BC2_UNORM_SRGB:
|
|
|
|
case DXGI_FORMAT_BC3_UNORM:
|
|
|
|
case DXGI_FORMAT_BC3_UNORM_SRGB:
|
|
|
|
case DXGI_FORMAT_BC5_UNORM:
|
|
|
|
case DXGI_FORMAT_BC5_SNORM:
|
|
|
|
case DXGI_FORMAT_BC6H_UF16:
|
|
|
|
case DXGI_FORMAT_BC6H_SF16:
|
|
|
|
case DXGI_FORMAT_BC7_UNORM:
|
|
|
|
case DXGI_FORMAT_BC7_UNORM_SRGB:
|
|
|
|
sbpp = 16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
for (size_t count = 0; count < rowPitch; count += sbpp)
|
|
|
|
{
|
|
|
|
switch (image.format)
|
|
|
|
{
|
|
|
|
case DXGI_FORMAT_BC1_UNORM:
|
|
|
|
case DXGI_FORMAT_BC1_UNORM_SRGB:
|
|
|
|
{
|
2022-04-04 22:03:02 +00:00
|
|
|
auto block = reinterpret_cast<const BC1Block*>(sptr);
|
|
|
|
|
|
|
|
if (block->rgb[0] <= block->rgb[1])
|
|
|
|
{
|
|
|
|
// Transparent block
|
|
|
|
++result.blockHist[1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Opaque block
|
|
|
|
++result.blockHist[0];
|
|
|
|
}
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
2022-04-04 22:03:02 +00:00
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
// BC2 only has a single 'type' of block
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
case DXGI_FORMAT_BC3_UNORM:
|
|
|
|
case DXGI_FORMAT_BC3_UNORM_SRGB:
|
|
|
|
{
|
2022-04-04 22:03:02 +00:00
|
|
|
auto block = reinterpret_cast<const BC3Block*>(sptr);
|
|
|
|
|
|
|
|
if (block->alpha[0] > block->alpha[1])
|
|
|
|
{
|
|
|
|
// 8 alpha block
|
|
|
|
++result.blockHist[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// 6 alpha block
|
|
|
|
++result.blockHist[1];
|
|
|
|
}
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
2022-04-04 22:03:02 +00:00
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
case DXGI_FORMAT_BC4_UNORM:
|
|
|
|
{
|
2022-04-04 22:03:02 +00:00
|
|
|
auto block = reinterpret_cast<const BC4UBlock*>(sptr);
|
|
|
|
|
|
|
|
if (block->red_0 > block->red_1)
|
|
|
|
{
|
|
|
|
// 8 red block
|
|
|
|
++result.blockHist[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// 6 red block
|
|
|
|
++result.blockHist[1];
|
|
|
|
}
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
2022-04-04 22:03:02 +00:00
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
case DXGI_FORMAT_BC4_SNORM:
|
|
|
|
{
|
2022-04-04 22:03:02 +00:00
|
|
|
auto block = reinterpret_cast<const BC4SBlock*>(sptr);
|
|
|
|
|
|
|
|
if (block->red_0 > block->red_1)
|
|
|
|
{
|
|
|
|
// 8 red block
|
|
|
|
++result.blockHist[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// 6 red block
|
|
|
|
++result.blockHist[1];
|
|
|
|
}
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
2022-04-04 22:03:02 +00:00
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
case DXGI_FORMAT_BC5_UNORM:
|
|
|
|
{
|
2022-04-04 22:03:02 +00:00
|
|
|
auto block = reinterpret_cast<const BC5UBlock*>(sptr);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
if (block->u.red_0 > block->u.red_1)
|
|
|
|
{
|
|
|
|
// 8 red block
|
|
|
|
++result.blockHist[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// 6 red block
|
|
|
|
++result.blockHist[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (block->v.red_0 > block->v.red_1)
|
|
|
|
{
|
|
|
|
// 8 green block
|
|
|
|
++result.blockHist[2];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// 6 green block
|
|
|
|
++result.blockHist[3];
|
|
|
|
}
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
2022-04-04 22:03:02 +00:00
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
case DXGI_FORMAT_BC5_SNORM:
|
|
|
|
{
|
2022-04-04 22:03:02 +00:00
|
|
|
auto block = reinterpret_cast<const BC5SBlock*>(sptr);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
if (block->u.red_0 > block->u.red_1)
|
|
|
|
{
|
|
|
|
// 8 red block
|
|
|
|
++result.blockHist[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// 6 red block
|
|
|
|
++result.blockHist[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (block->v.red_0 > block->v.red_1)
|
|
|
|
{
|
|
|
|
// 8 green block
|
|
|
|
++result.blockHist[2];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// 6 green block
|
|
|
|
++result.blockHist[3];
|
|
|
|
}
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
2022-04-04 22:03:02 +00:00
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
case DXGI_FORMAT_BC6H_UF16:
|
|
|
|
case DXGI_FORMAT_BC6H_SF16:
|
|
|
|
switch (*sptr & 0x03)
|
|
|
|
{
|
|
|
|
case 0x00:
|
|
|
|
// Mode 1 (2 bits, 00)
|
|
|
|
++result.blockHist[1];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x01:
|
|
|
|
// Mode 2 (2 bits, 01)
|
|
|
|
++result.blockHist[2];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
switch (*sptr & 0x1F)
|
|
|
|
{
|
|
|
|
case 0x02:
|
|
|
|
// Mode 3 (5 bits, 00010)
|
|
|
|
++result.blockHist[3];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x06:
|
|
|
|
// Mode 4 (5 bits, 00110)
|
|
|
|
++result.blockHist[4];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0A:
|
|
|
|
// Mode 5 (5 bits, 01010)
|
|
|
|
++result.blockHist[5];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0E:
|
|
|
|
// Mode 6 (5 bits, 01110)
|
|
|
|
++result.blockHist[6];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x12:
|
|
|
|
// Mode 7 (5 bits, 10010)
|
|
|
|
++result.blockHist[7];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x16:
|
|
|
|
// Mode 8 (5 bits, 10110)
|
|
|
|
++result.blockHist[8];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x1A:
|
|
|
|
// Mode 9 (5 bits, 11010)
|
|
|
|
++result.blockHist[9];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x1E:
|
|
|
|
// Mode 10 (5 bits, 11110)
|
|
|
|
++result.blockHist[10];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x03:
|
|
|
|
// Mode 11 (5 bits, 00011)
|
|
|
|
++result.blockHist[11];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x07:
|
|
|
|
// Mode 12 (5 bits, 00111)
|
|
|
|
++result.blockHist[12];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0B:
|
|
|
|
// Mode 13 (5 bits, 01011)
|
|
|
|
++result.blockHist[13];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0F:
|
|
|
|
// Mode 14 (5 bits, 01111)
|
|
|
|
++result.blockHist[14];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x13: // Reserved mode (5 bits, 10011)
|
|
|
|
case 0x17: // Reserved mode (5 bits, 10111)
|
|
|
|
case 0x1B: // Reserved mode (5 bits, 11011)
|
|
|
|
case 0x1F: // Reserved mode (5 bits, 11111)
|
|
|
|
default:
|
|
|
|
++result.blockHist[0];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DXGI_FORMAT_BC7_UNORM:
|
|
|
|
case DXGI_FORMAT_BC7_UNORM_SRGB:
|
|
|
|
if (*sptr & 0x01)
|
|
|
|
{
|
|
|
|
// Mode 0 (1)
|
|
|
|
++result.blockHist[0];
|
|
|
|
}
|
|
|
|
else if (*sptr & 0x02)
|
|
|
|
{
|
|
|
|
// Mode 1 (01)
|
|
|
|
++result.blockHist[1];
|
|
|
|
}
|
|
|
|
else if (*sptr & 0x04)
|
|
|
|
{
|
|
|
|
// Mode 2 (001)
|
|
|
|
++result.blockHist[2];
|
|
|
|
}
|
|
|
|
else if (*sptr & 0x08)
|
|
|
|
{
|
|
|
|
// Mode 3 (0001)
|
|
|
|
++result.blockHist[3];
|
|
|
|
}
|
|
|
|
else if (*sptr & 0x10)
|
|
|
|
{
|
|
|
|
// Mode 4 (00001)
|
|
|
|
++result.blockHist[4];
|
|
|
|
}
|
|
|
|
else if (*sptr & 0x20)
|
|
|
|
{
|
|
|
|
// Mode 5 (000001)
|
|
|
|
++result.blockHist[5];
|
|
|
|
}
|
|
|
|
else if (*sptr & 0x40)
|
|
|
|
{
|
|
|
|
// Mode 6 (0000001)
|
|
|
|
++result.blockHist[6];
|
|
|
|
}
|
|
|
|
else if (*sptr & 0x80)
|
|
|
|
{
|
|
|
|
// Mode 7 (00000001)
|
|
|
|
++result.blockHist[7];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Reserved mode 8 (00000000)
|
|
|
|
++result.blockHist[8];
|
|
|
|
}
|
|
|
|
break;
|
2019-07-06 06:48:39 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sptr += sbpp;
|
|
|
|
++result.blocks;
|
|
|
|
}
|
|
|
|
|
|
|
|
pSrc += rowPitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-09-27 07:24:19 +00:00
|
|
|
//--------------------------------------------------------------------------------------
|
2020-06-05 03:07:21 +00:00
|
|
|
HRESULT Difference(
|
|
|
|
const Image& image1,
|
|
|
|
const Image& image2,
|
|
|
|
TEX_FILTER_FLAGS dwFilter,
|
|
|
|
DXGI_FORMAT format,
|
2021-06-10 00:40:17 +00:00
|
|
|
uint32_t diffColor,
|
|
|
|
float threshold,
|
2020-06-05 03:07:21 +00:00
|
|
|
ScratchImage& result)
|
2016-09-27 07:24:19 +00:00
|
|
|
{
|
|
|
|
if (!image1.pixels || !image2.pixels)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
if (image1.width != image2.width
|
|
|
|
|| image1.height != image2.height)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
ScratchImage tempA;
|
|
|
|
const Image* imageA = &image1;
|
|
|
|
if (IsCompressed(image1.format))
|
|
|
|
{
|
|
|
|
HRESULT hr = Decompress(image1, DXGI_FORMAT_R32G32B32A32_FLOAT, tempA);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
imageA = tempA.GetImage(0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
ScratchImage tempB;
|
|
|
|
const Image* imageB = &image2;
|
|
|
|
if (image2.format != DXGI_FORMAT_R32G32B32A32_FLOAT)
|
|
|
|
{
|
|
|
|
if (IsCompressed(image2.format))
|
|
|
|
{
|
|
|
|
HRESULT hr = Decompress(image2, DXGI_FORMAT_R32G32B32A32_FLOAT, tempB);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2019-09-14 00:31:09 +00:00
|
|
|
imageB = tempB.GetImage(0, 0, 0);
|
2016-09-27 07:24:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HRESULT hr = Convert(image2, DXGI_FORMAT_R32G32B32A32_FLOAT, dwFilter, TEX_THRESHOLD_DEFAULT, tempB);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
imageB = tempB.GetImage(0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!imageA || !imageB)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2021-06-10 00:40:17 +00:00
|
|
|
XMVECTOR colorValue = PackedVector::XMLoadColor(reinterpret_cast<const PackedVector::XMCOLOR*>(&diffColor));
|
|
|
|
colorValue = XMVectorSelect(g_XMIdentityR3, colorValue, g_XMSelect1110);
|
|
|
|
|
2016-09-27 07:24:19 +00:00
|
|
|
ScratchImage diffImage;
|
|
|
|
HRESULT hr = TransformImage(*imageA, [&](XMVECTOR* outPixels, const XMVECTOR * inPixels, size_t width, size_t y)
|
|
|
|
{
|
2022-03-01 22:31:55 +00:00
|
|
|
const XMVECTOR tolerance = XMVectorReplicate(threshold);
|
2021-06-10 00:40:17 +00:00
|
|
|
|
2019-09-14 00:31:09 +00:00
|
|
|
auto *inPixelsB = reinterpret_cast<XMVECTOR*>(imageB->pixels + (y*imageB->rowPitch));
|
2016-09-27 07:24:19 +00:00
|
|
|
|
2019-09-14 00:31:09 +00:00
|
|
|
for (size_t x = 0; x < width; ++x)
|
|
|
|
{
|
|
|
|
XMVECTOR v1 = *inPixels++;
|
2022-03-01 22:31:55 +00:00
|
|
|
const XMVECTOR v2 = *inPixelsB++;
|
2016-09-27 07:24:19 +00:00
|
|
|
|
2019-09-14 00:31:09 +00:00
|
|
|
v1 = XMVectorSubtract(v1, v2);
|
|
|
|
v1 = XMVectorAbs(v1);
|
|
|
|
v1 = XMVectorSelect(g_XMIdentityR3, v1, g_XMSelect1110);
|
|
|
|
|
2021-06-10 00:40:17 +00:00
|
|
|
if (diffColor && XMVector3GreaterOrEqual(v1, tolerance))
|
|
|
|
{
|
|
|
|
*outPixels++ = colorValue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*outPixels++ = v1;
|
|
|
|
}
|
2019-09-14 00:31:09 +00:00
|
|
|
}
|
|
|
|
}, (format == DXGI_FORMAT_R32G32B32A32_FLOAT) ? result : diffImage);
|
2016-09-27 07:24:19 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2021-06-10 00:40:17 +00:00
|
|
|
if (format == diffImage.GetMetadata().format)
|
|
|
|
{
|
|
|
|
std::swap(diffImage, result);
|
2016-09-27 07:24:19 +00:00
|
|
|
return S_OK;
|
2021-06-10 00:40:17 +00:00
|
|
|
}
|
2016-09-27 07:24:19 +00:00
|
|
|
|
|
|
|
return Convert(diffImage.GetImages(), diffImage.GetImageCount(), diffImage.GetMetadata(), format, dwFilter, TEX_THRESHOLD_DEFAULT, result);
|
|
|
|
}
|
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
#pragma region DumpBC
|
2016-09-25 23:04:44 +00:00
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
// Partition, Shape, Fixup
|
|
|
|
const uint8_t g_aFixUp[3][64][3] =
|
|
|
|
{
|
|
|
|
{ // No fix-ups for 1st subset for BC6H or BC7
|
|
|
|
{ 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, 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, 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 },{ 0, 0, 0 },
|
|
|
|
{ 0, 0, 0 },{ 0, 0, 0 },{ 0, 0, 0 },{ 0, 0, 0 }
|
|
|
|
},
|
|
|
|
|
|
|
|
{ // BC6H/BC7 Partition Set Fixups for 2 Subsets
|
|
|
|
{ 0,15, 0 },{ 0,15, 0 },{ 0,15, 0 },{ 0,15, 0 },
|
|
|
|
{ 0,15, 0 },{ 0,15, 0 },{ 0,15, 0 },{ 0,15, 0 },
|
|
|
|
{ 0,15, 0 },{ 0,15, 0 },{ 0,15, 0 },{ 0,15, 0 },
|
|
|
|
{ 0,15, 0 },{ 0,15, 0 },{ 0,15, 0 },{ 0,15, 0 },
|
|
|
|
{ 0,15, 0 },{ 0, 2, 0 },{ 0, 8, 0 },{ 0, 2, 0 },
|
|
|
|
{ 0, 2, 0 },{ 0, 8, 0 },{ 0, 8, 0 },{ 0,15, 0 },
|
|
|
|
{ 0, 2, 0 },{ 0, 8, 0 },{ 0, 2, 0 },{ 0, 2, 0 },
|
|
|
|
{ 0, 8, 0 },{ 0, 8, 0 },{ 0, 2, 0 },{ 0, 2, 0 },
|
|
|
|
|
|
|
|
// BC7 Partition Set Fixups for 2 Subsets (second-half)
|
|
|
|
{ 0,15, 0 },{ 0,15, 0 },{ 0, 6, 0 },{ 0, 8, 0 },
|
|
|
|
{ 0, 2, 0 },{ 0, 8, 0 },{ 0,15, 0 },{ 0,15, 0 },
|
|
|
|
{ 0, 2, 0 },{ 0, 8, 0 },{ 0, 2, 0 },{ 0, 2, 0 },
|
|
|
|
{ 0, 2, 0 },{ 0,15, 0 },{ 0,15, 0 },{ 0, 6, 0 },
|
|
|
|
{ 0, 6, 0 },{ 0, 2, 0 },{ 0, 6, 0 },{ 0, 8, 0 },
|
|
|
|
{ 0,15, 0 },{ 0,15, 0 },{ 0, 2, 0 },{ 0, 2, 0 },
|
|
|
|
{ 0,15, 0 },{ 0,15, 0 },{ 0,15, 0 },{ 0,15, 0 },
|
|
|
|
{ 0,15, 0 },{ 0, 2, 0 },{ 0, 2, 0 },{ 0,15, 0 }
|
|
|
|
},
|
|
|
|
|
|
|
|
{ // BC7 Partition Set Fixups for 3 Subsets
|
|
|
|
{ 0, 3,15 },{ 0, 3, 8 },{ 0,15, 8 },{ 0,15, 3 },
|
|
|
|
{ 0, 8,15 },{ 0, 3,15 },{ 0,15, 3 },{ 0,15, 8 },
|
|
|
|
{ 0, 8,15 },{ 0, 8,15 },{ 0, 6,15 },{ 0, 6,15 },
|
|
|
|
{ 0, 6,15 },{ 0, 5,15 },{ 0, 3,15 },{ 0, 3, 8 },
|
|
|
|
{ 0, 3,15 },{ 0, 3, 8 },{ 0, 8,15 },{ 0,15, 3 },
|
|
|
|
{ 0, 3,15 },{ 0, 3, 8 },{ 0, 6,15 },{ 0,10, 8 },
|
|
|
|
{ 0, 5, 3 },{ 0, 8,15 },{ 0, 8, 6 },{ 0, 6,10 },
|
|
|
|
{ 0, 8,15 },{ 0, 5,15 },{ 0,15,10 },{ 0,15, 8 },
|
|
|
|
{ 0, 8,15 },{ 0,15, 3 },{ 0, 3,15 },{ 0, 5,10 },
|
|
|
|
{ 0, 6,10 },{ 0,10, 8 },{ 0, 8, 9 },{ 0,15,10 },
|
|
|
|
{ 0,15, 6 },{ 0, 3,15 },{ 0,15, 8 },{ 0, 5,15 },
|
|
|
|
{ 0,15, 3 },{ 0,15, 6 },{ 0,15, 6 },{ 0,15, 8 },
|
|
|
|
{ 0, 3,15 },{ 0,15, 3 },{ 0, 5,15 },{ 0, 5,15 },
|
|
|
|
{ 0, 5,15 },{ 0, 8,15 },{ 0, 5,15 },{ 0,10,15 },
|
|
|
|
{ 0, 5,15 },{ 0,10,15 },{ 0, 8,15 },{ 0,13,15 },
|
|
|
|
{ 0,15, 3 },{ 0,12,15 },{ 0, 3,15 },{ 0, 3, 8 }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-06-05 03:07:21 +00:00
|
|
|
inline static bool IsFixUpOffset(
|
|
|
|
_In_range_(0, 2) size_t uPartitions,
|
|
|
|
_In_range_(0, 63) uint64_t uShape,
|
|
|
|
_In_range_(0, 15) size_t uOffset)
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
|
|
|
for (size_t p = 0; p <= uPartitions; p++)
|
|
|
|
{
|
|
|
|
if (uOffset == g_aFixUp[uPartitions][uShape][p])
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------
|
2019-04-17 00:38:37 +00:00
|
|
|
#define SIGN_EXTEND(x,nb) ((((x)&(1<<((nb)-1)))?((~0)^((1<<(nb))-1)):0)|(x))
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2019-09-14 00:31:09 +00:00
|
|
|
#define NUM_PIXELS_PER_BLOCK 16
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
void Print565(uint16_t rgb)
|
|
|
|
{
|
2022-03-01 22:31:55 +00:00
|
|
|
auto const r = float(((rgb >> 11) & 31) * (1.0f / 31.0f));
|
|
|
|
auto const g = float(((rgb >> 5) & 63) * (1.0f / 63.0f));
|
|
|
|
auto const b = float(((rgb >> 0) & 31) * (1.0f / 31.0f));
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
wprintf(L"(R: %.3f, G: %.3f, B: %.3f)", r, g, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrintIndex2bpp(uint32_t bitmap)
|
|
|
|
{
|
|
|
|
for (size_t j = 0; j < NUM_PIXELS_PER_BLOCK; ++j, bitmap >>= 2)
|
|
|
|
{
|
|
|
|
wprintf(L"%u%ls", bitmap & 0x3, ((j < (NUM_PIXELS_PER_BLOCK - 1)) && ((j % 4) == 3)) ? L" | " : L" ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrintIndex2bpp(uint64_t bitmap, size_t parts, uint64_t shape)
|
|
|
|
{
|
|
|
|
for (size_t j = 0; j < NUM_PIXELS_PER_BLOCK; ++j)
|
|
|
|
{
|
|
|
|
if (IsFixUpOffset(parts, shape, j))
|
|
|
|
{
|
2018-05-02 17:05:48 +00:00
|
|
|
wprintf(L"%llu%ls", bitmap & 0x1, ((j < (NUM_PIXELS_PER_BLOCK - 1)) && ((j % 4) == 3)) ? L" | " : L" ");
|
2016-09-25 23:04:44 +00:00
|
|
|
bitmap >>= 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-02 17:05:48 +00:00
|
|
|
wprintf(L"%llu%ls", bitmap & 0x3, ((j < (NUM_PIXELS_PER_BLOCK - 1)) && ((j % 4) == 3)) ? L" | " : L" ");
|
2016-09-25 23:04:44 +00:00
|
|
|
bitmap >>= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrintIndex3bpp(uint64_t bitmap, size_t parts, uint64_t shape)
|
|
|
|
{
|
|
|
|
for (size_t j = 0; j < NUM_PIXELS_PER_BLOCK; ++j)
|
|
|
|
{
|
|
|
|
if (IsFixUpOffset(parts, shape, j))
|
|
|
|
{
|
2018-05-02 17:05:48 +00:00
|
|
|
wprintf(L"%llu%ls", bitmap & 0x3, ((j < (NUM_PIXELS_PER_BLOCK - 1)) && ((j % 4) == 3)) ? L" | " : L" ");
|
2016-09-25 23:04:44 +00:00
|
|
|
bitmap >>= 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-02 17:05:48 +00:00
|
|
|
wprintf(L"%llu%ls", bitmap & 0x7, ((j < (NUM_PIXELS_PER_BLOCK - 1)) && ((j % 4) == 3)) ? L" | " : L" ");
|
2016-09-25 23:04:44 +00:00
|
|
|
bitmap >>= 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrintIndex4bpp(uint64_t bitmap, size_t parts, uint64_t shape)
|
|
|
|
{
|
|
|
|
for (size_t j = 0; j < NUM_PIXELS_PER_BLOCK; ++j)
|
|
|
|
{
|
|
|
|
if (IsFixUpOffset(parts, shape, j))
|
|
|
|
{
|
2018-05-02 17:05:48 +00:00
|
|
|
wprintf(L"%llX%ls", bitmap & 0x7, ((j < (NUM_PIXELS_PER_BLOCK - 1)) && ((j % 4) == 3)) ? L" | " : L" ");
|
2016-09-25 23:04:44 +00:00
|
|
|
bitmap >>= 3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-02 17:05:48 +00:00
|
|
|
wprintf(L"%llX%ls", bitmap & 0xF, ((j < (NUM_PIXELS_PER_BLOCK - 1)) && ((j % 4) == 3)) ? L" | " : L" ");
|
2016-09-25 23:04:44 +00:00
|
|
|
bitmap >>= 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrintIndex3bpp(const uint8_t data[6])
|
|
|
|
{
|
2019-07-06 06:48:39 +00:00
|
|
|
uint32_t bitmap = uint32_t(data[0]) | (uint32_t(data[1]) << 8) | (uint32_t(data[2]) << 16);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
size_t j = 0;
|
|
|
|
for (; j < (NUM_PIXELS_PER_BLOCK / 2); ++j, bitmap >>= 3)
|
|
|
|
{
|
|
|
|
wprintf(L"%u%ls", bitmap & 0x7, ((j % 4) == 3) ? L" | " : L" ");
|
|
|
|
}
|
|
|
|
|
2019-07-06 06:48:39 +00:00
|
|
|
bitmap = uint32_t(data[3]) | (uint32_t(data[4]) << 8) | (uint32_t(data[5]) << 16);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
for (; j < NUM_PIXELS_PER_BLOCK; ++j, bitmap >>= 3)
|
|
|
|
{
|
|
|
|
wprintf(L"%u%ls", bitmap & 0x7, ((j < (NUM_PIXELS_PER_BLOCK - 1)) && ((j % 4) == 3)) ? L" | " : L" ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const wchar_t* GetRotBits(uint64_t rot)
|
|
|
|
{
|
|
|
|
switch (rot)
|
|
|
|
{
|
|
|
|
case 1: return L" (R<->A)";
|
|
|
|
case 2: return L" (G<->A)";
|
|
|
|
case 3: return L" (B<->A)";
|
|
|
|
default: return L"";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT DumpBCImage(const Image& image, int pixelx, int pixely)
|
|
|
|
{
|
|
|
|
size_t sbpp;
|
|
|
|
switch (image.format)
|
|
|
|
{
|
|
|
|
case DXGI_FORMAT_BC1_UNORM:
|
|
|
|
case DXGI_FORMAT_BC1_UNORM_SRGB:
|
|
|
|
case DXGI_FORMAT_BC4_UNORM:
|
|
|
|
case DXGI_FORMAT_BC4_SNORM:
|
|
|
|
sbpp = 8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DXGI_FORMAT_BC2_UNORM:
|
|
|
|
case DXGI_FORMAT_BC2_UNORM_SRGB:
|
|
|
|
case DXGI_FORMAT_BC3_UNORM:
|
|
|
|
case DXGI_FORMAT_BC3_UNORM_SRGB:
|
|
|
|
case DXGI_FORMAT_BC5_UNORM:
|
|
|
|
case DXGI_FORMAT_BC5_SNORM:
|
|
|
|
case DXGI_FORMAT_BC6H_UF16:
|
|
|
|
case DXGI_FORMAT_BC6H_SF16:
|
|
|
|
case DXGI_FORMAT_BC7_UNORM:
|
|
|
|
case DXGI_FORMAT_BC7_UNORM_SRGB:
|
|
|
|
sbpp = 16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint8_t *pSrc = image.pixels;
|
|
|
|
const size_t rowPitch = image.rowPitch;
|
|
|
|
|
|
|
|
size_t nblock = 0;
|
|
|
|
for (size_t h = 0; h < image.height; h += 4, pSrc += rowPitch)
|
|
|
|
{
|
|
|
|
if (pixely >= 0)
|
|
|
|
{
|
|
|
|
if ((pixely < int(h)) || (pixely >= int(h + 4)))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint8_t *sptr = pSrc;
|
|
|
|
|
|
|
|
size_t w = 0;
|
|
|
|
for (size_t count = 0; count < rowPitch; count += sbpp, w += 4, ++nblock, sptr += sbpp)
|
|
|
|
{
|
|
|
|
if (pixelx >= 0)
|
|
|
|
{
|
|
|
|
if ((pixelx < int(w)) || (pixelx >= int(w + 4)))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-05-02 00:34:54 +00:00
|
|
|
wprintf(L" Block %zu (pixel: %zu x %zu)\n", nblock, w, h);
|
2016-09-25 23:04:44 +00:00
|
|
|
switch (image.format)
|
|
|
|
{
|
|
|
|
case DXGI_FORMAT_BC1_UNORM:
|
|
|
|
case DXGI_FORMAT_BC1_UNORM_SRGB:
|
|
|
|
{
|
2022-04-04 22:03:02 +00:00
|
|
|
auto block = reinterpret_cast<const BC1Block*>(sptr);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
if (block->rgb[0] <= block->rgb[1])
|
|
|
|
{
|
|
|
|
// Transparent block
|
|
|
|
wprintf(L"\tTransparent - E0: ");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Opaque block
|
|
|
|
wprintf(L"\t Opaque - E0: ");
|
|
|
|
}
|
|
|
|
|
|
|
|
Print565(block->rgb[0]);
|
|
|
|
wprintf(L"\n\t E1: ");
|
|
|
|
Print565(block->rgb[1]);
|
|
|
|
wprintf(L"\n\t Index: ");
|
|
|
|
PrintIndex2bpp(block->bitmap);
|
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
case DXGI_FORMAT_BC2_UNORM:
|
|
|
|
case DXGI_FORMAT_BC2_UNORM_SRGB:
|
2022-04-04 22:03:02 +00:00
|
|
|
{
|
|
|
|
auto block = reinterpret_cast<const BC2Block*>(sptr);
|
|
|
|
|
|
|
|
wprintf(L"\tColor - E0: ");
|
|
|
|
Print565(block->bc1.rgb[0]);
|
|
|
|
wprintf(L"\n\t E1: ");
|
|
|
|
Print565(block->bc1.rgb[1]);
|
|
|
|
wprintf(L"\n\t Index: ");
|
|
|
|
PrintIndex2bpp(block->bc1.bitmap);
|
|
|
|
wprintf(L"\n");
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
wprintf(L"\tAlpha - ");
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
size_t j = 0;
|
|
|
|
uint32_t bitmap = block->bitmap[0];
|
|
|
|
for (; j < (NUM_PIXELS_PER_BLOCK / 2); ++j, bitmap >>= 4)
|
|
|
|
{
|
|
|
|
wprintf(L"%X%ls", bitmap & 0xF, ((j % 4) == 3) ? L" | " : L" ");
|
|
|
|
}
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
bitmap = block->bitmap[1];
|
|
|
|
for (; j < NUM_PIXELS_PER_BLOCK; ++j, bitmap >>= 4)
|
|
|
|
{
|
|
|
|
wprintf(L"%X%ls", bitmap & 0xF, ((j < (NUM_PIXELS_PER_BLOCK - 1)) && ((j % 4) == 3)) ? L" | " : L" ");
|
|
|
|
}
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
wprintf(L"\n");
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
2022-04-04 22:03:02 +00:00
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
case DXGI_FORMAT_BC3_UNORM:
|
|
|
|
case DXGI_FORMAT_BC3_UNORM_SRGB:
|
2022-04-04 22:03:02 +00:00
|
|
|
{
|
|
|
|
auto block = reinterpret_cast<const BC3Block*>(sptr);
|
|
|
|
|
|
|
|
wprintf(L"\tColor - E0: ");
|
|
|
|
Print565(block->bc1.rgb[0]);
|
|
|
|
wprintf(L"\n\t E1: ");
|
|
|
|
Print565(block->bc1.rgb[1]);
|
|
|
|
wprintf(L"\n\t Index: ");
|
|
|
|
PrintIndex2bpp(block->bc1.bitmap);
|
|
|
|
wprintf(L"\n");
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
wprintf(L"\tAlpha - E0: %0.3f E1: %0.3f (%u)\n\t Index: ",
|
|
|
|
(float(block->alpha[0]) / 255.f),
|
|
|
|
(float(block->alpha[1]) / 255.f), (block->alpha[0] > block->alpha[1]) ? 8u : 6u);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
PrintIndex3bpp(block->bitmap);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
case DXGI_FORMAT_BC4_UNORM:
|
2022-04-04 22:03:02 +00:00
|
|
|
{
|
|
|
|
auto block = reinterpret_cast<const BC4UBlock*>(sptr);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
wprintf(L"\t E0: %0.3f E1: %0.3f (%u)\n\tIndex: ",
|
|
|
|
(float(block->red_0) / 255.f),
|
|
|
|
(float(block->red_1) / 255.f), (block->red_0 > block->red_1) ? 8u : 6u);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
PrintIndex3bpp(block->indices);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
case DXGI_FORMAT_BC4_SNORM:
|
2022-04-04 22:03:02 +00:00
|
|
|
{
|
|
|
|
auto block = reinterpret_cast<const BC4SBlock*>(sptr);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
wprintf(L"\t E0: %0.3f E1: %0.3f (%u)\n\tIndex: ",
|
|
|
|
(float(block->red_0) / 127.f),
|
|
|
|
(float(block->red_1) / 127.f), (block->red_0 > block->red_1) ? 8u : 6u);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
PrintIndex3bpp(block->indices);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
case DXGI_FORMAT_BC5_UNORM:
|
2022-04-04 22:03:02 +00:00
|
|
|
{
|
|
|
|
auto block = reinterpret_cast<const BC5UBlock*>(sptr);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
wprintf(L"\tU - E0: %0.3f E1: %0.3f (%u)\n\t Index: ",
|
|
|
|
(float(block->u.red_0) / 255.f),
|
|
|
|
(float(block->u.red_1) / 255.f), (block->u.red_0 > block->u.red_1) ? 8u : 6u);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
PrintIndex3bpp(block->u.indices);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
wprintf(L"\n");
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
wprintf(L"\tV - E0: %0.3f E1: %0.3f (%u)\n\t Index: ",
|
|
|
|
(float(block->v.red_0) / 255.f),
|
|
|
|
(float(block->v.red_1) / 255.f), (block->v.red_0 > block->v.red_1) ? 8u : 6u);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
PrintIndex3bpp(block->v.indices);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
case DXGI_FORMAT_BC5_SNORM:
|
2022-04-04 22:03:02 +00:00
|
|
|
{
|
|
|
|
auto block = reinterpret_cast<const BC5SBlock*>(sptr);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
wprintf(L"\tU - E0: %0.3f E1: %0.3f (%u)\n\t Index: ",
|
|
|
|
(float(block->u.red_0) / 127.f),
|
|
|
|
(float(block->u.red_1) / 127.f), (block->u.red_0 > block->u.red_1) ? 8u : 6u);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
PrintIndex3bpp(block->u.indices);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
wprintf(L"\n");
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
wprintf(L"\tV - E0: %0.3f E1: %0.3f (%u)\n\t Index: ",
|
|
|
|
(float(block->v.red_0) / 127.f),
|
|
|
|
(float(block->v.red_1) / 127.f), (block->v.red_0 > block->v.red_1) ? 8u : 6u);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
PrintIndex3bpp(block->v.indices);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
case DXGI_FORMAT_BC6H_UF16:
|
|
|
|
case DXGI_FORMAT_BC6H_SF16:
|
|
|
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/hh308952.aspx#decoding_the_bc6h_format
|
|
|
|
|
|
|
|
switch (*sptr & 0x03)
|
|
|
|
{
|
|
|
|
case 0x00:
|
|
|
|
// Mode 1 (2 bits, 00)
|
|
|
|
{
|
2022-04-04 22:03:02 +00:00
|
|
|
struct bc6h_mode1
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
2022-04-04 22:03:02 +00:00
|
|
|
uint64_t mode : 2; // { M, 0}, { M, 1}
|
|
|
|
uint64_t gy4 : 1; // {GY, 4}
|
|
|
|
uint64_t by4 : 1; // {BY, 4}
|
|
|
|
uint64_t bz4 : 1; // {BZ, 4}
|
2016-09-25 23:04:44 +00:00
|
|
|
uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9}
|
|
|
|
uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9}
|
|
|
|
uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9}
|
|
|
|
uint64_t rx : 5; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}
|
2022-04-04 22:03:02 +00:00
|
|
|
uint64_t gz4 : 1; // {GZ, 4}
|
2016-09-25 23:04:44 +00:00
|
|
|
uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3}
|
2022-04-04 22:03:02 +00:00
|
|
|
uint64_t gx : 5; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}
|
|
|
|
uint64_t bz0 : 1; // {BZ, 0},
|
2016-09-25 23:04:44 +00:00
|
|
|
uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3}
|
2022-04-04 22:03:02 +00:00
|
|
|
uint64_t bx : 5; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}
|
2016-09-25 23:04:44 +00:00
|
|
|
uint64_t bz1 : 1; // {BZ, 1}
|
|
|
|
uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2}
|
|
|
|
uint64_t by3 : 1; // {BY, 3}
|
|
|
|
uint64_t ry : 5; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4}
|
|
|
|
uint64_t bz2 : 1; // {BZ, 2}
|
|
|
|
uint64_t rz : 5; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4}
|
|
|
|
uint64_t bz3 : 1; // {BZ, 3}
|
|
|
|
uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4}
|
|
|
|
uint64_t indices : 46;
|
|
|
|
};
|
2022-04-04 22:03:02 +00:00
|
|
|
static_assert(sizeof(bc6h_mode1) == 16, "Block size must be 16 bytes");
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-03-01 22:31:55 +00:00
|
|
|
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
auto m = reinterpret_cast<const bc6h_mode1*>(sptr);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw));
|
2016-09-25 23:04:44 +00:00
|
|
|
XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx));
|
|
|
|
XMINT3 e1_A(int(m->ry),
|
|
|
|
int(m->gy | (m->gy4 << 4)),
|
|
|
|
int(m->by | (m->by3 << 3) | (m->by4 << 4)));
|
|
|
|
XMINT3 e1_B(int(m->rz),
|
|
|
|
int(m->gz | (m->gz4 << 4)),
|
|
|
|
int(m->bz0 | (m->bz1 << 1) | (m->bz2 << 2) | (m->bz3 << 3) | (m->bz4 << 4)));
|
|
|
|
|
|
|
|
if (bSigned)
|
|
|
|
{
|
2022-04-04 22:03:02 +00:00
|
|
|
e0_A.x = SIGN_EXTEND(e0_A.x, 10);
|
|
|
|
e0_A.y = SIGN_EXTEND(e0_A.y, 10);
|
|
|
|
e0_A.z = SIGN_EXTEND(e0_A.z, 10);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
e0_B.x = SIGN_EXTEND(e0_B.x, 5);
|
|
|
|
e0_B.y = SIGN_EXTEND(e0_B.y, 5);
|
|
|
|
e0_B.z = SIGN_EXTEND(e0_B.z, 5);
|
|
|
|
|
|
|
|
e1_A.x = SIGN_EXTEND(e1_A.x, 5);
|
|
|
|
e1_A.y = SIGN_EXTEND(e1_A.y, 5);
|
|
|
|
e1_A.z = SIGN_EXTEND(e1_A.z, 5);
|
|
|
|
|
|
|
|
e1_B.x = SIGN_EXTEND(e1_B.x, 5);
|
|
|
|
e1_B.y = SIGN_EXTEND(e1_B.y, 5);
|
|
|
|
e1_B.z = SIGN_EXTEND(e1_B.z, 5);
|
|
|
|
}
|
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
wprintf(L"\tMode 1 - [10 5 5 5] shape %llu\n", m->d);
|
2016-09-25 23:04:44 +00:00
|
|
|
wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t Index: ");
|
|
|
|
PrintIndex3bpp(m->indices, 1, m->d);
|
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
case 0x01:
|
|
|
|
// Mode 2 (2 bits, 01)
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
2022-04-04 22:03:02 +00:00
|
|
|
struct bc6h_mode2
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
2022-04-04 22:03:02 +00:00
|
|
|
uint64_t mode : 2; // { M, 0}, { M, 1}
|
|
|
|
uint64_t gy5 : 1; // {GY, 5}
|
|
|
|
uint64_t gz45 : 2; // {GZ, 4}, {GZ, 5}
|
|
|
|
uint64_t rw : 7; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}
|
|
|
|
uint64_t bz : 2; // {BZ, 0}, {BZ, 1}
|
|
|
|
uint64_t by4 : 1; // {BY, 4},
|
|
|
|
uint64_t gw : 7; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}
|
|
|
|
uint64_t by5 : 1; // {BY, 5}
|
2016-09-25 23:04:44 +00:00
|
|
|
uint64_t bz2 : 1; // {BZ, 2}
|
|
|
|
uint64_t gy4 : 1; // {GY, 4}
|
2022-04-04 22:03:02 +00:00
|
|
|
uint64_t bw : 7; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}
|
2016-09-25 23:04:44 +00:00
|
|
|
uint64_t bz3 : 1; // {BZ, 3}
|
2022-04-04 22:03:02 +00:00
|
|
|
uint64_t bz5 : 1; // {BZ, 5}
|
2016-09-25 23:04:44 +00:00
|
|
|
uint64_t bz4 : 1; // {BZ, 4}
|
|
|
|
uint64_t rx : 6; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}, {RX, 5}
|
|
|
|
uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3}
|
2022-04-04 22:03:02 +00:00
|
|
|
uint64_t gx : 6; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}, {GX, 5}
|
2016-09-25 23:04:44 +00:00
|
|
|
uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3}
|
2022-04-04 22:03:02 +00:00
|
|
|
uint64_t bx : 5; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}, {BX, 5}
|
|
|
|
uint64_t by : 4; // {BY, 0}, {BY, 1}, {BY, 2}, {BY, 3}
|
2016-09-25 23:04:44 +00:00
|
|
|
uint64_t ry : 6; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4}, {RY, 5}
|
2022-04-04 22:03:02 +00:00
|
|
|
uint64_t rz : 6; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4}, {RZ, 5},
|
2016-09-25 23:04:44 +00:00
|
|
|
uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4}
|
|
|
|
uint64_t indices : 46;
|
2022-04-04 22:03:02 +00:00
|
|
|
|
2016-09-25 23:04:44 +00:00
|
|
|
};
|
2022-04-04 22:03:02 +00:00
|
|
|
static_assert(sizeof(bc6h_mode2) == 16, "Block size must be 16 bytes");
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-03-01 22:31:55 +00:00
|
|
|
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
auto m = reinterpret_cast<const bc6h_mode2*>(sptr);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw));
|
|
|
|
XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx));
|
|
|
|
XMINT3 e1_A(int(m->ry),
|
2022-04-04 22:03:02 +00:00
|
|
|
int(m->gy | (m->gy4 << 4) | (m->gy5 << 5)),
|
|
|
|
int(m->by | (m->by4 << 4) | (m->by5 << 5)));
|
2016-09-25 23:04:44 +00:00
|
|
|
XMINT3 e1_B(int(m->rz),
|
2022-04-04 22:03:02 +00:00
|
|
|
int(m->gz | (m->gz45 << 4)),
|
|
|
|
int(m->bz | (m->bz2 << 2) | (m->bz3 << 3) | (m->bz4 << 4) | (m->bz5 << 5)));
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
if (bSigned)
|
|
|
|
{
|
2022-04-04 22:03:02 +00:00
|
|
|
e0_A.x = SIGN_EXTEND(e0_A.x, 7);
|
|
|
|
e0_A.y = SIGN_EXTEND(e0_A.y, 7);
|
|
|
|
e0_A.z = SIGN_EXTEND(e0_A.z, 7);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
e0_B.x = SIGN_EXTEND(e0_B.x, 6);
|
2022-04-04 22:03:02 +00:00
|
|
|
e0_B.y = SIGN_EXTEND(e0_B.y, 6);
|
|
|
|
e0_B.z = SIGN_EXTEND(e0_B.z, 6);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
e1_A.x = SIGN_EXTEND(e1_A.x, 6);
|
2022-04-04 22:03:02 +00:00
|
|
|
e1_A.y = SIGN_EXTEND(e1_A.y, 6);
|
|
|
|
e1_A.z = SIGN_EXTEND(e1_A.z, 6);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
e1_B.x = SIGN_EXTEND(e1_B.x, 6);
|
2022-04-04 22:03:02 +00:00
|
|
|
e1_B.y = SIGN_EXTEND(e1_B.y, 6);
|
|
|
|
e1_B.z = SIGN_EXTEND(e1_B.z, 6);
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
wprintf(L"\tMode 2 - [7 6 6 6] shape %llu\n", m->d);
|
2016-09-25 23:04:44 +00:00
|
|
|
wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t Index: ");
|
|
|
|
PrintIndex3bpp(m->indices, 1, m->d);
|
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
default:
|
|
|
|
switch (*sptr & 0x1F)
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
2022-04-04 22:03:02 +00:00
|
|
|
case 0x02:
|
|
|
|
// Mode 3 (5 bits, 00010)
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
2022-04-04 22:03:02 +00:00
|
|
|
struct bc6h_mode3
|
|
|
|
{
|
|
|
|
uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4}
|
|
|
|
uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9}
|
|
|
|
uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9}
|
|
|
|
uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9}
|
|
|
|
uint64_t rx : 5; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}
|
|
|
|
uint64_t rw10 : 1; // {RW,10}
|
|
|
|
uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3}
|
|
|
|
uint64_t gx : 4; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}
|
|
|
|
uint64_t gw10 : 1; // {GW,10}
|
|
|
|
uint64_t bz0 : 1; // {BZ, 0}
|
|
|
|
uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3}
|
|
|
|
uint64_t bx : 4; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}
|
|
|
|
uint64_t bw10 : 1; // {BW,10}
|
|
|
|
uint64_t bz1 : 1; // {BZ, 1}
|
|
|
|
uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2}
|
|
|
|
uint64_t by3 : 1; // {BY, 3}
|
|
|
|
uint64_t ry : 5; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4}
|
|
|
|
uint64_t bz2 : 1; // {BZ, 2}
|
|
|
|
uint64_t rz : 5; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4}
|
|
|
|
uint64_t bz3 : 1; // {BZ, 3}
|
|
|
|
uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4}
|
|
|
|
uint64_t indices : 46;
|
|
|
|
|
|
|
|
};
|
|
|
|
static_assert(sizeof(bc6h_mode3) == 16, "Block size must be 16 bytes");
|
|
|
|
|
|
|
|
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
|
|
|
|
|
|
|
|
auto m = reinterpret_cast<const bc6h_mode3*>(sptr);
|
|
|
|
|
|
|
|
XMINT3 e0_A(int(m->rw | (m->rw10 << 10)),
|
|
|
|
int(m->gw | (m->gw10 << 10)),
|
|
|
|
int(m->bw | (m->bw10 << 10)));
|
|
|
|
XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx));
|
|
|
|
XMINT3 e1_A(int(m->ry), int(m->gy),
|
|
|
|
int(m->by | (m->by3 << 3)));
|
|
|
|
XMINT3 e1_B(int(m->rz),
|
|
|
|
int(m->gz),
|
|
|
|
int(m->bz0 | (m->bz1 << 1) | (m->bz2 << 2) | (m->bz3 << 3)));
|
|
|
|
|
|
|
|
if (bSigned)
|
|
|
|
{
|
|
|
|
e0_A.x = SIGN_EXTEND(e0_A.x, 11);
|
|
|
|
e0_A.y = SIGN_EXTEND(e0_A.y, 11);
|
|
|
|
e0_A.z = SIGN_EXTEND(e0_A.z, 11);
|
|
|
|
|
|
|
|
e0_B.x = SIGN_EXTEND(e0_B.x, 5);
|
|
|
|
e0_B.y = SIGN_EXTEND(e0_B.y, 4);
|
|
|
|
e0_B.z = SIGN_EXTEND(e0_B.z, 4);
|
|
|
|
|
|
|
|
e1_A.x = SIGN_EXTEND(e1_A.x, 5);
|
|
|
|
e1_A.y = SIGN_EXTEND(e1_A.y, 4);
|
|
|
|
e1_A.z = SIGN_EXTEND(e1_A.z, 4);
|
|
|
|
|
|
|
|
e1_B.x = SIGN_EXTEND(e1_B.x, 5);
|
|
|
|
e1_B.y = SIGN_EXTEND(e1_B.y, 4);
|
|
|
|
e1_B.z = SIGN_EXTEND(e1_B.z, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
wprintf(L"\tMode 3 - [11 5 4 4] shape %llu\n", m->d);
|
|
|
|
wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t Index: ");
|
|
|
|
PrintIndex3bpp(m->indices, 1, m->d);
|
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
case 0x06:
|
|
|
|
// Mode 4 (5 bits, 00110)
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
2022-04-04 22:03:02 +00:00
|
|
|
struct bc6h_mode4
|
|
|
|
{
|
|
|
|
uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4}
|
|
|
|
uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9}
|
|
|
|
uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9}
|
|
|
|
uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9}
|
|
|
|
uint64_t rx : 4; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}
|
|
|
|
uint64_t rw10 : 1; // {RW,10}
|
|
|
|
uint64_t gz4 : 1; // {GZ, 4}
|
|
|
|
uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3}
|
|
|
|
uint64_t gx : 5; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}
|
|
|
|
uint64_t gw10 : 1; // {GW,10}
|
|
|
|
uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3}
|
|
|
|
uint64_t bx : 4; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}
|
|
|
|
uint64_t bw10 : 1; // {BW,10}
|
|
|
|
uint64_t bz1 : 1; // {BZ, 1}
|
|
|
|
uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2}
|
|
|
|
uint64_t by3 : 1; // {BY, 3}
|
|
|
|
uint64_t ry : 4; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}
|
|
|
|
uint64_t bz0 : 1; // {BZ, 0}
|
|
|
|
uint64_t bz2 : 1; // {BZ, 2}
|
|
|
|
uint64_t rz : 4; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}
|
|
|
|
uint64_t gy4 : 1; // {GY, 4}
|
|
|
|
uint64_t bz3 : 1; // {BZ, 3}
|
|
|
|
uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4}
|
|
|
|
uint64_t indices : 46;
|
|
|
|
|
|
|
|
};
|
|
|
|
static_assert(sizeof(bc6h_mode4) == 16, "Block size must be 16 bytes");
|
|
|
|
|
|
|
|
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
|
|
|
|
|
|
|
|
auto m = reinterpret_cast<const bc6h_mode4*>(sptr);
|
|
|
|
|
|
|
|
XMINT3 e0_A(int(m->rw | (m->rw10 << 10)),
|
|
|
|
int(m->gw | (m->gw10 << 10)),
|
|
|
|
int(m->bw | (m->bw10 << 10)));
|
|
|
|
XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx));
|
|
|
|
XMINT3 e1_A(int(m->ry),
|
|
|
|
int(m->gy | (m->gy4 << 4)),
|
|
|
|
int(m->by | (m->by3 << 3)));
|
|
|
|
XMINT3 e1_B(int(m->rz),
|
|
|
|
int(m->gz | (m->gz4 << 4)),
|
|
|
|
int(m->bz0 | (m->bz1 << 1) | (m->bz2 << 2) | (m->bz3 << 3)));
|
|
|
|
|
|
|
|
if (bSigned)
|
|
|
|
{
|
|
|
|
e0_A.x = SIGN_EXTEND(e0_A.x, 11);
|
|
|
|
e0_A.y = SIGN_EXTEND(e0_A.y, 11);
|
|
|
|
e0_A.z = SIGN_EXTEND(e0_A.z, 11);
|
|
|
|
|
|
|
|
e0_B.x = SIGN_EXTEND(e0_B.x, 4);
|
|
|
|
e0_B.y = SIGN_EXTEND(e0_B.y, 5);
|
|
|
|
e0_B.z = SIGN_EXTEND(e0_B.z, 4);
|
|
|
|
|
|
|
|
e1_A.x = SIGN_EXTEND(e1_A.x, 4);
|
|
|
|
e1_A.y = SIGN_EXTEND(e1_A.y, 5);
|
|
|
|
e1_A.z = SIGN_EXTEND(e1_A.z, 4);
|
|
|
|
|
|
|
|
e1_B.x = SIGN_EXTEND(e1_B.x, 4);
|
|
|
|
e1_B.y = SIGN_EXTEND(e1_B.y, 5);
|
|
|
|
e1_B.z = SIGN_EXTEND(e1_B.z, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
wprintf(L"\tMode 4 - [11 4 5 4] shape %llu\n", m->d);
|
|
|
|
wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t Index: ");
|
|
|
|
PrintIndex3bpp(m->indices, 1, m->d);
|
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
case 0x0A:
|
|
|
|
// Mode 5 (5 bits, 01010)
|
|
|
|
{
|
|
|
|
struct bc6h_mode5
|
|
|
|
{
|
|
|
|
uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4}
|
|
|
|
uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9}
|
|
|
|
uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9}
|
|
|
|
uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9}
|
|
|
|
uint64_t rx : 4; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}
|
|
|
|
uint64_t rw10 : 1; // {RW,10}
|
|
|
|
uint64_t by4 : 1; // {BY, 4}
|
|
|
|
uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3}
|
|
|
|
uint64_t gx : 4; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}
|
|
|
|
uint64_t gw10 : 1; // {GW,10}
|
|
|
|
uint64_t bz0 : 1; // {BZ, 0}
|
|
|
|
uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3}
|
|
|
|
uint64_t bx : 5; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}
|
|
|
|
uint64_t bw10 : 1; // {BW,10}
|
|
|
|
uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2}
|
|
|
|
uint64_t by3 : 1; // {BY, 3}
|
|
|
|
uint64_t ry : 4; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}
|
|
|
|
uint64_t bz12 : 2; // {BZ, 1}, {BZ, 2}
|
|
|
|
uint64_t rz : 5; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {BZ, 4}
|
|
|
|
uint64_t bz3 : 1; // {BZ, 3}
|
|
|
|
uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4}
|
|
|
|
uint64_t indices : 46;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(bc6h_mode5) == 16, "Block size must be 16 bytes");
|
|
|
|
|
|
|
|
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
|
|
|
|
|
|
|
|
auto m = reinterpret_cast<const bc6h_mode5*>(sptr);
|
|
|
|
|
|
|
|
XMINT3 e0_A(int(m->rw | (m->rw10 << 10)),
|
|
|
|
int(m->gw | (m->gw10 << 10)),
|
|
|
|
int(m->bw | (m->bw10 << 10)));
|
|
|
|
XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx));
|
|
|
|
XMINT3 e1_A(int(m->ry), int(m->gy),
|
|
|
|
int(m->by | (m->by3 << 3) | (m->by4 << 4)));
|
|
|
|
XMINT3 e1_B(int(m->rz), int(m->gz),
|
|
|
|
int(m->bz0 | (m->bz12 << 1) | (m->bz3 << 3)));
|
|
|
|
|
|
|
|
if (bSigned)
|
|
|
|
{
|
|
|
|
e0_A.x = SIGN_EXTEND(e0_A.x, 11);
|
|
|
|
e0_A.y = SIGN_EXTEND(e0_A.y, 11);
|
|
|
|
e0_A.z = SIGN_EXTEND(e0_A.z, 11);
|
|
|
|
|
|
|
|
e0_B.x = SIGN_EXTEND(e0_B.x, 4);
|
|
|
|
e0_B.y = SIGN_EXTEND(e0_B.y, 4);
|
|
|
|
e0_B.z = SIGN_EXTEND(e0_B.z, 5);
|
|
|
|
|
|
|
|
e1_A.x = SIGN_EXTEND(e1_A.x, 4);
|
|
|
|
e1_A.y = SIGN_EXTEND(e1_A.y, 4);
|
|
|
|
e1_A.z = SIGN_EXTEND(e1_A.z, 5);
|
|
|
|
|
|
|
|
e1_B.x = SIGN_EXTEND(e1_B.x, 4);
|
|
|
|
e1_B.y = SIGN_EXTEND(e1_B.y, 4);
|
|
|
|
e1_B.z = SIGN_EXTEND(e1_B.z, 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
wprintf(L"\tMode 5 - [11 4 4 5] shape %llu\n", m->d);
|
|
|
|
wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t Index: ");
|
|
|
|
PrintIndex3bpp(m->indices, 1, m->d);
|
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
case 0x0E:
|
|
|
|
// Mode 6 (5 bits, 01110)
|
|
|
|
{
|
|
|
|
struct bc6h_mode6
|
|
|
|
{
|
|
|
|
uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4}
|
|
|
|
uint64_t rw : 9; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}
|
|
|
|
uint64_t by4 : 1; // {BY, 4}
|
|
|
|
uint64_t gw : 9; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}
|
|
|
|
uint64_t gy4 : 1; // {GY, 4}
|
|
|
|
uint64_t bw : 9; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}
|
|
|
|
uint64_t bz4 : 1; // {BZ, 4}
|
|
|
|
uint64_t rx : 5; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}
|
|
|
|
uint64_t gz4 : 1; // {GZ, 4}
|
|
|
|
uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3}
|
|
|
|
uint64_t gx : 5; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}
|
|
|
|
uint64_t bz0 : 1; // {BZ, 0}
|
|
|
|
uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3}
|
|
|
|
uint64_t bx : 5; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}
|
|
|
|
uint64_t bz1 : 1; // {BZ, 1}
|
|
|
|
uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2}
|
|
|
|
uint64_t by3 : 1; // {BY, 3}
|
|
|
|
uint64_t ry : 5; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4},
|
|
|
|
uint64_t bz2 : 1; // {BZ, 2}
|
|
|
|
uint64_t rz : 5; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {BZ, 4}
|
|
|
|
uint64_t bz3 : 1; // {BZ, 3}
|
|
|
|
uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4}
|
|
|
|
uint64_t indices : 46;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(bc6h_mode6) == 16, "Block size must be 16 bytes");
|
|
|
|
|
|
|
|
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
|
|
|
|
|
|
|
|
auto m = reinterpret_cast<const bc6h_mode6*>(sptr);
|
|
|
|
|
|
|
|
XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw));
|
|
|
|
XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx));
|
|
|
|
XMINT3 e1_A(int(m->ry),
|
|
|
|
int(m->gy | (m->gy4 << 4)),
|
|
|
|
int(m->by | (m->by3 << 3) | (m->by4 << 4)));
|
|
|
|
XMINT3 e1_B(int(m->rz),
|
|
|
|
int(m->gz | (m->gz4 << 4)),
|
|
|
|
int(m->bz0 | (m->bz1 << 1) | (m->bz2 << 2) | (m->bz3 << 3) | (m->bz4 << 4)));
|
|
|
|
|
|
|
|
if (bSigned)
|
|
|
|
{
|
|
|
|
e0_A.x = SIGN_EXTEND(e0_A.x, 9);
|
|
|
|
e0_A.y = SIGN_EXTEND(e0_A.y, 9);
|
|
|
|
e0_A.z = SIGN_EXTEND(e0_A.z, 9);
|
|
|
|
|
|
|
|
e0_B.x = SIGN_EXTEND(e0_B.x, 5);
|
|
|
|
e0_B.y = SIGN_EXTEND(e0_B.y, 5);
|
|
|
|
e0_B.z = SIGN_EXTEND(e0_B.z, 5);
|
|
|
|
|
|
|
|
e1_A.x = SIGN_EXTEND(e1_A.x, 5);
|
|
|
|
e1_A.y = SIGN_EXTEND(e1_A.y, 5);
|
|
|
|
e1_A.z = SIGN_EXTEND(e1_A.z, 5);
|
|
|
|
|
|
|
|
e1_B.x = SIGN_EXTEND(e1_B.x, 5);
|
|
|
|
e1_B.y = SIGN_EXTEND(e1_B.y, 5);
|
|
|
|
e1_B.z = SIGN_EXTEND(e1_B.z, 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
wprintf(L"\tMode 6 - [9 5 5 5] shape %llu\n", m->d);
|
|
|
|
wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t Index: ");
|
|
|
|
PrintIndex3bpp(m->indices, 1, m->d);
|
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
case 0x12:
|
|
|
|
// Mode 7 (5 bits, 10010)
|
|
|
|
{
|
|
|
|
struct bc6h_mode7
|
|
|
|
{
|
|
|
|
uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4}
|
|
|
|
uint64_t rw : 8; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}
|
|
|
|
uint64_t gz4 : 1; // {GZ, 4}
|
|
|
|
uint64_t by4 : 1; // {BY, 4}
|
|
|
|
uint64_t gw : 8; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}
|
|
|
|
uint64_t bz2 : 1; // {BZ, 2}
|
|
|
|
uint64_t gy4 : 1; // {GY, 4}
|
|
|
|
uint64_t bw : 8; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}
|
|
|
|
uint64_t bz3 : 1; // {BZ, 3}
|
|
|
|
uint64_t bz4 : 1; // {BZ, 4}
|
|
|
|
uint64_t rx : 6; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}, {RX, 5}
|
|
|
|
uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3}
|
|
|
|
uint64_t gx : 5; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}
|
|
|
|
uint64_t bz0 : 1; // {BZ, 0}
|
|
|
|
uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3}
|
|
|
|
uint64_t bx : 5; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}
|
|
|
|
uint64_t bz1 : 1; // {BZ, 1}
|
|
|
|
uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2}
|
|
|
|
uint64_t by3 : 1; // {BY, 3}
|
|
|
|
uint64_t ry : 6; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4}, {RY, 5}
|
|
|
|
uint64_t rz : 6; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4}, {RZ, 5}
|
|
|
|
uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4}
|
|
|
|
uint64_t indices : 46;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(bc6h_mode7) == 16, "Block size must be 16 bytes");
|
|
|
|
|
|
|
|
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
|
|
|
|
|
|
|
|
auto m = reinterpret_cast<const bc6h_mode7*>(sptr);
|
|
|
|
|
|
|
|
XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw));
|
|
|
|
XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx));
|
|
|
|
XMINT3 e1_A(int(m->ry),
|
|
|
|
int(m->gy | (m->gy4 << 4)),
|
|
|
|
int(m->by | (m->by3 << 3) | (m->by4 << 4)));
|
|
|
|
XMINT3 e1_B(int(m->rz),
|
|
|
|
int(m->gz | (m->gz4 << 4)),
|
|
|
|
int(m->bz0 | (m->bz1 << 1) | (m->bz2 << 2) | (m->bz3 << 3) | (m->bz4 << 4)));
|
|
|
|
|
|
|
|
if (bSigned)
|
|
|
|
{
|
|
|
|
e0_A.x = SIGN_EXTEND(e0_A.x, 8);
|
|
|
|
e0_A.y = SIGN_EXTEND(e0_A.y, 8);
|
|
|
|
e0_A.z = SIGN_EXTEND(e0_A.z, 8);
|
|
|
|
|
|
|
|
e0_B.x = SIGN_EXTEND(e0_B.x, 6);
|
|
|
|
e0_B.y = SIGN_EXTEND(e0_B.y, 5);
|
|
|
|
e0_B.z = SIGN_EXTEND(e0_B.z, 5);
|
|
|
|
|
|
|
|
e1_A.x = SIGN_EXTEND(e1_A.x, 6);
|
|
|
|
e1_A.y = SIGN_EXTEND(e1_A.y, 5);
|
|
|
|
e1_A.z = SIGN_EXTEND(e1_A.z, 5);
|
|
|
|
|
|
|
|
e1_B.x = SIGN_EXTEND(e1_B.x, 6);
|
|
|
|
e1_B.y = SIGN_EXTEND(e1_B.y, 5);
|
|
|
|
e1_B.z = SIGN_EXTEND(e1_B.z, 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
wprintf(L"\tMode 7 - [8 6 5 5] shape %llu\n", m->d);
|
|
|
|
wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t Index: ");
|
|
|
|
PrintIndex3bpp(m->indices, 1, m->d);
|
|
|
|
wprintf(L"\n");
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
2022-04-04 22:03:02 +00:00
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
case 0x16:
|
|
|
|
// Mode 8 (5 bits, 10110)
|
|
|
|
{
|
|
|
|
struct bc6h_mode8
|
|
|
|
{
|
|
|
|
uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4}
|
|
|
|
uint64_t rw : 8; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}
|
|
|
|
uint64_t bz0 : 1; // {BZ, 0}
|
|
|
|
uint64_t by4 : 1; // {BY, 4}
|
|
|
|
uint64_t gw : 8; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}
|
|
|
|
uint64_t gy5 : 1; // {GY, 5}
|
|
|
|
uint64_t gy4 : 1; // {GY, 4}
|
|
|
|
uint64_t bw : 8; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}
|
|
|
|
uint64_t gz5 : 1; // {GZ, 5}
|
|
|
|
uint64_t bz4 : 1; // {BZ, 4}
|
|
|
|
uint64_t rx : 5; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}
|
|
|
|
uint64_t gz4 : 1; // {GZ, 4}
|
|
|
|
uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3}
|
|
|
|
uint64_t gx : 6; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}, {GX, 5}
|
|
|
|
uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3}
|
|
|
|
uint64_t bx : 5; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}
|
|
|
|
uint64_t bz1 : 1; // {BZ, 1}
|
|
|
|
uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2}
|
|
|
|
uint64_t by3 : 1; // {BY, 3}
|
|
|
|
uint64_t ry : 5; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4}
|
|
|
|
uint64_t bz2 : 1; // {BZ, 2}
|
|
|
|
uint64_t rz : 5; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4}
|
|
|
|
uint64_t bz3 : 1; // {BZ, 3}
|
|
|
|
uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4}
|
|
|
|
uint64_t indices : 46;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(bc6h_mode8) == 16, "Block size must be 16 bytes");
|
|
|
|
|
|
|
|
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
|
|
|
|
|
|
|
|
auto m = reinterpret_cast<const bc6h_mode8*>(sptr);
|
|
|
|
|
|
|
|
XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw));
|
|
|
|
XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx));
|
|
|
|
XMINT3 e1_A(int(m->ry),
|
|
|
|
int(m->gy | (m->gy4 << 4) | (m->gy5 << 5)),
|
|
|
|
int(m->by | (m->by3 << 3) | (m->by4 << 4)));
|
|
|
|
XMINT3 e1_B(int(m->rz),
|
|
|
|
int(m->gz | (m->gz4 << 4) | (m->gz5 << 5)),
|
|
|
|
int(m->bz0 | (m->bz1 << 1) | (m->bz2 << 2) | (m->bz3 << 3) | (m->bz4 << 4)));
|
|
|
|
|
|
|
|
if (bSigned)
|
|
|
|
{
|
|
|
|
e0_A.x = SIGN_EXTEND(e0_A.x, 8);
|
|
|
|
e0_A.y = SIGN_EXTEND(e0_A.y, 8);
|
|
|
|
e0_A.z = SIGN_EXTEND(e0_A.z, 8);
|
|
|
|
|
|
|
|
e0_B.x = SIGN_EXTEND(e0_B.x, 5);
|
|
|
|
e0_B.y = SIGN_EXTEND(e0_B.y, 6);
|
|
|
|
e0_B.z = SIGN_EXTEND(e0_B.z, 5);
|
|
|
|
|
|
|
|
e1_A.x = SIGN_EXTEND(e1_A.x, 5);
|
|
|
|
e1_A.y = SIGN_EXTEND(e1_A.y, 6);
|
|
|
|
e1_A.z = SIGN_EXTEND(e1_A.z, 5);
|
|
|
|
|
|
|
|
e1_B.x = SIGN_EXTEND(e1_B.x, 5);
|
|
|
|
e1_B.y = SIGN_EXTEND(e1_B.y, 6);
|
|
|
|
e1_B.z = SIGN_EXTEND(e1_B.z, 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
wprintf(L"\tMode 8 - [8 5 6 5] shape %llu\n", m->d);
|
|
|
|
wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t Index: ");
|
|
|
|
PrintIndex3bpp(m->indices, 1, m->d);
|
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
case 0x1A:
|
|
|
|
// Mode 9 (5 bits, 11010)
|
|
|
|
{
|
2022-04-04 22:03:02 +00:00
|
|
|
struct bc6h_mode9
|
|
|
|
{
|
|
|
|
uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4}
|
|
|
|
uint64_t rw : 8; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}
|
|
|
|
uint64_t bz1 : 1; // {BZ, 1}
|
|
|
|
uint64_t by4 : 1; // {BY, 4}
|
|
|
|
uint64_t gw : 8; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}
|
|
|
|
uint64_t by5 : 1; // {BY, 5}
|
|
|
|
uint64_t gy4 : 1; // {GY, 4}
|
|
|
|
uint64_t bw : 8; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}
|
|
|
|
uint64_t bz5 : 1; // {BZ, 5}
|
|
|
|
uint64_t bz4 : 1; // {BZ, 4}
|
|
|
|
uint64_t rx : 5; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}
|
|
|
|
uint64_t gz4 : 1; // {GZ, 4}
|
|
|
|
uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3}
|
|
|
|
uint64_t gx : 5; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}
|
|
|
|
uint64_t bz0 : 1; // {BZ, 0}
|
|
|
|
uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3}
|
|
|
|
uint64_t bx : 6; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}, {BX, 5}
|
|
|
|
uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2}
|
|
|
|
uint64_t by3 : 1; // {BY, 3}
|
|
|
|
uint64_t ry : 5; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4}
|
|
|
|
uint64_t bz2 : 1; // {BZ, 2}
|
|
|
|
uint64_t rz : 5; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4}
|
|
|
|
uint64_t bz3 : 1; // {BZ, 3}
|
|
|
|
uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4}
|
|
|
|
uint64_t indices : 46;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(bc6h_mode9) == 16, "Block size must be 16 bytes");
|
|
|
|
|
|
|
|
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
|
|
|
|
|
|
|
|
auto m = reinterpret_cast<const bc6h_mode9*>(sptr);
|
|
|
|
|
|
|
|
XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw));
|
|
|
|
XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx));
|
|
|
|
XMINT3 e1_A(int(m->ry),
|
|
|
|
int(m->gy | (m->gy4 << 4)),
|
|
|
|
int(m->by | (m->by3 << 3) | (m->by4 << 4) | (m->by5 << 5)));
|
|
|
|
XMINT3 e1_B(int(m->rz),
|
|
|
|
int(m->gz | (m->gz4 << 4)),
|
|
|
|
int(m->bz0 | (m->bz1 << 1) | (m->bz2 << 2) | (m->bz3 << 3) | (m->bz4 << 4) | (m->bz5 << 5)));
|
|
|
|
|
|
|
|
if (bSigned)
|
|
|
|
{
|
|
|
|
e0_A.x = SIGN_EXTEND(e0_A.x, 8);
|
|
|
|
e0_A.y = SIGN_EXTEND(e0_A.y, 8);
|
|
|
|
e0_A.z = SIGN_EXTEND(e0_A.z, 8);
|
|
|
|
|
|
|
|
e0_B.x = SIGN_EXTEND(e0_B.x, 5);
|
|
|
|
e0_B.y = SIGN_EXTEND(e0_B.y, 5);
|
|
|
|
e0_B.z = SIGN_EXTEND(e0_B.z, 6);
|
|
|
|
|
|
|
|
e1_A.x = SIGN_EXTEND(e1_A.x, 5);
|
|
|
|
e1_A.y = SIGN_EXTEND(e1_A.y, 5);
|
|
|
|
e1_A.z = SIGN_EXTEND(e1_A.z, 6);
|
|
|
|
|
|
|
|
e1_B.x = SIGN_EXTEND(e1_B.x, 5);
|
|
|
|
e1_B.y = SIGN_EXTEND(e1_B.y, 5);
|
|
|
|
e1_B.z = SIGN_EXTEND(e1_B.z, 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
wprintf(L"\tMode 9 - [8 5 5 6] shape %llu\n", m->d);
|
|
|
|
wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t Index: ");
|
|
|
|
PrintIndex3bpp(m->indices, 1, m->d);
|
|
|
|
wprintf(L"\n");
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
2022-04-04 22:03:02 +00:00
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
case 0x1E:
|
|
|
|
// Mode 10 (5 bits, 11110)
|
|
|
|
{
|
2022-04-04 22:03:02 +00:00
|
|
|
struct bc6h_mode10
|
|
|
|
{
|
|
|
|
uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4}
|
|
|
|
uint64_t rw : 6; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}
|
|
|
|
uint64_t gz4 : 1; // {GZ, 4}
|
|
|
|
uint64_t bz : 2; // {BZ, 0}, {BZ, 1}
|
|
|
|
uint64_t by4 : 1; // {BY, 4}
|
|
|
|
uint64_t gw : 6; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}
|
|
|
|
uint64_t gy5 : 1; // {GY, 5}
|
|
|
|
uint64_t by5 : 1; // {BY, 5}
|
|
|
|
uint64_t bz2 : 1; // {BZ, 2}
|
|
|
|
uint64_t gy4 : 1; // {GY, 4}
|
|
|
|
uint64_t bw : 6; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {GZ, 5}
|
|
|
|
uint64_t bz3 : 1; // {BZ, 3}
|
|
|
|
uint64_t bz5 : 1; // {BZ, 5}
|
|
|
|
uint64_t bz4 : 1; // {BZ, 4}
|
|
|
|
uint64_t rx : 6; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}, {RX, 5}
|
|
|
|
uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3}
|
|
|
|
uint64_t gx : 6; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}, {GX, 5}
|
|
|
|
uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3}
|
|
|
|
uint64_t bx : 6; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}, {BX, 5}
|
|
|
|
uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2}
|
|
|
|
uint64_t by3 : 1; // {BY, 3}
|
|
|
|
uint64_t ry : 6; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4}, {RY, 5}
|
|
|
|
uint64_t rz : 6; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4}, {RZ, 5}
|
|
|
|
uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4}
|
|
|
|
uint64_t indices : 46;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(bc6h_mode10) == 16, "Block size must be 16 bytes");
|
|
|
|
|
|
|
|
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
|
|
|
|
|
|
|
|
auto m = reinterpret_cast<const bc6h_mode10*>(sptr);
|
|
|
|
|
|
|
|
XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw));
|
|
|
|
XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx));
|
|
|
|
XMINT3 e1_A(int(m->ry),
|
|
|
|
int(m->gy | (m->gy4 << 4) | (m->gy5 << 5)),
|
|
|
|
int(m->by | (m->by3 << 3) | (m->by4 << 4) | (m->by5 << 5)));
|
|
|
|
XMINT3 e1_B(int(m->rz),
|
|
|
|
int(m->gz | (m->gz4 << 4)),
|
|
|
|
int(m->bz | (m->bz2 << 2) | (m->bz3 << 3) | (m->bz4 << 4) | (m->bz5 << 5)));
|
|
|
|
|
|
|
|
if (bSigned)
|
|
|
|
{
|
|
|
|
e0_A.x = SIGN_EXTEND(e0_A.x, 6);
|
|
|
|
e0_A.y = SIGN_EXTEND(e0_A.y, 6);
|
|
|
|
e0_A.z = SIGN_EXTEND(e0_A.z, 6);
|
|
|
|
|
|
|
|
e0_B.x = SIGN_EXTEND(e0_B.x, 6);
|
|
|
|
e0_B.y = SIGN_EXTEND(e0_B.y, 6);
|
|
|
|
e0_B.z = SIGN_EXTEND(e0_B.z, 6);
|
|
|
|
|
|
|
|
e1_A.x = SIGN_EXTEND(e1_A.x, 6);
|
|
|
|
e1_A.y = SIGN_EXTEND(e1_A.y, 6);
|
|
|
|
e1_A.z = SIGN_EXTEND(e1_A.z, 6);
|
|
|
|
|
|
|
|
e1_B.x = SIGN_EXTEND(e1_B.x, 6);
|
|
|
|
e1_B.y = SIGN_EXTEND(e1_B.y, 6);
|
|
|
|
e1_B.z = SIGN_EXTEND(e1_B.z, 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
wprintf(L"\tMode 10 - [6 6 6 6] shape %llu\n", m->d);
|
|
|
|
wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t Index: ");
|
|
|
|
PrintIndex3bpp(m->indices, 1, m->d);
|
|
|
|
wprintf(L"\n");
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
2022-04-04 22:03:02 +00:00
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
case 0x03:
|
|
|
|
// Mode 11 (5 bits, 00011)
|
|
|
|
{
|
2022-04-04 22:03:02 +00:00
|
|
|
struct bc6h_mode11
|
|
|
|
{
|
|
|
|
uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4}
|
|
|
|
uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9}
|
|
|
|
uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9}
|
|
|
|
uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9}
|
|
|
|
uint64_t rx : 10; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}, {RX, 5}, {RX, 6}, {RX, 7}, {RX, 8}, {RX, 9}
|
|
|
|
uint64_t gx : 10; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}, {GX, 5}, {GX, 6}, {GX, 7}, {GX, 8}, {GX, 9}
|
|
|
|
uint64_t bx : 9; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}, {BX, 5}, {BX, 6}, {BX, 7}, {BX, 8}
|
|
|
|
uint64_t bx9 : 1; // {BX, 9}
|
|
|
|
uint64_t indices : 63;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(bc6h_mode11) == 16, "Block size must be 16 bytes");
|
|
|
|
|
|
|
|
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
|
|
|
|
|
|
|
|
auto m = reinterpret_cast<const bc6h_mode11*>(sptr);
|
|
|
|
|
|
|
|
XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw));
|
|
|
|
XMINT3 e0_B(int(m->rx), int(m->gx),
|
|
|
|
int(m->bx | (m->bx9 << 9)));
|
|
|
|
|
|
|
|
if (bSigned)
|
|
|
|
{
|
|
|
|
e0_A.x = SIGN_EXTEND(e0_A.x, 10);
|
|
|
|
e0_A.y = SIGN_EXTEND(e0_A.y, 10);
|
|
|
|
e0_A.z = SIGN_EXTEND(e0_A.z, 10);
|
|
|
|
|
|
|
|
e0_B.x = SIGN_EXTEND(e0_B.x, 10);
|
|
|
|
e0_B.y = SIGN_EXTEND(e0_B.y, 10);
|
|
|
|
e0_B.z = SIGN_EXTEND(e0_B.z, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
wprintf(L"\tMode 11 - [10 10]\n");
|
|
|
|
wprintf(L"\t E(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t Index: ");
|
|
|
|
PrintIndex4bpp(m->indices, 0, 0);
|
|
|
|
wprintf(L"\n");
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
2022-04-04 22:03:02 +00:00
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
case 0x07:
|
|
|
|
// Mode 12 (5 bits, 00111)
|
|
|
|
{
|
2022-04-04 22:03:02 +00:00
|
|
|
struct bc6h_mode12
|
|
|
|
{
|
|
|
|
uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4}
|
|
|
|
uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9}
|
|
|
|
uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9}
|
|
|
|
uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9}
|
|
|
|
uint64_t rx : 9; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}, {RX, 5}, {RX, 6}, {RX, 7}, {RX, 8}
|
|
|
|
uint64_t rw10 : 1; // {RW,10}
|
|
|
|
uint64_t gx : 9; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}, {GX, 5}, {GX, 6}, {GX, 7}, {GX, 8}
|
|
|
|
uint64_t gw10 : 1; // {GW,10}
|
|
|
|
uint64_t bx : 9; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}, {BX, 5}, {BX, 6}, {BX, 7}, {BX, 8}
|
|
|
|
uint64_t bw10 : 1; // {BW,10}
|
|
|
|
uint64_t indices : 63;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(bc6h_mode12) == 16, "Block size must be 16 bytes");
|
|
|
|
|
|
|
|
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
|
|
|
|
|
|
|
|
auto m = reinterpret_cast<const bc6h_mode12*>(sptr);
|
|
|
|
|
|
|
|
XMINT3 e0_A(int(m->rw | (m->rw10 << 10)),
|
|
|
|
int(m->gw | (m->gw10 << 10)),
|
|
|
|
int(m->bw | (m->bw10 << 10)));
|
|
|
|
XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx));
|
|
|
|
|
|
|
|
if (bSigned)
|
|
|
|
{
|
|
|
|
e0_A.x = SIGN_EXTEND(e0_A.x, 11);
|
|
|
|
e0_A.y = SIGN_EXTEND(e0_A.y, 11);
|
|
|
|
e0_A.z = SIGN_EXTEND(e0_A.z, 11);
|
|
|
|
|
|
|
|
e0_B.x = SIGN_EXTEND(e0_B.x, 9);
|
|
|
|
e0_B.y = SIGN_EXTEND(e0_B.y, 9);
|
|
|
|
e0_B.z = SIGN_EXTEND(e0_B.z, 9);
|
|
|
|
}
|
|
|
|
|
|
|
|
wprintf(L"\tMode 12 - [11 9]\n");
|
|
|
|
wprintf(L"\t E(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t Index: ");
|
|
|
|
PrintIndex4bpp(m->indices, 0, 0);
|
|
|
|
wprintf(L"\n");
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
2022-04-04 22:03:02 +00:00
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
case 0x0B:
|
|
|
|
// Mode 13 (5 bits, 01011)
|
|
|
|
{
|
2022-04-04 22:03:02 +00:00
|
|
|
struct bc6h_mode13
|
|
|
|
{
|
|
|
|
uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4}
|
|
|
|
uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9}
|
|
|
|
uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9}
|
|
|
|
uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9}
|
|
|
|
uint64_t rx : 8; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}, {RX, 5}, {RX, 6}, {RX, 7}
|
|
|
|
uint64_t rw11 : 1; // {RW,11}
|
|
|
|
uint64_t rw10 : 1; // {RW,10}
|
|
|
|
uint64_t gx : 8; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}, {GX, 5}, {GX, 6}, {GX, 7}
|
|
|
|
uint64_t gw11 : 1; // {GW,11}
|
|
|
|
uint64_t gw10 : 1; // {GW,10}
|
|
|
|
uint64_t bx : 8; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}, {BX, 5}, {BX, 6}, {BX, 7}
|
|
|
|
uint64_t bw11 : 1; // {BW,11}
|
|
|
|
uint64_t bw10 : 1; // {BW,10}
|
|
|
|
uint64_t indices : 63;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(bc6h_mode13) == 16, "Block size must be 16 bytes");
|
|
|
|
|
|
|
|
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
|
|
|
|
|
|
|
|
auto m = reinterpret_cast<const bc6h_mode13*>(sptr);
|
|
|
|
|
|
|
|
XMINT3 e0_A(int(m->rw | (m->rw10 << 10) | (m->rw11 << 11)),
|
|
|
|
int(m->gw | (m->gw10 << 10) | (m->gw11 << 11)),
|
|
|
|
int(m->bw | (m->bw10 << 10) | (m->bw11 << 11)));
|
|
|
|
XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx));
|
|
|
|
|
|
|
|
if (bSigned)
|
|
|
|
{
|
|
|
|
e0_A.x = SIGN_EXTEND(e0_A.x, 12);
|
|
|
|
e0_A.y = SIGN_EXTEND(e0_A.y, 12);
|
|
|
|
e0_A.z = SIGN_EXTEND(e0_A.z, 12);
|
|
|
|
|
|
|
|
e0_B.x = SIGN_EXTEND(e0_B.x, 8);
|
|
|
|
e0_B.y = SIGN_EXTEND(e0_B.y, 8);
|
|
|
|
e0_B.z = SIGN_EXTEND(e0_B.z, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
wprintf(L"\tMode 13 - [12 8]\n");
|
|
|
|
wprintf(L"\t E(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t Index: ");
|
|
|
|
PrintIndex4bpp(m->indices, 0, 0);
|
|
|
|
wprintf(L"\n");
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
2022-04-04 22:03:02 +00:00
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
case 0x0F:
|
|
|
|
// Mode 14 (5 bits, 01111)
|
|
|
|
{
|
2022-04-04 22:03:02 +00:00
|
|
|
struct bc6h_mode14
|
|
|
|
{
|
|
|
|
uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4}
|
|
|
|
uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9}
|
|
|
|
uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9}
|
|
|
|
uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9}
|
|
|
|
uint64_t rx : 4; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}
|
|
|
|
uint64_t rw15 : 1; // {RW,15}
|
|
|
|
uint64_t rw14 : 1; // {RW,14}
|
|
|
|
uint64_t rw13 : 1; // {RW,13}
|
|
|
|
uint64_t rw12 : 1; // {RW,12}
|
|
|
|
uint64_t rw11 : 1; // {RW,11}
|
|
|
|
uint64_t rw10 : 1; // {RW,10}
|
|
|
|
uint64_t gx : 4; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}
|
|
|
|
uint64_t gw15 : 1; // {GW,15}
|
|
|
|
uint64_t gw14 : 1; // {GW,14}
|
|
|
|
uint64_t gw13 : 1; // {GW,13}
|
|
|
|
uint64_t gw12 : 1; // {GW,12}
|
|
|
|
uint64_t gw11 : 1; // {GW,11}
|
|
|
|
uint64_t gw10 : 1; // {GW,10}
|
|
|
|
uint64_t bx : 4; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}
|
|
|
|
uint64_t bw15 : 1; // {BW,15}
|
|
|
|
uint64_t bw14 : 1; // {BW,14}
|
|
|
|
uint64_t bw13 : 1; // {BW,13}
|
|
|
|
uint64_t bw12 : 1; // {BW,12}
|
|
|
|
uint64_t bw11 : 1; // {BW,11}
|
|
|
|
uint64_t bw10 : 1; // {BW,10}
|
|
|
|
uint64_t indices : 63;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(bc6h_mode14) == 16, "Block size must be 16 bytes");
|
|
|
|
|
|
|
|
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
|
|
|
|
|
|
|
|
auto m = reinterpret_cast<const bc6h_mode14*>(sptr);
|
|
|
|
|
|
|
|
XMINT3 e0_A(int(m->rw | (m->rw10 << 10) | (m->rw11 << 11) | (m->rw12 << 12) | (m->rw13 << 13) | (m->rw14 << 14) | (m->rw15 << 15)),
|
|
|
|
int(m->gw | (m->gw10 << 10) | (m->gw11 << 11) | (m->gw12 << 12) | (m->gw13 << 13) | (m->gw14 << 14) | (m->gw15 << 15)),
|
|
|
|
int(m->bw | (m->bw10 << 10) | (m->bw11 << 11) | (m->bw12 << 12) | (m->bw13 << 13) | (m->bw14 << 14) | (m->bw15 << 15)));
|
|
|
|
XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx));
|
|
|
|
|
|
|
|
if (bSigned)
|
|
|
|
{
|
|
|
|
e0_A.x = SIGN_EXTEND(e0_A.x, 16);
|
|
|
|
e0_A.y = SIGN_EXTEND(e0_A.y, 16);
|
|
|
|
e0_A.z = SIGN_EXTEND(e0_A.z, 16);
|
|
|
|
|
|
|
|
e0_B.x = SIGN_EXTEND(e0_B.x, 4);
|
|
|
|
e0_B.y = SIGN_EXTEND(e0_B.y, 4);
|
|
|
|
e0_B.z = SIGN_EXTEND(e0_B.z, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
wprintf(L"\tMode 14 - [16 4]\n");
|
|
|
|
wprintf(L"\t E(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF);
|
|
|
|
wprintf(L"\t E(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF);
|
|
|
|
wprintf(L"\t Index: ");
|
|
|
|
PrintIndex4bpp(m->indices, 0, 0);
|
|
|
|
wprintf(L"\n");
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
2022-04-04 22:03:02 +00:00
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
case 0x13: // Reserved mode (5 bits, 10011)
|
|
|
|
wprintf(L"\tERROR - Reserved mode 10011\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x17: // Reserved mode (5 bits, 10111)
|
|
|
|
wprintf(L"\tERROR - Reserved mode 10011\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x1B: // Reserved mode (5 bits, 11011)
|
|
|
|
wprintf(L"\tERROR - Reserved mode 11011\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x1F: // Reserved mode (5 bits, 11111)
|
|
|
|
wprintf(L"\tERROR - Reserved mode 11111\n");
|
|
|
|
break;
|
2019-07-06 06:48:39 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DXGI_FORMAT_BC7_UNORM:
|
|
|
|
case DXGI_FORMAT_BC7_UNORM_SRGB:
|
|
|
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/hh308954.aspx
|
|
|
|
|
|
|
|
if (*sptr & 0x01)
|
|
|
|
{
|
|
|
|
// Mode 0 (1)
|
|
|
|
struct bc7_mode0
|
|
|
|
{
|
|
|
|
uint64_t mode : 1;
|
|
|
|
uint64_t part : 4;
|
|
|
|
uint64_t r0 : 4;
|
|
|
|
uint64_t r1 : 4;
|
|
|
|
uint64_t r2 : 4;
|
|
|
|
uint64_t r3 : 4;
|
|
|
|
uint64_t r4 : 4;
|
|
|
|
uint64_t r5 : 4;
|
|
|
|
uint64_t g0 : 4;
|
|
|
|
uint64_t g1 : 4;
|
|
|
|
uint64_t g2 : 4;
|
|
|
|
uint64_t g3 : 4;
|
|
|
|
uint64_t g4 : 4;
|
|
|
|
uint64_t g5 : 4;
|
|
|
|
uint64_t b0 : 4;
|
|
|
|
uint64_t b1 : 4;
|
|
|
|
uint64_t b2 : 3;
|
|
|
|
uint64_t b2n : 1;
|
|
|
|
uint64_t b3 : 4;
|
|
|
|
uint64_t b4 : 4;
|
|
|
|
uint64_t b5 : 4;
|
|
|
|
uint64_t P0 : 1;
|
|
|
|
uint64_t P1 : 1;
|
|
|
|
uint64_t P2 : 1;
|
|
|
|
uint64_t P3 : 1;
|
|
|
|
uint64_t P4 : 1;
|
|
|
|
uint64_t P5 : 1;
|
|
|
|
uint64_t index : 45;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(bc7_mode0) == 16, "Block size must be 16 bytes");
|
|
|
|
|
|
|
|
auto m = reinterpret_cast<const bc7_mode0*>(sptr);
|
|
|
|
|
2018-05-02 17:05:48 +00:00
|
|
|
wprintf(L"\tMode 0 - [4 4 4] partition %llu\n", m->part);
|
2016-09-25 23:04:44 +00:00
|
|
|
wprintf(L"\t E0:(%0.3f, %0.3f, %0.3f)\n", float((m->r0 << 1) | m->P0) / 31.f, float((m->g0 << 1) | m->P0) / 31.f, float((m->b0 << 1) | m->P0) / 31.f);
|
|
|
|
wprintf(L"\t E1:(%0.3f, %0.3f, %0.3f)\n", float((m->r1 << 1) | m->P1) / 31.f, float((m->g1 << 1) | m->P1) / 31.f, float((m->b1 << 1) | m->P1) / 31.f);
|
|
|
|
wprintf(L"\t E2:(%0.3f, %0.3f, %0.3f)\n", float((m->r2 << 1) | m->P2) / 31.f, float((m->g2 << 1) | m->P2) / 31.f, float(((m->b2 | (m->b2n << 3)) << 1) | m->P2) / 31.f);
|
|
|
|
wprintf(L"\t E3:(%0.3f, %0.3f, %0.3f)\n", float((m->r3 << 1) | m->P3) / 31.f, float((m->g3 << 1) | m->P3) / 31.f, float((m->b3 << 1) | m->P3) / 31.f);
|
|
|
|
wprintf(L"\t E4:(%0.3f, %0.3f, %0.3f)\n", float((m->r4 << 1) | m->P4) / 31.f, float((m->g4 << 1) | m->P4) / 31.f, float((m->b4 << 1) | m->P4) / 31.f);
|
|
|
|
wprintf(L"\t E5:(%0.3f, %0.3f, %0.3f)\n", float((m->r5 << 1) | m->P5) / 31.f, float((m->g5 << 1) | m->P5) / 31.f, float((m->b5 << 1) | m->P5) / 31.f);
|
|
|
|
wprintf(L"\t Index: ");
|
|
|
|
PrintIndex2bpp(m->index, 2, m->part);
|
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
else if (*sptr & 0x02)
|
|
|
|
{
|
|
|
|
// Mode 1 (01)
|
|
|
|
struct bc7_mode1
|
|
|
|
{
|
|
|
|
uint64_t mode : 2;
|
|
|
|
uint64_t part : 6;
|
|
|
|
uint64_t r0 : 6;
|
|
|
|
uint64_t r1 : 6;
|
|
|
|
uint64_t r2 : 6;
|
|
|
|
uint64_t r3 : 6;
|
|
|
|
uint64_t g0 : 6;
|
|
|
|
uint64_t g1 : 6;
|
|
|
|
uint64_t g2 : 6;
|
|
|
|
uint64_t g3 : 6;
|
|
|
|
uint64_t b0 : 6;
|
|
|
|
uint64_t b1 : 2;
|
|
|
|
uint64_t b1n : 4;
|
|
|
|
uint64_t b2 : 6;
|
|
|
|
uint64_t b3 : 6;
|
|
|
|
uint64_t P0 : 1;
|
|
|
|
uint64_t P1 : 1;
|
|
|
|
uint64_t index : 46;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(bc7_mode1) == 16, "Block size must be 16 bytes");
|
|
|
|
|
|
|
|
auto m = reinterpret_cast<const bc7_mode1*>(sptr);
|
|
|
|
|
2018-05-02 17:05:48 +00:00
|
|
|
wprintf(L"\tMode 1 - [6 6 6] partition %llu\n", m->part);
|
2016-09-25 23:04:44 +00:00
|
|
|
wprintf(L"\t E0:(%0.3f, %0.3f, %0.3f)\n", float((m->r0 << 1) | m->P0) / 127.f, float((m->g0 << 1) | m->P0) / 127.f, float((m->b0 << 1) | m->P0) / 127.f);
|
|
|
|
wprintf(L"\t E1:(%0.3f, %0.3f, %0.3f)\n", float((m->r1 << 1) | m->P0) / 127.f, float((m->g1 << 1) | m->P0) / 127.f, float(((m->b1 | (m->b1n << 2)) << 1) | m->P0) / 127.f);
|
|
|
|
wprintf(L"\t E2:(%0.3f, %0.3f, %0.3f)\n", float((m->r2 << 1) | m->P1) / 127.f, float((m->g2 << 1) | m->P1) / 127.f, float((m->b2 << 1) | m->P1) / 127.f);
|
|
|
|
wprintf(L"\t E3:(%0.3f, %0.3f, %0.3f)\n", float((m->r3 << 1) | m->P1) / 127.f, float((m->g3 << 1) | m->P1) / 127.f, float((m->b3 << 1) | m->P1) / 127.f);
|
|
|
|
wprintf(L"\t Index: ");
|
|
|
|
PrintIndex3bpp(m->index, 1, m->part);
|
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
else if (*sptr & 0x04)
|
|
|
|
{
|
|
|
|
// Mode 2 (001)
|
|
|
|
struct bc7_mode2
|
|
|
|
{
|
|
|
|
uint64_t mode : 3;
|
|
|
|
uint64_t part : 6;
|
|
|
|
uint64_t r0 : 5;
|
|
|
|
uint64_t r1 : 5;
|
|
|
|
uint64_t r2 : 5;
|
|
|
|
uint64_t r3 : 5;
|
|
|
|
uint64_t r4 : 5;
|
|
|
|
uint64_t r5 : 5;
|
|
|
|
uint64_t g0 : 5;
|
|
|
|
uint64_t g1 : 5;
|
|
|
|
uint64_t g2 : 5;
|
|
|
|
uint64_t g3 : 5;
|
|
|
|
uint64_t g4 : 5;
|
|
|
|
uint64_t g5 : 5;
|
|
|
|
uint64_t b0 : 5;
|
|
|
|
uint64_t b1 : 5;
|
|
|
|
uint64_t b2 : 5;
|
|
|
|
uint64_t b3 : 5;
|
|
|
|
uint64_t b4 : 5;
|
|
|
|
uint64_t b5 : 5;
|
|
|
|
uint64_t index : 29;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(bc7_mode2) == 16, "Block size must be 16 bytes");
|
|
|
|
|
|
|
|
auto m = reinterpret_cast<const bc7_mode2*>(sptr);
|
|
|
|
|
2018-05-02 17:05:48 +00:00
|
|
|
wprintf(L"\tMode 2 - [5 5 5] partition %llu\n", m->part);
|
2016-09-25 23:04:44 +00:00
|
|
|
wprintf(L"\t E0:(%0.3f, %0.3f, %0.3f)\n", float(m->r0) / 31.f, float(m->g0) / 31.f, float(m->b0) / 31.f);
|
|
|
|
wprintf(L"\t E1:(%0.3f, %0.3f, %0.3f)\n", float(m->r1) / 31.f, float(m->g1) / 31.f, float(m->b1) / 31.f);
|
|
|
|
wprintf(L"\t E2:(%0.3f, %0.3f, %0.3f)\n", float(m->r2) / 31.f, float(m->g2) / 31.f, float(m->b2) / 31.f);
|
|
|
|
wprintf(L"\t E3:(%0.3f, %0.3f, %0.3f)\n", float(m->r3) / 31.f, float(m->g3) / 31.f, float(m->b3) / 31.f);
|
|
|
|
wprintf(L"\t E4:(%0.3f, %0.3f, %0.3f)\n", float(m->r4) / 31.f, float(m->g4) / 31.f, float(m->b4) / 31.f);
|
|
|
|
wprintf(L"\t E5:(%0.3f, %0.3f, %0.3f)\n", float(m->r5) / 31.f, float(m->g5) / 31.f, float(m->b5) / 31.f);
|
|
|
|
wprintf(L"\t Index: ");
|
|
|
|
PrintIndex2bpp(m->index, 2, m->part);
|
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
else if (*sptr & 0x08)
|
|
|
|
{
|
|
|
|
// Mode 3 (0001)
|
|
|
|
struct bc7_mode3
|
|
|
|
{
|
|
|
|
uint64_t mode : 4;
|
|
|
|
uint64_t part : 6;
|
|
|
|
uint64_t r0 : 7;
|
|
|
|
uint64_t r1 : 7;
|
|
|
|
uint64_t r2 : 7;
|
|
|
|
uint64_t r3 : 7;
|
|
|
|
uint64_t g0 : 7;
|
|
|
|
uint64_t g1 : 7;
|
|
|
|
uint64_t g2 : 7;
|
|
|
|
uint64_t g3 : 5;
|
|
|
|
uint64_t g3n : 2;
|
|
|
|
uint64_t b0 : 7;
|
|
|
|
uint64_t b1 : 7;
|
|
|
|
uint64_t b2 : 7;
|
|
|
|
uint64_t b3 : 7;
|
|
|
|
uint64_t P0 : 1;
|
|
|
|
uint64_t P1 : 1;
|
|
|
|
uint64_t P2 : 1;
|
|
|
|
uint64_t P3 : 1;
|
|
|
|
uint64_t index : 30;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(bc7_mode3) == 16, "Block size must be 16 bytes");
|
|
|
|
|
|
|
|
auto m = reinterpret_cast<const bc7_mode3*>(sptr);
|
|
|
|
|
2018-05-02 17:05:48 +00:00
|
|
|
wprintf(L"\tMode 3 - [7 7 7] partition %llu\n", m->part);
|
2016-09-25 23:04:44 +00:00
|
|
|
wprintf(L"\t E0:(%0.3f, %0.3f, %0.3f)\n", float((m->r0 << 1) | m->P0) / 255.f, float((m->g0 << 1) | m->P0) / 255.f, float((m->b0 << 1) | m->P0) / 255.f);
|
|
|
|
wprintf(L"\t E1:(%0.3f, %0.3f, %0.3f)\n", float((m->r1 << 1) | m->P1) / 255.f, float((m->g1 << 1) | m->P1) / 255.f, float((m->b1 << 1) | m->P1) / 255.f);
|
|
|
|
wprintf(L"\t E2:(%0.3f, %0.3f, %0.3f)\n", float((m->r2 << 1) | m->P2) / 255.f, float((m->g2 << 1) | m->P2) / 255.f, float((m->b2 << 1) | m->P2) / 255.f);
|
|
|
|
wprintf(L"\t E3:(%0.3f, %0.3f, %0.3f)\n", float((m->r3 << 1) | m->P3) / 255.f, float(((m->g3 | (m->g3n << 5)) << 1) | m->P3) / 255.f, float((m->b3 << 1) | m->P3) / 255.f);
|
|
|
|
wprintf(L"\t Index: ");
|
|
|
|
PrintIndex2bpp(m->index, 1, m->part);
|
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
else if (*sptr & 0x10)
|
|
|
|
{
|
|
|
|
// Mode 4 (00001)
|
|
|
|
struct bc7_mode4
|
|
|
|
{
|
|
|
|
uint64_t mode : 5;
|
|
|
|
uint64_t rot : 2;
|
|
|
|
uint64_t idx : 1;
|
|
|
|
uint64_t r0 : 5;
|
|
|
|
uint64_t r1 : 5;
|
|
|
|
uint64_t g0 : 5;
|
|
|
|
uint64_t g1 : 5;
|
|
|
|
uint64_t b0 : 5;
|
|
|
|
uint64_t b1 : 5;
|
|
|
|
uint64_t a0 : 6;
|
|
|
|
uint64_t a1 : 6;
|
|
|
|
uint64_t color_index : 14;
|
|
|
|
uint64_t color_indexn : 17;
|
|
|
|
uint64_t alpha_index : 47;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(bc7_mode4) == 16, "Block size must be 16 bytes");
|
|
|
|
|
|
|
|
auto m = reinterpret_cast<const bc7_mode4*>(sptr);
|
|
|
|
|
2018-05-02 17:05:48 +00:00
|
|
|
wprintf(L"\tMode 4 - [5 5 5 A6] indx mode %ls, rot-bits %llu%ls\n", m->idx ? L"3-bit" : L"2-bit", m->rot, GetRotBits(m->rot));
|
2016-09-25 23:04:44 +00:00
|
|
|
wprintf(L"\t C0:(%0.3f, %0.3f, %0.3f)\n", float(m->r0) / 31.f, float(m->g0) / 31.f, float(m->b0) / 31.f);
|
|
|
|
wprintf(L"\t C1:(%0.3f, %0.3f, %0.3f)\n", float(m->r1) / 31.f, float(m->g1) / 31.f, float(m->b1) / 31.f);
|
|
|
|
wprintf(L"\t A0:(%0.3f)\n", float(m->a0) / 63.f);
|
|
|
|
wprintf(L"\t A1:(%0.3f)\n", float(m->a1) / 63.f);
|
|
|
|
wprintf(L"\t Colors: ");
|
|
|
|
|
2022-03-01 22:31:55 +00:00
|
|
|
const uint64_t color_index = uint64_t(m->color_index) | uint64_t(m->color_indexn << 14);
|
2016-09-25 23:04:44 +00:00
|
|
|
if (m->idx)
|
|
|
|
PrintIndex3bpp(color_index, 0, 0);
|
|
|
|
else
|
|
|
|
PrintIndex2bpp(color_index, 0, 0);
|
|
|
|
wprintf(L"\n");
|
|
|
|
wprintf(L"\t Alpha: ");
|
|
|
|
PrintIndex3bpp(m->alpha_index, 0, 0);
|
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
else if (*sptr & 0x20)
|
|
|
|
{
|
|
|
|
// Mode 5 (000001)
|
|
|
|
struct bc7_mode5
|
|
|
|
{
|
|
|
|
uint64_t mode : 6;
|
|
|
|
uint64_t rot : 2;
|
|
|
|
uint64_t r0 : 7;
|
|
|
|
uint64_t r1 : 7;
|
|
|
|
uint64_t g0 : 7;
|
|
|
|
uint64_t g1 : 7;
|
|
|
|
uint64_t b0 : 7;
|
|
|
|
uint64_t b1 : 7;
|
|
|
|
uint64_t a0 : 8;
|
|
|
|
uint64_t a1 : 6;
|
|
|
|
uint64_t a1n : 2;
|
|
|
|
uint64_t color_index : 31;
|
|
|
|
uint64_t alpha_index : 31;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(bc7_mode5) == 16, "Block size must be 16 bytes");
|
|
|
|
|
|
|
|
auto m = reinterpret_cast<const bc7_mode5*>(sptr);
|
|
|
|
|
2018-05-02 17:05:48 +00:00
|
|
|
wprintf(L"\tMode 5 - [7 7 7 A8] rot-bits %llu%ls\n", m->rot, GetRotBits(m->rot));
|
2016-09-25 23:04:44 +00:00
|
|
|
wprintf(L"\t C0:(%0.3f, %0.3f, %0.3f)\n", float(m->r0) / 127.f, float(m->g0) / 127.f, float(m->b0) / 127.f);
|
|
|
|
wprintf(L"\t C1:(%0.3f, %0.3f, %0.3f)\n", float(m->r1) / 127.f, float(m->g1) / 127.f, float(m->b1) / 127.f);
|
|
|
|
wprintf(L"\t A0:(%0.3f)\n", float(m->a0) / 255.f);
|
|
|
|
wprintf(L"\t A1:(%0.3f)\n", float(m->a1 | (m->a1n << 6)) / 255.f);
|
|
|
|
wprintf(L"\t Colors: ");
|
|
|
|
PrintIndex2bpp(m->color_index, 0, 0);
|
|
|
|
wprintf(L"\n");
|
|
|
|
wprintf(L"\t Alpha: ");
|
|
|
|
PrintIndex2bpp(m->alpha_index, 0, 0);
|
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
else if (*sptr & 0x40)
|
|
|
|
{
|
|
|
|
// Mode 6 (0000001)
|
|
|
|
struct bc7_mode6
|
|
|
|
{
|
|
|
|
uint64_t mode : 7;
|
|
|
|
uint64_t r0 : 7;
|
|
|
|
uint64_t r1 : 7;
|
|
|
|
uint64_t g0 : 7;
|
|
|
|
uint64_t g1 : 7;
|
|
|
|
uint64_t b0 : 7;
|
|
|
|
uint64_t b1 : 7;
|
|
|
|
uint64_t a0 : 7;
|
|
|
|
uint64_t a1 : 7;
|
|
|
|
uint64_t P0 : 1;
|
|
|
|
uint64_t P1 : 1;
|
|
|
|
uint64_t index : 63;
|
|
|
|
|
|
|
|
};
|
|
|
|
static_assert(sizeof(bc7_mode6) == 16, "Block size must be 16 bytes");
|
|
|
|
|
|
|
|
auto m = reinterpret_cast<const bc7_mode6*>(sptr);
|
|
|
|
|
|
|
|
wprintf(L"\tMode 6 - [7 7 7 A7]\n");
|
|
|
|
wprintf(L"\t C0:(%0.3f, %0.3f, %0.3f)\n", float((m->r0 << 1) | m->P0) / 255.f, float((m->g0 << 1) | m->P0) / 255.f, float((m->b0 << 1) | m->P0) / 255.f);
|
|
|
|
wprintf(L"\t C1:(%0.3f, %0.3f, %0.3f)\n", float((m->r1 << 1) | m->P1) / 255.f, float((m->g1 << 1) | m->P1) / 255.f, float((m->b1 << 1) | m->P1) / 255.f);
|
|
|
|
wprintf(L"\t A0:(%0.3f)\n", float((m->a0 << 1) | m->P0) / 255.f);
|
|
|
|
wprintf(L"\t A1:(%0.3f)\n", float((m->a1 << 1) | m->P1) / 255.f);
|
|
|
|
wprintf(L"\t Index: ");
|
|
|
|
PrintIndex4bpp(m->index, 0, 0);
|
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
else if (*sptr & 0x80)
|
|
|
|
{
|
|
|
|
// Mode 7 (00000001)
|
|
|
|
struct bc7_mode7
|
|
|
|
{
|
|
|
|
uint64_t mode : 8;
|
|
|
|
uint64_t part : 6;
|
|
|
|
uint64_t r0 : 5;
|
|
|
|
uint64_t r1 : 5;
|
|
|
|
uint64_t r2 : 5;
|
|
|
|
uint64_t r3 : 5;
|
|
|
|
uint64_t g0 : 5;
|
|
|
|
uint64_t g1 : 5;
|
|
|
|
uint64_t g2 : 5;
|
|
|
|
uint64_t g3 : 5;
|
|
|
|
uint64_t b0 : 5;
|
|
|
|
uint64_t b1 : 5;
|
|
|
|
uint64_t b2 : 5;
|
|
|
|
uint64_t b3 : 5;
|
|
|
|
uint64_t a0 : 5;
|
|
|
|
uint64_t a1 : 5;
|
|
|
|
uint64_t a2 : 5;
|
|
|
|
uint64_t a3 : 5;
|
|
|
|
uint64_t P0 : 1;
|
|
|
|
uint64_t P1 : 1;
|
|
|
|
uint64_t P2 : 1;
|
|
|
|
uint64_t P3 : 1;
|
|
|
|
uint64_t index : 30;
|
|
|
|
|
|
|
|
};
|
|
|
|
static_assert(sizeof(bc7_mode7) == 16, "Block size must be 16 bytes");
|
|
|
|
|
|
|
|
auto m = reinterpret_cast<const bc7_mode7*>(sptr);
|
|
|
|
|
2018-05-02 17:05:48 +00:00
|
|
|
wprintf(L"\tMode 7 - [5 5 5 A5] partition %llu\n", m->part);
|
2016-09-25 23:04:44 +00:00
|
|
|
wprintf(L"\t C0:(%0.3f, %0.3f, %0.3f)\n", float((m->r0 << 1) | m->P0) / 63.f, float((m->g0 << 1) | m->P0) / 63.f, float((m->b0 << 1) | m->P0) / 63.f);
|
|
|
|
wprintf(L"\t C1:(%0.3f, %0.3f, %0.3f)\n", float((m->r1 << 1) | m->P1) / 63.f, float((m->g1 << 1) | m->P1) / 63.f, float((m->b1 << 1) | m->P1) / 63.f);
|
|
|
|
wprintf(L"\t C2:(%0.3f, %0.3f, %0.3f)\n", float((m->r2 << 1) | m->P2) / 63.f, float((m->g2 << 1) | m->P2) / 63.f, float((m->b2 << 1) | m->P2) / 63.f);
|
|
|
|
wprintf(L"\t C3:(%0.3f, %0.3f, %0.3f)\n", float((m->r3 << 1) | m->P3) / 63.f, float((m->g3 << 1) | m->P3) / 63.f, float((m->b3 << 1) | m->P3) / 63.f);
|
|
|
|
wprintf(L"\t A0:(%0.3f)\n", float((m->a0 << 1) | m->P0) / 63.f);
|
|
|
|
wprintf(L"\t A1:(%0.3f)\n", float((m->a1 << 1) | m->P1) / 63.f);
|
|
|
|
wprintf(L"\t A2:(%0.3f)\n", float((m->a2 << 1) | m->P2) / 63.f);
|
|
|
|
wprintf(L"\t A3:(%0.3f)\n", float((m->a3 << 1) | m->P3) / 63.f);
|
|
|
|
wprintf(L"\t Index: ");
|
|
|
|
PrintIndex4bpp(m->index, 1, m->part);
|
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Reserved mode 8 (00000000)
|
|
|
|
wprintf(L"\tERROR - Reserved mode 8\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2022-04-04 22:03:02 +00:00
|
|
|
#pragma endregion
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
// Entry-point
|
|
|
|
//--------------------------------------------------------------------------------------
|
2019-07-06 06:48:39 +00:00
|
|
|
#ifdef _PREFAST_
|
2016-09-25 23:04:44 +00:00
|
|
|
#pragma prefast(disable : 28198, "Command-line tool, frees all memory on exit")
|
2019-07-06 06:48:39 +00:00
|
|
|
#endif
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|
|
|
{
|
|
|
|
// Parameters and defaults
|
2020-06-01 07:42:02 +00:00
|
|
|
TEX_FILTER_FLAGS dwFilter = TEX_FILTER_DEFAULT;
|
2016-09-25 23:04:44 +00:00
|
|
|
int pixelx = -1;
|
|
|
|
int pixely = -1;
|
2021-06-10 00:40:17 +00:00
|
|
|
uint32_t diffColor = 0;
|
|
|
|
float threshold = 0.25f;
|
2016-09-27 07:24:19 +00:00
|
|
|
DXGI_FORMAT diffFormat = DXGI_FORMAT_B8G8R8A8_UNORM;
|
2021-04-25 02:57:56 +00:00
|
|
|
uint32_t fileType = WIC_CODEC_BMP;
|
2023-06-13 22:40:45 +00:00
|
|
|
std::wstring outputFile;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2021-04-28 21:33:45 +00:00
|
|
|
// Set locale for output since GetErrorDesc can get localized strings.
|
|
|
|
std::locale::global(std::locale(""));
|
|
|
|
|
2016-09-25 23:04:44 +00:00
|
|
|
// Initialize COM (needed for WIC)
|
|
|
|
HRESULT hr = hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-04-01 07:59:57 +00:00
|
|
|
wprintf(L"Failed to initialize COM (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
2016-09-25 23:04:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process command line
|
|
|
|
if (argc < 2)
|
|
|
|
{
|
|
|
|
PrintUsage();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-03-27 23:02:41 +00:00
|
|
|
if (('-' == argv[1][0]) && ('-' == argv[1][1]))
|
|
|
|
{
|
|
|
|
if (!_wcsicmp(argv[1], L"--version"))
|
|
|
|
{
|
|
|
|
PrintLogo(true);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (!_wcsicmp(argv[1], L"--help"))
|
|
|
|
{
|
|
|
|
PrintUsage();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-01 22:31:55 +00:00
|
|
|
const uint32_t dwCommand = LookupByName(argv[1], g_pCommands);
|
2016-09-25 23:04:44 +00:00
|
|
|
switch (dwCommand)
|
|
|
|
{
|
|
|
|
case CMD_INFO:
|
|
|
|
case CMD_ANALYZE:
|
|
|
|
case CMD_COMPARE:
|
2016-09-27 07:24:19 +00:00
|
|
|
case CMD_DIFF:
|
2016-09-25 23:04:44 +00:00
|
|
|
case CMD_DUMPBC:
|
2018-02-09 22:45:34 +00:00
|
|
|
case CMD_DUMPDDS:
|
2016-09-25 23:04:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-02-09 22:45:34 +00:00
|
|
|
wprintf(L"Must use one of: info, analyze, compare, diff, dumpbc, or dumpdds\n\n");
|
2016-09-25 23:04:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-04-25 02:57:56 +00:00
|
|
|
uint32_t dwOptions = 0;
|
2016-09-25 23:04:44 +00:00
|
|
|
std::list<SConversion> conversion;
|
2023-03-27 23:02:41 +00:00
|
|
|
bool allowOpts = true;
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
for (int iArg = 2; iArg < argc; iArg++)
|
|
|
|
{
|
|
|
|
PWSTR pArg = argv[iArg];
|
|
|
|
|
2023-03-27 23:02:41 +00:00
|
|
|
if (allowOpts
|
|
|
|
&& ('-' == pArg[0]) && ('-' == pArg[1]))
|
|
|
|
{
|
|
|
|
if (pArg[2] == 0)
|
|
|
|
{
|
|
|
|
// "-- " is the POSIX standard for "end of options" marking to escape the '-' and '/' characters at the start of filepaths.
|
|
|
|
allowOpts = false;
|
|
|
|
}
|
|
|
|
else if (!_wcsicmp(pArg, L"--version"))
|
|
|
|
{
|
|
|
|
PrintLogo(true);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (!_wcsicmp(pArg, L"--help"))
|
|
|
|
{
|
|
|
|
PrintUsage();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wprintf(L"Unknown option: %ls\n", pArg);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (allowOpts
|
|
|
|
&& (('-' == pArg[0]) || ('/' == pArg[0])))
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
|
|
|
pArg++;
|
|
|
|
PWSTR pValue;
|
|
|
|
|
|
|
|
for (pValue = pArg; *pValue && (':' != *pValue); pValue++);
|
|
|
|
|
|
|
|
if (*pValue)
|
|
|
|
*pValue++ = 0;
|
|
|
|
|
2022-03-01 22:31:55 +00:00
|
|
|
const uint32_t dwOption = LookupByName(pArg, g_pOptions);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
if (!dwOption || (dwOptions & (1 << dwOption)))
|
|
|
|
{
|
|
|
|
PrintUsage();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
dwOptions |= 1 << dwOption;
|
|
|
|
|
|
|
|
// Handle options with additional value parameter
|
|
|
|
switch (dwOption)
|
|
|
|
{
|
|
|
|
case OPT_FILTER:
|
2016-09-27 07:24:19 +00:00
|
|
|
case OPT_FORMAT:
|
2018-02-09 22:45:34 +00:00
|
|
|
case OPT_FILETYPE:
|
2016-09-27 07:24:19 +00:00
|
|
|
case OPT_OUTPUTFILE:
|
2016-09-25 23:04:44 +00:00
|
|
|
case OPT_TARGET_PIXELX:
|
|
|
|
case OPT_TARGET_PIXELY:
|
2021-06-10 00:40:17 +00:00
|
|
|
case OPT_DIFF_COLOR:
|
|
|
|
case OPT_THRESHOLD:
|
2017-09-19 18:13:34 +00:00
|
|
|
case OPT_FILELIST:
|
2016-09-25 23:04:44 +00:00
|
|
|
if (!*pValue)
|
|
|
|
{
|
|
|
|
if ((iArg + 1 >= argc))
|
|
|
|
{
|
|
|
|
PrintUsage();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
iArg++;
|
|
|
|
pValue = argv[iArg];
|
|
|
|
}
|
|
|
|
break;
|
2019-07-06 06:48:39 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (dwOption)
|
|
|
|
{
|
2016-09-27 07:24:19 +00:00
|
|
|
case OPT_FORMAT:
|
|
|
|
if (dwCommand != CMD_DIFF)
|
|
|
|
{
|
|
|
|
wprintf(L"-f only valid for use with diff command\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-22 08:17:49 +00:00
|
|
|
diffFormat = static_cast<DXGI_FORMAT>(LookupByName(pValue, g_pFormats));
|
2016-09-27 07:24:19 +00:00
|
|
|
if (!diffFormat)
|
|
|
|
{
|
2018-02-22 08:17:49 +00:00
|
|
|
diffFormat = static_cast<DXGI_FORMAT>(LookupByName(pValue, g_pFormatAliases));
|
|
|
|
if (!diffFormat)
|
|
|
|
{
|
|
|
|
wprintf(L"Invalid value specified with -f (%ls)\n", pValue);
|
|
|
|
return 1;
|
|
|
|
}
|
2016-09-27 07:24:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-09-25 23:04:44 +00:00
|
|
|
case OPT_FILTER:
|
2020-06-01 07:42:02 +00:00
|
|
|
dwFilter = static_cast<TEX_FILTER_FLAGS>(LookupByName(pValue, g_pFilters));
|
2016-09-25 23:04:44 +00:00
|
|
|
if (!dwFilter)
|
|
|
|
{
|
|
|
|
wprintf(L"Invalid value specified with -if (%ls)\n", pValue);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-09-27 07:24:19 +00:00
|
|
|
case OPT_OUTPUTFILE:
|
|
|
|
if (dwCommand != CMD_DIFF)
|
|
|
|
{
|
|
|
|
wprintf(L"-o only valid for use with diff command\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-03-27 23:02:41 +00:00
|
|
|
std::filesystem::path path(pValue);
|
2023-06-13 22:40:45 +00:00
|
|
|
outputFile = path.make_preferred().native();
|
2016-09-27 07:24:19 +00:00
|
|
|
|
2023-06-13 22:40:45 +00:00
|
|
|
fileType = LookupByName(path.extension().c_str(), g_pExtFileTypes);
|
2018-02-09 22:45:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPT_FILETYPE:
|
|
|
|
if (dwCommand != CMD_DUMPDDS)
|
|
|
|
{
|
|
|
|
wprintf(L"-ft only valid for use with dumpdds command\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fileType = LookupByName(pValue, g_pDumpFileTypes);
|
|
|
|
if (!fileType)
|
|
|
|
{
|
|
|
|
wprintf(L"Invalid value specified with -ft (%ls)\n", pValue);
|
|
|
|
wprintf(L"\n");
|
|
|
|
PrintUsage();
|
|
|
|
return 1;
|
|
|
|
}
|
2016-09-27 07:24:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-09-25 23:04:44 +00:00
|
|
|
case OPT_TARGET_PIXELX:
|
2016-09-27 07:24:19 +00:00
|
|
|
if (dwCommand != CMD_DUMPBC)
|
|
|
|
{
|
|
|
|
wprintf(L"-targetx only valid with dumpbc command\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (swscanf_s(pValue, L"%d", &pixelx) != 1)
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
|
|
|
wprintf(L"Invalid value for pixel x location (%ls)\n", pValue);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPT_TARGET_PIXELY:
|
2016-09-27 07:24:19 +00:00
|
|
|
if (dwCommand != CMD_DUMPBC)
|
|
|
|
{
|
|
|
|
wprintf(L"-targety only valid with dumpbc command\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (swscanf_s(pValue, L"%d", &pixely) != 1)
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
|
|
|
wprintf(L"Invalid value for pixel y location (%ls)\n", pValue);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
2017-09-19 18:13:34 +00:00
|
|
|
|
2021-06-10 00:40:17 +00:00
|
|
|
case OPT_DIFF_COLOR:
|
|
|
|
if (swscanf_s(pValue, L"%x", &diffColor) != 1)
|
|
|
|
{
|
|
|
|
printf("Invalid value specified with -c (%ls)\n", pValue);
|
|
|
|
printf("\n");
|
|
|
|
PrintUsage();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
diffColor &= 0xFFFFFF;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPT_THRESHOLD:
|
|
|
|
if (swscanf_s(pValue, L"%f", &threshold) != 1)
|
|
|
|
{
|
|
|
|
printf("Invalid value specified with -t (%ls)\n", pValue);
|
|
|
|
printf("\n");
|
|
|
|
PrintUsage();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2017-09-19 18:13:34 +00:00
|
|
|
case OPT_FILELIST:
|
2019-09-14 00:31:09 +00:00
|
|
|
{
|
2023-03-27 23:02:41 +00:00
|
|
|
std::filesystem::path path(pValue);
|
|
|
|
std::wifstream inFile(path.make_preferred().c_str());
|
2022-04-04 22:03:02 +00:00
|
|
|
if (!inFile)
|
|
|
|
{
|
|
|
|
wprintf(L"Error opening -flist file %ls\n", pValue);
|
|
|
|
return 1;
|
|
|
|
}
|
2019-09-14 00:31:09 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
inFile.imbue(std::locale::classic());
|
2021-10-28 18:12:16 +00:00
|
|
|
|
2022-04-04 22:03:02 +00:00
|
|
|
ProcessFileList(inFile, conversion);
|
|
|
|
}
|
|
|
|
break;
|
2019-07-06 06:48:39 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (wcspbrk(pArg, L"?*") != nullptr)
|
|
|
|
{
|
2022-03-01 22:31:55 +00:00
|
|
|
const size_t count = conversion.size();
|
2023-03-27 23:02:41 +00:00
|
|
|
std::filesystem::path path(pArg);
|
2023-06-13 22:40:45 +00:00
|
|
|
SearchForFiles(path.make_preferred(), conversion, (dwOptions & (1 << OPT_RECURSIVE)) != 0);
|
2016-09-25 23:04:44 +00:00
|
|
|
if (conversion.size() <= count)
|
|
|
|
{
|
|
|
|
wprintf(L"No matching files found for %ls\n", pArg);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-09 20:44:59 +00:00
|
|
|
SConversion conv = {};
|
2023-03-27 23:02:41 +00:00
|
|
|
std::filesystem::path path(pArg);
|
2023-06-13 22:40:45 +00:00
|
|
|
conv.szSrc = path.make_preferred().native();
|
2016-09-25 23:04:44 +00:00
|
|
|
conversion.push_back(conv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conversion.empty())
|
|
|
|
{
|
|
|
|
PrintUsage();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (~dwOptions & (1 << OPT_NOLOGO))
|
2023-03-27 23:02:41 +00:00
|
|
|
PrintLogo(false);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
switch (dwCommand)
|
|
|
|
{
|
|
|
|
case CMD_COMPARE:
|
2016-09-27 07:24:19 +00:00
|
|
|
case CMD_DIFF:
|
|
|
|
// --- Compare/Diff ------------------------------------------------------------
|
2016-09-25 23:04:44 +00:00
|
|
|
if (conversion.size() != 2)
|
|
|
|
{
|
2016-09-27 07:24:19 +00:00
|
|
|
wprintf(L"ERROR: compare/diff needs exactly two images\n");
|
2016-09-25 23:04:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto pImage1 = conversion.cbegin();
|
|
|
|
|
2023-06-13 22:40:45 +00:00
|
|
|
wprintf(L"1: %ls", pImage1->szSrc.c_str());
|
2016-09-25 23:04:44 +00:00
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
TexMetadata info1;
|
|
|
|
std::unique_ptr<ScratchImage> image1;
|
2023-06-13 22:40:45 +00:00
|
|
|
hr = LoadImage(pImage1->szSrc.c_str(), dwOptions, dwFilter, info1, image1);
|
2016-09-25 23:04:44 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-04-01 07:59:57 +00:00
|
|
|
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
2016-09-25 23:04:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pImage2 = conversion.cbegin();
|
|
|
|
std::advance(pImage2, 1);
|
|
|
|
|
2023-06-13 22:40:45 +00:00
|
|
|
wprintf(L"\n2: %ls", pImage2->szSrc.c_str());
|
2016-09-25 23:04:44 +00:00
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
TexMetadata info2;
|
|
|
|
std::unique_ptr<ScratchImage> image2;
|
2023-06-13 22:40:45 +00:00
|
|
|
hr = LoadImage(pImage2->szSrc.c_str(), dwOptions, dwFilter, info2, image2);
|
2016-09-25 23:04:44 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-04-01 07:59:57 +00:00
|
|
|
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
2016-09-25 23:04:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wprintf(L"\n");
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
if (info1.height != info2.height
|
|
|
|
|| info1.width != info2.width)
|
|
|
|
{
|
2016-09-27 07:24:19 +00:00
|
|
|
wprintf(L"ERROR: Can only compare/diff images of the same width & height\n");
|
2016-09-25 23:04:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-09-27 07:24:19 +00:00
|
|
|
if (dwCommand == CMD_DIFF)
|
|
|
|
{
|
2023-06-13 22:40:45 +00:00
|
|
|
if (outputFile.empty())
|
2016-09-27 07:24:19 +00:00
|
|
|
{
|
2023-06-13 22:40:45 +00:00
|
|
|
std::filesystem::path curpath(pImage1->szSrc);
|
|
|
|
auto const ext = curpath.extension();
|
|
|
|
|
|
|
|
if (_wcsicmp(ext.c_str(), L".bmp") == 0)
|
2016-09-27 07:24:19 +00:00
|
|
|
{
|
|
|
|
wprintf(L"ERROR: Need to specify output file via -o\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-06-13 22:40:45 +00:00
|
|
|
outputFile = curpath.stem().concat(L".bmp").native();
|
2016-09-27 07:24:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (image1->GetImageCount() > 1 || image2->GetImageCount() > 1)
|
|
|
|
wprintf(L"WARNING: ignoring all images but first one in each file\n");
|
|
|
|
|
|
|
|
ScratchImage diffImage;
|
2021-06-10 00:40:17 +00:00
|
|
|
hr = Difference(*image1->GetImage(0, 0, 0), *image2->GetImage(0, 0, 0), dwFilter, diffFormat, diffColor, threshold, diffImage);
|
2016-09-27 07:24:19 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-04-01 07:59:57 +00:00
|
|
|
wprintf(L"Failed diffing images (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
2016-09-27 07:24:19 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-04-14 00:22:55 +00:00
|
|
|
if (dwOptions & (1 << OPT_TOLOWER))
|
|
|
|
{
|
2023-06-13 22:40:45 +00:00
|
|
|
std::transform(outputFile.begin(), outputFile.end(), outputFile.begin(), towlower);
|
2020-04-14 00:22:55 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 07:24:19 +00:00
|
|
|
if (~dwOptions & (1 << OPT_OVERWRITE))
|
|
|
|
{
|
2023-06-13 22:40:45 +00:00
|
|
|
if (GetFileAttributesW(outputFile.c_str()) != INVALID_FILE_ATTRIBUTES)
|
2016-09-27 07:24:19 +00:00
|
|
|
{
|
|
|
|
wprintf(L"\nERROR: Output file already exists, use -y to overwrite\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-13 22:40:45 +00:00
|
|
|
hr = SaveImage(diffImage.GetImage(0, 0, 0), outputFile.c_str(), fileType);
|
2016-09-27 07:24:19 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-04-01 07:59:57 +00:00
|
|
|
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
2016-09-27 07:24:19 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-06-13 22:40:45 +00:00
|
|
|
wprintf(L"Difference %ls\n", outputFile.c_str());
|
2016-09-27 07:24:19 +00:00
|
|
|
}
|
|
|
|
else if ((info1.depth == 1
|
2016-09-25 23:04:44 +00:00
|
|
|
&& info1.arraySize == 1
|
|
|
|
&& info1.mipLevels == 1)
|
|
|
|
|| info1.depth != info2.depth
|
|
|
|
|| info1.arraySize != info2.arraySize
|
|
|
|
|| info1.mipLevels != info2.mipLevels
|
|
|
|
|| image1->GetImageCount() != image2->GetImageCount())
|
|
|
|
{
|
|
|
|
// Compare single image
|
|
|
|
if (image1->GetImageCount() > 1 || image2->GetImageCount() > 1)
|
|
|
|
wprintf(L"WARNING: ignoring all images but first one in each file\n");
|
|
|
|
|
|
|
|
float mse, mseV[4];
|
|
|
|
hr = ComputeMSE(*image1->GetImage(0, 0, 0), *image2->GetImage(0, 0, 0), mse, mseV);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-04-01 07:59:57 +00:00
|
|
|
wprintf(L"Failed comparing images (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
2016-09-25 23:04:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wprintf(L"Result: %f (%f %f %f %f) PSNR %f dB\n", mse, mseV[0], mseV[1], mseV[2], mseV[3],
|
2018-03-29 17:17:31 +00:00
|
|
|
10.0 * log10(3.0 / (double(mseV[0]) + double(mseV[1]) + double(mseV[2]))));
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Compare all images
|
|
|
|
float min_mse = FLT_MAX;
|
|
|
|
float min_mseV[4] = { FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX };
|
|
|
|
|
|
|
|
float max_mse = -FLT_MAX;
|
|
|
|
float max_mseV[4] = { -FLT_MAX, -FLT_MAX, -FLT_MAX, -FLT_MAX };
|
|
|
|
|
|
|
|
double sum_mse = 0;
|
|
|
|
double sum_mseV[4] = { 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
size_t total_images = 0;
|
|
|
|
|
|
|
|
if (info1.depth > 1)
|
|
|
|
{
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"Results by mip (%3zu) and slice (%3zu)\n\n", info1.mipLevels, info1.depth);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
size_t depth = info1.depth;
|
|
|
|
for (size_t mip = 0; mip < info1.mipLevels; ++mip)
|
|
|
|
{
|
|
|
|
for (size_t slice = 0; slice < depth; ++slice)
|
|
|
|
{
|
|
|
|
const Image* img1 = image1->GetImage(mip, 0, slice);
|
|
|
|
const Image* img2 = image2->GetImage(mip, 0, slice);
|
|
|
|
|
|
|
|
if (!img1
|
|
|
|
|| !img2
|
|
|
|
|| img1->height != img2->height
|
|
|
|
|| img1->width != img2->width)
|
|
|
|
{
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"ERROR: Unexpected mismatch at slice %3zu, mip %3zu\n", slice, mip);
|
2016-09-25 23:04:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float mse, mseV[4];
|
|
|
|
hr = ComputeMSE(*img1, *img2, mse, mseV);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-04-01 07:59:57 +00:00
|
|
|
wprintf(L"Failed comparing images at slice %3zu, mip %3zu (%08X%ls)\n", slice, mip, static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
2016-09-25 23:04:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
min_mse = std::min(min_mse, mse);
|
|
|
|
max_mse = std::max(max_mse, mse);
|
2019-07-06 06:48:39 +00:00
|
|
|
sum_mse += double(mse);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
for (size_t j = 0; j < 4; ++j)
|
|
|
|
{
|
|
|
|
min_mseV[j] = std::min(min_mseV[j], mseV[j]);
|
|
|
|
max_mseV[j] = std::max(max_mseV[j], mseV[j]);
|
2019-07-06 06:48:39 +00:00
|
|
|
sum_mseV[j] += double(mseV[j]);
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
++total_images;
|
|
|
|
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"[%3zu,%3zu]: %f (%f %f %f %f) PSNR %f dB\n", mip, slice, mse, mseV[0], mseV[1], mseV[2], mseV[3],
|
2018-03-29 17:17:31 +00:00
|
|
|
10.0 * log10(3.0 / (double(mseV[0]) + double(mseV[1]) + double(mseV[2]))));
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (depth > 1)
|
|
|
|
depth >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"Results by item (%3zu) and mip (%3zu)\n\n", info1.arraySize, info1.mipLevels);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
for (size_t item = 0; item < info1.arraySize; ++item)
|
|
|
|
{
|
|
|
|
for (size_t mip = 0; mip < info1.mipLevels; ++mip)
|
|
|
|
{
|
|
|
|
const Image* img1 = image1->GetImage(mip, item, 0);
|
|
|
|
const Image* img2 = image2->GetImage(mip, item, 0);
|
|
|
|
|
|
|
|
if (!img1
|
|
|
|
|| !img2
|
|
|
|
|| img1->height != img2->height
|
|
|
|
|| img1->width != img2->width)
|
|
|
|
{
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"ERROR: Unexpected mismatch at item %3zu, mip %3zu\n", item, mip);
|
2016-09-25 23:04:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float mse, mseV[4];
|
|
|
|
hr = ComputeMSE(*img1, *img2, mse, mseV);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-04-01 07:59:57 +00:00
|
|
|
wprintf(L"Failed comparing images at item %3zu, mip %3zu (%08X%ls)\n", item, mip, static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
2016-09-25 23:04:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
min_mse = std::min(min_mse, mse);
|
|
|
|
max_mse = std::max(max_mse, mse);
|
2019-07-06 06:48:39 +00:00
|
|
|
sum_mse += double(mse);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
for (size_t j = 0; j < 4; ++j)
|
|
|
|
{
|
|
|
|
min_mseV[j] = std::min(min_mseV[j], mseV[j]);
|
|
|
|
max_mseV[j] = std::max(max_mseV[j], mseV[j]);
|
2019-07-06 06:48:39 +00:00
|
|
|
sum_mseV[j] += double(mseV[j]);
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
++total_images;
|
|
|
|
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"[%3zu,%3zu]: %f (%f %f %f %f) PSNR %f dB\n", item, mip, mse, mseV[0], mseV[1], mseV[2], mseV[3],
|
2018-03-29 17:17:31 +00:00
|
|
|
10.0 * log10(3.0 / (double(mseV[0]) + double(mseV[1]) + double(mseV[2]))));
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Output multi-image stats
|
|
|
|
if (total_images > 1)
|
|
|
|
{
|
|
|
|
wprintf(L"\n Minimum MSE: %f (%f %f %f %f) PSNR %f dB\n", min_mse, min_mseV[0], min_mseV[1], min_mseV[2], min_mseV[3],
|
2018-03-29 17:17:31 +00:00
|
|
|
10.0 * log10(3.0 / (double(min_mseV[0]) + double(min_mseV[1]) + double(min_mseV[2]))));
|
2022-03-01 22:31:55 +00:00
|
|
|
const double total_mseV0 = sum_mseV[0] / double(total_images);
|
|
|
|
const double total_mseV1 = sum_mseV[1] / double(total_images);
|
|
|
|
const double total_mseV2 = sum_mseV[2] / double(total_images);
|
2016-09-25 23:04:44 +00:00
|
|
|
wprintf(L" Average MSE: %f (%f %f %f %f) PSNR %f dB\n", sum_mse / double(total_images),
|
|
|
|
total_mseV0,
|
|
|
|
total_mseV1,
|
|
|
|
total_mseV2,
|
|
|
|
sum_mseV[3] / double(total_images),
|
|
|
|
10.0 * log10(3.0 / (total_mseV0 + total_mseV1 + total_mseV2)));
|
|
|
|
wprintf(L" Maximum MSE: %f (%f %f %f %f) PSNR %f dB\n", max_mse, max_mseV[0], max_mseV[1], max_mseV[2], max_mseV[3],
|
2018-03-29 17:17:31 +00:00
|
|
|
10.0 * log10(3.0 / (double(max_mseV[0]) + double(max_mseV[1]) + double(max_mseV[2]))));
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2019-09-14 00:31:09 +00:00
|
|
|
|
2016-09-25 23:04:44 +00:00
|
|
|
default:
|
|
|
|
for (auto pConv = conversion.cbegin(); pConv != conversion.cend(); ++pConv)
|
|
|
|
{
|
2023-06-13 22:40:45 +00:00
|
|
|
std::filesystem::path curpath(pConv->szSrc);
|
|
|
|
|
2016-09-25 23:04:44 +00:00
|
|
|
// Load source image
|
|
|
|
if (pConv != conversion.begin())
|
|
|
|
wprintf(L"\n");
|
|
|
|
|
2023-06-13 22:40:45 +00:00
|
|
|
wprintf(L"%ls", curpath.c_str());
|
2016-09-25 23:04:44 +00:00
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
TexMetadata info;
|
|
|
|
std::unique_ptr<ScratchImage> image;
|
2023-06-13 22:40:45 +00:00
|
|
|
hr = LoadImage(curpath.c_str(), dwOptions, dwFilter, info, image);
|
2016-09-25 23:04:44 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-04-01 07:59:57 +00:00
|
|
|
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
2016-09-25 23:04:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wprintf(L"\n");
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
if (dwCommand == CMD_INFO)
|
|
|
|
{
|
|
|
|
// --- Info ----------------------------------------------------------------
|
2018-05-02 00:34:54 +00:00
|
|
|
wprintf(L" width = %zu\n", info.width);
|
|
|
|
wprintf(L" height = %zu\n", info.height);
|
|
|
|
wprintf(L" depth = %zu\n", info.depth);
|
|
|
|
wprintf(L" mipLevels = %zu\n", info.mipLevels);
|
|
|
|
wprintf(L" arraySize = %zu\n", info.arraySize);
|
2016-09-25 23:04:44 +00:00
|
|
|
wprintf(L" format = ");
|
|
|
|
PrintFormat(info.format);
|
|
|
|
wprintf(L"\n dimension = ");
|
|
|
|
switch (info.dimension)
|
|
|
|
{
|
|
|
|
case TEX_DIMENSION_TEXTURE1D:
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"%ls", (info.arraySize > 1) ? L"1DArray\n" : L"1D\n");
|
2016-09-25 23:04:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TEX_DIMENSION_TEXTURE2D:
|
|
|
|
if (info.IsCubemap())
|
|
|
|
{
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"%ls", (info.arraySize > 6) ? L"CubeArray\n" : L"Cube\n");
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"%ls", (info.arraySize > 1) ? L"2DArray\n" : L"2D\n");
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TEX_DIMENSION_TEXTURE3D:
|
|
|
|
wprintf(L" 3D");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
wprintf(L" alpha mode = ");
|
|
|
|
switch (info.GetAlphaMode())
|
|
|
|
{
|
|
|
|
case TEX_ALPHA_MODE_OPAQUE:
|
|
|
|
wprintf(L"Opaque");
|
|
|
|
break;
|
|
|
|
case TEX_ALPHA_MODE_PREMULTIPLIED:
|
|
|
|
wprintf(L"Premultiplied");
|
|
|
|
break;
|
|
|
|
case TEX_ALPHA_MODE_STRAIGHT:
|
|
|
|
wprintf(L"Straight");
|
|
|
|
break;
|
2019-07-06 06:48:39 +00:00
|
|
|
case TEX_ALPHA_MODE_CUSTOM:
|
|
|
|
wprintf(L"Custom");
|
|
|
|
break;
|
|
|
|
case TEX_ALPHA_MODE_UNKNOWN:
|
2016-09-25 23:04:44 +00:00
|
|
|
wprintf(L"Unknown");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-05-02 00:34:54 +00:00
|
|
|
wprintf(L"\n images = %zu\n", image->GetImageCount());
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2022-03-01 22:31:55 +00:00
|
|
|
auto const sizeInKb = static_cast<uint32_t>(image->GetPixelsSize() / 1024);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
2016-10-02 06:56:42 +00:00
|
|
|
wprintf(L" pixel size = %u (KB)\n\n", sizeInKb);
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
2018-02-09 22:45:34 +00:00
|
|
|
else if (dwCommand == CMD_DUMPDDS)
|
|
|
|
{
|
|
|
|
// --- Dump DDS ------------------------------------------------------------
|
|
|
|
if (IsCompressed(info.format))
|
|
|
|
{
|
|
|
|
wprintf(L"ERROR: dumpdds only operates on non-compressed format DDS files\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-06-13 22:40:45 +00:00
|
|
|
auto const ext = LookupByValue(fileType, g_pDumpFileTypes);
|
2018-02-09 22:45:34 +00:00
|
|
|
|
|
|
|
if (info.depth > 1)
|
|
|
|
{
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"Writing by mip (%3zu) and slice (%3zu)...", info.mipLevels, info.depth);
|
2018-02-09 22:45:34 +00:00
|
|
|
|
|
|
|
size_t depth = info.depth;
|
|
|
|
for (size_t mip = 0; mip < info.mipLevels; ++mip)
|
|
|
|
{
|
|
|
|
for (size_t slice = 0; slice < depth; ++slice)
|
|
|
|
{
|
|
|
|
const Image* img = image->GetImage(mip, 0, slice);
|
|
|
|
|
|
|
|
if (!img)
|
|
|
|
{
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"ERROR: Unexpected error at slice %3zu, mip %3zu\n", slice, mip);
|
2018-02-09 22:45:34 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-13 22:40:45 +00:00
|
|
|
wchar_t subFname[_MAX_PATH] = {};
|
2018-02-09 22:45:34 +00:00
|
|
|
if (info.mipLevels > 1)
|
|
|
|
{
|
2023-06-13 22:40:45 +00:00
|
|
|
swprintf_s(subFname, L"%ls_slice%03zu_mip%03zu", curpath.stem().c_str(), slice, mip);
|
2018-02-09 22:45:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-13 22:40:45 +00:00
|
|
|
swprintf_s(subFname, L"%ls_slice%03zu", curpath.stem().c_str(), slice);
|
2018-02-09 22:45:34 +00:00
|
|
|
}
|
|
|
|
|
2023-06-13 22:40:45 +00:00
|
|
|
outputFile.assign(subFname);
|
|
|
|
outputFile.append(ext);
|
2018-02-09 22:45:34 +00:00
|
|
|
|
2023-06-13 22:40:45 +00:00
|
|
|
hr = SaveImage(img, outputFile.c_str(), fileType);
|
2018-02-09 22:45:34 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-04-01 07:59:57 +00:00
|
|
|
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
2018-02-09 22:45:34 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (depth > 1)
|
|
|
|
depth >>= 1;
|
|
|
|
}
|
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"Writing by item (%3zu) and mip (%3zu)...", info.arraySize, info.mipLevels);
|
2018-02-09 22:45:34 +00:00
|
|
|
|
|
|
|
for (size_t item = 0; item < info.arraySize; ++item)
|
|
|
|
{
|
|
|
|
for (size_t mip = 0; mip < info.mipLevels; ++mip)
|
|
|
|
{
|
|
|
|
const Image* img = image->GetImage(mip, item, 0);
|
|
|
|
|
|
|
|
if (!img)
|
|
|
|
{
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"ERROR: Unexpected error at item %3zu, mip %3zu\n", item, mip);
|
2018-02-09 22:45:34 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-13 22:40:45 +00:00
|
|
|
wchar_t subFname[_MAX_PATH] = {};
|
2018-02-09 22:45:34 +00:00
|
|
|
if (info.mipLevels > 1)
|
|
|
|
{
|
2023-06-13 22:40:45 +00:00
|
|
|
swprintf_s(subFname, L"%ls_item%03zu_mip%03zu", curpath.stem().c_str(), item, mip);
|
2018-02-09 22:45:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-13 22:40:45 +00:00
|
|
|
swprintf_s(subFname, L"%ls_item%03zu", curpath.stem().c_str(), item);
|
2018-02-09 22:45:34 +00:00
|
|
|
}
|
|
|
|
|
2023-06-13 22:40:45 +00:00
|
|
|
outputFile.assign(subFname);
|
|
|
|
outputFile.append(ext);
|
2018-02-09 22:45:34 +00:00
|
|
|
|
2023-06-13 22:40:45 +00:00
|
|
|
hr = SaveImage(img, outputFile.c_str(), fileType);
|
2018-02-09 22:45:34 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-04-01 07:59:57 +00:00
|
|
|
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
2018-02-09 22:45:34 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
}
|
2016-09-25 23:04:44 +00:00
|
|
|
else if (dwCommand == CMD_DUMPBC)
|
|
|
|
{
|
|
|
|
// --- Dump BC -------------------------------------------------------------
|
|
|
|
if (!IsCompressed(info.format))
|
|
|
|
{
|
|
|
|
wprintf(L"ERROR: dumpbc only operates on BC format DDS files\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-07-06 06:48:39 +00:00
|
|
|
if (pixelx >= int(info.width)
|
|
|
|
|| pixely >= int(info.height))
|
2016-09-25 23:04:44 +00:00
|
|
|
{
|
2018-05-02 00:34:54 +00:00
|
|
|
wprintf(L"WARNING: Specified pixel location (%d x %d) is out of range for image (%zu x %zu)\n", pixelx, pixely, info.width, info.height);
|
2016-09-25 23:04:44 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
wprintf(L"Compression: ");
|
|
|
|
PrintFormat(info.format);
|
|
|
|
wprintf(L"\n");
|
|
|
|
|
|
|
|
if (info.depth > 1)
|
|
|
|
{
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"Results by mip (%3zu) and slice (%3zu)\n", info.mipLevels, info.depth);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
size_t depth = info.depth;
|
|
|
|
for (size_t mip = 0; mip < info.mipLevels; ++mip)
|
|
|
|
{
|
|
|
|
for (size_t slice = 0; slice < depth; ++slice)
|
|
|
|
{
|
|
|
|
const Image* img = image->GetImage(mip, 0, slice);
|
|
|
|
|
|
|
|
if (!img)
|
|
|
|
{
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"ERROR: Unexpected error at slice %3zu, mip %3zu\n", slice, mip);
|
2016-09-25 23:04:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"\n[%3zu, %3zu]:\n", mip, slice);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
hr = DumpBCImage(*img, pixelx, pixely);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-04-01 07:59:57 +00:00
|
|
|
wprintf(L"ERROR: Failed dumping image at slice %3zu, mip %3zu (%08X%ls)\n", slice, mip, static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
2016-09-25 23:04:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (depth > 1)
|
|
|
|
depth >>= 1;
|
|
|
|
|
|
|
|
if (pixelx > 0)
|
|
|
|
pixelx >>= 1;
|
|
|
|
|
|
|
|
if (pixely > 0)
|
|
|
|
pixely >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"Results by item (%3zu) and mip (%3zu)\n", info.arraySize, info.mipLevels);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
for (size_t item = 0; item < info.arraySize; ++item)
|
|
|
|
{
|
|
|
|
int tpixelx = pixelx;
|
|
|
|
int tpixely = pixely;
|
|
|
|
|
|
|
|
for (size_t mip = 0; mip < info.mipLevels; ++mip)
|
|
|
|
{
|
|
|
|
const Image* img = image->GetImage(mip, item, 0);
|
|
|
|
|
|
|
|
if (!img)
|
|
|
|
{
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"ERROR: Unexpected error at item %3zu, mip %3zu\n", item, mip);
|
2016-09-25 23:04:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (image->GetImageCount() > 1)
|
|
|
|
{
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"\n[%3zu, %3zu]:\n", item, mip);
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
hr = DumpBCImage(*img, tpixelx, tpixely);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-04-01 07:59:57 +00:00
|
|
|
wprintf(L"ERROR: Failed dumping image at item %3zu, mip %3zu (%08X%ls)\n", item, mip, static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
2016-09-25 23:04:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tpixelx > 0)
|
|
|
|
tpixelx >>= 1;
|
|
|
|
|
|
|
|
if (tpixely > 0)
|
|
|
|
tpixely >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// --- Analyze -------------------------------------------------------------
|
|
|
|
if (IsPlanar(info.format))
|
|
|
|
{
|
|
|
|
auto img = image->GetImage(0, 0, 0);
|
|
|
|
assert(img);
|
2022-03-01 22:31:55 +00:00
|
|
|
const size_t nimg = image->GetImageCount();
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
|
|
|
|
if (!timage)
|
|
|
|
{
|
|
|
|
wprintf(L"\nERROR: Memory allocation failed\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = ConvertToSinglePlane(img, nimg, info, *timage);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-04-01 07:59:57 +00:00
|
|
|
wprintf(L" FAILED [converttosingleplane] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
2021-02-04 00:04:36 +00:00
|
|
|
return 1;
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto& tinfo = timage->GetMetadata();
|
|
|
|
|
|
|
|
info.format = tinfo.format;
|
|
|
|
|
|
|
|
assert(info.width == tinfo.width);
|
|
|
|
assert(info.height == tinfo.height);
|
|
|
|
assert(info.depth == tinfo.depth);
|
|
|
|
assert(info.arraySize == tinfo.arraySize);
|
|
|
|
assert(info.mipLevels == tinfo.mipLevels);
|
|
|
|
assert(info.miscFlags == tinfo.miscFlags);
|
|
|
|
assert(info.dimension == tinfo.dimension);
|
|
|
|
|
|
|
|
image.swap(timage);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info.depth > 1)
|
|
|
|
{
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"Results by mip (%3zu) and slice (%3zu)\n\n", info.mipLevels, info.depth);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
size_t depth = info.depth;
|
|
|
|
for (size_t mip = 0; mip < info.mipLevels; ++mip)
|
|
|
|
{
|
|
|
|
for (size_t slice = 0; slice < depth; ++slice)
|
|
|
|
{
|
|
|
|
const Image* img = image->GetImage(mip, 0, slice);
|
|
|
|
|
|
|
|
if (!img)
|
|
|
|
{
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"ERROR: Unexpected error at slice %3zu, mip %3zu\n", slice, mip);
|
2016-09-25 23:04:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AnalyzeData data;
|
|
|
|
hr = Analyze(*img, data);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-04-01 07:59:57 +00:00
|
|
|
wprintf(L"ERROR: Failed analyzing image at slice %3zu, mip %3zu (%08X%ls)\n", slice, mip, static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
2016-09-25 23:04:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"Result slice %3zu, mip %3zu:\n", slice, mip);
|
2016-09-25 23:04:44 +00:00
|
|
|
data.Print();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsCompressed(info.format))
|
|
|
|
{
|
|
|
|
AnalyzeBCData data;
|
|
|
|
hr = AnalyzeBC(*img, data);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-04-01 07:59:57 +00:00
|
|
|
wprintf(L"ERROR: Failed analyzing BC image at slice %3zu, mip %3zu (%08X%ls)\n", slice, mip, static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
2016-09-25 23:04:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
data.Print(img->format);
|
|
|
|
}
|
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (depth > 1)
|
|
|
|
depth >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"Results by item (%3zu) and mip (%3zu)\n\n", info.arraySize, info.mipLevels);
|
2016-09-25 23:04:44 +00:00
|
|
|
|
|
|
|
for (size_t item = 0; item < info.arraySize; ++item)
|
|
|
|
{
|
|
|
|
for (size_t mip = 0; mip < info.mipLevels; ++mip)
|
|
|
|
{
|
|
|
|
const Image* img = image->GetImage(mip, item, 0);
|
|
|
|
|
|
|
|
if (!img)
|
|
|
|
{
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"ERROR: Unexpected error at item %3zu, mip %3zu\n", item, mip);
|
2016-09-25 23:04:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AnalyzeData data;
|
|
|
|
hr = Analyze(*img, data);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-04-01 07:59:57 +00:00
|
|
|
wprintf(L"ERROR: Failed analyzing image at item %3zu, mip %3zu (%08X%ls)\n", item, mip, static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
2016-09-25 23:04:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (image->GetImageCount() > 1)
|
|
|
|
{
|
2019-11-15 08:13:05 +00:00
|
|
|
wprintf(L"Result item %3zu, mip %3zu:\n", item, mip);
|
2016-09-25 23:04:44 +00:00
|
|
|
}
|
|
|
|
data.Print();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsCompressed(info.format))
|
|
|
|
{
|
|
|
|
AnalyzeBCData data;
|
|
|
|
hr = AnalyzeBC(*img, data);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-04-01 07:59:57 +00:00
|
|
|
wprintf(L"ERROR: Failed analyzing BC image at item %3zu, mip %3zu (%08X%ls)\n", item, mip, static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
2016-09-25 23:04:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
data.Print(img->format);
|
|
|
|
}
|
|
|
|
wprintf(L"\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|