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

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

Issue 1359233002: Split up JBig2_GeneralDecoder.cpp. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@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
« no previous file with comments | « core/src/fxcodec/jbig2/JBig2_GsidProc.h ('k') | core/src/fxcodec/jbig2/JBig2_HtrdProc.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "JBig2_GsidProc.h"
8
9 #include "../../../../third_party/base/nonstd_unique_ptr.h"
10 #include "../../../include/fxcrt/fx_basic.h"
11 #include "JBig2_BitStream.h"
12 #include "JBig2_GrdProc.h"
13 #include "JBig2_Image.h"
14
15 FX_DWORD* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
16 JBig2ArithCtx* gbContext,
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());
28 pGRD->MMR = GSMMR;
29 pGRD->GBW = GSW;
30 pGRD->GBH = GSH;
31 pGRD->GBTEMPLATE = GSTEMPLATE;
32 pGRD->TPGDON = 0;
33 pGRD->USESKIP = GSUSESKIP;
34 pGRD->SKIP = GSKIP;
35 if (GSTEMPLATE <= 1) {
36 pGRD->GBAT[0] = 3;
37 } else {
38 pGRD->GBAT[0] = 2;
39 }
40 pGRD->GBAT[1] = -1;
41 if (pGRD->GBTEMPLATE == 0) {
42 pGRD->GBAT[2] = -3;
43 pGRD->GBAT[3] = -1;
44 pGRD->GBAT[4] = 2;
45 pGRD->GBAT[5] = -2;
46 pGRD->GBAT[6] = -2;
47 pGRD->GBAT[7] = -2;
48 }
49 FXCODEC_STATUS status = pGRD->Start_decode_Arith(
50 &GSPLANES[GSBPP - 1], pArithDecoder, gbContext, nullptr);
51 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) {
52 pGRD->Continue_decode(pPause);
53 }
54 if (!GSPLANES[GSBPP - 1]) {
55 goto failed;
56 }
57 J = GSBPP - 2;
58 while (J >= 0) {
59 FXCODEC_STATUS status = pGRD->Start_decode_Arith(
60 &GSPLANES[J], pArithDecoder, gbContext, nullptr);
61 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) {
62 pGRD->Continue_decode(pPause);
63 }
64 if (!GSPLANES[J]) {
65 for (K = GSBPP - 1; K > J; K--) {
66 delete GSPLANES[K];
67 goto failed;
68 }
69 }
70 GSPLANES[J]->composeFrom(0, 0, GSPLANES[J + 1], JBIG2_COMPOSE_XOR);
71 J = J - 1;
72 }
73 for (y = 0; y < GSH; y++) {
74 for (x = 0; x < GSW; x++) {
75 for (J = 0; J < GSBPP; J++) {
76 GSVALS[y * GSW + x] |= GSPLANES[J]->getPixel(x, y) << J;
77 }
78 }
79 }
80 for (J = 0; J < GSBPP; J++) {
81 delete GSPLANES[J];
82 }
83 FX_Free(GSPLANES);
84 return GSVALS;
85 failed:
86 FX_Free(GSPLANES);
87 FX_Free(GSVALS);
88 return nullptr;
89 }
90
91 FX_DWORD* CJBig2_GSIDProc::decode_MMR(CJBig2_BitStream* pStream,
92 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());
103 pGRD->MMR = GSMMR;
104 pGRD->GBW = GSW;
105 pGRD->GBH = GSH;
106 FXCODEC_STATUS status =
107 pGRD->Start_decode_MMR(&GSPLANES[GSBPP - 1], pStream, nullptr);
108 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) {
109 pGRD->Continue_decode(pPause);
110 }
111 if (!GSPLANES[GSBPP - 1]) {
112 goto failed;
113 }
114 pStream->alignByte();
115 pStream->offset(3);
116 J = GSBPP - 2;
117 while (J >= 0) {
118 FXCODEC_STATUS status =
119 pGRD->Start_decode_MMR(&GSPLANES[J], pStream, nullptr);
120 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) {
121 pGRD->Continue_decode(pPause);
122 }
123 if (!GSPLANES[J]) {
124 for (K = GSBPP - 1; K > J; K--) {
125 delete GSPLANES[K];
126 goto failed;
127 }
128 }
129 pStream->alignByte();
130 pStream->offset(3);
131 GSPLANES[J]->composeFrom(0, 0, GSPLANES[J + 1], JBIG2_COMPOSE_XOR);
132 J = J - 1;
133 }
134 for (y = 0; y < GSH; y++) {
135 for (x = 0; x < GSW; x++) {
136 for (J = 0; J < GSBPP; J++) {
137 GSVALS[y * GSW + x] |= GSPLANES[J]->getPixel(x, y) << J;
138 }
139 }
140 }
141 for (J = 0; J < GSBPP; J++) {
142 delete GSPLANES[J];
143 }
144 FX_Free(GSPLANES);
145 return GSVALS;
146 failed:
147 FX_Free(GSPLANES);
148 FX_Free(GSVALS);
149 return nullptr;
150 }
OLDNEW
« no previous file with comments | « core/src/fxcodec/jbig2/JBig2_GsidProc.h ('k') | core/src/fxcodec/jbig2/JBig2_HtrdProc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698