lv_draw_buf.h
Defines
-
LV_STRIDE_AUTO
-
_LV_DRAW_BUF_STRIDE(w, cf)
Stride alignment for draw buffers. It may vary between different color formats and hardware. Refine it to suit your needs.
-
_LV_DRAW_BUF_SIZE(w, h, cf)
-
LV_DRAW_BUF_DEFINE(name, _w, _h, _cf)
Define a static draw buffer with the given width, height, and color format. Stride alignment is set to LV_DRAW_BUF_STRIDE_ALIGN.
Typedefs
-
typedef void *(*lv_draw_buf_malloc_cb)(size_t size, lv_color_format_t color_format)
-
typedef void (*lv_draw_buf_free_cb)(void *draw_buf)
-
typedef void *(*lv_draw_buf_align_cb)(void *buf, lv_color_format_t color_format)
-
typedef void (*lv_draw_buf_invalidate_cache_cb)(void *buf, uint32_t stride, lv_color_format_t color_format, const lv_area_t *area)
-
typedef uint32_t (*lv_draw_buf_width_to_stride_cb)(uint32_t w, lv_color_format_t color_format)
Functions
-
void _lv_draw_buf_init_handlers(void)
Called internally to initialize the draw_buf_handlers in lv_global
-
lv_draw_buf_handlers_t *lv_draw_buf_get_handlers(void)
Get the struct which holds the callbacks for draw buf management. Custom callback can be set on the returned value
- Returns:
pointer to the struct of handlers
-
void *lv_draw_buf_align(void *buf, lv_color_format_t color_format)
Align the address of a buffer. The buffer needs to be large enough for the real data after alignment
- Parameters:
buf -- the data to align
color_format -- the color format of the buffer
- Returns:
the aligned buffer
-
void lv_draw_buf_invalidate_cache(void *buf, uint32_t stride, lv_color_format_t color_format, const lv_area_t *area)
Invalidate the cache of the buffer
- Parameters:
buf -- a memory address to invalidate
stride -- stride of the buffer
color_format -- color format of the buffer
area -- the area to invalidate in the buffer
-
uint32_t lv_draw_buf_width_to_stride(uint32_t w, lv_color_format_t color_format)
Calculate the stride in bytes based on a width and color format
- Parameters:
w -- the width in pixels
color_format -- the color format
- Returns:
the stride in bytes
-
void lv_draw_buf_clear(lv_draw_buf_t *draw_buf, const lv_area_t *a)
Clear an area on the buffer
- Parameters:
draw_buf -- pointer to draw buffer
a -- the area to clear, or NULL to clear the whole buffer
-
void lv_draw_buf_copy(lv_draw_buf_t *dest, const lv_area_t *dest_area, const lv_draw_buf_t *src, const lv_area_t *src_area)
Copy an area from a buffer to an other
Note
dest_area
andsrc_area
should have the same width and heightNote
dest
andsrc
should have same color format. Color converting is not supported fow now.- Parameters:
dest -- pointer to the destination draw buffer
dest_area -- the area to copy from the destination buffer, if NULL, use the whole buffer
src -- pointer to the source draw buffer
src_area -- the area to copy from the destination buffer, if NULL, use the whole buffer
-
lv_draw_buf_t *lv_draw_buf_create(uint32_t w, uint32_t h, lv_color_format_t cf, uint32_t stride)
Note: Eventually, lv_draw_buf_malloc/free will be kept as private. For now, we use
create
to distinguish with malloc.Create an draw buf by allocating struct for
lv_draw_buf_t
and allocating a buffer for it that meets specified requirements.- Parameters:
w -- the buffer width in pixels
h -- the buffer height in pixels
cf -- the color format for image
stride -- the stride in bytes for image. Use 0 for automatic calculation based on w, cf, and global stride alignment configuration.
-
lv_result_t lv_draw_buf_init(lv_draw_buf_t *draw_buf, uint32_t w, uint32_t h, lv_color_format_t cf, uint32_t stride, void *data, uint32_t data_size)
Initialize a draw buf with the given buffer and parameters.
- Parameters:
draw_buf -- the draw buf to initialize
w -- the buffer width in pixels
h -- the buffer height in pixels
cf -- the color format
stride -- the stride in bytes. Use 0 for automatic calculation
data -- the buffer used for drawing. Unaligned
data
will be aligned internallydata_size -- the size of the buffer in bytes
- Returns:
return LV_RESULT_OK on success, LV_RESULT_INVALID otherwise
-
lv_draw_buf_t *lv_draw_buf_dup(const lv_draw_buf_t *draw_buf)
Duplicate a draw buf with same image size, stride and color format. Copy the image data too.
- Parameters:
draw_buf -- the draw buf to duplicate
- Returns:
the duplicated draw buf on success, NULL if failed
-
lv_draw_buf_t *lv_draw_buf_reshape(lv_draw_buf_t *draw_buf, lv_color_format_t cf, uint32_t w, uint32_t h, uint32_t stride)
Keep using the existing memory, reshape the draw buffer to the given width and height. Return NULL if data_size is smaller than the required size.
- Parameters:
draw_buf -- pointer to a draw buffer
cf -- the new color format, use 0 or LV_COLOR_FORMAT_UNKNOWN to keep using the original color format.
w -- the new width in pixels
h -- the new height in pixels
stride -- the stride in bytes for image. Use 0 for automatic calculation.
-
void lv_draw_buf_destroy(lv_draw_buf_t *buf)
Destroy a draw buf by free the actual buffer if it's marked as LV_IMAGE_FLAGS_MODIFIABLE in header. Then free the lv_draw_buf_t struct.
-
void *lv_draw_buf_goto_xy(const lv_draw_buf_t *buf, uint32_t x, uint32_t y)
Return pointer to the buffer at the given coordinates
-
lv_draw_buf_t *lv_draw_buf_adjust_stride(const lv_draw_buf_t *src, uint32_t stride)
Adjust the stride of a draw buf.
-
lv_result_t lv_draw_buf_premultiply(lv_draw_buf_t *draw_buf)
Premultiply draw buffer color with alpha channel. If it's already premultiplied, return directly. Only color formats with alpha channel will be processed.
- Returns:
LV_RESULT_OK: premultiply success
-
static inline bool lv_draw_buf_has_flag(lv_draw_buf_t *draw_buf, lv_image_flags_t flag)
-
static inline void lv_draw_buf_from_image(lv_draw_buf_t *buf, const lv_image_dsc_t *img)
As of now, draw buf share same definition as
lv_image_dsc_t
. And is interchangeable withlv_image_dsc_t
.
-
static inline void lv_draw_buf_to_image(const lv_draw_buf_t *buf, lv_image_dsc_t *img)
-
struct lv_draw_buf_t
-
struct lv_draw_buf_handlers_t
Public Members
-
lv_draw_buf_malloc_cb buf_malloc_cb
-
lv_draw_buf_free_cb buf_free_cb
-
lv_draw_buf_align_cb align_pointer_cb
-
lv_draw_buf_invalidate_cache_cb invalidate_cache_cb
-
lv_draw_buf_width_to_stride_cb width_to_stride_cb
-
lv_draw_buf_malloc_cb buf_malloc_cb