LibreOffice Module basegfx (master) 1
bcolormodifier.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <config_options.h>
26#include <rtl/ustring.hxx>
27
28#include <osl/diagnose.h>
29
30#include <memory>
31#include <vector>
32
33namespace basegfx
34{
62 {
63 private:
66 protected:
67 // no one is allowed to incarnate the abstract base class
68 // except derivations
70
71 public:
72 // no one should directly destroy it; all incarnations should be
73 // handled in a std::shared_ptr of type BColorModifierSharedPtr
74 virtual ~BColorModifier();
75
76 // compare operator
77 virtual bool operator==(const BColorModifier& rCompare) const = 0;
78 bool operator!=(const BColorModifier& rCompare) const
79 {
80 return !(operator==(rCompare));
81 }
82
83 // compute modified color
84 virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const = 0;
85
86 virtual OUString getModifierName() const = 0;
87 };
88
92 {
93 public:
95 {
96 }
97
98 virtual ~BColorModifier_gray() override;
99
100 // compare operator
101 SAL_DLLPRIVATE virtual bool operator==(const BColorModifier& rCompare) const override;
102
103 // compute modified color
104 SAL_DLLPRIVATE virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const override;
105 SAL_DLLPRIVATE virtual OUString getModifierName() const override;
106 };
107
113 {
114 public:
116 {
117 }
118
119 virtual ~BColorModifier_invert() override;
120
121 // compare operator
122 SAL_DLLPRIVATE virtual bool operator==(const BColorModifier& rCompare) const override;
123
124 // compute modified color
125 SAL_DLLPRIVATE virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const override;
126 SAL_DLLPRIVATE virtual OUString getModifierName() const override;
127 };
128
138 {
139 public:
141 {
142 }
143
144 virtual ~BColorModifier_luminance_to_alpha() override;
145
146 // compare operator
147 SAL_DLLPRIVATE virtual bool operator==(const BColorModifier& rCompare) const override;
148
149 // compute modified color
150 SAL_DLLPRIVATE virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const override;
151 SAL_DLLPRIVATE virtual OUString getModifierName() const override;
152 };
153
161 {
162 private:
164
165 public:
166 BColorModifier_replace(const ::basegfx::BColor& rBColor)
167 : maBColor(rBColor)
168 {
169 }
170
171 virtual ~BColorModifier_replace() override;
172
173 // data access
174 const ::basegfx::BColor& getBColor() const { return maBColor; }
175
176 // compare operator
177 SAL_DLLPRIVATE virtual bool operator==(const BColorModifier& rCompare) const override;
178
179 // compute modified color
180 SAL_DLLPRIVATE virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const override;
181 SAL_DLLPRIVATE virtual OUString getModifierName() const override;
182 };
183
192 {
193 private:
195 double mfValue;
196
197 public:
198 BColorModifier_interpolate(const ::basegfx::BColor& rBColor, double fValue)
199 : maBColor(rBColor),
200 mfValue(fValue)
201 {
202 }
203
204 virtual ~BColorModifier_interpolate() override;
205
206 // compare operator
207 SAL_DLLPRIVATE virtual bool operator==(const BColorModifier& rCompare) const override;
208
209 // compute modified color
210 SAL_DLLPRIVATE virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const override;
211 SAL_DLLPRIVATE virtual OUString getModifierName() const override;
212 };
213
222 {
223 private:
225
226 public:
227 BColorModifier_saturate(double fValue);
228
229 virtual ~BColorModifier_saturate() override;
230
231 // compare operator
232 SAL_DLLPRIVATE virtual bool operator==(const BColorModifier& rCompare) const override;
233
234 // compute modified color
235 SAL_DLLPRIVATE virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const override;
236 SAL_DLLPRIVATE virtual OUString getModifierName() const override;
237 };
238
247 {
248 private:
249 std::vector<double> maVector;
250
251 public:
252 BColorModifier_matrix(std::vector<double> aVector)
253 : maVector(aVector)
254 {
255 }
256
257 virtual ~BColorModifier_matrix() override;
258
259 // compare operator
260 SAL_DLLPRIVATE virtual bool operator==(const BColorModifier& rCompare) const override;
261 // compute modified color
262 SAL_DLLPRIVATE virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const override;
263 SAL_DLLPRIVATE virtual OUString getModifierName() const override;
264 };
265
274 {
275 private:
277
278 public:
279 BColorModifier_hueRotate(double fRad);
280
281 virtual ~BColorModifier_hueRotate() override;
282
283 // compare operator
284 SAL_DLLPRIVATE virtual bool operator==(const BColorModifier& rCompare) const override;
285
286 // compute modified color
287 SAL_DLLPRIVATE virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const override;
288 SAL_DLLPRIVATE virtual OUString getModifierName() const override;
289 };
290
297 {
298 private:
299 double mfValue;
300
301 public:
303 : mfValue(fValue)
304 {
305 }
306
307 virtual ~BColorModifier_black_and_white() override;
308
309 // compare operator
310 SAL_DLLPRIVATE virtual bool operator==(const BColorModifier& rCompare) const override;
311
312 // compute modified color
313 SAL_DLLPRIVATE virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const override;
314 SAL_DLLPRIVATE virtual OUString getModifierName() const override;
315 };
316
324 class SAL_WARN_UNUSED UNLESS_MERGELIBS(BASEGFX_DLLPUBLIC) BColorModifier_gamma final : public BColorModifier
325 {
326 private:
327 double mfValue;
328 double mfInvValue;
329
330 bool mbUseIt : 1;
331
332 public:
333 BColorModifier_gamma(double fValue);
334
335 virtual ~BColorModifier_gamma() override;
336
337 // compare operator
338 SAL_DLLPRIVATE virtual bool operator==(const BColorModifier& rCompare) const override;
339
340 // compute modified color
341 virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const override;
342 SAL_DLLPRIVATE virtual OUString getModifierName() const override;
343 };
344
353 class SAL_WARN_UNUSED UNLESS_MERGELIBS(BASEGFX_DLLPUBLIC) BColorModifier_RGBLuminanceContrast final : public BColorModifier
354 {
355 private:
356 double mfRed;
357 double mfGreen;
358 double mfBlue;
359 double mfLuminance;
360 double mfContrast;
361
362 double mfContrastOff;
363 double mfRedOff;
364 double mfGreenOff;
365 double mfBlueOff;
366
367 bool mbUseIt : 1;
368
369 public:
370 BColorModifier_RGBLuminanceContrast(double fRed, double fGreen, double fBlue, double fLuminance, double fContrast);
371
372 virtual ~BColorModifier_RGBLuminanceContrast() override;
373
374 // compare operator
375 SAL_DLLPRIVATE virtual bool operator==(const BColorModifier& rCompare) const override;
376
377 // compute modified color
378 SAL_DLLPRIVATE virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const override;
379 SAL_DLLPRIVATE virtual OUString getModifierName() const override;
380 };
381
385 {
386 private:
387 // [0.0 .. 1.0] where 0.0 is no randomize, 1.0 is all random and in-between
388 // describes the mixed part. Default is 0.1 which means to mix with 10% random color
390
391 public:
392 BColorModifier_randomize(double fRandomPart = 0.1);
393
394 virtual ~BColorModifier_randomize() override;
395
396 // compare operator
397 SAL_DLLPRIVATE virtual bool operator==(const BColorModifier& rCompare) const override;
398
399 // compute modified color
400 SAL_DLLPRIVATE virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const override;
401 SAL_DLLPRIVATE virtual OUString getModifierName() const override;
402 };
403
406 typedef std::shared_ptr< BColorModifier > BColorModifierSharedPtr;
407
416 {
417 ::std::vector< BColorModifierSharedPtr > maBColorModifiers;
418
419 public:
420 sal_uInt32 count() const
421 {
422 return maBColorModifiers.size();
423 }
424
425 const BColorModifierSharedPtr& getBColorModifier(sal_uInt32 nIndex) const
426 {
427 OSL_ENSURE(nIndex < count(), "BColorModifierStack: Access out of range (!)");
428 return maBColorModifiers[nIndex];
429 }
430
431 // get the color in its modified form by applying all existing BColorModifiers,
432 // from back to front (the newest first)
433 ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& rSource) const;
434
436 {
437 maBColorModifiers.push_back(rNew);
438 }
439
440 void pop()
441 {
442 maBColorModifiers.pop_back();
443 }
444 };
445} // end of namespace basegfx
446
447/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define BASEGFX_DLLPUBLIC
Definition: basegfxdllapi.h:35
Class to hold a stack of BColorModifierSharedPtrs and to get the modified color with applying all exi...
const BColorModifierSharedPtr & getBColorModifier(sal_uInt32 nIndex) const
::std::vector< BColorModifierSharedPtr > maBColorModifiers
void push(const BColorModifierSharedPtr &rNew)
convert color to black and white
convert color to gray
Apply hueRotate This derivation is used for the svg importer and does exactly what SVG defines for th...
BColorModifier_interpolate(const ::basegfx::BColor &rBColor, double fValue)
convert to alpha based on luminance
Apply matrix This derivation is used for the svg importer and does exactly what SVG defines for this ...
BColorModifier_matrix(std::vector< double > aVector)
std::vector< double > maVector
BColorModifier_replace(const ::basegfx::BColor &rBColor)
const ::basegfx::BColor & getBColor() const
Apply saturation This derivation is used for the svg importer and does exactly what SVG defines for t...
basegfx::B3DHomMatrix maSatMatrix
base class to define color modifications
bool operator!=(const BColorModifier &rCompare) const
virtual OUString getModifierName() const =0
BColorModifier & operator=(const BColorModifier &)=delete
virtual bool operator==(const BColorModifier &rCompare) const =0
virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor &aSourceColor) const =0
BColorModifier(const BColorModifier &)=delete
Base Color class with three double values.
Definition: bcolor.hxx:41
sal_Int32 nIndex
std::shared_ptr< BColorModifier > BColorModifierSharedPtr
typedef to allow working with shared instances of BColorModifier for the whole mechanism
class UNLESS_MERGELIBS(BASEGFX_DLLPUBLIC) B2DTrapezoid
Gradient definition as used in ODF 1.2.
#define SAL_WARN_UNUSED
bool operator==(const XclFontData &rLeft, const XclFontData &rRight)