MCPcopy Create free account
hub / github.com/defold/defold / MakeColorFromHash

Function MakeColorFromHash

engine/profiler/src/profiler.cpp:839–866  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

837////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
838
839static inline uint32_t MakeColorFromHash(uint32_t hash)
840{
841 // Borrowed from Remotery.c
842
843 // Hash integer line position to full hue
844 float h = (float)hash / (float)0xFFFFFFFF;
845 float r = dmMath::Clamp(fabsf(fmodf(h * 6 + 0, 6) - 3) - 1, 0.0f, 1.0f);
846 float g = dmMath::Clamp(fabsf(fmodf(h * 6 + 4, 6) - 3) - 1, 0.0f, 1.0f);
847 float b = dmMath::Clamp(fabsf(fmodf(h * 6 + 2, 6) - 3) - 1, 0.0f, 1.0f);
848
849 // Cubic smooth
850 r = r * r * (3 - 2 * r);
851 g = g * g * (3 - 2 * g);
852 b = b * b * (3 - 2 * b);
853
854 // Lerp to HSV lightness a little
855 float k = 0.4;
856 r = r * k + (1 - k);
857 g = g * k + (1 - k);
858 b = b * k + (1 - k);
859
860 uint8_t br = (uint8_t)255*dmMath::Clamp(r, 0.0f, 1.0f);
861 uint8_t bg = (uint8_t)255*dmMath::Clamp(g, 0.0f, 1.0f);
862 uint8_t bb = (uint8_t)255*dmMath::Clamp(b, 0.0f, 1.0f);
863 uint8_t ba = 0xFF;
864
865 return (ba<<24) | (br << 16) | (bg << 8) | (bb << 0);
866}
867
868static void ProcessSample(dmProfileRender::ProfilerThread* thread, int indent, dmProfiler::HSample sample)
869{

Callers 1

ProcessSampleFunction · 0.85

Calls 1

ClampFunction · 0.50

Tested by

no test coverage detected