-
Notifications
You must be signed in to change notification settings - Fork 0
/
codetest.c
83 lines (71 loc) · 2.12 KB
/
codetest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* Copyright 2005 Andrew Rice
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* Email: acr31@cam.ac.uk
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "options.h"
#include "image.h"
#include "recognise.h"
#include "codegen_util.h"
int main(int argc,char** argv) {
if (argc != 2) {
printf("%s [code as hex]\n",argv[0]);
exit(-1);
}
unsigned char code[PAYLOAD_SIZE_BYTES] = {0};
unsigned char decoded[PAYLOAD_SIZE_BYTES] = {0};
unsigned char samplebuffer[EDGE_CELLS*EDGE_CELLS] = {0};
unsigned char image[IMAGE_BYTES_PER_LINE*IMAGE_WIDTH];
int i;
int read_order[EDGE_CELLS*EDGE_CELLS];
memset(image,255,IMAGE_BYTES_PER_LINE*IMAGE_WIDTH);
populate_read_order(read_order);
parse_code(argv[1],code);
encode(code,samplebuffer);
draw(image,samplebuffer,read_order);
printf("Encoded:\t");
for(i=0;i<PAYLOAD_SIZE_BYTES;++i) {
printf("%.2X ",code[i]);
}
printf("\n");
/* Save encoded tag: */
printf("Saving encoded image into encoded-tag.pnm...");
save_image(image, "encoded-tag.pnm", 0);
printf(" [DONE]\n");
if (process_image(image,decoded,read_order)) {
printf("Decoded:\t");
for(i=0;i<PAYLOAD_SIZE_BYTES;++i) {
printf("%.2X ",decoded[i]);
}
printf("\n");
for(i=0;i<PAYLOAD_SIZE_BYTES;++i) {
if (code[i] != decoded[i]) {
printf("Payload mismatch\n");
return -1;
}
}
}
else {
printf("Failed to decode image\n");
return -1;
}
return 1;
}