From 86243609b8b2cce6bd7a084783efa403fedd96eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Br=C3=BCns?= Date: Sun, 20 May 2018 19:31:53 +0200 Subject: [PATCH] Small optimization for AAXRGB8 pipes Skip some computations if both src and dest alpha are zero, or if src is fully opaque. For common cases (majority of pixels fully opaque) like in fdo#81211, this reduces execution time of pipeRunAAXBGR8 by 50% (-20% total execution time). --- splash/Splash.cc | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/splash/Splash.cc b/splash/Splash.cc index ca5c99d0..a8db9282 100644 --- a/splash/Splash.cc +++ b/splash/Splash.cc @@ -1123,25 +1123,35 @@ void Splash::pipeRunAAXBGR8(SplashPipe *pipe) { SplashColor cDest; Guchar cResult0, cResult1, cResult2; - //----- read destination pixel - cDest[0] = pipe->destColorPtr[2]; - cDest[1] = pipe->destColorPtr[1]; - cDest[2] = pipe->destColorPtr[0]; + //----- read destination alpha aDest = *pipe->destAlphaPtr; //----- source alpha aSrc = div255(pipe->aInput * pipe->shape); - //----- result alpha and non-isolated group element correction - aResult = aSrc + aDest - div255(aSrc * aDest); - alpha2 = aResult; - //----- result color - if (alpha2 == 0) { + if (aSrc == 255) { + cResult0 = state->rgbTransferR[pipe->cSrc[0]]; + cResult1 = state->rgbTransferG[pipe->cSrc[1]]; + cResult2 = state->rgbTransferB[pipe->cSrc[2]]; + aResult = 255; + + } else if (aSrc == 0 && aDest == 0) { cResult0 = 0; cResult1 = 0; cResult2 = 0; + aResult = 0; + } else { + //----- read destination color + cDest[0] = pipe->destColorPtr[2]; + cDest[1] = pipe->destColorPtr[1]; + cDest[2] = pipe->destColorPtr[0]; + + //----- result alpha and non-isolated group element correction + aResult = aSrc + aDest - div255(aSrc * aDest); + alpha2 = aResult; + cResult0 = state->rgbTransferR[(Guchar)(((alpha2 - aSrc) * cDest[0] + aSrc * pipe->cSrc[0]) / alpha2)]; cResult1 = state->rgbTransferG[(Guchar)(((alpha2 - aSrc) * cDest[1] + -- 2.16.3