fastqr 1.0.15 → 1.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,142 @@
1
+ /*
2
+ * FastQR - Fast QR Code Generator Library
3
+ * Copyright (C) 2025 FastQR Project
4
+ *
5
+ * This library is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * This library is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ * Lesser General Public License for more details.
14
+ */
15
+
16
+ #ifndef FASTQR_H
17
+ #define FASTQR_H
18
+
19
+ #include <string>
20
+ #include <cstdint>
21
+
22
+ namespace fastqr {
23
+
24
+ /**
25
+ * QR Code error correction level
26
+ */
27
+ enum class ErrorCorrectionLevel {
28
+ LOW, // Level L - ~7% correction
29
+ MEDIUM, // Level M - ~15% correction
30
+ QUARTILE, // Level Q - ~25% correction
31
+ HIGH // Level H - ~30% correction
32
+ };
33
+
34
+ /**
35
+ * Options for QR code generation
36
+ */
37
+ struct QROptions {
38
+ // Output image size (QR codes are square)
39
+ int size = 300;
40
+
41
+ // Optimize size - round up to nearest integer multiple for best performance
42
+ bool optimize_size = false;
43
+
44
+ // QR code colors (RGB)
45
+ struct Color {
46
+ uint8_t r = 0;
47
+ uint8_t g = 0;
48
+ uint8_t b = 0;
49
+ };
50
+
51
+ Color foreground = {0, 0, 0}; // QR code color (default: black)
52
+ Color background = {255, 255, 255}; // Background color (default: white)
53
+
54
+ // Error correction level
55
+ ErrorCorrectionLevel ec_level = ErrorCorrectionLevel::MEDIUM;
56
+
57
+ // Logo options
58
+ std::string logo_path = ""; // Path to logo image
59
+ int logo_size_percent = 20; // Logo size as percentage of QR code (default: 20%)
60
+
61
+ // Output format
62
+ std::string format = "png"; // png, jpg, webp, etc.
63
+ int quality = 95; // For lossy formats (1-100)
64
+ };
65
+
66
+ /**
67
+ * Generate QR code and save to file
68
+ *
69
+ * @param data The data to encode (supports UTF-8)
70
+ * @param output_path Path to save the generated QR code image
71
+ * @param options QR code generation options
72
+ * @return true if successful, false otherwise
73
+ */
74
+ bool generate(const std::string& data, const std::string& output_path, const QROptions& options = QROptions());
75
+
76
+ /**
77
+ * Generate QR code and return image data as buffer
78
+ *
79
+ * @param data The data to encode (supports UTF-8)
80
+ * @param buffer Output buffer for image data
81
+ * @param buffer_size Size of the output buffer
82
+ * @param options QR code generation options
83
+ * @return Size of image data written to buffer, or -1 on error
84
+ */
85
+ int generate_to_buffer(const std::string& data, void* buffer, size_t buffer_size, const QROptions& options = QROptions());
86
+
87
+ /**
88
+ * Get library version
89
+ *
90
+ * @return Version string (e.g., "1.0.0")
91
+ */
92
+ const char* version();
93
+
94
+ } // namespace fastqr
95
+
96
+ // C API for FFI bindings (Ruby, Node.js, Python, etc.)
97
+ #ifdef __cplusplus
98
+ extern "C" {
99
+ #endif
100
+
101
+ /**
102
+ * C struct for QR options (FFI-friendly)
103
+ */
104
+ typedef struct {
105
+ int size;
106
+ int optimize_size; // boolean: 0 or 1
107
+ unsigned char foreground_r;
108
+ unsigned char foreground_g;
109
+ unsigned char foreground_b;
110
+ unsigned char background_r;
111
+ unsigned char background_g;
112
+ unsigned char background_b;
113
+ int ec_level; // 0=LOW, 1=MEDIUM, 2=QUARTILE, 3=HIGH
114
+ const char* logo_path;
115
+ int logo_size_percent;
116
+ const char* format;
117
+ int quality;
118
+ } QROptions;
119
+
120
+ /**
121
+ * Generate QR code (C API)
122
+ *
123
+ * @param data Data to encode (UTF-8 string)
124
+ * @param output_path Path to save the QR code image
125
+ * @param options Pointer to QROptions struct (can be NULL for defaults)
126
+ * @return 1 if successful, 0 on error
127
+ */
128
+ int fastqr_generate(const char* data, const char* output_path, const QROptions* options);
129
+
130
+ /**
131
+ * Get library version (C API)
132
+ *
133
+ * @return Version string (e.g., "1.0.7")
134
+ */
135
+ const char* fastqr_version(void);
136
+
137
+ #ifdef __cplusplus
138
+ }
139
+ #endif
140
+
141
+ #endif // FASTQR_H
142
+