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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
// Copyright © 2022-2026 QRC. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
/// Macro to add a watermark image to a QR code.
///
/// # Parameters
/// * `$img` - The main QR code image as a mutable reference.
/// * `$watermark` - The watermark image as an immutable reference.
///
/// # Example
/// ```
/// use qrc::QRCode;
/// use image::{ImageBuffer, Rgba};
///
/// // Create a mock QR code and watermark image for the example
/// let mut img = ImageBuffer::from_pixel(100, 100, Rgba([0, 0, 0, 255]));
/// let watermark = ImageBuffer::from_pixel(50, 50, Rgba([255, 255, 255, 255]));
///
/// qrc::add_image_watermark!(&mut img, &watermark);
/// ```
/// Macro to create a new QR code from the given data.
///
/// # Parameters
/// * `$data` - The data to be encoded in the QR code.
///
/// # Example
/// ```
/// use qrc::{QRCode, qr_code};
/// qr_code!("Hello, world!".into());
/// ```
/// Macro to create a QR code with a specific error correction level.
///
/// # Parameters
/// * `$data` - The data to be encoded in the QR code.
/// * `$ec` - The error correction level (`EcLevel`).
///
/// # Example
/// ```
/// use qrc::{QRCode, EcLevel, qr_code_with_ec};
/// let qr = qr_code_with_ec!("Hello".into(), EcLevel::H);
/// assert_eq!(qr.ec_level, EcLevel::H);
/// ```
/// Macro to create a QR code in a specified format with a given width.
///
/// All arms return `Result<Vec<u8>, image::ImageError>` containing the encoded
/// image bytes (or an encoding error, e.g. a zero width).
///
/// # Parameters
/// * `$data` - The data to be encoded in the QR code.
/// * `$format` - The format of the QR code image (e.g., "png", "jpg", "gif").
/// * `$width` - The width of the QR code image.
///
/// # Example
/// ```
/// use qrc::{QRCode, qr_code_to};
/// let bytes = qr_code_to!("Hello, world!".into(), "png", 256).unwrap();
/// assert!(!bytes.is_empty());
/// ```
/// Sets the size of the QR code.
///
/// # Parameters
/// - `$qrcode:expr`: An instance of `QRCode`.
/// - `$size:expr`: The desired size for the QR code.
///
/// # Example
/// ```
/// use qrc::QRCode;
/// use qrc::resize;
///
/// let qrcode = QRCode::new("Hello, world!".as_bytes().to_vec());
/// let resized_qrcode = resize!(qrcode, 256);
/// ```
/// Sets the encoding format for the data in a QR code.
///
/// # Parameters
/// - `$qr_code:expr`: An instance of `QRCode`.
/// - `$format:expr`: The encoding format for the QR code data.
///
/// # Example
/// ```
/// use qrc::{QRCode, set_encoding_format};
///
/// let qr_code = QRCode::new("some data".as_bytes().to_vec());
/// let qr_with_format = set_encoding_format!(qr_code, "utf-8");
/// ```
/// Overlays an image (e.g., a logo) at the center of the QR code.
///
/// # Parameters
/// - `$qr_code:expr`: `QRCode` instance to which the image will be overlaid.
/// - `$image_path:expr`: Path to the image file to overlay.
///
/// # Example
/// ```
/// use qrc::{QRCode, overlay_image};
/// use image::{RgbaImage, ImageBuffer, Rgba};
///
/// let qr_code = QRCode::new("some data".as_bytes().to_vec());
/// let logo = ImageBuffer::from_pixel(10, 10, Rgba([255, 0, 0, 255]));
///
/// let qr_with_logo = overlay_image!(qr_code, &logo);
/// ```
/// Generates multiple QR codes in one operation.
///
/// # Parameters
/// - `$data_list:expr`: A vector of data strings for which QR codes are to be generated.
///
/// # Example
/// ```
/// use qrc::QRCode;
/// use qrc::batch_generate_qr;
/// let qr_codes = batch_generate_qr!(vec!["https://example.com".to_string(), "https://example2.com".to_string()]);
/// ```
/// Compresses data before encoding it into a QR code.
///
/// # Parameters
/// - `$data:expr`: The data to be compressed and encoded.
///
/// # Example
/// ```
/// use qrc::QRCode;
/// use qrc::compress_data_macro;
/// let compressed_data = compress_data_macro!("Some large string of data");
/// ```
/// Combines multiple QR codes into a single QR code.
///
/// # Parameters
/// - An array of `QRCode` instances to combine.
///
/// # Example
/// ```
/// use qrc::QRCode;
/// use qrc::combine_qr_codes;
///
/// let qr_code1 = QRCode::from_string("Data 1".to_string());
/// let qr_code2 = QRCode::from_string("Data 2".to_string());
/// let qr_code3 = QRCode::from_string("Data 3".to_string());
///
/// let combined_qr_code = combine_qr_codes!([qr_code1, qr_code2, qr_code3]);
/// ```
/// Generates a dynamic QR code, which can be updated after creation.
///
/// # Parameters
/// - `$initial_data:expr`: The initial data for the QR code.
///
/// # Example
/// ```
/// use qrc::QRCode;
/// use qrc::create_dynamic_qr;
/// create_dynamic_qr!("Initial Data");
/// ```
/// Generates QR codes with multi-language support.
///
/// The QR code displays different data based on the user's language preference.
/// Use the `$lang_pref; ...` form to specify a preferred language, or omit it
/// to default to `"en"`.
///
/// # Examples
///
/// ```
/// use qrc::QRCode;
/// use qrc::create_multilanguage_qr;
///
/// // Default (uses "en"):
/// let qr = create_multilanguage_qr! {
/// "en" => "Hello",
/// "es" => "Hola",
/// };
///
/// // Explicit language preference:
/// let qr = create_multilanguage_qr! {
/// "es";
/// "en" => "Hello",
/// "es" => "Hola",
/// };
/// ```