OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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 // Original code is licensed as follows: | 6 // Original code is licensed as follows: |
7 /* | 7 /* |
8 * Copyright 2007 ZXing authors | 8 * Copyright 2007 ZXing authors |
9 * | 9 * |
10 * Licensed under the Apache License, Version 2.0 (the "License"); | 10 * Licensed under the Apache License, Version 2.0 (the "License"); |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "BC_CommonBitSource.h" | 24 #include "BC_CommonBitSource.h" |
25 CBC_CommonBitSource::CBC_CommonBitSource(CFX_ByteArray* bytes) | 25 CBC_CommonBitSource::CBC_CommonBitSource(CFX_ByteArray* bytes) |
26 { | 26 { |
27 m_bytes.Copy((*bytes)); | 27 m_bytes.Copy((*bytes)); |
28 m_bitOffset = 0; | 28 m_bitOffset = 0; |
29 m_byteOffset = 0; | 29 m_byteOffset = 0; |
30 } | 30 } |
31 CBC_CommonBitSource::~CBC_CommonBitSource() | 31 CBC_CommonBitSource::~CBC_CommonBitSource() |
32 { | 32 { |
33 } | 33 } |
34 FX_INT32 CBC_CommonBitSource::ReadBits(FX_INT32 numBits, FX_INT32 &e) | 34 int32_t CBC_CommonBitSource::ReadBits(int32_t numBits, int32_t &e) |
35 { | 35 { |
36 if (numBits < 1 || numBits > 32) { | 36 if (numBits < 1 || numBits > 32) { |
37 e = BCExceptionIllegalArgument; | 37 e = BCExceptionIllegalArgument; |
38 return 0; | 38 return 0; |
39 } | 39 } |
40 FX_INT32 result = 0; | 40 int32_t result = 0; |
41 if (m_bitOffset > 0) { | 41 if (m_bitOffset > 0) { |
42 FX_INT32 bitsLeft = 8 - m_bitOffset; | 42 int32_t bitsLeft = 8 - m_bitOffset; |
43 FX_INT32 toRead = numBits < bitsLeft ? numBits : bitsLeft; | 43 int32_t toRead = numBits < bitsLeft ? numBits : bitsLeft; |
44 FX_INT32 bitsToNotRead = bitsLeft - toRead; | 44 int32_t bitsToNotRead = bitsLeft - toRead; |
45 FX_INT32 mask = (0xff >> (8 - toRead)) << bitsToNotRead; | 45 int32_t mask = (0xff >> (8 - toRead)) << bitsToNotRead; |
46 result = (m_bytes[m_byteOffset] & mask) >> bitsToNotRead; | 46 result = (m_bytes[m_byteOffset] & mask) >> bitsToNotRead; |
47 numBits -= toRead; | 47 numBits -= toRead; |
48 m_bitOffset += toRead; | 48 m_bitOffset += toRead; |
49 if (m_bitOffset == 8) { | 49 if (m_bitOffset == 8) { |
50 m_bitOffset = 0; | 50 m_bitOffset = 0; |
51 m_byteOffset++; | 51 m_byteOffset++; |
52 } | 52 } |
53 } | 53 } |
54 if (numBits > 0) { | 54 if (numBits > 0) { |
55 while(numBits >= 8) { | 55 while(numBits >= 8) { |
56 result = (result << 8) | (m_bytes[m_byteOffset] & 0xff); | 56 result = (result << 8) | (m_bytes[m_byteOffset] & 0xff); |
57 m_byteOffset++; | 57 m_byteOffset++; |
58 numBits -= 8; | 58 numBits -= 8; |
59 } | 59 } |
60 if (numBits > 0) { | 60 if (numBits > 0) { |
61 FX_INT32 bitsToNotRead = 8 - numBits; | 61 int32_t bitsToNotRead = 8 - numBits; |
62 FX_INT32 mask = (0xff >> bitsToNotRead) << bitsToNotRead; | 62 int32_t mask = (0xff >> bitsToNotRead) << bitsToNotRead; |
63 result = (result << numBits) | ((m_bytes[m_byteOffset] & mask) >> bi
tsToNotRead); | 63 result = (result << numBits) | ((m_bytes[m_byteOffset] & mask) >> bi
tsToNotRead); |
64 m_bitOffset += numBits; | 64 m_bitOffset += numBits; |
65 } | 65 } |
66 } | 66 } |
67 return result; | 67 return result; |
68 } | 68 } |
69 FX_INT32 CBC_CommonBitSource::Available() | 69 int32_t CBC_CommonBitSource::Available() |
70 { | 70 { |
71 return 8 * (m_bytes.GetSize() - m_byteOffset) - m_bitOffset; | 71 return 8 * (m_bytes.GetSize() - m_byteOffset) - m_bitOffset; |
72 } | 72 } |
73 FX_INT32 CBC_CommonBitSource::getByteOffset() | 73 int32_t CBC_CommonBitSource::getByteOffset() |
74 { | 74 { |
75 return m_byteOffset; | 75 return m_byteOffset; |
76 } | 76 } |
OLD | NEW |