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

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

Issue 1400663003: Merge to XFA: Fix a malloc/delete mismatch introduced in commit 8a9ce57. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: 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 | « no previous file | core/src/fxcodec/jbig2/JBig2_List.h » ('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 #include "JBig2_List.h"
14 15
15 FX_DWORD* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, 16 FX_DWORD* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
16 JBig2ArithCtx* gbContext, 17 JBig2ArithCtx* gbContext,
17 IFX_Pause* pPause) { 18 IFX_Pause* pPause) {
18 nonstd::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc()); 19 nonstd::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc());
19 pGRD->MMR = GSMMR; 20 pGRD->MMR = GSMMR;
20 pGRD->GBW = GSW; 21 pGRD->GBW = GSW;
21 pGRD->GBH = GSH; 22 pGRD->GBH = GSH;
22 pGRD->GBTEMPLATE = GSTEMPLATE; 23 pGRD->GBTEMPLATE = GSTEMPLATE;
23 pGRD->TPGDON = 0; 24 pGRD->TPGDON = 0;
24 pGRD->USESKIP = GSUSESKIP; 25 pGRD->USESKIP = GSUSESKIP;
25 pGRD->SKIP = GSKIP; 26 pGRD->SKIP = GSKIP;
26 if (GSTEMPLATE <= 1) { 27 if (GSTEMPLATE <= 1) {
27 pGRD->GBAT[0] = 3; 28 pGRD->GBAT[0] = 3;
28 } else { 29 } else {
29 pGRD->GBAT[0] = 2; 30 pGRD->GBAT[0] = 2;
30 } 31 }
31 pGRD->GBAT[1] = -1; 32 pGRD->GBAT[1] = -1;
32 if (pGRD->GBTEMPLATE == 0) { 33 if (pGRD->GBTEMPLATE == 0) {
33 pGRD->GBAT[2] = -3; 34 pGRD->GBAT[2] = -3;
34 pGRD->GBAT[3] = -1; 35 pGRD->GBAT[3] = -1;
35 pGRD->GBAT[4] = 2; 36 pGRD->GBAT[4] = 2;
36 pGRD->GBAT[5] = -2; 37 pGRD->GBAT[5] = -2;
37 pGRD->GBAT[6] = -2; 38 pGRD->GBAT[6] = -2;
38 pGRD->GBAT[7] = -2; 39 pGRD->GBAT[7] = -2;
39 } 40 }
40 41
41 nonstd::unique_ptr<CJBig2_Image*, FxFreeDeleter> GSPLANES( 42 CJBig2_List<CJBig2_Image> GSPLANES(GSBPP);
42 FX_Alloc(CJBig2_Image*, GSBPP)); 43 for (int32_t i = GSBPP - 1; i >= 0; --i) {
43 JBIG2_memset(GSPLANES.get(), 0, sizeof(CJBig2_Image*) * GSBPP); 44 CJBig2_Image* pImage = nullptr;
44 FXCODEC_STATUS status = pGRD->Start_decode_Arith( 45 FXCODEC_STATUS status =
45 &GSPLANES.get()[GSBPP - 1], pArithDecoder, gbContext, nullptr); 46 pGRD->Start_decode_Arith(&pImage, pArithDecoder, gbContext, nullptr);
46 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { 47 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE)
47 pGRD->Continue_decode(pPause); 48 pGRD->Continue_decode(pPause);
48 }
49 if (!GSPLANES.get()[GSBPP - 1])
50 return nullptr;
51 49
52 int32_t J = GSBPP - 2; 50 if (!pImage)
53 while (J >= 0) { 51 return nullptr;
54 FXCODEC_STATUS status = pGRD->Start_decode_Arith( 52
55 &GSPLANES.get()[J], pArithDecoder, gbContext, nullptr); 53 GSPLANES.set(i, pImage);
56 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { 54
57 pGRD->Continue_decode(pPause); 55 if (i < GSBPP - 1)
58 } 56 pImage->composeFrom(0, 0, GSPLANES.get(i + 1), JBIG2_COMPOSE_XOR);
59 if (!GSPLANES.get()[J]) {
60 for (int32_t K = GSBPP - 1; K > J; --K) {
61 delete GSPLANES.get()[K];
62 return nullptr;
63 }
64 }
65 GSPLANES.get()[J]->composeFrom(0, 0, GSPLANES.get()[J + 1],
66 JBIG2_COMPOSE_XOR);
67 J = J - 1;
68 } 57 }
69 nonstd::unique_ptr<FX_DWORD, FxFreeDeleter> GSVALS( 58 nonstd::unique_ptr<FX_DWORD, FxFreeDeleter> GSVALS(
70 FX_Alloc2D(FX_DWORD, GSW, GSH)); 59 FX_Alloc2D(FX_DWORD, GSW, GSH));
71 JBIG2_memset(GSVALS.get(), 0, sizeof(FX_DWORD) * GSW * GSH); 60 JBIG2_memset(GSVALS.get(), 0, sizeof(FX_DWORD) * GSW * GSH);
72 for (FX_DWORD y = 0; y < GSH; ++y) { 61 for (FX_DWORD y = 0; y < GSH; ++y) {
73 for (FX_DWORD x = 0; x < GSW; ++x) { 62 for (FX_DWORD x = 0; x < GSW; ++x) {
74 for (J = 0; J < GSBPP; ++J) { 63 for (int32_t i = 0; i < GSBPP; ++i) {
75 GSVALS.get()[y * GSW + x] |= GSPLANES.get()[J]->getPixel(x, y) << J; 64 GSVALS.get()[y * GSW + x] |= GSPLANES.get(i)->getPixel(x, y) << i;
76 } 65 }
77 } 66 }
78 } 67 }
79 for (J = 0; J < GSBPP; ++J) {
80 delete GSPLANES.get()[J];
81 }
82 return GSVALS.release(); 68 return GSVALS.release();
83 } 69 }
84 70
85 FX_DWORD* CJBig2_GSIDProc::decode_MMR(CJBig2_BitStream* pStream, 71 FX_DWORD* CJBig2_GSIDProc::decode_MMR(CJBig2_BitStream* pStream,
86 IFX_Pause* pPause) { 72 IFX_Pause* pPause) {
87 nonstd::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc()); 73 nonstd::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc());
88 pGRD->MMR = GSMMR; 74 pGRD->MMR = GSMMR;
89 pGRD->GBW = GSW; 75 pGRD->GBW = GSW;
90 pGRD->GBH = GSH; 76 pGRD->GBH = GSH;
91 77
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 for (J = 0; J < GSBPP; ++J) { 113 for (J = 0; J < GSBPP; ++J) {
128 GSVALS.get()[y * GSW + x] |= GSPLANES.get()[J]->getPixel(x, y) << J; 114 GSVALS.get()[y * GSW + x] |= GSPLANES.get()[J]->getPixel(x, y) << J;
129 } 115 }
130 } 116 }
131 } 117 }
132 for (J = 0; J < GSBPP; ++J) { 118 for (J = 0; J < GSBPP; ++J) {
133 delete GSPLANES.get()[J]; 119 delete GSPLANES.get()[J];
134 } 120 }
135 return GSVALS.release(); 121 return GSVALS.release();
136 } 122 }
OLDNEW
« no previous file with comments | « no previous file | core/src/fxcodec/jbig2/JBig2_List.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698