From 01148da03a7d2950515b540582cc05e2f9b16140 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 27 Apr 2018 20:20:09 +0000 Subject: Use std::function in CJBig2_GRDProc. Pick from a set of functions before calling it, instead of having code to call all of the functions with the same parameters. Change-Id: I7f479948f50bdc1a9eb2764d5eb7505dc7434418 Reviewed-on: https://pdfium-review.googlesource.com/31533 Commit-Queue: Lei Zhang Reviewed-by: Ryan Harrison --- core/fxcodec/jbig2/JBig2_GrdProc.cpp | 96 ++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 48 deletions(-) (limited to 'core/fxcodec/jbig2') diff --git a/core/fxcodec/jbig2/JBig2_GrdProc.cpp b/core/fxcodec/jbig2/JBig2_GrdProc.cpp index 0dc4126366..bc256f7b2a 100644 --- a/core/fxcodec/jbig2/JBig2_GrdProc.cpp +++ b/core/fxcodec/jbig2/JBig2_GrdProc.cpp @@ -6,6 +6,7 @@ #include "core/fxcodec/jbig2/JBig2_GrdProc.h" +#include #include #include @@ -49,23 +50,28 @@ std::unique_ptr CJBig2_GRDProc::DecodeArith( if (!CJBig2_Image::IsValidImageSize(GBW, GBH)) return pdfium::MakeUnique(GBW, GBH); - if (GBTEMPLATE == 0) { - if (UseTemplate0Opt3()) - return DecodeArithTemplate0Opt3(pArithDecoder, gbContext); - return DecodeArithTemplate0Unopt(pArithDecoder, gbContext); - } else if (GBTEMPLATE == 1) { - if (UseTemplate1Opt3()) - return DecodeArithTemplate1Opt3(pArithDecoder, gbContext); - return DecodeArithTemplate1Unopt(pArithDecoder, gbContext); - } else if (GBTEMPLATE == 2) { - if (UseTemplate23Opt3()) - return DecodeArithTemplate2Opt3(pArithDecoder, gbContext); - return DecodeArithTemplate2Unopt(pArithDecoder, gbContext); - } else { - if (UseTemplate23Opt3()) - return DecodeArithTemplate3Opt3(pArithDecoder, gbContext); - return DecodeArithTemplate3Unopt(pArithDecoder, gbContext); + using DecodeFunction = std::function( + CJBig2_GRDProc&, CJBig2_ArithDecoder*, JBig2ArithCtx*)>; + DecodeFunction func; + switch (GBTEMPLATE) { + case 0: + func = UseTemplate0Opt3() ? &CJBig2_GRDProc::DecodeArithTemplate0Opt3 + : &CJBig2_GRDProc::DecodeArithTemplate0Unopt; + break; + case 1: + func = UseTemplate1Opt3() ? &CJBig2_GRDProc::DecodeArithTemplate1Opt3 + : &CJBig2_GRDProc::DecodeArithTemplate1Unopt; + break; + case 2: + func = UseTemplate23Opt3() ? &CJBig2_GRDProc::DecodeArithTemplate2Opt3 + : &CJBig2_GRDProc::DecodeArithTemplate2Unopt; + break; + default: + func = UseTemplate23Opt3() ? &CJBig2_GRDProc::DecodeArithTemplate3Opt3 + : &CJBig2_GRDProc::DecodeArithTemplate3Unopt; + break; } + return func(*this, pArithDecoder, gbContext); } std::unique_ptr CJBig2_GRDProc::DecodeArithTemplate0Opt3( @@ -666,39 +672,33 @@ FXCODEC_STATUS CJBig2_GRDProc::ProgressiveDecodeArith( PauseIndicatorIface* pPause, CJBig2_ArithDecoder* pArithDecoder) { int iline = m_loopIndex; - if (GBTEMPLATE == 0) { - if (UseTemplate0Opt3()) { - m_ProssiveStatus = - ProgressiveDecodeArithTemplate0Opt3(pArithDecoder, pPause); - } else { - m_ProssiveStatus = - ProgressiveDecodeArithTemplate0Unopt(pArithDecoder, pPause); - } - } else if (GBTEMPLATE == 1) { - if (UseTemplate1Opt3()) { - m_ProssiveStatus = - ProgressiveDecodeArithTemplate1Opt3(pArithDecoder, pPause); - } else { - m_ProssiveStatus = - ProgressiveDecodeArithTemplate1Unopt(pArithDecoder, pPause); - } - } else if (GBTEMPLATE == 2) { - if (UseTemplate23Opt3()) { - m_ProssiveStatus = - ProgressiveDecodeArithTemplate2Opt3(pArithDecoder, pPause); - } else { - m_ProssiveStatus = - ProgressiveDecodeArithTemplate2Unopt(pArithDecoder, pPause); - } - } else { - if (UseTemplate23Opt3()) { - m_ProssiveStatus = - ProgressiveDecodeArithTemplate3Opt3(pArithDecoder, pPause); - } else { - m_ProssiveStatus = - ProgressiveDecodeArithTemplate3Unopt(pArithDecoder, pPause); - } + + using DecodeFunction = std::function; + DecodeFunction func; + switch (GBTEMPLATE) { + case 0: + func = UseTemplate0Opt3() + ? &CJBig2_GRDProc::ProgressiveDecodeArithTemplate0Opt3 + : &CJBig2_GRDProc::ProgressiveDecodeArithTemplate0Unopt; + break; + case 1: + func = UseTemplate1Opt3() + ? &CJBig2_GRDProc::ProgressiveDecodeArithTemplate1Opt3 + : &CJBig2_GRDProc::ProgressiveDecodeArithTemplate1Unopt; + break; + case 2: + func = UseTemplate23Opt3() + ? &CJBig2_GRDProc::ProgressiveDecodeArithTemplate2Opt3 + : &CJBig2_GRDProc::ProgressiveDecodeArithTemplate2Unopt; + break; + default: + func = UseTemplate23Opt3() + ? &CJBig2_GRDProc::ProgressiveDecodeArithTemplate3Opt3 + : &CJBig2_GRDProc::ProgressiveDecodeArithTemplate3Unopt; + break; } + m_ProssiveStatus = func(*this, pArithDecoder, pPause); m_ReplaceRect.left = 0; m_ReplaceRect.right = m_pImage->width(); m_ReplaceRect.top = iline; -- cgit v1.2.3