Files
CoopAllTheThings/tests/srgb_format_test.cpp
BlackMark 30eccf749d Apply clang-format across the whole tree
Run clang-format (the repo's .clang-format: LLVM base, 120 cols, tabs,
Allman functions) over every source file so the tree is formatter-clean.
Whitespace only -- no behavior change; full x64 + x86 suites pass.

Also set SortIncludes: false in .clang-format. Windows include order is
load-bearing (windows.h must precede tlhelp32.h / mmreg.h / xinput.h /
dinput.h; winsock2.h must precede windows.h), and the default
alphabetical sort reorders tlhelp32.h ahead of windows.h -- a build
break. Leaving order alone keeps the manual, correct grouping.
2026-07-12 11:52:53 +02:00

40 lines
1.6 KiB
C++

// Unit test for srgb_to_unorm (host/src/capture/dxgi_format.hpp): the hooked
// video path samples the shared backbuffer copy as plain UNORM so an *_SRGB game
// backbuffer isn't darkened by an sRGB->linear decode the host never re-encodes.
// Locks the format mapping that fix depends on. No device needed.
#include <cstdio>
#include "capture/dxgi_format.hpp"
using namespace coop;
namespace {
int g_failures = 0;
void expect(DXGI_FORMAT in, DXGI_FORMAT want, const char* what)
{
const DXGI_FORMAT got = srgb_to_unorm(in);
if (got != want) {
std::printf(" FAIL: %s (got %d, want %d)\n", what, static_cast<int>(got), static_cast<int>(want));
++g_failures;
}
}
} // namespace
int main()
{
// sRGB formats map to their plain-UNORM sibling.
expect(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UNORM, "R8G8B8A8 sRGB -> UNORM");
expect(DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, DXGI_FORMAT_B8G8R8A8_UNORM, "B8G8R8A8 sRGB -> UNORM");
expect(DXGI_FORMAT_B8G8R8X8_UNORM_SRGB, DXGI_FORMAT_B8G8R8X8_UNORM, "B8G8R8X8 sRGB -> UNORM");
// Non-sRGB formats pass through unchanged.
expect(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, "R8G8B8A8 UNORM passthrough");
expect(DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, "B8G8R8A8 UNORM passthrough");
expect(DXGI_FORMAT_R10G10B10A2_UNORM, DXGI_FORMAT_R10G10B10A2_UNORM, "R10G10B10A2 passthrough");
expect(DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, "RGBA16F passthrough");
std::printf(g_failures == 0 ? "SRGB FORMAT TEST PASS\n" : "SRGB FORMAT TEST FAILED (%d)\n", g_failures);
return g_failures == 0 ? 0 : 1;
}