diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-04-13 10:37:22 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-04-13 11:45:52 +0200 |
commit | 46ef52162eee2bdddb44a15fc8bf37aeb1aa3f48 (patch) | |
tree | 10204054589c63e293b415c8e5d7ecc1e85fd47b /core | |
parent | 8904731b8b0a8560c43a8b6680546d8f67f47bb7 (diff) |
Color: Rename `to_srgb`/`to_linear` to include base color space
This helps reduce confusion around sRGB <> Linear conversions by making
both input and output color spaces explicit.
Diffstat (limited to 'core')
-rw-r--r-- | core/io/image.cpp | 2 | ||||
-rw-r--r-- | core/math/color.h | 4 | ||||
-rw-r--r-- | core/variant/variant_call.cpp | 4 |
3 files changed, 5 insertions, 5 deletions
diff --git a/core/io/image.cpp b/core/io/image.cpp index fad9942017..4aed5a913a 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -3276,7 +3276,7 @@ Ref<Image> Image::rgbe_to_srgb() { for (int row = 0; row < height; row++) { for (int col = 0; col < width; col++) { - new_image->set_pixel(col, row, get_pixel(col, row).to_srgb()); + new_image->set_pixel(col, row, get_pixel(col, row).linear_to_srgb()); } } diff --git a/core/math/color.h b/core/math/color.h index b90a0f33a2..91e0bf5532 100644 --- a/core/math/color.h +++ b/core/math/color.h @@ -169,14 +169,14 @@ struct _NO_DISCARD_ Color { return res; } - _FORCE_INLINE_ Color to_linear() const { + _FORCE_INLINE_ Color srgb_to_linear() const { return Color( r < 0.04045f ? r * (1.0 / 12.92) : Math::pow((r + 0.055f) * (float)(1.0 / (1 + 0.055)), 2.4f), g < 0.04045f ? g * (1.0 / 12.92) : Math::pow((g + 0.055f) * (float)(1.0 / (1 + 0.055)), 2.4f), b < 0.04045f ? b * (1.0 / 12.92) : Math::pow((b + 0.055f) * (float)(1.0 / (1 + 0.055)), 2.4f), a); } - _FORCE_INLINE_ Color to_srgb() const { + _FORCE_INLINE_ Color linear_to_srgb() const { return Color( r < 0.0031308f ? 12.92f * r : (1.0f + 0.055f) * Math::pow(r, 1.0f / 2.4f) - 0.055f, g < 0.0031308f ? 12.92f * g : (1.0f + 0.055f) * Math::pow(g, 1.0f / 2.4f) - 0.055f, diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index c11925fa8c..f1daf1de13 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1656,8 +1656,8 @@ static void _register_variant_builtin_methods() { bind_method(Color, darkened, sarray("amount"), varray()); bind_method(Color, blend, sarray("over"), varray()); bind_method(Color, get_luminance, sarray(), varray()); - bind_method(Color, to_linear, sarray(), varray()); - bind_method(Color, to_srgb, sarray(), varray()); + bind_method(Color, srgb_to_linear, sarray(), varray()); + bind_method(Color, linear_to_srgb, sarray(), varray()); bind_method(Color, is_equal_approx, sarray("to"), varray()); |