Skip to content
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 112 additions & 7 deletions AccentColorizer/AccentColorHelper.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
#include "AccentColorHelper.h"
#include "ColorHelper.h"
#include <cmath>

COLORREF g_dwAccent;
int g_hsvAccentH;
COLORREF g_dwAccent{};
hsl_t g_hslAccent{};
hsl_t g_hslDefaultAccent{};
double g_oldhslAccentS{};
double g_balance1hslAccentS{};
double g_balance2hslAccentS{};
double g_oldhslAccentL{};
int g_hslLightAccentH{};
int g_hslDarkAccentH{};
double g_hslEnhancedAccentL{};
double g_oldhslEnhancedAccentL{};

bool UpdateAccentColor()
{
Expand All @@ -18,11 +28,106 @@ bool UpdateAccentColor()
return false;
}

if (accentColorChanges >= 2) {
g_oldhslAccentS = g_hslAccent.s;
if (g_oldhslAccentS <= 0.08) {
g_oldhslAccentS = 0.08;
}
}
else g_oldhslAccentS = 1;

if (accentColorChanges >= 2) {
g_oldhslAccentL = g_hslAccent.l;
}
else g_oldhslAccentL = 0;

g_dwAccent = dwAccent;
if ((double)GetRValue(dwAccent) == (double)GetGValue(dwAccent) && (double)GetGValue(dwAccent) == (double)GetBValue(dwAccent)) {
g_hslAccent.h = 210.0;
}
else {
g_hslAccent.h = rgb2hsl({
(double)GetRValue(dwAccent) / 255,
(double)GetGValue(dwAccent) / 255,
(double)GetBValue(dwAccent) / 255 }).h;
}
if (g_hslAccent.h >= 0 && g_hslAccent.h < 125) {
g_hslLightAccentH = 60;
}
else if (g_hslAccent.h >= 125 && g_hslAccent.h < 150) {
g_hslLightAccentH = 120;
}
else if (g_hslAccent.h >= 150 && g_hslAccent.h < 240) {
g_hslLightAccentH = 180;
}
else if (g_hslAccent.h >= 240 && g_hslAccent.h < 345) {
g_hslLightAccentH = 300;
}
else if (g_hslAccent.h >= 345 && g_hslAccent.h < 360) {
g_hslLightAccentH = 420;
}
if (g_hslAccent.h >= 0 && g_hslAccent.h < 60) {
g_hslDarkAccentH = 0;
}
else if (g_hslAccent.h >= 60 && g_hslAccent.h < 180) {
g_hslDarkAccentH = 120;
}
else if (g_hslAccent.h >= 180 && g_hslAccent.h < 300) {
g_hslDarkAccentH = 240;
}
else if (g_hslAccent.h >= 300 && g_hslAccent.h < 360) {
g_hslDarkAccentH = 360;
}

g_dwAccent = dwAccent;
g_hsvAccentH = rgb2hsv({
(double) GetRValue(dwAccent) / 255,
(double) GetGValue(dwAccent) / 255,
(double) GetBValue(dwAccent) / 255 }).h;
if ((double)GetRValue(dwAccent) == (double)GetGValue(dwAccent) && (double)GetGValue(dwAccent) == (double)GetBValue(dwAccent)) {
if (accentColorChanges == 1) {
g_hslAccent.s = 0.5;
}
else g_hslAccent.s = 0.0801;
}
else {
g_hslAccent.s = pow(double(rgb2hsl({
(double)GetRValue(dwAccent) / 254.999999999,
(double)GetGValue(dwAccent) / 254.999999999,
(double)GetBValue(dwAccent) / 254.999999999 }).s), double(0.95));
}


g_balance1hslAccentS = g_hslAccent.s;
g_balance2hslAccentS = (1 - g_hslAccent.s);

g_hslDefaultAccent.h = 206.532;
g_hslDefaultAccent.s = 1;
g_hslDefaultAccent.l = (double)(rgb2hsl({
(double)0 / 255,
(double)120 / 255,
(double)215 / 255 }).l);

if (g_hslAccent.s < 0.08) {
g_hslAccent.s = 0.08;
}
if (accentColorChanges >= 2) {
if (g_hslAccent.s > 1) {
g_hslAccent.s = g_balance1hslAccentS + g_balance2hslAccentS;
}
}

if ((double)GetRValue(dwAccent) == (double)GetGValue(dwAccent) && (double)GetGValue(dwAccent) == (double)GetBValue(dwAccent)){
if (accentColorChanges == 1) {
g_hslAccent.l = 0.0;
}
}
else {
g_hslAccent.l = ((double)(rgb2hsl({
(double)GetRValue(dwAccent) / 255,
(double)GetGValue(dwAccent) / 255,
(double)GetBValue(dwAccent) / 255 }).l) - (double)(rgb2hsl({
(double)0 / 255,
(double)110 / 255,
(double)199 / 255 }).l)) * -255.0; // based on default accent color #0078D7 (RGB 0, 120, 215), which is slightly darkened for DWM.
}
g_oldhslEnhancedAccentL = (g_hslDefaultAccent.l * 255) - (g_oldhslAccentL);

return true;
}
}
13 changes: 12 additions & 1 deletion AccentColorizer/AccentColorHelper.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
#pragma once
#include "framework.h"
#include "ColorHelper.h"

extern COLORREF g_dwAccent;
extern int g_hsvAccentH;
extern hsl_t g_hslAccent;
extern hsl_t g_hslDefaultAccent;
extern double g_oldhslAccentS;
extern double g_balance1hslAccentS;
extern double g_balance2hslAccentS;
extern double g_oldhslAccentL;
extern int g_hslLightAccentH;
extern int g_hslDarkAccentH;
extern double g_hslEnhancedAccentL;
extern double g_oldhslEnhancedAccentL;
extern int accentColorChanges;

bool UpdateAccentColor();
23 changes: 14 additions & 9 deletions AccentColorizer/AccentColorizer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,40 +38,40 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Static|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Static|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down Expand Up @@ -101,25 +101,31 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<TargetName>$(ProjectName)-$(PlatformTarget)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<TargetName>$(ProjectName)-$(PlatformTarget)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Static|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)Release\</OutDir>
<IntDir>Release\</IntDir>
<TargetName>$(ProjectName)-$(PlatformTarget)-Static</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<TargetName>$(ProjectName)-$(PlatformTarget)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<TargetName>$(ProjectName)-$(PlatformTarget)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Static|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)$(Platform)\Release\</OutDir>
<IntDir>$(Platform)\Release\</IntDir>
<TargetName>$(ProjectName)-$(PlatformTarget)-Static</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down Expand Up @@ -165,7 +171,6 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<OutputFile>$(OutDir)$(TargetName)-Static$(TargetExt)</OutputFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand Down Expand Up @@ -195,7 +200,6 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<OutputFile>$(OutDir)$(TargetName)-x64$(TargetExt)</OutputFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Static|x64'">
Expand All @@ -213,7 +217,6 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<OutputFile>$(OutDir)$(TargetName)-Static-x64$(TargetExt)</OutputFile>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand All @@ -222,6 +225,7 @@
<ClInclude Include="ColorHelper.h" />
<ClInclude Include="SettingsHelper.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="StyleColorHelper.h" />
<ClInclude Include="StyleModifier.h" />
<ClInclude Include="SysColorsModifier.h" />
<ClInclude Include="framework.h" />
Expand All @@ -233,6 +237,7 @@
<ClCompile Include="BitmapHelper.cpp" />
<ClCompile Include="ColorHelper.cpp" />
<ClCompile Include="SettingsHelper.cpp" />
<ClCompile Include="StyleColorHelper.cpp" />
<ClCompile Include="StyleModifier.cpp" />
<ClCompile Include="SysColorsModifier.cpp" />
<ClCompile Include="SystemHelper.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions AccentColorizer/AccentColorizer.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<ClCompile Include="SystemHelper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="StyleColorHelper.cpp">
<Filter>Header Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="AccentColorHelper.h">
Expand Down Expand Up @@ -54,6 +57,9 @@
<ClInclude Include="SystemHelper.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="StyleColorHelper.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Source Files">
Expand Down
2 changes: 1 addition & 1 deletion AccentColorizer/BitmapHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bool IterateBitmap(HBITMAP hbm, BitmapPixelHandler handler)
}

SetBitmapBits(hbm, bm.bmWidth * bm.bmHeight * 4, pBits);

delete[] pBits;

return true;
}
3 changes: 3 additions & 0 deletions AccentColorizer/BitmapHelper.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma once
#include "framework.h"
#include <set>

extern std::set<HBITMAP> handledBitmaps;

typedef void (*BitmapPixelHandler)(int& r, int& g, int& b, int& a);

Expand Down
Loading