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 29 matching lines...) Expand all Loading... |
40 } | 40 } |
41 int32_t CBC_CommonBitArray::GetSize() { | 41 int32_t CBC_CommonBitArray::GetSize() { |
42 return m_size; | 42 return m_size; |
43 } | 43 } |
44 CFX_Int32Array& CBC_CommonBitArray::GetBits() { | 44 CFX_Int32Array& CBC_CommonBitArray::GetBits() { |
45 return m_bits; | 45 return m_bits; |
46 } | 46 } |
47 int32_t CBC_CommonBitArray::GetSizeInBytes() { | 47 int32_t CBC_CommonBitArray::GetSizeInBytes() { |
48 return (m_size + 7) >> 3; | 48 return (m_size + 7) >> 3; |
49 } | 49 } |
50 FX_BOOL CBC_CommonBitArray::Get(int32_t i) { | 50 bool CBC_CommonBitArray::Get(int32_t i) { |
51 return (m_bits[i >> 5] & (1 << (i & 0x1f))) != 0; | 51 return (m_bits[i >> 5] & (1 << (i & 0x1f))) != 0; |
52 } | 52 } |
53 void CBC_CommonBitArray::Set(int32_t i) { | 53 void CBC_CommonBitArray::Set(int32_t i) { |
54 m_bits[i >> 5] |= 1 << (i & 0x1F); | 54 m_bits[i >> 5] |= 1 << (i & 0x1F); |
55 } | 55 } |
56 void CBC_CommonBitArray::Flip(int32_t i) { | 56 void CBC_CommonBitArray::Flip(int32_t i) { |
57 m_bits[i >> 5] ^= 1 << (i & 0x1F); | 57 m_bits[i >> 5] ^= 1 << (i & 0x1F); |
58 } | 58 } |
59 void CBC_CommonBitArray::SetBulk(int32_t i, int32_t newBits) { | 59 void CBC_CommonBitArray::SetBulk(int32_t i, int32_t newBits) { |
60 m_bits[i >> 5] = newBits; | 60 m_bits[i >> 5] = newBits; |
61 } | 61 } |
62 void CBC_CommonBitArray::Clear() { | 62 void CBC_CommonBitArray::Clear() { |
63 FXSYS_memset(&m_bits[0], 0x00, m_bits.GetSize() * sizeof(int32_t)); | 63 FXSYS_memset(&m_bits[0], 0x00, m_bits.GetSize() * sizeof(int32_t)); |
64 } | 64 } |
65 FX_BOOL CBC_CommonBitArray::IsRange(int32_t start, | 65 bool CBC_CommonBitArray::IsRange(int32_t start, |
66 int32_t end, | 66 int32_t end, |
67 FX_BOOL value, | 67 bool value, |
68 int32_t& e) { | 68 int32_t& e) { |
69 if (end < start) { | 69 if (end < start) { |
70 e = BCExceptionEndLessThanStart; | 70 e = BCExceptionEndLessThanStart; |
71 return FALSE; | 71 return false; |
72 } | 72 } |
73 if (end == start) { | 73 if (end == start) { |
74 return TRUE; | 74 return true; |
75 } | 75 } |
76 end--; | 76 end--; |
77 int32_t firstInt = start >> 5; | 77 int32_t firstInt = start >> 5; |
78 int32_t lastInt = end >> 5; | 78 int32_t lastInt = end >> 5; |
79 int32_t i; | 79 int32_t i; |
80 for (i = firstInt; i <= lastInt; i++) { | 80 for (i = firstInt; i <= lastInt; i++) { |
81 int32_t firstBit = i > firstInt ? 0 : start & 0x1F; | 81 int32_t firstBit = i > firstInt ? 0 : start & 0x1F; |
82 int32_t lastBit = i < lastInt ? 31 : end & 0x1F; | 82 int32_t lastBit = i < lastInt ? 31 : end & 0x1F; |
83 int32_t mask; | 83 int32_t mask; |
84 if (firstBit == 0 && lastBit == 31) { | 84 if (firstBit == 0 && lastBit == 31) { |
85 mask = -1; | 85 mask = -1; |
86 } else { | 86 } else { |
87 mask = 0; | 87 mask = 0; |
88 for (int32_t j = firstBit; j <= lastBit; j++) { | 88 for (int32_t j = firstBit; j <= lastBit; j++) { |
89 mask |= 1 << j; | 89 mask |= 1 << j; |
90 } | 90 } |
91 } | 91 } |
92 if ((m_bits[i] & mask) != (value ? mask : 0)) { | 92 if ((m_bits[i] & mask) != (value ? mask : 0)) { |
93 return FALSE; | 93 return false; |
94 } | 94 } |
95 } | 95 } |
96 return TRUE; | 96 return true; |
97 } | 97 } |
98 int32_t* CBC_CommonBitArray::GetBitArray() { | 98 int32_t* CBC_CommonBitArray::GetBitArray() { |
99 return &m_bits[0]; | 99 return &m_bits[0]; |
100 } | 100 } |
101 void CBC_CommonBitArray::Reverse() { | 101 void CBC_CommonBitArray::Reverse() { |
102 int32_t* newBits = FX_Alloc(int32_t, m_bits.GetSize()); | 102 int32_t* newBits = FX_Alloc(int32_t, m_bits.GetSize()); |
103 FXSYS_memset(newBits, 0x00, m_bits.GetSize() * sizeof(int32_t)); | 103 FXSYS_memset(newBits, 0x00, m_bits.GetSize() * sizeof(int32_t)); |
104 int32_t size = m_size; | 104 int32_t size = m_size; |
105 int32_t i; | 105 int32_t i; |
106 for (i = 0; i < size; i++) { | 106 for (i = 0; i < size; i++) { |
107 if (Get(size - i - 1)) { | 107 if (Get(size - i - 1)) { |
108 newBits[i >> 5] |= 1 << (i & 0x1F); | 108 newBits[i >> 5] |= 1 << (i & 0x1F); |
109 } | 109 } |
110 } | 110 } |
111 FXSYS_memcpy(&m_bits[0], newBits, m_bits.GetSize() * sizeof(int32_t)); | 111 FXSYS_memcpy(&m_bits[0], newBits, m_bits.GetSize() * sizeof(int32_t)); |
112 FX_Free(newBits); | 112 FX_Free(newBits); |
113 } | 113 } |
OLD | NEW |