comparison mupdf-source/thirdparty/zint/extras/sunburst.c @ 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 /*
2 * sunburst.c
3 *
4 * Many encoding schemes were put forward when the UPC system was being considered,
5 * and this code encodes numeric data according to one of the more interesting looking
6 * varieties. The system proposed by Charecogn Systems Inc. doesn't seem to have had
7 * an official name, but "sunburst" seems appropriate from its appearance. The idea was
8 * that the symbol would be read by a sensor mounted on a rotating head.
9 *
10 * This code takes numeric data and produces an image as an SVG.
11 *
12 * More details in US Patent 3,636,317, Filed April 28th 1969.
13 *
14 */
15
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <math.h>
20
21 void print_head(char upc_number[]) {
22 printf("<?xml version=\"1.0\" standalone=\"no\"?>\n");
23 printf("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n");
24 printf(" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
25 printf("<svg width=\"100\" height=\"100\" version=\"1.1\"\n");
26 printf(" xmlns=\"http://www.w3.org/2000/svg\">\n");
27 printf(" <desc>Sunburst %s</desc>\n\n", upc_number);
28 printf(" <g id=\"sunburst\" fill = \"#000000\">\n");
29 printf(" <rect x=\"0\" y=\"0\" width=\"100\" height=\"100\" fill=\"#ffffff\" />\n");
30 }
31
32 void print_foot() {
33 printf(" </g>\n");
34 printf("</svg>\n");
35 }
36
37 static const char *torrey[11] = {
38 "01010101", "10010101", "01100101", "10100101", "01010110", "10010110",
39 "01100110", "10101010", "01011001", "10011001", "01001101"
40 // Two "surplus" codes were also defined as "01011010" and "10110010"
41 // In these codes 0 is dark and 1 is light
42 };
43
44 int main(int argc, char** argv) {
45
46 int in_length;
47 char upc_number[12];
48 char binary[100];
49 int i;
50 int posn;
51 int left, right;
52 double ax, ay, bx, by, cx, cy, dx, dy;
53
54 if (argc != 2) {
55 /* Only command line input should be the number to encode */
56 printf("Usage: sunburst {number}\n");
57 printf("Where {number} is the number to be encoded, up to 11 digits\n");
58 return 0;
59 } else {
60 in_length = strlen(argv[1]);
61 if (in_length > 11) {
62 /* Check maximum length */
63 printf("Input data too long\n");
64 return 0;
65 } else {
66 /* Add padding if needed */
67 strcpy(upc_number, "");
68 for(i = in_length; i < 11; i++) {
69 strcat(upc_number, "0");
70 }
71 strcat(upc_number, argv[1]);
72 }
73 }
74
75 /* Check input is numeric */
76 for (i = 0; i < 11; i++) {
77 if ((upc_number[i] < '0') || (upc_number[i] > '9')) {
78 printf("Invalid character(s) in input data\n");
79 return 0;
80 }
81 }
82
83 strcpy(binary, torrey[10]); // Start
84
85 for (i = 0; i < 11; i++) {
86 strcat(binary, torrey[upc_number[i] - '0']);
87 }
88
89 print_head(upc_number);
90
91 posn = 0;
92
93 do {
94 if (binary[posn] == '0') {
95 for (i = 0; binary[posn + i] == '0'; i++);
96 left = posn;
97 right = posn + i;
98
99 ax = 50.0 + (18.72 * cos(0.06545 * left - 1.5708));
100 ay = 50.0 + (18.72 * sin(0.06545 * left - 1.5708));
101 bx = 50.0 + (50.0 * cos(0.06545 * left - 1.5708));
102 by = 50.0 + (50.0 * sin(0.06545 * left - 1.5708));
103 cx = 50.0 + (50.0 * cos(0.06545 * right - 1.5708));
104 cy = 50.0 + (50.0 * sin(0.06545 * right - 1.5708));
105 dx = 50.0 + (18.72 * cos(0.06545 * right - 1.5708));
106 dy = 50.0 + (18.72 * sin(0.06545 * right - 1.5708));
107
108 printf(" <path d=\"M %.2f %.2f A 50.00 50.00 0 0 1 %.2f %.2f L %.2f %.2f A 18.72 18.72 0 0 0 %.2f %.2f Z\" />\n",
109 bx, by, cx, cy, dx, dy, ax, ay);
110
111 posn += i;
112 } else {
113 posn++;
114 }
115 } while (posn < 96);
116
117 print_foot();
118
119 return (EXIT_SUCCESS);
120 }