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

Side by Side Diff: xfa/src/fxbarcode/src/BC_CommonBitSource.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
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_CommonBitSource.h"
25 CBC_CommonBitSource::CBC_CommonBitSource(CFX_ByteArray* bytes)
26 {
27 m_bytes.Copy((*bytes));
28 m_bitOffset = 0;
29 m_byteOffset = 0;
30 }
31 CBC_CommonBitSource::~CBC_CommonBitSource()
32 {
33 }
34 FX_INT32 CBC_CommonBitSource::ReadBits(FX_INT32 numBits, FX_INT32 &e)
35 {
36 if (numBits < 1 || numBits > 32) {
37 e = BCExceptionIllegalArgument;
38 return 0;
39 }
40 FX_INT32 result = 0;
41 if (m_bitOffset > 0) {
42 FX_INT32 bitsLeft = 8 - m_bitOffset;
43 FX_INT32 toRead = numBits < bitsLeft ? numBits : bitsLeft;
44 FX_INT32 bitsToNotRead = bitsLeft - toRead;
45 FX_INT32 mask = (0xff >> (8 - toRead)) << bitsToNotRead;
46 result = (m_bytes[m_byteOffset] & mask) >> bitsToNotRead;
47 numBits -= toRead;
48 m_bitOffset += toRead;
49 if (m_bitOffset == 8) {
50 m_bitOffset = 0;
51 m_byteOffset++;
52 }
53 }
54 if (numBits > 0) {
55 while(numBits >= 8) {
56 result = (result << 8) | (m_bytes[m_byteOffset] & 0xff);
57 m_byteOffset++;
58 numBits -= 8;
59 }
60 if (numBits > 0) {
61 FX_INT32 bitsToNotRead = 8 - numBits;
62 FX_INT32 mask = (0xff >> bitsToNotRead) << bitsToNotRead;
63 result = (result << numBits) | ((m_bytes[m_byteOffset] & mask) >> bi tsToNotRead);
64 m_bitOffset += numBits;
65 }
66 }
67 return result;
68 }
69 FX_INT32 CBC_CommonBitSource::Available()
70 {
71 return 8 * (m_bytes.GetSize() - m_byteOffset) - m_bitOffset;
72 }
73 FX_INT32 CBC_CommonBitSource::getByteOffset()
74 {
75 return m_byteOffset;
76 }
OLDNEW
« no previous file with comments | « xfa/src/fxbarcode/src/BC_CommonBitMatrix.cpp ('k') | xfa/src/fxbarcode/src/BC_CommonByteArray.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698