wxMaxima
Loading...
Searching...
No Matches
aztec_trace.h
1/* aztec_trace.h - Trace routines for optimized AZTEC encodation algorithm */
2/*
3 libzint - the open source barcode library
4 Copyright (C) 2026 Robin Stuart <rstuart114@gmail.com>
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15 3. Neither the name of the project nor the names of its contributors
16 may be used to endorse or promote products derived from this software
17 without specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 SUCH DAMAGE.
30 */
31/* SPDX-License-Identifier: BSD-3-Clause */
32
33#ifndef Z_AZTEC_TRACE_H
34#define Z_AZTEC_TRACE_H
35
36static void AZ_TRACE_EdgeToString(char *buf, const unsigned char *source, const int length, const char initial_mode,
37 struct az_edge *edges, struct az_edge *edge) {
38 struct az_edge *previous_edge = AZ_PREVIOUS(edges, edge);
39 int previousMode = previous_edge ? previous_edge->mode : initial_mode;
40 int previous = previous_edge ? (int) (previous_edge - edges) : 0;
41 int current = (int) (edge - edges);
42 (void)length;
43 if (buf) {
44 sprintf(buf, "%d_%c_%d %c(%d,%d) %d -> %d_%c_%d",
45 edge->from, az_mode_char(previousMode), previous, az_mode_char(edge->mode), source[edge->from], edge->len,
46 edge->size, edge->from + 1, az_mode_char(edge->mode), current);
47 } else {
48 printf("%d_%c_%d %c(%d,%d) %d -> %d_%c_%d",
49 edge->from, az_mode_char(previousMode), previous, az_mode_char(edge->mode), source[edge->from], edge->len,
50 edge->size, edge->from + 1, az_mode_char(edge->mode), current);
51 }
52}
53
54static void AZ_TRACE_Path(const unsigned char *source, const int length, const char initial_mode,
55 struct az_edge *edges, struct az_edge *edge, char *result, const int result_size) {
56 struct az_edge *current;
57 AZ_TRACE_EdgeToString(result, source, length, initial_mode, edges, edge);
58 current = AZ_PREVIOUS(edges, edge);
59 while (current) {
60 char s[256];
61 char *pos;
62 int len;
63 AZ_TRACE_EdgeToString(s, source, length, initial_mode, edges, current);
64 pos = strrchr(s, ' ');
65 assert(pos);
66 len = strlen(result);
67 if ((pos - s) + 1 + len + 1 >= result_size) {
68 memcpy(result + result_size - 4, "...", 4); /* Include terminating NUL */
69 break;
70 }
71 memmove(result + (pos - s) + 1, result, len + 1);
72 memcpy(result, s, (pos - s) + 1);
73 current = AZ_PREVIOUS(edges, current);
74 }
75 puts(result);
76}
77
78static void AZ_TRACE_Edges(const char *prefix, const unsigned char *source, const int length, const char initial_mode,
79 struct az_edge *edges, const int vertexIndex) {
80 int i, j, e_i;
81 char result[1024 * 2];
82 if (vertexIndex) {
83 printf(prefix, vertexIndex);
84 } else {
85 fputs(prefix, stdout);
86 }
87 for (i = vertexIndex; i <= length; i++) {
88 e_i = i * AZ_NUM_MODES;
89 for (j = 0; j < AZ_NUM_MODES; j++) {
90 if (edges[e_i + j].mode) {
91 fputs(" **** ", stdout);
92 AZ_TRACE_Path(source, length, initial_mode, edges, edges + e_i + j, result, (int) ARRAY_SIZE(result));
93 }
94 }
95 }
96}
97
98static void AZ_TRACE_AddEdge(const unsigned char *source, const int length, struct az_edge *edges,
99 struct az_edge *previous, const int vertexIndex, struct az_edge *edge) {
100 const int v_ij = vertexIndex * AZ_NUM_MODES + AZ_MASK(edge->mode) - 1;
101
102 (void)source; (void)length;
103
104 printf("add mode %c_%d, previous %d, from %d, len %d, v_ij mode %d || v_ij.size %d >= edge->size %d\n",
105 az_mode_char(edge->mode), v_ij, previous ? (int) (previous - edges) : 0, edge->from, edge->len,
106 edges[v_ij].mode, edges[v_ij].size, edge->size);
107}
108
109static void AZ_TRACE_NotAddEdge(const unsigned char *source, const int length, struct az_edge *edges,
110 struct az_edge *previous, const int vertexIndex, const int e_ij, struct az_edge *edge) {
111 const int v_ij = vertexIndex * AZ_NUM_MODES + AZ_MASK(edge->mode) - 1;
112
113 (void)source; (void)length; (void)e_ij;
114
115 printf("NOT mode %c_%d, previous %d, from %d, len %d, v_ij.size %d < edge->size %d\n",
116 az_mode_char(edge->mode), v_ij, previous ? (int) (previous - edges) : 0, edge->from, edge->len,
117 edges[v_ij].size, edge->size);
118}
119
120/* vim: set ts=4 sw=4 et : */
121#endif /* Z_AZTEC_TRACE_H */