Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <basegfx/color/bcolormodifier.hxx>
21 :
22 : //////////////////////////////////////////////////////////////////////////////
23 :
24 : namespace basegfx
25 : {
26 0 : ::basegfx::BColor BColorModifier::getModifiedColor(const ::basegfx::BColor& aSourceColor) const
27 : {
28 0 : switch(meMode)
29 : {
30 : case BCOLORMODIFYMODE_INTERPOLATE :
31 : {
32 0 : return interpolate(maBColor, aSourceColor, mfValue);
33 : }
34 : case BCOLORMODIFYMODE_GRAY :
35 : {
36 0 : const double fLuminance(aSourceColor.luminance());
37 0 : return ::basegfx::BColor(fLuminance, fLuminance, fLuminance);
38 : }
39 : case BCOLORMODIFYMODE_BLACKANDWHITE :
40 : {
41 0 : const double fLuminance(aSourceColor.luminance());
42 :
43 0 : if(fLuminance < mfValue)
44 : {
45 0 : return ::basegfx::BColor::getEmptyBColor();
46 : }
47 : else
48 : {
49 0 : return ::basegfx::BColor(1.0, 1.0, 1.0);
50 : }
51 : }
52 : case BCOLORMODIFYMODE_INVERT :
53 : {
54 0 : return ::basegfx::BColor(1.0 - aSourceColor.getRed(), 1.0 - aSourceColor.getGreen(), 1.0 - aSourceColor.getBlue());
55 : }
56 : case BCOLORMODIFYMODE_LUMINANCE_TO_ALPHA:
57 : {
58 0 : const double fAlpha(1.0 - ((aSourceColor.getRed() * 0.2125) + (aSourceColor.getGreen() * 0.7154) + (aSourceColor.getBlue() * 0.0721)));
59 0 : return ::basegfx::BColor(fAlpha, fAlpha, fAlpha);
60 : }
61 : default : // BCOLORMODIFYMODE_REPLACE
62 : {
63 0 : return maBColor;
64 : }
65 : }
66 : }
67 : } // end of namespace basegfx
68 :
69 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|