Changeset View
Changeset View
Standalone View
Standalone View
libs/pigment/compositeops/KoCompositeOpAlphaDarken.h
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 39 | public: | |||
---|---|---|---|---|---|
52 | 52 | | |||
53 | template<bool useMask> | 53 | template<bool useMask> | ||
54 | void genericComposite(const KoCompositeOp::ParameterInfo& params) const | 54 | void genericComposite(const KoCompositeOp::ParameterInfo& params) const | ||
55 | { | 55 | { | ||
56 | using namespace Arithmetic; | 56 | using namespace Arithmetic; | ||
57 | 57 | | |||
58 | qint32 srcInc = (params.srcRowStride == 0) ? 0 : channels_nb; | 58 | qint32 srcInc = (params.srcRowStride == 0) ? 0 : channels_nb; | ||
59 | channels_type flow = scale<channels_type>(params.flow); | 59 | channels_type flow = scale<channels_type>(params.flow); | ||
60 | channels_type opacity = mul(flow, scale<channels_type>(params.opacity)); | 60 | channels_type opacity = scale<channels_type>(params.opacity); | ||
61 | quint8* dstRowStart = params.dstRowStart; | 61 | quint8* dstRowStart = params.dstRowStart; | ||
62 | const quint8* srcRowStart = params.srcRowStart; | 62 | const quint8* srcRowStart = params.srcRowStart; | ||
63 | const quint8* maskRowStart = params.maskRowStart; | 63 | const quint8* maskRowStart = params.maskRowStart; | ||
64 | 64 | | |||
65 | for(quint32 r=params.rows; r>0; --r) { | 65 | for(quint32 r=params.rows; r>0; --r) { | ||
66 | const channels_type* src = reinterpret_cast<const channels_type*>(srcRowStart); | 66 | const channels_type* src = reinterpret_cast<const channels_type*>(srcRowStart); | ||
67 | channels_type* dst = reinterpret_cast<channels_type*>(dstRowStart); | 67 | channels_type* dst = reinterpret_cast<channels_type*>(dstRowStart); | ||
68 | const quint8* mask = maskRowStart; | 68 | const quint8* mask = maskRowStart; | ||
Show All 15 Lines | 83 | else { | |||
84 | for(qint32 i=0; i <channels_nb; i++) { | 84 | for(qint32 i=0; i <channels_nb; i++) { | ||
85 | if(i != alpha_pos) | 85 | if(i != alpha_pos) | ||
86 | dst[i] = src[i]; | 86 | dst[i] = src[i]; | ||
87 | } | 87 | } | ||
88 | } | 88 | } | ||
89 | 89 | | |||
90 | if(alpha_pos != -1) { | 90 | if(alpha_pos != -1) { | ||
91 | channels_type fullFlowAlpha; | 91 | channels_type fullFlowAlpha; | ||
92 | channels_type averageOpacity = mul(flow, scale<channels_type>(*params.lastOpacity)); | 92 | channels_type averageOpacity = scale<channels_type>(*params.lastOpacity); | ||
93 | 93 | | |||
94 | if (averageOpacity > opacity) { | 94 | if (averageOpacity > opacity) { | ||
95 | channels_type reverseBlend = KoColorSpaceMaths<channels_type>::divide(dstAlpha, averageOpacity); | 95 | channels_type reverseBlend = KoColorSpaceMaths<channels_type>::divide(dstAlpha, averageOpacity); | ||
96 | fullFlowAlpha = averageOpacity > dstAlpha ? lerp(srcAlpha, averageOpacity, reverseBlend) : dstAlpha; | 96 | fullFlowAlpha = averageOpacity > dstAlpha ? lerp(srcAlpha, averageOpacity, reverseBlend) : dstAlpha; | ||
97 | } else { | 97 | } else { | ||
98 | fullFlowAlpha = opacity > dstAlpha ? lerp(dstAlpha, opacity, mskAlpha) : dstAlpha; | 98 | fullFlowAlpha = opacity > dstAlpha ? lerp(dstAlpha, opacity, mskAlpha) : dstAlpha; | ||
99 | } | 99 | } | ||
100 | 100 | | |||
101 | if (params.flow == 1.0) { | 101 | if (params.flow == 1.0) { | ||
102 | dstAlpha = fullFlowAlpha; | 102 | dstAlpha = fullFlowAlpha; | ||
103 | } else { | 103 | } else { | ||
104 | channels_type zeroFlowAlpha = unionShapeOpacity(srcAlpha, dstAlpha); | 104 | channels_type zeroFlowAlpha = dstAlpha; | ||
105 | dstAlpha = lerp(zeroFlowAlpha, fullFlowAlpha, flow); | 105 | dstAlpha = lerp(zeroFlowAlpha, fullFlowAlpha, flow); | ||
106 | | ||||
woltherav: please don't add newlines :) | |||||
107 | | ||||
106 | } | 108 | } | ||
107 | 109 | | |||
108 | dst[alpha_pos] = dstAlpha; | 110 | dst[alpha_pos] = dstAlpha; | ||
109 | } | 111 | } | ||
110 | 112 | | |||
111 | src += srcInc; | 113 | src += srcInc; | ||
112 | dst += channels_nb; | 114 | dst += channels_nb; | ||
113 | 115 | | |||
Show All 12 Lines |
please don't add newlines :)