Skip to content

Commit eddba80

Browse files
committed
【完善】lcd bmp show 增加 bmp 图片位数检测
1 parent a9fec08 commit eddba80

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

port/modules/machine/machine_lcd.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@
2626

2727
#include <stdio.h>
2828
#include <string.h>
29-
29+
#include <dfs_posix.h>
3030
#include "py/mphal.h"
3131
#include "py/runtime.h"
32-
#include <dfs_posix.h>
3332
#include "py/mperrno.h"
3433

3534
#if MICROPY_PY_MACHINE_LCD
@@ -216,13 +215,13 @@ STATIC mp_obj_t machine_lcd_show_image(size_t n_args, const mp_obj_t *args) {
216215
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_lcd_show_image_obj, 6, 6, machine_lcd_show_image);
217216

218217
rt_uint16_t rgb888to565(rt_uint32_t RGB)
219-
{
218+
{
220219
int R, G, B;
221220
R = (RGB >> 19) & 0x1F;
222221
G = (RGB >> 10) & 0x3F;
223222
B = (RGB >> 3) & 0x1F;
224223
return (R << 11) | (G << 5) | B;
225-
}
224+
}
226225

227226
/// \method show_image array
228227
///
@@ -258,6 +257,13 @@ STATIC mp_obj_t machine_lcd_show_bmp(size_t n_args, const mp_obj_t *args) {
258257

259258
rt_uint32_t width = *(rt_uint32_t *)(bmp_info + 18);
260259
rt_uint32_t heigth = *(rt_uint32_t *)(bmp_info + 22);
260+
rt_uint16_t bit_count = *(rt_uint16_t *)(bmp_info + 28);
261+
262+
if (bit_count != 32)
263+
{
264+
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
265+
"bit count : %d, only support 32-bit bmp picture", bit_count));
266+
}
261267

262268
void *image_buf = rt_malloc(2 * width);
263269
if (image_buf == RT_NULL)

0 commit comments

Comments
 (0)