Skip to content

Commit dbae5f9

Browse files
author
Jamie C. Driver
committed
consistency: prefer min function to MIN macro
Changes types of scan box dimensions, but uint16_t is more than adequate
1 parent 9cc7f23 commit dbae5f9

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

main/camera.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ static void copy_camera_image_180(
176176

177177
void await_qr_help_activity(const char* url);
178178

179-
size_t camera_displayed_image_width(void) { return UI2CAM(DISPLAY_IMAGE_WIDTH); }
179+
uint16_t camera_displayed_image_width(void) { return UI2CAM(DISPLAY_IMAGE_WIDTH); }
180180

181-
size_t camera_displayed_image_height(void) { return UI2CAM(DISPLAY_IMAGE_HEIGHT); }
181+
uint16_t camera_displayed_image_height(void) { return UI2CAM(DISPLAY_IMAGE_HEIGHT); }
182182

183183
gui_activity_t* make_camera_activity(gui_view_node_t** image_node, gui_view_node_t** label_node, bool show_click_btn,
184184
qr_frame_guides_t qr_frame_guides, progress_bar_t* progress_bar, bool show_help_btn);

main/camera.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#endif
2020

2121
// How much image (central area) is displayed on screen
22-
size_t camera_displayed_image_width(void);
23-
size_t camera_displayed_image_height(void);
22+
uint16_t camera_displayed_image_width(void);
23+
uint16_t camera_displayed_image_height(void);
2424

2525
// Function to process images from the camera.
2626
// Should return false if processing incomplete (and so should be called again with the next frame)

main/qrscan.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
#include "qrscan.h"
99
#include "sensitive.h"
1010
#include "utils/malloc_ext.h"
11+
#include "utils/util.h"
1112

1213
#define SCAN_EXTRA_MARGIN 20
13-
#define MIN(a, b) (a < b ? a : b)
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.
@@ -132,10 +132,10 @@ bool scan_qr(const size_t width, const size_t height, const uint8_t* data, const
132132
JADE_ASSERT(qr_data->ds);
133133

134134
// Also correctly size the internal image buffer since we know the size of the camera images/display.
135-
const size_t ideal_scan_box_size
136-
= MIN(camera_displayed_image_width(), camera_displayed_image_height()) + SCAN_EXTRA_MARGIN;
137-
const size_t scan_width = MIN(ideal_scan_box_size, CAMERA_IMAGE_WIDTH);
138-
const size_t scan_height = MIN(ideal_scan_box_size, CAMERA_IMAGE_HEIGHT);
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);
139139
const int qret = quirc_resize(qr_data->q, scan_width, scan_height);
140140
JADE_ASSERT(qret == 0);
141141
qr_data->len = 0;
@@ -176,10 +176,10 @@ bool jade_camera_scan_qr(
176176

177177
// Also correctly size the internal image buffer since we know the size of the camera images/display.
178178
// This image buffer is then reused for every camera image frame processed.
179-
const size_t ideal_scan_box_size
180-
= MIN(camera_displayed_image_width(), camera_displayed_image_height()) + SCAN_EXTRA_MARGIN;
181-
const size_t scan_width = MIN(ideal_scan_box_size, CAMERA_IMAGE_WIDTH);
182-
const size_t scan_height = MIN(ideal_scan_box_size, CAMERA_IMAGE_HEIGHT);
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);
183183
const int qret = quirc_resize(qr_data->q, scan_width, scan_height);
184184
JADE_ASSERT(qret == 0);
185185
qr_data->len = 0;

0 commit comments

Comments
 (0)