SDL: Document the HDR tone mapping algorithm

From 98b1a59a9598b803e15937aa5dcf8c61baabdddc Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 26 Feb 2024 14:16:41 -0800
Subject: [PATCH] Document the HDR tone mapping algorithm

---
 src/video/SDL_blit_slow.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/video/SDL_blit_slow.c b/src/video/SDL_blit_slow.c
index d16be66e118b..9bd59a752af3 100644
--- a/src/video/SDL_blit_slow.c
+++ b/src/video/SDL_blit_slow.c
@@ -699,6 +699,17 @@ static void TonemapLinear(float *r, float *g, float *b, float scale)
     *b *= scale;
 }
 
+/* This uses the same tonemapping algorithm developed by Google for Chrome:
+ * https://colab.research.google.com/drive/1hI10nq6L6ru_UFvz7-f7xQaQp0qarz_K
+ *
+ * Essentially, you use the source headroom and the destination headroom
+ * to calculate scaling factors:
+ *  tonemap_a = (dst_headroom / (src_headroom * src_headroom));
+ *  tonemap_b = (1.0f / dst_headroom);
+ *
+ * Then you normalize your source color by the HDR whitepoint,
+ * and calculate a final scaling factor in BT.2020 colorspace.
+ */
 static void TonemapChrome(float *r, float *g, float *b, float tonemap_a, float tonemap_b)
 {
     float v1 = *r;