Merge pull request #860 from openmv/fix_fb_size

Fix fb_get_size.
This commit is contained in:
Ibrahim Abd Elkader 2020-07-20 23:54:15 +02:00 committed by GitHub
commit c52988fba2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 5 deletions

View File

@ -28,7 +28,7 @@ static char *pointer_overlay = &_fballoc_overlay;
static char *fb_alloc_min_address()
{
return (char *) (framebuffer_get_buffer() + framebuffer_get_size());
return (char *) (framebuffer_get_buffer() + framebuffer_get_frame_size());
}
__weak NORETURN void fb_alloc_fail()

View File

@ -16,6 +16,7 @@
#define CONSERVATIVE_JPEG_BUF_SIZE (OMV_JPEG_BUF_SIZE-64)
extern char _fb_base;
extern char _fballoc;
framebuffer_t *framebuffer = (framebuffer_t *) &_fb_base;
extern char _jpeg_buf;
@ -197,9 +198,34 @@ int32_t framebuffer_get_depth()
return framebuffer->bpp;
}
uint32_t framebuffer_get_size()
uint32_t framebuffer_get_frame_size()
{
return OMV_RAW_BUF_SIZE;
switch (framebuffer->bpp) {
case -1: {
// Invalid frame.
return 0;
}
case IMAGE_BPP_BINARY: {
return ((framebuffer->w + UINT32_T_MASK) >> UINT32_T_SHIFT) * framebuffer->h;
}
case IMAGE_BPP_GRAYSCALE: {
return (framebuffer->w * framebuffer->h) * sizeof(uint8_t);
}
case IMAGE_BPP_RGB565: {
return (framebuffer->w * framebuffer->h) * sizeof(uint16_t);
}
case IMAGE_BPP_BAYER: {
return framebuffer->w * framebuffer->h;
}
default: { // JPEG
return framebuffer->bpp;
}
}
}
uint32_t framebuffer_get_buffer_size()
{
return &_fballoc - (char *) framebuffer->pixels;
}
uint8_t *framebuffer_get_buffer()

View File

@ -60,7 +60,12 @@ int32_t framebuffer_get_width();
int32_t framebuffer_get_height();
int32_t framebuffer_get_depth();
uint32_t framebuffer_get_size();
// Return the size of the current frame (w * h * bpp) if the framebuffer is initialized,
// otherwise return 0 if the framebuffer is unintialized or invalid (e.g. first frame).
uint32_t framebuffer_get_frame_size();
// Return the max frame size that fits the framebuffer (i.e OMV_RAW_BUF_SIZE - sizeof(framebuffer_t))
uint32_t framebuffer_get_buffer_size();
// Return the current buffer address.
uint8_t *framebuffer_get_buffer();

View File

@ -383,7 +383,7 @@ void py_helper_update_framebuffer(image_t *img)
void py_helper_set_to_framebuffer(image_t *img)
{
PY_ASSERT_TRUE_MSG((image_size(img) <= framebuffer_get_size()),
PY_ASSERT_TRUE_MSG((image_size(img) <= framebuffer_get_buffer_size()),
"The image doesn't fit in the frame buffer!");
framebuffer_set(img->w, img->h, img->bpp);
img->data = framebuffer_get_buffer();