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

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

Issue 1359013003: Cleanup JBig2_ArithIntDecoder. (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
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_SddProc.h" 7 #include "JBig2_SddProc.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"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 nTmp++; 58 nTmp++;
59 } 59 }
60 IAID.reset(new CJBig2_ArithIaidDecoder((uint8_t)nTmp)); 60 IAID.reset(new CJBig2_ArithIaidDecoder((uint8_t)nTmp));
61 SDNEWSYMS = FX_Alloc(CJBig2_Image*, SDNUMNEWSYMS); 61 SDNEWSYMS = FX_Alloc(CJBig2_Image*, SDNUMNEWSYMS);
62 FXSYS_memset(SDNEWSYMS, 0, SDNUMNEWSYMS * sizeof(CJBig2_Image*)); 62 FXSYS_memset(SDNEWSYMS, 0, SDNUMNEWSYMS * sizeof(CJBig2_Image*));
63 63
64 HCHEIGHT = 0; 64 HCHEIGHT = 0;
65 NSYMSDECODED = 0; 65 NSYMSDECODED = 0;
66 while (NSYMSDECODED < SDNUMNEWSYMS) { 66 while (NSYMSDECODED < SDNUMNEWSYMS) {
67 BS = nullptr; 67 BS = nullptr;
68 if (IADH->decode(pArithDecoder, &HCDH) == -1) { 68 if (!IADH->decode(pArithDecoder, &HCDH)) {
69 goto failed; 69 goto failed;
70 } 70 }
71 HCHEIGHT = HCHEIGHT + HCDH; 71 HCHEIGHT = HCHEIGHT + HCDH;
72 if ((int)HCHEIGHT < 0 || (int)HCHEIGHT > JBIG2_MAX_IMAGE_SIZE) { 72 if ((int)HCHEIGHT < 0 || (int)HCHEIGHT > JBIG2_MAX_IMAGE_SIZE) {
73 goto failed; 73 goto failed;
74 } 74 }
75 SYMWIDTH = 0; 75 SYMWIDTH = 0;
76 TOTWIDTH = 0; 76 TOTWIDTH = 0;
77 for (;;) { 77 for (;;) {
78 nVal = IADW->decode(pArithDecoder, &DW); 78 nVal = IADW->decode(pArithDecoder, &DW);
(...skipping 30 matching lines...) Expand all
109 pGRD->GBAT[3] = SDAT[3]; 109 pGRD->GBAT[3] = SDAT[3];
110 pGRD->GBAT[4] = SDAT[4]; 110 pGRD->GBAT[4] = SDAT[4];
111 pGRD->GBAT[5] = SDAT[5]; 111 pGRD->GBAT[5] = SDAT[5];
112 pGRD->GBAT[6] = SDAT[6]; 112 pGRD->GBAT[6] = SDAT[6];
113 pGRD->GBAT[7] = SDAT[7]; 113 pGRD->GBAT[7] = SDAT[7];
114 BS = pGRD->decode_Arith(pArithDecoder, gbContext); 114 BS = pGRD->decode_Arith(pArithDecoder, gbContext);
115 if (!BS) { 115 if (!BS) {
116 goto failed; 116 goto failed;
117 } 117 }
118 } else { 118 } else {
119 if (IAAI->decode(pArithDecoder, (int*)&REFAGGNINST) == -1) { 119 if (!IAAI->decode(pArithDecoder, (int*)&REFAGGNINST)) {
120 goto failed; 120 goto failed;
121 } 121 }
122 if (REFAGGNINST > 1) { 122 if (REFAGGNINST > 1) {
123 nonstd::unique_ptr<CJBig2_TRDProc> pDecoder(new CJBig2_TRDProc()); 123 nonstd::unique_ptr<CJBig2_TRDProc> pDecoder(new CJBig2_TRDProc());
124 pDecoder->SBHUFF = SDHUFF; 124 pDecoder->SBHUFF = SDHUFF;
125 pDecoder->SBREFINE = 1; 125 pDecoder->SBREFINE = 1;
126 pDecoder->SBW = SYMWIDTH; 126 pDecoder->SBW = SYMWIDTH;
127 pDecoder->SBH = HCHEIGHT; 127 pDecoder->SBH = HCHEIGHT;
128 pDecoder->SBNUMINSTANCES = REFAGGNINST; 128 pDecoder->SBNUMINSTANCES = REFAGGNINST;
129 pDecoder->SBSTRIPS = 1; 129 pDecoder->SBSTRIPS = 1;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 ids.IARDY = IARDY.get(); 202 ids.IARDY = IARDY.get();
203 ids.IAID = IAID.get(); 203 ids.IAID = IAID.get();
204 BS = pDecoder->decode_Arith(pArithDecoder, grContext, &ids); 204 BS = pDecoder->decode_Arith(pArithDecoder, grContext, &ids);
205 if (!BS) { 205 if (!BS) {
206 FX_Free(SBSYMS); 206 FX_Free(SBSYMS);
207 goto failed; 207 goto failed;
208 } 208 }
209 FX_Free(SBSYMS); 209 FX_Free(SBSYMS);
210 } else if (REFAGGNINST == 1) { 210 } else if (REFAGGNINST == 1) {
211 SBNUMSYMS = SDNUMINSYMS + NSYMSDECODED; 211 SBNUMSYMS = SDNUMINSYMS + NSYMSDECODED;
212 if (IAID->decode(pArithDecoder, (int*)&IDI) == -1) { 212 IAID->decode(pArithDecoder, reinterpret_cast<int*>(&IDI));
Tom Sepez 2015/09/29 17:46:36 Technically, an illegal cast, since there's no rea
Lei Zhang 2015/09/30 05:12:19 Done.
213 goto failed; 213 if (!IARDX->decode(pArithDecoder, &RDXI) ||
214 } 214 !IARDY->decode(pArithDecoder, &RDYI)) {
215 if ((IARDX->decode(pArithDecoder, &RDXI) == -1) ||
216 (IARDY->decode(pArithDecoder, &RDYI) == -1)) {
217 goto failed; 215 goto failed;
218 } 216 }
219 if (IDI >= SBNUMSYMS) { 217 if (IDI >= SBNUMSYMS) {
220 goto failed; 218 goto failed;
221 } 219 }
222 SBSYMS = FX_Alloc(CJBig2_Image*, SBNUMSYMS); 220 SBSYMS = FX_Alloc(CJBig2_Image*, SBNUMSYMS);
223 JBIG2_memcpy(SBSYMS, SDINSYMS, SDNUMINSYMS * sizeof(CJBig2_Image*)); 221 JBIG2_memcpy(SBSYMS, SDINSYMS, SDNUMINSYMS * sizeof(CJBig2_Image*));
224 JBIG2_memcpy(SBSYMS + SDNUMINSYMS, SDNEWSYMS, 222 JBIG2_memcpy(SBSYMS + SDNUMINSYMS, SDNEWSYMS,
225 NSYMSDECODED * sizeof(CJBig2_Image*)); 223 NSYMSDECODED * sizeof(CJBig2_Image*));
226 if (!SBSYMS[IDI]) { 224 if (!SBSYMS[IDI]) {
(...skipping 22 matching lines...) Expand all
249 } 247 }
250 SDNEWSYMS[NSYMSDECODED] = BS; 248 SDNEWSYMS[NSYMSDECODED] = BS;
251 BS = nullptr; 249 BS = nullptr;
252 NSYMSDECODED = NSYMSDECODED + 1; 250 NSYMSDECODED = NSYMSDECODED + 1;
253 } 251 }
254 } 252 }
255 EXINDEX = 0; 253 EXINDEX = 0;
256 CUREXFLAG = 0; 254 CUREXFLAG = 0;
257 EXFLAGS = FX_Alloc(FX_BOOL, SDNUMINSYMS + SDNUMNEWSYMS); 255 EXFLAGS = FX_Alloc(FX_BOOL, SDNUMINSYMS + SDNUMNEWSYMS);
258 while (EXINDEX < SDNUMINSYMS + SDNUMNEWSYMS) { 256 while (EXINDEX < SDNUMINSYMS + SDNUMNEWSYMS) {
259 if (IAEX->decode(pArithDecoder, (int*)&EXRUNLENGTH) == -1) { 257 if (!IAEX->decode(pArithDecoder, (int*)&EXRUNLENGTH)) {
260 FX_Free(EXFLAGS); 258 FX_Free(EXFLAGS);
261 goto failed; 259 goto failed;
262 } 260 }
263 if (EXINDEX + EXRUNLENGTH > SDNUMINSYMS + SDNUMNEWSYMS) { 261 if (EXINDEX + EXRUNLENGTH > SDNUMINSYMS + SDNUMNEWSYMS) {
264 FX_Free(EXFLAGS); 262 FX_Free(EXFLAGS);
265 goto failed; 263 goto failed;
266 } 264 }
267 if (EXRUNLENGTH != 0) { 265 if (EXRUNLENGTH != 0) {
268 for (I = EXINDEX; I < EXINDEX + EXRUNLENGTH; I++) { 266 for (I = EXINDEX; I < EXINDEX + EXRUNLENGTH; I++) {
269 EXFLAGS[I] = CUREXFLAG; 267 EXFLAGS[I] = CUREXFLAG;
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 failed: 640 failed:
643 for (I = 0; I < NSYMSDECODED; I++) { 641 for (I = 0; I < NSYMSDECODED; I++) {
644 delete SDNEWSYMS[I]; 642 delete SDNEWSYMS[I];
645 } 643 }
646 FX_Free(SDNEWSYMS); 644 FX_Free(SDNEWSYMS);
647 if (SDREFAGG == 0) { 645 if (SDREFAGG == 0) {
648 FX_Free(SDNEWSYMWIDTHS); 646 FX_Free(SDNEWSYMWIDTHS);
649 } 647 }
650 return nullptr; 648 return nullptr;
651 } 649 }
OLDNEW
« no previous file with comments | « core/src/fxcodec/jbig2/JBig2_ArithIntDecoder.cpp ('k') | core/src/fxcodec/jbig2/JBig2_TrdProc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698