From 52fec34cab269f1497d25299716d4822d127b4f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pa=CC=84vels=20Nadtoc=CC=8Cajevs?= <7645683+bruvzg@users.noreply.github.com> Date: Fri, 14 Mar 2025 11:51:10 +0200 Subject: [PATCH] Fix `Color` precision error in the documentation generated on M3/M4 macOS. --- thirdparty/misc/ok_color.h | 5 +++++ .../ok_color-0001-srgb_to_okhsl_precision.patch | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 thirdparty/misc/patches/ok_color-0001-srgb_to_okhsl_precision.patch diff --git a/thirdparty/misc/ok_color.h b/thirdparty/misc/ok_color.h index 4d0f0049bdf..2cc7f1ceef6 100644 --- a/thirdparty/misc/ok_color.h +++ b/thirdparty/misc/ok_color.h @@ -541,6 +541,11 @@ static RGB okhsl_to_srgb(HSL hsl) static HSL srgb_to_okhsl(RGB rgb) { + // Fixes some precision errors. + if (rgb.r == 0.0f && rgb.g == 0.0f && rgb.b == 0.0f) { + return { 0.0f, 0.0f, 0.0f }; + } + Lab lab = linear_srgb_to_oklab({ srgb_transfer_function_inv(rgb.r), srgb_transfer_function_inv(rgb.g), diff --git a/thirdparty/misc/patches/ok_color-0001-srgb_to_okhsl_precision.patch b/thirdparty/misc/patches/ok_color-0001-srgb_to_okhsl_precision.patch new file mode 100644 index 00000000000..35996445ddb --- /dev/null +++ b/thirdparty/misc/patches/ok_color-0001-srgb_to_okhsl_precision.patch @@ -0,0 +1,16 @@ +diff --git a/thirdparty/misc/ok_color.h b/thirdparty/misc/ok_color.h +index 4d0f0049bd..2cc7f1ceef 100644 +--- a/thirdparty/misc/ok_color.h ++++ b/thirdparty/misc/ok_color.h +@@ -541,6 +541,11 @@ static RGB okhsl_to_srgb(HSL hsl) + + static HSL srgb_to_okhsl(RGB rgb) + { ++ // Fixes some precision errors. ++ if (rgb.r == 0.0f && rgb.g == 0.0f && rgb.b == 0.0f) { ++ return { 0.0f, 0.0f, 0.0f }; ++ } ++ + Lab lab = linear_srgb_to_oklab({ + srgb_transfer_function_inv(rgb.r), + srgb_transfer_function_inv(rgb.g),