diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2016-03-14 13:35:12 -0400 |
---|---|---|
committer | Dan Sinclair <dsinclair@chromium.org> | 2016-03-14 13:35:12 -0400 |
commit | 764ec513eecbebd12781bcc96ce81ed5e736ee92 (patch) | |
tree | 12763fde4be1f10ea1183d92185917b2b587e00b /core/fxcodec/jbig2/JBig2_HuffmanDecoder.cpp | |
parent | 97da97662417085774f75c26e535c6fbe70266ae (diff) | |
download | pdfium-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_HuffmanDecoder.cpp')
-rw-r--r-- | core/fxcodec/jbig2/JBig2_HuffmanDecoder.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/core/fxcodec/jbig2/JBig2_HuffmanDecoder.cpp b/core/fxcodec/jbig2/JBig2_HuffmanDecoder.cpp new file mode 100644 index 0000000000..afcc17a55e --- /dev/null +++ b/core/fxcodec/jbig2/JBig2_HuffmanDecoder.cpp @@ -0,0 +1,45 @@ +// Copyright 2014 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_HuffmanDecoder.h" + +#include "core/fxcodec/jbig2/JBig2_Define.h" + +CJBig2_HuffmanDecoder::CJBig2_HuffmanDecoder(CJBig2_BitStream* pStream) + : m_pStream(pStream) {} + +CJBig2_HuffmanDecoder::~CJBig2_HuffmanDecoder() {} + +int CJBig2_HuffmanDecoder::decodeAValue(CJBig2_HuffmanTable* pTable, + int* nResult) { + int nVal = 0; + int nBits = 0; + while (1) { + FX_DWORD nTmp; + if (m_pStream->read1Bit(&nTmp) == -1) + break; + + nVal = (nVal << 1) | nTmp; + ++nBits; + for (FX_DWORD i = 0; i < pTable->Size(); ++i) { + if (pTable->GetPREFLEN()[i] == nBits && pTable->GetCODES()[i] == nVal) { + if (pTable->IsHTOOB() && i == pTable->Size() - 1) + return JBIG2_OOB; + + if (m_pStream->readNBits(pTable->GetRANGELEN()[i], &nTmp) == -1) + return -1; + + FX_DWORD offset = pTable->IsHTOOB() ? 3 : 2; + if (i == pTable->Size() - offset) + *nResult = pTable->GetRANGELOW()[i] - nTmp; + else + *nResult = pTable->GetRANGELOW()[i] + nTmp; + return 0; + } + } + } + return -1; +} |