Log the luminance of HDR10 shots and keep their raw pixels, and show an HDR shot as a 2.2 display would.

A shot taken from an HDR10 swapchain (the menu's test hook, NX2NAVI_SHOT_EVERY) now writes the picture's luminance in nits to the log, the darkest pixel, four percentiles and the brightest, and its pixels as the swapchain holds them beside the PNG. The PNG of such a shot shows the HDR display's light at the HUD's white through the power 2.2, not the sRGB curve, so a dark tone the HDR display lifts looks lifted in it too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-11 14:10:31 -05:00
parent 3752b8d157
commit 358ad54105
3 changed files with 73 additions and 8 deletions

View File

@@ -637,7 +637,13 @@ int vk_present_captured(const uint8_t **px, int *w, int *h, VkFormat *fmt) {
return ok;
}
// The captured swapchain image as a PNG (the menu's test hook), RGBA with opaque alpha.
static float g_pic[4]; // gfx_picture_rect
static volatile int32_t g_pic_ok;
// The captured swapchain image as a PNG (the menu's test hook), RGBA with opaque alpha. From an HDR10 swapchain the
// log also gets the luminance in nits of the picture's rectangle (vk_hdr_luminance_stats: the black floor of a dark
// scene, for one), and <path>.pq10 keeps the raw pixels: "PQ10", width, height, 1 when A2R10G10B10 (u32 each), then
// the pixels as the swapchain holds them.
static void save_capture(const char *path) {
size_t n = (size_t)g_cap_w * (size_t)g_cap_h * 4;
uint8_t *px = malloc(n);
@@ -653,15 +659,36 @@ static void save_capture(const char *path) {
rt_write_png(path, px, (uint32_t)g_cap_w, (uint32_t)g_cap_h);
free(px);
rt_log("gfx: menu test shot %s (%dx%d)", path, g_cap_w, g_cap_h);
if (!g_sc_hdr) return;
int a2r = g_sc_fmt == VK_FORMAT_A2R10G10B10_UNORM_PACK32;
int rect[4] = {0, 0, g_cap_w, g_cap_h};
if (__atomic_load_n(&g_pic_ok, __ATOMIC_ACQUIRE)) {
rect[0] = (int)(g_pic[0] * (float)g_cap_w + 0.5f), rect[1] = (int)(g_pic[1] * (float)g_cap_h + 0.5f);
rect[2] = (int)(g_pic[2] * (float)g_cap_w + 0.5f), rect[3] = (int)(g_pic[3] * (float)g_cap_h + 0.5f);
if (rect[2] <= 0 || rect[3] <= 0 || rect[0] + rect[2] > g_cap_w || rect[1] + rect[3] > g_cap_h)
rect[0] = rect[1] = 0, rect[2] = g_cap_w, rect[3] = g_cap_h;
}
float st[7];
vk_hdr_luminance_stats(g_cap_ptr, g_cap_w, rect, a2r, st);
rt_log("gfx: shot %s, HDR10 luminance of the picture (%dx%d at %d,%d) in nits: darkest %.5f, 0.1%% %.5f, 1%% %.5f, "
"median %.3f, 99%% %.1f, brightest %.1f; %.2f%% of pixels under 0.01", path, rect[2], rect[3], rect[0], rect[1],
st[0], st[1], st[2], st[3], st[4], st[5], 100.0f * st[6]);
char raw[1200];
snprintf(raw, sizeof raw, "%s.pq10", path);
FILE *f = fopen(raw, "wb");
if (f) {
uint32_t head[4] = {0x30315150u /* "PQ10" */, (uint32_t)g_cap_w, (uint32_t)g_cap_h, (uint32_t)a2r};
fwrite(head, sizeof head, 1, f);
fwrite(g_cap_ptr, 4, (size_t)g_cap_w * (size_t)g_cap_h, f);
fclose(f);
}
}
// The rectangle {x, y, w, h} of a dw x dh swapchain image the cw x ch picture goes into: the whole image with
// NX2NAVI_ASPECT=stretch, else (fit, the default) the largest one of the picture's own aspect ratio, centred (a 16:9 picture
// on the Steam Deck's 1280x800 screen gets bars of 40 rows above and below; a 16:9 picture in a 21:9 window, bars at the
// sides).
// Where the last present put the picture, as fractions of the swapchain (x, y, w, h): menu_cursor.c's pointer
static float g_pic[4];
static volatile int32_t g_pic_ok;
// Where the last present put the picture, as fractions of the swapchain (x, y, w, h; g_pic): menu_cursor.c's pointer
int gfx_picture_rect(float out[4]) {
if (!__atomic_load_n(&g_pic_ok, __ATOMIC_ACQUIRE)) return 0;
memcpy(out, g_pic, sizeof g_pic);