From 26c9e2caf07b57aeec24a13dd0a824d05af37fa2 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 7 Oct 2015 21:31:16 -0700 Subject: Merge to XFA: Remove gotos in JBig2 code. TBR=tsepez@chromium.org Review URL: https://codereview.chromium.org/1382613003 . (cherry picked from commit 8a9ce5778e0789beb7ba15a62c592a353a51bcdd) Review URL: https://codereview.chromium.org/1397683002 . --- core/src/fxcodec/jbig2/JBig2_GsidProc.cpp | 114 +++++++++++++----------------- 1 file changed, 50 insertions(+), 64 deletions(-) (limited to 'core/src/fxcodec/jbig2/JBig2_GsidProc.cpp') diff --git a/core/src/fxcodec/jbig2/JBig2_GsidProc.cpp b/core/src/fxcodec/jbig2/JBig2_GsidProc.cpp index b97a212926..d89bb8f249 100644 --- a/core/src/fxcodec/jbig2/JBig2_GsidProc.cpp +++ b/core/src/fxcodec/jbig2/JBig2_GsidProc.cpp @@ -15,15 +15,6 @@ FX_DWORD* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext, IFX_Pause* pPause) { - CJBig2_Image** GSPLANES; - int32_t J, K; - FX_DWORD x, y; - FX_DWORD* GSVALS; - GSPLANES = FX_Alloc(CJBig2_Image*, GSBPP); - GSVALS = FX_Alloc2D(FX_DWORD, GSW, GSH); - JBIG2_memset(GSPLANES, 0, sizeof(CJBig2_Image*) * GSBPP); - JBIG2_memset(GSVALS, 0, sizeof(FX_DWORD) * GSW * GSH); - nonstd::unique_ptr pGRD(new CJBig2_GRDProc()); pGRD->MMR = GSMMR; pGRD->GBW = GSW; @@ -46,105 +37,100 @@ FX_DWORD* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, pGRD->GBAT[6] = -2; pGRD->GBAT[7] = -2; } + + nonstd::unique_ptr GSPLANES( + FX_Alloc(CJBig2_Image*, GSBPP)); + JBIG2_memset(GSPLANES.get(), 0, sizeof(CJBig2_Image*) * GSBPP); FXCODEC_STATUS status = pGRD->Start_decode_Arith( - &GSPLANES[GSBPP - 1], pArithDecoder, gbContext, nullptr); + &GSPLANES.get()[GSBPP - 1], pArithDecoder, gbContext, nullptr); while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { pGRD->Continue_decode(pPause); } - if (!GSPLANES[GSBPP - 1]) { - goto failed; - } - J = GSBPP - 2; + if (!GSPLANES.get()[GSBPP - 1]) + return nullptr; + + int32_t J = GSBPP - 2; while (J >= 0) { FXCODEC_STATUS status = pGRD->Start_decode_Arith( - &GSPLANES[J], pArithDecoder, gbContext, nullptr); + &GSPLANES.get()[J], pArithDecoder, gbContext, nullptr); while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { pGRD->Continue_decode(pPause); } - if (!GSPLANES[J]) { - for (K = GSBPP - 1; K > J; K--) { - delete GSPLANES[K]; - goto failed; + if (!GSPLANES.get()[J]) { + for (int32_t K = GSBPP - 1; K > J; --K) { + delete GSPLANES.get()[K]; + return nullptr; } } - GSPLANES[J]->composeFrom(0, 0, GSPLANES[J + 1], JBIG2_COMPOSE_XOR); + GSPLANES.get()[J]->composeFrom(0, 0, GSPLANES.get()[J + 1], + JBIG2_COMPOSE_XOR); J = J - 1; } - for (y = 0; y < GSH; y++) { - for (x = 0; x < GSW; x++) { - for (J = 0; J < GSBPP; J++) { - GSVALS[y * GSW + x] |= GSPLANES[J]->getPixel(x, y) << J; + nonstd::unique_ptr GSVALS( + FX_Alloc2D(FX_DWORD, GSW, GSH)); + JBIG2_memset(GSVALS.get(), 0, sizeof(FX_DWORD) * GSW * GSH); + for (FX_DWORD y = 0; y < GSH; ++y) { + for (FX_DWORD x = 0; x < GSW; ++x) { + for (J = 0; J < GSBPP; ++J) { + GSVALS.get()[y * GSW + x] |= GSPLANES.get()[J]->getPixel(x, y) << J; } } } - for (J = 0; J < GSBPP; J++) { - delete GSPLANES[J]; + for (J = 0; J < GSBPP; ++J) { + delete GSPLANES.get()[J]; } - FX_Free(GSPLANES); - return GSVALS; -failed: - FX_Free(GSPLANES); - FX_Free(GSVALS); - return nullptr; + return GSVALS.release(); } FX_DWORD* CJBig2_GSIDProc::decode_MMR(CJBig2_BitStream* pStream, IFX_Pause* pPause) { - CJBig2_Image** GSPLANES; - int32_t J, K; - FX_DWORD x, y; - FX_DWORD* GSVALS; - GSPLANES = FX_Alloc(CJBig2_Image*, GSBPP); - GSVALS = FX_Alloc2D(FX_DWORD, GSW, GSH); - JBIG2_memset(GSPLANES, 0, sizeof(CJBig2_Image*) * GSBPP); - JBIG2_memset(GSVALS, 0, sizeof(FX_DWORD) * GSW * GSH); - nonstd::unique_ptr pGRD(new CJBig2_GRDProc()); pGRD->MMR = GSMMR; pGRD->GBW = GSW; pGRD->GBH = GSH; + + nonstd::unique_ptr GSPLANES(FX_Alloc(CJBig2_Image*, GSBPP)); + JBIG2_memset(GSPLANES.get(), 0, sizeof(CJBig2_Image*) * GSBPP); FXCODEC_STATUS status = - pGRD->Start_decode_MMR(&GSPLANES[GSBPP - 1], pStream, nullptr); + pGRD->Start_decode_MMR(&GSPLANES.get()[GSBPP - 1], pStream, nullptr); while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { pGRD->Continue_decode(pPause); } - if (!GSPLANES[GSBPP - 1]) { - goto failed; - } + if (!GSPLANES.get()[GSBPP - 1]) + return nullptr; + pStream->alignByte(); pStream->offset(3); - J = GSBPP - 2; + int32_t J = GSBPP - 2; while (J >= 0) { FXCODEC_STATUS status = - pGRD->Start_decode_MMR(&GSPLANES[J], pStream, nullptr); + pGRD->Start_decode_MMR(&GSPLANES.get()[J], pStream, nullptr); while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { pGRD->Continue_decode(pPause); } - if (!GSPLANES[J]) { - for (K = GSBPP - 1; K > J; K--) { - delete GSPLANES[K]; - goto failed; + if (!GSPLANES.get()[J]) { + for (int32_t K = GSBPP - 1; K > J; --K) { + delete GSPLANES.get()[K]; + return nullptr; } } pStream->alignByte(); pStream->offset(3); - GSPLANES[J]->composeFrom(0, 0, GSPLANES[J + 1], JBIG2_COMPOSE_XOR); + GSPLANES.get()[J]->composeFrom(0, 0, GSPLANES.get()[J + 1], + JBIG2_COMPOSE_XOR); J = J - 1; } - for (y = 0; y < GSH; y++) { - for (x = 0; x < GSW; x++) { - for (J = 0; J < GSBPP; J++) { - GSVALS[y * GSW + x] |= GSPLANES[J]->getPixel(x, y) << J; + nonstd::unique_ptr GSVALS(FX_Alloc2D(FX_DWORD, GSW, GSH)); + JBIG2_memset(GSVALS.get(), 0, sizeof(FX_DWORD) * GSW * GSH); + for (FX_DWORD y = 0; y < GSH; ++y) { + for (FX_DWORD x = 0; x < GSW; ++x) { + for (J = 0; J < GSBPP; ++J) { + GSVALS.get()[y * GSW + x] |= GSPLANES.get()[J]->getPixel(x, y) << J; } } } - for (J = 0; J < GSBPP; J++) { - delete GSPLANES[J]; + for (J = 0; J < GSBPP; ++J) { + delete GSPLANES.get()[J]; } - FX_Free(GSPLANES); - return GSVALS; -failed: - FX_Free(GSPLANES); - FX_Free(GSVALS); - return nullptr; + return GSVALS.release(); } -- cgit v1.2.3