resize the buffer

This commit is contained in:
Corwin 2024-05-24 19:15:34 +01:00
parent 51b1f909c5
commit 2d34099afc
No known key found for this signature in database

View file

@ -73,15 +73,19 @@ const PADDING: i32 = 8;
/// Returns the width / height of the QR code + padding in pixels /// Returns the width / height of the QR code + padding in pixels
fn draw_qr_code(gfx: &mut Bitmap3<'_>, qrcode_string_data: &str) -> i32 { fn draw_qr_code(gfx: &mut Bitmap3<'_>, qrcode_string_data: &str) -> i32 {
const MAX_VERSION: qrcodegen_no_heap::Version = qrcodegen_no_heap::Version::new(6); const MAX_VERSION: qrcodegen_no_heap::Version = qrcodegen_no_heap::Version::new(6);
let buffer_len = MAX_VERSION.buffer_len();
let (Ok(mut temp_buffer), Ok(mut out_buffer)) = ( let (Ok(mut temp_buffer), Ok(mut out_buffer)) = (
Vec::try_with_capacity_in(MAX_VERSION.buffer_len(), crate::ExternalAllocator), Vec::try_with_capacity_in(buffer_len, crate::ExternalAllocator),
Vec::try_with_capacity_in(MAX_VERSION.buffer_len(), crate::ExternalAllocator), Vec::try_with_capacity_in(buffer_len, crate::ExternalAllocator),
) else { ) else {
crate::println!("Failed to allocate memory to generate QR code"); crate::println!("Failed to allocate memory to generate QR code");
return PADDING; return PADDING;
}; };
temp_buffer.resize(buffer_len, 0);
out_buffer.resize(buffer_len, 0);
let qr_code = match qrcodegen_no_heap::QrCode::encode_text( let qr_code = match qrcodegen_no_heap::QrCode::encode_text(
qrcode_string_data, qrcode_string_data,
&mut temp_buffer, &mut temp_buffer,