Move HSV color conversion to a separate source file.

This commit is contained in:
Bartosz Taudul 2020-04-02 01:04:40 +02:00
parent 2303f18d39
commit b2c2bfc2aa
5 changed files with 58 additions and 28 deletions

View File

@ -112,6 +112,7 @@
<ClCompile Include="..\..\..\nfd\nfd_common.c" />
<ClCompile Include="..\..\..\nfd\nfd_win.cpp" />
<ClCompile Include="..\..\..\server\TracyBadVersion.cpp" />
<ClCompile Include="..\..\..\server\TracyColor.cpp" />
<ClCompile Include="..\..\..\server\TracyMemory.cpp" />
<ClCompile Include="..\..\..\server\TracyMmap.cpp" />
<ClCompile Include="..\..\..\server\TracyPrint.cpp" />
@ -184,6 +185,7 @@
<ClInclude Include="..\..\..\server\TracyBadVersion.hpp" />
<ClInclude Include="..\..\..\server\TracyBuzzAnim.hpp" />
<ClInclude Include="..\..\..\server\TracyCharUtil.hpp" />
<ClInclude Include="..\..\..\server\TracyColor.hpp" />
<ClInclude Include="..\..\..\server\TracyDecayValue.hpp" />
<ClInclude Include="..\..\..\server\TracyEvent.hpp" />
<ClInclude Include="..\..\..\server\TracyFileHeader.hpp" />

View File

@ -192,6 +192,9 @@
<ClCompile Include="..\..\..\server\TracySourceView.cpp">
<Filter>server</Filter>
</ClCompile>
<ClCompile Include="..\..\..\server\TracyColor.cpp">
<Filter>server</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\common\tracy_lz4.hpp">
@ -476,6 +479,9 @@
<ClInclude Include="..\..\..\server\TracySourceView.hpp">
<Filter>server</Filter>
</ClInclude>
<ClInclude Include="..\..\..\server\TracyColor.hpp">
<Filter>server</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Natvis Include="DebugVis.natvis" />

36
server/TracyColor.cpp Normal file
View File

@ -0,0 +1,36 @@
#include <algorithm>
#include "TracyColor.hpp"
namespace tracy
{
uint32_t GetHsvColor( uint64_t hue, int value )
{
const uint8_t h = ( hue * 11400714819323198485ull ) & 0xFF;
const uint8_t s = 108;
const uint8_t v = std::max( 96, 170 - value * 8 );
const uint8_t reg = h / 43;
const uint8_t rem = ( h - ( reg * 43 ) ) * 6;
const uint8_t p = ( v * ( 255 - s ) ) >> 8;
const uint8_t q = ( v * ( 255 - ( ( s * rem ) >> 8 ) ) ) >> 8;
const uint8_t t = ( v * ( 255 - ( ( s * ( 255 - rem ) ) >> 8 ) ) ) >> 8;
uint8_t r, g, b;
switch( reg )
{
case 0: r = v; g = t; b = p; break;
case 1: r = q; g = v; b = p; break;
case 2: r = p; g = v; b = t; break;
case 3: r = p; g = q; b = v; break;
case 4: r = t; g = p; b = v; break;
default: r = v; g = p; b = q; break;
}
return 0xFF000000 | ( r << 16 ) | ( g << 8 ) | b;
}
}

13
server/TracyColor.hpp Normal file
View File

@ -0,0 +1,13 @@
#ifndef __TRACYCOLOR_HPP__
#define __TRACYCOLOR_HPP__
#include <stdint.h>
namespace tracy
{
uint32_t GetHsvColor( uint64_t hue, int value );
}
#endif

View File

@ -28,6 +28,7 @@
#include "tracy_pdqsort.h"
#include "TracyBadVersion.hpp"
#include "TracyColor.hpp"
#include "TracyFileRead.hpp"
#include "TracyFileWrite.hpp"
#include "TracyFilesystem.hpp"
@ -14767,34 +14768,6 @@ uint32_t View::GetZoneColor( const ZoneEvent& ev, uint64_t thread, int depth )
}
}
static uint32_t GetHsvColor( uint64_t hue, int value )
{
const uint8_t h = ( hue * 11400714819323198485ull ) & 0xFF;
const uint8_t s = 108;
const uint8_t v = std::max( 96, 170 - value * 8 );
const uint8_t reg = h / 43;
const uint8_t rem = ( h - ( reg * 43 ) ) * 6;
const uint8_t p = ( v * ( 255 - s ) ) >> 8;
const uint8_t q = ( v * ( 255 - ( ( s * rem ) >> 8 ) ) ) >> 8;
const uint8_t t = ( v * ( 255 - ( ( s * ( 255 - rem ) ) >> 8 ) ) ) >> 8;
uint8_t r, g, b;
switch( reg )
{
case 0: r = v; g = t; b = p; break;
case 1: r = q; g = v; b = p; break;
case 2: r = p; g = v; b = t; break;
case 3: r = p; g = q; b = v; break;
case 4: r = t; g = p; b = v; break;
default: r = v; g = p; b = q; break;
}
return 0xFF000000 | ( r << 16 ) | ( g << 8 ) | b;
}
uint32_t View::GetThreadColor( uint64_t thread, int depth )
{
if( m_vd.dynamicColors == 0 ) return 0xFFCC5555;