OLD | NEW |
| (Empty) |
1 // Copyright 2014 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 // Original code is licensed as follows: | |
7 /* | |
8 * Copyright 2007 ZXing authors | |
9 * | |
10 * Licensed under the Apache License, Version 2.0 (the "License"); | |
11 * you may not use this file except in compliance with the License. | |
12 * You may obtain a copy of the License at | |
13 * | |
14 * http://www.apache.org/licenses/LICENSE-2.0 | |
15 * | |
16 * Unless required by applicable law or agreed to in writing, software | |
17 * distributed under the License is distributed on an "AS IS" BASIS, | |
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
19 * See the License for the specific language governing permissions and | |
20 * limitations under the License. | |
21 */ | |
22 | |
23 #include "barcode.h" | |
24 #include "include/BC_CommonBitArray.h" | |
25 CBC_CommonBitArray::CBC_CommonBitArray(CBC_CommonBitArray* array) | |
26 { | |
27 m_size = array->GetSize(); | |
28 m_bits.Copy(array->GetBits()); | |
29 } | |
30 CBC_CommonBitArray::CBC_CommonBitArray() | |
31 { | |
32 m_bits.SetSize(1); | |
33 m_size = 0; | |
34 } | |
35 CBC_CommonBitArray::CBC_CommonBitArray(FX_INT32 size) | |
36 { | |
37 m_bits.SetSize((size + 31) >> 5); | |
38 m_size = size; | |
39 } | |
40 CBC_CommonBitArray::~CBC_CommonBitArray() | |
41 { | |
42 m_size = 0; | |
43 } | |
44 FX_INT32 CBC_CommonBitArray::GetSize() | |
45 { | |
46 return m_size; | |
47 } | |
48 CFX_Int32Array& CBC_CommonBitArray::GetBits() | |
49 { | |
50 return m_bits; | |
51 } | |
52 FX_INT32 CBC_CommonBitArray::GetSizeInBytes() | |
53 { | |
54 return (m_size + 7) >> 3; | |
55 } | |
56 FX_BOOL CBC_CommonBitArray::Get(FX_INT32 i) | |
57 { | |
58 return (m_bits[i >> 5] & (1 << (i & 0x1f))) != 0; | |
59 } | |
60 void CBC_CommonBitArray::Set(FX_INT32 i) | |
61 { | |
62 m_bits[i >> 5] |= 1 << (i & 0x1F); | |
63 } | |
64 void CBC_CommonBitArray::Flip(FX_INT32 i) | |
65 { | |
66 m_bits[i >> 5] ^= 1 << (i & 0x1F); | |
67 } | |
68 void CBC_CommonBitArray::SetBulk(FX_INT32 i, FX_INT32 newBits) | |
69 { | |
70 m_bits[i >> 5] = newBits; | |
71 } | |
72 void CBC_CommonBitArray::Clear() | |
73 { | |
74 FXSYS_memset32(&m_bits[0], 0x00, m_bits.GetSize() * sizeof(FX_INT32)); | |
75 } | |
76 FX_BOOL CBC_CommonBitArray::IsRange(FX_INT32 start, FX_INT32 end, FX_BOOL value,
FX_INT32 &e) | |
77 { | |
78 if (end < start) { | |
79 e = BCExceptionEndLessThanStart; | |
80 return FALSE; | |
81 } | |
82 if (end == start) { | |
83 return TRUE; | |
84 } | |
85 end--; | |
86 FX_INT32 firstInt = start >> 5; | |
87 FX_INT32 lastInt = end >> 5; | |
88 FX_INT32 i; | |
89 for (i = firstInt; i <= lastInt; i++) { | |
90 FX_INT32 firstBit = i > firstInt ? 0 : start & 0x1F; | |
91 FX_INT32 lastBit = i < lastInt ? 31 : end & 0x1F; | |
92 FX_INT32 mask; | |
93 if (firstBit == 0 && lastBit == 31) { | |
94 mask = -1; | |
95 } else { | |
96 mask = 0; | |
97 for (FX_INT32 j = firstBit; j <= lastBit; j++) { | |
98 mask |= 1 << j; | |
99 } | |
100 } | |
101 if ((m_bits[i] & mask) != (value ? mask : 0)) { | |
102 return FALSE; | |
103 } | |
104 } | |
105 return TRUE; | |
106 } | |
107 FX_INT32* CBC_CommonBitArray::GetBitArray() | |
108 { | |
109 return &m_bits[0]; | |
110 } | |
111 void CBC_CommonBitArray::Reverse() | |
112 { | |
113 FX_INT32* newBits = FX_Alloc(FX_INT32, m_bits.GetSize()); | |
114 FXSYS_memset32(newBits, 0x00, m_bits.GetSize() * sizeof(FX_INT32)); | |
115 FX_INT32 size = m_size; | |
116 FX_INT32 i; | |
117 for (i = 0; i < size; i++) { | |
118 if (Get(size - i - 1)) { | |
119 newBits[i >> 5] |= 1 << (i & 0x1F); | |
120 } | |
121 } | |
122 FXSYS_memcpy32(&m_bits[0], newBits, m_bits.GetSize() * sizeof(FX_INT32)); | |
123 FX_Free(newBits); | |
124 } | |
OLD | NEW |