OLD | NEW |
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 "core/fxcodec/jbig2/JBig2_GrrdProc.h" | 7 #include "core/fxcodec/jbig2/JBig2_GrrdProc.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 } | 27 } |
28 | 28 |
29 if ((GRREFERENCEDX == 0) && (GRW == (uint32_t)GRREFERENCE->m_nWidth)) | 29 if ((GRREFERENCEDX == 0) && (GRW == (uint32_t)GRREFERENCE->m_nWidth)) |
30 return decode_Template1_opt(pArithDecoder, grContext); | 30 return decode_Template1_opt(pArithDecoder, grContext); |
31 return decode_Template1_unopt(pArithDecoder, grContext); | 31 return decode_Template1_unopt(pArithDecoder, grContext); |
32 } | 32 } |
33 | 33 |
34 CJBig2_Image* CJBig2_GRRDProc::decode_Template0_unopt( | 34 CJBig2_Image* CJBig2_GRRDProc::decode_Template0_unopt( |
35 CJBig2_ArithDecoder* pArithDecoder, | 35 CJBig2_ArithDecoder* pArithDecoder, |
36 JBig2ArithCtx* grContext) { | 36 JBig2ArithCtx* grContext) { |
37 FX_BOOL LTP, SLTP, bVal; | 37 FX_BOOL LTP = FALSE; |
38 uint32_t CONTEXT; | |
39 uint32_t line1, line2, line3, line4, line5; | |
40 LTP = 0; | |
41 std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(GRW, GRH)); | 38 std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(GRW, GRH)); |
42 GRREG->fill(0); | 39 GRREG->fill(0); |
43 for (uint32_t h = 0; h < GRH; h++) { | 40 for (uint32_t h = 0; h < GRH; h++) { |
44 if (TPGRON) { | 41 if (TPGRON) |
45 SLTP = pArithDecoder->DECODE(&grContext[0x0010]); | 42 LTP = LTP ^ pArithDecoder->DECODE(&grContext[0x0010]); |
46 LTP = LTP ^ SLTP; | 43 if (!LTP) { |
47 } | 44 uint32_t line1 = GRREG->getPixel(1, h - 1); |
48 if (LTP == 0) { | |
49 line1 = GRREG->getPixel(1, h - 1); | |
50 line1 |= GRREG->getPixel(0, h - 1) << 1; | 45 line1 |= GRREG->getPixel(0, h - 1) << 1; |
51 line2 = 0; | 46 uint32_t line2 = 0; |
52 line3 = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY - 1); | 47 uint32_t line3 = |
| 48 GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY - 1); |
53 line3 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY - 1) | 49 line3 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY - 1) |
54 << 1; | 50 << 1; |
55 line4 = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY); | 51 uint32_t line4 = |
| 52 GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY); |
56 line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY) << 1; | 53 line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY) << 1; |
57 line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY) | 54 line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY) |
58 << 2; | 55 << 2; |
59 line5 = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY + 1); | 56 uint32_t line5 = |
| 57 GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY + 1); |
60 line5 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY + 1) | 58 line5 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY + 1) |
61 << 1; | 59 << 1; |
62 line5 |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY + 1) | 60 line5 |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY + 1) |
63 << 2; | 61 << 2; |
64 for (uint32_t w = 0; w < GRW; w++) { | 62 for (uint32_t w = 0; w < GRW; w++) { |
65 CONTEXT = line5; | 63 uint32_t CONTEXT = line5; |
66 CONTEXT |= line4 << 3; | 64 CONTEXT |= line4 << 3; |
67 CONTEXT |= line3 << 6; | 65 CONTEXT |= line3 << 6; |
68 CONTEXT |= GRREFERENCE->getPixel(w - GRREFERENCEDX + GRAT[2], | 66 CONTEXT |= GRREFERENCE->getPixel(w - GRREFERENCEDX + GRAT[2], |
69 h - GRREFERENCEDY + GRAT[3]) | 67 h - GRREFERENCEDY + GRAT[3]) |
70 << 8; | 68 << 8; |
71 CONTEXT |= line2 << 9; | 69 CONTEXT |= line2 << 9; |
72 CONTEXT |= line1 << 10; | 70 CONTEXT |= line1 << 10; |
73 CONTEXT |= GRREG->getPixel(w + GRAT[0], h + GRAT[1]) << 12; | 71 CONTEXT |= GRREG->getPixel(w + GRAT[0], h + GRAT[1]) << 12; |
74 bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); | 72 FX_BOOL bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); |
75 GRREG->setPixel(w, h, bVal); | 73 GRREG->setPixel(w, h, bVal); |
76 line1 = ((line1 << 1) | GRREG->getPixel(w + 2, h - 1)) & 0x03; | 74 line1 = ((line1 << 1) | GRREG->getPixel(w + 2, h - 1)) & 0x03; |
77 line2 = ((line2 << 1) | bVal) & 0x01; | 75 line2 = ((line2 << 1) | bVal) & 0x01; |
78 line3 = ((line3 << 1) | | 76 line3 = ((line3 << 1) | |
79 GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, | 77 GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, |
80 h - GRREFERENCEDY - 1)) & | 78 h - GRREFERENCEDY - 1)) & |
81 0x03; | 79 0x03; |
82 line4 = | 80 line4 = |
83 ((line4 << 1) | | 81 ((line4 << 1) | |
84 GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, h - GRREFERENCEDY)) & | 82 GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, h - GRREFERENCEDY)) & |
85 0x07; | 83 0x07; |
86 line5 = ((line5 << 1) | | 84 line5 = ((line5 << 1) | |
87 GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, | 85 GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, |
88 h - GRREFERENCEDY + 1)) & | 86 h - GRREFERENCEDY + 1)) & |
89 0x07; | 87 0x07; |
90 } | 88 } |
91 } else { | 89 } else { |
92 line1 = GRREG->getPixel(1, h - 1); | 90 uint32_t line1 = GRREG->getPixel(1, h - 1); |
93 line1 |= GRREG->getPixel(0, h - 1) << 1; | 91 line1 |= GRREG->getPixel(0, h - 1) << 1; |
94 line2 = 0; | 92 uint32_t line2 = 0; |
95 line3 = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY - 1); | 93 uint32_t line3 = |
| 94 GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY - 1); |
96 line3 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY - 1) | 95 line3 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY - 1) |
97 << 1; | 96 << 1; |
98 line4 = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY); | 97 uint32_t line4 = |
| 98 GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY); |
99 line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY) << 1; | 99 line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY) << 1; |
100 line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY) | 100 line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY) |
101 << 2; | 101 << 2; |
102 line5 = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY + 1); | 102 uint32_t line5 = |
| 103 GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY + 1); |
103 line5 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY + 1) | 104 line5 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY + 1) |
104 << 1; | 105 << 1; |
105 line5 |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY + 1) | 106 line5 |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY + 1) |
106 << 2; | 107 << 2; |
107 for (uint32_t w = 0; w < GRW; w++) { | 108 for (uint32_t w = 0; w < GRW; w++) { |
108 bVal = GRREFERENCE->getPixel(w, h); | 109 FX_BOOL bVal = GRREFERENCE->getPixel(w, h); |
109 if (!(TPGRON && (bVal == GRREFERENCE->getPixel(w - 1, h - 1)) && | 110 if (!(TPGRON && (bVal == GRREFERENCE->getPixel(w - 1, h - 1)) && |
110 (bVal == GRREFERENCE->getPixel(w, h - 1)) && | 111 (bVal == GRREFERENCE->getPixel(w, h - 1)) && |
111 (bVal == GRREFERENCE->getPixel(w + 1, h - 1)) && | 112 (bVal == GRREFERENCE->getPixel(w + 1, h - 1)) && |
112 (bVal == GRREFERENCE->getPixel(w - 1, h)) && | 113 (bVal == GRREFERENCE->getPixel(w - 1, h)) && |
113 (bVal == GRREFERENCE->getPixel(w + 1, h)) && | 114 (bVal == GRREFERENCE->getPixel(w + 1, h)) && |
114 (bVal == GRREFERENCE->getPixel(w - 1, h + 1)) && | 115 (bVal == GRREFERENCE->getPixel(w - 1, h + 1)) && |
115 (bVal == GRREFERENCE->getPixel(w, h + 1)) && | 116 (bVal == GRREFERENCE->getPixel(w, h + 1)) && |
116 (bVal == GRREFERENCE->getPixel(w + 1, h + 1)))) { | 117 (bVal == GRREFERENCE->getPixel(w + 1, h + 1)))) { |
117 CONTEXT = line5; | 118 uint32_t CONTEXT = line5; |
118 CONTEXT |= line4 << 3; | 119 CONTEXT |= line4 << 3; |
119 CONTEXT |= line3 << 6; | 120 CONTEXT |= line3 << 6; |
120 CONTEXT |= GRREFERENCE->getPixel(w - GRREFERENCEDX + GRAT[2], | 121 CONTEXT |= GRREFERENCE->getPixel(w - GRREFERENCEDX + GRAT[2], |
121 h - GRREFERENCEDY + GRAT[3]) | 122 h - GRREFERENCEDY + GRAT[3]) |
122 << 8; | 123 << 8; |
123 CONTEXT |= line2 << 9; | 124 CONTEXT |= line2 << 9; |
124 CONTEXT |= line1 << 10; | 125 CONTEXT |= line1 << 10; |
125 CONTEXT |= GRREG->getPixel(w + GRAT[0], h + GRAT[1]) << 12; | 126 CONTEXT |= GRREG->getPixel(w + GRAT[0], h + GRAT[1]) << 12; |
126 bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); | 127 bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); |
127 } | 128 } |
(...skipping 17 matching lines...) Expand all Loading... |
145 } | 146 } |
146 return GRREG.release(); | 147 return GRREG.release(); |
147 } | 148 } |
148 | 149 |
149 CJBig2_Image* CJBig2_GRRDProc::decode_Template0_opt( | 150 CJBig2_Image* CJBig2_GRRDProc::decode_Template0_opt( |
150 CJBig2_ArithDecoder* pArithDecoder, | 151 CJBig2_ArithDecoder* pArithDecoder, |
151 JBig2ArithCtx* grContext) { | 152 JBig2ArithCtx* grContext) { |
152 if (!GRREFERENCE->m_pData) | 153 if (!GRREFERENCE->m_pData) |
153 return nullptr; | 154 return nullptr; |
154 | 155 |
155 FX_BOOL LTP, SLTP, bVal; | 156 int32_t iGRW = static_cast<int32_t>(GRW); |
156 uint32_t CONTEXT; | 157 int32_t iGRH = static_cast<int32_t>(GRH); |
157 uint32_t line1, line1_r, line2_r, line3_r; | 158 std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(iGRW, iGRH)); |
158 uint8_t *pLine, *pLineR, cVal; | |
159 intptr_t nStride, nStrideR, nOffset; | |
160 int32_t k, nBits; | |
161 int32_t GRWR, GRHR; | |
162 int32_t GRW, GRH; | |
163 GRW = (int32_t)CJBig2_GRRDProc::GRW; | |
164 GRH = (int32_t)CJBig2_GRRDProc::GRH; | |
165 LTP = 0; | |
166 std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(GRW, GRH)); | |
167 if (!GRREG->m_pData) | 159 if (!GRREG->m_pData) |
168 return nullptr; | 160 return nullptr; |
169 | 161 |
170 pLine = GRREG->m_pData; | 162 FX_BOOL LTP = FALSE; |
171 pLineR = GRREFERENCE->m_pData; | 163 uint8_t* pLine = GRREG->m_pData; |
172 nStride = GRREG->m_nStride; | 164 uint8_t* pLineR = GRREFERENCE->m_pData; |
173 nStrideR = GRREFERENCE->m_nStride; | 165 intptr_t nStride = GRREG->m_nStride; |
174 GRWR = (int32_t)GRREFERENCE->m_nWidth; | 166 intptr_t nStrideR = GRREFERENCE->m_nStride; |
175 GRHR = (int32_t)GRREFERENCE->m_nHeight; | 167 int32_t GRWR = GRREFERENCE->m_nWidth; |
176 if (GRREFERENCEDY < -GRHR + 1 || GRREFERENCEDY > GRHR - 1) { | 168 int32_t GRHR = GRREFERENCE->m_nHeight; |
| 169 if (GRREFERENCEDY < -GRHR + 1 || GRREFERENCEDY > GRHR - 1) |
177 GRREFERENCEDY = 0; | 170 GRREFERENCEDY = 0; |
178 } | 171 intptr_t nOffset = -GRREFERENCEDY * nStrideR; |
179 nOffset = -GRREFERENCEDY * nStrideR; | 172 for (int32_t h = 0; h < iGRH; h++) { |
180 for (int32_t h = 0; h < GRH; h++) { | 173 if (TPGRON) |
181 if (TPGRON) { | 174 LTP = LTP ^ pArithDecoder->DECODE(&grContext[0x0010]); |
182 SLTP = pArithDecoder->DECODE(&grContext[0x0010]); | 175 uint32_t line1 = (h > 0) ? pLine[-nStride] << 4 : 0; |
183 LTP = LTP ^ SLTP; | |
184 } | |
185 line1 = (h > 0) ? pLine[-nStride] << 4 : 0; | |
186 int32_t reference_h = h - GRREFERENCEDY; | 176 int32_t reference_h = h - GRREFERENCEDY; |
187 FX_BOOL line1_r_ok = (reference_h > 0 && reference_h < GRHR + 1); | 177 FX_BOOL line1_r_ok = (reference_h > 0 && reference_h < GRHR + 1); |
188 FX_BOOL line2_r_ok = (reference_h > -1 && reference_h < GRHR); | 178 FX_BOOL line2_r_ok = (reference_h > -1 && reference_h < GRHR); |
189 FX_BOOL line3_r_ok = (reference_h > -2 && reference_h < GRHR - 1); | 179 FX_BOOL line3_r_ok = (reference_h > -2 && reference_h < GRHR - 1); |
190 line1_r = line1_r_ok ? pLineR[nOffset - nStrideR] : 0; | 180 uint32_t line1_r = line1_r_ok ? pLineR[nOffset - nStrideR] : 0; |
191 line2_r = line2_r_ok ? pLineR[nOffset] : 0; | 181 uint32_t line2_r = line2_r_ok ? pLineR[nOffset] : 0; |
192 line3_r = line3_r_ok ? pLineR[nOffset + nStrideR] : 0; | 182 uint32_t line3_r = line3_r_ok ? pLineR[nOffset + nStrideR] : 0; |
193 if (LTP == 0) { | 183 if (!LTP) { |
194 CONTEXT = (line1 & 0x1c00) | (line1_r & 0x01c0) | | 184 uint32_t CONTEXT = (line1 & 0x1c00) | (line1_r & 0x01c0) | |
195 ((line2_r >> 3) & 0x0038) | ((line3_r >> 6) & 0x0007); | 185 ((line2_r >> 3) & 0x0038) | ((line3_r >> 6) & 0x0007); |
196 for (int32_t w = 0; w < GRW; w += 8) { | 186 for (int32_t w = 0; w < iGRW; w += 8) { |
197 nBits = GRW - w > 8 ? 8 : GRW - w; | 187 int32_t nBits = iGRW - w > 8 ? 8 : iGRW - w; |
198 if (h > 0) | 188 if (h > 0) { |
199 line1 = (line1 << 8) | | 189 line1 = (line1 << 8) | |
200 (w + 8 < GRW ? pLine[-nStride + (w >> 3) + 1] << 4 : 0); | 190 (w + 8 < iGRW ? pLine[-nStride + (w >> 3) + 1] << 4 : 0); |
| 191 } |
201 if (h > GRHR + GRREFERENCEDY + 1) { | 192 if (h > GRHR + GRREFERENCEDY + 1) { |
202 line1_r = 0; | 193 line1_r = 0; |
203 line2_r = 0; | 194 line2_r = 0; |
204 line3_r = 0; | 195 line3_r = 0; |
205 } else { | 196 } else { |
206 if (line1_r_ok) | 197 if (line1_r_ok) { |
207 line1_r = | 198 line1_r = |
208 (line1_r << 8) | | 199 (line1_r << 8) | |
209 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); | 200 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); |
210 if (line2_r_ok) | 201 } |
| 202 if (line2_r_ok) { |
211 line2_r = (line2_r << 8) | | 203 line2_r = (line2_r << 8) | |
212 (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); | 204 (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); |
| 205 } |
213 if (line3_r_ok) { | 206 if (line3_r_ok) { |
214 line3_r = | 207 line3_r = |
215 (line3_r << 8) | | 208 (line3_r << 8) | |
216 (w + 8 < GRWR ? pLineR[nOffset + nStrideR + (w >> 3) + 1] : 0); | 209 (w + 8 < GRWR ? pLineR[nOffset + nStrideR + (w >> 3) + 1] : 0); |
217 } else { | 210 } else { |
218 line3_r = 0; | 211 line3_r = 0; |
219 } | 212 } |
220 } | 213 } |
221 cVal = 0; | 214 uint8_t cVal = 0; |
222 for (k = 0; k < nBits; k++) { | 215 for (int32_t k = 0; k < nBits; k++) { |
223 bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); | 216 FX_BOOL bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); |
224 cVal |= bVal << (7 - k); | 217 cVal |= bVal << (7 - k); |
225 CONTEXT = ((CONTEXT & 0x0cdb) << 1) | (bVal << 9) | | 218 CONTEXT = ((CONTEXT & 0x0cdb) << 1) | (bVal << 9) | |
226 ((line1 >> (7 - k)) & 0x0400) | | 219 ((line1 >> (7 - k)) & 0x0400) | |
227 ((line1_r >> (7 - k)) & 0x0040) | | 220 ((line1_r >> (7 - k)) & 0x0040) | |
228 ((line2_r >> (10 - k)) & 0x0008) | | 221 ((line2_r >> (10 - k)) & 0x0008) | |
229 ((line3_r >> (13 - k)) & 0x0001); | 222 ((line3_r >> (13 - k)) & 0x0001); |
230 } | 223 } |
231 pLine[w >> 3] = cVal; | 224 pLine[w >> 3] = cVal; |
232 } | 225 } |
233 } else { | 226 } else { |
234 CONTEXT = (line1 & 0x1c00) | (line1_r & 0x01c0) | | 227 uint32_t CONTEXT = (line1 & 0x1c00) | (line1_r & 0x01c0) | |
235 ((line2_r >> 3) & 0x0038) | ((line3_r >> 6) & 0x0007); | 228 ((line2_r >> 3) & 0x0038) | ((line3_r >> 6) & 0x0007); |
236 for (int32_t w = 0; w < GRW; w += 8) { | 229 for (int32_t w = 0; w < iGRW; w += 8) { |
237 nBits = GRW - w > 8 ? 8 : GRW - w; | 230 int32_t nBits = iGRW - w > 8 ? 8 : iGRW - w; |
238 if (h > 0) | 231 if (h > 0) { |
239 line1 = (line1 << 8) | | 232 line1 = (line1 << 8) | |
240 (w + 8 < GRW ? pLine[-nStride + (w >> 3) + 1] << 4 : 0); | 233 (w + 8 < iGRW ? pLine[-nStride + (w >> 3) + 1] << 4 : 0); |
241 if (line1_r_ok) | 234 } |
| 235 if (line1_r_ok) { |
242 line1_r = | 236 line1_r = |
243 (line1_r << 8) | | 237 (line1_r << 8) | |
244 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); | 238 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); |
245 if (line2_r_ok) | 239 } |
| 240 if (line2_r_ok) { |
246 line2_r = (line2_r << 8) | | 241 line2_r = (line2_r << 8) | |
247 (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); | 242 (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); |
| 243 } |
248 if (line3_r_ok) { | 244 if (line3_r_ok) { |
249 line3_r = | 245 line3_r = |
250 (line3_r << 8) | | 246 (line3_r << 8) | |
251 (w + 8 < GRWR ? pLineR[nOffset + nStrideR + (w >> 3) + 1] : 0); | 247 (w + 8 < GRWR ? pLineR[nOffset + nStrideR + (w >> 3) + 1] : 0); |
252 } else { | 248 } else { |
253 line3_r = 0; | 249 line3_r = 0; |
254 } | 250 } |
255 cVal = 0; | 251 uint8_t cVal = 0; |
256 for (k = 0; k < nBits; k++) { | 252 for (int32_t k = 0; k < nBits; k++) { |
257 bVal = GRREFERENCE->getPixel(w + k, h); | 253 FX_BOOL bVal = GRREFERENCE->getPixel(w + k, h); |
258 if (!(TPGRON && (bVal == GRREFERENCE->getPixel(w + k - 1, h - 1)) && | 254 if (!(TPGRON && (bVal == GRREFERENCE->getPixel(w + k - 1, h - 1)) && |
259 (bVal == GRREFERENCE->getPixel(w + k, h - 1)) && | 255 (bVal == GRREFERENCE->getPixel(w + k, h - 1)) && |
260 (bVal == GRREFERENCE->getPixel(w + k + 1, h - 1)) && | 256 (bVal == GRREFERENCE->getPixel(w + k + 1, h - 1)) && |
261 (bVal == GRREFERENCE->getPixel(w + k - 1, h)) && | 257 (bVal == GRREFERENCE->getPixel(w + k - 1, h)) && |
262 (bVal == GRREFERENCE->getPixel(w + k + 1, h)) && | 258 (bVal == GRREFERENCE->getPixel(w + k + 1, h)) && |
263 (bVal == GRREFERENCE->getPixel(w + k - 1, h + 1)) && | 259 (bVal == GRREFERENCE->getPixel(w + k - 1, h + 1)) && |
264 (bVal == GRREFERENCE->getPixel(w + k, h + 1)) && | 260 (bVal == GRREFERENCE->getPixel(w + k, h + 1)) && |
265 (bVal == GRREFERENCE->getPixel(w + k + 1, h + 1)))) { | 261 (bVal == GRREFERENCE->getPixel(w + k + 1, h + 1)))) { |
266 bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); | 262 bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); |
267 } | 263 } |
(...skipping 11 matching lines...) Expand all Loading... |
279 if (h < GRHR + GRREFERENCEDY) { | 275 if (h < GRHR + GRREFERENCEDY) { |
280 pLineR += nStrideR; | 276 pLineR += nStrideR; |
281 } | 277 } |
282 } | 278 } |
283 return GRREG.release(); | 279 return GRREG.release(); |
284 } | 280 } |
285 | 281 |
286 CJBig2_Image* CJBig2_GRRDProc::decode_Template1_unopt( | 282 CJBig2_Image* CJBig2_GRRDProc::decode_Template1_unopt( |
287 CJBig2_ArithDecoder* pArithDecoder, | 283 CJBig2_ArithDecoder* pArithDecoder, |
288 JBig2ArithCtx* grContext) { | 284 JBig2ArithCtx* grContext) { |
289 FX_BOOL LTP, SLTP, bVal; | 285 FX_BOOL LTP = FALSE; |
290 uint32_t CONTEXT; | |
291 uint32_t line1, line2, line3, line4, line5; | |
292 LTP = 0; | |
293 std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(GRW, GRH)); | 286 std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(GRW, GRH)); |
294 GRREG->fill(0); | 287 GRREG->fill(0); |
295 for (uint32_t h = 0; h < GRH; h++) { | 288 for (uint32_t h = 0; h < GRH; h++) { |
296 if (TPGRON) { | 289 if (TPGRON) |
297 SLTP = pArithDecoder->DECODE(&grContext[0x0008]); | 290 LTP = LTP ^ pArithDecoder->DECODE(&grContext[0x0008]); |
298 LTP = LTP ^ SLTP; | 291 if (!LTP) { |
299 } | 292 uint32_t line1 = GRREG->getPixel(1, h - 1); |
300 if (LTP == 0) { | |
301 line1 = GRREG->getPixel(1, h - 1); | |
302 line1 |= GRREG->getPixel(0, h - 1) << 1; | 293 line1 |= GRREG->getPixel(0, h - 1) << 1; |
303 line1 |= GRREG->getPixel(-1, h - 1) << 2; | 294 line1 |= GRREG->getPixel(-1, h - 1) << 2; |
304 line2 = 0; | 295 uint32_t line2 = 0; |
305 line3 = GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY - 1); | 296 uint32_t line3 = |
306 line4 = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY); | 297 GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY - 1); |
| 298 uint32_t line4 = |
| 299 GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY); |
307 line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY) << 1; | 300 line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY) << 1; |
308 line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY) | 301 line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY) |
309 << 2; | 302 << 2; |
310 line5 = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY + 1); | 303 uint32_t line5 = |
| 304 GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY + 1); |
311 line5 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY + 1) | 305 line5 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY + 1) |
312 << 1; | 306 << 1; |
313 for (uint32_t w = 0; w < GRW; w++) { | 307 for (uint32_t w = 0; w < GRW; w++) { |
314 CONTEXT = line5; | 308 uint32_t CONTEXT = line5; |
315 CONTEXT |= line4 << 2; | 309 CONTEXT |= line4 << 2; |
316 CONTEXT |= line3 << 5; | 310 CONTEXT |= line3 << 5; |
317 CONTEXT |= line2 << 6; | 311 CONTEXT |= line2 << 6; |
318 CONTEXT |= line1 << 7; | 312 CONTEXT |= line1 << 7; |
319 bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); | 313 FX_BOOL bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); |
320 GRREG->setPixel(w, h, bVal); | 314 GRREG->setPixel(w, h, bVal); |
321 line1 = ((line1 << 1) | GRREG->getPixel(w + 2, h - 1)) & 0x07; | 315 line1 = ((line1 << 1) | GRREG->getPixel(w + 2, h - 1)) & 0x07; |
322 line2 = ((line2 << 1) | bVal) & 0x01; | 316 line2 = ((line2 << 1) | bVal) & 0x01; |
323 line3 = ((line3 << 1) | | 317 line3 = ((line3 << 1) | |
324 GRREFERENCE->getPixel(w - GRREFERENCEDX + 1, | 318 GRREFERENCE->getPixel(w - GRREFERENCEDX + 1, |
325 h - GRREFERENCEDY - 1)) & | 319 h - GRREFERENCEDY - 1)) & |
326 0x01; | 320 0x01; |
327 line4 = | 321 line4 = |
328 ((line4 << 1) | | 322 ((line4 << 1) | |
329 GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, h - GRREFERENCEDY)) & | 323 GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, h - GRREFERENCEDY)) & |
330 0x07; | 324 0x07; |
331 line5 = ((line5 << 1) | | 325 line5 = ((line5 << 1) | |
332 GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, | 326 GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, |
333 h - GRREFERENCEDY + 1)) & | 327 h - GRREFERENCEDY + 1)) & |
334 0x03; | 328 0x03; |
335 } | 329 } |
336 } else { | 330 } else { |
337 line1 = GRREG->getPixel(1, h - 1); | 331 uint32_t line1 = GRREG->getPixel(1, h - 1); |
338 line1 |= GRREG->getPixel(0, h - 1) << 1; | 332 line1 |= GRREG->getPixel(0, h - 1) << 1; |
339 line1 |= GRREG->getPixel(-1, h - 1) << 2; | 333 line1 |= GRREG->getPixel(-1, h - 1) << 2; |
340 line2 = 0; | 334 uint32_t line2 = 0; |
341 line3 = GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY - 1); | 335 uint32_t line3 = |
342 line4 = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY); | 336 GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY - 1); |
| 337 uint32_t line4 = |
| 338 GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY); |
343 line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY) << 1; | 339 line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY) << 1; |
344 line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY) | 340 line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY) |
345 << 2; | 341 << 2; |
346 line5 = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY + 1); | 342 uint32_t line5 = |
| 343 GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY + 1); |
347 line5 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY + 1) | 344 line5 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY + 1) |
348 << 1; | 345 << 1; |
349 for (uint32_t w = 0; w < GRW; w++) { | 346 for (uint32_t w = 0; w < GRW; w++) { |
350 bVal = GRREFERENCE->getPixel(w, h); | 347 FX_BOOL bVal = GRREFERENCE->getPixel(w, h); |
351 if (!(TPGRON && (bVal == GRREFERENCE->getPixel(w - 1, h - 1)) && | 348 if (!(TPGRON && (bVal == GRREFERENCE->getPixel(w - 1, h - 1)) && |
352 (bVal == GRREFERENCE->getPixel(w, h - 1)) && | 349 (bVal == GRREFERENCE->getPixel(w, h - 1)) && |
353 (bVal == GRREFERENCE->getPixel(w + 1, h - 1)) && | 350 (bVal == GRREFERENCE->getPixel(w + 1, h - 1)) && |
354 (bVal == GRREFERENCE->getPixel(w - 1, h)) && | 351 (bVal == GRREFERENCE->getPixel(w - 1, h)) && |
355 (bVal == GRREFERENCE->getPixel(w + 1, h)) && | 352 (bVal == GRREFERENCE->getPixel(w + 1, h)) && |
356 (bVal == GRREFERENCE->getPixel(w - 1, h + 1)) && | 353 (bVal == GRREFERENCE->getPixel(w - 1, h + 1)) && |
357 (bVal == GRREFERENCE->getPixel(w, h + 1)) && | 354 (bVal == GRREFERENCE->getPixel(w, h + 1)) && |
358 (bVal == GRREFERENCE->getPixel(w + 1, h + 1)))) { | 355 (bVal == GRREFERENCE->getPixel(w + 1, h + 1)))) { |
359 CONTEXT = line5; | 356 uint32_t CONTEXT = line5; |
360 CONTEXT |= line4 << 2; | 357 CONTEXT |= line4 << 2; |
361 CONTEXT |= line3 << 5; | 358 CONTEXT |= line3 << 5; |
362 CONTEXT |= line2 << 6; | 359 CONTEXT |= line2 << 6; |
363 CONTEXT |= line1 << 7; | 360 CONTEXT |= line1 << 7; |
364 bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); | 361 bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); |
365 } | 362 } |
366 GRREG->setPixel(w, h, bVal); | 363 GRREG->setPixel(w, h, bVal); |
367 line1 = ((line1 << 1) | GRREG->getPixel(w + 2, h - 1)) & 0x07; | 364 line1 = ((line1 << 1) | GRREG->getPixel(w + 2, h - 1)) & 0x07; |
368 line2 = ((line2 << 1) | bVal) & 0x01; | 365 line2 = ((line2 << 1) | bVal) & 0x01; |
369 line3 = ((line3 << 1) | | 366 line3 = ((line3 << 1) | |
(...skipping 13 matching lines...) Expand all Loading... |
383 } | 380 } |
384 return GRREG.release(); | 381 return GRREG.release(); |
385 } | 382 } |
386 | 383 |
387 CJBig2_Image* CJBig2_GRRDProc::decode_Template1_opt( | 384 CJBig2_Image* CJBig2_GRRDProc::decode_Template1_opt( |
388 CJBig2_ArithDecoder* pArithDecoder, | 385 CJBig2_ArithDecoder* pArithDecoder, |
389 JBig2ArithCtx* grContext) { | 386 JBig2ArithCtx* grContext) { |
390 if (!GRREFERENCE->m_pData) | 387 if (!GRREFERENCE->m_pData) |
391 return nullptr; | 388 return nullptr; |
392 | 389 |
393 FX_BOOL LTP, SLTP, bVal; | 390 int32_t iGRW = static_cast<int32_t>(GRW); |
394 uint32_t CONTEXT; | 391 int32_t iGRH = static_cast<int32_t>(GRH); |
395 uint32_t line1, line1_r, line2_r, line3_r; | 392 std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(iGRW, iGRH)); |
396 uint8_t *pLine, *pLineR, cVal; | |
397 intptr_t nStride, nStrideR, nOffset; | |
398 int32_t k, nBits; | |
399 int32_t GRWR, GRHR; | |
400 int32_t GRW, GRH; | |
401 GRW = (int32_t)CJBig2_GRRDProc::GRW; | |
402 GRH = (int32_t)CJBig2_GRRDProc::GRH; | |
403 LTP = 0; | |
404 std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(GRW, GRH)); | |
405 if (!GRREG->m_pData) | 393 if (!GRREG->m_pData) |
406 return nullptr; | 394 return nullptr; |
407 | 395 |
408 pLine = GRREG->m_pData; | 396 FX_BOOL LTP = FALSE; |
409 pLineR = GRREFERENCE->m_pData; | 397 uint8_t* pLine = GRREG->m_pData; |
410 nStride = GRREG->m_nStride; | 398 uint8_t* pLineR = GRREFERENCE->m_pData; |
411 nStrideR = GRREFERENCE->m_nStride; | 399 intptr_t nStride = GRREG->m_nStride; |
412 GRWR = (int32_t)GRREFERENCE->m_nWidth; | 400 intptr_t nStrideR = GRREFERENCE->m_nStride; |
413 GRHR = (int32_t)GRREFERENCE->m_nHeight; | 401 int32_t GRWR = GRREFERENCE->m_nWidth; |
| 402 int32_t GRHR = GRREFERENCE->m_nHeight; |
414 if (GRREFERENCEDY < -GRHR + 1 || GRREFERENCEDY > GRHR - 1) { | 403 if (GRREFERENCEDY < -GRHR + 1 || GRREFERENCEDY > GRHR - 1) { |
415 GRREFERENCEDY = 0; | 404 GRREFERENCEDY = 0; |
416 } | 405 } |
417 nOffset = -GRREFERENCEDY * nStrideR; | 406 intptr_t nOffset = -GRREFERENCEDY * nStrideR; |
418 for (int32_t h = 0; h < GRH; h++) { | 407 for (int32_t h = 0; h < iGRH; h++) { |
419 if (TPGRON) { | 408 if (TPGRON) |
420 SLTP = pArithDecoder->DECODE(&grContext[0x0008]); | 409 LTP = LTP ^ pArithDecoder->DECODE(&grContext[0x0008]); |
421 LTP = LTP ^ SLTP; | 410 uint32_t line1 = (h > 0) ? pLine[-nStride] << 1 : 0; |
422 } | |
423 line1 = (h > 0) ? pLine[-nStride] << 1 : 0; | |
424 int32_t reference_h = h - GRREFERENCEDY; | 411 int32_t reference_h = h - GRREFERENCEDY; |
425 FX_BOOL line1_r_ok = (reference_h > 0 && reference_h < GRHR + 1); | 412 FX_BOOL line1_r_ok = (reference_h > 0 && reference_h < GRHR + 1); |
426 FX_BOOL line2_r_ok = (reference_h > -1 && reference_h < GRHR); | 413 FX_BOOL line2_r_ok = (reference_h > -1 && reference_h < GRHR); |
427 FX_BOOL line3_r_ok = (reference_h > -2 && reference_h < GRHR - 1); | 414 FX_BOOL line3_r_ok = (reference_h > -2 && reference_h < GRHR - 1); |
428 line1_r = line1_r_ok ? pLineR[nOffset - nStrideR] : 0; | 415 uint32_t line1_r = line1_r_ok ? pLineR[nOffset - nStrideR] : 0; |
429 line2_r = line2_r_ok ? pLineR[nOffset] : 0; | 416 uint32_t line2_r = line2_r_ok ? pLineR[nOffset] : 0; |
430 line3_r = line3_r_ok ? pLineR[nOffset + nStrideR] : 0; | 417 uint32_t line3_r = line3_r_ok ? pLineR[nOffset + nStrideR] : 0; |
431 if (LTP == 0) { | 418 if (!LTP) { |
432 CONTEXT = (line1 & 0x0380) | ((line1_r >> 2) & 0x0020) | | 419 uint32_t CONTEXT = (line1 & 0x0380) | ((line1_r >> 2) & 0x0020) | |
433 ((line2_r >> 4) & 0x001c) | ((line3_r >> 6) & 0x0003); | 420 ((line2_r >> 4) & 0x001c) | ((line3_r >> 6) & 0x0003); |
434 for (int32_t w = 0; w < GRW; w += 8) { | 421 for (int32_t w = 0; w < iGRW; w += 8) { |
435 nBits = GRW - w > 8 ? 8 : GRW - w; | 422 int32_t nBits = iGRW - w > 8 ? 8 : iGRW - w; |
436 if (h > 0) | 423 if (h > 0) |
437 line1 = (line1 << 8) | | 424 line1 = (line1 << 8) | |
438 (w + 8 < GRW ? pLine[-nStride + (w >> 3) + 1] << 1 : 0); | 425 (w + 8 < iGRW ? pLine[-nStride + (w >> 3) + 1] << 1 : 0); |
439 if (line1_r_ok) | 426 if (line1_r_ok) |
440 line1_r = | 427 line1_r = |
441 (line1_r << 8) | | 428 (line1_r << 8) | |
442 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); | 429 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); |
443 if (line2_r_ok) | 430 if (line2_r_ok) |
444 line2_r = (line2_r << 8) | | 431 line2_r = (line2_r << 8) | |
445 (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); | 432 (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); |
446 if (line3_r_ok) { | 433 if (line3_r_ok) { |
447 line3_r = | 434 line3_r = |
448 (line3_r << 8) | | 435 (line3_r << 8) | |
449 (w + 8 < GRWR ? pLineR[nOffset + nStrideR + (w >> 3) + 1] : 0); | 436 (w + 8 < GRWR ? pLineR[nOffset + nStrideR + (w >> 3) + 1] : 0); |
450 } else { | 437 } else { |
451 line3_r = 0; | 438 line3_r = 0; |
452 } | 439 } |
453 cVal = 0; | 440 uint8_t cVal = 0; |
454 for (k = 0; k < nBits; k++) { | 441 for (int32_t k = 0; k < nBits; k++) { |
455 bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); | 442 FX_BOOL bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); |
456 cVal |= bVal << (7 - k); | 443 cVal |= bVal << (7 - k); |
457 CONTEXT = ((CONTEXT & 0x018d) << 1) | (bVal << 6) | | 444 CONTEXT = ((CONTEXT & 0x018d) << 1) | (bVal << 6) | |
458 ((line1 >> (7 - k)) & 0x0080) | | 445 ((line1 >> (7 - k)) & 0x0080) | |
459 ((line1_r >> (9 - k)) & 0x0020) | | 446 ((line1_r >> (9 - k)) & 0x0020) | |
460 ((line2_r >> (11 - k)) & 0x0004) | | 447 ((line2_r >> (11 - k)) & 0x0004) | |
461 ((line3_r >> (13 - k)) & 0x0001); | 448 ((line3_r >> (13 - k)) & 0x0001); |
462 } | 449 } |
463 pLine[w >> 3] = cVal; | 450 pLine[w >> 3] = cVal; |
464 } | 451 } |
465 } else { | 452 } else { |
466 CONTEXT = (line1 & 0x0380) | ((line1_r >> 2) & 0x0020) | | 453 uint32_t CONTEXT = (line1 & 0x0380) | ((line1_r >> 2) & 0x0020) | |
467 ((line2_r >> 4) & 0x001c) | ((line3_r >> 6) & 0x0003); | 454 ((line2_r >> 4) & 0x001c) | ((line3_r >> 6) & 0x0003); |
468 for (int32_t w = 0; w < GRW; w += 8) { | 455 for (int32_t w = 0; w < iGRW; w += 8) { |
469 nBits = GRW - w > 8 ? 8 : GRW - w; | 456 int32_t nBits = iGRW - w > 8 ? 8 : iGRW - w; |
470 if (h > 0) | 457 if (h > 0) |
471 line1 = (line1 << 8) | | 458 line1 = (line1 << 8) | |
472 (w + 8 < GRW ? pLine[-nStride + (w >> 3) + 1] << 1 : 0); | 459 (w + 8 < iGRW ? pLine[-nStride + (w >> 3) + 1] << 1 : 0); |
473 if (line1_r_ok) | 460 if (line1_r_ok) |
474 line1_r = | 461 line1_r = |
475 (line1_r << 8) | | 462 (line1_r << 8) | |
476 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); | 463 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); |
477 if (line2_r_ok) | 464 if (line2_r_ok) |
478 line2_r = (line2_r << 8) | | 465 line2_r = (line2_r << 8) | |
479 (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); | 466 (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); |
480 if (line3_r_ok) { | 467 if (line3_r_ok) { |
481 line3_r = | 468 line3_r = |
482 (line3_r << 8) | | 469 (line3_r << 8) | |
483 (w + 8 < GRWR ? pLineR[nOffset + nStrideR + (w >> 3) + 1] : 0); | 470 (w + 8 < GRWR ? pLineR[nOffset + nStrideR + (w >> 3) + 1] : 0); |
484 } else { | 471 } else { |
485 line3_r = 0; | 472 line3_r = 0; |
486 } | 473 } |
487 cVal = 0; | 474 uint8_t cVal = 0; |
488 for (k = 0; k < nBits; k++) { | 475 for (int32_t k = 0; k < nBits; k++) { |
489 bVal = GRREFERENCE->getPixel(w + k, h); | 476 FX_BOOL bVal = GRREFERENCE->getPixel(w + k, h); |
490 if (!(TPGRON && (bVal == GRREFERENCE->getPixel(w + k - 1, h - 1)) && | 477 if (!(TPGRON && (bVal == GRREFERENCE->getPixel(w + k - 1, h - 1)) && |
491 (bVal == GRREFERENCE->getPixel(w + k, h - 1)) && | 478 (bVal == GRREFERENCE->getPixel(w + k, h - 1)) && |
492 (bVal == GRREFERENCE->getPixel(w + k + 1, h - 1)) && | 479 (bVal == GRREFERENCE->getPixel(w + k + 1, h - 1)) && |
493 (bVal == GRREFERENCE->getPixel(w + k - 1, h)) && | 480 (bVal == GRREFERENCE->getPixel(w + k - 1, h)) && |
494 (bVal == GRREFERENCE->getPixel(w + k + 1, h)) && | 481 (bVal == GRREFERENCE->getPixel(w + k + 1, h)) && |
495 (bVal == GRREFERENCE->getPixel(w + k - 1, h + 1)) && | 482 (bVal == GRREFERENCE->getPixel(w + k - 1, h + 1)) && |
496 (bVal == GRREFERENCE->getPixel(w + k, h + 1)) && | 483 (bVal == GRREFERENCE->getPixel(w + k, h + 1)) && |
497 (bVal == GRREFERENCE->getPixel(w + k + 1, h + 1)))) { | 484 (bVal == GRREFERENCE->getPixel(w + k + 1, h + 1)))) { |
498 bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); | 485 bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); |
499 } | 486 } |
500 cVal |= bVal << (7 - k); | 487 cVal |= bVal << (7 - k); |
501 CONTEXT = ((CONTEXT & 0x018d) << 1) | (bVal << 6) | | 488 CONTEXT = ((CONTEXT & 0x018d) << 1) | (bVal << 6) | |
502 ((line1 >> (7 - k)) & 0x0080) | | 489 ((line1 >> (7 - k)) & 0x0080) | |
503 ((line1_r >> (9 - k)) & 0x0020) | | 490 ((line1_r >> (9 - k)) & 0x0020) | |
504 ((line2_r >> (11 - k)) & 0x0004) | | 491 ((line2_r >> (11 - k)) & 0x0004) | |
505 ((line3_r >> (13 - k)) & 0x0001); | 492 ((line3_r >> (13 - k)) & 0x0001); |
506 } | 493 } |
507 pLine[w >> 3] = cVal; | 494 pLine[w >> 3] = cVal; |
508 } | 495 } |
509 } | 496 } |
510 pLine += nStride; | 497 pLine += nStride; |
511 if (h < GRHR + GRREFERENCEDY) { | 498 if (h < GRHR + GRREFERENCEDY) { |
512 pLineR += nStrideR; | 499 pLineR += nStrideR; |
513 } | 500 } |
514 } | 501 } |
515 return GRREG.release(); | 502 return GRREG.release(); |
516 } | 503 } |
OLD | NEW |