From 5f07769cb9f4c065688444e828c784df8ecb89a9 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 AABGR8 pipes Skip some computations if both src and dest alpha are zero, or if src is fully opaque. Equivalent to Commit f47936af7508A ("Small optimization for AAXRGB8 pipes"). --- splash/Splash.cc | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/splash/Splash.cc b/splash/Splash.cc index 14f40cd7..d749ab03 100644 --- a/splash/Splash.cc +++ b/splash/Splash.cc @@ -1191,25 +1191,35 @@ void Splash::pipeRunAABGR8(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