diff --git a/src/draw/lv_draw_buf.c b/src/draw/lv_draw_buf.c index 03d456ee7..1610f84b9 100644 --- a/src/draw/lv_draw_buf.c +++ b/src/draw/lv_draw_buf.c @@ -10,6 +10,7 @@ #include "lv_draw_buf.h" #include "../stdlib/lv_string.h" #include "../core/lv_global.h" +#include "../misc/lv_math.h" /********************* * DEFINES @@ -522,8 +523,7 @@ static void * buf_align(void * buf, lv_color_format_t color_format) uint8_t * buf_u8 = buf; if(buf_u8) { - buf_u8 += LV_DRAW_BUF_ALIGN - 1; - buf_u8 = (uint8_t *)((lv_uintptr_t) buf_u8 & ~(LV_DRAW_BUF_ALIGN - 1)); + buf_u8 = (uint8_t *)LV_ROUND_UP((lv_uintptr_t)buf_u8, LV_DRAW_BUF_ALIGN); } return buf_u8; } diff --git a/src/misc/lv_math.h b/src/misc/lv_math.h index 1055b8f78..c81717a63 100644 --- a/src/misc/lv_math.h +++ b/src/misc/lv_math.h @@ -29,6 +29,9 @@ extern "C" { /*Align up value x to align, align must be a power of two*/ #define LV_ALIGN_UP(x, align) (((x) + ((align) - 1)) & ~((align) - 1)) +/*Round up value x to round, round can be any integer number*/ +#define LV_ROUND_UP(x, round) ((((x) + ((round) - 1)) / (round)) * (round)) + /********************** * TYPEDEFS **********************/