|
33 | 33 |
|
34 | 34 | namespace WebCore { |
35 | 35 |
|
36 | | -uint8_t FECompositeSoftwareApplier::clampByte(int c) |
| 36 | +FECompositeSoftwareApplier::FECompositeSoftwareApplier(const FEComposite& effect) |
| 37 | + : Base(effect) |
37 | 38 | { |
38 | | - uint8_t buff[] = { static_cast<uint8_t>(c), 255, 0 }; |
39 | | - unsigned uc = static_cast<unsigned>(c); |
40 | | - return buff[!!(uc & ~0xff) + !!(uc & ~(~0u >> 1))]; |
| 39 | + ASSERT(m_effect.operation() != FECOMPOSITE_OPERATOR_ARITHMETIC); |
41 | 40 | } |
42 | 41 |
|
43 | | -template <int b1, int b4> |
44 | | -inline void FECompositeSoftwareApplier::computeArithmeticPixels(unsigned char* source, unsigned char* destination, int pixelArrayLength, float k1, float k2, float k3, float k4) |
45 | | -{ |
46 | | - float scaledK1; |
47 | | - float scaledK4; |
48 | | - if (b1) |
49 | | - scaledK1 = k1 / 255.0f; |
50 | | - if (b4) |
51 | | - scaledK4 = k4 * 255.0f; |
52 | | - |
53 | | - while (--pixelArrayLength >= 0) { |
54 | | - unsigned char i1 = *source; |
55 | | - unsigned char i2 = *destination; |
56 | | - float result = k2 * i1 + k3 * i2; |
57 | | - if (b1) |
58 | | - result += scaledK1 * i1 * i2; |
59 | | - if (b4) |
60 | | - result += scaledK4; |
61 | | - |
62 | | - *destination = clampByte(result); |
63 | | - ++source; |
64 | | - ++destination; |
65 | | - } |
66 | | -} |
67 | | - |
68 | | -// computeArithmeticPixelsUnclamped is a faster version of computeArithmeticPixels for the common case where clamping |
69 | | -// is not necessary. This enables aggresive compiler optimizations such as auto-vectorization. |
70 | | -template <int b1, int b4> |
71 | | -inline void FECompositeSoftwareApplier::computeArithmeticPixelsUnclamped(unsigned char* source, unsigned char* destination, int pixelArrayLength, float k1, float k2, float k3, float k4) |
72 | | -{ |
73 | | - float scaledK1; |
74 | | - float scaledK4; |
75 | | - if (b1) |
76 | | - scaledK1 = k1 / 255.0f; |
77 | | - if (b4) |
78 | | - scaledK4 = k4 * 255.0f; |
79 | | - |
80 | | - while (--pixelArrayLength >= 0) { |
81 | | - unsigned char i1 = *source; |
82 | | - unsigned char i2 = *destination; |
83 | | - float result = k2 * i1 + k3 * i2; |
84 | | - if (b1) |
85 | | - result += scaledK1 * i1 * i2; |
86 | | - if (b4) |
87 | | - result += scaledK4; |
88 | | - |
89 | | - *destination = result; |
90 | | - ++source; |
91 | | - ++destination; |
92 | | - } |
93 | | -} |
94 | | - |
95 | | -#if !HAVE(ARM_NEON_INTRINSICS) |
96 | | -inline void FECompositeSoftwareApplier::applyPlatformArithmetic(unsigned char* source, unsigned char* destination, int pixelArrayLength, float k1, float k2, float k3, float k4) |
97 | | -{ |
98 | | - float upperLimit = std::max(0.0f, k1) + std::max(0.0f, k2) + std::max(0.0f, k3) + k4; |
99 | | - float lowerLimit = std::min(0.0f, k1) + std::min(0.0f, k2) + std::min(0.0f, k3) + k4; |
100 | | - if ((k4 >= 0.0f && k4 <= 1.0f) && (upperLimit >= 0.0f && upperLimit <= 1.0f) && (lowerLimit >= 0.0f && lowerLimit <= 1.0f)) { |
101 | | - if (k4) { |
102 | | - if (k1) |
103 | | - computeArithmeticPixelsUnclamped<1, 1>(source, destination, pixelArrayLength, k1, k2, k3, k4); |
104 | | - else |
105 | | - computeArithmeticPixelsUnclamped<0, 1>(source, destination, pixelArrayLength, k1, k2, k3, k4); |
106 | | - } else { |
107 | | - if (k1) |
108 | | - computeArithmeticPixelsUnclamped<1, 0>(source, destination, pixelArrayLength, k1, k2, k3, k4); |
109 | | - else |
110 | | - computeArithmeticPixelsUnclamped<0, 0>(source, destination, pixelArrayLength, k1, k2, k3, k4); |
111 | | - } |
112 | | - return; |
113 | | - } |
114 | | - |
115 | | - if (k4) { |
116 | | - if (k1) |
117 | | - computeArithmeticPixels<1, 1>(source, destination, pixelArrayLength, k1, k2, k3, k4); |
118 | | - else |
119 | | - computeArithmeticPixels<0, 1>(source, destination, pixelArrayLength, k1, k2, k3, k4); |
120 | | - } else { |
121 | | - if (k1) |
122 | | - computeArithmeticPixels<1, 0>(source, destination, pixelArrayLength, k1, k2, k3, k4); |
123 | | - else |
124 | | - computeArithmeticPixels<0, 0>(source, destination, pixelArrayLength, k1, k2, k3, k4); |
125 | | - } |
126 | | -} |
127 | | -#endif |
128 | | - |
129 | | -bool FECompositeSoftwareApplier::applyArithmetic(FilterImage& input, FilterImage& input2, FilterImage& result) const |
| 42 | +bool FECompositeSoftwareApplier::apply(const Filter&, const FilterImageVector& inputs, FilterImage& result) const |
130 | 43 | { |
131 | | - auto destinationPixelBuffer = result.pixelBuffer(AlphaPremultiplication::Premultiplied); |
132 | | - if (!destinationPixelBuffer) |
133 | | - return false; |
134 | | - |
135 | | - IntRect effectADrawingRect = result.absoluteImageRectRelativeTo(input); |
136 | | - auto sourcePixelBuffer = input.getPixelBuffer(AlphaPremultiplication::Premultiplied, effectADrawingRect, m_effect.operatingColorSpace()); |
137 | | - if (!sourcePixelBuffer) |
138 | | - return false; |
139 | | - |
140 | | - IntRect effectBDrawingRect = result.absoluteImageRectRelativeTo(input2); |
141 | | - input2.copyPixelBuffer(*destinationPixelBuffer, effectBDrawingRect); |
142 | | - |
143 | | - auto* sourcePixelBytes = sourcePixelBuffer->bytes(); |
144 | | - auto* destinationPixelBytes = destinationPixelBuffer->bytes(); |
145 | | - |
146 | | - auto length = sourcePixelBuffer->sizeInBytes(); |
147 | | - ASSERT(length == destinationPixelBuffer->sizeInBytes()); |
148 | | -#if !HAVE(ARM_NEON_INTRINSICS) |
149 | | - applyPlatformArithmetic(sourcePixelBytes, destinationPixelBytes, length, m_effect.k1(), m_effect.k2(), m_effect.k3(), m_effect.k4()); |
150 | | -#endif |
151 | | - return true; |
152 | | -} |
| 44 | + auto& input = inputs[0].get(); |
| 45 | + auto& input2 = inputs[1].get(); |
153 | 46 |
|
154 | | -bool FECompositeSoftwareApplier::applyNonArithmetic(FilterImage& input, FilterImage& input2, FilterImage& result) const |
155 | | -{ |
156 | 47 | auto resultImage = result.imageBuffer(); |
157 | 48 | if (!resultImage) |
158 | 49 | return false; |
@@ -218,14 +109,4 @@ bool FECompositeSoftwareApplier::applyNonArithmetic(FilterImage& input, FilterIm |
218 | 109 | return true; |
219 | 110 | } |
220 | 111 |
|
221 | | -bool FECompositeSoftwareApplier::apply(const Filter&, const FilterImageVector& inputs, FilterImage& result) const |
222 | | -{ |
223 | | - auto& input = inputs[0].get(); |
224 | | - auto& input2 = inputs[1].get(); |
225 | | - |
226 | | - if (m_effect.operation() == FECOMPOSITE_OPERATOR_ARITHMETIC) |
227 | | - return applyArithmetic(input, input2, result); |
228 | | - return applyNonArithmetic(input, input2, result); |
229 | | -} |
230 | | - |
231 | 112 | } // namespace WebCore |
0 commit comments