diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h index 24139dfdd40d8b267e1b42faae6609b5c9f5d8c8..d9055f13c1f6247c256ad16e4b12c286ccbec356 100644 --- a/epicardium/epicardium.h +++ b/epicardium/epicardium.h @@ -1664,12 +1664,13 @@ API(API_DISP_PIXEL, int epic_disp_pixel( /** * Blit an image buffer to display - * + * * :param x: x position * :param y: y position * :param w: image width * :param h: image height * :param img: image data (rgb565) + * :param alpah: 8 bit alpha channel. Currently unused. */ API(API_DISP_BLIT, int epic_disp_blit( int16_t x, @@ -1678,7 +1679,6 @@ API(API_DISP_BLIT, int epic_disp_blit( int16_t h, size_t size, uint16_t *img, - uint16_t bg, uint8_t *alpha )); diff --git a/epicardium/modules/display.c b/epicardium/modules/display.c index b854af9f4c5539af39f8db665e1cb0d492fe87c6..21be30a3b4e911201376776fc92f2204dee2ddaa 100644 --- a/epicardium/modules/display.c +++ b/epicardium/modules/display.c @@ -87,10 +87,6 @@ int epic_disp_pixel(int16_t x, int16_t y, uint16_t color) } } -#define BGR_MASK 0b00000111111000001111100000011111 -#define TO_BGR(RGB) (((RGB) | ((RGB) << 16)) & BGR_MASK) -#define TO_RGB(BGR) ((uint16_t)((BGR) | ((BGR) >> 16))) - int epic_disp_blit( int16_t pos_x, int16_t pos_y, @@ -98,9 +94,9 @@ int epic_disp_blit( int16_t height, size_t size, uint16_t *img, - uint16_t bg, uint8_t *alpha ) { + /* TODO: alpha is not supported yet */ int cl = check_lock(); if (cl < 0) { return cl; @@ -117,8 +113,8 @@ int epic_disp_blit( count_y -= (pos_y + height) - 80; } - if (alpha == NULL && offset_x == 0 && offset_y == 0 && - count_x == width && count_y == height) { + if (offset_x == 0 && offset_y == 0 && count_x == width && + count_y == height) { /* Simply copy full image, no cropping or alpha blending */ gfx_copy_region( &display_screen, @@ -130,7 +126,7 @@ int epic_disp_blit( size, img ); - } else if (alpha == NULL) { + } else { /* Copy cropped image line by line */ for (int16_t curr_y = offset_y; curr_y < offset_y + count_y; @@ -148,38 +144,6 @@ int epic_disp_blit( curr_img ); } - } else { - /* Draw alpha blended cropped image pixel by pixel */ - uint32_t bg_bgr = TO_BGR(bg); - for (int16_t curr_y = offset_y; - curr_y < offset_y + count_y; - curr_y++) { - for (int16_t curr_x = offset_x; - curr_x < offset_x + count_x; - curr_x++) { - uint16_t fg = - img[curr_y * width + curr_x]; - - uint32_t fg_bgr = TO_BGR(fg); - uint8_t alpha_bgr = - (alpha[curr_y * width + curr_x] + - 4) >> - 3; - uint32_t color_bgr = - ((((fg_bgr - bg_bgr) * - alpha_bgr) >> - 5) + - bg_bgr) & - BGR_MASK; - uint_fast16_t color = TO_RGB(color_bgr); - gfx_setpixel( - &display_screen, - pos_x + curr_x, - pos_y + curr_y, - color - ); - } - } } return 0; diff --git a/pycardium/modules/py/display.py b/pycardium/modules/py/display.py index 877183dade8f8e87a91f415b6457c6c85b6a5e9a..d6bc0dc8a57e628772936528190194d4a17d9f4a 100644 --- a/pycardium/modules/py/display.py +++ b/pycardium/modules/py/display.py @@ -120,7 +120,7 @@ class Display: sys_display.pixel(x, y, col) return self - def blit(self, x, y, w, h, img, bg=None, alpha=None): + def blit(self, x, y, w, h, img, alpha=None): """ Blit an image to the display @@ -129,14 +129,20 @@ class Display: :param w: image width :param h: image height :param img: a byte buffer with pixel data (rgb565) - :param bg: background color :param alpha: alpha mask for `img` + + .. note:: + The alpha channel is not implemented yet. + """ + # TODO: alpha is not yet supported by epicardium + assert alpha == None + if alpha is None: sys_display.blit(x, y, w, h, img) else: - sys_display.blit(x, y, w, h, img, bg, alpha) + sys_display.blit(x, y, w, h, img, alpha) return self diff --git a/pycardium/modules/sys_display.c b/pycardium/modules/sys_display.c index 7e0dd682ac82bae37daea9100b30da8efdcf28ea..a4713c0a18065d662991b9fbf6570967958a8576 100644 --- a/pycardium/modules/sys_display.c +++ b/pycardium/modules/sys_display.c @@ -100,10 +100,10 @@ static mp_obj_t mp_display_blit(size_t n_args, const mp_obj_t *args) /* Required arguments: posx, posy (on display), width, height (of image), buffer (rgb data of image) */ - int16_t pos_x = mp_obj_get_int(args[0]); - int16_t pos_y = mp_obj_get_int(args[1]); - int16_t width = mp_obj_get_int(args[2]); - int16_t height = mp_obj_get_int(args[3]); + int pos_x = mp_obj_get_int(args[0]); + int pos_y = mp_obj_get_int(args[1]); + int width = mp_obj_get_int(args[2]); + int height = mp_obj_get_int(args[3]); mp_buffer_info_t img; int res = 0; @@ -112,21 +112,20 @@ static mp_obj_t mp_display_blit(size_t n_args, const mp_obj_t *args) if (!mp_get_buffer(args[4], &img, MP_BUFFER_READ)) { mp_raise_TypeError("'img' does not support buffer protocol."); } - if (img.len < width * height * 2) { + if ((int)img.len < width * height * 2) { mp_raise_ValueError("'img' is too small."); } - if (n_args > 6) { - uint16_t bg = mp_obj_get_int(args[5]); + if (n_args > 5) { mp_buffer_info_t alpha; /* Load alpha buffer and check size */ - if (!mp_get_buffer(args[6], &alpha, MP_BUFFER_READ)) { + if (!mp_get_buffer(args[5], &alpha, MP_BUFFER_READ)) { mp_raise_TypeError( "'alpha' does not support buffer protocol." ); } - if (alpha.len < width * height) { + if ((int)alpha.len < width * height) { mp_raise_ValueError("'alpha' is too small."); } @@ -137,7 +136,6 @@ static mp_obj_t mp_display_blit(size_t n_args, const mp_obj_t *args) height, img.len, (uint16_t *)img.buf, - bg, (uint8_t *)alpha.buf ); } else { @@ -148,7 +146,6 @@ static mp_obj_t mp_display_blit(size_t n_args, const mp_obj_t *args) height, img.len, (uint16_t *)img.buf, - 0, NULL ); } @@ -160,7 +157,7 @@ static mp_obj_t mp_display_blit(size_t n_args, const mp_obj_t *args) return mp_const_none; } static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN( - display_blit_obj, 5, 7, mp_display_blit + display_blit_obj, 5, 6, mp_display_blit ); /* set display backlight brightness */