int ctob[26][5] = {
/*{ 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 1 }, { 0, 0, 0, 1, 0 },*/ { 0, 0, 0, 1, 1 },
/*{ 0, 0, 1, 0, 0 },*/ { 0, 0, 1, 0, 1 }, { 0, 0, 1, 1, 0 }, { 0, 0, 1, 1, 1 },
/*{ 0, 1, 0, 0, 0 },*/ { 0, 1, 0, 0, 1 }, { 0, 1, 0, 1, 0 }, { 0, 1, 0, 1, 1 },
{ 0, 1, 1, 0, 0 }, { 0, 1, 1, 0, 1 }, { 0, 1, 1, 1, 0 }, { 0, 1, 1, 1, 1 },
/*{ 1, 0, 0, 0, 0 },*/ { 1, 0, 0, 0, 1 }, { 1, 0, 0, 1, 0 }, { 1, 0, 0, 1, 1 },
{ 1, 0, 1, 0, 0 }, { 1, 0, 1, 0, 1 }, { 1, 0, 1, 1, 0 }, { 1, 0, 1, 1, 1 },
{ 1, 1, 0, 0, 0 }, { 1, 1, 0, 0, 1 }, { 1, 1, 0, 1, 0 }, { 1, 1, 0, 1, 1 },
{ 1, 1, 1, 0, 0 }, { 1, 1, 1, 0, 1 }, { 1, 1, 1, 1, 0 }, { 1, 1, 1, 1, 1 } };
char btoc[33] = "000A0BCD0EFGHIJK0LMNOPQRSTUVWXYZ";
inline void mark0(char QRC[100][100], int y, int x) {
QRC[y][x] = QRC[y][x + 1] = QRC[y][x + 2] =
QRC[y + 1][x] = QRC[y + 1][x + 1] = QRC[y + 1][x + 2] =
QRC[y + 2][x] = QRC[y + 2][x + 1] = QRC[y + 2][x + 2] = 0;
}
void encode(char QRC[100][100], char SRC[100]) {
for (int i = 0; i < 100; ++i)
for (int k = 0; k < 100; ++k)
QRC[i][k] = 1;
int y = 3;
int x = 3;
for (int i = 0; i < 100; ++i) {
int num = SRC[i] - 'A';
for (int k = 0; k < 5; ++k) {
if (ctob[num][k] == 0)
mark0(QRC, y, x);
x += 4;
if (x > 95) {
x = 3;
y += 4;
}
}
}
}
int find_marker_y(char GRY[100][100], int sy, int sx) {
int cnt = 0;
for (int y = sy; y < 100; ++y) {
if (GRY[y][sx] == 4)
cnt++;
else
return 0;
if (cnt == 49)
return 1;
}
return 0;
}
void find_marker(char GRY[100][100], int *my, int *mx) {
*mx = *my = -1;
for (int y = 0; y <= 50; ++y) {
int cnt = 0;
int sx = -1;
for (int x = 0; x < 100; ++x) {
if (GRY[y][x] == 4) {
cnt++;
if (sx == -1)
sx = x;
if (cnt == 49) {
if (find_marker_y(GRY, y, sx) == 1) {
*mx = sx;
*my = y;
return;
}
sx++;
cnt--;
}
} else {
cnt = 0;
sx = -1;
if (x > 50)
break;
}
}
}
}
int get(char GRY[100][100], int y, int x) {
int num = GRY[y][x] + GRY[y + 1][x] + GRY[y][x + 1] + GRY[y + 1][x + 1];
if (num == 16)
return 1;
return 0;
}
void decode(char GRY[100][100], char DST[100]) {
int mx, my;
find_marker(GRY, &my, &mx);
if (mx == -1)
return;
mx++;
my++;
int x = mx;
for (int i = 0; i < 100; ++i) {
int num = 0;
for (int k = 0; k < 5; ++k) {
int bit = get(GRY, my, x);
num = num * 2 + bit;
x += 2;
if (x > mx + 47) {
x = mx;
my += 2;
}
}
DST[i] = btoc[num];
}
}
댓글