21
10
This has intrigued me for quite some time.
Does anyone know the algorithm Windows 7 Aero uses to determine the colour to use as the hot-tracking hover highlight on taskbar buttons for currently-running apps?
It is definitely based on the icon of the app, but I can't see a specific pattern of where it's getting the colour value from.
It doesn't seem to be any of the following:
- An average colour value from the entire icon, otherwise you would get brown
all the timewith multi-coloured icons like Chrome. - The colour used the most in the image, otherwise you'd get yellow for the SQL Server Management Studio icon (6th from left). Also, the Chrome icon used red, green and yellow in equal measure.
- A colour located at certain pixel coordinates within the icon, because Chrome is red - indicating the top of the icon - and Notepad++ (2nd from right) is green - indicating the bottom of the icon.
I asked this question on ux.stackoverflow.com and it got closed as off-topic, but someone answered with the following:
As described by Raymond Chen in this MSDN blog article:
Some people ask how it's done. It's really nothing special. The code just looks for the predominant color in the icon. (And, since visual designers are sticklers for this sort of thing, black, white, and shades of gray are not considered "colors" for the purpose of this calculation.)
However I wasn't really satisfied with that answer because it doesn't explain how the "predominant" colour is calculated. Surely on the SQL Management Studio icon, the predominant colour, to my eyes at least, is yellow. Yet the highlight is green. I want to know, specifically, what the algorithm is.
I'm guessing but, all pixels are in 3-dimensional space (1 value for each color). Divide them in groups/cubes of for example 10x10x10 , so the color RGB(12,56,97) get's in the group/cube (10-20,50-60,90-100). When dividing the pixels over these groups you keep track of which one is the largest. Finally you determine the predominant color by averaging the group with the most pixels. The size of groups is then a trade of in performance/accuracy. – mxt3 – 2014-09-17T10:44:14.220
An average colour value from the entire icon, otherwise you would get brown all the time.
That doesn’t make sense. For example, how would the Skype, command-prompt, or µTorrent icons average out to brown? ಠ_ఠ (The last time I reverse-engineered one of Windows’ color-calculation algorithms, it took several years of on and off attention and a lot of different kinds of work to finally figure it out. It looks like I may end up hacking this one at some point.) – Synetech – 2014-06-02T18:00:50.893@Synetech you're right - I was just thinking about the wide array of icons available and lots of them that contain multiple colours. For example the Chrome icon or the IIS icon contains red, green yellow & blue and green, yellow & blue respectively. I lazily figured these would average out to a murky brown colour, but you're right that it doesn't apply to lots of more-or-less monochrome icons. – theyetiman – 2014-06-03T08:37:18.850
The ONT post has a comment which links to a question about Chrome’s version of this and the linked page explains it by examining the Chrome source-code. The explanation (for that at least) isn’t exactly a simple algorithm.
– Synetech – 2014-06-09T21:39:03.633@Synetech nice find - now we're getting somewhere. This is along the lines of what I was looking for. Now, if only we could get the Win7 source code... ;) – theyetiman – 2014-06-10T09:15:14.057