summaryrefslogtreecommitdiff
path: root/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2016-03-14 13:35:12 -0400
committerDan Sinclair <dsinclair@chromium.org>2016-03-14 13:35:12 -0400
commit764ec513eecbebd12781bcc96ce81ed5e736ee92 (patch)
tree12763fde4be1f10ea1183d92185917b2b587e00b /core/fxcodec/jbig2/JBig2_HtrdProc.cpp
parent97da97662417085774f75c26e535c6fbe70266ae (diff)
downloadpdfium-764ec513eecbebd12781bcc96ce81ed5e736ee92.tar.xz
Move core/src/ up to core/.
This CL moves the core/src/ files up to core/ and fixes up the include guards, includes and build files. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1800523005 .
Diffstat (limited to 'core/fxcodec/jbig2/JBig2_HtrdProc.cpp')
-rw-r--r--core/fxcodec/jbig2/JBig2_HtrdProc.cpp104
1 files changed, 104 insertions, 0 deletions
diff --git a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
new file mode 100644
index 0000000000..daee067d74
--- /dev/null
+++ b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
@@ -0,0 +1,104 @@
+// Copyright 2015 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fxcodec/jbig2/JBig2_HtrdProc.h"
+
+#include <memory>
+
+#include "core/fxcodec/jbig2/JBig2_GsidProc.h"
+#include "core/include/fxcrt/fx_basic.h"
+
+CJBig2_Image* CJBig2_HTRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
+ JBig2ArithCtx* gbContext,
+ IFX_Pause* pPause) {
+ FX_DWORD ng, mg;
+ int32_t x, y;
+ FX_DWORD HBPP;
+ FX_DWORD* GI;
+ std::unique_ptr<CJBig2_Image> HSKIP;
+ std::unique_ptr<CJBig2_Image> HTREG(new CJBig2_Image(HBW, HBH));
+ HTREG->fill(HDEFPIXEL);
+ if (HENABLESKIP == 1) {
+ HSKIP.reset(new CJBig2_Image(HGW, HGH));
+ for (mg = 0; mg < HGH; mg++) {
+ for (ng = 0; ng < HGW; ng++) {
+ x = (HGX + mg * HRY + ng * HRX) >> 8;
+ y = (HGY + mg * HRX - ng * HRY) >> 8;
+ if ((x + HPW <= 0) | (x >= (int32_t)HBW) | (y + HPH <= 0) |
+ (y >= (int32_t)HPH)) {
+ HSKIP->setPixel(ng, mg, 1);
+ } else {
+ HSKIP->setPixel(ng, mg, 0);
+ }
+ }
+ }
+ }
+ HBPP = 1;
+ while ((FX_DWORD)(1 << HBPP) < HNUMPATS) {
+ HBPP++;
+ }
+ std::unique_ptr<CJBig2_GSIDProc> pGID(new CJBig2_GSIDProc());
+ pGID->GSMMR = HMMR;
+ pGID->GSW = HGW;
+ pGID->GSH = HGH;
+ pGID->GSBPP = (uint8_t)HBPP;
+ pGID->GSUSESKIP = HENABLESKIP;
+ pGID->GSKIP = HSKIP.get();
+ pGID->GSTEMPLATE = HTEMPLATE;
+ GI = pGID->decode_Arith(pArithDecoder, gbContext, pPause);
+ if (!GI)
+ return nullptr;
+
+ for (mg = 0; mg < HGH; mg++) {
+ for (ng = 0; ng < HGW; ng++) {
+ x = (HGX + mg * HRY + ng * HRX) >> 8;
+ y = (HGY + mg * HRX - ng * HRY) >> 8;
+ FX_DWORD pat_index = GI[mg * HGW + ng];
+ if (pat_index >= HNUMPATS) {
+ pat_index = HNUMPATS - 1;
+ }
+ HTREG->composeFrom(x, y, HPATS[pat_index], HCOMBOP);
+ }
+ }
+ FX_Free(GI);
+ return HTREG.release();
+}
+
+CJBig2_Image* CJBig2_HTRDProc::decode_MMR(CJBig2_BitStream* pStream,
+ IFX_Pause* pPause) {
+ FX_DWORD ng, mg;
+ int32_t x, y;
+ FX_DWORD* GI;
+ std::unique_ptr<CJBig2_Image> HTREG(new CJBig2_Image(HBW, HBH));
+ HTREG->fill(HDEFPIXEL);
+ FX_DWORD HBPP = 1;
+ while ((FX_DWORD)(1 << HBPP) < HNUMPATS) {
+ HBPP++;
+ }
+ std::unique_ptr<CJBig2_GSIDProc> pGID(new CJBig2_GSIDProc());
+ pGID->GSMMR = HMMR;
+ pGID->GSW = HGW;
+ pGID->GSH = HGH;
+ pGID->GSBPP = (uint8_t)HBPP;
+ pGID->GSUSESKIP = 0;
+ GI = pGID->decode_MMR(pStream, pPause);
+ if (!GI)
+ return nullptr;
+
+ for (mg = 0; mg < HGH; mg++) {
+ for (ng = 0; ng < HGW; ng++) {
+ x = (HGX + mg * HRY + ng * HRX) >> 8;
+ y = (HGY + mg * HRX - ng * HRY) >> 8;
+ FX_DWORD pat_index = GI[mg * HGW + ng];
+ if (pat_index >= HNUMPATS) {
+ pat_index = HNUMPATS - 1;
+ }
+ HTREG->composeFrom(x, y, HPATS[pat_index], HCOMBOP);
+ }
+ }
+ FX_Free(GI);
+ return HTREG.release();
+}