| 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/src/fxcodec/jbig2/JBig2_BitStream.h" | 7 #include "core/fxcodec/jbig2/JBig2_BitStream.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "core/include/fpdfapi/cpdf_stream.h" | 11 #include "core/include/fpdfapi/cpdf_stream.h" |
| 12 | 12 |
| 13 CJBig2_BitStream::CJBig2_BitStream(CPDF_StreamAcc* pSrcStream) | 13 CJBig2_BitStream::CJBig2_BitStream(CPDF_StreamAcc* pSrcStream) |
| 14 : m_pBuf(pSrcStream->GetData()), | 14 : m_pBuf(pSrcStream->GetData()), |
| 15 m_dwLength(pSrcStream->GetSize()), | 15 m_dwLength(pSrcStream->GetSize()), |
| 16 m_dwByteIdx(0), | 16 m_dwByteIdx(0), |
| 17 m_dwBitIdx(0), | 17 m_dwBitIdx(0), |
| 18 m_dwObjNum(pSrcStream->GetStream() ? pSrcStream->GetStream()->GetObjNum() | 18 m_dwObjNum(pSrcStream->GetStream() ? pSrcStream->GetStream()->GetObjNum() |
| 19 : 0) { | 19 : 0) { |
| 20 if (m_dwLength > 256 * 1024 * 1024) { | 20 if (m_dwLength > 256 * 1024 * 1024) { |
| 21 m_dwLength = 0; | 21 m_dwLength = 0; |
| 22 m_pBuf = nullptr; | 22 m_pBuf = nullptr; |
| 23 } | 23 } |
| 24 } | 24 } |
| 25 | 25 |
| 26 CJBig2_BitStream::~CJBig2_BitStream() { | 26 CJBig2_BitStream::~CJBig2_BitStream() {} |
| 27 } | |
| 28 | 27 |
| 29 int32_t CJBig2_BitStream::readNBits(FX_DWORD dwBits, FX_DWORD* dwResult) { | 28 int32_t CJBig2_BitStream::readNBits(FX_DWORD dwBits, FX_DWORD* dwResult) { |
| 30 FX_DWORD dwBitPos = getBitPos(); | 29 FX_DWORD dwBitPos = getBitPos(); |
| 31 if (dwBitPos > LengthInBits()) | 30 if (dwBitPos > LengthInBits()) |
| 32 return -1; | 31 return -1; |
| 33 | 32 |
| 34 *dwResult = 0; | 33 *dwResult = 0; |
| 35 if (dwBitPos + dwBits <= LengthInBits()) | 34 if (dwBitPos + dwBits <= LengthInBits()) |
| 36 dwBitPos = dwBits; | 35 dwBitPos = dwBits; |
| 37 else | 36 else |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 return m_dwByteIdx < m_dwLength; | 179 return m_dwByteIdx < m_dwLength; |
| 181 } | 180 } |
| 182 | 181 |
| 183 FX_DWORD CJBig2_BitStream::LengthInBits() const { | 182 FX_DWORD CJBig2_BitStream::LengthInBits() const { |
| 184 return m_dwLength << 3; | 183 return m_dwLength << 3; |
| 185 } | 184 } |
| 186 | 185 |
| 187 FX_DWORD CJBig2_BitStream::getObjNum() const { | 186 FX_DWORD CJBig2_BitStream::getObjNum() const { |
| 188 return m_dwObjNum; | 187 return m_dwObjNum; |
| 189 } | 188 } |
| OLD | NEW |