mirror of
https://github.com/openmv/openmv.git
synced 2025-09-26 23:09:13 +08:00
lib/imlib: Fix raw stream buffer size check.
Check frame dimensions as well as total image size top scale the image if needed. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This commit is contained in:
parent
7a7788a03a
commit
552f4ada8e
@ -88,7 +88,7 @@ void framebuffer_to_image(framebuffer_t *fb, image_t *img) {
|
|||||||
|
|
||||||
// For streaming buffers (no queues), use raw_base directly
|
// For streaming buffers (no queues), use raw_base directly
|
||||||
if (fb->used_queue == NULL) {
|
if (fb->used_queue == NULL) {
|
||||||
img->pixels = (uint8_t *)fb->raw_base;
|
img->pixels = (uint8_t *) fb->raw_base;
|
||||||
} else {
|
} else {
|
||||||
vbuffer_t *buffer = framebuffer_acquire(fb, FB_FLAG_USED | FB_FLAG_PEEK);
|
vbuffer_t *buffer = framebuffer_acquire(fb, FB_FLAG_USED | FB_FLAG_PEEK);
|
||||||
img->pixels = (buffer == NULL) ? NULL : buffer->data;
|
img->pixels = (buffer == NULL) ? NULL : buffer->data;
|
||||||
@ -144,7 +144,7 @@ void framebuffer_flush(framebuffer_t *fb) {
|
|||||||
queue_flush(fb->used_queue);
|
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);
|
vbuffer_t *buffer = framebuffer_pool_get(fb, i);
|
||||||
|
|
||||||
// Reset the buffer's state.
|
// Reset the buffer's state.
|
||||||
@ -275,8 +275,8 @@ void framebuffer_update_preview(image_t *src) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reserve space for header at the beginning
|
// Reserve space for header at the beginning
|
||||||
framebuffer_header_t *header = (framebuffer_header_t *)fb->raw_base;
|
framebuffer_header_t *header = (framebuffer_header_t *) fb->raw_base;
|
||||||
uint8_t *frame_data = (uint8_t *)fb->raw_base + sizeof(framebuffer_header_t);
|
uint8_t *frame_data = (uint8_t *) fb->raw_base + sizeof(framebuffer_header_t);
|
||||||
size_t available_size = fb->raw_size - sizeof(framebuffer_header_t);
|
size_t available_size = fb->raw_size - sizeof(framebuffer_header_t);
|
||||||
|
|
||||||
if (src->is_compressed) {
|
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.
|
// Down-scale the frame (if necessary) and send the raw frame.
|
||||||
dst.size = src->bpp;
|
dst.size = src->bpp;
|
||||||
dst.pixfmt = src->pixfmt;
|
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));
|
memcpy(dst.pixels, src->pixels, image_size(src));
|
||||||
} else {
|
} else {
|
||||||
float scale = IM_MIN((fb->raw_w / (float) src->w),
|
float scale = IM_MIN((fb->raw_w / (float) src->w),
|
||||||
|
Loading…
Reference in New Issue
Block a user