Merge pull request #2356 from openmv/fb_preview

imlib: Add support for sending raw preview frames.
This commit is contained in:
Ibrahim Abdelkader 2024-08-05 16:59:56 +02:00 committed by GitHub
commit 0ad4d34a42
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,6 +10,7 @@
*/
#include <stdio.h>
#include "mpprint.h"
#include "fmath.h"
#include "framebuffer.h"
#include "omv_boardconfig.h"
@ -166,8 +167,32 @@ void framebuffer_update_jpeg_buffer() {
.size = OMV_JPEG_BUFFER_SIZE_MAX,
.pixels = jpeg_framebuffer->pixels
};
// Note: lower quality saves USB bandwidth and results in a faster IDE FPS.
bool overflow = jpeg_compress(src, &dst, jpeg_framebuffer->quality, false, JPEG_SUBSAMPLING_AUTO);
bool overflow = false;
if (0) {
#if OMV_RAW_PREVIEW_ENABLE
} else if (src->is_mutable &&
image_size(src) <= OMV_JPEG_BUFFER_SIZE_MAX) {
// Down-scale the frame (if necessary) and send the raw frame.
dst.size = src->bpp;
dst.pixfmt = src->pixfmt;
if (src->w <= OMV_RAW_PREVIEW_WIDTH && src->h <= OMV_RAW_PREVIEW_HEIGHT) {
memcpy(dst.pixels, src->pixels, image_size(src));
} else {
dst.w = OMV_RAW_PREVIEW_WIDTH;
dst.h = OMV_RAW_PREVIEW_HEIGHT;
if (src->w > src->h) {
dst.h = fast_floorf(dst.h * (src->h / (float) src->w));
} else if (src->h > src->w) {
dst.w = fast_floorf(dst.w * (src->w / (float) src->h));
}
imlib_draw_image(&dst, src, 0, 0, 1.0f, 1.0f, NULL, -1, 255,
NULL, NULL, IMAGE_HINT_BILINEAR, NULL, NULL, NULL);
}
#endif
} else {
// For all other formats, send a compressed frame.
overflow = jpeg_compress(src, &dst, jpeg_framebuffer->quality, false, JPEG_SUBSAMPLING_AUTO);
}
if (overflow) {
// JPEG buffer overflowed, reduce JPEG quality for the next frame