Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
74 changes: 68 additions & 6 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;
int g_hslAccentH;
double g_hslAccentS;
double g_oldhslAccentS;
double g_balance1hslAccentS;
double g_balance2hslAccentS;
double g_hslAccentL;
double g_oldhslAccentL;
double g_defaulthslAccentH;
double g_defaulthslAccentS;
double g_defaulthslAccentL;

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

if (accentColorChanges >= 1) {
g_oldhslAccentS = g_hslAccentS;
if (g_oldhslAccentS <= 0.0666) {
g_oldhslAccentS = 0.0666;
}
}
else g_oldhslAccentS = 1;

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)) {
g_hslAccentH = 210.0;
}
else {
g_hslAccentH = rgb2hsl({
(double)GetRValue(dwAccent) / 255,
(double)GetGValue(dwAccent) / 255,
(double)GetBValue(dwAccent) / 255 }).h;
}
/* if (g_hslAccentH < 0.0) {
g_hslAccentH += 360.0;
}

if (g_hslAccentH > 360.0) {
g_hslAccentH -= 360.0;
} */

g_dwAccent = dwAccent;
if ((double)GetRValue(dwAccent) == (double)GetGValue(dwAccent) && (double)GetGValue(dwAccent) == (double)GetBValue(dwAccent)) {
g_hslAccentS = 0.0667;
}
else {
g_hslAccentS = pow(double(rgb2hsl({
(double)GetRValue(dwAccent) / 254.999999999,
(double)GetGValue(dwAccent) / 254.999999999,
(double)GetBValue(dwAccent) / 254.999999999 }).s), double(0.85));
}


g_balance1hslAccentS = g_hslAccentS;
g_balance2hslAccentS = (1 - g_hslAccentS);

g_defaulthslAccentH = 207;
g_defaulthslAccentS = 1;

if (g_hslAccentS < 0.0666) {
g_hslAccentS = 0.0666;
}
if (accentColorChanges >= 1) {
if (g_hslAccentS > 1) {
g_hslAccentS = g_balance1hslAccentS + g_balance2hslAccentS;
}
}

g_hslAccentL = (double(rgb2hsl({
(double)GetRValue(dwAccent) / 254.999999999,
(double)GetGValue(dwAccent) / 254.999999999,
(double)GetBValue(dwAccent) / 254.999999999 }).l) - (double)0.4215686) * 255; // based on default accent color #0078D7 (RGB 0, 120, 215)

return true;
}
}
12 changes: 11 additions & 1 deletion AccentColorizer/AccentColorHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
#include "framework.h"

extern COLORREF g_dwAccent;
extern int g_hsvAccentH;
extern int g_hslAccentH;
extern double g_hslAccentS;
extern double g_oldhslAccentS;
extern double g_balance1hslAccentS;
extern double g_balance2hslAccentS;
extern double g_hslAccentL;
extern double g_oldhslAccentL;
extern double g_defaulthslAccentH;
Comment thread
krlvm marked this conversation as resolved.
Outdated
extern double g_defaulthslAccentS;
extern double g_defaulthslAccentL;
extern int accentColorChanges;

bool UpdateAccentColor();
14 changes: 8 additions & 6 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 @@ -222,6 +222,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 +234,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
64 changes: 34 additions & 30 deletions AccentColorizer/BitmapHelper.cpp
Original file line number Diff line number Diff line change
@@ -1,46 +1,50 @@
#include "BitmapHelper.h"

vector <HBITMAP> hBitmapList;
Comment thread
krlvm marked this conversation as resolved.
Outdated

bool IterateBitmap(HBITMAP hbm, BitmapPixelHandler handler)
{
BITMAP bm;
GetObject(hbm, sizeof(bm), &bm);

if (!hbm || bm.bmBitsPixel != 32)
{
return false;
}
if (count(hBitmapList.begin(), hBitmapList.end(), hbm) < 1) {
Comment thread
krlvm marked this conversation as resolved.
Outdated
hBitmapList.push_back(hbm);
BITMAP bm;
GetObject(hbm, sizeof(bm), &bm);

BYTE* pBits = new BYTE[bm.bmWidth * bm.bmHeight * 4];
GetBitmapBits(hbm, bm.bmWidth * bm.bmHeight * 4, pBits);
if (!hbm || bm.bmBitsPixel != 32)
{
return false;
}

BYTE* pPixel;
int x, y;
int r, g, b, a;
BYTE* pBits = new BYTE[bm.bmWidth * bm.bmHeight * 4];
GetBitmapBits(hbm, bm.bmWidth * bm.bmHeight * 4, pBits);

for (y = 0; y < bm.bmHeight; y++)
{
pPixel = pBits + bm.bmWidth * 4 * y;
BYTE* pPixel;
int x, y;
int r, g, b, a;

for (x = 0; x < bm.bmWidth; x++)
for (y = 0; y < bm.bmHeight; y++)
{
r = pPixel[2] & 0xFFFFFF;
g = pPixel[1] & 0xFFFFFF;
b = pPixel[0] & 0xFFFFFF;
a = pPixel[3] & 0xFFFFFF;
pPixel = pBits + bm.bmWidth * 4 * y;

handler(r, g, b, a);
for (x = 0; x < bm.bmWidth; x++)
{
r = pPixel[2] & 0xFFFFFF;
g = pPixel[1] & 0xFFFFFF;
b = pPixel[0] & 0xFFFFFF;
a = pPixel[3] & 0xFFFFFF;

pPixel[2] = r;
pPixel[1] = g;
pPixel[0] = b;
pPixel[3] = a;
handler(r, g, b, a);

pPixel += 4;
}
}
pPixel[2] = r;
pPixel[1] = g;
pPixel[0] = b;
pPixel[3] = a;

SetBitmapBits(hbm, bm.bmWidth * bm.bmHeight * 4, pBits);
pPixel += 4;
}
}

delete[] pBits;
SetBitmapBits(hbm, bm.bmWidth * bm.bmHeight * 4, pBits);
delete[] pBits;
}
return true;
}
5 changes: 5 additions & 0 deletions AccentColorizer/BitmapHelper.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#pragma once
#include "framework.h"
#include <iostream>
#include <vector>

using namespace std;
extern vector <HBITMAP> hBitmapList;

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

Expand Down
Loading