-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeco_code.c
63 lines (51 loc) · 1.82 KB
/
deco_code.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
// Copyright (C) 2019 Pieter Goetschalckx
//
// 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 3 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, see <https://www.gnu.org/licenses/>.
#include <stdlib.h>
#include <stdio.h>
#include "decogen.h"
#include "planar_code.h"
static void compute_deco_code(PreDeco *pd, unsigned char *code, int dual) {
int number[pd->size];
compute_planar_code(pd, code, number);
code += 1 + pd->size + pd->nedges;
Edge *edge = pd->v1;
*code = dual + 2 * (edge->label != 4);
code++;
*code = number[edge->start]; code++;
*code = number[edge->end]; code++;
do {
if (edge == pd->v2 || edge == pd->v0) { *code = 0; code++; }
edge = edge->next->inverse;
if (edge->label == 1) {
*code = 1; code++;
} else if (edge->label == 3) {
*code = 2; code++;
edge = edge->next->inverse;
}
} while (edge != pd->v1);
*code = 0; code++;
}
void write_deco_header() {
unsigned char header[13] = ">>deco_code<<";
fwrite(header, sizeof(unsigned char), 13, OUTFILE);
}
void write_deco_code(PreDeco *pd) {
int size = 5 * pd->size + 3 - pd->extensions - (pd->v1->label == 4);
unsigned char code[size];
compute_deco_code(pd, code, 0);
fwrite(code, sizeof(unsigned char), size, OUTFILE);
compute_deco_code(pd, code, 1);
fwrite(code, sizeof(unsigned char), size, OUTFILE);
}