Saturday, February 13, 2016

How does Windows determine the highlight color for running apps in the taskbar?

When you mouse over the taskbar icon of a running program in Windows 7 or 8, a colored shine effect appear behind your mouse. I just answered this Super User question that asked how that color is determined from the icon.

Basically, Windows looks at each non-fully-transparent pixel and sorts it into buckets. A pixel can go into one of 27 buckets depending on the value of each of its channels (red, green, blue). Effectively, the buckets are in a three-dimensional array that is three wide in each direction, so the ranges are split into three chunks. They don't appear to be equal ranges, though: it looks like they're about 0-60, 60-200, and 200-255.

Once all the pixels are put into buckets, some buckets are eliminated, specifically, those where all channels were in the same chunk. That removes black, white, and gray. Windows then looks for which bucket has the highest number of pixels in it, and makes the highlight color something in the middle of the bucket's range.

Other notes:

  • If the program defines no icon at all, it gets a white highlight despite the default icon being greenish or blue
  • There's no rule that says multiple programs can't have the same highlight color
  • Icons with no pixels in any acceptable buckets get a light blue highlight no matter what the system theme color is
  • Ties are broken in a deterministic but not super intuitive way; it's probably just a consequence of the maximum-finding algorithm
Note that all of this might not be exactly right because I, of course, don't have access to the actual code; it was mostly experimental. Science!

No comments:

Post a Comment