@Override public Color getColor() { return orig.getColor(); }
@Override public int getAlpha() { return orig.getAlpha(); }
@Override public int getHueMod() { return orig.getHueMod(); }
/** * Convert color transformations in {@link ColorStyle} to a {@link Color} instance * * @see <a href="https://msdn.microsoft.com/en-us/library/dd560821%28v=office.12%29.aspx">Using Office Open XML to Customize Document Formatting in the 2007 Office System</a> * @see <a href="https://social.msdn.microsoft.com/Forums/office/en-US/040e0a1f-dbfe-4ce5-826b-38b4b6f6d3f7/saturation-modulation-satmod">saturation modulation (satMod)</a> * @see <a href="http://stackoverflow.com/questions/6754127/office-open-xml-satmod-results-in-more-than-100-saturation">Office Open XML satMod results in more than 100% saturation</a> */ public static Color applyColorTransform(ColorStyle color){ // TODO: The colors don't match 100% the results of Powerpoint, maybe because we still // operate in sRGB and not scRGB ... work in progress ... if (color == null || color.getColor() == null) { return TRANSPARENT; } Color result = color.getColor(); double alpha = getAlpha(result, color); double[] hsl = RGB2HSL(result); // values are in the range [0..100] (usually ...) applyHslModOff(hsl, 0, color.getHueMod(), color.getHueOff()); applyHslModOff(hsl, 1, color.getSatMod(), color.getSatOff()); applyHslModOff(hsl, 2, color.getLumMod(), color.getLumOff()); applyShade(hsl, color); applyTint(hsl, color); result = HSL2RGB(hsl[0], hsl[1], hsl[2], alpha); return result; }
/** * Apply the shade * * For a shade, the equation is luminance * %tint. */ private static void applyShade(double[] hsl, ColorStyle fc) { int shade = fc.getShade(); if (shade == -1) { return; } double shadePct = shade / 100000.; hsl[2] *= 1. - shadePct; }
/** * Apply the tint * * For a tint, the equation is luminance * %tint + (1-%tint). * (Note that 1-%tint is equal to the lumOff value in DrawingML.) */ private static void applyTint(double[] hsl, ColorStyle fc) { int tint = fc.getTint(); if (tint == -1) { return; } // see 18.8.19 fgColor (Foreground Color) double tintPct = tint / 100000.; hsl[2] = hsl[2]*(1.-tintPct) + (100.-100.*(1.-tintPct)); }
@Override public int getSatOff() { return orig.getSatOff(); }
@Override public int getLumOff() { return orig.getLumOff(); }
@Override public int getLumMod() { return orig.getLumMod(); }
@Override public int getHueOff() { return orig.getHueOff(); }
@Override public int getSatMod() { return orig.getSatMod(); }
/** * Convert color transformations in {@link ColorStyle} to a {@link Color} instance * * @see <a href="https://msdn.microsoft.com/en-us/library/dd560821%28v=office.12%29.aspx">Using Office Open XML to Customize Document Formatting in the 2007 Office System</a> * @see <a href="https://social.msdn.microsoft.com/Forums/office/en-US/040e0a1f-dbfe-4ce5-826b-38b4b6f6d3f7/saturation-modulation-satmod">saturation modulation (satMod)</a> * @see <a href="http://stackoverflow.com/questions/6754127/office-open-xml-satmod-results-in-more-than-100-saturation">Office Open XML satMod results in more than 100% saturation</a> */ public static Color applyColorTransform(ColorStyle color){ // TODO: The colors don't match 100% the results of Powerpoint, maybe because we still // operate in sRGB and not scRGB ... work in progress ... if (color == null || color.getColor() == null) { return TRANSPARENT; } Color result = color.getColor(); double alpha = getAlpha(result, color); double[] hsl = RGB2HSL(result); // values are in the range [0..100] (usually ...) applyHslModOff(hsl, 0, color.getHueMod(), color.getHueOff()); applyHslModOff(hsl, 1, color.getSatMod(), color.getSatOff()); applyHslModOff(hsl, 2, color.getLumMod(), color.getLumOff()); applyShade(hsl, color); applyTint(hsl, color); result = HSL2RGB(hsl[0], hsl[1], hsl[2], alpha); return result; }
@Override public int getShade() { return scale(orig.getShade(), PaintModifier.DARKEN_LESS, PaintModifier.DARKEN); }
@Override public int getTint() { return scale(orig.getTint(), PaintModifier.LIGHTEN_LESS, PaintModifier.LIGHTEN); }
@Override public int getSatOff() { return orig.getSatOff(); }
@Override public int getLumOff() { return orig.getLumOff(); }
@Override public int getLumMod() { return orig.getLumMod(); }
@Override public int getHueOff() { return orig.getHueOff(); }
@Override public int getSatMod() { return orig.getSatMod(); }
private static double getAlpha(Color c, ColorStyle fc) { double alpha = c.getAlpha()/255d; int fcAlpha = fc.getAlpha(); if (fcAlpha != -1) { alpha *= fcAlpha/100000d; } return Math.min(1, Math.max(0, alpha)); }