Merge pull request #2855 from openmv/fix_raw_stream_size
Some checks failed
🔥 Firmware Build / build-firmware (0, ARDUINO_GIGA) (push) Waiting to run
🔥 Firmware Build / build-firmware (0, ARDUINO_NANO_33_BLE_SENSE) (push) Waiting to run
🔥 Firmware Build / build-firmware (0, ARDUINO_NANO_RP2040_CONNECT) (push) Waiting to run
🔥 Firmware Build / build-firmware (0, ARDUINO_NICLA_VISION) (push) Waiting to run
🔥 Firmware Build / build-firmware (0, ARDUINO_PORTENTA_H7) (push) Waiting to run
🔥 Firmware Build / build-firmware (0, DOCKER) (push) Waiting to run
🔥 Firmware Build / build-firmware (0, OPENMV2) (push) Waiting to run
🔥 Firmware Build / build-firmware (0, OPENMV3) (push) Waiting to run
🔥 Firmware Build / build-firmware (0, OPENMV4) (push) Waiting to run
🔥 Firmware Build / build-firmware (0, OPENMV4P) (push) Waiting to run
🔥 Firmware Build / build-firmware (0, OPENMVPT) (push) Waiting to run
🔥 Firmware Build / build-firmware (0, OPENMV_AE3) (push) Waiting to run
🔥 Firmware Build / build-firmware (0, OPENMV_N6) (push) Waiting to run
🔥 Firmware Build / build-firmware (0, OPENMV_RT1060) (push) Waiting to run
🔥 Firmware Build / build-firmware (1, OPENMV_N6) (push) Waiting to run
🔥 Firmware Build / code-size-report (push) Blocked by required conditions
🔥 Firmware Build / stable-release (push) Blocked by required conditions
🔥 Firmware Build / development-release (push) Blocked by required conditions
🔎 Check Code Formatting / formatting-check (push) Has been cancelled

lib/imlib: Fix raw stream buffer size check.
This commit is contained in:
Ibrahim Abdelkader 2025-09-21 21:26:28 +03:00 committed by GitHub
commit 87b01fac51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -45,11 +45,11 @@ void framebuffer_init0() {
// Reuse the last enabled flag after resetting the state.
bool enabled = framebuffer_get(FB_STREAM_ID)->enabled;
// Initialize the main framebuffer.
// Initialize the main framebuffer.
framebuffer_init(framebuffer_get(FB_MAINFB_ID), &_fb_memory_start,
&_fb_memory_end - &_fb_memory_start, false, true);
// Initialize the streaming buffer.
// Initialize the streaming buffer.
framebuffer_init(framebuffer_get(FB_STREAM_ID), &_sb_memory_start,
&_sb_memory_end - &_sb_memory_start, false, enabled);
@ -85,10 +85,10 @@ void framebuffer_to_image(framebuffer_t *fb, image_t *img) {
img->h = fb->h;
img->size = fb->size;
img->pixfmt = fb->pixfmt;
// For streaming buffers (no queues), use raw_base directly
if (fb->used_queue == NULL) {
img->pixels = (uint8_t *)fb->raw_base;
img->pixels = (uint8_t *) fb->raw_base;
} else {
vbuffer_t *buffer = framebuffer_acquire(fb, FB_FLAG_USED | FB_FLAG_PEEK);
img->pixels = (buffer == NULL) ? NULL : buffer->data;
@ -144,7 +144,7 @@ void framebuffer_flush(framebuffer_t *fb) {
queue_flush(fb->used_queue);
}
for (size_t i=0; i<fb->buf_count; i++) {
for (size_t i = 0; i < fb->buf_count; i++) {
vbuffer_t *buffer = framebuffer_pool_get(fb, i);
// Reset the buffer's state.
@ -275,8 +275,8 @@ void framebuffer_update_preview(image_t *src) {
}
// Reserve space for header at the beginning
framebuffer_header_t *header = (framebuffer_header_t *)fb->raw_base;
uint8_t *frame_data = (uint8_t *)fb->raw_base + sizeof(framebuffer_header_t);
framebuffer_header_t *header = (framebuffer_header_t *) fb->raw_base;
uint8_t *frame_data = (uint8_t *) fb->raw_base + sizeof(framebuffer_header_t);
size_t available_size = fb->raw_size - sizeof(framebuffer_header_t);
if (src->is_compressed) {
@ -305,7 +305,7 @@ void framebuffer_update_preview(image_t *src) {
// Down-scale the frame (if necessary) and send the raw frame.
dst.size = src->bpp;
dst.pixfmt = src->pixfmt;
if (image_size(&dst) <= available_size) {
if (src->w <= fb->raw_w && src->h <= fb->raw_h && image_size(&dst) <= available_size) {
memcpy(dst.pixels, src->pixels, image_size(src));
} else {
float scale = IM_MIN((fb->raw_w / (float) src->w),
@ -359,7 +359,7 @@ exit_cleanup:
header->height = fb->h;
header->pixfmt = fb->pixfmt;
header->size = fb->is_compressed ? fb->size : fb->bpp;
// Unlock the streaming buffer.
mutex_unlock(&fb->lock, MUTEX_TID_OMV);
}