Krita Source Code Documentation
Loading...
Searching...
No Matches
KisMaskingBrushCompositeOpFactory.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2017 Dmitry Kazakov <dimula73@gmail.com>
3 * SPDX-FileCopyrightText: 2021 Deif Lou <ginoba@gmail.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
9
10#include "kis_assert.h"
11
13
15
16#include <KoConfig.h>
17#ifdef HAVE_OPENEXR
18#include <half.h>
19#endif /* HAVE_OPENEXR */
20
21
22namespace {
23
24template <typename channel_type, bool mask_is_alpha = false>
25KisMaskingBrushCompositeOpBase *createTypedOp(const QString &id, int pixelSize, int alphaOffset)
26{
28
29 if (id == COMPOSITE_MULT) {
31 } else if (id == COMPOSITE_DARKEN) {
33 } else if (id == COMPOSITE_OVERLAY) {
35 } else if (id == COMPOSITE_DODGE) {
37 } else if (id == COMPOSITE_BURN) {
39 } else if (id == COMPOSITE_LINEAR_BURN) {
41 } else if (id == COMPOSITE_LINEAR_DODGE) {
43 } else if (id == COMPOSITE_HARD_MIX_PHOTOSHOP) {
45 } else if (id == COMPOSITE_HARD_MIX_SOFTER_PHOTOSHOP) {
47 } else if (id == COMPOSITE_SUBTRACT) {
49 }
50
51 KIS_SAFE_ASSERT_RECOVER (result && "Unknown composite op for masked brush!") {
53 }
54
55 return result;
56}
57
58template <typename channel_type, bool mask_is_alpha = false, bool use_soft_texturing = false>
59KisMaskingBrushCompositeOpBase *createTypedOp(const QString &id, int pixelSize, int alphaOffset, qreal strength)
60{
62
63 if (id == COMPOSITE_MULT) {
65 mask_is_alpha, true, use_soft_texturing>
66 (pixelSize, alphaOffset, strength);
67 } else if (id == COMPOSITE_DARKEN) {
69 mask_is_alpha, true, use_soft_texturing>
70 (pixelSize, alphaOffset, strength);
71 } else if (id == COMPOSITE_OVERLAY) {
73 mask_is_alpha, true, use_soft_texturing>
74 (pixelSize, alphaOffset, strength);
75 } else if (id == COMPOSITE_DODGE) {
77 mask_is_alpha, true, use_soft_texturing>
78 (pixelSize, alphaOffset, strength);
79 } else if (id == COMPOSITE_BURN) {
81 mask_is_alpha, true, use_soft_texturing>
82 (pixelSize, alphaOffset, strength);
83 } else if (id == COMPOSITE_LINEAR_BURN) {
85 mask_is_alpha, true, use_soft_texturing>
86 (pixelSize, alphaOffset, strength);
87 } else if (id == COMPOSITE_LINEAR_DODGE) {
89 mask_is_alpha, true, use_soft_texturing>
90 (pixelSize, alphaOffset, strength);
91 } else if (id == COMPOSITE_HARD_MIX_PHOTOSHOP) {
93 mask_is_alpha, true, use_soft_texturing>
94 (pixelSize, alphaOffset, strength);
95 } else if (id == COMPOSITE_HARD_MIX_SOFTER_PHOTOSHOP) {
97 mask_is_alpha, true, use_soft_texturing>
98 (pixelSize, alphaOffset, strength);
99 } else if (id == COMPOSITE_SUBTRACT) {
101 mask_is_alpha, true, use_soft_texturing>
102 (pixelSize, alphaOffset, strength);
103 // Special modes that useful when used with strength
104 } else if (id == "height") {
106 mask_is_alpha, true, use_soft_texturing>
107 (pixelSize, alphaOffset, strength);
108 } else if (id == "linear_height") {
110 mask_is_alpha, true, use_soft_texturing>
111 (pixelSize, alphaOffset, strength);
112 } else if (id == "height_photoshop") {
114 mask_is_alpha, true, use_soft_texturing>
115 (pixelSize, alphaOffset, strength);
116 } else if (id == "linear_height_photoshop") {
118 mask_is_alpha, true, use_soft_texturing>
119 (pixelSize, alphaOffset, strength);
120 }
121
122 KIS_SAFE_ASSERT_RECOVER (result && "Unknown composite op for masked brush!") {
124 }
125
126 return result;
127}
128
129}
130
131template <bool mask_is_alpha>
132KisMaskingBrushCompositeOpBase *createImpl(const QString &id, KoChannelInfo::enumChannelValueType channelType, int pixelSize, int alphaOffset)
133{
135
136 switch (channelType) {
138 result = createTypedOp<quint8, mask_is_alpha>(id, pixelSize, alphaOffset);
139 break;
141 result = createTypedOp<quint16, mask_is_alpha>(id, pixelSize, alphaOffset);
142 break;
144 result = createTypedOp<quint32, mask_is_alpha>(id, pixelSize, alphaOffset);
145 break;
146
147#ifdef HAVE_OPENEXR
149 result = createTypedOp<half, mask_is_alpha>(id, pixelSize, alphaOffset);
150 break;
151#endif /* HAVE_OPENEXR */
152
154 result = createTypedOp<float, mask_is_alpha>(id, pixelSize, alphaOffset);
155 break;
157 result = createTypedOp<double, mask_is_alpha>(id, pixelSize, alphaOffset);
158 break;
159// NOTE: we have no color space like that, so it is not supported!
160// case KoChannelInfo::INT8:
161// result = createTypedOp<qint8>(id, pixelSize, alphaOffset);
162// break;
164 result = createTypedOp<qint16, mask_is_alpha>(id, pixelSize, alphaOffset);
165 break;
166 default:
167 KIS_SAFE_ASSERT_RECOVER_NOOP(0 && "Unknown channel type for masked brush!");
168 }
169
170 return result;
171}
172
173template <bool mask_is_alpha, bool use_soft_texturing>
174KisMaskingBrushCompositeOpBase *createImpl(const QString &id, KoChannelInfo::enumChannelValueType channelType, int pixelSize, int alphaOffset, qreal strength)
175{
177
178 switch (channelType) {
180 result = createTypedOp<quint8, mask_is_alpha, use_soft_texturing>(id, pixelSize, alphaOffset, strength);
181 break;
183 result = createTypedOp<quint16, mask_is_alpha, use_soft_texturing>(id, pixelSize, alphaOffset, strength);
184 break;
186 result = createTypedOp<quint32, mask_is_alpha, use_soft_texturing>(id, pixelSize, alphaOffset, strength);
187 break;
188
189#ifdef HAVE_OPENEXR
191 result = createTypedOp<half, mask_is_alpha, use_soft_texturing>(id, pixelSize, alphaOffset, strength);
192 break;
193#endif /* HAVE_OPENEXR */
194
196 result = createTypedOp<float, mask_is_alpha, use_soft_texturing>(id, pixelSize, alphaOffset, strength);
197 break;
199 result = createTypedOp<double, mask_is_alpha, use_soft_texturing>(id, pixelSize, alphaOffset, strength);
200 break;
202 result = createTypedOp<qint16, mask_is_alpha, use_soft_texturing>(id, pixelSize, alphaOffset, strength);
203 break;
204 default:
205 KIS_SAFE_ASSERT_RECOVER_NOOP(0 && "Unknown channel type for masked brush!");
206 }
207
208 return result;
209}
210
212 const QString &id, KoChannelInfo::enumChannelValueType channelType,
213 int pixelSize, int alphaOffset)
214{
215 return createImpl<false>(id, channelType, pixelSize, alphaOffset);
216}
217
219 const QString &id, KoChannelInfo::enumChannelValueType channelType,
220 int pixelSize, int alphaOffset, qreal strength, bool useSoftTexturing)
221{
222 if (useSoftTexturing) {
223 return createImpl<false, true>(id, channelType, pixelSize, alphaOffset, strength);
224 } else {
225 return createImpl<false, false>(id, channelType, pixelSize, alphaOffset, strength);
226 }
227}
228
230 const QString &id, KoChannelInfo::enumChannelValueType channelType,
231 int pixelSize, int alphaOffset)
232{
233 return createImpl<true>(id, channelType, pixelSize, alphaOffset);
234}
235
237 const QString &id, KoChannelInfo::enumChannelValueType channelType,
238 int pixelSize, int alphaOffset, qreal strength, bool useSoftTexturing)
239{
240 if (useSoftTexturing) {
241 return createImpl<true, true>(id, channelType, pixelSize, alphaOffset, strength);
242 } else {
243 return createImpl<true, false>(id, channelType, pixelSize, alphaOffset, strength);
244 }
245}
246
KisMaskingBrushCompositeOpBase * createImpl(const QString &id, KoChannelInfo::enumChannelValueType channelType, int pixelSize, int alphaOffset)
@ KIS_MASKING_BRUSH_COMPOSITE_BURN
@ KIS_MASKING_BRUSH_COMPOSITE_LINEAR_HEIGHT_PHOTOSHOP
@ KIS_MASKING_BRUSH_COMPOSITE_SUBTRACT
@ KIS_MASKING_BRUSH_COMPOSITE_HEIGHT
@ KIS_MASKING_BRUSH_COMPOSITE_DODGE
@ KIS_MASKING_BRUSH_COMPOSITE_LINEAR_DODGE
@ KIS_MASKING_BRUSH_COMPOSITE_MULT
@ KIS_MASKING_BRUSH_COMPOSITE_OVERLAY
@ KIS_MASKING_BRUSH_COMPOSITE_HARD_MIX_SOFTER_PHOTOSHOP
@ KIS_MASKING_BRUSH_COMPOSITE_HARD_MIX_PHOTOSHOP
@ KIS_MASKING_BRUSH_COMPOSITE_DARKEN
@ KIS_MASKING_BRUSH_COMPOSITE_HEIGHT_PHOTOSHOP
@ KIS_MASKING_BRUSH_COMPOSITE_LINEAR_HEIGHT
@ KIS_MASKING_BRUSH_COMPOSITE_LINEAR_BURN
const QString COMPOSITE_DARKEN
const QString COMPOSITE_OVERLAY
const QString COMPOSITE_DODGE
const QString COMPOSITE_LINEAR_BURN
const QString COMPOSITE_MULT
const QString COMPOSITE_SUBTRACT
const QString COMPOSITE_BURN
const QString COMPOSITE_LINEAR_DODGE
const QString COMPOSITE_HARD_MIX_SOFTER_PHOTOSHOP
const QString COMPOSITE_HARD_MIX_PHOTOSHOP
static KisMaskingBrushCompositeOpBase * createForAlphaSrc(const QString &id, KoChannelInfo::enumChannelValueType channelType, int pixelSize, int alphaOffset)
static KisMaskingBrushCompositeOpBase * create(const QString &id, KoChannelInfo::enumChannelValueType channelType, int pixelSize, int alphaOffset)
enumChannelValueType
enum to define the value of the channel
@ UINT8
use this for an unsigned integer 8bits channel
@ UINT16
use this for an integer 16bits channel
@ INT16
use this for an integer 16bits channel
@ FLOAT32
use this for a float 32bits channel
@ FLOAT16
use this for a float 16bits channel
@ UINT32
use this for an unsigned integer 21bits channel
@ FLOAT64
use this for a float 64bits channel
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130