Skip to content

Commit

Permalink
Cache result of rgb2hsv
Browse files Browse the repository at this point in the history
  • Loading branch information
krlvm committed Jun 6, 2022
1 parent d8c0c1f commit 930d619
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
4 changes: 2 additions & 2 deletions AccentColorizer/AccentColorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ HANDLE hHandle;

void ApplyAccentColorization() {
UpdateAccentColors();
ModifySysColors();
ModifyStyles();
ModifyStyles(accent);
if (accentOpaqueAvailable) ModifySysColors(accentOpaque);
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Expand Down
30 changes: 18 additions & 12 deletions AccentColorizer/StyleModifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@
#include "AccentColorHelper.h"
#include <VersionHelpers.h>

void StandardBitmapHandler(int* r, int* g, int* b, int* a) {
rgb rgbOriginal = { *r, *g, *b };
rgb rgbAccent = { GetRValue(accent), GetGValue(accent), GetBValue(accent) };
int hsvAccentH;

hsv hsvOriginal = rgb2hsv(rgbOriginal);
hsv hsvAccent = rgb2hsv(rgbAccent);
void StandardBitmapHandler(int* r, int* g, int* b, int* a) {
rgb rgbVal = { *r, *g, *b };
hsv hsvVal = rgb2hsv(rgbVal);

hsvOriginal.h = hsvAccent.h;
hsvVal.h = hsvAccentH;

rgb rgbNew = hsv2rgb(hsvOriginal);
rgbVal = hsv2rgb(hsvVal);

*r = rgbNew.r;
*g = rgbNew.g;
*b = rgbNew.b;
*r = rgbVal.r;
*g = rgbVal.g;
*b = rgbVal.b;
}

bool ModifyStyle(LPCWSTR pszClassList, int iPartId, int iStateId, int iPropId)
Expand All @@ -37,8 +36,6 @@ void ModifyStyles() {
ModifyStyle(VSCLASS_BUTTON, BP_PUSHBUTTON, 0, TMT_DIBDATA);
for (j = 1; j <= 7; j++) {
ModifyStyle(VSCLASS_BUTTON, BP_CHECKBOX, 0, j);
}
for (j = 1; j <= 7; j++) {
ModifyStyle(VSCLASS_BUTTON, BP_RADIOBUTTON, 0, j);
}
for (j = 1; j <= 3; j++) {
Expand Down Expand Up @@ -203,3 +200,12 @@ void ModifyStyles() {
ModifyStyle(L"Menu", 7, 0, TMT_DIBDATA);
}
}

void ModifyStyles(COLORREF accentColor)
{
rgb rgbAccent = { GetRValue(accentColor), GetGValue(accentColor), GetBValue(accentColor) };
hsv hsvAccent = rgb2hsv(rgbAccent);
hsvAccentH = hsvAccent.h;

ModifyStyles();
}
2 changes: 1 addition & 1 deletion AccentColorizer/StyleModifier.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#include "framework.h"

void ModifyStyles();
void ModifyStyles(COLORREF accentColor);
9 changes: 2 additions & 7 deletions AccentColorizer/SysColorsModifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@

const int size = 5;

void ModifySysColors() {
if (!accentOpaqueAvailable)
{
return;
}

void ModifySysColors(COLORREF accentColor) {
int aElements[size] =
{
COLOR_ACTIVECAPTION,
Expand All @@ -20,7 +15,7 @@ void ModifySysColors() {
};
DWORD aNewColors[size];

COLORREF color = RGB(GetRValue(accentOpaque), GetGValue(accentOpaque), GetBValue(accentOpaque));
COLORREF color = RGB(GetRValue(accentColor), GetGValue(accentColor), GetBValue(accentColor));
for (int i = 0; i < size; i++)
{
aNewColors[i] = color;
Expand Down
2 changes: 1 addition & 1 deletion AccentColorizer/SysColorsModifier.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#include "framework.h"

void ModifySysColors();
void ModifySysColors(COLORREF accentColor);

0 comments on commit 930d619

Please sign in to comment.