diff options
Diffstat (limited to 'source/blender/blenlib/BLI_color.hh')
-rw-r--r-- | source/blender/blenlib/BLI_color.hh | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_color.hh b/source/blender/blenlib/BLI_color.hh index 37f74edcf4c..265013c0013 100644 --- a/source/blender/blenlib/BLI_color.hh +++ b/source/blender/blenlib/BLI_color.hh @@ -51,6 +51,25 @@ struct Color4f { stream << "(" << c.r << ", " << c.g << ", " << c.b << ", " << c.a << ")"; return stream; } + + friend bool operator==(const Color4f &a, const Color4f &b) + { + return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a; + } + + friend bool operator!=(const Color4f &a, const Color4f &b) + { + return !(a == b); + } + + uint32_t hash() const + { + uint32_t x1 = *(uint32_t *)&r; + uint32_t x2 = *(uint32_t *)&g; + uint32_t x3 = *(uint32_t *)&b; + uint32_t x4 = *(uint32_t *)&a; + return (x1 * 1283591) ^ (x2 * 850177) ^ (x3 * 735391) ^ (x4 * 442319); + } }; struct Color4b { @@ -89,6 +108,22 @@ struct Color4b { stream << "(" << c.r << ", " << c.g << ", " << c.b << ", " << c.a << ")"; return stream; } + + friend bool operator==(const Color4b &a, const Color4b &b) + { + return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a; + } + + friend bool operator!=(const Color4b &a, const Color4b &b) + { + return !(a == b); + } + + uint32_t hash() const + { + return ((uint32_t)r * 1283591) ^ ((uint32_t)g * 850177) ^ ((uint32_t)b * 735391) ^ + ((uint32_t)a * 442319); + } }; } // namespace blender |