Skip to content

Commit

Permalink
camera: improve handling front-facing camera images
Browse files Browse the repository at this point in the history
Reflect the image being written to the screen, so it behaves like a
mirror or a selfie-camera, with the image reversed.  Note the underlying
image as passed to the callback is not reversed (vital for QR scanning).
  • Loading branch information
JamieDriver committed Oct 3, 2024
1 parent b721efb commit 60b78ca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
20 changes: 13 additions & 7 deletions main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,20 @@ menu "Blockstream Jade"
default -1
endmenu

config HAS_CAMERA
bool "Enable Camera Functions"
help
Enables camera functionality
default y if BOARD_TYPE_JADE_V2 || BOARD_TYPE_JADE_V1_1 || BOARD_TYPE_JADE || (ETH_USE_OPENETH && HTTPD_WS_SUPPORT) || BOARD_TYPE_M5_CORES3 || BOARD_TYPE_TTGO_TDISPLAYS3PROCAMERA

config JADE_USE_USB_JTAG_SERIAL
bool "Use USB JTAG serial instead of CDC tinyusb"
depends on IDF_TARGET_ESP32S3
help
Enables USB JTAG serial rather than CDC tinyusb, implies no tinyusb/host storage/etc
default n

menu "Camera Rotation"
config HAS_CAMERA
bool "Enable Camera Functions"
help
Enables camera functionality
default y if BOARD_TYPE_JADE_V2 || BOARD_TYPE_JADE_V1_1 || BOARD_TYPE_JADE || (ETH_USE_OPENETH && HTTPD_WS_SUPPORT) || BOARD_TYPE_M5_CORES3 || BOARD_TYPE_TTGO_TDISPLAYS3PROCAMERA

menu "Camera Orientation"
visible if HAS_CAMERA && BOARD_TYPE_CUSTOM

config CAMERA_ROTATE_90
Expand All @@ -271,7 +271,13 @@ menu "Blockstream Jade"
default y if BOARD_TYPE_TTGO_TDISPLAYS3PROCAMERA
default n

config CAMERA_FRONT_FACING
bool "Front-facing camera"
default y if BOARD_TYPE_M5_CORES3
default n

endmenu

menu "Camera Pin Mapping"
visible if HAS_CAMERA && (BOARD_TYPE_CUSTOM || BOARD_TYPE_M5_CORES3)

Expand Down
11 changes: 11 additions & 0 deletions main/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,18 @@ static inline void copy_pixel(uint8_t dest[DISPLAY_IMAGE_HEIGHT][DISPLAY_IMAGE_W
JADE_ASSERT(srcx < CAMERA_IMAGE_WIDTH);
JADE_ASSERT(srcy < CAMERA_IMAGE_HEIGHT);
#endif

// For a front-facing camera, write the image from right-to-left, so it 'moves' the way
// the user would expect, ie. behaves like a mirror. In the final image any writing would be backwards...
// NOTE: this is only done here for the image going to the screen - the source data remains as
// presented by the camera, so in the source frame-buffer (ie. as passed to the processing callback)
// any writing would be 'correct'. This is important for text *and QR codes* (and is why we can't use
// sensor->set_hmirror(i) which would reverse what the hw places in the framebuffer).
#ifdef CONFIG_CAMERA_FRONT_FACING
dest[desty][(DISPLAY_IMAGE_WIDTH - 1) - destx] = src[srcy][srcx];
#else
dest[desty][destx] = src[srcy][srcx];
#endif
}

// Loops to copy the camera image
Expand Down

0 comments on commit 60b78ca

Please sign in to comment.