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_HtrdProc.h" | 7 #include "core/fxcodec/jbig2/JBig2_HtrdProc.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "core/fxcodec/jbig2/JBig2_GsidProc.h" | 11 #include "core/fxcodec/jbig2/JBig2_GsidProc.h" |
12 #include "core/fxcrt/include/fx_basic.h" | 12 #include "core/fxcrt/include/fx_basic.h" |
13 | 13 |
14 CJBig2_Image* CJBig2_HTRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, | 14 CJBig2_Image* CJBig2_HTRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, |
15 JBig2ArithCtx* gbContext, | 15 JBig2ArithCtx* gbContext, |
16 IFX_Pause* pPause) { | 16 IFX_Pause* pPause) { |
17 FX_DWORD ng, mg; | 17 uint32_t ng, mg; |
18 int32_t x, y; | 18 int32_t x, y; |
19 FX_DWORD HBPP; | 19 uint32_t HBPP; |
20 FX_DWORD* GI; | 20 uint32_t* GI; |
21 std::unique_ptr<CJBig2_Image> HSKIP; | 21 std::unique_ptr<CJBig2_Image> HSKIP; |
22 std::unique_ptr<CJBig2_Image> HTREG(new CJBig2_Image(HBW, HBH)); | 22 std::unique_ptr<CJBig2_Image> HTREG(new CJBig2_Image(HBW, HBH)); |
23 HTREG->fill(HDEFPIXEL); | 23 HTREG->fill(HDEFPIXEL); |
24 if (HENABLESKIP == 1) { | 24 if (HENABLESKIP == 1) { |
25 HSKIP.reset(new CJBig2_Image(HGW, HGH)); | 25 HSKIP.reset(new CJBig2_Image(HGW, HGH)); |
26 for (mg = 0; mg < HGH; mg++) { | 26 for (mg = 0; mg < HGH; mg++) { |
27 for (ng = 0; ng < HGW; ng++) { | 27 for (ng = 0; ng < HGW; ng++) { |
28 x = (HGX + mg * HRY + ng * HRX) >> 8; | 28 x = (HGX + mg * HRY + ng * HRX) >> 8; |
29 y = (HGY + mg * HRX - ng * HRY) >> 8; | 29 y = (HGY + mg * HRX - ng * HRY) >> 8; |
30 if ((x + HPW <= 0) | (x >= (int32_t)HBW) | (y + HPH <= 0) | | 30 if ((x + HPW <= 0) | (x >= (int32_t)HBW) | (y + HPH <= 0) | |
31 (y >= (int32_t)HPH)) { | 31 (y >= (int32_t)HPH)) { |
32 HSKIP->setPixel(ng, mg, 1); | 32 HSKIP->setPixel(ng, mg, 1); |
33 } else { | 33 } else { |
34 HSKIP->setPixel(ng, mg, 0); | 34 HSKIP->setPixel(ng, mg, 0); |
35 } | 35 } |
36 } | 36 } |
37 } | 37 } |
38 } | 38 } |
39 HBPP = 1; | 39 HBPP = 1; |
40 while ((FX_DWORD)(1 << HBPP) < HNUMPATS) { | 40 while ((uint32_t)(1 << HBPP) < HNUMPATS) { |
41 HBPP++; | 41 HBPP++; |
42 } | 42 } |
43 std::unique_ptr<CJBig2_GSIDProc> pGID(new CJBig2_GSIDProc()); | 43 std::unique_ptr<CJBig2_GSIDProc> pGID(new CJBig2_GSIDProc()); |
44 pGID->GSMMR = HMMR; | 44 pGID->GSMMR = HMMR; |
45 pGID->GSW = HGW; | 45 pGID->GSW = HGW; |
46 pGID->GSH = HGH; | 46 pGID->GSH = HGH; |
47 pGID->GSBPP = (uint8_t)HBPP; | 47 pGID->GSBPP = (uint8_t)HBPP; |
48 pGID->GSUSESKIP = HENABLESKIP; | 48 pGID->GSUSESKIP = HENABLESKIP; |
49 pGID->GSKIP = HSKIP.get(); | 49 pGID->GSKIP = HSKIP.get(); |
50 pGID->GSTEMPLATE = HTEMPLATE; | 50 pGID->GSTEMPLATE = HTEMPLATE; |
51 GI = pGID->decode_Arith(pArithDecoder, gbContext, pPause); | 51 GI = pGID->decode_Arith(pArithDecoder, gbContext, pPause); |
52 if (!GI) | 52 if (!GI) |
53 return nullptr; | 53 return nullptr; |
54 | 54 |
55 for (mg = 0; mg < HGH; mg++) { | 55 for (mg = 0; mg < HGH; mg++) { |
56 for (ng = 0; ng < HGW; ng++) { | 56 for (ng = 0; ng < HGW; ng++) { |
57 x = (HGX + mg * HRY + ng * HRX) >> 8; | 57 x = (HGX + mg * HRY + ng * HRX) >> 8; |
58 y = (HGY + mg * HRX - ng * HRY) >> 8; | 58 y = (HGY + mg * HRX - ng * HRY) >> 8; |
59 FX_DWORD pat_index = GI[mg * HGW + ng]; | 59 uint32_t pat_index = GI[mg * HGW + ng]; |
60 if (pat_index >= HNUMPATS) { | 60 if (pat_index >= HNUMPATS) { |
61 pat_index = HNUMPATS - 1; | 61 pat_index = HNUMPATS - 1; |
62 } | 62 } |
63 HTREG->composeFrom(x, y, HPATS[pat_index], HCOMBOP); | 63 HTREG->composeFrom(x, y, HPATS[pat_index], HCOMBOP); |
64 } | 64 } |
65 } | 65 } |
66 FX_Free(GI); | 66 FX_Free(GI); |
67 return HTREG.release(); | 67 return HTREG.release(); |
68 } | 68 } |
69 | 69 |
70 CJBig2_Image* CJBig2_HTRDProc::decode_MMR(CJBig2_BitStream* pStream, | 70 CJBig2_Image* CJBig2_HTRDProc::decode_MMR(CJBig2_BitStream* pStream, |
71 IFX_Pause* pPause) { | 71 IFX_Pause* pPause) { |
72 FX_DWORD ng, mg; | 72 uint32_t ng, mg; |
73 int32_t x, y; | 73 int32_t x, y; |
74 FX_DWORD* GI; | 74 uint32_t* GI; |
75 std::unique_ptr<CJBig2_Image> HTREG(new CJBig2_Image(HBW, HBH)); | 75 std::unique_ptr<CJBig2_Image> HTREG(new CJBig2_Image(HBW, HBH)); |
76 HTREG->fill(HDEFPIXEL); | 76 HTREG->fill(HDEFPIXEL); |
77 FX_DWORD HBPP = 1; | 77 uint32_t HBPP = 1; |
78 while ((FX_DWORD)(1 << HBPP) < HNUMPATS) { | 78 while ((uint32_t)(1 << HBPP) < HNUMPATS) { |
79 HBPP++; | 79 HBPP++; |
80 } | 80 } |
81 std::unique_ptr<CJBig2_GSIDProc> pGID(new CJBig2_GSIDProc()); | 81 std::unique_ptr<CJBig2_GSIDProc> pGID(new CJBig2_GSIDProc()); |
82 pGID->GSMMR = HMMR; | 82 pGID->GSMMR = HMMR; |
83 pGID->GSW = HGW; | 83 pGID->GSW = HGW; |
84 pGID->GSH = HGH; | 84 pGID->GSH = HGH; |
85 pGID->GSBPP = (uint8_t)HBPP; | 85 pGID->GSBPP = (uint8_t)HBPP; |
86 pGID->GSUSESKIP = 0; | 86 pGID->GSUSESKIP = 0; |
87 GI = pGID->decode_MMR(pStream, pPause); | 87 GI = pGID->decode_MMR(pStream, pPause); |
88 if (!GI) | 88 if (!GI) |
89 return nullptr; | 89 return nullptr; |
90 | 90 |
91 for (mg = 0; mg < HGH; mg++) { | 91 for (mg = 0; mg < HGH; mg++) { |
92 for (ng = 0; ng < HGW; ng++) { | 92 for (ng = 0; ng < HGW; ng++) { |
93 x = (HGX + mg * HRY + ng * HRX) >> 8; | 93 x = (HGX + mg * HRY + ng * HRX) >> 8; |
94 y = (HGY + mg * HRX - ng * HRY) >> 8; | 94 y = (HGY + mg * HRX - ng * HRY) >> 8; |
95 FX_DWORD pat_index = GI[mg * HGW + ng]; | 95 uint32_t pat_index = GI[mg * HGW + ng]; |
96 if (pat_index >= HNUMPATS) { | 96 if (pat_index >= HNUMPATS) { |
97 pat_index = HNUMPATS - 1; | 97 pat_index = HNUMPATS - 1; |
98 } | 98 } |
99 HTREG->composeFrom(x, y, HPATS[pat_index], HCOMBOP); | 99 HTREG->composeFrom(x, y, HPATS[pat_index], HCOMBOP); |
100 } | 100 } |
101 } | 101 } |
102 FX_Free(GI); | 102 FX_Free(GI); |
103 return HTREG.release(); | 103 return HTREG.release(); |
104 } | 104 } |
OLD | NEW |