Changeset View
Changeset View
Standalone View
Standalone View
libs/image/kis_brush_mask_applicator_factories.cpp
Context not available. | |||||
17 | */ | 17 | */ | ||
---|---|---|---|---|---|
18 | 18 | | |||
19 | #include "kis_brush_mask_applicator_factories.h" | 19 | #include "kis_brush_mask_applicator_factories.h" | ||
20 | #include "vc_extra_math.h" | ||||
20 | 21 | | |||
21 | #include "kis_circle_mask_generator.h" | 22 | #include "kis_circle_mask_generator.h" | ||
22 | #include "kis_circle_mask_generator_p.h" | 23 | #include "kis_circle_mask_generator_p.h" | ||
23 | #include "kis_gauss_circle_mask_generator_p.h" | 24 | #include "kis_gauss_circle_mask_generator_p.h" | ||
24 | #include "kis_curve_circle_mask_generator_p.h" | 25 | #include "kis_curve_circle_mask_generator_p.h" | ||
26 | #include "kis_gauss_rect_mask_generator_p.h" | ||||
25 | 27 | | |||
26 | #include "kis_brush_mask_applicators.h" | 28 | #include "kis_brush_mask_applicators.h" | ||
27 | #include "kis_brush_mask_applicator_base.h" | 29 | #include "kis_brush_mask_applicator_base.h" | ||
Context not available. | |||||
53 | return new KisBrushMaskVectorApplicator<KisGaussCircleMaskGenerator,Vc::CurrentImplementation::current()>(maskGenerator); | 55 | return new KisBrushMaskVectorApplicator<KisGaussCircleMaskGenerator,Vc::CurrentImplementation::current()>(maskGenerator); | ||
54 | } | 56 | } | ||
55 | 57 | | |||
56 | | ||||
57 | template<> | 58 | template<> | ||
58 | template<> | 59 | template<> | ||
59 | MaskApplicatorFactory<KisCurveCircleMaskGenerator, KisBrushMaskVectorApplicator>::ReturnType | 60 | MaskApplicatorFactory<KisCurveCircleMaskGenerator, KisBrushMaskVectorApplicator>::ReturnType | ||
Context not available. | |||||
62 | return new KisBrushMaskVectorApplicator<KisCurveCircleMaskGenerator,Vc::CurrentImplementation::current()>(maskGenerator); | 63 | return new KisBrushMaskVectorApplicator<KisCurveCircleMaskGenerator,Vc::CurrentImplementation::current()>(maskGenerator); | ||
63 | } | 64 | } | ||
64 | 65 | | |||
66 | template<> | ||||
67 | template<> | ||||
68 | MaskApplicatorFactory<KisGaussRectangleMaskGenerator, KisBrushMaskVectorApplicator>::ReturnType | ||||
69 | MaskApplicatorFactory<KisGaussRectangleMaskGenerator, KisBrushMaskVectorApplicator>::create<Vc::CurrentImplementation::current()>(ParamType maskGenerator) | ||||
70 | { | ||||
71 | return new KisBrushMaskVectorApplicator<KisGaussRectangleMaskGenerator,Vc::CurrentImplementation::current()>(maskGenerator); | ||||
72 | } | ||||
73 | | ||||
65 | 74 | | |||
66 | #if defined HAVE_VC | 75 | #if defined HAVE_VC | ||
67 | 76 | | |||
Context not available. | |||||
172 | FastRowProcessor::process<Vc::CurrentImplementation::current()>(float* buffer, int width, float y, float cosa, float sina, | 181 | FastRowProcessor::process<Vc::CurrentImplementation::current()>(float* buffer, int width, float y, float cosa, float sina, | ||
173 | float centerX, float centerY) | 182 | float centerX, float centerY) | ||
174 | { | 183 | { | ||
175 | const bool antialiasOn = d->fadeMaker.getAliasingEnabled(); | | |||
176 | | ||||
177 | float y_ = y - centerY; | 184 | float y_ = y - centerY; | ||
178 | float sinay_ = sina * y_; | 185 | float sinay_ = sina * y_; | ||
179 | float cosay_ = cosa * y_; | 186 | float cosay_ = cosa * y_; | ||
Context not available. | |||||
195 | Vc::float_v vDistfactor(d->distfactor); | 202 | Vc::float_v vDistfactor(d->distfactor); | ||
196 | Vc::float_v vAlphafactor(d->alphafactor); | 203 | Vc::float_v vAlphafactor(d->alphafactor); | ||
197 | 204 | | |||
198 | Vc::float_v vFadeRadius(d->fadeMaker.getRadius()); | | |||
199 | Vc::float_v vFadeStartValue(d->fadeMaker.getFadeStartValue()); | | |||
200 | Vc::float_v vFadeAFadeStart(d->fadeMaker.getAntialiasingFadeStart()); | | |||
201 | Vc::float_v vFadeAFadeCoeff(d->fadeMaker.getAntialiasingFadeCoeff()); | | |||
202 | | ||||
203 | Vc::float_v vOne(Vc::One); | | |||
204 | Vc::float_v vZero(Vc::Zero); | 205 | Vc::float_v vZero(Vc::Zero); | ||
205 | Vc::float_v vValMax(255.f); | 206 | Vc::float_v vValMax(255.f); | ||
206 | 207 | | |||
Context not available. | |||||
213 | 214 | | |||
214 | Vc::float_v dist = sqrt(pow2(xr) + pow2(yr * vYCoeff)); | 215 | Vc::float_v dist = sqrt(pow2(xr) + pow2(yr * vYCoeff)); | ||
215 | 216 | | |||
216 | // BEGIN FadeMaker needFade vectorized | 217 | // Apply FadeMaker mask and operations | ||
217 | // follow fademaker rules for outsideMask | 218 | Vc::float_m excludeMask = d->fadeMaker.needFade(dist); | ||
218 | Vc::float_m outsideMask = dist > vFadeRadius; | | |||
219 | dist(outsideMask) = vOne; | | |||
220 | | ||||
221 | Vc::float_m fadeStartMask(false); | | |||
222 | // if antialias is off, do not process | | |||
223 | if(antialiasOn){ | | |||
224 | fadeStartMask = dist > vFadeAFadeStart; | | |||
225 | dist((outsideMask ^ fadeStartMask) & fadeStartMask) = (vFadeStartValue + (dist - vFadeAFadeStart) * vFadeAFadeCoeff) / vValMax; | | |||
226 | } | | |||
227 | Vc::float_m excludeMask(outsideMask | fadeStartMask); | | |||
228 | 219 | | |||
229 | if (!excludeMask.isFull()) { | 220 | if (!excludeMask.isFull()) { | ||
230 | Vc::float_v valDist = dist * vDistfactor; | 221 | Vc::float_v valDist = dist * vDistfactor; | ||
231 | Vc::float_v fullFade = vAlphafactor * ( d->vErf(valDist + vCenter) - d->vErf(valDist - vCenter)); | 222 | Vc::float_v fullFade = vAlphafactor * ( VcExtraMath::erf(valDist + vCenter) - VcExtraMath::erf(valDist - vCenter)); | ||
232 | 223 | | |||
233 | Vc::float_m mask; | 224 | Vc::float_m mask; | ||
234 | // Mask undefined values, out of range are out of mask | | |||
235 | mask = Vc::isfinite(fullFade); | | |||
236 | fullFade.setZero(!mask); | | |||
237 | | ||||
238 | // Mask in the inner circe of the mask | 225 | // Mask in the inner circe of the mask | ||
239 | mask = fullFade < vZero; | 226 | mask = fullFade < vZero; | ||
240 | fullFade.setZero(mask); | 227 | fullFade.setZero(mask); | ||
Context not available. | |||||
276 | FastRowProcessor::process<Vc::CurrentImplementation::current()>(float* buffer, int width, float y, float cosa, float sina, | 263 | FastRowProcessor::process<Vc::CurrentImplementation::current()>(float* buffer, int width, float y, float cosa, float sina, | ||
277 | float centerX, float centerY) | 264 | float centerX, float centerY) | ||
278 | { | 265 | { | ||
279 | const bool antialiasOn = d->fadeMaker.getAliasingEnabled(); | | |||
280 | | ||||
281 | float y_ = y - centerY; | 266 | float y_ = y - centerY; | ||
282 | float sinay_ = sina * y_; | 267 | float sinay_ = sina * y_; | ||
283 | float cosay_ = cosa * y_; | 268 | float cosay_ = cosa * y_; | ||
Context not available. | |||||
303 | Vc::float_v vCurvedData(Vc::Zero); | 288 | Vc::float_v vCurvedData(Vc::Zero); | ||
304 | Vc::float_v vCurvedData1(Vc::Zero); | 289 | Vc::float_v vCurvedData1(Vc::Zero); | ||
305 | 290 | | |||
306 | Vc::float_v vFadeRadius(d->fadeMaker.getRadius()); | | |||
307 | Vc::float_v vFadeStartValue(d->fadeMaker.getFadeStartValue()); | | |||
308 | Vc::float_v vFadeAFadeStart(d->fadeMaker.getAntialiasingFadeStart()); | | |||
309 | Vc::float_v vFadeAFadeCoeff(d->fadeMaker.getAntialiasingFadeCoeff()); | | |||
310 | | ||||
311 | Vc::float_v vOne(Vc::One); | 291 | Vc::float_v vOne(Vc::One); | ||
312 | Vc::float_v vZero(Vc::Zero); | 292 | Vc::float_v vZero(Vc::Zero); | ||
313 | Vc::float_v vValMax(255.f); | | |||
314 | 293 | | |||
315 | for (int i=0; i < width; i+= Vc::float_v::size()){ | 294 | for (int i=0; i < width; i+= Vc::float_v::size()){ | ||
316 | 295 | | |||
Context not available. | |||||
321 | 300 | | |||
322 | Vc::float_v dist = pow2(xr * vXCoeff) + pow2(yr * vYCoeff); | 301 | Vc::float_v dist = pow2(xr * vXCoeff) + pow2(yr * vYCoeff); | ||
323 | 302 | | |||
324 | // BEGIN FadeMaker needFade vectorized | 303 | // Apply FadeMaker mask and operations | ||
325 | // follow fademaker rules for outsideMask | 304 | Vc::float_m excludeMask = d->fadeMaker.needFade(dist); | ||
326 | Vc::float_m outsideMask = dist > vFadeRadius; | | |||
327 | dist(outsideMask) = vOne; | | |||
328 | | ||||
329 | Vc::float_m fadeStartMask(false); | | |||
330 | // if antialias is off, do not process | | |||
331 | if(antialiasOn){ | | |||
332 | fadeStartMask = dist > vFadeAFadeStart; | | |||
333 | dist((outsideMask ^ fadeStartMask) & fadeStartMask) = (vFadeStartValue + (dist - vFadeAFadeStart) * vFadeAFadeCoeff) / vValMax; | | |||
334 | } | | |||
335 | | ||||
336 | Vc::float_m excludeMask = outsideMask | fadeStartMask; | | |||
337 | 305 | | |||
338 | if (!excludeMask.isFull()) { | 306 | if (!excludeMask.isFull()) { | ||
339 | Vc::float_v valDist = dist * vCurveResolution; | 307 | Vc::float_v valDist = dist * vCurveResolution; | ||
Context not available. | |||||
375 | } | 343 | } | ||
376 | } | 344 | } | ||
377 | 345 | | |||
346 | struct KisGaussRectangleMaskGenerator::FastRowProcessor | ||||
347 | { | ||||
348 | FastRowProcessor(KisGaussRectangleMaskGenerator *maskGenerator) | ||||
349 | : d(maskGenerator->d.data()) {} | ||||
350 | | ||||
351 | template<Vc::Implementation _impl> | ||||
352 | void process(float* buffer, int width, float y, float cosa, float sina, | ||||
353 | float centerX, float centerY); | ||||
354 | | ||||
355 | KisGaussRectangleMaskGenerator::Private *d; | ||||
356 | }; | ||||
357 | | ||||
358 | template<> void KisGaussRectangleMaskGenerator:: | ||||
359 | FastRowProcessor::process<Vc::CurrentImplementation::current()>(float* buffer, int width, float y, float cosa, float sina, | ||||
360 | float centerX, float centerY) | ||||
361 | { | ||||
362 | float y_ = y - centerY; | ||||
363 | float sinay_ = sina * y_; | ||||
364 | float cosay_ = cosa * y_; | ||||
365 | | ||||
366 | float* bufferPointer = buffer; | ||||
367 | | ||||
368 | Vc::float_v currentIndices = Vc::float_v::IndexesFromZero(); | ||||
369 | | ||||
370 | Vc::float_v increment((float)Vc::float_v::size()); | ||||
371 | Vc::float_v vCenterX(centerX); | ||||
372 | | ||||
373 | Vc::float_v vCosa(cosa); | ||||
374 | Vc::float_v vSina(sina); | ||||
375 | Vc::float_v vCosaY_(cosay_); | ||||
376 | Vc::float_v vSinaY_(sinay_); | ||||
377 | | ||||
378 | Vc::float_v vhalfWidth(d->halfWidth); | ||||
379 | Vc::float_v vhalfHeight(d->halfHeight); | ||||
380 | Vc::float_v vXFade(d->xfade); | ||||
381 | Vc::float_v vYFade(d->yfade); | ||||
382 | | ||||
383 | Vc::float_v vAlphafactor(d->alphafactor); | ||||
384 | | ||||
385 | Vc::float_v vOne(Vc::One); | ||||
386 | Vc::float_v vZero(Vc::Zero); | ||||
387 | Vc::float_v vValMax(255.f); | ||||
388 | | ||||
389 | for (int i=0; i < width; i+= Vc::float_v::size()){ | ||||
390 | | ||||
391 | Vc::float_v x_ = currentIndices - vCenterX; | ||||
392 | | ||||
393 | Vc::float_v xr = x_ * vCosa - vSinaY_; | ||||
394 | Vc::float_v yr = abs(x_ * vSina + vCosaY_); | ||||
395 | | ||||
396 | Vc::float_v vValue; | ||||
397 | | ||||
398 | // check if we need to apply fader on values | ||||
399 | Vc::float_m excludeMask = d->fadeMaker.needFade(xr,yr); | ||||
400 | vValue(excludeMask) = vOne; | ||||
401 | | ||||
402 | if (!excludeMask.isFull()) { | ||||
403 | Vc::float_v fullFade = vValMax - (vAlphafactor * (VcExtraMath::erf((vhalfWidth + xr) * vXFade) + VcExtraMath::erf((vhalfWidth - xr) * vXFade)) | ||||
404 | * (VcExtraMath::erf((vhalfHeight + yr) * vYFade) + VcExtraMath::erf((vhalfHeight - yr) * vYFade))); | ||||
405 | | ||||
406 | // apply antialias fader | ||||
407 | d->fadeMaker.apply2DFader(fullFade,excludeMask,xr,yr); | ||||
408 | | ||||
409 | Vc::float_m mask; | ||||
410 | | ||||
411 | // Mask in the inner circe of the mask | ||||
412 | mask = fullFade < vZero; | ||||
413 | fullFade.setZero(mask); | ||||
414 | | ||||
415 | // Mask the outter circle | ||||
416 | mask = fullFade > 254.974f; | ||||
417 | fullFade(mask) = vValMax; | ||||
418 | | ||||
419 | // Mask (value - value), presicion errors. | ||||
420 | Vc::float_v vFade = fullFade / vValMax; | ||||
421 | | ||||
422 | // return original vValue values before vFade transform | ||||
423 | vFade(excludeMask) = vValue; | ||||
424 | vFade.store(bufferPointer, Vc::Aligned); | ||||
425 | | ||||
426 | } else { | ||||
427 | vValue.store(bufferPointer, Vc::Aligned); | ||||
428 | } | ||||
429 | currentIndices = currentIndices + increment; | ||||
430 | | ||||
431 | bufferPointer += Vc::float_v::size(); | ||||
432 | } | ||||
433 | } | ||||
434 | | ||||
378 | #endif /* defined HAVE_VC */ | 435 | #endif /* defined HAVE_VC */ | ||
Context not available. |