Rename fb functions for consistency.

This commit is contained in:
iabdalkader 2020-05-01 14:43:13 +02:00
parent 28296408c3
commit 9a025b60b9
4 changed files with 24 additions and 24 deletions

View File

@ -18,22 +18,22 @@ framebuffer_t *fb_framebuffer = (framebuffer_t *) &_fb_base;
extern char _jpeg_buf; extern char _jpeg_buf;
jpegbuffer_t *jpeg_fb_framebuffer = (jpegbuffer_t *) &_jpeg_buf; jpegbuffer_t *jpeg_fb_framebuffer = (jpegbuffer_t *) &_jpeg_buf;
void set_fb_streaming_disabled(bool en) void fb_set_streaming_enabled(bool enable)
{ {
MAIN_FB()->fb_streaming_disable = en; MAIN_FB()->streaming_enabled = enable;
} }
bool is_fb_streaming_disabled() bool fb_get_streaming_enabled()
{ {
return MAIN_FB()->fb_streaming_disable; return MAIN_FB()->streaming_enabled;
} }
int encode_for_ide_new_size(image_t *img) int fb_encode_for_ide_new_size(image_t *img)
{ {
return (((img->bpp * 8) + 5) / 6) + 2; return (((img->bpp * 8) + 5) / 6) + 2;
} }
void encode_for_ide(uint8_t *ptr, image_t *img) void fb_encode_for_ide(uint8_t *ptr, image_t *img)
{ {
*ptr++ = 0xFE; *ptr++ = 0xFE;
@ -92,7 +92,7 @@ void fb_update_jpeg_buffer()
{ {
static int overflow_count = 0; static int overflow_count = 0;
if ((!MAIN_FB()->fb_streaming_disable) && JPEG_FB()->enabled) { if ((!MAIN_FB()->streaming_enabled) && JPEG_FB()->enabled) {
if (MAIN_FB()->bpp > 3) { if (MAIN_FB()->bpp > 3) {
bool does_not_fit = false; bool does_not_fit = false;
// Lock FB // Lock FB
@ -111,10 +111,10 @@ void fb_update_jpeg_buffer()
} }
if (does_not_fit) { if (does_not_fit) {
image_t out = { .w=MAIN_FB()->w, .h=MAIN_FB()->h, .bpp=MAIN_FB()->bpp, .data=MAIN_FB()->pixels }; image_t out = { .w=MAIN_FB()->w, .h=MAIN_FB()->h, .bpp=MAIN_FB()->bpp, .data=MAIN_FB()->pixels };
int new_size = encode_for_ide_new_size(&out); int new_size = fb_encode_for_ide_new_size(&out);
fb_alloc_mark(); fb_alloc_mark();
uint8_t *temp = fb_alloc(new_size, FB_ALLOC_NO_HINT); uint8_t *temp = fb_alloc(new_size, FB_ALLOC_NO_HINT);
encode_for_ide(temp, &out); fb_encode_for_ide(temp, &out);
(MP_PYTHON_PRINTER)->print_strn((MP_PYTHON_PRINTER)->data, (const char *) temp, new_size); (MP_PYTHON_PRINTER)->print_strn((MP_PYTHON_PRINTER)->data, (const char *) temp, new_size);
fb_alloc_free_till_mark(); fb_alloc_free_till_mark();
} }

View File

@ -19,7 +19,7 @@ typedef struct framebuffer {
int32_t w,h; int32_t w,h;
int32_t u,v; int32_t u,v;
int32_t bpp; int32_t bpp;
int32_t fb_streaming_disable; int32_t streaming_enabled;
// NOTE: This buffer must be aligned on a 16 byte boundary // NOTE: This buffer must be aligned on a 16 byte boundary
uint8_t pixels[]; uint8_t pixels[];
} framebuffer_t; } framebuffer_t;
@ -48,12 +48,12 @@ extern jpegbuffer_t *jpeg_fb_framebuffer;
#define JPEG_FB_PIXELS() (JPEG_FB()->pixels + JPEG_FB()->size) #define JPEG_FB_PIXELS() (JPEG_FB()->pixels + JPEG_FB()->size)
// Force fb streaming to the IDE off. // Force fb streaming to the IDE off.
void set_fb_streaming_disabled(bool en); void fb_set_streaming_enabled(bool enable);
bool is_fb_streaming_disabled(); bool fb_get_streaming_enabled();
// Encode jpeg data for transmission over a text channel. // Encode jpeg data for transmission over a text channel.
int encode_for_ide_new_size(image_t *img); int fb_encode_for_ide_new_size(image_t *img);
void encode_for_ide(uint8_t *ptr, image_t *img); void fb_encode_for_ide(uint8_t *ptr, image_t *img);
// Returns the main frame buffer size, factoring in pixel formats. // Returns the main frame buffer size, factoring in pixel formats.
uint32_t fb_buffer_size(); uint32_t fb_buffer_size();

View File

@ -1374,9 +1374,9 @@ static mp_obj_t py_image_compress_for_ide(uint n_args, const mp_obj_t *args, mp_
uint8_t *buffer = fb_alloc_all(&size, FB_ALLOC_PREFER_SIZE); uint8_t *buffer = fb_alloc_all(&size, FB_ALLOC_PREFER_SIZE);
image_t out = { .w=arg_img->w, .h=arg_img->h, .bpp=size, .data=buffer }; image_t out = { .w=arg_img->w, .h=arg_img->h, .bpp=size, .data=buffer };
PY_ASSERT_FALSE_MSG(jpeg_compress(arg_img, &out, arg_q, false), "Out of Memory!"); PY_ASSERT_FALSE_MSG(jpeg_compress(arg_img, &out, arg_q, false), "Out of Memory!");
int new_size = encode_for_ide_new_size(&out); int new_size = fb_encode_for_ide_new_size(&out);
PY_ASSERT_TRUE_MSG(new_size <= image_size(arg_img), "Can't compress in place!"); PY_ASSERT_TRUE_MSG(new_size <= image_size(arg_img), "Can't compress in place!");
encode_for_ide(arg_img->data, &out); fb_encode_for_ide(arg_img->data, &out);
out.bpp = new_size; out.bpp = new_size;
arg_img->bpp = out.bpp; arg_img->bpp = out.bpp;
@ -1421,9 +1421,9 @@ static mp_obj_t py_image_compressed_for_ide(uint n_args, const mp_obj_t *args, m
uint8_t *buffer = fb_alloc_all(&size, FB_ALLOC_PREFER_SIZE); uint8_t *buffer = fb_alloc_all(&size, FB_ALLOC_PREFER_SIZE);
image_t out = { .w=arg_img->w, .h=arg_img->h, .bpp=size, .data=buffer }; image_t out = { .w=arg_img->w, .h=arg_img->h, .bpp=size, .data=buffer };
PY_ASSERT_FALSE_MSG(jpeg_compress(arg_img, &out, arg_q, false), "Out of Memory!"); PY_ASSERT_FALSE_MSG(jpeg_compress(arg_img, &out, arg_q, false), "Out of Memory!");
int new_size = encode_for_ide_new_size(&out); int new_size = fb_encode_for_ide_new_size(&out);
uint8_t *temp = xalloc(new_size); uint8_t *temp = xalloc(new_size);
encode_for_ide(temp, &out); fb_encode_for_ide(temp, &out);
out.bpp = new_size; out.bpp = new_size;
out.data = temp; out.data = temp;
@ -1439,10 +1439,10 @@ static mp_obj_t py_image_jpeg_encode_for_ide(mp_obj_t img_obj)
PY_ASSERT_TRUE_MSG(arg_img->bpp >= IMAGE_BPP_JPEG, "Image format is not supported!"); PY_ASSERT_TRUE_MSG(arg_img->bpp >= IMAGE_BPP_JPEG, "Image format is not supported!");
PY_ASSERT_TRUE_MSG(MAIN_FB()->pixels == arg_img->data, "Can't compress in place!"); PY_ASSERT_TRUE_MSG(MAIN_FB()->pixels == arg_img->data, "Can't compress in place!");
int new_size = encode_for_ide_new_size(arg_img); int new_size = fb_encode_for_ide_new_size(arg_img);
fb_alloc_mark(); fb_alloc_mark();
uint8_t *temp = fb_alloc(new_size, FB_ALLOC_NO_HINT); uint8_t *temp = fb_alloc(new_size, FB_ALLOC_NO_HINT);
encode_for_ide(temp, arg_img); fb_encode_for_ide(temp, arg_img);
MAIN_FB()->bpp = 0; MAIN_FB()->bpp = 0;
PY_ASSERT_TRUE_MSG(new_size <= fb_avail(), "The new image won't fit in the main frame buffer!"); PY_ASSERT_TRUE_MSG(new_size <= fb_avail(), "The new image won't fit in the main frame buffer!");
@ -1461,9 +1461,9 @@ static mp_obj_t py_image_jpeg_encoded_for_ide(mp_obj_t img_obj)
image_t *arg_img = py_image_cobj(img_obj); image_t *arg_img = py_image_cobj(img_obj);
PY_ASSERT_TRUE_MSG(arg_img->bpp >= IMAGE_BPP_JPEG, "Image format is not supported!"); PY_ASSERT_TRUE_MSG(arg_img->bpp >= IMAGE_BPP_JPEG, "Image format is not supported!");
int new_size = encode_for_ide_new_size(arg_img); int new_size = fb_encode_for_ide_new_size(arg_img);
uint8_t *temp = xalloc(new_size); uint8_t *temp = xalloc(new_size);
encode_for_ide(temp, arg_img); fb_encode_for_ide(temp, arg_img);
return py_image(arg_img->w, arg_img->h, new_size, temp); return py_image(arg_img->w, arg_img->h, new_size, temp);
} }

View File

@ -52,9 +52,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(py_omv_board_id_obj, py_omv_board_id);
static mp_obj_t py_omv_disable_fb(uint n_args, const mp_obj_t *args) static mp_obj_t py_omv_disable_fb(uint n_args, const mp_obj_t *args)
{ {
if (!n_args) { if (!n_args) {
return mp_obj_new_bool(is_fb_streaming_disabled()); return mp_obj_new_bool(fb_get_streaming_enabled());
} }
set_fb_streaming_disabled(mp_obj_get_int(args[0])); fb_set_streaming_enabled(mp_obj_get_int(args[0]));
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(py_omv_disable_fb_obj, 0, 1, py_omv_disable_fb); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(py_omv_disable_fb_obj, 0, 1, py_omv_disable_fb);