Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: core/src/fxcodec/jbig2/JBig2_GsidProc.cpp

Issue 1382613003: Remove gotos in JBig2 code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: address comments Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fxcodec/jbig2/JBig2_Context.cpp ('k') | core/src/fxcodec/jbig2/JBig2_HuffmanTable.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 PDFium Authors. All rights reserved. 1 // Copyright 2015 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "JBig2_GsidProc.h" 7 #include "JBig2_GsidProc.h"
8 8
9 #include "../../../../third_party/base/nonstd_unique_ptr.h" 9 #include "../../../../third_party/base/nonstd_unique_ptr.h"
10 #include "../../../include/fxcrt/fx_basic.h" 10 #include "../../../include/fxcrt/fx_basic.h"
11 #include "JBig2_BitStream.h" 11 #include "JBig2_BitStream.h"
12 #include "JBig2_GrdProc.h" 12 #include "JBig2_GrdProc.h"
13 #include "JBig2_Image.h" 13 #include "JBig2_Image.h"
14 14
15 FX_DWORD* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, 15 FX_DWORD* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
16 JBig2ArithCtx* gbContext, 16 JBig2ArithCtx* gbContext,
17 IFX_Pause* pPause) { 17 IFX_Pause* pPause) {
18 CJBig2_Image** GSPLANES;
19 int32_t J, K;
20 FX_DWORD x, y;
21 FX_DWORD* GSVALS;
22 GSPLANES = FX_Alloc(CJBig2_Image*, GSBPP);
23 GSVALS = FX_Alloc2D(FX_DWORD, GSW, GSH);
24 JBIG2_memset(GSPLANES, 0, sizeof(CJBig2_Image*) * GSBPP);
25 JBIG2_memset(GSVALS, 0, sizeof(FX_DWORD) * GSW * GSH);
26
27 nonstd::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc()); 18 nonstd::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc());
28 pGRD->MMR = GSMMR; 19 pGRD->MMR = GSMMR;
29 pGRD->GBW = GSW; 20 pGRD->GBW = GSW;
30 pGRD->GBH = GSH; 21 pGRD->GBH = GSH;
31 pGRD->GBTEMPLATE = GSTEMPLATE; 22 pGRD->GBTEMPLATE = GSTEMPLATE;
32 pGRD->TPGDON = 0; 23 pGRD->TPGDON = 0;
33 pGRD->USESKIP = GSUSESKIP; 24 pGRD->USESKIP = GSUSESKIP;
34 pGRD->SKIP = GSKIP; 25 pGRD->SKIP = GSKIP;
35 if (GSTEMPLATE <= 1) { 26 if (GSTEMPLATE <= 1) {
36 pGRD->GBAT[0] = 3; 27 pGRD->GBAT[0] = 3;
37 } else { 28 } else {
38 pGRD->GBAT[0] = 2; 29 pGRD->GBAT[0] = 2;
39 } 30 }
40 pGRD->GBAT[1] = -1; 31 pGRD->GBAT[1] = -1;
41 if (pGRD->GBTEMPLATE == 0) { 32 if (pGRD->GBTEMPLATE == 0) {
42 pGRD->GBAT[2] = -3; 33 pGRD->GBAT[2] = -3;
43 pGRD->GBAT[3] = -1; 34 pGRD->GBAT[3] = -1;
44 pGRD->GBAT[4] = 2; 35 pGRD->GBAT[4] = 2;
45 pGRD->GBAT[5] = -2; 36 pGRD->GBAT[5] = -2;
46 pGRD->GBAT[6] = -2; 37 pGRD->GBAT[6] = -2;
47 pGRD->GBAT[7] = -2; 38 pGRD->GBAT[7] = -2;
48 } 39 }
40
41 nonstd::unique_ptr<CJBig2_Image*, FxFreeDeleter> GSPLANES(
42 FX_Alloc(CJBig2_Image*, GSBPP));
43 JBIG2_memset(GSPLANES.get(), 0, sizeof(CJBig2_Image*) * GSBPP);
49 FXCODEC_STATUS status = pGRD->Start_decode_Arith( 44 FXCODEC_STATUS status = pGRD->Start_decode_Arith(
50 &GSPLANES[GSBPP - 1], pArithDecoder, gbContext, nullptr); 45 &GSPLANES.get()[GSBPP - 1], pArithDecoder, gbContext, nullptr);
51 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { 46 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) {
52 pGRD->Continue_decode(pPause); 47 pGRD->Continue_decode(pPause);
53 } 48 }
54 if (!GSPLANES[GSBPP - 1]) { 49 if (!GSPLANES.get()[GSBPP - 1])
55 goto failed; 50 return nullptr;
56 } 51
57 J = GSBPP - 2; 52 int32_t J = GSBPP - 2;
58 while (J >= 0) { 53 while (J >= 0) {
59 FXCODEC_STATUS status = pGRD->Start_decode_Arith( 54 FXCODEC_STATUS status = pGRD->Start_decode_Arith(
60 &GSPLANES[J], pArithDecoder, gbContext, nullptr); 55 &GSPLANES.get()[J], pArithDecoder, gbContext, nullptr);
61 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { 56 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) {
62 pGRD->Continue_decode(pPause); 57 pGRD->Continue_decode(pPause);
63 } 58 }
64 if (!GSPLANES[J]) { 59 if (!GSPLANES.get()[J]) {
65 for (K = GSBPP - 1; K > J; K--) { 60 for (int32_t K = GSBPP - 1; K > J; --K) {
66 delete GSPLANES[K]; 61 delete GSPLANES.get()[K];
67 goto failed; 62 return nullptr;
68 } 63 }
69 } 64 }
70 GSPLANES[J]->composeFrom(0, 0, GSPLANES[J + 1], JBIG2_COMPOSE_XOR); 65 GSPLANES.get()[J]->composeFrom(0, 0, GSPLANES.get()[J + 1],
66 JBIG2_COMPOSE_XOR);
71 J = J - 1; 67 J = J - 1;
72 } 68 }
73 for (y = 0; y < GSH; y++) { 69 nonstd::unique_ptr<FX_DWORD, FxFreeDeleter> GSVALS(
74 for (x = 0; x < GSW; x++) { 70 FX_Alloc2D(FX_DWORD, GSW, GSH));
75 for (J = 0; J < GSBPP; J++) { 71 JBIG2_memset(GSVALS.get(), 0, sizeof(FX_DWORD) * GSW * GSH);
76 GSVALS[y * GSW + x] |= GSPLANES[J]->getPixel(x, y) << J; 72 for (FX_DWORD y = 0; y < GSH; ++y) {
73 for (FX_DWORD x = 0; x < GSW; ++x) {
74 for (J = 0; J < GSBPP; ++J) {
75 GSVALS.get()[y * GSW + x] |= GSPLANES.get()[J]->getPixel(x, y) << J;
77 } 76 }
78 } 77 }
79 } 78 }
80 for (J = 0; J < GSBPP; J++) { 79 for (J = 0; J < GSBPP; ++J) {
81 delete GSPLANES[J]; 80 delete GSPLANES.get()[J];
82 } 81 }
83 FX_Free(GSPLANES); 82 return GSVALS.release();
84 return GSVALS;
85 failed:
86 FX_Free(GSPLANES);
87 FX_Free(GSVALS);
88 return nullptr;
89 } 83 }
90 84
91 FX_DWORD* CJBig2_GSIDProc::decode_MMR(CJBig2_BitStream* pStream, 85 FX_DWORD* CJBig2_GSIDProc::decode_MMR(CJBig2_BitStream* pStream,
92 IFX_Pause* pPause) { 86 IFX_Pause* pPause) {
93 CJBig2_Image** GSPLANES;
94 int32_t J, K;
95 FX_DWORD x, y;
96 FX_DWORD* GSVALS;
97 GSPLANES = FX_Alloc(CJBig2_Image*, GSBPP);
98 GSVALS = FX_Alloc2D(FX_DWORD, GSW, GSH);
99 JBIG2_memset(GSPLANES, 0, sizeof(CJBig2_Image*) * GSBPP);
100 JBIG2_memset(GSVALS, 0, sizeof(FX_DWORD) * GSW * GSH);
101
102 nonstd::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc()); 87 nonstd::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc());
103 pGRD->MMR = GSMMR; 88 pGRD->MMR = GSMMR;
104 pGRD->GBW = GSW; 89 pGRD->GBW = GSW;
105 pGRD->GBH = GSH; 90 pGRD->GBH = GSH;
91
92 nonstd::unique_ptr<CJBig2_Image*> GSPLANES(FX_Alloc(CJBig2_Image*, GSBPP));
93 JBIG2_memset(GSPLANES.get(), 0, sizeof(CJBig2_Image*) * GSBPP);
106 FXCODEC_STATUS status = 94 FXCODEC_STATUS status =
107 pGRD->Start_decode_MMR(&GSPLANES[GSBPP - 1], pStream, nullptr); 95 pGRD->Start_decode_MMR(&GSPLANES.get()[GSBPP - 1], pStream, nullptr);
108 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { 96 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) {
109 pGRD->Continue_decode(pPause); 97 pGRD->Continue_decode(pPause);
110 } 98 }
111 if (!GSPLANES[GSBPP - 1]) { 99 if (!GSPLANES.get()[GSBPP - 1])
112 goto failed; 100 return nullptr;
113 } 101
114 pStream->alignByte(); 102 pStream->alignByte();
115 pStream->offset(3); 103 pStream->offset(3);
116 J = GSBPP - 2; 104 int32_t J = GSBPP - 2;
117 while (J >= 0) { 105 while (J >= 0) {
118 FXCODEC_STATUS status = 106 FXCODEC_STATUS status =
119 pGRD->Start_decode_MMR(&GSPLANES[J], pStream, nullptr); 107 pGRD->Start_decode_MMR(&GSPLANES.get()[J], pStream, nullptr);
120 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { 108 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) {
121 pGRD->Continue_decode(pPause); 109 pGRD->Continue_decode(pPause);
122 } 110 }
123 if (!GSPLANES[J]) { 111 if (!GSPLANES.get()[J]) {
124 for (K = GSBPP - 1; K > J; K--) { 112 for (int32_t K = GSBPP - 1; K > J; --K) {
125 delete GSPLANES[K]; 113 delete GSPLANES.get()[K];
126 goto failed; 114 return nullptr;
127 } 115 }
128 } 116 }
129 pStream->alignByte(); 117 pStream->alignByte();
130 pStream->offset(3); 118 pStream->offset(3);
131 GSPLANES[J]->composeFrom(0, 0, GSPLANES[J + 1], JBIG2_COMPOSE_XOR); 119 GSPLANES.get()[J]->composeFrom(0, 0, GSPLANES.get()[J + 1],
120 JBIG2_COMPOSE_XOR);
132 J = J - 1; 121 J = J - 1;
133 } 122 }
134 for (y = 0; y < GSH; y++) { 123 nonstd::unique_ptr<FX_DWORD> GSVALS(FX_Alloc2D(FX_DWORD, GSW, GSH));
135 for (x = 0; x < GSW; x++) { 124 JBIG2_memset(GSVALS.get(), 0, sizeof(FX_DWORD) * GSW * GSH);
136 for (J = 0; J < GSBPP; J++) { 125 for (FX_DWORD y = 0; y < GSH; ++y) {
137 GSVALS[y * GSW + x] |= GSPLANES[J]->getPixel(x, y) << J; 126 for (FX_DWORD x = 0; x < GSW; ++x) {
127 for (J = 0; J < GSBPP; ++J) {
128 GSVALS.get()[y * GSW + x] |= GSPLANES.get()[J]->getPixel(x, y) << J;
138 } 129 }
139 } 130 }
140 } 131 }
141 for (J = 0; J < GSBPP; J++) { 132 for (J = 0; J < GSBPP; ++J) {
142 delete GSPLANES[J]; 133 delete GSPLANES.get()[J];
143 } 134 }
144 FX_Free(GSPLANES); 135 return GSVALS.release();
145 return GSVALS;
146 failed:
147 FX_Free(GSPLANES);
148 FX_Free(GSVALS);
149 return nullptr;
150 } 136 }
OLDNEW
« no previous file with comments | « core/src/fxcodec/jbig2/JBig2_Context.cpp ('k') | core/src/fxcodec/jbig2/JBig2_HuffmanTable.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698