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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 if (!GRREFERENCE->m_pData) | 152 if (!GRREFERENCE->m_pData) |
153 return nullptr; | 153 return nullptr; |
154 | 154 |
155 FX_BOOL LTP, SLTP, bVal; | 155 FX_BOOL LTP, SLTP, bVal; |
156 uint32_t CONTEXT; | 156 uint32_t CONTEXT; |
157 uint32_t line1, line1_r, line2_r, line3_r; | 157 uint32_t line1, line1_r, line2_r, line3_r; |
158 uint8_t *pLine, *pLineR, cVal; | 158 uint8_t *pLine, *pLineR, cVal; |
159 intptr_t nStride, nStrideR, nOffset; | 159 intptr_t nStride, nStrideR, nOffset; |
160 int32_t k, nBits; | 160 int32_t k, nBits; |
161 int32_t GRWR, GRHR; | 161 int32_t GRWR, GRHR; |
162 int32_t GRW, GRH; | 162 int32_t iGRW, iGRH; |
dsinclair
2016/06/06 12:50:11
nit: one per line
Wei Li
2016/06/07 17:33:53
Done.
| |
163 GRW = (int32_t)CJBig2_GRRDProc::GRW; | 163 iGRW = static_cast<int32_t>(GRW); |
164 GRH = (int32_t)CJBig2_GRRDProc::GRH; | 164 iGRH = static_cast<int32_t>(GRH); |
165 LTP = 0; | 165 LTP = 0; |
166 std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(GRW, GRH)); | 166 std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(iGRW, iGRH)); |
167 if (!GRREG->m_pData) | 167 if (!GRREG->m_pData) |
168 return nullptr; | 168 return nullptr; |
169 | 169 |
170 pLine = GRREG->m_pData; | 170 pLine = GRREG->m_pData; |
171 pLineR = GRREFERENCE->m_pData; | 171 pLineR = GRREFERENCE->m_pData; |
172 nStride = GRREG->m_nStride; | 172 nStride = GRREG->m_nStride; |
173 nStrideR = GRREFERENCE->m_nStride; | 173 nStrideR = GRREFERENCE->m_nStride; |
174 GRWR = (int32_t)GRREFERENCE->m_nWidth; | 174 GRWR = (int32_t)GRREFERENCE->m_nWidth; |
175 GRHR = (int32_t)GRREFERENCE->m_nHeight; | 175 GRHR = (int32_t)GRREFERENCE->m_nHeight; |
176 if (GRREFERENCEDY < -GRHR + 1 || GRREFERENCEDY > GRHR - 1) { | 176 if (GRREFERENCEDY < -GRHR + 1 || GRREFERENCEDY > GRHR - 1) { |
177 GRREFERENCEDY = 0; | 177 GRREFERENCEDY = 0; |
178 } | 178 } |
179 nOffset = -GRREFERENCEDY * nStrideR; | 179 nOffset = -GRREFERENCEDY * nStrideR; |
180 for (int32_t h = 0; h < GRH; h++) { | 180 for (int32_t h = 0; h < iGRH; h++) { |
181 if (TPGRON) { | 181 if (TPGRON) { |
182 SLTP = pArithDecoder->DECODE(&grContext[0x0010]); | 182 SLTP = pArithDecoder->DECODE(&grContext[0x0010]); |
183 LTP = LTP ^ SLTP; | 183 LTP = LTP ^ SLTP; |
184 } | 184 } |
185 line1 = (h > 0) ? pLine[-nStride] << 4 : 0; | 185 line1 = (h > 0) ? pLine[-nStride] << 4 : 0; |
186 int32_t reference_h = h - GRREFERENCEDY; | 186 int32_t reference_h = h - GRREFERENCEDY; |
187 FX_BOOL line1_r_ok = (reference_h > 0 && reference_h < GRHR + 1); | 187 FX_BOOL line1_r_ok = (reference_h > 0 && reference_h < GRHR + 1); |
188 FX_BOOL line2_r_ok = (reference_h > -1 && reference_h < GRHR); | 188 FX_BOOL line2_r_ok = (reference_h > -1 && reference_h < GRHR); |
189 FX_BOOL line3_r_ok = (reference_h > -2 && reference_h < GRHR - 1); | 189 FX_BOOL line3_r_ok = (reference_h > -2 && reference_h < GRHR - 1); |
190 line1_r = line1_r_ok ? pLineR[nOffset - nStrideR] : 0; | 190 line1_r = line1_r_ok ? pLineR[nOffset - nStrideR] : 0; |
191 line2_r = line2_r_ok ? pLineR[nOffset] : 0; | 191 line2_r = line2_r_ok ? pLineR[nOffset] : 0; |
192 line3_r = line3_r_ok ? pLineR[nOffset + nStrideR] : 0; | 192 line3_r = line3_r_ok ? pLineR[nOffset + nStrideR] : 0; |
193 if (LTP == 0) { | 193 if (LTP == 0) { |
194 CONTEXT = (line1 & 0x1c00) | (line1_r & 0x01c0) | | 194 CONTEXT = (line1 & 0x1c00) | (line1_r & 0x01c0) | |
195 ((line2_r >> 3) & 0x0038) | ((line3_r >> 6) & 0x0007); | 195 ((line2_r >> 3) & 0x0038) | ((line3_r >> 6) & 0x0007); |
196 for (int32_t w = 0; w < GRW; w += 8) { | 196 for (int32_t w = 0; w < iGRW; w += 8) { |
197 nBits = GRW - w > 8 ? 8 : GRW - w; | 197 nBits = iGRW - w > 8 ? 8 : iGRW - w; |
198 if (h > 0) | 198 if (h > 0) |
199 line1 = (line1 << 8) | | 199 line1 = (line1 << 8) | |
200 (w + 8 < GRW ? pLine[-nStride + (w >> 3) + 1] << 4 : 0); | 200 (w + 8 < iGRW ? pLine[-nStride + (w >> 3) + 1] << 4 : 0); |
201 if (h > GRHR + GRREFERENCEDY + 1) { | 201 if (h > GRHR + GRREFERENCEDY + 1) { |
202 line1_r = 0; | 202 line1_r = 0; |
203 line2_r = 0; | 203 line2_r = 0; |
204 line3_r = 0; | 204 line3_r = 0; |
205 } else { | 205 } else { |
206 if (line1_r_ok) | 206 if (line1_r_ok) |
207 line1_r = | 207 line1_r = |
208 (line1_r << 8) | | 208 (line1_r << 8) | |
209 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); | 209 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); |
210 if (line2_r_ok) | 210 if (line2_r_ok) |
(...skipping 15 matching lines...) Expand all Loading... | |
226 ((line1 >> (7 - k)) & 0x0400) | | 226 ((line1 >> (7 - k)) & 0x0400) | |
227 ((line1_r >> (7 - k)) & 0x0040) | | 227 ((line1_r >> (7 - k)) & 0x0040) | |
228 ((line2_r >> (10 - k)) & 0x0008) | | 228 ((line2_r >> (10 - k)) & 0x0008) | |
229 ((line3_r >> (13 - k)) & 0x0001); | 229 ((line3_r >> (13 - k)) & 0x0001); |
230 } | 230 } |
231 pLine[w >> 3] = cVal; | 231 pLine[w >> 3] = cVal; |
232 } | 232 } |
233 } else { | 233 } else { |
234 CONTEXT = (line1 & 0x1c00) | (line1_r & 0x01c0) | | 234 CONTEXT = (line1 & 0x1c00) | (line1_r & 0x01c0) | |
235 ((line2_r >> 3) & 0x0038) | ((line3_r >> 6) & 0x0007); | 235 ((line2_r >> 3) & 0x0038) | ((line3_r >> 6) & 0x0007); |
236 for (int32_t w = 0; w < GRW; w += 8) { | 236 for (int32_t w = 0; w < iGRW; w += 8) { |
237 nBits = GRW - w > 8 ? 8 : GRW - w; | 237 nBits = iGRW - w > 8 ? 8 : iGRW - w; |
238 if (h > 0) | 238 if (h > 0) |
239 line1 = (line1 << 8) | | 239 line1 = (line1 << 8) | |
240 (w + 8 < GRW ? pLine[-nStride + (w >> 3) + 1] << 4 : 0); | 240 (w + 8 < iGRW ? pLine[-nStride + (w >> 3) + 1] << 4 : 0); |
241 if (line1_r_ok) | 241 if (line1_r_ok) |
242 line1_r = | 242 line1_r = |
243 (line1_r << 8) | | 243 (line1_r << 8) | |
244 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); | 244 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); |
245 if (line2_r_ok) | 245 if (line2_r_ok) |
246 line2_r = (line2_r << 8) | | 246 line2_r = (line2_r << 8) | |
247 (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); | 247 (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); |
248 if (line3_r_ok) { | 248 if (line3_r_ok) { |
249 line3_r = | 249 line3_r = |
250 (line3_r << 8) | | 250 (line3_r << 8) | |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
389 JBig2ArithCtx* grContext) { | 389 JBig2ArithCtx* grContext) { |
390 if (!GRREFERENCE->m_pData) | 390 if (!GRREFERENCE->m_pData) |
391 return nullptr; | 391 return nullptr; |
392 | 392 |
393 FX_BOOL LTP, SLTP, bVal; | 393 FX_BOOL LTP, SLTP, bVal; |
394 uint32_t CONTEXT; | 394 uint32_t CONTEXT; |
395 uint32_t line1, line1_r, line2_r, line3_r; | 395 uint32_t line1, line1_r, line2_r, line3_r; |
396 uint8_t *pLine, *pLineR, cVal; | 396 uint8_t *pLine, *pLineR, cVal; |
397 intptr_t nStride, nStrideR, nOffset; | 397 intptr_t nStride, nStrideR, nOffset; |
398 int32_t k, nBits; | 398 int32_t k, nBits; |
399 int32_t GRWR, GRHR; | 399 int32_t GRWR, GRHR; |
Tom Sepez
2016/06/06 16:43:33
nit: move to line 412 while at it.
Wei Li
2016/06/07 17:33:53
Done.
| |
400 int32_t GRW, GRH; | 400 int32_t iGRW, iGRH; |
dsinclair
2016/06/06 12:50:11
ditto
Tom Sepez
2016/06/06 16:43:33
Also combine definition and initialization onto on
Wei Li
2016/06/07 17:33:53
Done.
Wei Li
2016/06/07 17:33:53
Done.
| |
401 GRW = (int32_t)CJBig2_GRRDProc::GRW; | 401 iGRW = static_cast<int32_t>(GRW); |
402 GRH = (int32_t)CJBig2_GRRDProc::GRH; | 402 iGRH = static_cast<int32_t>(GRH); |
403 LTP = 0; | 403 LTP = 0; |
404 std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(GRW, GRH)); | 404 std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(iGRW, iGRH)); |
405 if (!GRREG->m_pData) | 405 if (!GRREG->m_pData) |
406 return nullptr; | 406 return nullptr; |
407 | 407 |
408 pLine = GRREG->m_pData; | 408 pLine = GRREG->m_pData; |
409 pLineR = GRREFERENCE->m_pData; | 409 pLineR = GRREFERENCE->m_pData; |
410 nStride = GRREG->m_nStride; | 410 nStride = GRREG->m_nStride; |
411 nStrideR = GRREFERENCE->m_nStride; | 411 nStrideR = GRREFERENCE->m_nStride; |
412 GRWR = (int32_t)GRREFERENCE->m_nWidth; | 412 GRWR = (int32_t)GRREFERENCE->m_nWidth; |
413 GRHR = (int32_t)GRREFERENCE->m_nHeight; | 413 GRHR = (int32_t)GRREFERENCE->m_nHeight; |
414 if (GRREFERENCEDY < -GRHR + 1 || GRREFERENCEDY > GRHR - 1) { | 414 if (GRREFERENCEDY < -GRHR + 1 || GRREFERENCEDY > GRHR - 1) { |
415 GRREFERENCEDY = 0; | 415 GRREFERENCEDY = 0; |
416 } | 416 } |
417 nOffset = -GRREFERENCEDY * nStrideR; | 417 nOffset = -GRREFERENCEDY * nStrideR; |
418 for (int32_t h = 0; h < GRH; h++) { | 418 for (int32_t h = 0; h < iGRH; h++) { |
419 if (TPGRON) { | 419 if (TPGRON) { |
420 SLTP = pArithDecoder->DECODE(&grContext[0x0008]); | 420 SLTP = pArithDecoder->DECODE(&grContext[0x0008]); |
421 LTP = LTP ^ SLTP; | 421 LTP = LTP ^ SLTP; |
422 } | 422 } |
423 line1 = (h > 0) ? pLine[-nStride] << 1 : 0; | 423 line1 = (h > 0) ? pLine[-nStride] << 1 : 0; |
424 int32_t reference_h = h - GRREFERENCEDY; | 424 int32_t reference_h = h - GRREFERENCEDY; |
425 FX_BOOL line1_r_ok = (reference_h > 0 && reference_h < GRHR + 1); | 425 FX_BOOL line1_r_ok = (reference_h > 0 && reference_h < GRHR + 1); |
426 FX_BOOL line2_r_ok = (reference_h > -1 && reference_h < GRHR); | 426 FX_BOOL line2_r_ok = (reference_h > -1 && reference_h < GRHR); |
427 FX_BOOL line3_r_ok = (reference_h > -2 && reference_h < GRHR - 1); | 427 FX_BOOL line3_r_ok = (reference_h > -2 && reference_h < GRHR - 1); |
428 line1_r = line1_r_ok ? pLineR[nOffset - nStrideR] : 0; | 428 line1_r = line1_r_ok ? pLineR[nOffset - nStrideR] : 0; |
429 line2_r = line2_r_ok ? pLineR[nOffset] : 0; | 429 line2_r = line2_r_ok ? pLineR[nOffset] : 0; |
430 line3_r = line3_r_ok ? pLineR[nOffset + nStrideR] : 0; | 430 line3_r = line3_r_ok ? pLineR[nOffset + nStrideR] : 0; |
431 if (LTP == 0) { | 431 if (LTP == 0) { |
432 CONTEXT = (line1 & 0x0380) | ((line1_r >> 2) & 0x0020) | | 432 CONTEXT = (line1 & 0x0380) | ((line1_r >> 2) & 0x0020) | |
433 ((line2_r >> 4) & 0x001c) | ((line3_r >> 6) & 0x0003); | 433 ((line2_r >> 4) & 0x001c) | ((line3_r >> 6) & 0x0003); |
434 for (int32_t w = 0; w < GRW; w += 8) { | 434 for (int32_t w = 0; w < iGRW; w += 8) { |
435 nBits = GRW - w > 8 ? 8 : GRW - w; | 435 nBits = iGRW - w > 8 ? 8 : iGRW - w; |
436 if (h > 0) | 436 if (h > 0) |
437 line1 = (line1 << 8) | | 437 line1 = (line1 << 8) | |
438 (w + 8 < GRW ? pLine[-nStride + (w >> 3) + 1] << 1 : 0); | 438 (w + 8 < iGRW ? pLine[-nStride + (w >> 3) + 1] << 1 : 0); |
439 if (line1_r_ok) | 439 if (line1_r_ok) |
440 line1_r = | 440 line1_r = |
441 (line1_r << 8) | | 441 (line1_r << 8) | |
442 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); | 442 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); |
443 if (line2_r_ok) | 443 if (line2_r_ok) |
444 line2_r = (line2_r << 8) | | 444 line2_r = (line2_r << 8) | |
445 (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); | 445 (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); |
446 if (line3_r_ok) { | 446 if (line3_r_ok) { |
447 line3_r = | 447 line3_r = |
448 (line3_r << 8) | | 448 (line3_r << 8) | |
449 (w + 8 < GRWR ? pLineR[nOffset + nStrideR + (w >> 3) + 1] : 0); | 449 (w + 8 < GRWR ? pLineR[nOffset + nStrideR + (w >> 3) + 1] : 0); |
450 } else { | 450 } else { |
451 line3_r = 0; | 451 line3_r = 0; |
452 } | 452 } |
453 cVal = 0; | 453 cVal = 0; |
454 for (k = 0; k < nBits; k++) { | 454 for (k = 0; k < nBits; k++) { |
455 bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); | 455 bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); |
456 cVal |= bVal << (7 - k); | 456 cVal |= bVal << (7 - k); |
457 CONTEXT = ((CONTEXT & 0x018d) << 1) | (bVal << 6) | | 457 CONTEXT = ((CONTEXT & 0x018d) << 1) | (bVal << 6) | |
458 ((line1 >> (7 - k)) & 0x0080) | | 458 ((line1 >> (7 - k)) & 0x0080) | |
459 ((line1_r >> (9 - k)) & 0x0020) | | 459 ((line1_r >> (9 - k)) & 0x0020) | |
460 ((line2_r >> (11 - k)) & 0x0004) | | 460 ((line2_r >> (11 - k)) & 0x0004) | |
461 ((line3_r >> (13 - k)) & 0x0001); | 461 ((line3_r >> (13 - k)) & 0x0001); |
462 } | 462 } |
463 pLine[w >> 3] = cVal; | 463 pLine[w >> 3] = cVal; |
464 } | 464 } |
465 } else { | 465 } else { |
466 CONTEXT = (line1 & 0x0380) | ((line1_r >> 2) & 0x0020) | | 466 CONTEXT = (line1 & 0x0380) | ((line1_r >> 2) & 0x0020) | |
467 ((line2_r >> 4) & 0x001c) | ((line3_r >> 6) & 0x0003); | 467 ((line2_r >> 4) & 0x001c) | ((line3_r >> 6) & 0x0003); |
468 for (int32_t w = 0; w < GRW; w += 8) { | 468 for (int32_t w = 0; w < iGRW; w += 8) { |
469 nBits = GRW - w > 8 ? 8 : GRW - w; | 469 nBits = iGRW - w > 8 ? 8 : iGRW - w; |
470 if (h > 0) | 470 if (h > 0) |
471 line1 = (line1 << 8) | | 471 line1 = (line1 << 8) | |
472 (w + 8 < GRW ? pLine[-nStride + (w >> 3) + 1] << 1 : 0); | 472 (w + 8 < iGRW ? pLine[-nStride + (w >> 3) + 1] << 1 : 0); |
473 if (line1_r_ok) | 473 if (line1_r_ok) |
474 line1_r = | 474 line1_r = |
475 (line1_r << 8) | | 475 (line1_r << 8) | |
476 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); | 476 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); |
477 if (line2_r_ok) | 477 if (line2_r_ok) |
478 line2_r = (line2_r << 8) | | 478 line2_r = (line2_r << 8) | |
479 (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); | 479 (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); |
480 if (line3_r_ok) { | 480 if (line3_r_ok) { |
481 line3_r = | 481 line3_r = |
482 (line3_r << 8) | | 482 (line3_r << 8) | |
(...skipping 24 matching lines...) Expand all Loading... | |
507 pLine[w >> 3] = cVal; | 507 pLine[w >> 3] = cVal; |
508 } | 508 } |
509 } | 509 } |
510 pLine += nStride; | 510 pLine += nStride; |
511 if (h < GRHR + GRREFERENCEDY) { | 511 if (h < GRHR + GRREFERENCEDY) { |
512 pLineR += nStrideR; | 512 pLineR += nStrideR; |
513 } | 513 } |
514 } | 514 } |
515 return GRREG.release(); | 515 return GRREG.release(); |
516 } | 516 } |
OLD | NEW |