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_CommonBitMatrix.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_CommonBitArray.h"
25 #include "include/BC_CommonBitMatrix.h"
26 CBC_CommonBitMatrix::CBC_CommonBitMatrix()
27 {
28 m_width = 0;
29 m_height = 0;
30 m_rowSize = 0;
31 m_bits = NULL;
32 }
33 void CBC_CommonBitMatrix::Init(FX_INT32 dimension)
34 {
35 m_width = dimension;
36 m_height = dimension;
37 FX_INT32 rowSize = (m_height + 31) >> 5;
38 m_rowSize = rowSize;
39 m_bits = FX_Alloc(FX_INT32, m_rowSize * m_height);
40 FXSYS_memset32(m_bits, 0, m_rowSize * m_height * sizeof(FX_INT32));
41 }
42 void CBC_CommonBitMatrix::Init(FX_INT32 width, FX_INT32 height)
43 {
44 m_width = width;
45 m_height = height;
46 FX_INT32 rowSize = (width + 31) >> 5;
47 m_rowSize = rowSize;
48 m_bits = FX_Alloc(FX_INT32, m_rowSize * m_height);
49 FXSYS_memset32(m_bits, 0, m_rowSize * m_height * sizeof(FX_INT32));
50 }
51 CBC_CommonBitMatrix::~CBC_CommonBitMatrix()
52 {
53 if (m_bits != NULL) {
54 FX_Free(m_bits);
55 }
56 m_bits = NULL;
57 m_height = m_width = m_rowSize = 0;
58 }
59 FX_BOOL CBC_CommonBitMatrix::Get(FX_INT32 x, FX_INT32 y)
60 {
61 FX_INT32 offset = y * m_rowSize + (x >> 5);
62 if (offset >= m_rowSize * m_height || offset < 0) {
63 return false;
64 }
65 return ((((FX_DWORD)m_bits[offset]) >> (x & 0x1f)) & 1) != 0;
66 }
67 FX_INT32* CBC_CommonBitMatrix::GetBits()
68 {
69 return m_bits;
70 }
71 void CBC_CommonBitMatrix::Set(FX_INT32 x, FX_INT32 y)
72 {
73 FX_INT32 offset = y * m_rowSize + (x >> 5);
74 if (offset >= m_rowSize * m_height || offset < 0) {
75 return;
76 }
77 m_bits[offset] |= 1 << (x & 0x1f);
78 }
79 void CBC_CommonBitMatrix::Flip(FX_INT32 x, FX_INT32 y)
80 {
81 FX_INT32 offset = y * m_rowSize + (x >> 5);
82 m_bits[offset] ^= 1 << (x & 0x1f);
83 }
84 void CBC_CommonBitMatrix::Clear()
85 {
86 FXSYS_memset32(m_bits, 0, m_rowSize * m_height * sizeof(FX_INT32));
87 }
88 void CBC_CommonBitMatrix::SetRegion(FX_INT32 left, FX_INT32 top, FX_INT32 width, FX_INT32 height, FX_INT32 &e)
89 {
90 if (top < 0 || left < 0) {
91 e = BCExceptionLeftAndTopMustBeNonnegative;
92 return;
93 }
94 if (height < 1 || width < 1) {
95 e = BCExceptionHeightAndWidthMustBeAtLeast1;
96 return;
97 }
98 FX_INT32 right = left + width;
99 FX_INT32 bottom = top + height;
100 if (m_height < bottom || m_width < right) {
101 e = BCExceptionRegionMustFitInsideMatrix;
102 return;
103 }
104 FX_INT32 y;
105 for (y = top; y < bottom; y++) {
106 FX_INT32 offset = y * m_rowSize;
107 FX_INT32 x;
108 for (x = left; x < right; x++) {
109 m_bits[offset + (x >> 5)] |= 1 << (x & 0x1f);
110 }
111 }
112 }
113 CBC_CommonBitArray* CBC_CommonBitMatrix::GetRow(FX_INT32 y, CBC_CommonBitArray* row)
114 {
115 CBC_CommonBitArray* rowArray = NULL;
116 if (row == NULL || row->GetSize() < m_width) {
117 rowArray = FX_NEW CBC_CommonBitArray(m_width);
118 } else {
119 rowArray = FX_NEW CBC_CommonBitArray(row);
120 }
121 FX_INT32 offset = y * m_rowSize;
122 FX_INT32 x;
123 for (x = 0; x < m_rowSize; x++) {
124 rowArray->SetBulk(x << 5, m_bits[offset + x]);
125 }
126 return rowArray;
127 }
128 void CBC_CommonBitMatrix::SetRow(FX_INT32 y, CBC_CommonBitArray* row)
129 {
130 FX_INT32 l = y * m_rowSize;
131 for (FX_INT32 i = 0; i < m_rowSize; i++) {
132 m_bits[l] = row->GetBitArray()[i];
133 l++;
134 }
135 }
136 void CBC_CommonBitMatrix::SetCol(FX_INT32 y, CBC_CommonBitArray* col)
137 {
138 for (FX_INT32 i = 0; i < col->GetBits().GetSize(); i++) {
139 m_bits[i * m_rowSize + y] = col->GetBitArray()[i];
140 }
141 }
142 FX_INT32 CBC_CommonBitMatrix::GetWidth()
143 {
144 return m_width;
145 }
146 FX_INT32 CBC_CommonBitMatrix::GetHeight()
147 {
148 return m_height;
149 }
150 FX_INT32 CBC_CommonBitMatrix::GetRowSize()
151 {
152 return m_rowSize;
153 }
154 FX_INT32 CBC_CommonBitMatrix::GetDimension(FX_INT32 &e)
155 {
156 if (m_width != m_height) {
157 e = BCExceptionCanNotCallGetDimensionOnNonSquareMatrix;
158 return 0;
159 }
160 return m_width;
161 }
OLDNEW
« no previous file with comments | « xfa/src/fxbarcode/src/BC_CommonBitArray.cpp ('k') | xfa/src/fxbarcode/src/BC_CommonBitSource.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698