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

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: rebase 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 17 matching lines...) Expand all
28 CJBig2_Image* BS; 28 CJBig2_Image* BS;
29 FX_DWORD I, J, REFAGGNINST; 29 FX_DWORD I, J, REFAGGNINST;
30 FX_BOOL* EXFLAGS; 30 FX_BOOL* EXFLAGS;
31 FX_DWORD EXINDEX; 31 FX_DWORD EXINDEX;
32 FX_BOOL CUREXFLAG; 32 FX_BOOL CUREXFLAG;
33 FX_DWORD EXRUNLENGTH; 33 FX_DWORD EXRUNLENGTH;
34 int32_t nVal; 34 int32_t nVal;
35 FX_DWORD nTmp; 35 FX_DWORD nTmp;
36 FX_DWORD SBNUMSYMS; 36 FX_DWORD SBNUMSYMS;
37 uint8_t SBSYMCODELEN; 37 uint8_t SBSYMCODELEN;
38 FX_DWORD IDI;
39 int32_t RDXI, RDYI; 38 int32_t RDXI, RDYI;
40 CJBig2_Image** SBSYMS; 39 CJBig2_Image** SBSYMS;
41 nonstd::unique_ptr<CJBig2_ArithIaidDecoder> IAID; 40 nonstd::unique_ptr<CJBig2_ArithIaidDecoder> IAID;
42 nonstd::unique_ptr<CJBig2_SymbolDict> pDict; 41 nonstd::unique_ptr<CJBig2_SymbolDict> pDict;
43 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IADH(new CJBig2_ArithIntDecoder); 42 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IADH(new CJBig2_ArithIntDecoder);
44 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IADW(new CJBig2_ArithIntDecoder); 43 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IADW(new CJBig2_ArithIntDecoder);
45 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IAAI(new CJBig2_ArithIntDecoder); 44 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IAAI(new CJBig2_ArithIntDecoder);
46 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IARDX(new CJBig2_ArithIntDecoder); 45 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IARDX(new CJBig2_ArithIntDecoder);
47 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IARDY(new CJBig2_ArithIntDecoder); 46 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IARDY(new CJBig2_ArithIntDecoder);
48 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IAEX(new CJBig2_ArithIntDecoder); 47 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IAEX(new CJBig2_ArithIntDecoder);
49 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IADT(new CJBig2_ArithIntDecoder); 48 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IADT(new CJBig2_ArithIntDecoder);
50 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IAFS(new CJBig2_ArithIntDecoder); 49 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IAFS(new CJBig2_ArithIntDecoder);
51 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IADS(new CJBig2_ArithIntDecoder); 50 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IADS(new CJBig2_ArithIntDecoder);
52 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IAIT(new CJBig2_ArithIntDecoder); 51 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IAIT(new CJBig2_ArithIntDecoder);
53 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IARI(new CJBig2_ArithIntDecoder); 52 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IARI(new CJBig2_ArithIntDecoder);
54 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IARDW(new CJBig2_ArithIntDecoder); 53 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IARDW(new CJBig2_ArithIntDecoder);
55 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IARDH(new CJBig2_ArithIntDecoder); 54 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IARDH(new CJBig2_ArithIntDecoder);
56 nTmp = 0; 55 nTmp = 0;
57 while ((FX_DWORD)(1 << nTmp) < (SDNUMINSYMS + SDNUMNEWSYMS)) { 56 while ((FX_DWORD)(1 << nTmp) < (SDNUMINSYMS + SDNUMNEWSYMS)) {
58 nTmp++; 57 nTmp++;
59 } 58 }
60 IAID.reset(new CJBig2_ArithIaidDecoder((uint8_t)nTmp)); 59 IAID.reset(new CJBig2_ArithIaidDecoder((uint8_t)nTmp));
61 SDNEWSYMS = FX_Alloc(CJBig2_Image*, SDNUMNEWSYMS); 60 SDNEWSYMS = FX_Alloc(CJBig2_Image*, SDNUMNEWSYMS);
62 FXSYS_memset(SDNEWSYMS, 0, SDNUMNEWSYMS * sizeof(CJBig2_Image*)); 61 FXSYS_memset(SDNEWSYMS, 0, SDNUMNEWSYMS * sizeof(CJBig2_Image*));
63 62
64 HCHEIGHT = 0; 63 HCHEIGHT = 0;
65 NSYMSDECODED = 0; 64 NSYMSDECODED = 0;
66 while (NSYMSDECODED < SDNUMNEWSYMS) { 65 while (NSYMSDECODED < SDNUMNEWSYMS) {
67 BS = nullptr; 66 BS = nullptr;
68 if (IADH->decode(pArithDecoder, &HCDH) == -1) { 67 if (!IADH->decode(pArithDecoder, &HCDH)) {
69 goto failed; 68 goto failed;
70 } 69 }
71 HCHEIGHT = HCHEIGHT + HCDH; 70 HCHEIGHT = HCHEIGHT + HCDH;
72 if ((int)HCHEIGHT < 0 || (int)HCHEIGHT > JBIG2_MAX_IMAGE_SIZE) { 71 if ((int)HCHEIGHT < 0 || (int)HCHEIGHT > JBIG2_MAX_IMAGE_SIZE) {
73 goto failed; 72 goto failed;
74 } 73 }
75 SYMWIDTH = 0; 74 SYMWIDTH = 0;
76 TOTWIDTH = 0; 75 TOTWIDTH = 0;
77 for (;;) { 76 for (;;) {
78 nVal = IADW->decode(pArithDecoder, &DW); 77 nVal = IADW->decode(pArithDecoder, &DW);
(...skipping 30 matching lines...) Expand all
109 pGRD->GBAT[3] = SDAT[3]; 108 pGRD->GBAT[3] = SDAT[3];
110 pGRD->GBAT[4] = SDAT[4]; 109 pGRD->GBAT[4] = SDAT[4];
111 pGRD->GBAT[5] = SDAT[5]; 110 pGRD->GBAT[5] = SDAT[5];
112 pGRD->GBAT[6] = SDAT[6]; 111 pGRD->GBAT[6] = SDAT[6];
113 pGRD->GBAT[7] = SDAT[7]; 112 pGRD->GBAT[7] = SDAT[7];
114 BS = pGRD->decode_Arith(pArithDecoder, gbContext); 113 BS = pGRD->decode_Arith(pArithDecoder, gbContext);
115 if (!BS) { 114 if (!BS) {
116 goto failed; 115 goto failed;
117 } 116 }
118 } else { 117 } else {
119 if (IAAI->decode(pArithDecoder, (int*)&REFAGGNINST) == -1) { 118 if (!IAAI->decode(pArithDecoder, (int*)&REFAGGNINST)) {
120 goto failed; 119 goto failed;
121 } 120 }
122 if (REFAGGNINST > 1) { 121 if (REFAGGNINST > 1) {
123 nonstd::unique_ptr<CJBig2_TRDProc> pDecoder(new CJBig2_TRDProc()); 122 nonstd::unique_ptr<CJBig2_TRDProc> pDecoder(new CJBig2_TRDProc());
124 pDecoder->SBHUFF = SDHUFF; 123 pDecoder->SBHUFF = SDHUFF;
125 pDecoder->SBREFINE = 1; 124 pDecoder->SBREFINE = 1;
126 pDecoder->SBW = SYMWIDTH; 125 pDecoder->SBW = SYMWIDTH;
127 pDecoder->SBH = HCHEIGHT; 126 pDecoder->SBH = HCHEIGHT;
128 pDecoder->SBNUMINSTANCES = REFAGGNINST; 127 pDecoder->SBNUMINSTANCES = REFAGGNINST;
129 pDecoder->SBSTRIPS = 1; 128 pDecoder->SBSTRIPS = 1;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 ids.IARDY = IARDY.get(); 201 ids.IARDY = IARDY.get();
203 ids.IAID = IAID.get(); 202 ids.IAID = IAID.get();
204 BS = pDecoder->decode_Arith(pArithDecoder, grContext, &ids); 203 BS = pDecoder->decode_Arith(pArithDecoder, grContext, &ids);
205 if (!BS) { 204 if (!BS) {
206 FX_Free(SBSYMS); 205 FX_Free(SBSYMS);
207 goto failed; 206 goto failed;
208 } 207 }
209 FX_Free(SBSYMS); 208 FX_Free(SBSYMS);
210 } else if (REFAGGNINST == 1) { 209 } else if (REFAGGNINST == 1) {
211 SBNUMSYMS = SDNUMINSYMS + NSYMSDECODED; 210 SBNUMSYMS = SDNUMINSYMS + NSYMSDECODED;
212 if (IAID->decode(pArithDecoder, (int*)&IDI) == -1) { 211 FX_DWORD IDI;
213 goto failed; 212 IAID->decode(pArithDecoder, &IDI);
214 } 213 if (!IARDX->decode(pArithDecoder, &RDXI) ||
215 if ((IARDX->decode(pArithDecoder, &RDXI) == -1) || 214 !IARDY->decode(pArithDecoder, &RDYI)) {
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