Skip to content

Commit 719fa40

Browse files
Daniel Newtonjgriffiths
authored andcommitted
change QR scan box to use the largest centered square of the camera image (minus a small margin)
1 parent 5e5df8c commit 719fa40

File tree

3 files changed

+11
-25
lines changed

3 files changed

+11
-25
lines changed

main/camera.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,6 @@ static void copy_camera_image_180(
174174

175175
void await_qr_help_activity(const char* url);
176176

177-
uint16_t camera_displayed_image_width(void) { return UI2CAM(DISPLAY_IMAGE_WIDTH); }
178-
179-
uint16_t camera_displayed_image_height(void) { return UI2CAM(DISPLAY_IMAGE_HEIGHT); }
180-
181177
gui_activity_t* make_camera_activity(gui_view_node_t** image_node, gui_view_node_t** label_node, bool show_click_btn,
182178
qr_frame_guides_t qr_frame_guides, progress_bar_t* progress_bar, bool show_help_btn);
183179

main/camera.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
#define CAMERA_IMAGE_WIDTH 320
1414
#define CAMERA_IMAGE_HEIGHT 240
1515

16-
// How much image (central area) is displayed on screen
17-
uint16_t camera_displayed_image_width(void);
18-
uint16_t camera_displayed_image_height(void);
19-
2016
// Function to process images from the camera.
2117
// Should return false if processing incomplete (and so should be called again with the next frame)
2218
// Should return true when processing complete (and the image capture loop/task should exit)

main/qrscan.c

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "utils/malloc_ext.h"
1111
#include "utils/util.h"
1212

13-
#define SCAN_EXTRA_MARGIN 20
13+
#define SCAN_MARGIN 20
1414

1515
// Inspect qrcodes and try to extract payload - whether any were seen and any
1616
// string data extracted are stored in the qr_data struct passed.
@@ -131,17 +131,14 @@ bool scan_qr(const size_t width, const size_t height, const uint8_t* data, const
131131
qr_data->ds = JADE_MALLOC_DRAM(sizeof(struct datastream));
132132
JADE_ASSERT(qr_data->ds);
133133

134-
// Also correctly size the internal image buffer since we know the size of the camera images/display.
135-
const uint16_t ideal_scan_box_size
136-
= min_u16(camera_displayed_image_width(), camera_displayed_image_height()) + SCAN_EXTRA_MARGIN;
137-
const uint16_t scan_width = min_u16(ideal_scan_box_size, CAMERA_IMAGE_WIDTH);
138-
const uint16_t scan_height = min_u16(ideal_scan_box_size, CAMERA_IMAGE_HEIGHT);
139-
const int qret = quirc_resize(qr_data->q, scan_width, scan_height);
134+
// Also correctly size the internal image buffer since we know the size of the camera images.
135+
const uint16_t scan_width = min_u16(CAMERA_IMAGE_WIDTH, CAMERA_IMAGE_HEIGHT) - SCAN_MARGIN;
136+
const int qret = quirc_resize(qr_data->q, scan_width, scan_width);
140137
JADE_ASSERT(qret == 0);
141138
qr_data->len = 0;
142139

143-
JADE_LOGI("SCAN WIDTH: %u", scan_width);
144-
JADE_LOGI("SCAN HEIGHT: %u", scan_height);
140+
JADE_LOGE("SCAN WIDTH: %u", scan_width);
141+
JADE_LOGE("SCAN HEIGHT: %u", scan_width);
145142

146143
const bool ret = qr_recognize(width, height, data, len, qr_data);
147144

@@ -174,18 +171,15 @@ bool jade_camera_scan_qr(
174171
qr_data->ds = JADE_MALLOC_DRAM(sizeof(struct datastream));
175172
JADE_ASSERT(qr_data->ds);
176173

177-
// Also correctly size the internal image buffer since we know the size of the camera images/display.
174+
// Also correctly size the internal image buffer since we know the size of the camera images.
178175
// This image buffer is then reused for every camera image frame processed.
179-
const uint16_t ideal_scan_box_size
180-
= min_u16(camera_displayed_image_width(), camera_displayed_image_height()) + SCAN_EXTRA_MARGIN;
181-
const uint16_t scan_width = min_u16(ideal_scan_box_size, CAMERA_IMAGE_WIDTH);
182-
const uint16_t scan_height = min_u16(ideal_scan_box_size, CAMERA_IMAGE_HEIGHT);
183-
const int qret = quirc_resize(qr_data->q, scan_width, scan_height);
176+
const uint16_t scan_width = min_u16(CAMERA_IMAGE_WIDTH, CAMERA_IMAGE_HEIGHT) - SCAN_MARGIN;
177+
const int qret = quirc_resize(qr_data->q, scan_width, scan_width);
184178
JADE_ASSERT(qret == 0);
185179
qr_data->len = 0;
186180

187-
JADE_LOGI("SCAN WIDTH: %u", scan_width);
188-
JADE_LOGI("SCAN HEIGHT: %u", scan_height);
181+
JADE_LOGE("SCAN WIDTH: %u", scan_width);
182+
JADE_LOGE("SCAN HEIGHT: %u", scan_width);
189183

190184
// Run the camera task trying to interpet frames as qr-codes
191185
const bool show_camera_ui = true;

0 commit comments

Comments
 (0)