8
9
10
11
12
13
14
15
16
17
18
19
20
21
23#include "fxbarcode/datamatrix/BC_DefaultPlacement.h"
29#include "core/fxcrt/data_vector.h"
30#include "core/fxcrt/fx_2d_size.h"
31#include "fxbarcode/datamatrix/BC_Encoder.h"
32#include "third_party/base/check_op.h"
36size_t GetIndex(size_t col, size_t row, size_t num_cols) {
37 return row * num_cols + col;
49 CHECK_GT(m_numrows, 0);
50 CHECK_GT(m_numcols, 0);
56bool CBC_DefaultPlacement::
GetBit(int32_t col, int32_t row)
const {
59 CHECK_LT(col, m_numcols);
60 CHECK_LT(row, m_numrows);
61 return m_bits[GetIndex(col, row, m_numcols)] == 1;
64void CBC_DefaultPlacement::SetBit(int32_t col, int32_t row,
bool bit) {
67 DCHECK_LT(col, m_numcols);
68 DCHECK_LT(row, m_numrows);
69 m_bits[GetIndex(col, row, m_numcols)] = bit ? 1 : 0;
72bool CBC_DefaultPlacement::HasBit(int32_t col, int32_t row)
const {
75 DCHECK_LT(col, m_numcols);
76 DCHECK_LT(row, m_numrows);
77 return m_bits[GetIndex(col, row, m_numcols)] != 2;
80void CBC_DefaultPlacement::Init() {
85 if ((row == m_numrows) && (col == 0)) {
88 if ((row == m_numrows - 2) && (col == 0) && ((m_numcols % 4) != 0)) {
91 if ((row == m_numrows - 2) && (col == 0) && (m_numcols % 8 == 4)) {
94 if ((row == m_numrows + 4) && (col == 2) && ((m_numcols % 8) == 0)) {
98 if ((row < m_numrows) && (col >= 0) && !HasBit(col, row)) {
99 SetUtah(row, col, pos++);
103 }
while (row >= 0 && (col < m_numcols));
107 if ((row >= 0) && (col < m_numcols) && !HasBit(col, row)) {
108 SetUtah(row, col, pos++);
112 }
while ((row < m_numrows) && (col >= 0));
115 }
while ((row < m_numrows) || (col < m_numcols));
116 if (!HasBit(m_numcols - 1, m_numrows - 1)) {
117 SetBit(m_numcols - 1, m_numrows - 1,
true);
118 SetBit(m_numcols - 2, m_numrows - 2,
true);
122void CBC_DefaultPlacement::SetModule(int32_t row,
128 col += 4 - ((m_numrows + 4) % 8);
132 row += 4 - ((m_numcols + 4) % 8);
134 int32_t v = m_codewords[pos];
136 SetBit(col, row, v != 0);
139void CBC_DefaultPlacement::SetUtah(int32_t row, int32_t col, int32_t pos) {
140 SetModule(row - 2, col - 2, pos, 1);
141 SetModule(row - 2, col - 1, pos, 2);
142 SetModule(row - 1, col - 2, pos, 3);
143 SetModule(row - 1, col - 1, pos, 4);
144 SetModule(row - 1, col, pos, 5);
145 SetModule(row, col - 2, pos, 6);
146 SetModule(row, col - 1, pos, 7);
147 SetModule(row, col, pos, 8);
150void CBC_DefaultPlacement::SetCorner1(int32_t pos) {
151 SetModule(m_numrows - 1, 0, pos, 1);
152 SetModule(m_numrows - 1, 1, pos, 2);
153 SetModule(m_numrows - 1, 2, pos, 3);
154 SetModule(0, m_numcols - 2, pos, 4);
155 SetModule(0, m_numcols - 1, pos, 5);
156 SetModule(1, m_numcols - 1, pos, 6);
157 SetModule(2, m_numcols - 1, pos, 7);
158 SetModule(3, m_numcols - 1, pos, 8);
161void CBC_DefaultPlacement::SetCorner2(int32_t pos) {
162 SetModule(m_numrows - 3, 0, pos, 1);
163 SetModule(m_numrows - 2, 0, pos, 2);
164 SetModule(m_numrows - 1, 0, pos, 3);
165 SetModule(0, m_numcols - 4, pos, 4);
166 SetModule(0, m_numcols - 3, pos, 5);
167 SetModule(0, m_numcols - 2, pos, 6);
168 SetModule(0, m_numcols - 1, pos, 7);
169 SetModule(1, m_numcols - 1, pos, 8);
172void CBC_DefaultPlacement::SetCorner3(int32_t pos) {
173 SetModule(m_numrows - 3, 0, pos, 1);
174 SetModule(m_numrows - 2, 0, pos, 2);
175 SetModule(m_numrows - 1, 0, pos, 3);
176 SetModule(0, m_numcols - 2, pos, 4);
177 SetModule(0, m_numcols - 1, pos, 5);
178 SetModule(1, m_numcols - 1, pos, 6);
179 SetModule(2, m_numcols - 1, pos, 7);
180 SetModule(3, m_numcols - 1, pos, 8);
183void CBC_DefaultPlacement::SetCorner4(int32_t pos) {
184 SetModule(m_numrows - 1, 0, pos, 1);
185 SetModule(m_numrows - 1, m_numcols - 1, pos, 2);
186 SetModule(0, m_numcols - 3, pos, 3);
187 SetModule(0, m_numcols - 2, pos, 4);
188 SetModule(0, m_numcols - 1, pos, 5);
189 SetModule(1, m_numcols - 3, pos, 6);
190 SetModule(1, m_numcols - 2, pos, 7);
191 SetModule(1, m_numcols - 1, pos, 8);
bool GetBit(int32_t col, int32_t row) const
CBC_DefaultPlacement(WideString codewords, int32_t numcols, int32_t numrows)