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