summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2018-08-21 17:47:31 +0200
committerRémi Verschelde <rverschelde@gmail.com>2018-08-21 17:48:31 +0200
commit2969dffbe3dc8cc5fc45f284a935f177f79efab4 (patch)
tree642952237ce1a03ff0aa49fc89b02fa43df3f6e0
parent238b70e2db7e376ce8b627bbba5770535270da30 (diff)
Deprecate incorrect Color::gray()
This average is not a proper approximation of a grayscale value, get_v() is better suited for that. If we want a real to_grayscale() conversion, it's somewhat more involved: https://en.wikipedia.org/wiki/Grayscale Remove the deprecated Gray() from C# bindings as it conflicts with new named color constants.
-rw-r--r--core/color.cpp3
-rw-r--r--core/image.cpp4
-rw-r--r--modules/mono/glue/cs_files/Color.cs5
-rw-r--r--scene/2d/collision_shape_2d.cpp2
4 files changed, 6 insertions, 8 deletions
diff --git a/core/color.cpp b/core/color.cpp
index fcfcf20355..0d8cad1a5e 100644
--- a/core/color.cpp
+++ b/core/color.cpp
@@ -506,8 +506,11 @@ Color Color::from_hsv(float p_h, float p_s, float p_v, float p_a) {
return Color(m + r, m + g, m + b, p_a);
}
+// FIXME: Remove once Godot 3.1 has been released
float Color::gray() const {
+ ERR_EXPLAIN("Color.gray() is deprecated and will be removed in a future version. Use Color.get_v() for a better grayscale approximation.");
+ WARN_DEPRECATED
return (r + g + b) / 3.0;
}
diff --git a/core/image.cpp b/core/image.cpp
index c94f2c3534..2fd7ea5c14 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -2230,10 +2230,10 @@ void Image::set_pixel(int p_x, int p_y, const Color &p_color) {
switch (format) {
case FORMAT_L8: {
- ptr[ofs] = uint8_t(CLAMP(p_color.gray() * 255.0, 0, 255));
+ ptr[ofs] = uint8_t(CLAMP(p_color.get_v() * 255.0, 0, 255));
} break;
case FORMAT_LA8: {
- ptr[ofs * 2 + 0] = uint8_t(CLAMP(p_color.gray() * 255.0, 0, 255));
+ ptr[ofs * 2 + 0] = uint8_t(CLAMP(p_color.get_v() * 255.0, 0, 255));
ptr[ofs * 2 + 1] = uint8_t(CLAMP(p_color.a * 255.0, 0, 255));
} break;
case FORMAT_R8: {
diff --git a/modules/mono/glue/cs_files/Color.cs b/modules/mono/glue/cs_files/Color.cs
index 1195071bd3..49e04b333a 100644
--- a/modules/mono/glue/cs_files/Color.cs
+++ b/modules/mono/glue/cs_files/Color.cs
@@ -258,11 +258,6 @@ namespace Godot
return res;
}
- public float Gray()
- {
- return (r + g + b) / 3.0f;
- }
-
public Color Inverted()
{
return new Color(
diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp
index 83ef4df8f4..ff5f7062c4 100644
--- a/scene/2d/collision_shape_2d.cpp
+++ b/scene/2d/collision_shape_2d.cpp
@@ -119,7 +119,7 @@ void CollisionShape2D::_notification(int p_what) {
Color draw_col = get_tree()->get_debug_collisions_color();
if (disabled) {
- float g = draw_col.gray();
+ float g = draw_col.get_v();
draw_col.r = g;
draw_col.g = g;
draw_col.b = g;