comparison mupdf-source/thirdparty/zint/backend/pdf417_trace.h @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 /* pdf417_trace.h - Trace routines for optimal PDF417 optimization algorithm */
2 /*
3 libzint - the open source barcode library
4 Copyright (C) 2022-2023 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_PDF417_TRACE_H
34 #define Z_PDF417_TRACE_H
35
36 #ifndef PDF_TRACE
37 #define PDF_TRACE_Edges(px, s, l, p, v)
38 #define PDF_TRACE_AddEdge(s, l, es, p, v, t, e) do { (void)(s); (void)(l); } while (0)
39 #define PDF_TRACE_NotAddEdge(s, l, es, p, v, t, e) do { (void)(s); (void)(l); } while (0)
40 #else
41
42 static int PDF_TRACE_getPreviousMode(struct pdf_edge *edges, struct pdf_edge *edge) {
43 struct pdf_edge *previous = PDF_PREVIOUS(edges, edge);
44 return previous == NULL ? PDF_ALP : previous->mode;
45 }
46
47 static void PDF_TRACE_EdgeToString(char *buf, const unsigned char *source, const int length, struct pdf_edge *edges,
48 struct pdf_edge *edge) {
49 int previousMode = PDF_TRACE_getPreviousMode(edges, edge);
50 (void)length;
51 if (buf) {
52 sprintf(buf, "%d_%c %c(%d,%d) %d(%d,%d,%d) -> %d_%c",
53 edge->from, pdf_smodes[previousMode], pdf_smodes[edge->mode], source[edge->from], edge->len, edge->size
54 + edge->unit_size, edge->units, edge->unit_size, edge->size, edge->from + 1, pdf_smodes[edge->mode]);
55 } else {
56 printf("%d_%c %c(%d,%d) %d(%d,%d,%d) -> %d_%c",
57 edge->from, pdf_smodes[previousMode], pdf_smodes[edge->mode], source[edge->from], edge->len, edge->size
58 + edge->unit_size, edge->units, edge->unit_size, edge->size, edge->from + 1, pdf_smodes[edge->mode]);
59 }
60 }
61
62 static void PDF_TRACE_Path(const unsigned char *source, const int length, struct pdf_edge *edges,
63 struct pdf_edge *edge, char *result, const int result_size) {
64 PDF_TRACE_EdgeToString(result, source, length, edges, edge);
65 struct pdf_edge *current = PDF_PREVIOUS(edges, edge);
66 while (current) {
67 char s[256];
68 char *pos;
69 int len;
70 PDF_TRACE_EdgeToString(s, source, length, edges, current);
71 pos = strrchr(s, ' ');
72 assert(pos);
73 len = strlen(result);
74 if ((pos - s) + 1 + len + 1 >= result_size) {
75 result[result_size - 4] = '\0';
76 strcat(result, "...");
77 break;
78 }
79 memmove(result + (pos - s) + 1, result, len + 1);
80 memcpy(result, s, (pos - s) + 1);
81 current = PDF_PREVIOUS(edges, current);
82 }
83 puts(result);
84 }
85
86 static void PDF_TRACE_Edges(const char *prefix, const unsigned char *source, const int length,
87 struct pdf_edge *edges, const int vertexIndex) {
88 int i, j, e_i;
89 char result[1024 * 2];
90 if (vertexIndex) {
91 printf(prefix, vertexIndex);
92 } else {
93 fputs(prefix, stdout);
94 }
95 for (i = vertexIndex; i <= length; i++) {
96 e_i = i * PDF_NUM_MODES;
97 for (j = 0; j < PDF_NUM_MODES; j++) {
98 if (edges[e_i + j].mode) {
99 fputs(" **** ", stdout);
100 PDF_TRACE_Path(source, length, edges, edges + e_i + j, result, (int) ARRAY_SIZE(result));
101 }
102 }
103 }
104 }
105
106 static void PDF_TRACE_AddEdge(const unsigned char *source, const int length, struct pdf_edge *edges,
107 struct pdf_edge *previous, const int vertexIndex, const int t_table, struct pdf_edge *edge) {
108 const int new_size = edge->size + edge->unit_size;
109 const int v_ij = vertexIndex * PDF_NUM_MODES + edge->mode - 1;
110 const int v_size = edges[v_ij].size + edges[v_ij].unit_size;
111
112 (void)source; (void)length;
113
114 printf("add mode %c, t_table 0x%X, previous %d, from %d, len %d, v_ij %d, %d(%d,%d,%d) > %d(%d,%d,%d)\n",
115 pdf_smodes[edge->mode], t_table, previous ? (int) (previous - edges) : 0, edge->from, edge->len, v_ij,
116 v_size, edges[v_ij].units, edges[v_ij].unit_size, edges[v_ij].size,
117 new_size, edge->units, edge->unit_size, edge->size);
118 }
119
120 static void PDF_TRACE_NotAddEdge(const unsigned char *source, const int length, struct pdf_edge *edges,
121 struct pdf_edge *previous, const int vertexIndex, const int t_table, struct pdf_edge *edge) {
122 const int new_size = edge->size + edge->unit_size;
123 const int v_ij = vertexIndex * PDF_NUM_MODES + edge->mode - 1;
124 const int v_size = edges[v_ij].size + edges[v_ij].unit_size;
125
126 (void)source; (void)length;
127
128 printf("NOT mode %c, t_table %d, previous %d, from %d, len %d, v_ij %d, %d(%d,%d,%d) <= %d(%d,%d,%d)\n",
129 pdf_smodes[edge->mode], t_table, previous ? (int) (previous - edges) : 0, edge->from, edge->len, v_ij,
130 v_size, edges[v_ij].units, edges[v_ij].unit_size, edges[v_ij].size,
131 new_size, edge->units, edge->unit_size, edge->size);
132 }
133
134 #endif /* PDF_TRACE */
135 /* vim: set ts=4 sw=4 et : */
136 #endif /* Z_PDF417_TRACE_H */