Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Unified Diff: core/src/fxcodec/jbig2/JBig2_BitStream.h

Issue 1390883004: Merge to XFA: Stop inlining CJBig2_BitStream. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « BUILD.gn ('k') | core/src/fxcodec/jbig2/JBig2_BitStream.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/src/fxcodec/jbig2/JBig2_BitStream.h
diff --git a/core/src/fxcodec/jbig2/JBig2_BitStream.h b/core/src/fxcodec/jbig2/JBig2_BitStream.h
index 85c992f4ff7a941311e247f254851fc022ab96c1..9a3d8b0a18d7e3f8ee3698f334fc2cf145d7db60 100644
--- a/core/src/fxcodec/jbig2/JBig2_BitStream.h
+++ b/core/src/fxcodec/jbig2/JBig2_BitStream.h
@@ -4,287 +4,51 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#ifndef _JBIG2_BIT_STREAM_H_
-#define _JBIG2_BIT_STREAM_H_
+#ifndef CORE_SRC_FXCODEC_JBIG2_JBIG2_BITSTREAM_H_
+#define CORE_SRC_FXCODEC_JBIG2_JBIG2_BITSTREAM_H_
-#include "JBig2_Define.h"
+#include "../../../include/fxcrt/fx_basic.h"
class CJBig2_BitStream {
public:
CJBig2_BitStream(const uint8_t* pBuffer, FX_DWORD dwLength);
-
- CJBig2_BitStream(CJBig2_BitStream& bs);
-
~CJBig2_BitStream();
+ // TODO(thestig): readFoo() should return bool.
int32_t readNBits(FX_DWORD nBits, FX_DWORD* dwResult);
-
int32_t readNBits(FX_DWORD nBits, int32_t* nResult);
-
int32_t read1Bit(FX_DWORD* dwResult);
-
int32_t read1Bit(FX_BOOL* bResult);
-
int32_t read1Byte(uint8_t* cResult);
-
int32_t readInteger(FX_DWORD* dwResult);
-
int32_t readShortInteger(FX_WORD* wResult);
-
void alignByte();
-
- void align4Byte();
-
- uint8_t getAt(FX_DWORD dwOffset);
-
- uint8_t getCurByte();
-
- uint8_t getNextByte();
-
- int32_t incByteIdx();
-
- uint8_t getCurByte_arith();
-
- uint8_t getNextByte_arith();
-
- FX_DWORD getOffset();
-
+ uint8_t getCurByte() const;
+ void incByteIdx();
+ uint8_t getCurByte_arith() const;
+ uint8_t getNextByte_arith() const;
+ FX_DWORD getOffset() const;
void setOffset(FX_DWORD dwOffset);
-
- FX_DWORD getBitPos();
-
+ FX_DWORD getBitPos() const;
void setBitPos(FX_DWORD dwBitPos);
-
- const uint8_t* getBuf();
-
- FX_DWORD getLength() { return m_dwLength; }
-
- const uint8_t* getPointer();
-
+ const uint8_t* getBuf() const;
+ FX_DWORD getLength() const { return m_dwLength; }
+ const uint8_t* getPointer() const;
void offset(FX_DWORD dwOffset);
-
- FX_DWORD getByteLeft();
+ FX_DWORD getByteLeft() const;
private:
- const uint8_t* m_pBuf;
+ void AdvanceBit();
+ bool IsInBound() const;
+ FX_DWORD LengthInBits() const;
+ const uint8_t* m_pBuf;
FX_DWORD m_dwLength;
-
FX_DWORD m_dwByteIdx;
-
FX_DWORD m_dwBitIdx;
-};
-inline CJBig2_BitStream::CJBig2_BitStream(const uint8_t* pBuffer,
- FX_DWORD dwLength) {
- m_pBuf = pBuffer;
- m_dwLength = dwLength;
- m_dwByteIdx = 0;
- m_dwBitIdx = 0;
- if (m_dwLength > 256 * 1024 * 1024) {
- m_dwLength = 0;
- m_pBuf = NULL;
- }
-}
-inline CJBig2_BitStream::CJBig2_BitStream(CJBig2_BitStream& bs) {
- m_pBuf = bs.m_pBuf;
- m_dwLength = bs.m_dwLength;
- m_dwByteIdx = bs.m_dwByteIdx;
- m_dwBitIdx = bs.m_dwBitIdx;
-}
-inline CJBig2_BitStream::~CJBig2_BitStream() {}
-inline int32_t CJBig2_BitStream::readNBits(FX_DWORD dwBits,
- FX_DWORD* dwResult) {
- FX_DWORD dwTemp = (m_dwByteIdx << 3) + m_dwBitIdx;
- if (dwTemp <= (m_dwLength << 3)) {
- *dwResult = 0;
- if (dwTemp + dwBits <= (m_dwLength << 3)) {
- dwTemp = dwBits;
- } else {
- dwTemp = (m_dwLength << 3) - dwTemp;
- }
- while (dwTemp > 0) {
- *dwResult =
- (*dwResult << 1) | ((m_pBuf[m_dwByteIdx] >> (7 - m_dwBitIdx)) & 0x01);
- if (m_dwBitIdx == 7) {
- m_dwByteIdx++;
- m_dwBitIdx = 0;
- } else {
- m_dwBitIdx++;
- }
- dwTemp--;
- }
- return 0;
- } else {
- return -1;
- }
-}
-inline int32_t CJBig2_BitStream::readNBits(FX_DWORD dwBits, int32_t* nResult) {
- FX_DWORD dwTemp = (m_dwByteIdx << 3) + m_dwBitIdx;
- if (dwTemp <= (m_dwLength << 3)) {
- *nResult = 0;
- if (dwTemp + dwBits <= (m_dwLength << 3)) {
- dwTemp = dwBits;
- } else {
- dwTemp = (m_dwLength << 3) - dwTemp;
- }
- while (dwTemp > 0) {
- *nResult =
- (*nResult << 1) | ((m_pBuf[m_dwByteIdx] >> (7 - m_dwBitIdx)) & 0x01);
- if (m_dwBitIdx == 7) {
- m_dwByteIdx++;
- m_dwBitIdx = 0;
- } else {
- m_dwBitIdx++;
- }
- dwTemp--;
- }
- return 0;
- } else {
- return -1;
- }
-}
-
-inline int32_t CJBig2_BitStream::read1Bit(FX_DWORD* dwResult) {
- if (m_dwByteIdx < m_dwLength) {
- *dwResult = (m_pBuf[m_dwByteIdx] >> (7 - m_dwBitIdx)) & 0x01;
- if (m_dwBitIdx == 7) {
- m_dwByteIdx++;
- m_dwBitIdx = 0;
- } else {
- m_dwBitIdx++;
- }
- return 0;
- } else {
- return -1;
- }
-}
-inline int32_t CJBig2_BitStream::read1Bit(FX_BOOL* bResult) {
- if (m_dwByteIdx < m_dwLength) {
- *bResult = (m_pBuf[m_dwByteIdx] >> (7 - m_dwBitIdx)) & 0x01;
- if (m_dwBitIdx == 7) {
- m_dwByteIdx++;
- m_dwBitIdx = 0;
- } else {
- m_dwBitIdx++;
- }
- return 0;
- } else {
- return -1;
- }
-}
-inline int32_t CJBig2_BitStream::read1Byte(uint8_t* cResult) {
- if (m_dwByteIdx < m_dwLength) {
- *cResult = m_pBuf[m_dwByteIdx];
- m_dwByteIdx++;
- return 0;
- } else {
- return -1;
- }
-}
-
-inline int32_t CJBig2_BitStream::readInteger(FX_DWORD* dwResult) {
- if (m_dwByteIdx + 3 < m_dwLength) {
- *dwResult = (m_pBuf[m_dwByteIdx] << 24) | (m_pBuf[m_dwByteIdx + 1] << 16) |
- (m_pBuf[m_dwByteIdx + 2] << 8) | m_pBuf[m_dwByteIdx + 3];
- m_dwByteIdx += 4;
- return 0;
- } else {
- return -1;
- }
-}
+ CJBig2_BitStream(const CJBig2_BitStream&) = delete;
+ void operator=(const CJBig2_BitStream&) = delete;
+};
-inline int32_t CJBig2_BitStream::readShortInteger(FX_WORD* dwResult) {
- if (m_dwByteIdx + 1 < m_dwLength) {
- *dwResult = (m_pBuf[m_dwByteIdx] << 8) | m_pBuf[m_dwByteIdx + 1];
- m_dwByteIdx += 2;
- return 0;
- } else {
- return -1;
- }
-}
-inline void CJBig2_BitStream::alignByte() {
- if (m_dwBitIdx != 0) {
- m_dwByteIdx++;
- m_dwBitIdx = 0;
- }
-}
-inline void CJBig2_BitStream::align4Byte() {
- if (m_dwBitIdx != 0) {
- m_dwByteIdx++;
- m_dwBitIdx = 0;
- }
- m_dwByteIdx = (m_dwByteIdx + 3) & -4;
-}
-inline uint8_t CJBig2_BitStream::getAt(FX_DWORD dwOffset) {
- if (dwOffset < m_dwLength) {
- return m_pBuf[dwOffset];
- } else {
- return 0;
- }
-}
-inline uint8_t CJBig2_BitStream::getCurByte() {
- if (m_dwByteIdx < m_dwLength) {
- return m_pBuf[m_dwByteIdx];
- } else {
- return 0;
- }
-}
-inline uint8_t CJBig2_BitStream::getNextByte() {
- if (m_dwByteIdx + 1 < m_dwLength) {
- return m_pBuf[m_dwByteIdx + 1];
- } else {
- return 0;
- }
-}
-inline int32_t CJBig2_BitStream::incByteIdx() {
- if (m_dwByteIdx < m_dwLength) {
- m_dwByteIdx++;
- return 0;
- } else {
- return -1;
- }
-}
-inline uint8_t CJBig2_BitStream::getCurByte_arith() {
- if (m_dwByteIdx < m_dwLength) {
- return m_pBuf[m_dwByteIdx];
- } else {
- return 0xff;
- }
-}
-inline uint8_t CJBig2_BitStream::getNextByte_arith() {
- if (m_dwByteIdx + 1 < m_dwLength) {
- return m_pBuf[m_dwByteIdx + 1];
- } else {
- return 0xff;
- }
-}
-inline FX_DWORD CJBig2_BitStream::getOffset() {
- return m_dwByteIdx;
-}
-inline void CJBig2_BitStream::setOffset(FX_DWORD dwOffset) {
- if (dwOffset > m_dwLength) {
- dwOffset = m_dwLength;
- }
- m_dwByteIdx = dwOffset;
-}
-inline FX_DWORD CJBig2_BitStream::getBitPos() {
- return (m_dwByteIdx << 3) + m_dwBitIdx;
-}
-inline void CJBig2_BitStream::setBitPos(FX_DWORD dwBitPos) {
- m_dwByteIdx = dwBitPos >> 3;
- m_dwBitIdx = dwBitPos & 7;
-}
-inline const uint8_t* CJBig2_BitStream::getBuf() {
- return m_pBuf;
-}
-inline const uint8_t* CJBig2_BitStream::getPointer() {
- return m_pBuf + m_dwByteIdx;
-}
-inline void CJBig2_BitStream::offset(FX_DWORD dwOffset) {
- m_dwByteIdx += dwOffset;
-}
-inline FX_DWORD CJBig2_BitStream::getByteLeft() {
- return m_dwLength - m_dwByteIdx;
-}
-#endif
+#endif // CORE_SRC_FXCODEC_JBIG2_JBIG2_BITSTREAM_H_
« no previous file with comments | « BUILD.gn ('k') | core/src/fxcodec/jbig2/JBig2_BitStream.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698