From 9976e134ca6b8d491b278abac78e3afd526bb328 Mon Sep 17 00:00:00 2001 From: ge0rdi Date: Sat, 6 Jun 2020 13:01:13 +0200 Subject: [PATCH] Fix 'Invert Metro icon color' option for grayscale icons When `Invert Metro icon color` is enabled `Open-Shell` needs to distinguish full color icons from monochromatic ones. Color icons are displayed normally. Monochromatic ones are displayed inverted (original background becomes transparent and foreground will get Metro accent color). Metro icon is loaded from Metro app resources (usually PNG image) as bitmap with premultiplied alpha channel. This causes monochromatic image to essentially become grayscale (because RGB values are multiplied with alpha channel value). Function `DetectGrayscaleImage` is used to distinguish such images. Unfortunatelly if original image is grayscale (such as new Windows Terminal icon) it is recognized as monochromatic and thus inverted. To prevent this we will take into account also alpha channel in `DetectGrayscaleImage`. In monochromatic images alpha channel value will be the same as the rest of channel values. For color images alpha channel value will be different than other channel values. Fixes #364. --- Src/StartMenu/StartMenuDLL/ItemManager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Src/StartMenu/StartMenuDLL/ItemManager.cpp b/Src/StartMenu/StartMenuDLL/ItemManager.cpp index 456ab75..0ff59c6 100644 --- a/Src/StartMenu/StartMenuDLL/ItemManager.cpp +++ b/Src/StartMenu/StartMenuDLL/ItemManager.cpp @@ -142,10 +142,11 @@ static bool DetectGrayscaleImage( const unsigned int *bits, int stride, int widt for (int x=0;x>24)&255; int r=(pixel>>16)&255; int g=(pixel>>8)&255; int b=(pixel)&255; - if (abs(r-g)>2 || abs(r-b)>2 || abs(g-b)>2) + if (abs(a-r)>2 || abs(r-g)>2 || abs(r-b)>2 || abs(g-b)>2) return false; // found colored pixel if (!(pixel&0xFF000000)) transparent++;