From b2c2bfc2aa5ec6c675fd8195d743b034868fffff Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 2 Apr 2020 01:04:40 +0200 Subject: [PATCH] Move HSV color conversion to a separate source file. --- profiler/build/win32/Tracy.vcxproj | 2 ++ profiler/build/win32/Tracy.vcxproj.filters | 6 ++++ server/TracyColor.cpp | 36 ++++++++++++++++++++++ server/TracyColor.hpp | 13 ++++++++ server/TracyView.cpp | 29 +---------------- 5 files changed, 58 insertions(+), 28 deletions(-) create mode 100644 server/TracyColor.cpp create mode 100644 server/TracyColor.hpp diff --git a/profiler/build/win32/Tracy.vcxproj b/profiler/build/win32/Tracy.vcxproj index 1ec36a14..c36b5a3f 100644 --- a/profiler/build/win32/Tracy.vcxproj +++ b/profiler/build/win32/Tracy.vcxproj @@ -112,6 +112,7 @@ + @@ -184,6 +185,7 @@ + diff --git a/profiler/build/win32/Tracy.vcxproj.filters b/profiler/build/win32/Tracy.vcxproj.filters index 5ed71bf3..2cfdeb54 100644 --- a/profiler/build/win32/Tracy.vcxproj.filters +++ b/profiler/build/win32/Tracy.vcxproj.filters @@ -192,6 +192,9 @@ server + + server + @@ -476,6 +479,9 @@ server + + server + diff --git a/server/TracyColor.cpp b/server/TracyColor.cpp new file mode 100644 index 00000000..4e3f2e88 --- /dev/null +++ b/server/TracyColor.cpp @@ -0,0 +1,36 @@ +#include + +#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; +} + +} diff --git a/server/TracyColor.hpp b/server/TracyColor.hpp new file mode 100644 index 00000000..78534be8 --- /dev/null +++ b/server/TracyColor.hpp @@ -0,0 +1,13 @@ +#ifndef __TRACYCOLOR_HPP__ +#define __TRACYCOLOR_HPP__ + +#include + +namespace tracy +{ + +uint32_t GetHsvColor( uint64_t hue, int value ); + +} + +#endif diff --git a/server/TracyView.cpp b/server/TracyView.cpp index d9f5cc10..f562fcae 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -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;