From e19574ce7766cd754b42808c36cc88fd0f510033 Mon Sep 17 00:00:00 2001 From: pommicket Date: Thu, 20 Feb 2025 10:02:58 -0500 Subject: optimization for MJPEG->JPEG saving --- camera.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/camera.c b/camera.c index f2c43f5..a8872b4 100644 --- a/camera.c +++ b/camera.c @@ -336,6 +336,16 @@ static uint8_t *curr_frame_rgb24(Camera *camera) { } bool camera_save_jpg(Camera *camera, const char *name, int quality) { + if (camera_pixel_format(camera) == V4L2_PIX_FMT_MJPEG && camera_curr_frame(camera)) { + // frame is already in jpeg format + FILE *fp = fopen(name, "wb"); + if (!fp) { + perror("fopen"); + return false; + } + fwrite(camera_curr_frame(camera), 1, camera->frame_bytes_set, fp); + fclose(fp); + } uint8_t *frame = curr_frame_rgb24(camera); if (frame) { uint32_t frame_width = camera_frame_width(camera); -- cgit v1.2.3