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

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

Issue 1359233002: Split up JBig2_GeneralDecoder.cpp. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: revert bad changes, fix a nit 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
(Empty)
1 // Copyright 2014 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_ArithDecoder.h"
8
9 #include "../../../include/fxcrt/fx_basic.h"
10 #include "JBig2_BitStream.h"
11 #include "JBig2_Define.h"
12
13 namespace {
14
15 struct JBig2ArithQe {
16 unsigned int Qe;
17 unsigned int NMPS;
18 unsigned int NLPS;
19 unsigned int nSwitch;
20 };
21
22 const JBig2ArithQe kQeTable[] = {{0x5601, 1, 1, 1},
23 {0x3401, 2, 6, 0},
Tom Sepez 2015/09/23 23:03:34 nit: I hate you, clang_format. If you put a newli
Lei Zhang 2015/09/24 08:05:21 Done.
24 {0x1801, 3, 9, 0},
25 {0x0AC1, 4, 12, 0},
26 {0x0521, 5, 29, 0},
27 {0x0221, 38, 33, 0},
28 {0x5601, 7, 6, 1},
29 {0x5401, 8, 14, 0},
30 {0x4801, 9, 14, 0},
31 {0x3801, 10, 14, 0},
32 {0x3001, 11, 17, 0},
33 {0x2401, 12, 18, 0},
34 {0x1C01, 13, 20, 0},
35 {0x1601, 29, 21, 0},
36 {0x5601, 15, 14, 1},
37 {0x5401, 16, 14, 0},
38 {0x5101, 17, 15, 0},
39 {0x4801, 18, 16, 0},
40 {0x3801, 19, 17, 0},
41 {0x3401, 20, 18, 0},
42 {0x3001, 21, 19, 0},
43 {0x2801, 22, 19, 0},
44 {0x2401, 23, 20, 0},
45 {0x2201, 24, 21, 0},
46 {0x1C01, 25, 22, 0},
47 {0x1801, 26, 23, 0},
48 {0x1601, 27, 24, 0},
49 {0x1401, 28, 25, 0},
50 {0x1201, 29, 26, 0},
51 {0x1101, 30, 27, 0},
52 {0x0AC1, 31, 28, 0},
53 {0x09C1, 32, 29, 0},
54 {0x08A1, 33, 30, 0},
55 {0x0521, 34, 31, 0},
56 {0x0441, 35, 32, 0},
57 {0x02A1, 36, 33, 0},
58 {0x0221, 37, 34, 0},
59 {0x0141, 38, 35, 0},
60 {0x0111, 39, 36, 0},
61 {0x0085, 40, 37, 0},
62 {0x0049, 41, 38, 0},
63 {0x0025, 42, 39, 0},
64 {0x0015, 43, 40, 0},
65 {0x0009, 44, 41, 0},
66 {0x0005, 45, 42, 0},
67 {0x0001, 45, 43, 0},
68 {0x5601, 46, 46, 0}};
69
70 } // namespace
71
72 CJBig2_ArithDecoder::CJBig2_ArithDecoder(CJBig2_BitStream* pStream) {
73 m_pStream = pStream;
74 INITDEC();
75 }
76
77 CJBig2_ArithDecoder::~CJBig2_ArithDecoder() {
78 }
79
80 int CJBig2_ArithDecoder::DECODE(JBig2ArithCtx* pCX) {
81 if (!pCX || pCX->I >= FX_ArraySize(kQeTable)) {
82 return 0;
83 }
84
85 int D;
86 const JBig2ArithQe* qe = &kQeTable[pCX->I];
87 A = A - qe->Qe;
88 if ((C >> 16) < A) {
89 if (A & 0x8000) {
90 D = pCX->MPS;
91 } else {
92 if (A < qe->Qe) {
93 D = 1 - pCX->MPS;
94 if (qe->nSwitch == 1) {
95 pCX->MPS = 1 - pCX->MPS;
96 }
97 pCX->I = qe->NLPS;
98 } else {
99 D = pCX->MPS;
100 pCX->I = qe->NMPS;
101 }
102 do {
103 if (CT == 0) {
104 BYTEIN();
105 }
106 A <<= 1;
107 C <<= 1;
108 CT--;
109 } while ((A & 0x8000) == 0);
110 }
111 } else {
112 C -= A << 16;
113 if (A < qe->Qe) {
114 A = qe->Qe;
115 D = pCX->MPS;
116 pCX->I = qe->NMPS;
117 } else {
118 A = qe->Qe;
119 D = 1 - pCX->MPS;
120 if (qe->nSwitch == 1) {
121 pCX->MPS = 1 - pCX->MPS;
122 }
123 pCX->I = qe->NLPS;
124 }
125 do {
126 if (CT == 0) {
127 BYTEIN();
128 }
129 A <<= 1;
130 C <<= 1;
131 CT--;
132 } while ((A & 0x8000) == 0);
133 }
134 return D;
135 }
136
137 void CJBig2_ArithDecoder::INITDEC() {
138 B = m_pStream->getCurByte_arith();
139 C = (B ^ 0xff) << 16;
140 BYTEIN();
141 C = C << 7;
142 CT = CT - 7;
143 A = 0x8000;
144 }
145
146 void CJBig2_ArithDecoder::BYTEIN() {
147 unsigned char B1;
148 if (B == 0xff) {
149 B1 = m_pStream->getNextByte_arith();
150 if (B1 > 0x8f) {
151 CT = 8;
152 } else {
153 m_pStream->incByteIdx();
154 B = B1;
155 C = C + 0xfe00 - (B << 9);
156 CT = 7;
157 }
158 } else {
159 m_pStream->incByteIdx();
160 B = m_pStream->getCurByte_arith();
161 C = C + 0xff00 - (B << 8);
162 CT = 8;
163 }
164 }
OLDNEW
« no previous file with comments | « core/src/fxcodec/jbig2/JBig2_ArithDecoder.h ('k') | core/src/fxcodec/jbig2/JBig2_ArithIntDecoder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698