Note: It behaves in a quite unclear way, when at least one pixel is fully transparent. There are three cases: Case A) None of the pixels is fully transparent.
63 {
64
65
66 qreal totals[_CSTrait::channels_nb];
67
68 qreal totalWeight = 0;
69 qreal totalWeightTransparent = 0;
70
71 memset(totals, 0, sizeof(qreal) * _CSTrait::channels_nb);
72
73 for (; nPixels--; colors++, kernelValues++) {
74 qreal weight = *kernelValues;
76 if (weight != 0) {
77 if (_CSTrait::opacityU8(*colors) == 0) {
78 totalWeightTransparent += weight;
79 } else {
80 for (
uint i = 0; i < _CSTrait::channels_nb; i++) {
81 totals[i] += color[i] * weight;
82 }
83 }
84 totalWeight += weight;
85 }
86 }
87
88 typename _CSTrait::channels_type* dstColor = _CSTrait::nativeArray(dst);
89
90 bool allChannels = channelFlags.isEmpty();
91 Q_ASSERT(allChannels || channelFlags.size() == (int)_CSTrait::channels_nb);
92 if (totalWeightTransparent == 0) {
93
94 for (
uint i = 0; i < _CSTrait::channels_nb; i++) {
95 if (allChannels || channelFlags.testBit(i)) {
99 }
100 }
101 } else if (totalWeightTransparent != totalWeight) {
102 if (totalWeight == factor) {
103
104 qint64 a = (totalWeight - totalWeightTransparent);
105 for (
uint i = 0; i < _CSTrait::channels_nb; i++) {
106 if (allChannels || channelFlags.testBit(i)) {
107 if (i == (
uint)_CSTrait::alpha_pos) {
111 } else {
115 }
116 }
117 }
118 } else {
119
120 qreal a = qreal(totalWeight) / (factor * (totalWeight - totalWeightTransparent));
121 for (
uint i = 0; i < _CSTrait::channels_nb; i++) {
122 if (allChannels || channelFlags.testBit(i)) {
123 if (i == (
uint)_CSTrait::alpha_pos) {
127 } else {
131 }
132 }
133 }
134 }
135 }
136
137 }
_CSTrait::channels_type channels_type
KoColorSpaceMathsTraits< typename_CSTrait::channels_type >::compositetype compositetype