Krita Source Code Documentation
Loading...
Searching...
No Matches
AlphaDarkenCompositor128< channels_type, ParamsWrapperT, wash > Struct Template Reference

#include <KoOptimizedCompositeOpAlphaDarken128.h>

Classes

struct  Pixel
 

Public Types

using ParamsWrapper = ParamsWrapperT
 

Static Public Member Functions

template<bool haveMask, typename _impl >
static ALWAYS_INLINE void compositeOnePixelScalar (const quint8 *s, quint8 *d, const quint8 *mask, float opacity, const ParamsWrapper &oparams)
 
template<bool haveMask, bool src_aligned, typename _impl >
static ALWAYS_INLINE void compositeVector (const quint8 *src, quint8 *dst, const quint8 *mask, float opacity, const ParamsWrapper &oparams)
 

Detailed Description

template<typename channels_type, typename ParamsWrapperT, bool wash = true>
struct AlphaDarkenCompositor128< channels_type, ParamsWrapperT, wash >

Definition at line 18 of file KoOptimizedCompositeOpAlphaDarken128.h.

Member Typedef Documentation

◆ ParamsWrapper

template<typename channels_type , typename ParamsWrapperT , bool wash = true>
using AlphaDarkenCompositor128< channels_type, ParamsWrapperT, wash >::ParamsWrapper = ParamsWrapperT

Definition at line 19 of file KoOptimizedCompositeOpAlphaDarken128.h.

Member Function Documentation

◆ compositeOnePixelScalar()

template<typename channels_type , typename ParamsWrapperT , bool wash = true>
template<bool haveMask, typename _impl >
static ALWAYS_INLINE void AlphaDarkenCompositor128< channels_type, ParamsWrapperT, wash >::compositeOnePixelScalar ( const quint8 * s,
quint8 * d,
const quint8 * mask,
float opacity,
const ParamsWrapper & oparams )
inlinestatic

Composes one pixel of the source into the destination

Definition at line 155 of file KoOptimizedCompositeOpAlphaDarken128.h.

156 {
157 using namespace Arithmetic;
158 const qint32 alpha_pos = 3;
159
160 const auto *src = reinterpret_cast<const channels_type*>(s);
161 auto *dst = reinterpret_cast<channels_type*>(d);
162
163 float dstAlphaNorm = dst[alpha_pos];
165
166 const float uint8Rec1 = 1.0f / 255.0f;
167 float mskAlphaNorm = haveMask ? float(*mask) * uint8Rec1 * src[alpha_pos] : src[alpha_pos];
169
170 Q_UNUSED(opacity);
171 opacity = oparams.opacity;
172
173 const float srcAlphaNorm = mskAlphaNorm * opacity;
174
175 if (dstAlphaNorm != 0) {
176 dst[0] = PixelWrapper<channels_type, _impl>::lerpMixedUintFloat(dst[0], src[0], srcAlphaNorm);
177 dst[1] = PixelWrapper<channels_type, _impl>::lerpMixedUintFloat(dst[1], src[1], srcAlphaNorm);
178 dst[2] = PixelWrapper<channels_type, _impl>::lerpMixedUintFloat(dst[2], src[2], srcAlphaNorm);
179 } else {
180 if constexpr (wash) {
181 const auto *s = reinterpret_cast<const Pixel*>(src);
182 auto *d = reinterpret_cast<Pixel*>(dst);
183 *d = *s;
184 } else {
185 dst[0] = src[0];
186 dst[1] = src[1];
187 dst[2] = src[2];
188 }
189 }
190
191 if constexpr (wash) {
192 const float flow = oparams.flow;
193 const float averageOpacity = oparams.averageOpacity;
194
195 const float fullFlowAlpha = [&]() {
196 if (averageOpacity > opacity) {
197 return averageOpacity > dstAlphaNorm ? lerp(srcAlphaNorm, averageOpacity, dstAlphaNorm / averageOpacity) : dstAlphaNorm;
198 } else {
199 return opacity > dstAlphaNorm ? lerp(dstAlphaNorm, opacity, mskAlphaNorm) : dstAlphaNorm;
200 }
201 }();
202
203 dstAlphaNorm = [&]() {
204 if (flow == 1.0f) {
205 return fullFlowAlpha;
206 } else {
207 const float zeroFlowAlpha = ParamsWrapper::calculateZeroFlowAlpha(srcAlphaNorm, dstAlphaNorm);
208 return lerp(zeroFlowAlpha, fullFlowAlpha, flow);
209 }
210 }();
211
213 dst[alpha_pos] = PixelWrapper<channels_type, _impl>::roundFloatToUint(dstAlphaNorm);
214 } else {
215 // Clamp paint mode.
216 if (srcAlphaNorm > dstAlphaNorm) {
217 const float flow = oparams.flow;
218
219 dstAlphaNorm = [&](){
220 if (flow == 1.0f) {
221 return srcAlphaNorm;
222 } else {
223 return lerp(dstAlphaNorm, srcAlphaNorm, flow);
224 }
225 }();
226
228 dst[alpha_pos] = PixelWrapper<channels_type, _impl>::roundFloatToUint(dstAlphaNorm);
229 }
230 }
231 }
QPointF lerp(const QPointF &p1, const QPointF &p2, qreal t)

References lerp().

◆ compositeVector()

template<typename channels_type , typename ParamsWrapperT , bool wash = true>
template<bool haveMask, bool src_aligned, typename _impl >
static ALWAYS_INLINE void AlphaDarkenCompositor128< channels_type, ParamsWrapperT, wash >::compositeVector ( const quint8 * src,
quint8 * dst,
const quint8 * mask,
float opacity,
const ParamsWrapper & oparams )
inlinestatic

This is a vector equivalent of compositeOnePixelScalar(). It is considered to process float_v::size pixels in a single pass.

o the haveMask parameter points whether the real (non-null) mask pointer is passed to the function. o the src pointer may be aligned to vector boundary or may be not. In case not, it must be pointed with a special parameter src_aligned. o the dst pointer must always(!) be aligned to the boundary of a streaming vector. Unaligned writes are really expensive.

Definition at line 41 of file KoOptimizedCompositeOpAlphaDarken128.h.

42 {
43 using float_v = typename KoStreamedMath<_impl>::float_v;
44 using float_m = typename float_v::batch_bool_type;
45
46 float_v src_c1;
47 float_v src_c2;
48 float_v src_c3;
49 float_v src_alpha;
50
52 dataWrapper.read(src, src_c1, src_c2, src_c3, src_alpha);
53
54 const float_v msk_norm_alpha = [&](){;
55 if (haveMask) {
56 const float_v uint8Rec1(1.0f / 255.0f);
57 const float_v mask_vec = KoStreamedMath<_impl>::fetch_mask_8(mask);
58 return mask_vec * uint8Rec1 * src_alpha;
59 }
60 else {
61 return src_alpha;
62 }
63 }();
64
65 // we don't use directly passed value
66 Q_UNUSED(opacity);
67
68 // instead we use value calculated by ParamsWrapper
69 opacity = oparams.opacity;
70 const float_v opacity_vec(opacity);
71
72 src_alpha = msk_norm_alpha * opacity_vec;
73
74 const float_v zeroValue(static_cast<float>(KoColorSpaceMathsTraits<channels_type>::zeroValue));
75
76 float_v dst_c1;
77 float_v dst_c2;
78 float_v dst_c3;
79 float_v dst_alpha;
80
81 dataWrapper.read(dst, dst_c1, dst_c2, dst_c3, dst_alpha);
82
83 const float_m empty_dst_pixels_mask = dst_alpha == zeroValue;
84
85 if (!xsimd::all(empty_dst_pixels_mask)) {
86 if (xsimd::none(empty_dst_pixels_mask)) {
87 dst_c1 = (src_c1 - dst_c1) * src_alpha + dst_c1;
88 dst_c2 = (src_c2 - dst_c2) * src_alpha + dst_c2;
89 dst_c3 = (src_c3 - dst_c3) * src_alpha + dst_c3;
90 }
91 else {
92 dst_c1 = xsimd::select(empty_dst_pixels_mask, src_c1, (src_c1 - dst_c1) * src_alpha + dst_c1);
93 dst_c2 = xsimd::select(empty_dst_pixels_mask, src_c2, (src_c2 - dst_c2) * src_alpha + dst_c2);
94 dst_c3 = xsimd::select(empty_dst_pixels_mask, src_c3, (src_c3 - dst_c3) * src_alpha + dst_c3);
95 }
96 }
97 else {
98 dst_c1 = src_c1;
99 dst_c2 = src_c2;
100 dst_c3 = src_c3;
101 }
102
103 if constexpr (wash) {
104 const float_v fullFlowAlpha = [&]() {
105 if (oparams.averageOpacity > opacity) {
106 const float_v average_opacity_vec(oparams.averageOpacity);
107 const float_m fullFlowAlpha_mask = average_opacity_vec > dst_alpha;
108 return xsimd::select(fullFlowAlpha_mask,
109 (average_opacity_vec - src_alpha)
110 * (dst_alpha / average_opacity_vec)
111 + src_alpha,
112 dst_alpha);
113 } else {
114 const float_m fullFlowAlpha_mask = opacity_vec > dst_alpha;
115 return xsimd::select(
116 fullFlowAlpha_mask,
117 (opacity_vec - dst_alpha) * msk_norm_alpha + dst_alpha,
118 dst_alpha);
119 }
120 }();
121
122 dst_alpha = [&]() {
123 if (oparams.flow == 1.0) {
124 return fullFlowAlpha;
125 }
126 else {
127 const float_v zeroFlowAlpha = ParamsWrapper::calculateZeroFlowAlpha(src_alpha, dst_alpha);
128 const float_v flow_norm_vec(oparams.flow);
129 return (fullFlowAlpha - zeroFlowAlpha) * flow_norm_vec + zeroFlowAlpha;
130 }
131 }();
132 } else {
133 // Clamp paint mode.
134 const float_m fullFlowAlpha_mask = src_alpha > dst_alpha;
135 if (!xsimd::none(fullFlowAlpha_mask)) {
136 dst_alpha = [&]() {
137 if (oparams.flow == 1.0f) {
138 return xsimd::select(fullFlowAlpha_mask, src_alpha, dst_alpha);
139 } else {
140 const float_v flow_norm_vec(oparams.flow);
141 const float_v lerped = (src_alpha - dst_alpha) * flow_norm_vec + dst_alpha;
142 return xsimd::select(fullFlowAlpha_mask, lerped, dst_alpha);
143 }
144 }();
145 }
146 }
147
148 dataWrapper.write(dst, dst_c1, dst_c2, dst_c3, dst_alpha);
149 }
xsimd::batch< float, _impl > float_v
static float_v fetch_mask_8(const quint8 *data)

References KoStreamedMath< _impl >::fetch_mask_8().


The documentation for this struct was generated from the following file: