Search code examples
c#powerpointvsto

PowerPoint ThemeColorScheme derived colors/shades


wrestling with the way VSTO/PowerPoint handles colors, I am looking for a way to get the colors derived from the color scheme (see image, interesting portion framed in red).

I tried TintAndShade and various other transformations in the RGB space, but I can't seem to reproduce what PowerPoint is doing to generate these colors. Has anyone succeeded in getting these colors (programmatically, and independent of the actual color scheme used, of course)?

Colors I'm looking for in red

Any help would be highly appreciated! Thanks in advance, eDude


Solution

  • I found the answer in this article.

    In essence, the transformation is applied in the HSL space (Hue/Saturation/Lightness). The conversion from RGB to HSL is somewhat tedious to implement, but is a straightforward mathematical operation.

    Once the principal ThemeColorScheme colors are converted from RGB to HSL, the following transformation will go from the main color to the different shades:

    L = L*Abs(fraction) + (fraction > 0 ? 1 : 0) * (1-fraction)

    Where fraction is the percent value given in the tool tip. Convert back from HSL to RGB and you have the colors from the picture.

    From my experimenting, then fractions used to build the PowerPoint depend on the L value of the main color. My best guess for the limits are:

    • For colors with L < 0.8, the fractions are 0.2, 0.4, 0.6, -0.75 and -0.5
    • For colors with L >= 0.8, but not 1.0, the fractions are -0.9, -0.75, -0.5, -0.25 and -0.1
    • For white, the fractions are -0.95, -0.85, -0.75, -0.65 and -0.5

    With that, I could programmatically build the whole PowerPoint color palette.