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

Side by Side Diff: xfa/src/fxbarcode/src/BC_QRCoderBitVector.cpp

Issue 842043002: Organize barcode codes into modules. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: rebase Created 5 years, 11 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 unified diff | Download patch
« no previous file with comments | « xfa/src/fxbarcode/src/BC_QRCoder.cpp ('k') | xfa/src/fxbarcode/src/BC_QRCoderBlockPair.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_QRCoderBitVector.h"
25 CBC_QRCoderBitVector::CBC_QRCoderBitVector()
26 {
27 m_sizeInBits = 0;
28 m_size = 32;
29 }
30 void CBC_QRCoderBitVector::Init()
31 {
32 m_array = FX_Alloc(FX_BYTE, m_size);
33 }
34 CBC_QRCoderBitVector::~CBC_QRCoderBitVector()
35 {
36 if(m_array != NULL) {
37 FX_Free(m_array);
38 }
39 m_size = 0;
40 m_sizeInBits = 0;
41 }
42 void CBC_QRCoderBitVector::Clear()
43 {
44 if(m_array != NULL) {
45 FX_Free(m_array);
46 m_array = NULL;
47 }
48 m_sizeInBits = 0;
49 m_size = 32;
50 m_array = FX_Alloc(FX_BYTE, m_size);
51 }
52 FX_INT32 CBC_QRCoderBitVector::At(FX_INT32 index, FX_INT32 &e)
53 {
54 if(index < 0 || index >= m_sizeInBits) {
55 e = BCExceptionBadIndexException;
56 BC_EXCEPTION_CHECK_ReturnValue(e, 0);
57 }
58 FX_INT32 value = m_array[index >> 3] & 0xff;
59 return (value >> (7 - (index & 0x7))) & 1;
60 }
61 FX_INT32 CBC_QRCoderBitVector::sizeInBytes()
62 {
63 return (m_sizeInBits + 7) >> 3;
64 }
65 FX_INT32 CBC_QRCoderBitVector::Size()
66 {
67 return m_sizeInBits;
68 }
69 void CBC_QRCoderBitVector::AppendBit(FX_INT32 bit, FX_INT32 &e)
70 {
71 if(!(bit == 0 || bit == 1)) {
72 e = BCExceptionBadValueException;
73 BC_EXCEPTION_CHECK_ReturnVoid(e);
74 }
75 FX_INT32 numBitsInLastByte = m_sizeInBits & 0x7;
76 if(numBitsInLastByte == 0) {
77 AppendByte(0);
78 m_sizeInBits -= 8;
79 }
80 m_array[m_sizeInBits >> 3] |= (bit << (7 - numBitsInLastByte));
81 ++m_sizeInBits;
82 }
83 void CBC_QRCoderBitVector::AppendBits(FX_INT32 value, FX_INT32 numBits, FX_INT32 &e)
84 {
85 if (numBits < 0 || numBits > 32) {
86 e = BCExceptionBadNumBitsException;
87 BC_EXCEPTION_CHECK_ReturnVoid(e);
88 }
89 FX_INT32 numBitsLeft = numBits;
90 while (numBitsLeft > 0) {
91 if ((m_sizeInBits & 0x7) == 0 && numBitsLeft >= 8) {
92 FX_INT32 newByte = (value >> (numBitsLeft - 8)) & 0xff;
93 AppendByte(newByte);
94 numBitsLeft -= 8;
95 } else {
96 FX_INT32 bit = (value >> (numBitsLeft - 1)) & 1;
97 AppendBit(bit, e);
98 BC_EXCEPTION_CHECK_ReturnVoid(e);
99 --numBitsLeft;
100 }
101 }
102 }
103 void CBC_QRCoderBitVector::AppendBitVector(CBC_QRCoderBitVector *bits, FX_INT32 &e)
104 {
105 FX_INT32 size = bits->Size();
106 for(FX_INT32 i = 0; i < size; i++) {
107 FX_INT32 num = bits->At(i, e);
108 BC_EXCEPTION_CHECK_ReturnVoid(e);
109 AppendBit(num, e);
110 BC_EXCEPTION_CHECK_ReturnVoid(e)
111 }
112 }
113 void CBC_QRCoderBitVector::XOR(CBC_QRCoderBitVector *other, FX_INT32 &e)
114 {
115 if(m_sizeInBits != other->Size()) {
116 e = BCExceptioncanNotOperatexorOperator;
117 BC_EXCEPTION_CHECK_ReturnVoid(e);
118 }
119 FX_INT32 sizeInBytes = (m_sizeInBits + 7) >> 3;
120 for(FX_INT32 i = 0; i < sizeInBytes; ++i) {
121 m_array[i] ^= (other->GetArray())[i];
122 }
123 }
124 FX_BYTE* CBC_QRCoderBitVector::GetArray()
125 {
126 return m_array;
127 }
128 void CBC_QRCoderBitVector::AppendByte(FX_INT32 value)
129 {
130 if((m_sizeInBits >> 3) == m_size) {
131 FX_BYTE* newArray = FX_Alloc(FX_BYTE, m_size << 1);
132 FXSYS_memcpy32(newArray, m_array, m_size);
133 if(m_array != NULL) {
134 FX_Free(m_array);
135 }
136 m_array = newArray;
137 m_size = m_size << 1;
138 }
139 m_array[m_sizeInBits >> 3] = (FX_BYTE) value;
140 m_sizeInBits += 8;
141 }
OLDNEW
« no previous file with comments | « xfa/src/fxbarcode/src/BC_QRCoder.cpp ('k') | xfa/src/fxbarcode/src/BC_QRCoderBlockPair.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698