Skip to content

Commit

Permalink
camera: Revert recent camera change following beta/ux testing
Browse files Browse the repository at this point in the history
Revert displaying the centre of the camera image rather than scaling

This reverts commit 78f2f5c.
  • Loading branch information
JamieDriver committed Oct 19, 2023
1 parent 30df5f0 commit 61320dd
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions main/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
// as we don't want the unit to shut down because of apparent inactivity.
#define CAMERA_MIN_TIMEOUT_SECS 300

// The image from the camera framebuffer is centered and cropped to fit the display image
// The image from the camera framebuffer is scaled and cropped to fit the display image
// (Based on Jade screen dimensions and the fact that the image is half the screen.)
#define DISPLAY_IMAGE_WIDTH 120
#define DISPLAY_IMAGE_HEIGHT 135
#define DISPLAY_IMAGE_SCALE_FACTOR 2

void await_qr_help_activity(const char* url);

Expand Down Expand Up @@ -213,7 +214,7 @@ static void jade_camera_task(void* data)
gui_update_text(label_node, camera_config->text_label);

// Image from camera to display on screen.
// centered rotated and cropped - still a 20k image buffer.
// 50% scale down and rotated - still a 20k image buffer.
// Keep image in spiram but make sure to zero it after use in case it
// captures potentially sensitive data eg. a valid mnemonic qrcode.
image_buffer = JADE_MALLOC_PREFER_SPIRAM(image_size);
Expand All @@ -231,10 +232,6 @@ static void jade_camera_task(void* data)
gui_activity_register_event(act, GUI_BUTTON_EVENT, ESP_EVENT_ANY_ID, sync_wait_event_handler, event_data);
}

// Offsets for centering the image on screen
const size_t offsetX = (CAMERA_IMAGE_WIDTH - DISPLAY_IMAGE_WIDTH) / 2;
const size_t offsetY = (CAMERA_IMAGE_HEIGHT - DISPLAY_IMAGE_HEIGHT) / 2;

// Loop periodically refreshes screen image from camera, and waits for button event
bool done = false;
while (!done) {
Expand All @@ -251,20 +248,22 @@ static void jade_camera_task(void* data)
// If we have a gui, update the image on screen and check for button events
if (has_gui) {
// Copy from camera output to screen image
// (Ensure source image large enough to be scaled down to display image size)
const uint8_t scale = DISPLAY_IMAGE_SCALE_FACTOR;
JADE_ASSERT(fb->len >= scale * scale * image_size);
uint8_t(*image_matrix)[DISPLAY_IMAGE_WIDTH] = image_buffer;
uint8_t(*fb_matrix)[CAMERA_IMAGE_WIDTH] = (uint8_t(*)[CAMERA_IMAGE_WIDTH])fb->buf;
for (size_t imgy = 0; imgy < DISPLAY_IMAGE_HEIGHT; ++imgy) {
for (size_t imgx = 0; imgx < DISPLAY_IMAGE_WIDTH; ++imgx) {
#if defined(CONFIG_CAMERA_ROTATE_90)
image_matrix[imgy][imgx] = fb_matrix[CAMERA_IMAGE_HEIGHT - 1 - (imgx + offsetX)][imgy + offsetY];
image_matrix[imgy][imgx] = fb_matrix[(CAMERA_IMAGE_HEIGHT - 1) - (imgx * scale)][imgy * scale];
#elif defined(CONFIG_CAMERA_ROTATE_180)
image_matrix[imgy][imgx] = fb_matrix[CAMERA_IMAGE_WIDTH - 1 - (imgx + offsetX)]
[CAMERA_IMAGE_HEIGHT - 1 - (imgy + offsetY)];
image_matrix[imgy][imgx] = fb_matrix[(CAMERA_IMAGE_WIDTH - 1) - (imgy * scale)]
[(CAMERA_IMAGE_HEIGHT - 1) - (imgx * scale)];
#elif defined(CONFIG_CAMERA_ROTATE_270)
image_matrix[imgy][imgx] = fb_matrix[imgx + offsetX][CAMERA_IMAGE_WIDTH - 1 - (imgy + offsetY)];
image_matrix[imgy][imgx] = fb_matrix[imgx * scale][(CAMERA_IMAGE_WIDTH - 1) - (imgy * scale)];
#else
image_matrix[imgy][imgx] = fb_matrix[CAMERA_IMAGE_HEIGHT - 1 - (imgy + offsetY)]
[CAMERA_IMAGE_WIDTH - 1 - (imgx + offsetX)];
image_matrix[imgy][imgx] = fb_matrix[imgy * scale][imgx * scale];
#endif
}
}
Expand Down

0 comments on commit 61320dd

Please sign in to comment.