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 11 matching lines...) Expand all Loading... |
22 | 22 |
23 #include "../barcode.h" | 23 #include "../barcode.h" |
24 #include "BC_QRCoderBitVector.h" | 24 #include "BC_QRCoderBitVector.h" |
25 CBC_QRCoderBitVector::CBC_QRCoderBitVector() | 25 CBC_QRCoderBitVector::CBC_QRCoderBitVector() |
26 { | 26 { |
27 m_sizeInBits = 0; | 27 m_sizeInBits = 0; |
28 m_size = 32; | 28 m_size = 32; |
29 } | 29 } |
30 void CBC_QRCoderBitVector::Init() | 30 void CBC_QRCoderBitVector::Init() |
31 { | 31 { |
32 m_array = FX_Alloc(FX_BYTE, m_size); | 32 m_array = FX_Alloc(uint8_t, m_size); |
33 } | 33 } |
34 CBC_QRCoderBitVector::~CBC_QRCoderBitVector() | 34 CBC_QRCoderBitVector::~CBC_QRCoderBitVector() |
35 { | 35 { |
36 if(m_array != NULL) { | 36 if(m_array != NULL) { |
37 FX_Free(m_array); | 37 FX_Free(m_array); |
38 } | 38 } |
39 m_size = 0; | 39 m_size = 0; |
40 m_sizeInBits = 0; | 40 m_sizeInBits = 0; |
41 } | 41 } |
42 void CBC_QRCoderBitVector::Clear() | 42 void CBC_QRCoderBitVector::Clear() |
43 { | 43 { |
44 if(m_array != NULL) { | 44 if(m_array != NULL) { |
45 FX_Free(m_array); | 45 FX_Free(m_array); |
46 m_array = NULL; | 46 m_array = NULL; |
47 } | 47 } |
48 m_sizeInBits = 0; | 48 m_sizeInBits = 0; |
49 m_size = 32; | 49 m_size = 32; |
50 m_array = FX_Alloc(FX_BYTE, m_size); | 50 m_array = FX_Alloc(uint8_t, m_size); |
51 } | 51 } |
52 FX_INT32 CBC_QRCoderBitVector::At(FX_INT32 index, FX_INT32 &e) | 52 int32_t CBC_QRCoderBitVector::At(int32_t index, int32_t &e) |
53 { | 53 { |
54 if(index < 0 || index >= m_sizeInBits) { | 54 if(index < 0 || index >= m_sizeInBits) { |
55 e = BCExceptionBadIndexException; | 55 e = BCExceptionBadIndexException; |
56 BC_EXCEPTION_CHECK_ReturnValue(e, 0); | 56 BC_EXCEPTION_CHECK_ReturnValue(e, 0); |
57 } | 57 } |
58 FX_INT32 value = m_array[index >> 3] & 0xff; | 58 int32_t value = m_array[index >> 3] & 0xff; |
59 return (value >> (7 - (index & 0x7))) & 1; | 59 return (value >> (7 - (index & 0x7))) & 1; |
60 } | 60 } |
61 FX_INT32 CBC_QRCoderBitVector::sizeInBytes() | 61 int32_t CBC_QRCoderBitVector::sizeInBytes() |
62 { | 62 { |
63 return (m_sizeInBits + 7) >> 3; | 63 return (m_sizeInBits + 7) >> 3; |
64 } | 64 } |
65 FX_INT32 CBC_QRCoderBitVector::Size() | 65 int32_t CBC_QRCoderBitVector::Size() |
66 { | 66 { |
67 return m_sizeInBits; | 67 return m_sizeInBits; |
68 } | 68 } |
69 void CBC_QRCoderBitVector::AppendBit(FX_INT32 bit, FX_INT32 &e) | 69 void CBC_QRCoderBitVector::AppendBit(int32_t bit, int32_t &e) |
70 { | 70 { |
71 if(!(bit == 0 || bit == 1)) { | 71 if(!(bit == 0 || bit == 1)) { |
72 e = BCExceptionBadValueException; | 72 e = BCExceptionBadValueException; |
73 BC_EXCEPTION_CHECK_ReturnVoid(e); | 73 BC_EXCEPTION_CHECK_ReturnVoid(e); |
74 } | 74 } |
75 FX_INT32 numBitsInLastByte = m_sizeInBits & 0x7; | 75 int32_t numBitsInLastByte = m_sizeInBits & 0x7; |
76 if(numBitsInLastByte == 0) { | 76 if(numBitsInLastByte == 0) { |
77 AppendByte(0); | 77 AppendByte(0); |
78 m_sizeInBits -= 8; | 78 m_sizeInBits -= 8; |
79 } | 79 } |
80 m_array[m_sizeInBits >> 3] |= (bit << (7 - numBitsInLastByte)); | 80 m_array[m_sizeInBits >> 3] |= (bit << (7 - numBitsInLastByte)); |
81 ++m_sizeInBits; | 81 ++m_sizeInBits; |
82 } | 82 } |
83 void CBC_QRCoderBitVector::AppendBits(FX_INT32 value, FX_INT32 numBits, FX_INT32
&e) | 83 void CBC_QRCoderBitVector::AppendBits(int32_t value, int32_t numBits, int32_t &e
) |
84 { | 84 { |
85 if (numBits < 0 || numBits > 32) { | 85 if (numBits < 0 || numBits > 32) { |
86 e = BCExceptionBadNumBitsException; | 86 e = BCExceptionBadNumBitsException; |
87 BC_EXCEPTION_CHECK_ReturnVoid(e); | 87 BC_EXCEPTION_CHECK_ReturnVoid(e); |
88 } | 88 } |
89 FX_INT32 numBitsLeft = numBits; | 89 int32_t numBitsLeft = numBits; |
90 while (numBitsLeft > 0) { | 90 while (numBitsLeft > 0) { |
91 if ((m_sizeInBits & 0x7) == 0 && numBitsLeft >= 8) { | 91 if ((m_sizeInBits & 0x7) == 0 && numBitsLeft >= 8) { |
92 FX_INT32 newByte = (value >> (numBitsLeft - 8)) & 0xff; | 92 int32_t newByte = (value >> (numBitsLeft - 8)) & 0xff; |
93 AppendByte(newByte); | 93 AppendByte(newByte); |
94 numBitsLeft -= 8; | 94 numBitsLeft -= 8; |
95 } else { | 95 } else { |
96 FX_INT32 bit = (value >> (numBitsLeft - 1)) & 1; | 96 int32_t bit = (value >> (numBitsLeft - 1)) & 1; |
97 AppendBit(bit, e); | 97 AppendBit(bit, e); |
98 BC_EXCEPTION_CHECK_ReturnVoid(e); | 98 BC_EXCEPTION_CHECK_ReturnVoid(e); |
99 --numBitsLeft; | 99 --numBitsLeft; |
100 } | 100 } |
101 } | 101 } |
102 } | 102 } |
103 void CBC_QRCoderBitVector::AppendBitVector(CBC_QRCoderBitVector *bits, FX_INT32
&e) | 103 void CBC_QRCoderBitVector::AppendBitVector(CBC_QRCoderBitVector *bits, int32_t &
e) |
104 { | 104 { |
105 FX_INT32 size = bits->Size(); | 105 int32_t size = bits->Size(); |
106 for(FX_INT32 i = 0; i < size; i++) { | 106 for(int32_t i = 0; i < size; i++) { |
107 FX_INT32 num = bits->At(i, e); | 107 int32_t num = bits->At(i, e); |
108 BC_EXCEPTION_CHECK_ReturnVoid(e); | 108 BC_EXCEPTION_CHECK_ReturnVoid(e); |
109 AppendBit(num, e); | 109 AppendBit(num, e); |
110 BC_EXCEPTION_CHECK_ReturnVoid(e) | 110 BC_EXCEPTION_CHECK_ReturnVoid(e) |
111 } | 111 } |
112 } | 112 } |
113 void CBC_QRCoderBitVector::XOR(CBC_QRCoderBitVector *other, FX_INT32 &e) | 113 void CBC_QRCoderBitVector::XOR(CBC_QRCoderBitVector *other, int32_t &e) |
114 { | 114 { |
115 if(m_sizeInBits != other->Size()) { | 115 if(m_sizeInBits != other->Size()) { |
116 e = BCExceptioncanNotOperatexorOperator; | 116 e = BCExceptioncanNotOperatexorOperator; |
117 BC_EXCEPTION_CHECK_ReturnVoid(e); | 117 BC_EXCEPTION_CHECK_ReturnVoid(e); |
118 } | 118 } |
119 FX_INT32 sizeInBytes = (m_sizeInBits + 7) >> 3; | 119 int32_t sizeInBytes = (m_sizeInBits + 7) >> 3; |
120 for(FX_INT32 i = 0; i < sizeInBytes; ++i) { | 120 for(int32_t i = 0; i < sizeInBytes; ++i) { |
121 m_array[i] ^= (other->GetArray())[i]; | 121 m_array[i] ^= (other->GetArray())[i]; |
122 } | 122 } |
123 } | 123 } |
124 FX_BYTE* CBC_QRCoderBitVector::GetArray() | 124 uint8_t* CBC_QRCoderBitVector::GetArray() |
125 { | 125 { |
126 return m_array; | 126 return m_array; |
127 } | 127 } |
128 void CBC_QRCoderBitVector::AppendByte(FX_INT32 value) | 128 void CBC_QRCoderBitVector::AppendByte(int32_t value) |
129 { | 129 { |
130 if((m_sizeInBits >> 3) == m_size) { | 130 if((m_sizeInBits >> 3) == m_size) { |
131 FX_BYTE* newArray = FX_Alloc(FX_BYTE, m_size << 1); | 131 uint8_t* newArray = FX_Alloc(uint8_t, m_size << 1); |
132 FXSYS_memcpy32(newArray, m_array, m_size); | 132 FXSYS_memcpy32(newArray, m_array, m_size); |
133 if(m_array != NULL) { | 133 if(m_array != NULL) { |
134 FX_Free(m_array); | 134 FX_Free(m_array); |
135 } | 135 } |
136 m_array = newArray; | 136 m_array = newArray; |
137 m_size = m_size << 1; | 137 m_size = m_size << 1; |
138 } | 138 } |
139 m_array[m_sizeInBits >> 3] = (FX_BYTE) value; | 139 m_array[m_sizeInBits >> 3] = (uint8_t) value; |
140 m_sizeInBits += 8; | 140 m_sizeInBits += 8; |
141 } | 141 } |
OLD | NEW |