Unnamed: 0
int64 0
0
| repo_id
stringlengths 5
186
| file_path
stringlengths 15
223
| content
stringlengths 1
32.8M
⌀ |
---|---|---|---|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/sw | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/sw/blend/lv_draw_sw_blend_to_argb8888.h | /**
* @file lv_draw_sw_blend_argb8888.h
*
*/
#ifndef LV_DRAW_SW_BLEND_ARGB8888_H
#define LV_DRAW_SW_BLEND_ARGB8888_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_draw_sw.h"
#if LV_USE_DRAW_SW
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
LV_ATTRIBUTE_FAST_MEM void lv_draw_sw_blend_color_to_argb8888(_lv_draw_sw_blend_fill_dsc_t * dsc);
LV_ATTRIBUTE_FAST_MEM void lv_draw_sw_blend_image_to_argb8888(_lv_draw_sw_blend_image_dsc_t * dsc);
/**********************
* MACROS
**********************/
#endif /*LV_USE_DRAW_SW*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_DRAW_SW_BLEND_ARGB8888_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/sw | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/sw/blend/lv_draw_sw_blend_to_argb8888.c | /**
* @file lv_draw_sw_blend.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_sw_blend_to_argb8888.h"
#if LV_USE_DRAW_SW
#include "lv_draw_sw_blend.h"
#include "../../../misc/lv_math.h"
#include "../../../display/lv_display.h"
#include "../../../core/lv_refr.h"
#include "../../../misc/lv_color.h"
#include "../../../stdlib/lv_string.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef struct {
lv_color32_t fg_saved;
lv_color32_t bg_saved;
lv_color32_t res_saved;
lv_opa_t res_alpha_saved;
lv_opa_t ratio_saved;
} lv_color_mix_alpha_cache_t;
/**********************
* STATIC PROTOTYPES
**********************/
LV_ATTRIBUTE_FAST_MEM static void rgb565_image_blend(_lv_draw_sw_blend_image_dsc_t * dsc);
LV_ATTRIBUTE_FAST_MEM static void rgb888_image_blend(_lv_draw_sw_blend_image_dsc_t * dsc, const uint8_t src_px_size);
LV_ATTRIBUTE_FAST_MEM static void argb8888_image_blend(_lv_draw_sw_blend_image_dsc_t * dsc);
LV_ATTRIBUTE_FAST_MEM static inline lv_color32_t lv_color_32_32_mix(lv_color32_t fg, lv_color32_t bg,
lv_color_mix_alpha_cache_t * cache);
static void lv_color_mix_with_alpha_cache_init(lv_color_mix_alpha_cache_t * cache);
LV_ATTRIBUTE_FAST_MEM static inline void blend_non_normal_pixel(lv_color32_t * dest, lv_color32_t src,
lv_blend_mode_t mode, lv_color_mix_alpha_cache_t * cache);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
LV_ATTRIBUTE_FAST_MEM void lv_draw_sw_blend_color_to_argb8888(_lv_draw_sw_blend_fill_dsc_t * dsc)
{
int32_t w = dsc->dest_w;
int32_t h = dsc->dest_h;
lv_opa_t opa = dsc->opa;
const lv_opa_t * mask = dsc->mask_buf;
int32_t mask_stride = dsc->mask_stride;
int32_t dest_stride = dsc->dest_stride;
lv_color_mix_alpha_cache_t cache;
lv_color_mix_with_alpha_cache_init(&cache);
int32_t x;
int32_t y;
/*Simple fill*/
if(mask == NULL && opa >= LV_OPA_MAX) {
uint32_t color32 = lv_color_to_u32(dsc->color);
uint32_t * dest_buf = dsc->dest_buf;
for(y = 0; y < h; y++) {
for(x = 0; x < w - 16; x += 16) {
dest_buf[x + 0] = color32;
dest_buf[x + 1] = color32;
dest_buf[x + 2] = color32;
dest_buf[x + 3] = color32;
dest_buf[x + 4] = color32;
dest_buf[x + 5] = color32;
dest_buf[x + 6] = color32;
dest_buf[x + 7] = color32;
dest_buf[x + 8] = color32;
dest_buf[x + 9] = color32;
dest_buf[x + 10] = color32;
dest_buf[x + 11] = color32;
dest_buf[x + 12] = color32;
dest_buf[x + 13] = color32;
dest_buf[x + 14] = color32;
dest_buf[x + 15] = color32;
}
for(; x < w; x ++) {
dest_buf[x] = color32;
}
dest_buf += dest_stride;
}
}
/*Opacity only*/
else if(mask == NULL && opa < LV_OPA_MAX) {
lv_color32_t color_argb = lv_color_to_32(dsc->color, opa);
lv_color32_t * dest_buf = dsc->dest_buf;
for(y = 0; y < h; y++) {
for(x = 0; x < w; x++) {
dest_buf[x] = lv_color_32_32_mix(color_argb, dest_buf[x], &cache);
}
dest_buf += dest_stride;
}
}
/*Masked with full opacity*/
else if(mask && opa >= LV_OPA_MAX) {
lv_color32_t color_argb = lv_color_to_32(dsc->color, 0xff);
lv_color32_t * dest_buf = dsc->dest_buf;
for(y = 0; y < h; y++) {
for(x = 0; x < w; x++) {
color_argb.alpha = mask[x];
dest_buf[x] = lv_color_32_32_mix(color_argb, dest_buf[x], &cache);
}
dest_buf += dest_stride;
mask += mask_stride;
}
}
/*Masked with opacity*/
else {
lv_color32_t color_argb = lv_color_to_32(dsc->color, opa);
lv_color32_t * dest_buf = dsc->dest_buf;
for(y = 0; y < h; y++) {
for(x = 0; x < w; x++) {
color_argb.alpha = LV_OPA_MIX2(mask[x], opa);
dest_buf[x] = lv_color_32_32_mix(color_argb, dest_buf[x], &cache);
}
dest_buf += dest_stride;
mask += mask_stride;
}
}
}
LV_ATTRIBUTE_FAST_MEM void lv_draw_sw_blend_image_to_argb8888(_lv_draw_sw_blend_image_dsc_t * dsc)
{
switch(dsc->src_color_format) {
case LV_COLOR_FORMAT_RGB565:
rgb565_image_blend(dsc);
break;
case LV_COLOR_FORMAT_RGB888:
rgb888_image_blend(dsc, 3);
break;
case LV_COLOR_FORMAT_XRGB8888:
rgb888_image_blend(dsc, 4);
break;
case LV_COLOR_FORMAT_ARGB8888:
argb8888_image_blend(dsc);
break;
default:
LV_LOG_WARN("Not supported source color format");
break;
}
}
/**********************
* STATIC FUNCTIONS
**********************/
LV_ATTRIBUTE_FAST_MEM static void rgb565_image_blend(_lv_draw_sw_blend_image_dsc_t * dsc)
{
int32_t w = dsc->dest_w;
int32_t h = dsc->dest_h;
lv_opa_t opa = dsc->opa;
lv_color32_t * dest_buf_c32 = dsc->dest_buf;
int32_t dest_stride = dsc->dest_stride;
const lv_color16_t * src_buf_c16 = (const lv_color16_t *) dsc->src_buf;
int32_t src_stride = dsc->src_stride;
const lv_opa_t * mask_buf = dsc->mask_buf;
int32_t mask_stride = dsc->mask_stride;
lv_color32_t color_argb;
lv_color_mix_alpha_cache_t cache;
lv_color_mix_with_alpha_cache_init(&cache);
int32_t x;
int32_t y;
if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
if(mask_buf == NULL) {
color_argb.alpha = opa;
for(y = 0; y < h; y++) {
for(x = 0; x < w; x++) {
color_argb.red = (src_buf_c16[x].red * 2106) >> 8; /*To make it rounded*/
color_argb.green = (src_buf_c16[x].green * 1037) >> 8;
color_argb.blue = (src_buf_c16[x].blue * 2106) >> 8;
dest_buf_c32[x] = lv_color_32_32_mix(color_argb, dest_buf_c32[x], &cache);
}
dest_buf_c32 += dest_stride;
src_buf_c16 += src_stride;
}
}
else if(mask_buf && opa >= LV_OPA_MAX) {
for(y = 0; y < h; y++) {
for(x = 0; x < w; x++) {
color_argb.alpha = mask_buf[x];
color_argb.red = (src_buf_c16[x].red * 2106) >> 8; /*To make it rounded*/
color_argb.green = (src_buf_c16[x].green * 1037) >> 8;
color_argb.blue = (src_buf_c16[x].blue * 2106) >> 8;
dest_buf_c32[x] = lv_color_32_32_mix(color_argb, dest_buf_c32[x], &cache);
}
dest_buf_c32 += dest_stride;
src_buf_c16 += src_stride;
mask_buf += mask_stride;
}
}
else {
for(y = 0; y < h; y++) {
for(x = 0; x < w; x++) {
color_argb.alpha = LV_OPA_MIX2(mask_buf[x], opa);
color_argb.red = (src_buf_c16[x].red * 2106) >> 8; /*To make it rounded*/
color_argb.green = (src_buf_c16[x].green * 1037) >> 8;
color_argb.blue = (src_buf_c16[x].blue * 2106) >> 8;
dest_buf_c32[x] = lv_color_32_32_mix(color_argb, dest_buf_c32[x], &cache);
}
dest_buf_c32 += dest_stride;
src_buf_c16 += src_stride;
mask_buf += mask_stride;
}
}
}
else {
lv_color32_t src_argb;
for(y = 0; y < h; y++) {
for(x = 0; x < w; x++) {
src_argb.red = (src_buf_c16[x].red * 2106) >> 8;
src_argb.green = (src_buf_c16[x].green * 1037) >> 8;
src_argb.blue = (src_buf_c16[x].blue * 2106) >> 8;
if(mask_buf == NULL) src_argb.alpha = opa;
else src_argb.alpha = LV_OPA_MIX2(mask_buf[x], opa);
blend_non_normal_pixel(&dest_buf_c32[x], src_argb, dsc->blend_mode, &cache);
}
if(mask_buf) mask_buf += mask_stride;
dest_buf_c32 += dest_stride;
src_buf_c16 += src_stride;
}
}
}
LV_ATTRIBUTE_FAST_MEM static void rgb888_image_blend(_lv_draw_sw_blend_image_dsc_t * dsc, const uint8_t src_px_size)
{
int32_t w = dsc->dest_w;
int32_t h = dsc->dest_h;
lv_opa_t opa = dsc->opa;
lv_color32_t * dest_buf_c32 = dsc->dest_buf;
int32_t dest_stride = dsc->dest_stride;
const uint8_t * src_buf = dsc->src_buf;
int32_t src_stride = dsc->src_stride * src_px_size;
const lv_opa_t * mask_buf = dsc->mask_buf;
int32_t mask_stride = dsc->mask_stride;
lv_color32_t color_argb;
lv_color_mix_alpha_cache_t cache;
lv_color_mix_with_alpha_cache_init(&cache);
int32_t dest_x;
int32_t src_x;
int32_t y;
if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
/*Special case*/
if(mask_buf == NULL && opa >= LV_OPA_MAX) {
if(src_px_size == 4) {
uint32_t line_in_bytes = w * 4;
for(y = 0; y < h; y++) {
lv_memcpy(dest_buf_c32, src_buf, line_in_bytes);
dest_buf_c32 += dest_stride;
src_buf += src_stride;
}
}
else if(src_px_size == 3) {
for(y = 0; y < h; y++) {
for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += 3) {
dest_buf_c32[dest_x].red = src_buf[src_x + 2];
dest_buf_c32[dest_x].green = src_buf[src_x + 1];
dest_buf_c32[dest_x].blue = src_buf[src_x + 0];
dest_buf_c32[dest_x].alpha = 0xff;
}
dest_buf_c32 += dest_stride;
src_buf += src_stride;
}
}
}
if(mask_buf == NULL && opa < LV_OPA_MAX) {
color_argb.alpha = opa;
for(y = 0; y < h; y++) {
for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += src_px_size) {
color_argb.red = src_buf[src_x + 2];
color_argb.green = src_buf[src_x + 1];
color_argb.blue = src_buf[src_x + 0];
dest_buf_c32[dest_x] = lv_color_32_32_mix(color_argb, dest_buf_c32[dest_x], &cache);
}
dest_buf_c32 += dest_stride;
src_buf += src_stride;
}
}
if(mask_buf && opa >= LV_OPA_MAX) {
for(y = 0; y < h; y++) {
for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += src_px_size) {
color_argb.alpha = mask_buf[dest_x];
color_argb.red = src_buf[src_x + 2];
color_argb.green = src_buf[src_x + 1];
color_argb.blue = src_buf[src_x + 0];
dest_buf_c32[dest_x] = lv_color_32_32_mix(color_argb, dest_buf_c32[dest_x], &cache);
}
dest_buf_c32 += dest_stride;
src_buf += src_stride;
mask_buf += mask_stride;
}
}
if(mask_buf && opa < LV_OPA_MAX) {
for(y = 0; y < h; y++) {
for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += src_px_size) {
color_argb.alpha = (opa * mask_buf[dest_x]) >> 8;
color_argb.red = src_buf[src_x + 2];
color_argb.green = src_buf[src_x + 1];
color_argb.blue = src_buf[src_x + 0];
dest_buf_c32[dest_x] = lv_color_32_32_mix(color_argb, dest_buf_c32[dest_x], &cache);
}
dest_buf_c32 += dest_stride;
src_buf += src_stride;
mask_buf += mask_stride;
}
}
}
else {
lv_color32_t src_argb;
for(y = 0; y < h; y++) {
for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += src_px_size) {
src_argb.red = src_buf[src_x + 2];
src_argb.green = src_buf[src_x + 1];
src_argb.blue = src_buf[src_x + 0];
if(mask_buf == NULL) src_argb.alpha = opa;
else src_argb.alpha = LV_OPA_MIX2(mask_buf[dest_x], opa);
blend_non_normal_pixel(&dest_buf_c32[dest_x], src_argb, dsc->blend_mode, &cache);
}
if(mask_buf) mask_buf += mask_stride;
dest_buf_c32 += dest_stride;
src_buf += src_stride;
}
}
}
LV_ATTRIBUTE_FAST_MEM static void argb8888_image_blend(_lv_draw_sw_blend_image_dsc_t * dsc)
{
int32_t w = dsc->dest_w;
int32_t h = dsc->dest_h;
lv_opa_t opa = dsc->opa;
lv_color32_t * dest_buf_c32 = dsc->dest_buf;
int32_t dest_stride = dsc->dest_stride;
const lv_color32_t * src_buf_c32 = dsc->src_buf;
int32_t src_stride = dsc->src_stride;
const lv_opa_t * mask_buf = dsc->mask_buf;
int32_t mask_stride = dsc->mask_stride;
lv_color32_t color_argb;
lv_color_mix_alpha_cache_t cache;
lv_color_mix_with_alpha_cache_init(&cache);
int32_t x;
int32_t y;
if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
if(mask_buf == NULL && opa >= LV_OPA_MAX) {
for(y = 0; y < h; y++) {
for(x = 0; x < w; x++) {
dest_buf_c32[x] = lv_color_32_32_mix(src_buf_c32[x], dest_buf_c32[x], &cache);
}
dest_buf_c32 += dest_stride;
src_buf_c32 += src_stride;
}
}
else if(mask_buf == NULL && opa < LV_OPA_MAX) {
for(y = 0; y < h; y++) {
for(x = 0; x < w; x++) {
color_argb = src_buf_c32[x];
color_argb.alpha = LV_OPA_MIX2(color_argb.alpha, opa);
dest_buf_c32[x] = lv_color_32_32_mix(color_argb, dest_buf_c32[x], &cache);
}
dest_buf_c32 += dest_stride;
src_buf_c32 += src_stride;
}
}
else if(mask_buf && opa >= LV_OPA_MAX) {
for(y = 0; y < h; y++) {
for(x = 0; x < w; x++) {
color_argb = src_buf_c32[x];
color_argb.alpha = LV_OPA_MIX2(color_argb.alpha, mask_buf[x]);
dest_buf_c32[x] = lv_color_32_32_mix(color_argb, dest_buf_c32[x], &cache);
}
dest_buf_c32 += dest_stride;
src_buf_c32 += src_stride;
mask_buf += mask_stride;
}
}
else if(mask_buf && opa < LV_OPA_MAX) {
for(y = 0; y < h; y++) {
for(x = 0; x < w; x++) {
color_argb = src_buf_c32[x];
color_argb.alpha = LV_OPA_MIX3(color_argb.alpha, opa, mask_buf[x]);
dest_buf_c32[x] = lv_color_32_32_mix(color_argb, dest_buf_c32[x], &cache);
}
dest_buf_c32 += dest_stride;
src_buf_c32 += src_stride;
mask_buf += mask_stride;
}
}
}
else {
for(y = 0; y < h; y++) {
for(x = 0; x < w; x++) {
color_argb = src_buf_c32[x];
if(mask_buf == NULL) color_argb.alpha = LV_OPA_MIX2(color_argb.alpha, opa);
else color_argb.alpha = LV_OPA_MIX3(color_argb.alpha, mask_buf[x], opa);
blend_non_normal_pixel(&dest_buf_c32[x], color_argb, dsc->blend_mode, &cache);
}
if(mask_buf) mask_buf += mask_stride;
dest_buf_c32 += dest_stride;
src_buf_c32 += src_stride;
}
}
}
LV_ATTRIBUTE_FAST_MEM static inline lv_color32_t lv_color_32_32_mix(lv_color32_t fg, lv_color32_t bg,
lv_color_mix_alpha_cache_t * cache)
{
/*Pick the foreground if it's fully opaque or the Background is fully transparent*/
if(fg.alpha >= LV_OPA_MAX || bg.alpha <= LV_OPA_MIN) {
return fg;
}
/*Transparent foreground: use the Background*/
else if(fg.alpha <= LV_OPA_MIN) {
return bg;
}
/*Opaque background: use simple mix*/
else if(bg.alpha == 255) {
return lv_color_mix32(fg, bg);
}
/*Both colors have alpha. Expensive calculation need to be applied*/
else {
/*Save the parameters and the result. If they will be asked again don't compute again*/
/*Update the ratio and the result alpha value if the input alpha values change*/
if(bg.alpha != cache->bg_saved.alpha || fg.alpha != cache->fg_saved.alpha) {
/*Info:
* https://en.wikipedia.org/wiki/Alpha_compositing#Analytical_derivation_of_the_over_operator*/
cache->res_alpha_saved = 255 - LV_OPA_MIX2(255 - fg.alpha, 255 - bg.alpha);
LV_ASSERT(cache->ratio_saved != 0);
cache->ratio_saved = (uint32_t)((uint32_t)fg.alpha * 255) / cache->res_alpha_saved;
}
if(!lv_color32_eq(bg, cache->bg_saved) || !lv_color32_eq(fg, cache->fg_saved)) {
cache->fg_saved = fg;
cache->bg_saved = bg;
fg.alpha = cache->ratio_saved;
cache->res_saved = lv_color_mix32(fg, bg);
cache->res_saved.alpha = cache->res_alpha_saved;
}
return cache->res_saved;
}
}
void lv_color_mix_with_alpha_cache_init(lv_color_mix_alpha_cache_t * cache)
{
lv_memzero(&cache->fg_saved, sizeof(lv_color32_t));
lv_memzero(&cache->bg_saved, sizeof(lv_color32_t));
lv_memzero(&cache->res_saved, sizeof(lv_color32_t));
cache->res_alpha_saved = 255;
cache->ratio_saved = 255;
}
LV_ATTRIBUTE_FAST_MEM static inline void blend_non_normal_pixel(lv_color32_t * dest, lv_color32_t src,
lv_blend_mode_t mode, lv_color_mix_alpha_cache_t * cache)
{
lv_color32_t res = {0, 0, 0, 0};
switch(mode) {
case LV_BLEND_MODE_ADDITIVE:
res.red = LV_MIN(dest->red + src.red, 255);
res.green = LV_MIN(dest->green + src.green, 255);
res.blue = LV_MIN(dest->blue + src.blue, 255);
break;
case LV_BLEND_MODE_SUBTRACTIVE:
res.red = LV_MAX(dest->red - src.red, 0);
res.green = LV_MAX(dest->green - src.green, 0);
res.blue = LV_MAX(dest->blue - src.blue, 0);
break;
case LV_BLEND_MODE_MULTIPLY:
res.red = (dest->red * src.red) >> 8;
res.green = (dest->green * src.green) >> 8;
res.blue = (dest->blue * src.blue) >> 8;
break;
default:
LV_LOG_WARN("Not supported blend mode: %d", mode);
return;
}
*dest = lv_color_32_32_mix(res, *dest, cache);
}
#endif
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/sw | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/sw/blend/lv_draw_sw_blend_to_rgb888.c | /**
* @file lv_draw_sw_blend_rgb888.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_sw_blend_to_rgb888.h"
#if LV_USE_DRAW_SW
#include "lv_draw_sw_blend.h"
#include "../../../misc/lv_math.h"
#include "../../../display/lv_display.h"
#include "../../../core/lv_refr.h"
#include "../../../misc/lv_color.h"
#include "../../../stdlib/lv_string.h"
#if LV_USE_DRAW_SW_ASM == LV_DRAW_SW_ASM_NEON
#include "neon/lv_blend_to_rgb888_neon.h"
#elif LV_USE_DRAW_SW_ASM == LV_DRAW_SW_ASM_CUSTOM
#include LV_DRAW_SW_ASM_CUSTOM_INCLUDE
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
LV_ATTRIBUTE_FAST_MEM static void rgb565_image_blend(_lv_draw_sw_blend_image_dsc_t * dsc, uint32_t dest_px_size);
LV_ATTRIBUTE_FAST_MEM static void rgb888_image_blend(_lv_draw_sw_blend_image_dsc_t * dsc, const uint8_t dest_px_size,
uint32_t src_px_size);
LV_ATTRIBUTE_FAST_MEM static void argb8888_image_blend(_lv_draw_sw_blend_image_dsc_t * dsc, uint32_t dest_px_size);
LV_ATTRIBUTE_FAST_MEM static inline void lv_color_24_24_mix(const uint8_t * src, uint8_t * dest, uint8_t mix);
LV_ATTRIBUTE_FAST_MEM static inline void blend_non_normal_pixel(uint8_t * dest, lv_color32_t src, lv_blend_mode_t mode);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
LV_ATTRIBUTE_FAST_MEM void lv_draw_sw_blend_color_to_rgb888(_lv_draw_sw_blend_fill_dsc_t * dsc, uint32_t dest_px_size)
{
int32_t w = dsc->dest_w;
int32_t h = dsc->dest_h;
lv_opa_t opa = dsc->opa;
const lv_opa_t * mask = dsc->mask_buf;
int32_t mask_stride = dsc->mask_stride;
int32_t dest_stride = dsc->dest_stride;
int32_t x;
int32_t y;
LV_UNUSED(w);
LV_UNUSED(h);
LV_UNUSED(x);
LV_UNUSED(y);
LV_UNUSED(opa);
LV_UNUSED(mask);
LV_UNUSED(mask_stride);
LV_UNUSED(dest_stride);
/*Simple fill*/
if(mask == NULL && opa >= LV_OPA_MAX) {
#ifdef LV_DRAW_SW_COLOR_BLEND_TO_RGB888
LV_DRAW_SW_COLOR_BLEND_TO_RGB888(dsc, dest_px_size);
#else
if(dest_px_size == 3) {
uint8_t * dest_buf_u8 = dsc->dest_buf;
uint8_t * dest_buf_ori = dsc->dest_buf;
dest_stride *= dest_px_size;
w *= dest_px_size;
for(x = 0; x < w; x += 3) {
dest_buf_u8[x + 0] = dsc->color.blue;
dest_buf_u8[x + 1] = dsc->color.green;
dest_buf_u8[x + 2] = dsc->color.red;
}
dest_buf_u8 += dest_stride;
for(y = 1; y < h; y++) {
lv_memcpy(dest_buf_u8, dest_buf_ori, w);
dest_buf_u8 += dest_stride;
}
}
if(dest_px_size == 4) {
uint32_t color32 = lv_color_to_u32(dsc->color);
uint32_t * dest_buf_u32 = dsc->dest_buf;
for(y = 0; y < h; y++) {
for(x = 0; x <= w - 16; x += 16) {
dest_buf_u32[x + 0] = color32;
dest_buf_u32[x + 1] = color32;
dest_buf_u32[x + 2] = color32;
dest_buf_u32[x + 3] = color32;
dest_buf_u32[x + 4] = color32;
dest_buf_u32[x + 5] = color32;
dest_buf_u32[x + 6] = color32;
dest_buf_u32[x + 7] = color32;
dest_buf_u32[x + 8] = color32;
dest_buf_u32[x + 9] = color32;
dest_buf_u32[x + 10] = color32;
dest_buf_u32[x + 11] = color32;
dest_buf_u32[x + 12] = color32;
dest_buf_u32[x + 13] = color32;
dest_buf_u32[x + 14] = color32;
dest_buf_u32[x + 15] = color32;
}
for(; x < w; x ++) {
dest_buf_u32[x] = color32;
}
dest_buf_u32 += dest_stride;
}
}
#endif
}
/*Opacity only*/
else if(mask == NULL && opa < LV_OPA_MAX) {
#ifdef LV_DRAW_SW_COLOR_BLEND_TO_RGB888_WITH_OPA
LV_DRAW_SW_COLOR_BLEND_TO_RGB888_WITH_OPA(dsc, dest_px_size);
#else
uint32_t color32 = lv_color_to_u32(dsc->color);
uint8_t * dest_buf = dsc->dest_buf;
dest_stride *= dest_px_size;
w *= dest_px_size;
for(y = 0; y < h; y++) {
for(x = 0; x < w; x += dest_px_size) {
lv_color_24_24_mix((const uint8_t *)&color32, &dest_buf[x], opa);
}
dest_buf += dest_stride;
}
#endif
}
/*Masked with full opacity*/
else if(mask && opa >= LV_OPA_MAX) {
#ifdef LV_DRAW_SW_COLOR_BLEND_TO_RGB888_WITH_MASK
LV_DRAW_SW_COLOR_BLEND_TO_RGB888_WITH_MASK(dsc, dest_px_size);
#else
uint32_t color32 = lv_color_to_u32(dsc->color);
uint8_t * dest_buf = dsc->dest_buf;
dest_stride *= dest_px_size;
w *= dest_px_size;
for(y = 0; y < h; y++) {
uint32_t mask_x;
for(x = 0, mask_x = 0; x < w; x += dest_px_size, mask_x++) {
lv_color_24_24_mix((const uint8_t *)&color32, &dest_buf[x], mask[mask_x]);
}
dest_buf += dest_stride;
mask += mask_stride;
}
#endif
}
/*Masked with opacity*/
else {
#ifdef LV_DRAW_SW_COLOR_BLEND_TO_RGB888_MIX_MASK_OPA
LV_DRAW_SW_COLOR_BLEND_TO_RGB888_MIX_MASK_OPA(dsc, dest_px_size);
#else
uint32_t color32 = lv_color_to_u32(dsc->color);
uint8_t * dest_buf = dsc->dest_buf;
dest_stride *= dest_px_size;
w *= dest_px_size;
for(y = 0; y < h; y++) {
uint32_t mask_x;
for(x = 0, mask_x = 0; x < w; x += dest_px_size, mask_x++) {
lv_color_24_24_mix((const uint8_t *) &color32, &dest_buf[x], LV_OPA_MIX2(opa, mask[mask_x]));
}
dest_buf += dest_stride;
mask += mask_stride;
}
#endif
}
}
LV_ATTRIBUTE_FAST_MEM void lv_draw_sw_blend_image_to_rgb888(_lv_draw_sw_blend_image_dsc_t * dsc, uint32_t dest_px_size)
{
switch(dsc->src_color_format) {
case LV_COLOR_FORMAT_RGB565:
rgb565_image_blend(dsc, dest_px_size);
break;
case LV_COLOR_FORMAT_RGB888:
rgb888_image_blend(dsc, dest_px_size, 3);
break;
case LV_COLOR_FORMAT_XRGB8888:
rgb888_image_blend(dsc, dest_px_size, 4);
break;
case LV_COLOR_FORMAT_ARGB8888:
argb8888_image_blend(dsc, dest_px_size);
break;
default:
LV_LOG_WARN("Not supported source color format");
break;
}
}
/**********************
* STATIC FUNCTIONS
**********************/
LV_ATTRIBUTE_FAST_MEM static void rgb565_image_blend(_lv_draw_sw_blend_image_dsc_t * dsc, uint32_t dest_px_size)
{
int32_t w = dsc->dest_w;
int32_t h = dsc->dest_h;
lv_opa_t opa = dsc->opa;
uint8_t * dest_buf_u8 = dsc->dest_buf;
int32_t dest_stride = dsc->dest_stride * dest_px_size;
const lv_color16_t * src_buf_c16 = (const lv_color16_t *) dsc->src_buf;
int32_t src_stride = dsc->src_stride;
const lv_opa_t * mask_buf = dsc->mask_buf;
int32_t mask_stride = dsc->mask_stride;
int32_t src_x;
int32_t dest_x;
int32_t y;
if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
if(mask_buf == NULL && opa >= LV_OPA_MAX) {
for(y = 0; y < h; y++) {
for(src_x = 0, dest_x = 0; src_x < w; dest_x += dest_px_size, src_x++) {
dest_buf_u8[dest_x + 2] = (src_buf_c16[src_x].red * 2106) >> 8; /*To make it rounded*/
dest_buf_u8[dest_x + 1] = (src_buf_c16[src_x].green * 1037) >> 8;
dest_buf_u8[dest_x + 0] = (src_buf_c16[src_x].blue * 2106) >> 8;
}
dest_buf_u8 += dest_stride;
src_buf_c16 += src_stride;
}
}
else if(mask_buf == NULL && opa < LV_OPA_MAX) {
uint8_t res[3];
for(y = 0; y < h; y++) {
for(src_x = 0, dest_x = 0; src_x < w; dest_x += dest_px_size, src_x++) {
res[2] = (src_buf_c16[src_x].red * 2106) >> 8; /*To make it rounded*/
res[1] = (src_buf_c16[src_x].green * 1037) >> 8;
res[0] = (src_buf_c16[src_x].blue * 2106) >> 8;
lv_color_24_24_mix(res, &dest_buf_u8[dest_x], opa);
}
dest_buf_u8 += dest_stride;
src_buf_c16 += src_stride;
}
}
else if(mask_buf && opa >= LV_OPA_MAX) {
uint8_t res[3];
for(y = 0; y < h; y++) {
for(src_x = 0, dest_x = 0; src_x < w; dest_x += dest_px_size, src_x++) {
res[2] = (src_buf_c16[src_x].red * 2106) >> 8; /*To make it rounded*/
res[1] = (src_buf_c16[src_x].green * 1037) >> 8;
res[0] = (src_buf_c16[src_x].blue * 2106) >> 8;
lv_color_24_24_mix(res, &dest_buf_u8[dest_x], mask_buf[src_x]);
}
dest_buf_u8 += dest_stride;
src_buf_c16 += src_stride;
mask_buf += mask_stride;
}
}
else {
uint8_t res[3];
for(y = 0; y < h; y++) {
for(src_x = 0, dest_x = 0; src_x < w; dest_x += dest_px_size, src_x++) {
res[2] = (src_buf_c16[src_x].red * 2106) >> 8; /*To make it rounded*/
res[1] = (src_buf_c16[src_x].green * 1037) >> 8;
res[0] = (src_buf_c16[src_x].blue * 2106) >> 8;
lv_color_24_24_mix(res, &dest_buf_u8[dest_x], LV_OPA_MIX2(opa, mask_buf[src_x]));
}
dest_buf_u8 += dest_stride;
src_buf_c16 += src_stride;
mask_buf += mask_stride;
}
}
}
else {
lv_color32_t src_argb;
for(y = 0; y < h; y++) {
for(src_x = 0, dest_x = 0; src_x < w; src_x++, dest_x += dest_px_size) {
src_argb.red = (src_buf_c16[src_x].red * 2106) >> 8;
src_argb.green = (src_buf_c16[src_x].green * 1037) >> 8;
src_argb.blue = (src_buf_c16[src_x].blue * 2106) >> 8;
if(mask_buf == NULL) src_argb.alpha = opa;
else src_argb.alpha = LV_OPA_MIX2(mask_buf[src_x], opa);
blend_non_normal_pixel(&dest_buf_u8[dest_x], src_argb, dsc->blend_mode);
}
if(mask_buf) mask_buf += mask_stride;
dest_buf_u8 += dest_stride;
src_buf_c16 += src_stride;
}
}
}
LV_ATTRIBUTE_FAST_MEM static void rgb888_image_blend(_lv_draw_sw_blend_image_dsc_t * dsc, const uint8_t dest_px_size,
uint32_t src_px_size)
{
int32_t w = dsc->dest_w * dest_px_size;
int32_t h = dsc->dest_h;
lv_opa_t opa = dsc->opa;
uint8_t * dest_buf = dsc->dest_buf;
int32_t dest_stride = dsc->dest_stride * dest_px_size;
const uint8_t * src_buf = dsc->src_buf;
int32_t src_stride = dsc->src_stride * src_px_size;
const lv_opa_t * mask_buf = dsc->mask_buf;
int32_t mask_stride = dsc->mask_stride;
int32_t dest_x;
int32_t src_x;
int32_t y;
if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
/*Special case*/
if(mask_buf == NULL && opa >= LV_OPA_MAX) {
if(src_px_size == dest_px_size) {
for(y = 0; y < h; y++) {
lv_memcpy(dest_buf, src_buf, w);
dest_buf += dest_stride;
src_buf += src_stride;
}
}
else {
for(y = 0; y < h; y++) {
for(dest_x = 0, src_x = 0; dest_x < w; dest_x += dest_px_size, src_x += src_px_size) {
dest_buf[dest_x + 0] = src_buf[src_x + 0];
dest_buf[dest_x + 1] = src_buf[src_x + 1];
dest_buf[dest_x + 2] = src_buf[src_x + 2];
}
dest_buf += dest_stride;
src_buf += src_stride;
}
}
}
if(mask_buf == NULL && opa < LV_OPA_MAX) {
for(y = 0; y < h; y++) {
for(dest_x = 0, src_x = 0; dest_x < w; dest_x += dest_px_size, src_x += src_px_size) {
lv_color_24_24_mix(&src_buf[src_x], &dest_buf[dest_x], opa);
}
dest_buf += dest_stride;
src_buf += src_stride;
}
}
if(mask_buf && opa >= LV_OPA_MAX) {
uint32_t mask_x;
for(y = 0; y < h; y++) {
for(mask_x = 0, dest_x = 0, src_x = 0; dest_x < w; mask_x++, dest_x += dest_px_size, src_x += src_px_size) {
lv_color_24_24_mix(&src_buf[src_x], &dest_buf[dest_x], mask_buf[mask_x]);
}
dest_buf += dest_stride;
src_buf += src_stride;
mask_buf += mask_stride;
}
}
if(mask_buf && opa < LV_OPA_MAX) {
uint32_t mask_x;
for(y = 0; y < h; y++) {
for(mask_x = 0, dest_x = 0, src_x = 0; dest_x < w; mask_x++, dest_x += dest_px_size, src_x += src_px_size) {
lv_color_24_24_mix(&src_buf[src_x], &dest_buf[dest_x], LV_OPA_MIX2(opa, mask_buf[mask_x]));
}
dest_buf += dest_stride;
src_buf += src_stride;
mask_buf += mask_stride;
}
}
}
else {
lv_color32_t src_argb;
for(y = 0; y < h; y++) {
for(dest_x = 0, src_x = 0; dest_x < w; dest_x += dest_px_size, src_x += src_px_size) {
src_argb.red = src_buf[src_x + 2];
src_argb.green = src_buf[src_x + 1];
src_argb.blue = src_buf[src_x + 0];
if(mask_buf == NULL) src_argb.alpha = opa;
else src_argb.alpha = LV_OPA_MIX2(mask_buf[dest_x], opa);
blend_non_normal_pixel(&dest_buf[dest_x], src_argb, dsc->blend_mode);
}
if(mask_buf) mask_buf += mask_stride;
dest_buf += dest_stride;
src_buf += src_stride;
}
}
}
LV_ATTRIBUTE_FAST_MEM static void argb8888_image_blend(_lv_draw_sw_blend_image_dsc_t * dsc, uint32_t dest_px_size)
{
int32_t w = dsc->dest_w;
int32_t h = dsc->dest_h;
lv_opa_t opa = dsc->opa;
uint8_t * dest_buf = dsc->dest_buf;
int32_t dest_stride = dsc->dest_stride * dest_px_size;
const lv_color32_t * src_buf_c32 = dsc->src_buf;
int32_t src_stride = dsc->src_stride;
const lv_opa_t * mask_buf = dsc->mask_buf;
int32_t mask_stride = dsc->mask_stride;
int32_t dest_x;
int32_t src_x;
int32_t y;
if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
if(mask_buf == NULL && opa >= LV_OPA_MAX) {
#ifdef LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB888
LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB888(dsc, dest_px_size);
#else
for(y = 0; y < h; y++) {
for(dest_x = 0, src_x = 0; src_x < w; dest_x += dest_px_size, src_x++) {
lv_color_24_24_mix((const uint8_t *)&src_buf_c32[src_x], &dest_buf[dest_x], src_buf_c32[src_x].alpha);
}
dest_buf += dest_stride;
src_buf_c32 += src_stride;
}
#endif
}
else if(mask_buf == NULL && opa < LV_OPA_MAX) {
#ifdef LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB888_WITH_OPA
LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB888_WITH_OPA(dsc, dest_px_size);
#else
for(y = 0; y < h; y++) {
for(dest_x = 0, src_x = 0; src_x < w; dest_x += dest_px_size, src_x++) {
lv_color_24_24_mix((const uint8_t *)&src_buf_c32[src_x], &dest_buf[dest_x], LV_OPA_MIX2(src_buf_c32[src_x].alpha, opa));
}
dest_buf += dest_stride;
src_buf_c32 += src_stride;
}
#endif
}
else if(mask_buf && opa >= LV_OPA_MAX) {
#ifdef LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB888_WITH_MASK
LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB888_WITH_MASK(dsc, dest_px_size);
#else
for(y = 0; y < h; y++) {
for(dest_x = 0, src_x = 0; src_x < w; dest_x += dest_px_size, src_x++) {
lv_color_24_24_mix((const uint8_t *)&src_buf_c32[src_x], &dest_buf[dest_x],
LV_OPA_MIX2(src_buf_c32[src_x].alpha, mask_buf[src_x]));
}
dest_buf += dest_stride;
src_buf_c32 += src_stride;
mask_buf += mask_stride;
}
#endif
}
else if(mask_buf && opa < LV_OPA_MAX) {
#ifdef LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB888_MIX_MASK_OPA
LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB888_MIX_MASK_OPA(dsc, dest_px_size);
#else
for(y = 0; y < h; y++) {
for(dest_x = 0, src_x = 0; src_x < w; dest_x += dest_px_size, src_x++) {
lv_color_24_24_mix((const uint8_t *)&src_buf_c32[src_x], &dest_buf[dest_x],
LV_OPA_MIX3(src_buf_c32[src_x].alpha, mask_buf[src_x], opa));
}
dest_buf += dest_stride;
src_buf_c32 += src_stride;
mask_buf += mask_stride;
}
#endif
}
}
else {
lv_color32_t src_argb;
for(y = 0; y < h; y++) {
for(dest_x = 0, src_x = 0; src_x < w; dest_x += dest_px_size, src_x ++) {
src_argb = src_buf_c32[src_x];
if(mask_buf == NULL) src_argb.alpha = LV_OPA_MIX2(src_argb.alpha, opa);
else src_argb.alpha = LV_OPA_MIX3(src_argb.alpha, mask_buf[dest_x], opa);
blend_non_normal_pixel(&dest_buf[dest_x], src_argb, dsc->blend_mode);
}
if(mask_buf) mask_buf += mask_stride;
dest_buf += dest_stride;
src_buf_c32 += src_stride;
}
}
}
LV_ATTRIBUTE_FAST_MEM static inline void blend_non_normal_pixel(uint8_t * dest, lv_color32_t src, lv_blend_mode_t mode)
{
uint8_t res[3] = {0, 0, 0};
switch(mode) {
case LV_BLEND_MODE_ADDITIVE:
res[0] = LV_MIN(dest[0] + src.red, 255);
res[1] = LV_MIN(dest[1] + src.green, 255);
res[2] = LV_MIN(dest[2] + src.blue, 255);
break;
case LV_BLEND_MODE_SUBTRACTIVE:
res[0] = LV_MAX(dest[0] - src.red, 0);
res[1] = LV_MAX(dest[1] - src.green, 0);
res[2] = LV_MAX(dest[2] - src.blue, 0);
break;
case LV_BLEND_MODE_MULTIPLY:
res[0] = (dest[0] * src.red) >> 8;
res[1] = (dest[1] * src.green) >> 8;
res[2] = (dest[2] * src.blue) >> 8;
break;
default:
LV_LOG_WARN("Not supported blend mode: %d", mode);
return;
}
lv_color_24_24_mix(res, dest, src.alpha);
}
LV_ATTRIBUTE_FAST_MEM static inline void lv_color_24_24_mix(const uint8_t * src, uint8_t * dest, uint8_t mix)
{
if(mix == 0) return;
// dest[0] = 0xff;
// dest[1] = 0x00;
// dest[2] = 0x00;
// return;
if(mix >= LV_OPA_MAX) {
dest[0] = src[0];
dest[1] = src[1];
dest[2] = src[2];
}
else {
lv_opa_t mix_inv = 255 - mix;
dest[0] = (uint32_t)((uint32_t)src[0] * mix + dest[0] * mix_inv) >> 8;
dest[1] = (uint32_t)((uint32_t)src[1] * mix + dest[1] * mix_inv) >> 8;
dest[2] = (uint32_t)((uint32_t)src[2] * mix + dest[2] * mix_inv) >> 8;
}
}
#endif
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/sw/blend | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/sw/blend/neon/lv_blend_to_rgb888_neon.h | /**
* @file lv_blend_to_rgb888_neon.h
*
*/
#ifndef LV_BLEND_TO_RGB888_NEON_H
#define LV_BLEND_TO_RGB888_NEON_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include <stdint.h>
#if LV_DRAW_SW_ASM_NEON
/*********************
* DEFINES
*********************/
#define LV_DRAW_SW_COLOR_BLEND_TO_RGB888(dsc, px_size) \
_lv_color_blend_to_rgb888_neon(dsc, px_size)
#define LV_DRAW_SW_COLOR_BLEND_TO_RGB888_WITH_OPA(dsc, px_size) \
_lv_color_blend_to_rgb888_with_opa_neon(dsc, px_size)
#define LV_DRAW_SW_COLOR_BLEND_TO_RGB888_WITH_MASK(dsc, px_size) \
_lv_color_blend_to_rgb888_with_mask_neon(dsc, px_size)
#define LV_DRAW_SW_COLOR_BLEND_TO_RGB888_MIX_MASK_OPA(dsc, px_size) \
_lv_color_blend_to_rgb888_mix_mask_opa_neon(dsc, px_size)
#define LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB888(dsc, px_size) \
_lv_argb8888_blend_normal_to_rgb888_neon(dsc, px_size)
#define LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB888_WITH_OPA(dsc, px_size) \
_lv_argb8888_blend_normal_to_rgb888_with_opa_neon(dsc, px_size)
#define LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB888_WITH_MASK(dsc, px_size) \
_lv_argb8888_blend_normal_to_rgb888_with_mask_neon(dsc, px_size)
#define LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB888_MIX_MASK_OPA(dsc, px_size) \
_lv_argb8888_blend_normal_to_rgb888_mix_mask_opa_neon(dsc, px_size)
/*
d26 ~ d29 is the source pixel (color or img)
d18 ~ d21 is the dest pixel
d17 is the inverse opa
d16 = 255
q0 ~ q2 is the premult src color
*/
#define SRC_PREMULT_8_PIXEL_NEON(opa) \
"vmull.u8 q0, d26, "#opa" \n" /* sb * opa */ \
"vmull.u8 q1, d27, "#opa" \n" /* sg * opa */ \
"vmull.u8 q2, d28, "#opa" \n" /* sr * opa */
#define SRC_PREMULT_8_PIXEL_INV_OPA_NEON(opa) \
"vsub.u8 d17, d16, "#opa" \n" /* inv opa */ \
"vmull.u8 q0, d26, "#opa" \n" /* sb * opa */ \
"vmull.u8 q1, d27, "#opa" \n" /* sg * opa */ \
"vmull.u8 q2, d28, "#opa" \n" /* sr * opa */
#define SRC_OVER_8_PIXEL_NEON \
"vmull.u8 q12, d20, d17 \n" /* dr * inv_a */ \
"vmull.u8 q11, d19, d17 \n" /* dg * inv_a */ \
"vmull.u8 q10, d18, d17 \n" /* db * inv_a */ \
"vqadd.u16 q10, q10, q0 \n" /* (premult b) + (db * inv_a) */ \
"vqadd.u16 q11, q11, q1 \n" /* (premult g) + (dg * inv_a) */ \
"vqadd.u16 q12, q12, q2 \n" /* (premult r) + (dr * inv_a) */ \
"vqrshrn.u16 d18, q10, #8 \n" /* db >>= 8 */ \
"vqrshrn.u16 d19, q11, #8 \n" /* dg >>= 8 */ \
"vqrshrn.u16 d20, q12, #8 \n" /* dr >>= 8 */ \
"vmov.u8 d21, #255 \n"
#define SRC_OVER_8_PIXEL_COVER_NEON \
"vmlal.u8 q0, d18, d17 \n" /* (premult b) + (db * inv_a) */ \
"vmlal.u8 q1, d19, d17 \n" /* (premult g) + (dg * inv_a) */ \
"vmlal.u8 q2, d20, d17 \n" /* (premult r) + (dr * inv_a) */ \
"vqrshrn.u16 d18, q0, #8 \n" /* db >>= 8 */ \
"vqrshrn.u16 d19, q1, #8 \n" /* dg >>= 8 */ \
"vqrshrn.u16 d20, q2, #8 \n" /* dr >>= 8 */ \
#define LOAD_8_XRGB8888_FROM_SRC \
"vld4.u8 {d26, d27, d28, d29}, [%[src]]! \n"
#define LOAD_8_XRGB8888_FROM_DST \
"vld4.u8 {d18, d19, d20, d21}, [r4]! \n"
#define STORE_8_XRGB8888_TO_DST \
"vst4.u8 {d18, d19, d20, d21}, [%[dst]]! \n"
#define LOAD_8_RGB888_FROM_DST \
"vld3.u8 {d18, d19, d20}, [r4]! \n"
#define STORE_8_RGB888_TO_DST \
"vst3.u8 {d18, d19, d20}, [%[dst]]! \n"
#define LOAD_4_XRGB8888_FROM_SRC \
"vld4.u8 {d26[0], d27[0], d28[0], d29[0]}, [%[src]]! \n" \
"vld4.u8 {d26[1], d27[1], d28[1], d29[1]}, [%[src]]! \n" \
"vld4.u8 {d26[2], d27[2], d28[2], d29[2]}, [%[src]]! \n" \
"vld4.u8 {d26[3], d27[3], d28[3], d29[3]}, [%[src]]! \n"
#define LOAD_4_XRGB8888_FROM_DST \
"vld4.u8 {d18[0], d19[0], d20[0], d21[0]}, [r4]! \n" \
"vld4.u8 {d18[1], d19[1], d20[1], d21[1]}, [r4]! \n" \
"vld4.u8 {d18[2], d19[2], d20[2], d21[2]}, [r4]! \n" \
"vld4.u8 {d18[3], d19[3], d20[3], d21[3]}, [r4]! \n"
#define STORE_4_XRGB8888_TO_DST \
"vst4.u8 {d18[0], d19[0], d20[0], d21[0]}, [%[dst]]! \n" \
"vst4.u8 {d18[1], d19[1], d20[1], d21[1]}, [%[dst]]! \n" \
"vst4.u8 {d18[2], d19[2], d20[2], d21[2]}, [%[dst]]! \n" \
"vst4.u8 {d18[3], d19[3], d20[3], d21[3]}, [%[dst]]! \n"
#define LOAD_4_RGB888_FROM_DST \
"vld3.u8 {d18[0], d19[0], d20[0]}, [r4]! \n" \
"vld3.u8 {d18[1], d19[1], d20[1]}, [r4]! \n" \
"vld3.u8 {d18[2], d19[2], d20[2]}, [r4]! \n" \
"vld3.u8 {d18[3], d19[3], d20[3]}, [r4]! \n"
#define STORE_4_RGB888_TO_DST \
"vst3.u8 {d18[0], d19[0], d20[0]}, [%[dst]]! \n" \
"vst3.u8 {d18[1], d19[1], d20[1]}, [%[dst]]! \n" \
"vst3.u8 {d18[2], d19[2], d20[2]}, [%[dst]]! \n" \
"vst3.u8 {d18[3], d19[3], d20[3]}, [%[dst]]! \n"
#define LOAD_2_XRGB8888_FROM_SRC \
"vld4.u8 {d26[0], d27[0], d28[0], d29[0]}, [%[src]]! \n" \
"vld4.u8 {d26[1], d27[1], d28[1], d29[1]}, [%[src]]! \n"
#define LOAD_2_XRGB8888_FROM_DST \
"vld4.u8 {d18[0], d19[0], d20[0], d21[0]}, [r4]! \n" \
"vld4.u8 {d18[1], d19[1], d20[1], d21[1]}, [r4]! \n"
#define STORE_2_XRGB8888_TO_DST \
"vst4.u8 {d18[0], d19[0], d20[0], d21[0]}, [%[dst]]! \n" \
"vst4.u8 {d18[1], d19[1], d20[1], d21[1]}, [%[dst]]! \n"
#define LOAD_2_RGB888_FROM_DST \
"vld3.u8 {d18[0], d19[0], d20[0]}, [r4]! \n" \
"vld3.u8 {d18[1], d19[1], d20[1]}, [r4]! \n"
#define STORE_2_RGB888_TO_DST \
"vst3.u8 {d18[0], d19[0], d20[0]}, [%[dst]]! \n" \
"vst3.u8 {d18[1], d19[1], d20[1]}, [%[dst]]! \n"
#define LOAD_1_XRGB8888_FROM_SRC \
"vld4.u8 {d26[0], d27[0], d28[0], d29[0]}, [%[src]]! \n"
#define LOAD_1_XRGB8888_FROM_DST \
"vld4.u8 {d18[0], d19[0], d20[0], d21[0]}, [r4]! \n"
#define STORE_1_XRGB8888_TO_DST \
"vst4.u8 {d18[0], d19[0], d20[0], d21[0]}, [%[dst]]! \n"
#define LOAD_1_RGB888_FROM_DST \
"vld3.u8 {d18[0], d19[0], d20[0]}, [r4]! \n"
#define STORE_1_RGB888_TO_DST \
"vst3.u8 {d18[0], d19[0], d20[0]}, [%[dst]]! \n"
#define LOAD_8_MASK(res) \
"vld1.u8 {"#res"}, [%[mask]]! \n"
#define LOAD_4_MASK(res) \
"vld1.u8 {"#res"[0]}, [%[mask]]! \n" \
"vld1.u8 {"#res"[1]}, [%[mask]]! \n" \
"vld1.u8 {"#res"[2]}, [%[mask]]! \n" \
"vld1.u8 {"#res"[3]}, [%[mask]]! \n"
#define LOAD_2_MASK(res) \
"vld1.u8 {"#res"[0]}, [%[mask]]! \n" \
"vld1.u8 {"#res"[1]}, [%[mask]]! \n"
#define LOAD_1_MASK(res) \
"vld1.u8 {"#res"[0]}, [%[mask]]! \n"
#define MIX_OPA_2(opa1, opa2, res) \
"vmull.u8 q0, "#opa1", "#opa2" \n" /* sa * opa */ \
"vqrshrn.u16 "#res", q0, #8 \n" /* (sa * opa) >>= 8 */
#define MIX_OPA_3(opa1, opa2, opa3, res) \
"vmull.u8 q0, "#opa1", "#opa2" \n" /* sa * opa */ \
"vqrshrn.u16 "#res", q0, #8 \n" /* (sa * opa) >>= 8 */ \
"vmull.u8 q0, "#opa3", "#res" \n" /* sa * opa */ \
"vqrshrn.u16 "#res", q0, #8 \n" /* (sa * opa) >>= 8 */
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
static inline void lv_color_blend_to_rgb888_neon
(uint8_t * pcolor, uint8_t * dst, int32_t w, int32_t h, uint32_t dst_lineskip)
{
asm volatile(
"vld3.u8 {d0[], d1[], d2[]}, [%[pcolor]] \n"
"0: \n"
"movs ip, %[w], lsr #3 \n"
"beq 4f \n"
"8: \n"
"subs ip, ip, #1 \n"
"vst3.u8 {d0, d1, d2}, [%[dst]]! \n"
"bgt 8b \n"
"4: \n"
"ands ip, %[w], #4 \n"
"beq 2f \n"
"vst3.u8 {d0[0], d1[0], d2[0]}, [%[dst]]! \n"
"vst3.u8 {d0[0], d1[0], d2[0]}, [%[dst]]! \n"
"vst3.u8 {d0[0], d1[0], d2[0]}, [%[dst]]! \n"
"vst3.u8 {d0[0], d1[0], d2[0]}, [%[dst]]! \n"
"2: \n"
"ands ip, %[w], #2 \n"
"beq 1f \n"
"vst3.u8 {d0[0], d1[0], d2[0]}, [%[dst]]! \n"
"vst3.u8 {d0[0], d1[0], d2[0]}, [%[dst]]! \n"
"1: \n"
"ands ip, %[w], #1 \n"
"beq 99f \n"
"vst3.u8 {d0[0], d1[0], d2[0]}, [%[dst]]! \n"
"99: \n"
"subs %[h], %[h], #1 \n"
"add %[dst], %[dst], %[d_lineskip] \n"
"bgt 0b \n"
: [dst] "+r"(dst),
[h] "+r"(h)
: [pcolor] "r"(pcolor),
[w] "r"(w),
[d_lineskip] "r"(dst_lineskip)
: "cc", "memory", "q0", "q1", "ip");
}
static inline void lv_color_blend_to_xrgb8888_neon
(uint8_t * pcolor, uint8_t * dst, int32_t w, int32_t h, uint32_t dst_lineskip)
{
asm volatile(
"vld1.u32 {d0[]}, [%[pcolor]] \n"
"vld1.u32 {d1[]}, [%[pcolor]] \n"
"vld1.u32 {d2[]}, [%[pcolor]] \n"
"vld1.u32 {d3[]}, [%[pcolor]] \n"
"0: \n"
"movs ip, %[w], lsr #3 \n"
"beq 4f \n"
"8: \n"
"subs ip, ip, #1 \n"
"vst4.u32 {d0-d3}, [%[dst]]! \n"
"bgt 8b \n"
"4: \n"
"ands ip, %[w], #4 \n"
"beq 2f \n"
"vst2.u32 {d0, d1}, [%[dst]]! \n"
"2: \n"
"ands ip, %[w], #2 \n"
"beq 1f \n"
"vst1.u32 {d0}, [%[dst]]! \n"
"1: \n"
"ands ip, %[w], #1 \n"
"beq 99f \n"
"vst1.u32 {d0[0]}, [%[dst]]! \n"
"99: \n"
"subs %[h], %[h], #1 \n"
"add %[dst], %[dst], %[d_lineskip] \n"
"bgt 0b \n"
: [dst] "+r"(dst),
[h] "+r"(h)
: [pcolor] "r"(pcolor),
[w] "r"(w),
[d_lineskip] "r"(dst_lineskip)
: "cc", "memory", "q0", "q1", "ip");
}
static inline void lv_color_blend_to_rgb888_with_opa_neon
(uint8_t * pcolor, uint8_t * dst, int32_t w, int32_t h, uint8_t opa, uint32_t dst_lineskip)
{
asm volatile(
"vmov.u8 d16, #255 \n" /* a = 255 */
"vld3.u8 {d26[], d27[], d28[]}, [%[pcolor]] \n"
"vdup.u8 d29, %[opa] \n"
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
"0: \n"
"movs ip, %[w], lsr #3 \n"
"mov r4, %[dst] \n"
"beq 4f \n"
"8: \n"
"subs ip, ip, #1 \n"
LOAD_8_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_8_RGB888_TO_DST
"bgt 8b \n"
"4: \n"
"ands ip, %[w], #4 \n"
"beq 2f \n"
LOAD_4_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_4_RGB888_TO_DST
"2: \n"
"ands ip, %[w], #2 \n"
"beq 1f \n"
LOAD_2_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_2_RGB888_TO_DST
"1: \n"
"ands ip, %[w], #1 \n"
"beq 99f \n"
LOAD_1_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_1_RGB888_TO_DST
"99: \n"
"subs %[h], %[h], #1 \n"
"add %[dst], %[dst], %[d_lineskip] \n"
"bgt 0b \n"
: [dst] "+r"(dst),
[h] "+r"(h)
: [pcolor] "r"(pcolor),
[opa] "r"(opa),
[w] "r"(w),
[d_lineskip] "r"(dst_lineskip)
: "cc", "memory", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15", "r4", "ip");
}
static inline void lv_color_blend_to_xrgb8888_with_opa_neon
(uint8_t * pcolor, uint8_t * dst, int32_t w, int32_t h, uint8_t opa, uint32_t dst_lineskip)
{
asm volatile(
"vmov.u8 d16, #255 \n" /* a = 255 */
"vld3.u8 {d26[], d27[], d28[]}, [%[pcolor]] \n"
"vdup.u8 d29, %[opa] \n"
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
"0: \n"
"movs ip, %[w], lsr #3 \n"
"mov r4, %[dst] \n"
"beq 4f \n"
"8: \n"
"subs ip, ip, #1 \n"
LOAD_8_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_8_XRGB8888_TO_DST
"bgt 8b \n"
"4: \n"
"ands ip, %[w], #4 \n"
"beq 2f \n"
LOAD_4_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_4_XRGB8888_TO_DST
"2: \n"
"ands ip, %[w], #2 \n"
"beq 1f \n"
LOAD_2_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_2_XRGB8888_TO_DST
"1: \n"
"ands ip, %[w], #1 \n"
"beq 99f \n"
LOAD_1_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_1_XRGB8888_TO_DST
"99: \n"
"subs %[h], %[h], #1 \n"
"add %[dst], %[dst], %[d_lineskip] \n"
"bgt 0b \n"
: [dst] "+r"(dst),
[h] "+r"(h)
: [pcolor] "r"(pcolor),
[opa] "r"(opa),
[w] "r"(w),
[d_lineskip] "r"(dst_lineskip)
: "cc", "memory", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15", "r4", "ip");
}
static inline void lv_color_blend_to_rgb888_with_mask_neon
(uint8_t * pcolor, uint8_t * dst, int32_t w, int32_t h, uint8_t * mask, uint32_t dst_lineskip, uint32_t mask_lineskip)
{
asm volatile(
"vmov.u8 d16, #255 \n" /* a = 255 */
"vld3.u8 {d26[], d27[], d28[]}, [%[pcolor]] \n"
"0: \n"
"movs ip, %[w], lsr #3 \n"
"mov r4, %[dst] \n"
"beq 4f \n"
"8: \n"
"subs ip, ip, #1 \n"
LOAD_8_MASK(d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_8_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_8_RGB888_TO_DST
"bgt 8b \n"
"4: \n"
"ands ip, %[w], #4 \n"
"beq 2f \n"
LOAD_4_MASK(d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_4_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_4_RGB888_TO_DST
"2: \n"
"ands ip, %[w], #2 \n"
"beq 1f \n"
LOAD_2_MASK(d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_2_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_2_RGB888_TO_DST
"1: \n"
"ands ip, %[w], #1 \n"
"beq 99f \n"
LOAD_1_MASK(d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_1_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_1_RGB888_TO_DST
"99: \n"
"subs %[h], %[h], #1 \n"
"add %[dst], %[dst], %[d_lineskip] \n"
"add %[mask], %[mask], %[m_lineskip] \n"
"bgt 0b \n"
: [dst] "+r"(dst),
[mask] "+r"(mask),
[h] "+r"(h)
: [pcolor] "r"(pcolor),
[w] "r"(w),
[d_lineskip] "r"(dst_lineskip),
[m_lineskip] "r"(mask_lineskip)
: "cc", "memory", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15", "r4", "ip");
}
static inline void lv_color_blend_to_xrgb8888_with_mask_neon
(uint8_t * pcolor, uint8_t * dst, int32_t w, int32_t h, uint8_t * mask, uint32_t dst_lineskip, uint32_t mask_lineskip)
{
asm volatile(
"vmov.u8 d16, #255 \n" /* a = 255 */
"vld3.u8 {d26[], d27[], d28[]}, [%[pcolor]] \n"
"0: \n"
"movs ip, %[w], lsr #3 \n"
"mov r4, %[dst] \n"
"beq 4f \n"
"8: \n"
"subs ip, ip, #1 \n"
LOAD_8_MASK(d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_8_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_8_XRGB8888_TO_DST
"bgt 8b \n"
"4: \n"
"ands ip, %[w], #4 \n"
"beq 2f \n"
LOAD_4_MASK(d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_4_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_4_XRGB8888_TO_DST
"2: \n"
"ands ip, %[w], #2 \n"
"beq 1f \n"
LOAD_2_MASK(d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_2_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_2_XRGB8888_TO_DST
"1: \n"
"ands ip, %[w], #1 \n"
"beq 99f \n"
LOAD_1_MASK(d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_1_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_1_XRGB8888_TO_DST
"99: \n"
"subs %[h], %[h], #1 \n"
"add %[dst], %[dst], %[d_lineskip] \n"
"add %[mask], %[mask], %[m_lineskip] \n"
"bgt 0b \n"
: [dst] "+r"(dst),
[mask] "+r"(mask),
[h] "+r"(h)
: [pcolor] "r"(pcolor),
[w] "r"(w),
[d_lineskip] "r"(dst_lineskip),
[m_lineskip] "r"(mask_lineskip)
: "cc", "memory", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15", "r4", "ip");
}
static inline void lv_color_blend_to_rgb888_mix_mask_opa_neon
(uint8_t * pcolor, uint8_t * dst, int32_t w, int32_t h, uint8_t * mask, uint8_t opa, uint32_t dst_lineskip,
uint32_t mask_lineskip)
{
asm volatile(
"vmov.u8 d16, #255 \n" /* a = 255 */
"vld3.u8 {d26[], d27[], d28[]}, [%[pcolor]] \n"
"vdup.u8 d30, %[opa] \n"
"0: \n"
"movs ip, %[w], lsr #3 \n"
"mov r4, %[dst] \n"
"beq 4f \n"
"8: \n"
"subs ip, ip, #1 \n"
LOAD_8_MASK(d29)
MIX_OPA_2(d29, d30, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_8_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_8_RGB888_TO_DST
"bgt 8b \n"
"4: \n"
"ands ip, %[w], #4 \n"
"beq 2f \n"
LOAD_4_MASK(d29)
MIX_OPA_2(d29, d30, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_4_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_4_RGB888_TO_DST
"2: \n"
"ands ip, %[w], #2 \n"
"beq 1f \n"
LOAD_2_MASK(d29)
MIX_OPA_2(d29, d30, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_2_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_2_RGB888_TO_DST
"1: \n"
"ands ip, %[w], #1 \n"
"beq 99f \n"
LOAD_1_MASK(d29)
MIX_OPA_2(d29, d30, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_1_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_1_RGB888_TO_DST
"99: \n"
"subs %[h], %[h], #1 \n"
"add %[dst], %[dst], %[d_lineskip] \n"
"add %[mask], %[mask], %[m_lineskip] \n"
"bgt 0b \n"
: [dst] "+r"(dst),
[mask] "+r"(mask),
[h] "+r"(h)
: [pcolor] "r"(pcolor),
[w] "r"(w),
[opa] "r"(opa),
[d_lineskip] "r"(dst_lineskip),
[m_lineskip] "r"(mask_lineskip)
: "cc", "memory", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15", "r4", "ip"
);
}
static inline void lv_color_blend_to_xrgb8888_mix_mask_opa_neon
(uint8_t * pcolor, uint8_t * dst, int32_t w, int32_t h, uint8_t * mask, uint8_t opa, uint32_t dst_lineskip,
uint32_t mask_lineskip)
{
asm volatile(
"vmov.u8 d16, #255 \n" /* a = 255 */
"vld3.u8 {d26[], d27[], d28[]}, [%[pcolor]] \n"
"vdup.u8 d30, %[opa] \n"
"0: \n"
"movs ip, %[w], lsr #3 \n"
"mov r4, %[dst] \n"
"beq 4f \n"
"8: \n"
"subs ip, ip, #1 \n"
LOAD_8_MASK(d29)
MIX_OPA_2(d29, d30, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_8_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_8_XRGB8888_TO_DST
"bgt 8b \n"
"4: \n"
"ands ip, %[w], #4 \n"
"beq 2f \n"
LOAD_4_MASK(d29)
MIX_OPA_2(d29, d30, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_4_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_4_XRGB8888_TO_DST
"2: \n"
"ands ip, %[w], #2 \n"
"beq 1f \n"
LOAD_2_MASK(d29)
MIX_OPA_2(d29, d30, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_2_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_2_XRGB8888_TO_DST
"1: \n"
"ands ip, %[w], #1 \n"
"beq 99f \n"
LOAD_1_MASK(d29)
MIX_OPA_2(d29, d30, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_1_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_1_XRGB8888_TO_DST
"99: \n"
"subs %[h], %[h], #1 \n"
"add %[dst], %[dst], %[d_lineskip] \n"
"add %[mask], %[mask], %[m_lineskip] \n"
"bgt 0b \n"
: [dst] "+r"(dst),
[mask] "+r"(mask),
[h] "+r"(h)
: [pcolor] "r"(pcolor),
[w] "r"(w),
[opa] "r"(opa),
[d_lineskip] "r"(dst_lineskip),
[m_lineskip] "r"(mask_lineskip)
: "cc", "memory", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15", "r4", "ip"
);
}
static inline void lv_argb8888_blend_normal_to_rgb888_neon
(uint8_t * src, uint8_t * dst, int32_t w, int32_t h, uint32_t dst_lineskip, uint32_t src_lineskip)
{
asm volatile(
"vmov.u8 d16, #255 \n" /* a = 255 */
"0: \n"
"movs ip, %[w], lsr #3 \n"
"mov r4, %[dst] \n"
"beq 4f \n"
"8: \n"
"subs ip, ip, #1 \n"
LOAD_8_XRGB8888_FROM_SRC
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_8_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_8_RGB888_TO_DST
"bgt 8b \n"
"4: \n"
"ands ip, %[w], #4 \n"
"beq 2f \n"
LOAD_4_XRGB8888_FROM_SRC
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_4_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_4_RGB888_TO_DST
"2: \n"
"ands ip, %[w], #2 \n"
"beq 1f \n"
LOAD_2_XRGB8888_FROM_SRC
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_2_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_2_RGB888_TO_DST
"1: \n"
"ands ip, %[w], #1 \n"
"beq 99f \n"
LOAD_1_XRGB8888_FROM_SRC
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_1_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_1_RGB888_TO_DST
"99: \n"
"subs %[h], %[h], #1 \n"
"add %[dst], %[dst], %[d_lineskip] \n"
"add %[src], %[src], %[s_lineskip] \n"
"bgt 0b \n"
: [dst] "+r"(dst),
[src] "+r"(src),
[h] "+r"(h)
:[w] "r"(w),
[d_lineskip] "r"(dst_lineskip),
[s_lineskip] "r"(src_lineskip)
: "cc", "memory", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15", "r4", "ip");
}
static inline void lv_argb8888_blend_normal_to_xrgb8888_neon
(uint8_t * src, uint8_t * dst, int32_t w, int32_t h, uint32_t dst_lineskip, uint32_t src_lineskip)
{
asm volatile(
"vmov.u8 d16, #255 \n" /* a = 255 */
"0: \n"
"movs ip, %[w], lsr #3 \n"
"mov r4, %[dst] \n"
"beq 4f \n"
"8: \n"
"subs ip, ip, #1 \n"
LOAD_8_XRGB8888_FROM_SRC
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_8_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_8_XRGB8888_TO_DST
"bgt 8b \n"
"4: \n"
"ands ip, %[w], #4 \n"
"beq 2f \n"
LOAD_4_XRGB8888_FROM_SRC
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_4_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_4_XRGB8888_TO_DST
"2: \n"
"ands ip, %[w], #2 \n"
"beq 1f \n"
LOAD_2_XRGB8888_FROM_SRC
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_2_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_2_XRGB8888_TO_DST
"1: \n"
"ands ip, %[w], #1 \n"
"beq 99f \n"
LOAD_1_XRGB8888_FROM_SRC
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_1_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_1_XRGB8888_TO_DST
"99: \n"
"subs %[h], %[h], #1 \n"
"add %[dst], %[dst], %[d_lineskip] \n"
"add %[src], %[src], %[s_lineskip] \n"
"bgt 0b \n"
: [dst] "+r"(dst),
[src] "+r"(src),
[h] "+r"(h)
:[w] "r"(w),
[d_lineskip] "r"(dst_lineskip),
[s_lineskip] "r"(src_lineskip)
: "cc", "memory", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15", "r4", "ip");
}
static inline void lv_argb8888_blend_normal_to_rgb888_with_opa_neon
(uint8_t * src, uint8_t * dst, int32_t w, int32_t h, uint8_t opa, uint32_t dst_lineskip, uint32_t src_lineskip)
{
asm volatile(
"vmov.u8 d16, #255 \n" /* a = 255 */
"vdup.u8 d30, %[opa] \n"
"0: \n"
"movs ip, %[w], lsr #3 \n"
"mov r4, %[dst] \n"
"beq 4f \n"
"8: \n"
"subs ip, ip, #1 \n"
LOAD_8_XRGB8888_FROM_SRC
MIX_OPA_2(d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_8_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_8_RGB888_TO_DST
"bgt 8b \n"
"4: \n"
"ands ip, %[w], #4 \n"
"beq 2f \n"
LOAD_4_XRGB8888_FROM_SRC
MIX_OPA_2(d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_4_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_4_RGB888_TO_DST
"2: \n"
"ands ip, %[w], #2 \n"
"beq 1f \n"
LOAD_2_XRGB8888_FROM_SRC
MIX_OPA_2(d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_2_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_2_RGB888_TO_DST
"1: \n"
"ands ip, %[w], #1 \n"
"beq 99f \n"
LOAD_1_XRGB8888_FROM_SRC
MIX_OPA_2(d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d30)
LOAD_1_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_1_RGB888_TO_DST
"99: \n"
"subs %[h], %[h], #1 \n"
"add %[dst], %[dst], %[d_lineskip] \n"
"add %[src], %[src], %[s_lineskip] \n"
"bgt 0b \n"
: [dst] "+r"(dst),
[src] "+r"(src),
[h] "+r"(h)
:[w] "r"(w),
[opa] "r"(opa),
[d_lineskip] "r"(dst_lineskip),
[s_lineskip] "r"(src_lineskip)
: "cc", "memory", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15", "r4", "ip");
}
static inline void lv_argb8888_blend_normal_to_xrgb8888_with_opa_neon
(uint8_t * src, uint8_t * dst, int32_t w, int32_t h, uint8_t opa, uint32_t dst_lineskip, uint32_t src_lineskip)
{
asm volatile(
"vmov.u8 d16, #255 \n" /* a = 255 */
"vdup.u8 d30, %[opa] \n"
"0: \n"
"movs ip, %[w], lsr #3 \n"
"mov r4, %[dst] \n"
"beq 4f \n"
"8: \n"
"subs ip, ip, #1 \n"
LOAD_8_XRGB8888_FROM_SRC
MIX_OPA_2(d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_8_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_8_XRGB8888_TO_DST
"bgt 8b \n"
"4: \n"
"ands ip, %[w], #4 \n"
"beq 2f \n"
LOAD_4_XRGB8888_FROM_SRC
MIX_OPA_2(d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_4_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_4_XRGB8888_TO_DST
"2: \n"
"ands ip, %[w], #2 \n"
"beq 1f \n"
LOAD_2_XRGB8888_FROM_SRC
MIX_OPA_2(d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_2_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_2_XRGB8888_TO_DST
"1: \n"
"ands ip, %[w], #1 \n"
"beq 99f \n"
LOAD_1_XRGB8888_FROM_SRC
MIX_OPA_2(d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_1_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_1_XRGB8888_TO_DST
"99: \n"
"subs %[h], %[h], #1 \n"
"add %[dst], %[dst], %[d_lineskip] \n"
"add %[src], %[src], %[s_lineskip] \n"
"bgt 0b \n"
: [dst] "+r"(dst),
[src] "+r"(src),
[h] "+r"(h)
:[w] "r"(w),
[opa] "r"(opa),
[d_lineskip] "r"(dst_lineskip),
[s_lineskip] "r"(src_lineskip)
: "cc", "memory", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15", "r4", "ip");
}
static inline void lv_argb8888_blend_normal_to_rgb888_with_mask_neon(uint8_t * src, uint8_t * dst, int32_t w, int32_t h,
uint8_t * mask, uint32_t dst_lineskip, uint32_t src_lineskip, uint32_t mask_lineskip)
{
asm volatile(
"vmov.u8 d16, #255 \n" /* a = 255 */
"0: \n"
"movs ip, %[w], lsr #3 \n"
"mov r4, %[dst] \n"
"beq 4f \n"
"8: \n"
"subs ip, ip, #1 \n"
LOAD_8_XRGB8888_FROM_SRC
LOAD_8_MASK(d30)
MIX_OPA_2(d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_8_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_8_RGB888_TO_DST
"bgt 8b \n"
"4: \n"
"ands ip, %[w], #4 \n"
"beq 2f \n"
LOAD_4_XRGB8888_FROM_SRC
LOAD_4_MASK(d30)
MIX_OPA_2(d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_4_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_4_RGB888_TO_DST
"2: \n"
"ands ip, %[w], #2 \n"
"beq 1f \n"
LOAD_2_XRGB8888_FROM_SRC
LOAD_2_MASK(d30)
MIX_OPA_2(d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_2_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_2_RGB888_TO_DST
"1: \n"
"ands ip, %[w], #1 \n"
"beq 99f \n"
LOAD_1_XRGB8888_FROM_SRC
LOAD_1_MASK(d30)
MIX_OPA_2(d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_1_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_1_RGB888_TO_DST
"99: \n"
"subs %[h], %[h], #1 \n"
"add %[dst], %[dst], %[d_lineskip] \n"
"add %[src], %[src], %[s_lineskip] \n"
"add %[mask], %[mask], %[m_lineskip] \n"
"bgt 0b \n"
: [dst] "+r"(dst),
[src] "+r"(src),
[mask] "+r"(mask),
[h] "+r"(h)
:[w] "r"(w),
[d_lineskip] "r"(dst_lineskip),
[s_lineskip] "r"(src_lineskip),
[m_lineskip] "r"(mask_lineskip)
: "cc", "memory", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15", "r4", "ip");
}
static inline void lv_argb8888_blend_normal_to_xrgb8888_with_mask_neon(uint8_t * src, uint8_t * dst, int32_t w,
int32_t h,
uint8_t * mask, uint32_t dst_lineskip, uint32_t src_lineskip, uint32_t mask_lineskip)
{
asm volatile(
"vmov.u8 d16, #255 \n" /* a = 255 */
"0: \n"
"movs ip, %[w], lsr #3 \n"
"mov r4, %[dst] \n"
"beq 4f \n"
"8: \n"
"subs ip, ip, #1 \n"
LOAD_8_XRGB8888_FROM_SRC
LOAD_8_MASK(d30)
MIX_OPA_2(d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_8_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_8_XRGB8888_TO_DST
"bgt 8b \n"
"4: \n"
"ands ip, %[w], #4 \n"
"beq 2f \n"
LOAD_4_XRGB8888_FROM_SRC
LOAD_4_MASK(d30)
MIX_OPA_2(d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_4_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_4_XRGB8888_TO_DST
"2: \n"
"ands ip, %[w], #2 \n"
"beq 1f \n"
LOAD_2_XRGB8888_FROM_SRC
LOAD_2_MASK(d30)
MIX_OPA_2(d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_2_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_2_XRGB8888_TO_DST
"1: \n"
"ands ip, %[w], #1 \n"
"beq 99f \n"
LOAD_1_XRGB8888_FROM_SRC
LOAD_1_MASK(d30)
MIX_OPA_2(d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_1_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_1_XRGB8888_TO_DST
"99: \n"
"subs %[h], %[h], #1 \n"
"add %[dst], %[dst], %[d_lineskip] \n"
"add %[src], %[src], %[s_lineskip] \n"
"add %[mask], %[mask], %[m_lineskip] \n"
"bgt 0b \n"
: [dst] "+r"(dst),
[src] "+r"(src),
[mask] "+r"(mask),
[h] "+r"(h)
:[w] "r"(w),
[d_lineskip] "r"(dst_lineskip),
[s_lineskip] "r"(src_lineskip),
[m_lineskip] "r"(mask_lineskip)
: "cc", "memory", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15", "r4", "ip");
}
static inline void lv_argb8888_blend_normal_to_rgb888_mix_mask_opa_neon(uint8_t * src, uint8_t * dst, int32_t w,
int32_t h,
uint8_t * mask, uint8_t opa, uint32_t dst_lineskip, uint32_t src_lineskip, uint32_t mask_lineskip)
{
asm volatile(
"vmov.u8 d16, #255 \n" /* a = 255 */
"vdup.u8 d30, %[opa] \n"
"0: \n"
"movs ip, %[w], lsr #3 \n"
"mov r4, %[dst] \n"
"beq 4f \n"
"8: \n"
"subs ip, ip, #1 \n"
LOAD_8_XRGB8888_FROM_SRC
LOAD_8_MASK(d31)
MIX_OPA_3(d31, d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_8_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_8_RGB888_TO_DST
"bgt 8b \n"
"4: \n"
"ands ip, %[w], #4 \n"
"beq 2f \n"
LOAD_4_XRGB8888_FROM_SRC
LOAD_4_MASK(d31)
MIX_OPA_3(d31, d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_4_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_4_RGB888_TO_DST
"2: \n"
"ands ip, %[w], #2 \n"
"beq 1f \n"
LOAD_2_XRGB8888_FROM_SRC
LOAD_2_MASK(d31)
MIX_OPA_3(d31, d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_2_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_2_RGB888_TO_DST
"1: \n"
"ands ip, %[w], #1 \n"
"beq 99f \n"
LOAD_1_XRGB8888_FROM_SRC
LOAD_1_MASK(d30)
MIX_OPA_3(d31, d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_1_RGB888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_1_RGB888_TO_DST
"99: \n"
"subs %[h], %[h], #1 \n"
"add %[dst], %[dst], %[d_lineskip] \n"
"add %[src], %[src], %[s_lineskip] \n"
"add %[mask], %[mask], %[m_lineskip] \n"
"bgt 0b \n"
: [dst] "+r"(dst),
[src] "+r"(src),
[mask] "+r"(mask),
[h] "+r"(h)
:[w] "r"(w),
[opa] "r"(opa),
[d_lineskip] "r"(dst_lineskip),
[s_lineskip] "r"(src_lineskip),
[m_lineskip] "r"(mask_lineskip)
: "cc", "memory", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15", "r4", "ip");
}
static inline void lv_argb8888_blend_normal_to_xrgb8888_mix_mask_opa_neon(uint8_t * src, uint8_t * dst, int32_t w,
int32_t h,
uint8_t * mask, uint8_t opa, uint32_t dst_lineskip, uint32_t src_lineskip, uint32_t mask_lineskip)
{
asm volatile(
"vmov.u8 d16, #255 \n" /* a = 255 */
"vdup.u8 d30, %[opa] \n"
"0: \n"
"movs ip, %[w], lsr #3 \n"
"mov r4, %[dst] \n"
"beq 4f \n"
"8: \n"
"subs ip, ip, #1 \n"
LOAD_8_XRGB8888_FROM_SRC
LOAD_8_MASK(d31)
MIX_OPA_3(d31, d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_8_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_8_XRGB8888_TO_DST
"bgt 8b \n"
"4: \n"
"ands ip, %[w], #4 \n"
"beq 2f \n"
LOAD_4_XRGB8888_FROM_SRC
LOAD_4_MASK(d31)
MIX_OPA_3(d31, d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_4_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_4_XRGB8888_TO_DST
"2: \n"
"ands ip, %[w], #2 \n"
"beq 1f \n"
LOAD_2_XRGB8888_FROM_SRC
LOAD_2_MASK(d31)
MIX_OPA_3(d31, d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_2_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_2_XRGB8888_TO_DST
"1: \n"
"ands ip, %[w], #1 \n"
"beq 99f \n"
LOAD_1_XRGB8888_FROM_SRC
LOAD_1_MASK(d31)
MIX_OPA_3(d31, d30, d29, d29)
SRC_PREMULT_8_PIXEL_INV_OPA_NEON(d29)
LOAD_1_XRGB8888_FROM_DST
SRC_OVER_8_PIXEL_NEON
STORE_1_XRGB8888_TO_DST
"99: \n"
"subs %[h], %[h], #1 \n"
"add %[dst], %[dst], %[d_lineskip] \n"
"add %[src], %[src], %[s_lineskip] \n"
"add %[mask], %[mask], %[m_lineskip] \n"
"bgt 0b \n"
: [dst] "+r"(dst),
[src] "+r"(src),
[mask] "+r"(mask),
[h] "+r"(h)
:[w] "r"(w),
[opa] "r"(opa),
[d_lineskip] "r"(dst_lineskip),
[s_lineskip] "r"(src_lineskip),
[m_lineskip] "r"(mask_lineskip)
: "cc", "memory", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15", "r4", "ip");
}
static inline void _lv_color_blend_to_rgb888_neon(_lv_draw_sw_blend_fill_dsc_t * dsc, uint32_t dest_px_size)
{
uint32_t color32 = lv_color_to_u32(dsc->color);
if(dest_px_size == 3) {
lv_color_blend_to_rgb888_neon((uint8_t *)&color32, dsc->dest_buf, dsc->dest_w, dsc->dest_h,
(dsc->dest_stride - dsc->dest_w) * dest_px_size);
}
if(dest_px_size == 4) {
lv_color_blend_to_xrgb8888_neon((uint8_t *)&color32, dsc->dest_buf, dsc->dest_w, dsc->dest_h,
(dsc->dest_stride - dsc->dest_w) * dest_px_size);
}
}
static inline void _lv_color_blend_to_rgb888_with_opa_neon(_lv_draw_sw_blend_fill_dsc_t * dsc, uint32_t dest_px_size)
{
if(dest_px_size == 3) {
lv_color_blend_to_rgb888_with_opa_neon((uint8_t *)&dsc->color, dsc->dest_buf, dsc->dest_w, dsc->dest_h, dsc->opa,
(dsc->dest_stride - dsc->dest_w) * dest_px_size);
}
if(dest_px_size == 4) {
lv_color_blend_to_xrgb8888_with_opa_neon((uint8_t *)&dsc->color, dsc->dest_buf, dsc->dest_w, dsc->dest_h, dsc->opa,
(dsc->dest_stride - dsc->dest_w) * dest_px_size);
}
}
static inline void _lv_color_blend_to_rgb888_with_mask_neon(_lv_draw_sw_blend_fill_dsc_t * dsc, uint32_t dest_px_size)
{
if(dest_px_size == 3) {
lv_color_blend_to_rgb888_with_mask_neon((uint8_t *)&dsc->color, dsc->dest_buf, dsc->dest_w, dsc->dest_h,
(uint8_t *)dsc->mask_buf,
(dsc->dest_stride - dsc->dest_w) * dest_px_size,
dsc->mask_stride - dsc->dest_w);
}
if(dest_px_size == 4) {
lv_color_blend_to_xrgb8888_with_mask_neon((uint8_t *)&dsc->color, dsc->dest_buf, dsc->dest_w, dsc->dest_h,
(uint8_t *)dsc->mask_buf,
(dsc->dest_stride - dsc->dest_w) * dest_px_size,
dsc->mask_stride - dsc->dest_w);
}
}
static inline void _lv_color_blend_to_rgb888_mix_mask_opa_neon(_lv_draw_sw_blend_fill_dsc_t * dsc,
uint32_t dest_px_size)
{
if(dest_px_size == 3) {
lv_color_blend_to_rgb888_mix_mask_opa_neon((uint8_t *)&dsc->color, dsc->dest_buf, dsc->dest_w, dsc->dest_h,
(uint8_t *)dsc->mask_buf, dsc->opa,
(dsc->dest_stride - dsc->dest_w) * dest_px_size,
dsc->mask_stride - dsc->dest_w);
}
if(dest_px_size == 4) {
lv_color_blend_to_xrgb8888_mix_mask_opa_neon((uint8_t *)&dsc->color, dsc->dest_buf, dsc->dest_w, dsc->dest_h,
(uint8_t *)dsc->mask_buf, dsc->opa,
(dsc->dest_stride - dsc->dest_w) * dest_px_size,
dsc->mask_stride - dsc->dest_w);
}
}
static inline void _lv_argb8888_blend_normal_to_rgb888_neon(_lv_draw_sw_blend_image_dsc_t * dsc, uint32_t dest_px_size)
{
if(dest_px_size == 3) {
lv_argb8888_blend_normal_to_rgb888_neon((uint8_t *)dsc->src_buf, dsc->dest_buf, dsc->dest_w, dsc->dest_h,
(dsc->dest_stride - dsc->dest_w) * dest_px_size,
(dsc->src_stride - dsc->dest_w) * 4);
}
if(dest_px_size == 4) {
lv_argb8888_blend_normal_to_xrgb8888_neon((uint8_t *)dsc->src_buf, dsc->dest_buf, dsc->dest_w, dsc->dest_h,
(dsc->dest_stride - dsc->dest_w) * dest_px_size,
(dsc->src_stride - dsc->dest_w) * 4);
}
}
static inline void _lv_argb8888_blend_normal_to_rgb888_with_opa_neon(_lv_draw_sw_blend_image_dsc_t * dsc,
uint32_t dest_px_size)
{
if(dest_px_size == 3) {
lv_argb8888_blend_normal_to_rgb888_with_opa_neon((uint8_t *)dsc->src_buf, dsc->dest_buf, dsc->dest_w, dsc->dest_h,
dsc->opa,
(dsc->dest_stride - dsc->dest_w) * dest_px_size,
(dsc->src_stride - dsc->dest_w) * 4);
}
if(dest_px_size == 4) {
lv_argb8888_blend_normal_to_xrgb8888_with_opa_neon((uint8_t *)dsc->src_buf, dsc->dest_buf, dsc->dest_w, dsc->dest_h,
dsc->opa,
(dsc->dest_stride - dsc->dest_w) * dest_px_size,
(dsc->src_stride - dsc->dest_w) * 4);
}
}
static inline void _lv_argb8888_blend_normal_to_rgb888_with_mask_neon(_lv_draw_sw_blend_image_dsc_t * dsc,
uint32_t dest_px_size)
{
if(dest_px_size == 3) {
lv_argb8888_blend_normal_to_rgb888_with_mask_neon((uint8_t *)dsc->src_buf, dsc->dest_buf, dsc->dest_w, dsc->dest_h,
(uint8_t *)dsc->mask_buf,
(dsc->dest_stride - dsc->dest_w) * dest_px_size,
(dsc->src_stride - dsc->dest_w) * 4,
dsc->mask_stride - dsc->dest_w);
}
if(dest_px_size == 4) {
lv_argb8888_blend_normal_to_xrgb8888_with_mask_neon((uint8_t *)dsc->src_buf, dsc->dest_buf, dsc->dest_w, dsc->dest_h,
(uint8_t *)dsc->mask_buf,
(dsc->dest_stride - dsc->dest_w) * dest_px_size,
(dsc->src_stride - dsc->dest_w) * 4,
dsc->mask_stride - dsc->dest_w);
}
}
static inline void _lv_argb8888_blend_normal_to_rgb888_mix_mask_opa_neon(_lv_draw_sw_blend_image_dsc_t * dsc,
uint32_t dest_px_size)
{
if(dest_px_size == 3) {
lv_argb8888_blend_normal_to_rgb888_mix_mask_opa_neon((uint8_t *)dsc->src_buf, dsc->dest_buf, dsc->dest_w, dsc->dest_h,
(uint8_t *)dsc->mask_buf, dsc->opa,
(dsc->dest_stride - dsc->dest_w) * dest_px_size,
(dsc->src_stride - dsc->dest_w) * 4,
dsc->mask_stride - dsc->dest_w);
}
if(dest_px_size == 4) {
lv_argb8888_blend_normal_to_xrgb8888_mix_mask_opa_neon((uint8_t *)dsc->src_buf, dsc->dest_buf, dsc->dest_w, dsc->dest_h,
(uint8_t *)dsc->mask_buf, dsc->opa,
(dsc->dest_stride - dsc->dest_w) * dest_px_size,
(dsc->src_stride - dsc->dest_w) * 4,
dsc->mask_stride - dsc->dest_w);
}
}
/**********************
* MACROS
**********************/
#endif /*LV_DRAW_SW_ASM_NEON*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_BLEND_TO_RGB888_NEON_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/pxp/lv_draw_pxp_layer.c | /**
* @file lv_draw_pxp_layer.c
*
*/
/**
* Copyright 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_pxp.h"
#if LV_USE_DRAW_PXP
#include "../../../stdlib/lv_string.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_pxp_layer(lv_draw_unit_t * draw_unit, const lv_draw_image_dsc_t * draw_dsc,
const lv_area_t * coords)
{
lv_layer_t * layer_to_draw = (lv_layer_t *)draw_dsc->src;
/*It can happen that nothing was draw on a layer and therefore its buffer is not allocated.
*In this case just return. */
if(layer_to_draw->draw_buf.buf == NULL)
return;
lv_image_dsc_t img_dsc;
img_dsc.header.w = layer_to_draw->draw_buf.width;
img_dsc.header.h = layer_to_draw->draw_buf.height;
img_dsc.header.cf = layer_to_draw->draw_buf.color_format;
img_dsc.header.always_zero = 0;
img_dsc.data = lv_draw_buf_get_buf(&layer_to_draw->draw_buf);
lv_draw_image_dsc_t new_draw_dsc;
lv_memcpy(&new_draw_dsc, draw_dsc, sizeof(lv_draw_image_dsc_t));
new_draw_dsc.src = &img_dsc;
lv_draw_pxp_img(draw_unit, &new_draw_dsc, coords);
}
#endif /*LV_USE_DRAW_PXP*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/pxp/lv_pxp_utils.h | /**
* @file lv_pxp_utils.h
*
*/
/**
* Copyright 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
#ifndef LV_PXP_UTILS_H
#define LV_PXP_UTILS_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../../../lv_conf_internal.h"
#if LV_USE_DRAW_PXP
#include "fsl_pxp.h"
#include "../../../misc/lv_color.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
pxp_output_pixel_format_t pxp_get_out_px_format(lv_color_format_t cf);
pxp_as_pixel_format_t pxp_get_as_px_format(lv_color_format_t cf);
pxp_ps_pixel_format_t pxp_get_ps_px_format(lv_color_format_t cf);
/**********************
* MACROS
**********************/
/**********************
* STATIC FUNCTIONS
**********************/
#endif /*LV_USE_DRAW_PXP*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_PXP_UTILS_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/pxp/lv_pxp_cfg.h | /**
* @file lv_pxp_cfg.h
*
*/
/**
* Copyright 2020-2023 NXP
*
* SPDX-License-Identifier: MIT
*/
#ifndef LV_PXP_CFG_H
#define LV_PXP_CFG_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../../../lv_conf_internal.h"
#if LV_USE_DRAW_PXP
#include "fsl_cache.h"
#include "fsl_pxp.h"
#include "../../../misc/lv_log.h"
/*********************
* DEFINES
*********************/
/** PXP module instance to use*/
#define PXP_ID PXP
/** PXP interrupt line ID*/
#define PXP_IRQ_ID PXP_IRQn
/**********************
* TYPEDEFS
**********************/
/**
* NXP PXP device configuration.
*/
typedef struct {
/** Callback for PXP interrupt initialization*/
void (*pxp_interrupt_init)(void);
/** Callback for PXP interrupt de-initialization*/
void (*pxp_interrupt_deinit)(void);
/** Callback for PXP start*/
void (*pxp_run)(void);
/** Callback for waiting of PXP completion*/
void (*pxp_wait)(void);
} pxp_cfg_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Reset and initialize PXP device. This function should be called as a part
* of display init sequence.
*/
void lv_pxp_init(void);
/**
* Disable PXP device. Should be called during display deinit sequence.
*/
void lv_pxp_deinit(void);
/**
* Reset PXP device.
*/
void lv_pxp_reset(void);
/**
* Clear cache and start PXP.
*/
void lv_pxp_run(void);
/**
* Wait for PXP completion.
*/
void lv_pxp_wait(void);
/**********************
* MACROS
**********************/
#endif /*LV_USE_DRAW_PXP*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_PXP_CFG_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/pxp/lv_pxp_cfg.c | /**
* @file lv_pxp_cfg.c
*
*/
/**
* Copyright 2020-2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_pxp_cfg.h"
#if LV_USE_DRAW_PXP
#include "lv_pxp_osa.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static pxp_cfg_t * _pxp_cfg;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_pxp_init(void)
{
_pxp_cfg = pxp_get_default_cfg();
if(!_pxp_cfg || !_pxp_cfg->pxp_interrupt_deinit || !_pxp_cfg->pxp_interrupt_init ||
!_pxp_cfg->pxp_run || !_pxp_cfg->pxp_wait)
LV_LOG_ERROR("PXP configuration error.");
PXP_Init(PXP_ID);
PXP_EnableCsc1(PXP_ID, false); /*Disable CSC1, it is enabled by default.*/
PXP_SetProcessBlockSize(PXP_ID, kPXP_BlockSize16); /*Block size 16x16 for higher performance*/
PXP_EnableInterrupts(PXP_ID, kPXP_CompleteInterruptEnable);
_pxp_cfg->pxp_interrupt_init();
}
void lv_pxp_deinit(void)
{
_pxp_cfg->pxp_interrupt_deinit();
PXP_DisableInterrupts(PXP_ID, kPXP_CompleteInterruptEnable);
PXP_Deinit(PXP_ID);
}
void lv_pxp_reset(void)
{
PXP_ResetControl(PXP_ID);
PXP_EnableCsc1(PXP_ID, false); /*Disable CSC1, it is enabled by default.*/
PXP_SetProcessBlockSize(PXP_ID, kPXP_BlockSize16); /*Block size 16x16 for higher performance*/
}
void lv_pxp_run(void)
{
_pxp_cfg->pxp_run();
_pxp_cfg->pxp_wait();
}
void lv_pxp_wait(void)
{
_pxp_cfg->pxp_wait();
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif /*LV_USE_DRAW_PXP*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/pxp/lv_pxp_osa.c | /**
* @file lv_pxp_osa.c
*
*/
/**
* Copyright 2020, 2022, 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_pxp_osa.h"
#if LV_USE_DRAW_PXP
#include "../../../misc/lv_log.h"
#include "fsl_pxp.h"
#if defined(SDK_OS_FREE_RTOS)
#include "FreeRTOS.h"
#include "semphr.h"
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**
* PXP interrupt initialization.
*/
static void _pxp_interrupt_init(void);
/**
* PXP interrupt de-initialization.
*/
static void _pxp_interrupt_deinit(void);
/**
* Start the PXP job.
*/
static void _pxp_run(void);
/**
* Wait for PXP completion.
*/
static void _pxp_wait(void);
/**********************
* STATIC VARIABLES
**********************/
#if defined(SDK_OS_FREE_RTOS)
static SemaphoreHandle_t xPXPIdleSemaphore;
#endif
static volatile bool ucPXPIdle;
static pxp_cfg_t _pxp_default_cfg = {
.pxp_interrupt_init = _pxp_interrupt_init,
.pxp_interrupt_deinit = _pxp_interrupt_deinit,
.pxp_run = _pxp_run,
.pxp_wait = _pxp_wait,
};
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void PXP_IRQHandler(void)
{
#if defined(SDK_OS_FREE_RTOS)
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
#endif
if(kPXP_CompleteFlag & PXP_GetStatusFlags(PXP_ID)) {
PXP_ClearStatusFlags(PXP_ID, kPXP_CompleteFlag);
#if defined(SDK_OS_FREE_RTOS)
xSemaphoreGiveFromISR(xPXPIdleSemaphore, &xHigherPriorityTaskWoken);
/* If xHigherPriorityTaskWoken is now set to pdTRUE then a context switch
should be performed to ensure the interrupt returns directly to the highest
priority task. The macro used for this purpose is dependent on the port in
use and may be called portEND_SWITCHING_ISR(). */
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
#else
ucPXPIdle = true;
#endif
}
}
pxp_cfg_t * pxp_get_default_cfg(void)
{
return &_pxp_default_cfg;
}
/**********************
* STATIC FUNCTIONS
**********************/
static void _pxp_interrupt_init(void)
{
#if defined(SDK_OS_FREE_RTOS)
xPXPIdleSemaphore = xSemaphoreCreateBinary();
if(xPXPIdleSemaphore == NULL) {
LV_LOG_ERROR("xSemaphoreCreateBinary failed!");
return;
}
NVIC_SetPriority(PXP_IRQ_ID, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 1);
#endif
ucPXPIdle = true;
NVIC_EnableIRQ(PXP_IRQ_ID);
}
static void _pxp_interrupt_deinit(void)
{
NVIC_DisableIRQ(PXP_IRQ_ID);
#if defined(SDK_OS_FREE_RTOS)
vSemaphoreDelete(xPXPIdleSemaphore);
#endif
}
/**
* Function to start PXP job.
*/
static void _pxp_run(void)
{
ucPXPIdle = false;
PXP_EnableInterrupts(PXP_ID, kPXP_CompleteInterruptEnable);
PXP_Start(PXP_ID);
}
/**
* Function to wait for PXP completion.
*/
static void _pxp_wait(void)
{
#if defined(SDK_OS_FREE_RTOS)
/* Return if PXP was never started, otherwise the semaphore will lock forever. */
if(ucPXPIdle == true)
return;
if(xSemaphoreTake(xPXPIdleSemaphore, portMAX_DELAY) == pdTRUE)
ucPXPIdle = true;
#else
while(ucPXPIdle == false) {
}
#endif
}
#endif /*LV_USE_DRAW_PXP*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/pxp/lv_draw_pxp_bg_img.c | /**
* @file lv_draw_pxp_bg_img.c
*
*/
/**
* Copyright 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_pxp.h"
#if LV_USE_DRAW_PXP
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_pxp_bg_img(lv_draw_unit_t * draw_unit, const lv_draw_bg_image_dsc_t * dsc,
const lv_area_t * coords)
{
if(dsc->src == NULL) return;
if(dsc->opa <= LV_OPA_MIN) return;
lv_area_t clip_area;
if(!_lv_area_intersect(&clip_area, coords, draw_unit->clip_area)) {
return;
}
const lv_area_t * clip_area_ori = draw_unit->clip_area;
draw_unit->clip_area = &clip_area;
lv_draw_image_dsc_t img_dsc;
lv_draw_image_dsc_init(&img_dsc);
img_dsc.recolor = dsc->recolor;
img_dsc.recolor_opa = dsc->recolor_opa;
img_dsc.opa = dsc->opa;
img_dsc.src = dsc->src;
/*Center align*/
if(dsc->tiled == false) {
lv_area_t area;
area.x1 = coords->x1 + lv_area_get_width(coords) / 2 - dsc->img_header.w / 2;
area.y1 = coords->y1 + lv_area_get_height(coords) / 2 - dsc->img_header.h / 2;
area.x2 = area.x1 + dsc->img_header.w - 1;
area.y2 = area.y1 + dsc->img_header.h - 1;
lv_draw_pxp_img(draw_unit, &img_dsc, &area);
}
else {
lv_area_t area;
area.y1 = coords->y1;
area.y2 = area.y1 + dsc->img_header.h - 1;
for(; area.y1 <= coords->y2; area.y1 += dsc->img_header.h, area.y2 += dsc->img_header.h) {
area.x1 = coords->x1;
area.x2 = area.x1 + dsc->img_header.w - 1;
for(; area.x1 <= coords->x2; area.x1 += dsc->img_header.w, area.x2 += dsc->img_header.w) {
lv_draw_pxp_img(draw_unit, &img_dsc, &area);
}
}
}
draw_unit->clip_area = clip_area_ori;
}
#endif /*LV_USE_DRAW_PXP*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/pxp/lv_draw_pxp_img.c | /**
* @file lv_draw_pxp_img.c
*
*/
/**
* Copyright 2020-2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_pxp.h"
#if LV_USE_DRAW_PXP
#include "lv_pxp_cfg.h"
#include "lv_pxp_utils.h"
#include <math.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/* Blit w/ recolor for images w/o opa and alpha channel */
static void _pxp_blit_recolor(uint8_t * dest_buf, const lv_area_t * dest_area, int32_t dest_stride,
lv_color_format_t dest_cf, const uint8_t * src_buf, const lv_area_t * src_area,
int32_t src_stride, lv_color_format_t src_cf, const lv_draw_image_dsc_t * dsc);
/* Blit w/ transformation for images w/o opa and alpha channel */
static void _pxp_blit_transform(uint8_t * dest_buf, const lv_area_t * dest_area, int32_t dest_stride,
lv_color_format_t dest_cf, const uint8_t * src_buf, const lv_area_t * src_area,
int32_t src_stride, lv_color_format_t src_cf, const lv_draw_image_dsc_t * dsc);
/* Blit simple w/ opa and alpha channel */
static void _pxp_blit(uint8_t * dest_buf, const lv_area_t * dest_area, int32_t dest_stride,
lv_color_format_t dest_cf, const uint8_t * src_buf, const lv_area_t * src_area,
int32_t src_stride, lv_color_format_t src_cf, lv_opa_t opa);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_pxp_img(lv_draw_unit_t * draw_unit, const lv_draw_image_dsc_t * dsc,
const lv_area_t * coords)
{
if(dsc->opa <= (lv_opa_t)LV_OPA_MIN)
return;
lv_layer_t * layer = draw_unit->target_layer;
const lv_image_dsc_t * img_dsc = dsc->src;
lv_area_t rel_coords;
lv_area_copy(&rel_coords, coords);
lv_area_move(&rel_coords, -layer->draw_buf_ofs.x, -layer->draw_buf_ofs.y);
lv_area_t rel_clip_area;
lv_area_copy(&rel_clip_area, draw_unit->clip_area);
lv_area_move(&rel_clip_area, -layer->draw_buf_ofs.x, -layer->draw_buf_ofs.y);
lv_area_t blend_area;
bool has_transform = dsc->rotation != 0 || dsc->zoom != LV_SCALE_NONE;
if(has_transform)
lv_area_copy(&blend_area, &rel_coords);
else if(!_lv_area_intersect(&blend_area, &rel_coords, &rel_clip_area))
return; /*Fully clipped, nothing to do*/
const uint8_t * src_buf = img_dsc->data;
lv_area_t src_area;
src_area.x1 = blend_area.x1 - (coords->x1 - layer->draw_buf_ofs.x);
src_area.y1 = blend_area.y1 - (coords->y1 - layer->draw_buf_ofs.y);
src_area.x2 = src_area.x1 + lv_area_get_width(coords) - 1;
src_area.y2 = src_area.y1 + lv_area_get_height(coords) - 1;
int32_t src_stride = img_dsc->header.stride;
lv_color_format_t src_cf = img_dsc->header.cf;
uint8_t * dest_buf = layer->draw_buf.buf;
int32_t dest_stride = lv_draw_buf_get_stride(&layer->draw_buf);
lv_color_format_t dest_cf = layer->draw_buf.color_format;
bool has_recolor = (dsc->recolor_opa != LV_OPA_TRANSP);
if(has_recolor && !has_transform)
_pxp_blit_recolor(dest_buf, &blend_area, dest_stride, dest_cf,
src_buf, &src_area, src_stride, src_cf, dsc);
else if(has_transform)
_pxp_blit_transform(dest_buf, &blend_area, dest_stride, dest_cf,
src_buf, &src_area, src_stride, src_cf, dsc);
else
_pxp_blit(dest_buf, &blend_area, dest_stride, dest_cf,
src_buf, &src_area, src_stride, src_cf, dsc->opa);
}
/**********************
* STATIC FUNCTIONS
**********************/
static void _pxp_blit_recolor(uint8_t * dest_buf, const lv_area_t * dest_area, int32_t dest_stride,
lv_color_format_t dest_cf, const uint8_t * src_buf, const lv_area_t * src_area,
int32_t src_stride, lv_color_format_t src_cf, const lv_draw_image_dsc_t * dsc)
{
int32_t dest_w = lv_area_get_width(dest_area);
int32_t dest_h = lv_area_get_height(dest_area);
int32_t src_w = lv_area_get_width(src_area);
int32_t src_h = lv_area_get_height(src_area);
bool src_has_alpha = (src_cf == LV_COLOR_FORMAT_ARGB8888);
uint8_t src_px_size = lv_color_format_get_size(src_cf);
uint8_t dest_px_size = lv_color_format_get_size(dest_cf);
lv_pxp_reset();
/*AS buffer - source image*/
pxp_as_buffer_config_t asBufferConfig = {
.pixelFormat = pxp_get_as_px_format(src_cf),
.bufferAddr = (uint32_t)(src_buf + src_stride * src_area->y1 + src_px_size * src_area->x1),
.pitchBytes = src_stride
};
PXP_SetAlphaSurfaceBufferConfig(PXP_ID, &asBufferConfig);
PXP_SetAlphaSurfacePosition(PXP_ID, 0U, 0U, src_w - 1U, src_h - 1U);
/*Disable PS, use as color generator*/
PXP_SetProcessSurfacePosition(PXP_ID, 0xFFFFU, 0xFFFFU, 0U, 0U);
PXP_SetProcessSurfaceBackGroundColor(PXP_ID, lv_color_to_u32(dsc->recolor));
/*Output buffer*/
pxp_output_buffer_config_t outputBufferConfig = {
.pixelFormat = pxp_get_out_px_format(dest_cf),
.interlacedMode = kPXP_OutputProgressive,
.buffer0Addr = (uint32_t)(dest_buf + dest_stride * dest_area->y1 + dest_px_size * dest_area->x1),
.buffer1Addr = (uint32_t)0U,
.pitchBytes = dest_stride,
.width = dest_w,
.height = dest_h
};
PXP_SetOutputBufferConfig(PXP_ID, &outputBufferConfig);
/**
* Configure Porter-Duff blending.
*
* Note: srcFactorMode and dstFactorMode are inverted in fsl_pxp.h:
* srcFactorMode is actually applied on PS alpha value
* dstFactorMode is actually applied on AS alpha value
*/
pxp_porter_duff_config_t pdConfig = {
.enable = 1,
.dstColorMode = kPXP_PorterDuffColorWithAlpha,
.srcColorMode = kPXP_PorterDuffColorWithAlpha,
.dstGlobalAlphaMode = kPXP_PorterDuffGlobalAlpha,
.srcGlobalAlphaMode = src_has_alpha ? kPXP_PorterDuffLocalAlpha : kPXP_PorterDuffGlobalAlpha,
.dstFactorMode = kPXP_PorterDuffFactorStraight,
.srcFactorMode = kPXP_PorterDuffFactorInversed,
.dstGlobalAlpha = dsc->recolor_opa,
.srcGlobalAlpha = 0xff,
.dstAlphaMode = kPXP_PorterDuffAlphaStraight, /*don't care*/
.srcAlphaMode = kPXP_PorterDuffAlphaStraight
};
PXP_SetPorterDuffConfig(PXP_ID, &pdConfig);
lv_pxp_run();
}
static void _pxp_blit_transform(uint8_t * dest_buf, const lv_area_t * dest_area, int32_t dest_stride,
lv_color_format_t dest_cf, const uint8_t * src_buf, const lv_area_t * src_area,
int32_t src_stride, lv_color_format_t src_cf, const lv_draw_image_dsc_t * dsc)
{
int32_t src_w = lv_area_get_width(src_area);
int32_t src_h = lv_area_get_height(src_area);
int32_t dest_w = lv_area_get_width(dest_area);
int32_t dest_h = lv_area_get_height(dest_area);
lv_point_t pivot = dsc->pivot;
/*The offsets are now relative to the transformation result with pivot ULC*/
int32_t piv_offset_x = 0;
int32_t piv_offset_y = 0;
int32_t trim_size = 0;
bool has_rotation = (dsc->rotation != 0);
bool has_scale = (dsc->zoom != LV_SCALE_NONE);
uint8_t src_px_size = lv_color_format_get_size(src_cf);
uint8_t dest_px_size = lv_color_format_get_size(dest_cf);
lv_pxp_reset();
if(has_rotation) {
/*Convert rotation angle and calculate offsets caused by pivot*/
pxp_rotate_degree_t pxp_angle;
switch(dsc->rotation) {
case 0:
pxp_angle = kPXP_Rotate0;
piv_offset_x = 0;
piv_offset_y = 0;
break;
case 900:
pxp_angle = kPXP_Rotate90;
piv_offset_x = pivot.x + pivot.y - src_h;
piv_offset_y = pivot.y - pivot.x;
break;
case 1800:
pxp_angle = kPXP_Rotate180;
piv_offset_x = 2 * pivot.x - src_w;
piv_offset_y = 2 * pivot.y - src_h;
break;
case 2700:
pxp_angle = kPXP_Rotate270;
piv_offset_x = pivot.x - pivot.y;
piv_offset_y = pivot.x + pivot.y - src_w;
break;
default:
pxp_angle = kPXP_Rotate0;
piv_offset_x = 0;
piv_offset_y = 0;
}
/*PS buffer rotation and decimation does not function at the same time*/
PXP_SetRotateConfig(PXP_ID, kPXP_RotateOutputBuffer, pxp_angle, kPXP_FlipDisable);
}
if(has_scale) {
float scale_factor_fp = (float)dsc->zoom / LV_SCALE_NONE;
int32_t scale_factor_int = (int32_t)scale_factor_fp;
/*Any scale_factor in (k, k + 1] will result in a trim equal to k*/
if(scale_factor_fp == scale_factor_int)
trim_size = scale_factor_int - 1;
else
trim_size = scale_factor_int;
dest_w = src_w * scale_factor_fp + trim_size;
dest_h = src_h * scale_factor_fp + trim_size;
/*Final pivot offset = scale_factor * rotation_pivot_offset + scaling_pivot_offset*/
piv_offset_x = floor(scale_factor_fp * piv_offset_x) - floor((scale_factor_fp - 1) * pivot.x);
piv_offset_y = floor(scale_factor_fp * piv_offset_y) - floor((scale_factor_fp - 1) * pivot.y);
}
/*PS buffer - source image*/
pxp_ps_buffer_config_t psBufferConfig = {
.pixelFormat = pxp_get_ps_px_format(src_cf),
.swapByte = false,
.bufferAddr = (uint32_t)(src_buf + src_stride * src_area->y1 + src_px_size * src_area->x1),
.bufferAddrU = 0,
.bufferAddrV = 0,
.pitchBytes = src_stride
};
PXP_SetProcessSurfaceBufferConfig(PXP_ID, &psBufferConfig);
PXP_SetProcessSurfacePosition(PXP_ID, 0U, 0U, dest_w - trim_size - 1U, dest_h - trim_size - 1U);
if(has_scale)
PXP_SetProcessSurfaceScaler(PXP_ID, src_w, src_h, dest_w, dest_h);
/*AS disabled */
PXP_SetAlphaSurfacePosition(PXP_ID, 0xFFFFU, 0xFFFFU, 0U, 0U);
/*Output buffer*/
pxp_output_buffer_config_t outputBufferConfig = {
.pixelFormat = pxp_get_out_px_format(dest_cf),
.interlacedMode = kPXP_OutputProgressive,
.buffer0Addr = (uint32_t)(dest_buf + dest_stride * (dest_area->y1 + piv_offset_y) + dest_px_size * (dest_area->x1 + piv_offset_x)),
.buffer1Addr = (uint32_t)0U,
.pitchBytes = dest_stride,
.width = dest_w - trim_size,
.height = dest_h - trim_size
};
PXP_SetOutputBufferConfig(PXP_ID, &outputBufferConfig);
lv_pxp_run();
}
static void _pxp_blit(uint8_t * dest_buf, const lv_area_t * dest_area, int32_t dest_stride,
lv_color_format_t dest_cf, const uint8_t * src_buf, const lv_area_t * src_area,
int32_t src_stride, lv_color_format_t src_cf, lv_opa_t opa)
{
int32_t dest_w = lv_area_get_width(dest_area);
int32_t dest_h = lv_area_get_height(dest_area);
int32_t src_w = lv_area_get_width(src_area);
int32_t src_h = lv_area_get_height(src_area);
bool src_has_alpha = (src_cf == LV_COLOR_FORMAT_ARGB8888);
uint8_t src_px_size = lv_color_format_get_size(src_cf);
uint8_t dest_px_size = lv_color_format_get_size(dest_cf);
lv_pxp_reset();
pxp_as_blend_config_t asBlendConfig = {
.alpha = opa,
.invertAlpha = false,
.alphaMode = kPXP_AlphaRop,
.ropMode = kPXP_RopMergeAs
};
if(opa >= (lv_opa_t)LV_OPA_MAX && !src_has_alpha) {
/*Simple blit, no effect - Disable PS buffer*/
PXP_SetProcessSurfacePosition(PXP_ID, 0xFFFFU, 0xFFFFU, 0U, 0U);
}
else {
/*PS must be enabled to fetch background pixels.
PS and OUT buffers are the same, blend will be done in-place*/
pxp_ps_buffer_config_t psBufferConfig = {
.pixelFormat = pxp_get_ps_px_format(dest_cf),
.swapByte = false,
.bufferAddr = (uint32_t)(dest_buf + dest_stride * dest_area->y1 + dest_px_size * dest_area->x1),
.bufferAddrU = 0U,
.bufferAddrV = 0U,
.pitchBytes = dest_stride
};
if(opa >= (lv_opa_t)LV_OPA_MAX)
asBlendConfig.alphaMode = src_has_alpha ? kPXP_AlphaEmbedded : kPXP_AlphaOverride;
else
asBlendConfig.alphaMode = src_has_alpha ? kPXP_AlphaMultiply : kPXP_AlphaOverride;
PXP_SetProcessSurfaceBufferConfig(PXP_ID, &psBufferConfig);
PXP_SetProcessSurfacePosition(PXP_ID, 0U, 0U, dest_w - 1U, dest_h - 1U);
}
/*AS buffer - source image*/
pxp_as_buffer_config_t asBufferConfig = {
.pixelFormat = pxp_get_as_px_format(src_cf),
.bufferAddr = (uint32_t)(src_buf + src_stride * src_area->y1 + src_px_size * src_area->x1),
.pitchBytes = src_stride
};
PXP_SetAlphaSurfaceBufferConfig(PXP_ID, &asBufferConfig);
PXP_SetAlphaSurfacePosition(PXP_ID, 0U, 0U, src_w - 1U, src_h - 1U);
PXP_SetAlphaSurfaceBlendConfig(PXP_ID, &asBlendConfig);
PXP_EnableAlphaSurfaceOverlayColorKey(PXP_ID, false);
/*Output buffer.*/
pxp_output_buffer_config_t outputBufferConfig = {
.pixelFormat = pxp_get_out_px_format(dest_cf),
.interlacedMode = kPXP_OutputProgressive,
.buffer0Addr = (uint32_t)(dest_buf + dest_stride * dest_area->y1 + dest_px_size * dest_area->x1),
.buffer1Addr = (uint32_t)0U,
.pitchBytes = dest_stride,
.width = dest_w,
.height = dest_h
};
PXP_SetOutputBufferConfig(PXP_ID, &outputBufferConfig);
lv_pxp_run();
}
#endif /*LV_USE_DRAW_PXP*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/pxp/lv_draw_pxp.h | /**
* @file lv_draw_pxp.h
*
*/
/**
* Copyright 2022, 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
#ifndef LV_DRAW_PXP_H
#define LV_DRAW_PXP_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../../../lv_conf_internal.h"
#if LV_USE_DRAW_PXP
#include "../../sw/lv_draw_sw.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef lv_layer_t lv_pxp_layer_t;
typedef struct {
lv_draw_unit_t base_unit;
struct _lv_draw_task_t * task_act;
#if LV_USE_OS
lv_thread_sync_t sync;
lv_thread_t thread;
#endif
} lv_draw_pxp_unit_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
void lv_draw_buf_pxp_init_handlers(void);
void lv_draw_pxp_init(void);
void lv_draw_pxp_bg_img(lv_draw_unit_t * draw_unit, const lv_draw_bg_image_dsc_t * dsc,
const lv_area_t * coords);
void lv_draw_pxp_fill(lv_draw_unit_t * draw_unit, const lv_draw_fill_dsc_t * dsc,
const lv_area_t * coords);
void lv_draw_pxp_img(lv_draw_unit_t * draw_unit, const lv_draw_image_dsc_t * dsc,
const lv_area_t * coords);
void lv_draw_pxp_layer(lv_draw_unit_t * draw_unit, const lv_draw_image_dsc_t * draw_dsc,
const lv_area_t * coords);
/**********************
* MACROS
**********************/
#endif /*LV_USE_DRAW_PXP*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_DRAW_PXP_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/pxp/lv_draw_pxp_fill.c | /**
* @file lv_draw_pxp_fill.c
*
*/
/**
* Copyright 2020-2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_pxp.h"
#if LV_USE_DRAW_PXP
#include "lv_pxp_cfg.h"
#include "lv_pxp_utils.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void _pxp_fill(uint8_t * dest_buf, const lv_area_t * dest_area, int32_t dest_stride,
lv_color_format_t dest_cf, const lv_draw_fill_dsc_t * dsc);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_pxp_fill(lv_draw_unit_t * draw_unit, const lv_draw_fill_dsc_t * dsc,
const lv_area_t * coords)
{
if(dsc->opa <= (lv_opa_t)LV_OPA_MIN)
return;
lv_layer_t * layer = draw_unit->target_layer;
lv_area_t rel_coords;
lv_area_copy(&rel_coords, coords);
lv_area_move(&rel_coords, -layer->draw_buf_ofs.x, -layer->draw_buf_ofs.y);
lv_area_t rel_clip_area;
lv_area_copy(&rel_clip_area, draw_unit->clip_area);
lv_area_move(&rel_clip_area, -layer->draw_buf_ofs.x, -layer->draw_buf_ofs.y);
lv_area_t blend_area;
if(!_lv_area_intersect(&blend_area, &rel_coords, &rel_clip_area))
return; /*Fully clipped, nothing to do*/
uint8_t * dest_buf = layer->draw_buf.buf;
int32_t dest_stride = lv_draw_buf_get_stride(&layer->draw_buf);
lv_color_format_t dest_cf = layer->draw_buf.color_format;
_pxp_fill(dest_buf, &blend_area, dest_stride, dest_cf, dsc);
}
/**********************
* STATIC FUNCTIONS
**********************/
static void _pxp_fill(uint8_t * dest_buf, const lv_area_t * dest_area, int32_t dest_stride,
lv_color_format_t dest_cf, const lv_draw_fill_dsc_t * dsc)
{
int32_t dest_w = lv_area_get_width(dest_area);
int32_t dest_h = lv_area_get_height(dest_area);
lv_pxp_reset();
uint8_t px_size = lv_color_format_get_size(dest_cf);
/*OUT buffer configure*/
pxp_output_buffer_config_t outputConfig = {
.pixelFormat = pxp_get_out_px_format(dest_cf),
.interlacedMode = kPXP_OutputProgressive,
.buffer0Addr = (uint32_t)(dest_buf + dest_stride * dest_area->y1 + px_size * dest_area->x1),
.buffer1Addr = (uint32_t)NULL,
.pitchBytes = dest_stride,
.width = dest_w,
.height = dest_h
};
PXP_SetOutputBufferConfig(PXP_ID, &outputConfig);
if(dsc->opa >= (lv_opa_t)LV_OPA_MAX) {
/*Simple color fill without opacity - AS disabled*/
PXP_SetAlphaSurfacePosition(PXP_ID, 0xFFFFU, 0xFFFFU, 0U, 0U);
}
else {
/*Fill with opacity - AS used as source (same as OUT)*/
pxp_as_buffer_config_t asBufferConfig = {
.pixelFormat = pxp_get_as_px_format(dest_cf),
.bufferAddr = outputConfig.buffer0Addr,
.pitchBytes = outputConfig.pitchBytes
};
PXP_SetAlphaSurfaceBufferConfig(PXP_ID, &asBufferConfig);
PXP_SetAlphaSurfacePosition(PXP_ID, 0U, 0U, dest_w - 1U, dest_h - 1U);
}
/*Disable PS, use as color generator*/
PXP_SetProcessSurfacePosition(PXP_ID, 0xFFFFU, 0xFFFFU, 0U, 0U);
PXP_SetProcessSurfaceBackGroundColor(PXP_ID, lv_color_to_u32(dsc->color));
/**
* Configure Porter-Duff blending - src settings are unused for fill without opacity (opa = 0xff).
*
* Note: srcFactorMode and dstFactorMode are inverted in fsl_pxp.h:
* srcFactorMode is actually applied on PS alpha value
* dstFactorMode is actually applied on AS alpha value
*/
pxp_porter_duff_config_t pdConfig = {
.enable = 1,
.dstColorMode = kPXP_PorterDuffColorNoAlpha,
.srcColorMode = kPXP_PorterDuffColorNoAlpha,
.dstGlobalAlphaMode = kPXP_PorterDuffGlobalAlpha,
.srcGlobalAlphaMode = kPXP_PorterDuffGlobalAlpha,
.dstFactorMode = kPXP_PorterDuffFactorStraight,
.srcFactorMode = (dsc->opa >= (lv_opa_t)LV_OPA_MAX) ? kPXP_PorterDuffFactorStraight : kPXP_PorterDuffFactorInversed,
.dstGlobalAlpha = dsc->opa,
.srcGlobalAlpha = dsc->opa,
.dstAlphaMode = kPXP_PorterDuffAlphaStraight, /*don't care*/
.srcAlphaMode = kPXP_PorterDuffAlphaStraight /*don't care*/
};
PXP_SetPorterDuffConfig(PXP_ID, &pdConfig);
lv_pxp_run();
}
#endif /*LV_USE_DRAW_PXP*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/pxp/lv_draw_pxp.c | /**
* @file lv_draw_pxp.c
*
*/
/**
* Copyright 2022, 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_pxp.h"
#if LV_USE_DRAW_PXP
#include "lv_pxp_cfg.h"
#include "../../../display/lv_display_private.h"
/*********************
* DEFINES
*********************/
#define DRAW_UNIT_ID_PXP 3
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/*
* Dispatch a task to the PXP unit.
* Return 1 if task was dispatched, 0 otherwise (task not supported).
*/
static int32_t _pxp_dispatch(lv_draw_unit_t * draw_unit, lv_layer_t * layer);
/*
* Evaluate a task and set the score and preferred PXP unit.
* Return 1 if task is preferred, 0 otherwise (task is not supported).
*/
static int32_t _pxp_evaluate(lv_draw_unit_t * draw_unit, lv_draw_task_t * task);
#if LV_USE_OS
static void _pxp_render_thread_cb(void * ptr);
#endif
static void _pxp_execute_drawing(lv_draw_pxp_unit_t * u);
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_pxp_init(void)
{
lv_draw_buf_pxp_init_handlers();
lv_draw_pxp_unit_t * draw_pxp_unit = lv_draw_create_unit(sizeof(lv_draw_pxp_unit_t));
draw_pxp_unit->base_unit.dispatch_cb = _pxp_dispatch;
draw_pxp_unit->base_unit.evaluate_cb = _pxp_evaluate;
lv_pxp_init();
#if LV_USE_OS
lv_thread_init(&draw_pxp_unit->thread, LV_THREAD_PRIO_HIGH, _pxp_render_thread_cb, 8 * 1024, draw_pxp_unit);
#endif
}
/**********************
* STATIC FUNCTIONS
**********************/
static inline bool _pxp_cf_supported(lv_color_format_t cf)
{
bool is_cf_supported = (cf == LV_COLOR_FORMAT_RGB565 || cf == LV_COLOR_FORMAT_RGB888 ||
cf == LV_COLOR_FORMAT_ARGB8888 || cf == LV_COLOR_FORMAT_XRGB8888);
return is_cf_supported;
}
static bool _pxp_draw_img_supported(const lv_draw_image_dsc_t * draw_dsc)
{
const lv_image_dsc_t * img_dsc = draw_dsc->src;
bool has_recolor = (draw_dsc->recolor_opa != LV_OPA_TRANSP);
bool has_transform = (draw_dsc->rotation != 0 || draw_dsc->zoom != LV_SCALE_NONE);
/* Recolor and transformation are not supported at the same time. */
if(has_recolor && has_transform)
return false;
bool has_opa = (draw_dsc->opa < (lv_opa_t)LV_OPA_MAX);
bool src_has_alpha = (img_dsc->header.cf == LV_COLOR_FORMAT_ARGB8888);
/*
* Recolor or transformation for images w/ opa or alpha channel can't
* be obtained in a single PXP configuration. Two steps are required.
*/
if((has_recolor || has_transform) && (has_opa || src_has_alpha))
return false;
/* PXP can only rotate at 90x angles. */
if(draw_dsc->rotation % 900)
return false;
/*
* PXP is set to process 16x16 blocks to optimize the system for memory
* bandwidth and image processing time.
* The output engine essentially truncates any output pixels after the
* desired number of pixels has been written.
* When rotating a source image and the output is not divisible by the block
* size, the incorrect pixels could be truncated and the final output image
* can look shifted.
*
* No combination of rotate with flip, scaling or decimation is possible
* if buffer is unaligned.
*/
if(has_transform && (img_dsc->header.w % 16 || img_dsc->header.h % 16))
return false;
return true;
}
static int32_t _pxp_evaluate(lv_draw_unit_t * u, lv_draw_task_t * t)
{
LV_UNUSED(u);
switch(t->type) {
case LV_DRAW_TASK_TYPE_FILL: {
const lv_draw_fill_dsc_t * draw_dsc = (lv_draw_fill_dsc_t *) t->draw_dsc;
/* Most simple case: just a plain rectangle (no radius, no gradient). */
if((draw_dsc->radius != 0) || (draw_dsc->grad.dir != (lv_grad_dir_t)LV_GRAD_DIR_NONE))
return 0;
if(t->preference_score > 70) {
t->preference_score = 70;
t->preferred_draw_unit_id = DRAW_UNIT_ID_PXP;
}
return 1;
}
case LV_DRAW_TASK_TYPE_BG_IMG: {
const lv_draw_bg_image_dsc_t * draw_dsc = (lv_draw_bg_image_dsc_t *) t->draw_dsc;
lv_image_src_t src_type = lv_image_src_get_type(draw_dsc->src);
if(src_type == LV_IMAGE_SRC_SYMBOL)
return 0;
if(!_pxp_cf_supported(draw_dsc->img_header.cf))
return 0;
if(t->preference_score > 70) {
t->preference_score = 70;
t->preferred_draw_unit_id = DRAW_UNIT_ID_PXP;
}
return 1;
}
case LV_DRAW_TASK_TYPE_LAYER: {
const lv_draw_image_dsc_t * draw_dsc = (lv_draw_image_dsc_t *) t->draw_dsc;
lv_layer_t * layer_to_draw = (lv_layer_t *)draw_dsc->src;
lv_draw_buf_t * draw_buf = &layer_to_draw->draw_buf;
if(!_pxp_cf_supported(draw_buf->color_format))
return 0;
if(!_pxp_draw_img_supported(draw_dsc))
return 0;
if(t->preference_score > 70) {
t->preference_score = 70;
t->preferred_draw_unit_id = DRAW_UNIT_ID_PXP;
}
return 1;
}
case LV_DRAW_TASK_TYPE_IMAGE: {
lv_draw_image_dsc_t * draw_dsc = (lv_draw_image_dsc_t *) t->draw_dsc;
const lv_image_dsc_t * img_dsc = draw_dsc->src;
if(!_pxp_cf_supported(img_dsc->header.cf))
return 0;
if(!_pxp_draw_img_supported(draw_dsc))
return 0;
if(t->preference_score > 70) {
t->preference_score = 70;
t->preferred_draw_unit_id = DRAW_UNIT_ID_PXP;
}
return 1;
}
default:
return 0;
}
return 0;
}
static int32_t _pxp_dispatch(lv_draw_unit_t * draw_unit, lv_layer_t * layer)
{
lv_draw_pxp_unit_t * draw_pxp_unit = (lv_draw_pxp_unit_t *) draw_unit;
/* Return immediately if it's busy with draw task. */
if(draw_pxp_unit->task_act)
return 0;
/* Return if target buffer format is not supported. */
if(!_pxp_cf_supported(layer->draw_buf.color_format))
return 0;
/* Try to get an ready to draw. */
lv_draw_task_t * t = lv_draw_get_next_available_task(layer, NULL, DRAW_UNIT_ID_PXP);
/* Return 0 is no selection, some tasks can be supported only by other units. */
if(t == NULL || t->preferred_draw_unit_id != DRAW_UNIT_ID_PXP)
return 0;
void * buf = lv_draw_layer_alloc_buf(layer);
if(buf == NULL)
return -1;
t->state = LV_DRAW_TASK_STATE_IN_PROGRESS;
draw_pxp_unit->base_unit.target_layer = layer;
draw_pxp_unit->base_unit.clip_area = &t->clip_area;
draw_pxp_unit->task_act = t;
#if LV_USE_OS
/* Let the render thread work. */
lv_thread_sync_signal(&draw_pxp_unit->sync);
#else
_pxp_execute_drawing(draw_pxp_unit);
draw_pxp_unit->task_act->state = LV_DRAW_TASK_STATE_READY;
draw_pxp_unit->task_act = NULL;
/* The draw unit is free now. Request a new dispatching as it can get a new task. */
lv_draw_dispatch_request();
#endif
return 1;
}
static void _pxp_execute_drawing(lv_draw_pxp_unit_t * u)
{
lv_draw_task_t * t = u->task_act;
lv_draw_unit_t * draw_unit = (lv_draw_unit_t *)u;
/* Invalidate cache */
lv_layer_t * layer = draw_unit->target_layer;
lv_draw_buf_invalidate_cache(&layer->draw_buf, (const char *)&t->area);
switch(t->type) {
case LV_DRAW_TASK_TYPE_FILL:
lv_draw_pxp_fill(draw_unit, t->draw_dsc, &t->area);
break;
case LV_DRAW_TASK_TYPE_BG_IMG:
lv_draw_pxp_bg_img(draw_unit, t->draw_dsc, &t->area);
break;
case LV_DRAW_TASK_TYPE_IMAGE:
lv_draw_pxp_img(draw_unit, t->draw_dsc, &t->area);
break;
case LV_DRAW_TASK_TYPE_LAYER:
lv_draw_pxp_layer(draw_unit, t->draw_dsc, &t->area);
break;
default:
break;
}
}
#if LV_USE_OS
static void _pxp_render_thread_cb(void * ptr)
{
lv_draw_pxp_unit_t * u = ptr;
lv_thread_sync_init(&u->sync);
while(1) {
/*
* Wait for sync if no task received or _draw_task_buf is empty.
* The thread will have to run as much as there are pending tasks.
*/
while(u->task_act == NULL) {
lv_thread_sync_wait(&u->sync);
}
_pxp_execute_drawing(u);
/* Cleanup. */
u->task_act->state = LV_DRAW_TASK_STATE_READY;
u->task_act = NULL;
/* The draw unit is free now. Request a new dispatching as it can get a new task. */
lv_draw_dispatch_request();
}
}
#endif
#endif /*LV_USE_DRAW_PXP*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/pxp/lv_pxp_osa.h | /**
* @file lv_pxp_osa.h
*
*/
/**
* Copyright 2020, 2022, 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
#ifndef LV_PXP_OSA_H
#define LV_PXP_OSA_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../../../lv_conf_internal.h"
#if LV_USE_DRAW_PXP
#include "lv_pxp_cfg.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* PXP device interrupt handler. Used to check PXP task completion status.
*/
void PXP_IRQHandler(void);
/**
* Get the PXP default configuration.
*/
pxp_cfg_t * pxp_get_default_cfg(void);
/**********************
* MACROS
**********************/
#endif /*LV_USE_DRAW_PXP*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_PXP_OSA_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/pxp/lv_pxp_utils.c | /**
* @file lv_pxp_utils.c
*
*/
/**
* Copyright 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_pxp_utils.h"
#if LV_USE_DRAW_PXP
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
pxp_output_pixel_format_t pxp_get_out_px_format(lv_color_format_t cf)
{
pxp_output_pixel_format_t out_px_format = kPXP_OutputPixelFormatRGB565;
switch(cf) {
/*2 byte (+alpha) formats*/
case LV_COLOR_FORMAT_RGB565:
out_px_format = kPXP_OutputPixelFormatRGB565;
break;
case LV_COLOR_FORMAT_RGB565A8:
LV_ASSERT_MSG(false, "Unsupported color format.");
break;
/*3 byte (+alpha) formats*/
case LV_COLOR_FORMAT_RGB888:
out_px_format = kPXP_OutputPixelFormatRGB888P;
break;
case LV_COLOR_FORMAT_ARGB8888:
out_px_format = kPXP_OutputPixelFormatARGB8888;
break;
case LV_COLOR_FORMAT_XRGB8888:
out_px_format = kPXP_OutputPixelFormatRGB888;
break;
default:
LV_ASSERT_MSG(false, "Unsupported color format.");
break;
}
return out_px_format;
}
pxp_as_pixel_format_t pxp_get_as_px_format(lv_color_format_t cf)
{
pxp_as_pixel_format_t as_px_format = kPXP_AsPixelFormatRGB565;
switch(cf) {
/*2 byte (+alpha) formats*/
case LV_COLOR_FORMAT_RGB565:
as_px_format = kPXP_AsPixelFormatRGB565;
break;
case LV_COLOR_FORMAT_RGB565A8:
LV_ASSERT_MSG(false, "Unsupported color format.");
break;
/*3 byte (+alpha) formats*/
case LV_COLOR_FORMAT_RGB888:
LV_ASSERT_MSG(false, "Unsupported color format.");
break;
case LV_COLOR_FORMAT_ARGB8888:
as_px_format = kPXP_AsPixelFormatARGB8888;
break;
case LV_COLOR_FORMAT_XRGB8888:
as_px_format = kPXP_AsPixelFormatRGB888;
break;
default:
LV_ASSERT_MSG(false, "Unsupported color format.");
break;
}
return as_px_format;
}
pxp_ps_pixel_format_t pxp_get_ps_px_format(lv_color_format_t cf)
{
pxp_ps_pixel_format_t ps_px_format = kPXP_PsPixelFormatRGB565;
switch(cf) {
/*2 byte (+alpha) formats*/
case LV_COLOR_FORMAT_RGB565:
ps_px_format = kPXP_PsPixelFormatRGB565;
break;
case LV_COLOR_FORMAT_RGB565A8:
LV_ASSERT_MSG(false, "Unsupported color format.");
break;
/*3 byte (+alpha) formats*/
case LV_COLOR_FORMAT_RGB888:
LV_ASSERT_MSG(false, "Unsupported color format.");
break;
case LV_COLOR_FORMAT_ARGB8888:
#if (!(defined(FSL_FEATURE_PXP_HAS_NO_EXTEND_PIXEL_FORMAT) && FSL_FEATURE_PXP_HAS_NO_EXTEND_PIXEL_FORMAT)) && \
(!(defined(FSL_FEATURE_PXP_V3) && FSL_FEATURE_PXP_V3))
ps_px_format = kPXP_PsPixelFormatARGB8888;
#else
LV_ASSERT_MSG(false, "Unsupported color format.");
#endif
break;
case LV_COLOR_FORMAT_XRGB8888:
#if (!(defined(FSL_FEATURE_PXP_HAS_NO_EXTEND_PIXEL_FORMAT) && FSL_FEATURE_PXP_HAS_NO_EXTEND_PIXEL_FORMAT)) && \
(!(defined(FSL_FEATURE_PXP_V3) && FSL_FEATURE_PXP_V3))
ps_px_format = kPXP_PsPixelFormatARGB8888;
#else
ps_px_format = kPXP_PsPixelFormatRGB888;
#endif
break;
default:
LV_ASSERT_MSG(false, "Unsupported color format.");
break;
}
return ps_px_format;
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif /*LV_USE_DRAW_PXP*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/pxp/lv_draw_buf_pxp.c | /**
* @file lv_draw_buf_pxp.c
*
*/
/**
* Copyright 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_pxp.h"
#if LV_USE_DRAW_PXP
#include "lv_pxp_cfg.h"
#include "lv_pxp_utils.h"
#include "lvgl_support.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void _invalidate_cache(lv_draw_buf_t * draw_buf, const char * area);
static void _pxp_buf_copy(void * dest_buf, uint32_t dest_stride, const lv_area_t * dest_area,
void * src_buf, uint32_t src_stride, const lv_area_t * src_area, lv_color_format_t cf);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_buf_pxp_init_handlers(void)
{
lv_draw_buf_handlers_t * handlers = lv_draw_buf_get_handlers();
handlers->invalidate_cache_cb = _invalidate_cache;
handlers->buf_copy_cb = _pxp_buf_copy;
}
/**********************
* STATIC FUNCTIONS
**********************/
static void _invalidate_cache(lv_draw_buf_t * draw_buf, const char * area)
{
LV_UNUSED(draw_buf);
LV_UNUSED(area);
DEMO_CleanInvalidateCache();
}
void _pxp_buf_copy(void * dest_buf, uint32_t dest_stride, const lv_area_t * dest_area,
void * src_buf, uint32_t src_stride, const lv_area_t * src_area,
lv_color_format_t cf)
{
lv_pxp_reset();
const pxp_pic_copy_config_t picCopyConfig = {
.srcPicBaseAddr = (uint32_t)src_buf,
.srcPitchBytes = src_stride,
.srcOffsetX = src_area->x1,
.srcOffsetY = src_area->y1,
.destPicBaseAddr = (uint32_t)dest_buf,
.destPitchBytes = dest_stride,
.destOffsetX = dest_area->x1,
.destOffsetY = dest_area->y1,
.width = lv_area_get_width(src_area),
.height = lv_area_get_height(src_area),
.pixelFormat = pxp_get_as_px_format(cf)
};
PXP_StartPictureCopy(PXP_ID, &picCopyConfig);
lv_pxp_run();
}
#endif /*LV_USE_DRAW_PXP*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/vglite/lv_draw_vglite_bg_img.c | /**
* @file lv_draw_vglite_bg_img.c
*
*/
/**
* Copyright 2022, 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_vglite.h"
#if LV_USE_DRAW_VGLITE
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_vglite_bg_img(lv_draw_unit_t * draw_unit, const lv_draw_bg_image_dsc_t * dsc,
const lv_area_t * coords)
{
if(dsc->src == NULL) return;
if(dsc->opa <= LV_OPA_MIN) return;
lv_area_t clip_area;
if(!_lv_area_intersect(&clip_area, coords, draw_unit->clip_area)) {
return;
}
const lv_area_t * clip_area_ori = draw_unit->clip_area;
draw_unit->clip_area = &clip_area;
lv_image_src_t src_type = lv_image_src_get_type(dsc->src);
if(src_type == LV_IMAGE_SRC_SYMBOL) {
lv_point_t size;
lv_text_get_size(&size, dsc->src, dsc->font, 0, 0, LV_COORD_MAX, LV_TEXT_FLAG_NONE);
lv_area_t a;
a.x1 = coords->x1 + lv_area_get_width(coords) / 2 - size.x / 2;
a.x2 = a.x1 + size.x - 1;
a.y1 = coords->y1 + lv_area_get_height(coords) / 2 - size.y / 2;
a.y2 = a.y1 + size.y - 1;
lv_draw_label_dsc_t label_draw_dsc;
lv_draw_label_dsc_init(&label_draw_dsc);
label_draw_dsc.font = dsc->font;
label_draw_dsc.color = dsc->recolor;
label_draw_dsc.opa = dsc->opa;
label_draw_dsc.text = dsc->src;
lv_draw_vglite_label(draw_unit, &label_draw_dsc, &a);
}
else {
lv_draw_image_dsc_t img_dsc;
lv_draw_image_dsc_init(&img_dsc);
img_dsc.recolor = dsc->recolor;
img_dsc.recolor_opa = dsc->recolor_opa;
img_dsc.opa = dsc->opa;
img_dsc.src = dsc->src;
/*Center align*/
if(dsc->tiled == false) {
lv_area_t area;
area.x1 = coords->x1 + lv_area_get_width(coords) / 2 - dsc->img_header.w / 2;
area.y1 = coords->y1 + lv_area_get_height(coords) / 2 - dsc->img_header.h / 2;
area.x2 = area.x1 + dsc->img_header.w - 1;
area.y2 = area.y1 + dsc->img_header.h - 1;
lv_draw_vglite_img(draw_unit, &img_dsc, &area);
}
else {
lv_area_t area;
area.y1 = coords->y1;
area.y2 = area.y1 + dsc->img_header.h - 1;
for(; area.y1 <= coords->y2; area.y1 += dsc->img_header.h, area.y2 += dsc->img_header.h) {
area.x1 = coords->x1;
area.x2 = area.x1 + dsc->img_header.w - 1;
for(; area.x1 <= coords->x2; area.x1 += dsc->img_header.w, area.x2 += dsc->img_header.w) {
lv_draw_vglite_img(draw_unit, &img_dsc, &area);
}
}
}
}
draw_unit->clip_area = clip_area_ori;
}
#endif /*LV_USE_DRAW_VGLITE*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/vglite/lv_draw_buf_vglite.c | /**
* @file lv_draw_buf_vglite.c
*
*/
/**
* Copyright 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_vglite.h"
#if LV_USE_DRAW_VGLITE
#include "lv_vglite_buf.h"
#include "lv_vglite_matrix.h"
#include "lv_vglite_utils.h"
#include "lvgl_support.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void * _buf_malloc(size_t size_bytes, lv_color_format_t cf);
static void * _align_buf(void * buf, lv_color_format_t cf);
static void _invalidate_cache(lv_draw_buf_t * draw_buf, const char * area);
static uint32_t _width_to_stride(uint32_t w, lv_color_format_t cf);
static void * _go_to_xy(lv_draw_buf_t * draw_buf, int32_t x, int32_t y);
static void _vglite_buf_clear(lv_draw_buf_t * draw_buf, const lv_area_t * area);
static void _vglite_buf_copy(void * dest_buf, uint32_t dest_stride, const lv_area_t * dest_area,
void * src_buf, uint32_t src_stride, const lv_area_t * src_area, lv_color_format_t cf);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_buf_vglite_init_handlers(void)
{
lv_draw_buf_handlers_t * handlers = lv_draw_buf_get_handlers();
handlers->buf_malloc_cb = _buf_malloc;
handlers->align_pointer_cb = _align_buf;
handlers->invalidate_cache_cb = _invalidate_cache;
handlers->width_to_stride_cb = _width_to_stride;
handlers->go_to_xy_cb = _go_to_xy;
handlers->buf_clear_cb = _vglite_buf_clear;
handlers->buf_copy_cb = _vglite_buf_copy;
}
/**********************
* STATIC FUNCTIONS
**********************/
static void * _buf_malloc(size_t size_bytes, lv_color_format_t cf)
{
uint8_t align_bytes = vglite_get_alignment(cf);
/*Allocate larger memory to be sure it can be aligned as needed*/
size_bytes += align_bytes - 1;
return lv_malloc(size_bytes);
}
static void * _align_buf(void * buf, lv_color_format_t cf)
{
uint8_t align_bytes = vglite_get_alignment(cf);
uint8_t * buf_u8 = buf;
if(buf_u8) {
buf_u8 += align_bytes - 1;
buf_u8 = (uint8_t *)((lv_uintptr_t)buf_u8 & ~(align_bytes - 1));
}
return buf_u8;
}
static void _invalidate_cache(lv_draw_buf_t * draw_buf, const char * area)
{
LV_UNUSED(draw_buf);
LV_UNUSED(area);
DEMO_CleanInvalidateCache();
}
static uint32_t _width_to_stride(uint32_t w, lv_color_format_t cf)
{
uint8_t bits_per_pixel = vglite_get_px_size(cf);
uint32_t width_bits = (w * bits_per_pixel + 7) & ~7;
uint32_t width_bytes = width_bits / 8;
uint8_t align_bytes = vglite_get_alignment(cf);
return (width_bytes + align_bytes - 1) & ~(align_bytes - 1);
}
static void * _go_to_xy(lv_draw_buf_t * draw_buf, int32_t x, int32_t y)
{
uint8_t bits_per_pixel = vglite_get_px_size(draw_buf->color_format);
uint32_t stride = lv_draw_buf_get_stride(draw_buf);
uint8_t * buf_tmp = lv_draw_buf_get_buf(draw_buf);
buf_tmp += stride * y;
buf_tmp += (x * bits_per_pixel) / 8;
return buf_tmp;
}
static void _vglite_buf_clear(lv_draw_buf_t * draw_buf, const lv_area_t * area)
{
uint32_t stride = lv_draw_buf_get_stride(draw_buf);
/* Set vgbuf structure. */
vg_lite_buffer_t vgbuf;
vglite_set_buf(&vgbuf, draw_buf->buf, draw_buf->width, draw_buf->height, stride, draw_buf->color_format);
vg_lite_color_t vgcol = 0;
vg_lite_rectangle_t rect = {
.x = area->x1,
.y = area->y1,
.width = lv_area_get_width(area),
.height = lv_area_get_height(area)
};
vg_lite_error_t err = vg_lite_clear(&vgbuf, &rect, vgcol);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Clear failed.");
vglite_run();
}
static void _vglite_buf_copy(void * dest_buf, uint32_t dest_stride, const lv_area_t * dest_area,
void * src_buf, uint32_t src_stride, const lv_area_t * src_area,
lv_color_format_t cf)
{
/* Set src_vgbuf structure. */
vg_lite_buffer_t src_vgbuf;
vglite_set_buf(&src_vgbuf, src_buf, lv_area_get_width(src_area), lv_area_get_height(src_area), src_stride, cf);
/* Set dest_vgbuf structure. */
vg_lite_buffer_t dest_vgbuf;
vglite_set_buf(&dest_vgbuf, dest_buf, lv_area_get_width(dest_area), lv_area_get_height(dest_area), dest_stride, cf);
uint32_t rect[] = {
(uint32_t)src_area->x1, /* start x */
(uint32_t)src_area->y1, /* start y */
(uint32_t)lv_area_get_width(src_area), /* width */
(uint32_t)lv_area_get_height(src_area) /* height */
};
/* Set scissor. */
vglite_set_scissor(dest_area);
/* Set vgmatrix. */
vglite_set_translation_matrix(dest_area);
vg_lite_matrix_t * vgmatrix = vglite_get_matrix();
vg_lite_error_t err = vg_lite_blit_rect(&dest_vgbuf, &src_vgbuf, rect, vgmatrix,
VG_LITE_BLEND_NONE, 0xFFFFFFFFU, VG_LITE_FILTER_POINT);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Blit rectangle failed.");
vglite_run();
/* Disable scissor. */
vglite_disable_scissor();
}
#endif /*LV_USE_DRAW_VGLITE*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/vglite/lv_draw_vglite.h | /**
* @file lv_draw_vglite.h
*
*/
/**
* Copyright 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
#ifndef LV_DRAW_VGLITE_H
#define LV_DRAW_VGLITE_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../../../lv_conf_internal.h"
#if LV_USE_DRAW_VGLITE
#include "../../sw/lv_draw_sw.h"
/*********************
* DEFINES
*********************/
/**
* Enable BLIT quality degradation workaround for RT595,
* recommended for screen's dimension > 352 pixels.
*/
#define RT595_BLIT_WRKRND_ENABLED 1
/* Internal compound symbol */
#if (defined(CPU_MIMXRT595SFFOB) || defined(CPU_MIMXRT595SFFOB_cm33) || \
defined(CPU_MIMXRT595SFFOC) || defined(CPU_MIMXRT595SFFOC_cm33)) && \
RT595_BLIT_WRKRND_ENABLED
#define VGLITE_BLIT_SPLIT_ENABLED 1
#else
#define VGLITE_BLIT_SPLIT_ENABLED 0
#endif
/**********************
* TYPEDEFS
**********************/
typedef struct {
lv_draw_unit_t base_unit;
struct _lv_draw_task_t * task_act;
#if LV_USE_OS
lv_thread_sync_t sync;
lv_thread_t thread;
#endif
} lv_draw_vglite_unit_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
void lv_draw_buf_vglite_init_handlers(void);
void lv_draw_vglite_init(void);
void lv_draw_vglite_arc(lv_draw_unit_t * draw_unit, const lv_draw_arc_dsc_t * dsc,
const lv_area_t * coords);
void lv_draw_vglite_bg_img(lv_draw_unit_t * draw_unit, const lv_draw_bg_image_dsc_t * dsc,
const lv_area_t * coords);
void lv_draw_vglite_border(lv_draw_unit_t * draw_unit, const lv_draw_border_dsc_t * dsc,
const lv_area_t * coords);
void lv_draw_vglite_fill(lv_draw_unit_t * draw_unit, const lv_draw_fill_dsc_t * dsc,
const lv_area_t * coords);
void lv_draw_vglite_img(lv_draw_unit_t * draw_unit, const lv_draw_image_dsc_t * dsc,
const lv_area_t * coords);
void lv_draw_vglite_label(lv_draw_unit_t * draw_unit, const lv_draw_label_dsc_t * dsc,
const lv_area_t * coords);
void lv_draw_vglite_layer(lv_draw_unit_t * draw_unit, const lv_draw_image_dsc_t * draw_dsc,
const lv_area_t * coords);
void lv_draw_vglite_line(lv_draw_unit_t * draw_unit, const lv_draw_line_dsc_t * dsc);
/**********************
* MACROS
**********************/
#endif /*LV_USE_DRAW_VGLITE*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_DRAW_VGLITE_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/vglite/lv_draw_vglite_img.c | /**
* @file lv_draw_vglite_blend.c
*
*/
/**
* Copyright 2020-2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_vglite.h"
#if LV_USE_DRAW_VGLITE
#include "lv_vglite_buf.h"
#include "lv_vglite_matrix.h"
#include "lv_vglite_utils.h"
#include "../../../misc/lv_log.h"
/*********************
* DEFINES
*********************/
#if VGLITE_BLIT_SPLIT_ENABLED
/**
* BLIT split threshold - BLITs with width or height higher than this value will
* be done in multiple steps. Value must be multiple of stride alignment in px.
* For most color formats the alignment is 16px (except the index formats).
*/
#define VGLITE_BLIT_SPLIT_THR 352
/* Enable for logging debug traces. */
#define VGLITE_LOG_TRACE 0
#if VGLITE_LOG_TRACE
#define VGLITE_TRACE(fmt, ...) \
do { \
LV_LOG(fmt, ##__VA_ARGS__); \
} while (0)
#else
#define VGLITE_TRACE(fmt, ...) \
do { \
} while (0)
#endif
#endif
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**
* BLock Image Transfer - copy rectangular image from src_buf to dst_buf with effects.
* By default, image is copied directly, with optional opacity.
*
* @param[in] dest_area Destination area with relative coordinates to dest buffer
* @param[in] src_area Source area with relative coordinates to src buffer
* @param[in] opa Opacity
*
*/
static void _vglite_blit_single(const lv_area_t * dest_area, const lv_area_t * src_area, lv_opa_t opa);
#if VGLITE_BLIT_SPLIT_ENABLED
/**
* Move buffer pointer as close as possible to area, but with respect to alignment requirements.
*
* @param[in] buf Buffer address pointer
* @param[in] area Area with relative coordinates to the buffer
* @param[in] stride Stride of buffer in bytes
* @param[in] cf Color format of buffer
*/
static void _move_buf_close_to_area(void ** buf, lv_area_t * area, uint32_t stride, lv_color_format_t cf);
/**
* BLock Image Transfer - copy rectangular image from src_buf to dst_buf with effects.
* By default, image is copied directly, with optional opacity.
*
* @param dest_buf Destination buffer
* @param[in] dest_area Destination area with relative coordinates to dest buffer
* @param[in] dest_stride Stride of destination buffer in bytes
* @param[in] dest_cf Color format of destination buffer
* @param[in] src_buf Source buffer
* @param[in] src_area Source area with relative coordinates to src buffer
* @param[in] src_stride Stride of source buffer in bytes
* @param[in] src_cf Color format of source buffer
* @param[in] opa Opacity
*
*/
static void _vglite_blit_split(void * dest_buf, lv_area_t * dest_area, uint32_t dest_stride, lv_color_format_t dest_cf,
const void * src_buf, lv_area_t * src_area, uint32_t src_stride, lv_color_format_t src_cf,
lv_opa_t opa);
#else
/**
* BLock Image Transfer - copy rectangular image from src_buf to dst_buf with transformation.
* By default, image is copied directly, with optional opacity.
*
* @param[in] dest_area Area with relative coordinates to dest buffer
* @param[in] clip_area Clip area with relative coordinates to dest buffer
* @param[in] src_area Source area with relative coordinates to src buffer
* @param[in] dsc Image descriptor
*
*/
static void _vglite_blit_transform(const lv_area_t * dest_area, const lv_area_t * clip_area,
const lv_area_t * src_area, const lv_draw_image_dsc_t * dsc);
#endif /*VGLITE_BLIT_SPLIT_ENABLED*/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_vglite_img(lv_draw_unit_t * draw_unit, const lv_draw_image_dsc_t * dsc,
const lv_area_t * coords)
{
if(dsc->opa <= (lv_opa_t)LV_OPA_MIN)
return;
lv_layer_t * layer = draw_unit->target_layer;
const lv_image_dsc_t * img_dsc = dsc->src;
lv_area_t rel_coords;
lv_area_copy(&rel_coords, coords);
lv_area_move(&rel_coords, -layer->draw_buf_ofs.x, -layer->draw_buf_ofs.y);
lv_area_t rel_clip_area;
lv_area_copy(&rel_clip_area, draw_unit->clip_area);
lv_area_move(&rel_clip_area, -layer->draw_buf_ofs.x, -layer->draw_buf_ofs.y);
lv_area_t blend_area;
bool has_transform = dsc->rotation != 0 || dsc->zoom != LV_SCALE_NONE;
if(has_transform)
lv_area_copy(&blend_area, &rel_coords);
else if(!_lv_area_intersect(&blend_area, &rel_coords, &rel_clip_area))
return; /*Fully clipped, nothing to do*/
const void * src_buf = img_dsc->data;
lv_area_t src_area;
src_area.x1 = blend_area.x1 - (coords->x1 - layer->draw_buf_ofs.x);
src_area.y1 = blend_area.y1 - (coords->y1 - layer->draw_buf_ofs.y);
src_area.x2 = src_area.x1 + lv_area_get_width(coords) - 1;
src_area.y2 = src_area.y1 + lv_area_get_height(coords) - 1;
lv_color_format_t src_cf = img_dsc->header.cf;
uint32_t src_stride = img_dsc->header.stride;
/* Set src_vgbuf structure. */
vglite_set_src_buf(src_buf, lv_area_get_width(&src_area), lv_area_get_height(&src_area), src_stride, src_cf);
#if VGLITE_BLIT_SPLIT_ENABLED
void * dest_buf = lv_draw_buf_get_buf(&layer->draw_buf);
uint32_t dest_stride = lv_draw_buf_get_stride(&layer->draw_buf);
lv_color_format_t dest_cf = layer->draw_buf.color_format;
if(!has_transform)
_vglite_blit_split(dest_buf, &blend_area, dest_stride, dest_cf,
src_buf, &src_area, src_stride, src_cf, dsc->opa);
#else
if(has_transform)
_vglite_blit_transform(&blend_area, &rel_clip_area, &src_area, dsc);
else
_vglite_blit_single(&blend_area, &src_area, dsc->opa);
#endif
}
/**********************
* STATIC FUNCTIONS
**********************/
static void _vglite_blit(const lv_area_t * src_area, lv_opa_t opa)
{
vg_lite_error_t err = VG_LITE_SUCCESS;
vg_lite_buffer_t * dst_vgbuf = vglite_get_dest_buf();
vg_lite_buffer_t * src_vgbuf = vglite_get_src_buf();
uint32_t rect[] = {
(uint32_t)src_area->x1, /* start x */
(uint32_t)src_area->y1, /* start y */
(uint32_t)lv_area_get_width(src_area), /* width */
(uint32_t)lv_area_get_height(src_area) /* height */
};
uint32_t color;
vg_lite_blend_t blend;
if(opa >= (lv_opa_t)LV_OPA_MAX) {
color = 0xFFFFFFFFU;
blend = VG_LITE_BLEND_SRC_OVER;
src_vgbuf->transparency_mode = VG_LITE_IMAGE_TRANSPARENT;
}
else {
if(vg_lite_query_feature(gcFEATURE_BIT_VG_PE_PREMULTIPLY)) {
color = (opa << 24) | 0x00FFFFFFU;
}
else {
color = (opa << 24) | (opa << 16) | (opa << 8) | opa;
}
blend = VG_LITE_BLEND_SRC_OVER;
src_vgbuf->image_mode = VG_LITE_MULTIPLY_IMAGE_MODE;
src_vgbuf->transparency_mode = VG_LITE_IMAGE_TRANSPARENT;
}
vg_lite_matrix_t * vgmatrix = vglite_get_matrix();
err = vg_lite_blit_rect(dst_vgbuf, src_vgbuf, rect, vgmatrix, blend, color, VG_LITE_FILTER_POINT);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Blit rectangle failed.");
vglite_run();
}
static void _vglite_blit_single(const lv_area_t * dest_area, const lv_area_t * src_area, lv_opa_t opa)
{
/* Set scissor. */
vglite_set_scissor(dest_area);
/* Set vgmatrix. */
vglite_set_translation_matrix(dest_area);
/* Start blit. */
_vglite_blit(src_area, opa);
/* Disable scissor. */
vglite_disable_scissor();
}
#if VGLITE_BLIT_SPLIT_ENABLED
static void _move_buf_close_to_area(void ** buf, lv_area_t * area, uint32_t stride, lv_color_format_t cf)
{
uint8_t ** buf_u8 = (uint8_t **)buf;
uint8_t align_bytes = vglite_get_alignment(cf);
uint8_t bits_per_pixel = vglite_get_px_size(cf);
uint16_t align_pixels = align_bytes * 8 / bits_per_pixel;
if(area->x1 >= (int32_t)(area->x1 % align_pixels)) {
uint16_t shift_x = area->x1 - (area->x1 % align_pixels);
area->x1 -= shift_x;
area->x2 -= shift_x;
*buf_u8 += (shift_x * bits_per_pixel) / 8;
}
if(area->y1) {
uint16_t shift_y = area->y1;
area->y1 -= shift_y;
area->y2 -= shift_y;
*buf_u8 += shift_y * stride;
}
}
static void _vglite_blit_split(void * dest_buf, lv_area_t * dest_area, uint32_t dest_stride, lv_color_format_t dest_cf,
const void * src_buf, lv_area_t * src_area, uint32_t src_stride, lv_color_format_t src_cf,
lv_opa_t opa)
{
VGLITE_TRACE("Blit "
"Area: ([%d,%d], [%d,%d]) -> ([%d,%d], [%d,%d]) | "
"Size: ([%dx%d] -> [%dx%d]) | "
"Addr: (0x%x -> 0x%x)",
src_area->x1, src_area->y1, src_area->x2, src_area->y2,
dest_area->x1, dest_area->y1, dest_area->x2, dest_area->y2,
lv_area_get_width(src_area), lv_area_get_height(src_area),
lv_area_get_width(dest_area), lv_area_get_height(dest_area),
(uintptr_t)src_buf, (uintptr_t)dest_buf);
/* Move starting pointers as close as possible to [x1, y1], so coordinates are as small as possible */
_move_buf_close_to_area((void **)&src_buf, src_area, src_stride, src_cf);
_move_buf_close_to_area(&dest_buf, dest_area, dest_stride, dest_cf);
/* If we're in limit, do a single BLIT */
if((src_area->x2 < VGLITE_BLIT_SPLIT_THR) &&
(src_area->y2 < VGLITE_BLIT_SPLIT_THR)) {
/* Set new dest_vgbuf and src_vgbuf memory addresses */
vglite_set_dest_buf_ptr(dest_buf);
vglite_set_src_buf_ptr(src_buf);
_vglite_blit_single(dest_area, src_area, opa);
VGLITE_TRACE("Single "
"Area: ([%d,%d], [%d,%d]) -> ([%d,%d], [%d,%d]) | "
"Size: ([%dx%d] -> [%dx%d]) | "
"Addr: (0x%x -> 0x%x)",
src_area->x1, src_area->y1, src_area->x2, src_area->y2,
dest_area->x1, dest_area->y1, dest_area->x2, dest_area->y2,
lv_area_get_width(src_area), lv_area_get_height(src_area),
lv_area_get_width(dest_area), lv_area_get_height(dest_area),
(uintptr_t)src_buf, (uintptr_t)dest_buf);
};
/* Split the BLIT into multiple tiles */
VGLITE_TRACE("Split "
"Area: ([%d,%d], [%d,%d]) -> ([%d,%d], [%d,%d]) | "
"Size: ([%dx%d] -> [%dx%d]) | "
"Addr: (0x%x -> 0x%x)",
src_area->x1, src_area->y1, src_area->x2, src_area->y2,
dest_area->x1, dest_area->y1, dest_area->x2, dest_area->y2,
lv_area_get_width(src_area), lv_area_get_height(src_area),
lv_area_get_width(dest_area), lv_area_get_height(dest_area),
(uintptr_t)src_buf, (uintptr_t)dest_buf);
int32_t width = LV_MIN(lv_area_get_width(src_area), lv_area_get_width(dest_area));
int32_t height = LV_MIN(lv_area_get_height(src_area), lv_area_get_height(dest_area));
/* Number of tiles needed */
uint8_t total_tiles_x = (src_area->x1 + width + VGLITE_BLIT_SPLIT_THR - 1) /
VGLITE_BLIT_SPLIT_THR;
uint8_t total_tiles_y = (src_area->y1 + height + VGLITE_BLIT_SPLIT_THR - 1) /
VGLITE_BLIT_SPLIT_THR;
uint16_t shift_src_x = src_area->x1;
uint16_t shift_dest_x = dest_area->x1;
VGLITE_TRACE("X shift: src: %d, dst: %d", shift_src_x, shift_dest_x);
uint8_t * tile_dest_buf;
lv_area_t tile_dest_area;
const uint8_t * tile_src_buf;
lv_area_t tile_src_area;
for(uint8_t y = 0; y < total_tiles_y; y++) {
/* y1 always start from 0 */
tile_src_area.y1 = 0;
/* Calculate y2 coordinates */
if(y < total_tiles_y - 1)
tile_src_area.y2 = VGLITE_BLIT_SPLIT_THR - 1;
else
tile_src_area.y2 = height - y * VGLITE_BLIT_SPLIT_THR - 1;
/* No vertical shift, dest y is always in sync with src y */
tile_dest_area.y1 = tile_src_area.y1;
tile_dest_area.y2 = tile_src_area.y2;
/* Advance start pointer for every tile, except the first column (y = 0) */
tile_src_buf = (uint8_t *)src_buf + y * VGLITE_BLIT_SPLIT_THR * src_stride;
tile_dest_buf = (uint8_t *)dest_buf + y * VGLITE_BLIT_SPLIT_THR * dest_stride;
for(uint8_t x = 0; x < total_tiles_x; x++) {
/* x1 always start from the same shift */
tile_src_area.x1 = shift_src_x;
tile_dest_area.x1 = shift_dest_x;
if(x > 0) {
/* Advance start pointer for every tile, except the first raw (x = 0) */
tile_src_buf += VGLITE_BLIT_SPLIT_THR * vglite_get_px_size(src_cf) / 8;
tile_dest_buf += VGLITE_BLIT_SPLIT_THR * vglite_get_px_size(dest_cf) / 8;
}
/* Calculate x2 coordinates */
if(x < total_tiles_x - 1)
tile_src_area.x2 = VGLITE_BLIT_SPLIT_THR - 1;
else
tile_src_area.x2 = width - x * VGLITE_BLIT_SPLIT_THR - 1;
tile_dest_area.x2 = tile_src_area.x2;
/* Shift x2 coordinates */
tile_src_area.x2 += shift_src_x;
tile_dest_area.x2 += shift_dest_x;
/* Set new dest_vgbuf and src_vgbuf memory addresses */
vglite_set_dest_buf_ptr(tile_dest_buf);
vglite_set_src_buf_ptr(tile_src_buf);
_vglite_blit_single(&tile_dest_area, &tile_src_area, opa);
VGLITE_TRACE("Tile [%d, %d] "
"Area: ([%d,%d], [%d,%d]) -> ([%d,%d], [%d,%d]) | "
"Size: ([%dx%d] -> [%dx%d]) | "
"Addr: (0x%x -> 0x%x)",
x, y,
tile_src_area.x1, tile_src_area.y1, tile_src_area.x2, tile_src_area.y2,
tile_dest_area.x1, tile_dest_area.y1, tile_dest_area.x2, tile_dest_area.y2,
lv_area_get_width(&tile_src_area), lv_area_get_height(&tile_src_area),
lv_area_get_width(&tile_dest_area), lv_area_get_height(&tile_dest_area),
(uintptr_t)tile_src_buf, (uintptr_t)tile_dest_buf);
}
}
}
#else
static void _vglite_blit_transform(const lv_area_t * dest_area, const lv_area_t * clip_area,
const lv_area_t * src_area, const lv_draw_image_dsc_t * dsc)
{
/* Set scissor. */
vglite_set_scissor(clip_area);
/* Set vgmatrix. */
vglite_set_transformation_matrix(dest_area, dsc);
/* Start blit. */
_vglite_blit(src_area, dsc->opa);
/* Disable scissor. */
vglite_disable_scissor();
}
#endif /*VGLITE_BLIT_SPLIT_ENABLED*/
#endif /*LV_USE_DRAW_VGLITE*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/vglite/lv_draw_vglite_label.c | /**
* @file lv_draw_vglite_label.c
*
*/
/**
* Copyright 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_vglite.h"
#if LV_USE_DRAW_VGLITE
#include "lv_vglite_buf.h"
#include "lv_vglite_matrix.h"
#include "lv_vglite_utils.h"
#include "../../../stdlib/lv_string.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void _draw_vglite_letter(lv_draw_unit_t * draw_unit, lv_draw_glyph_dsc_t * glyph_draw_dsc,
lv_draw_fill_dsc_t * fill_draw_dsc, const lv_area_t * fill_area);
/**
* Draw letter (character bitmap blend) with optional color and opacity
*
* @param[in] dest_area Area with relative coordinates of destination buffer
* @param[in] mask_buf Mask buffer
* @param[in] mask_area Mask area with relative coordinates of source buffer
* @param[in] mask_stride Stride of mask buffer in bytes
* @param[in] color Color
* @param[in] opa Opacity
*
*/
static void _vglite_draw_letter(const lv_area_t * dest_area,
const void * mask_buf, const lv_area_t * mask_area, uint32_t mask_stride,
lv_color_t color, lv_opa_t opa);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* GLOBAL VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_vglite_label(lv_draw_unit_t * draw_unit, const lv_draw_label_dsc_t * dsc,
const lv_area_t * coords)
{
if(dsc->opa <= LV_OPA_MIN) return;
lv_draw_label_iterate_letters(draw_unit, dsc, coords, _draw_vglite_letter);
}
/**********************
* STATIC FUNCTIONS
**********************/
static void _draw_vglite_letter(lv_draw_unit_t * draw_unit, lv_draw_glyph_dsc_t * glyph_draw_dsc,
lv_draw_fill_dsc_t * fill_draw_dsc, const lv_area_t * fill_area)
{
if(glyph_draw_dsc) {
if(glyph_draw_dsc->bitmap == NULL) {
#if LV_USE_FONT_PLACEHOLDER
/* Draw a placeholder rectangle*/
lv_draw_border_dsc_t border_draw_dsc;
lv_draw_border_dsc_init(&border_draw_dsc);
border_draw_dsc.opa = glyph_draw_dsc->opa;
border_draw_dsc.color = glyph_draw_dsc->color;
border_draw_dsc.width = 1;
lv_draw_vglite_border(draw_unit, &border_draw_dsc, glyph_draw_dsc->bg_coords);
#endif
}
else if(glyph_draw_dsc->format == LV_DRAW_LETTER_BITMAP_FORMAT_A8) {
/*Do not draw transparent things*/
if(glyph_draw_dsc->opa <= LV_OPA_MIN)
return;
lv_layer_t * layer = draw_unit->target_layer;
lv_area_t blend_area;
if(!_lv_area_intersect(&blend_area, glyph_draw_dsc->letter_coords, draw_unit->clip_area))
return;
lv_area_move(&blend_area, -layer->draw_buf_ofs.x, -layer->draw_buf_ofs.y);
//void * dest_buf = lv_draw_buf_go_to_xy(&layer->draw_buf,
// blend_area.x1 - layer->draw_buf_ofs.x,
// blend_area.y1 - layer->draw_buf_ofs.y);
const uint8_t * mask_buf = glyph_draw_dsc->bitmap;
lv_area_t mask_area;
lv_area_copy(&mask_area, glyph_draw_dsc->letter_coords);
lv_area_move(&mask_area, -layer->draw_buf_ofs.x, -layer->draw_buf_ofs.y);
uint32_t mask_stride = lv_draw_buf_width_to_stride(
lv_area_get_width(glyph_draw_dsc->letter_coords),
LV_COLOR_FORMAT_A8);
if(mask_buf) {
mask_buf += mask_stride * (blend_area.y1 - glyph_draw_dsc->letter_coords->y1) +
(blend_area.x1 - glyph_draw_dsc->letter_coords->x1);
}
if(!vglite_buf_aligned(mask_buf, mask_stride, LV_COLOR_FORMAT_A8)) {
/* Draw a placeholder rectangle*/
lv_draw_border_dsc_t border_draw_dsc;
lv_draw_border_dsc_init(&border_draw_dsc);
border_draw_dsc.opa = glyph_draw_dsc->opa;
border_draw_dsc.color = glyph_draw_dsc->color;
border_draw_dsc.width = 1;
lv_draw_vglite_border(draw_unit, &border_draw_dsc, glyph_draw_dsc->bg_coords);
}
else {
_vglite_draw_letter(&blend_area, mask_buf, &mask_area, mask_stride,
glyph_draw_dsc->color, glyph_draw_dsc->opa);
}
}
else if(glyph_draw_dsc->format == LV_DRAW_LETTER_BITMAP_FORMAT_IMAGE) {
#if LV_USE_IMGFONT
lv_draw_img_dsc_t img_dsc;
lv_draw_img_dsc_init(&img_dsc);
img_dsc.angle = 0;
img_dsc.zoom = LV_ZOOM_NONE;
img_dsc.opa = glyph_draw_dsc->opa;
img_dsc.src = glyph_draw_dsc->bitmap;
lv_draw_vglite_img(draw_unit, &img_dsc, glyph_draw_dsc->letter_coords);
#endif
}
}
if(fill_draw_dsc && fill_area) {
lv_draw_vglite_fill(draw_unit, fill_draw_dsc, fill_area);
}
}
static void _vglite_draw_letter(const lv_area_t * dest_area,
const void * mask_buf, const lv_area_t * mask_area, uint32_t mask_stride,
lv_color_t color, lv_opa_t opa)
{
vg_lite_error_t err = VG_LITE_SUCCESS;
vg_lite_buffer_t * dst_vgbuf = vglite_get_dest_buf();
vg_lite_buffer_t mask_vgbuf;
mask_vgbuf.format = VG_LITE_A8;
mask_vgbuf.tiled = VG_LITE_LINEAR;
mask_vgbuf.image_mode = VG_LITE_MULTIPLY_IMAGE_MODE;
mask_vgbuf.transparency_mode = VG_LITE_IMAGE_TRANSPARENT;
mask_vgbuf.width = (int32_t)lv_area_get_width(mask_area);
mask_vgbuf.height = (int32_t)lv_area_get_height(mask_area);
mask_vgbuf.stride = (int32_t)mask_stride;
lv_memset(&mask_vgbuf.yuv, 0, sizeof(mask_vgbuf.yuv));
mask_vgbuf.memory = (void *)mask_buf;
mask_vgbuf.address = (uint32_t)mask_vgbuf.memory;
mask_vgbuf.handle = NULL;
uint32_t rect[] = {
(uint32_t)0, /* start x */
(uint32_t)0, /* start y */
(uint32_t)lv_area_get_width(mask_area), /* width */
(uint32_t)lv_area_get_height(mask_area) /* height */
};
lv_color32_t col32 = lv_color_to_32(color, opa);
vg_lite_color_t vgcol = vglite_get_color(col32, false);
/* Set vgmatrix. */
vglite_set_translation_matrix(dest_area);
vg_lite_matrix_t * vgmatrix = vglite_get_matrix();
/*Blit with font color as paint color*/
err = vg_lite_blit_rect(dst_vgbuf, &mask_vgbuf, rect, vgmatrix, VG_LITE_BLEND_SRC_OVER, vgcol,
VG_LITE_FILTER_POINT);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Draw letter failed.");
vglite_run();
}
#endif /*LV_USE_DRAW_VGLITE*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/vglite/lv_vglite_path.c | /**
* @file lv_vglite_path.c
*
*/
/**
* Copyright 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_vglite_path.h"
#if LV_USE_DRAW_VGLITE
#include "vg_lite.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void vglite_create_rect_path_data(int32_t * path_data, uint32_t * path_data_size,
int32_t radius,
const lv_area_t * coords)
{
int32_t rect_width = lv_area_get_width(coords);
int32_t rect_height = lv_area_get_height(coords);
/* Get the final radius. Can't be larger than the half of the shortest side */
int32_t shortest_side = LV_MIN(rect_width, rect_height);
int32_t final_radius = LV_MIN(radius, shortest_side / 2);
/* Path data element index */
uint8_t pidx = 0;
if((radius == (int32_t)LV_RADIUS_CIRCLE) && (rect_width == rect_height)) {
/* Get the control point offset for rounded cases */
int32_t cpoff = (int32_t)((float)final_radius * BEZIER_OPTIM_CIRCLE);
/* Circle case */
/* Starting point */
path_data[pidx++] = VLC_OP_MOVE;
path_data[pidx++] = coords->x1 + final_radius;
path_data[pidx++] = coords->y1;
/* Top-right arc */
path_data[pidx++] = VLC_OP_CUBIC_REL;
path_data[pidx++] = cpoff;
path_data[pidx++] = 0;
path_data[pidx++] = final_radius;
path_data[pidx++] = final_radius - cpoff;
path_data[pidx++] = final_radius;
path_data[pidx++] = final_radius;
/* Bottom-right arc*/
path_data[pidx++] = VLC_OP_CUBIC_REL;
path_data[pidx++] = 0;
path_data[pidx++] = cpoff;
path_data[pidx++] = cpoff - final_radius;
path_data[pidx++] = final_radius;
path_data[pidx++] = 0 - final_radius;
path_data[pidx++] = final_radius;
/* Bottom-left arc */
path_data[pidx++] = VLC_OP_CUBIC_REL;
path_data[pidx++] = 0 - cpoff;
path_data[pidx++] = 0;
path_data[pidx++] = 0 - final_radius;
path_data[pidx++] = cpoff - final_radius;
path_data[pidx++] = 0 - final_radius;
path_data[pidx++] = 0 - final_radius;
/* Top-left arc*/
path_data[pidx++] = VLC_OP_CUBIC_REL;
path_data[pidx++] = 0;
path_data[pidx++] = 0 - cpoff;
path_data[pidx++] = final_radius - cpoff;
path_data[pidx++] = 0 - final_radius;
path_data[pidx++] = final_radius;
path_data[pidx++] = 0 - final_radius;
/* Ending point */
path_data[pidx++] = VLC_OP_END;
}
else if(radius > 0) {
/* Get the control point offset for rounded cases */
int32_t cpoff = (int32_t)((float)final_radius * BEZIER_OPTIM_CIRCLE);
/* Rounded rectangle case */
/* Starting point */
path_data[pidx++] = VLC_OP_MOVE;
path_data[pidx++] = coords->x1 + final_radius;
path_data[pidx++] = coords->y1;
/* Top side */
path_data[pidx++] = VLC_OP_LINE;
path_data[pidx++] = coords->x2 - final_radius + 1; // Extended for VGLite
path_data[pidx++] = coords->y1;
/* Top-right corner */
path_data[pidx++] = VLC_OP_CUBIC_REL;
path_data[pidx++] = cpoff;
path_data[pidx++] = 0;
path_data[pidx++] = final_radius;
path_data[pidx++] = final_radius - cpoff;
path_data[pidx++] = final_radius;
path_data[pidx++] = final_radius;
/* Right side */
path_data[pidx++] = VLC_OP_LINE;
path_data[pidx++] = coords->x2 + 1; // Extended for VGLite
path_data[pidx++] = coords->y2 - final_radius + 1; // Extended for VGLite
/* Bottom-right corner*/
path_data[pidx++] = VLC_OP_CUBIC_REL;
path_data[pidx++] = 0;
path_data[pidx++] = cpoff;
path_data[pidx++] = cpoff - final_radius;
path_data[pidx++] = final_radius;
path_data[pidx++] = 0 - final_radius;
path_data[pidx++] = final_radius;
/* Bottom side */
path_data[pidx++] = VLC_OP_LINE;
path_data[pidx++] = coords->x1 + final_radius;
path_data[pidx++] = coords->y2 + 1; // Extended for VGLite
/* Bottom-left corner */
path_data[pidx++] = VLC_OP_CUBIC_REL;
path_data[pidx++] = 0 - cpoff;
path_data[pidx++] = 0;
path_data[pidx++] = 0 - final_radius;
path_data[pidx++] = cpoff - final_radius;
path_data[pidx++] = 0 - final_radius;
path_data[pidx++] = 0 - final_radius;
/* Left side*/
path_data[pidx++] = VLC_OP_LINE;
path_data[pidx++] = coords->x1;
path_data[pidx++] = coords->y1 + final_radius;
/* Top-left corner */
path_data[pidx++] = VLC_OP_CUBIC_REL;
path_data[pidx++] = 0;
path_data[pidx++] = 0 - cpoff;
path_data[pidx++] = final_radius - cpoff;
path_data[pidx++] = 0 - final_radius;
path_data[pidx++] = final_radius;
path_data[pidx++] = 0 - final_radius;
/* Ending point */
path_data[pidx++] = VLC_OP_END;
}
else {
/* Non-rounded rectangle case */
/* Starting point */
path_data[pidx++] = VLC_OP_MOVE;
path_data[pidx++] = coords->x1;
path_data[pidx++] = coords->y1;
/* Top side */
path_data[pidx++] = VLC_OP_LINE;
path_data[pidx++] = coords->x2 + 1; // Extended for VGLite
path_data[pidx++] = coords->y1;
/* Right side */
path_data[pidx++] = VLC_OP_LINE;
path_data[pidx++] = coords->x2 + 1; // Extended for VGLite
path_data[pidx++] = coords->y2 + 1; // Extended for VGLite
/* Bottom side */
path_data[pidx++] = VLC_OP_LINE;
path_data[pidx++] = coords->x1;
path_data[pidx++] = coords->y2 + 1; // Extended for VGLite
/* Left side*/
path_data[pidx++] = VLC_OP_LINE;
path_data[pidx++] = coords->x1;
path_data[pidx++] = coords->y1;
/* Ending point */
path_data[pidx++] = VLC_OP_END;
}
/* Resulting path size */
*path_data_size = pidx * sizeof(int32_t);
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif /*LV_USE_DRAW_VGLITE*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/vglite/lv_draw_vglite.c | /**
* @file lv_draw_vglite.c
*
*/
/**
* Copyright 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_vglite.h"
#if LV_USE_DRAW_VGLITE
#include "lv_vglite_buf.h"
#include "lv_vglite_utils.h"
#include "../../../display/lv_display_private.h"
/*********************
* DEFINES
*********************/
#define DRAW_UNIT_ID_VGLITE 2
#if LV_USE_OS
#define VGLITE_TASK_BUF_SIZE 10
#endif
/**********************
* TYPEDEFS
**********************/
#if LV_USE_OS
/**
* Structure of pending vglite draw task
*/
typedef struct _vglite_draw_task_t {
lv_draw_task_t * task;
bool flushed;
} vglite_draw_tasks_t;
#endif
/**********************
* STATIC PROTOTYPES
**********************/
/*
* Dispatch a task to the VGLite unit.
* Return 1 if task was dispatched, 0 otherwise (task not supported).
*/
static int32_t _vglite_dispatch(lv_draw_unit_t * draw_unit, lv_layer_t * layer);
/*
* Evaluate a task and set the score and preferred VGLite unit.
* Return 1 if task is preferred, 0 otherwise (task is not supported).
*/
static int32_t _vglite_evaluate(lv_draw_unit_t * draw_unit, lv_draw_task_t * task);
#if LV_USE_OS
static void _vglite_render_thread_cb(void * ptr);
#endif
static void _vglite_execute_drawing(lv_draw_vglite_unit_t * u);
/**********************
* STATIC VARIABLES
**********************/
#if LV_USE_OS
/*
* Circular buffer to hold the queued and the flushed tasks.
* Two indexes, _head and _tail, are used to signal the beginning
* and the end of the valid tasks that are pending.
*/
static vglite_draw_tasks_t _draw_task_buf[VGLITE_TASK_BUF_SIZE];
static volatile int _head = 0;
static volatile int _tail = 0;
#endif
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_vglite_init(void)
{
lv_draw_buf_vglite_init_handlers();
lv_draw_vglite_unit_t * draw_vglite_unit = lv_draw_create_unit(sizeof(lv_draw_vglite_unit_t));
draw_vglite_unit->base_unit.dispatch_cb = _vglite_dispatch;
draw_vglite_unit->base_unit.evaluate_cb = _vglite_evaluate;
#if LV_USE_OS
lv_thread_init(&draw_vglite_unit->thread, LV_THREAD_PRIO_HIGH, _vglite_render_thread_cb, 8 * 1024, draw_vglite_unit);
#endif
}
/**********************
* STATIC FUNCTIONS
**********************/
static inline bool _vglite_cf_supported(lv_color_format_t cf)
{
// Add here the platform specific code for supported formats.
bool is_cf_unsupported = (cf == LV_COLOR_FORMAT_RGB565A8 || cf == LV_COLOR_FORMAT_RGB888);
return (!is_cf_unsupported);
}
static int32_t _vglite_evaluate(lv_draw_unit_t * u, lv_draw_task_t * t)
{
LV_UNUSED(u);
switch(t->type) {
case LV_DRAW_TASK_TYPE_FILL:
if(t->preference_score > 80) {
t->preference_score = 80;
t->preferred_draw_unit_id = DRAW_UNIT_ID_VGLITE;
}
return 1;
case LV_DRAW_TASK_TYPE_LINE:
case LV_DRAW_TASK_TYPE_ARC:
if(t->preference_score > 90) {
t->preference_score = 90;
t->preferred_draw_unit_id = DRAW_UNIT_ID_VGLITE;
}
return 1;
case LV_DRAW_TASK_TYPE_LABEL:
if(t->preference_score > 95) {
t->preference_score = 95;
t->preferred_draw_unit_id = DRAW_UNIT_ID_VGLITE;
}
return 1;
case LV_DRAW_TASK_TYPE_BORDER: {
const lv_draw_border_dsc_t * draw_dsc = (lv_draw_border_dsc_t *) t->draw_dsc;
if(draw_dsc->side != (lv_border_side_t)LV_BORDER_SIDE_FULL)
return 0;
if(t->preference_score > 90) {
t->preference_score = 90;
t->preferred_draw_unit_id = DRAW_UNIT_ID_VGLITE;
}
return 1;
}
case LV_DRAW_TASK_TYPE_BG_IMG: {
const lv_draw_bg_image_dsc_t * draw_dsc = (lv_draw_bg_image_dsc_t *) t->draw_dsc;
lv_image_src_t src_type = lv_image_src_get_type(draw_dsc->src);
if(src_type != LV_IMAGE_SRC_SYMBOL) {
bool has_recolor = (draw_dsc->recolor_opa != LV_OPA_TRANSP);
if(has_recolor
|| (!_vglite_cf_supported(draw_dsc->img_header.cf))
|| (!vglite_buf_aligned(draw_dsc->src, draw_dsc->img_header.stride, draw_dsc->img_header.cf))
)
return 0;
}
if(t->preference_score > 80) {
t->preference_score = 80;
t->preferred_draw_unit_id = DRAW_UNIT_ID_VGLITE;
}
return 1;
}
case LV_DRAW_TASK_TYPE_LAYER: {
const lv_draw_image_dsc_t * draw_dsc = (lv_draw_image_dsc_t *) t->draw_dsc;
lv_layer_t * layer_to_draw = (lv_layer_t *)draw_dsc->src;
lv_draw_buf_t * draw_buf = &layer_to_draw->draw_buf;
bool has_recolor = (draw_dsc->recolor_opa != LV_OPA_TRANSP);
if(has_recolor
|| (!_vglite_cf_supported(draw_buf->color_format))
)
return 0;
if(t->preference_score > 80) {
t->preference_score = 80;
t->preferred_draw_unit_id = DRAW_UNIT_ID_VGLITE;
}
return 1;
}
case LV_DRAW_TASK_TYPE_IMAGE: {
lv_draw_image_dsc_t * draw_dsc = (lv_draw_image_dsc_t *) t->draw_dsc;
const lv_image_dsc_t * img_dsc = draw_dsc->src;
bool has_recolor = (draw_dsc->recolor_opa != LV_OPA_TRANSP);
#if VGLITE_BLIT_SPLIT_ENABLED
bool has_transform = (draw_dsc->angle != 0 || draw_dsc->zoom != LV_ZOOM_NONE);
#endif
if(has_recolor
#if VGLITE_BLIT_SPLIT_ENABLED
|| has_transform
#endif
|| (!_vglite_cf_supported(img_dsc->header.cf))
|| (!vglite_buf_aligned(img_dsc->data, img_dsc->header.stride, img_dsc->header.cf))
)
return 0;
if(t->preference_score > 80) {
t->preference_score = 80;
t->preferred_draw_unit_id = DRAW_UNIT_ID_VGLITE;
}
return 1;
}
default:
return 0;
}
return 0;
}
static int32_t _vglite_dispatch(lv_draw_unit_t * draw_unit, lv_layer_t * layer)
{
lv_draw_vglite_unit_t * draw_vglite_unit = (lv_draw_vglite_unit_t *) draw_unit;
/* Return immediately if it's busy with draw task. */
if(draw_vglite_unit->task_act)
return 0;
/* Return if target buffer format is not supported.
*
* FIXME: Source format and destination format support is different!
*/
if(!_vglite_cf_supported(layer->draw_buf.color_format))
return 0;
/* Try to get an ready to draw. */
lv_draw_task_t * t = lv_draw_get_next_available_task(layer, NULL, DRAW_UNIT_ID_VGLITE);
/* Return 0 is no selection, some tasks can be supported by other units. */
if(t == NULL || t->preferred_draw_unit_id != DRAW_UNIT_ID_VGLITE)
return 0;
void * buf = lv_draw_layer_alloc_buf(layer);
if(buf == NULL)
return -1;
t->state = LV_DRAW_TASK_STATE_IN_PROGRESS;
draw_vglite_unit->base_unit.target_layer = layer;
draw_vglite_unit->base_unit.clip_area = &t->clip_area;
draw_vglite_unit->task_act = t;
#if LV_USE_OS
/* Let the render thread work. */
lv_thread_sync_signal(&draw_vglite_unit->sync);
#else
_vglite_execute_drawing(draw_vglite_unit);
draw_vglite_unit->task_act->state = LV_DRAW_TASK_STATE_READY;
draw_vglite_unit->task_act = NULL;
/* The draw unit is free now. Request a new dispatching as it can get a new task. */
lv_draw_dispatch_request();
#endif
return 1;
}
static void _vglite_execute_drawing(lv_draw_vglite_unit_t * u)
{
lv_draw_task_t * t = u->task_act;
lv_draw_unit_t * draw_unit = (lv_draw_unit_t *)u;
/* Set target buffer */
lv_layer_t * layer = draw_unit->target_layer;
vglite_set_dest_buf(&layer->draw_buf);
/* Invalidate cache */
lv_draw_buf_invalidate_cache(&layer->draw_buf, (const char *)&t->area);
switch(t->type) {
case LV_DRAW_TASK_TYPE_LABEL:
lv_draw_vglite_label(draw_unit, t->draw_dsc, &t->area);
break;
case LV_DRAW_TASK_TYPE_FILL:
lv_draw_vglite_fill(draw_unit, t->draw_dsc, &t->area);
break;
case LV_DRAW_TASK_TYPE_BORDER:
lv_draw_vglite_border(draw_unit, t->draw_dsc, &t->area);
break;
case LV_DRAW_TASK_TYPE_BG_IMG:
lv_draw_vglite_bg_img(draw_unit, t->draw_dsc, &t->area);
break;
case LV_DRAW_TASK_TYPE_IMAGE:
lv_draw_vglite_img(draw_unit, t->draw_dsc, &t->area);
break;
case LV_DRAW_TASK_TYPE_ARC:
lv_draw_vglite_arc(draw_unit, t->draw_dsc, &t->area);
break;
case LV_DRAW_TASK_TYPE_LINE:
lv_draw_vglite_line(draw_unit, t->draw_dsc);
break;
case LV_DRAW_TASK_TYPE_LAYER:
lv_draw_vglite_layer(draw_unit, t->draw_dsc, &t->area);
break;
default:
break;
}
#if LV_USE_PARALLEL_DRAW_DEBUG
/* Layers manage it for themselves. */
if(t->type != LV_DRAW_TASK_TYPE_LAYER) {
lv_area_t draw_area;
if(!_lv_area_intersect(&draw_area, &t->area, u->base_unit.clip_area))
return;
int32_t idx = 0;
lv_disp_t * disp = _lv_refr_get_disp_refreshing();
lv_draw_unit_t * draw_unit_tmp = disp->draw_unit_head;
while(draw_unit_tmp != (lv_draw_unit_t *)u) {
draw_unit_tmp = draw_unit_tmp->next;
idx++;
}
lv_draw_rect_dsc_t rect_dsc;
lv_draw_rect_dsc_init(&rect_dsc);
rect_dsc.bg_color = lv_palette_main(idx % _LV_PALETTE_LAST);
rect_dsc.border_color = rect_dsc.bg_color;
rect_dsc.bg_opa = LV_OPA_10;
rect_dsc.border_opa = LV_OPA_80;
rect_dsc.border_width = 1;
lv_draw_vglite_rect((lv_draw_unit_t *)u, &rect_dsc, &draw_area);
lv_point_t txt_size;
lv_txt_get_size(&txt_size, "W", LV_FONT_DEFAULT, 0, 0, 100, LV_TEXT_FLAG_NONE);
lv_area_t txt_area;
txt_area.x1 = draw_area.x1;
txt_area.y1 = draw_area.y1;
txt_area.x2 = draw_area.x1 + txt_size.x - 1;
txt_area.y2 = draw_area.y1 + txt_size.y - 1;
lv_draw_rect_dsc_init(&rect_dsc);
rect_dsc.bg_color = lv_color_white();
lv_draw_vglite_rect((lv_draw_unit_t *)u, &rect_dsc, &txt_area);
char buf[8];
lv_snprintf(buf, sizeof(buf), "%d", idx);
lv_draw_label_dsc_t label_dsc;
lv_draw_label_dsc_init(&label_dsc);
label_dsc.color = lv_color_black();
label_dsc.text = buf;
lv_draw_vglite_label((lv_draw_unit_t *)u, &label_dsc, &txt_area);
}
#endif
}
#if LV_USE_OS
static inline void _vglite_queue_task(lv_draw_task_t * task_act)
{
_draw_task_buf[_tail].task = task_act;
_draw_task_buf[_tail].flushed = false;
_tail = (_tail + 1) % VGLITE_TASK_BUF_SIZE;
}
static inline void _vglite_signal_task_ready(lv_draw_task_t * task_act)
{
if(vglite_cmd_buf_is_flushed()) {
int end = (_head < _tail) ? _tail : _tail + VGLITE_TASK_BUF_SIZE;
for(int i = _head; i < end; i++) {
/* Previous flushed tasks are ready now. */
if(_draw_task_buf[i % VGLITE_TASK_BUF_SIZE].flushed) {
lv_draw_task_t * task = _draw_task_buf[i % VGLITE_TASK_BUF_SIZE].task;
/* Signal the ready state to dispatcher. */
task->state = LV_DRAW_TASK_STATE_READY;
_head = (_head + 1) % VGLITE_TASK_BUF_SIZE;
/* No need to cleanup the tasks in buffer as we advance with the _head. */
}
else {
/* Those tasks have been flushed now. */
_draw_task_buf[i % VGLITE_TASK_BUF_SIZE].flushed = true;
}
}
}
if(task_act)
LV_ASSERT_MSG(_tail != _head, "VGLite task buffer full.");
}
static void _vglite_render_thread_cb(void * ptr)
{
lv_draw_vglite_unit_t * u = ptr;
lv_thread_sync_init(&u->sync);
while(1) {
/*
* Wait for sync if no task received or _draw_task_buf is empty.
* The thread will have to run as much as there are pending tasks.
*/
while(u->task_act == NULL && _head == _tail) {
lv_thread_sync_wait(&u->sync);
}
if(u->task_act) {
_vglite_queue_task((void *)u->task_act);
_vglite_execute_drawing(u);
}
else {
/*
* Update the flush status for last pending tasks.
* vg_lite_flush() will early return if there is nothing to submit.
*/
vglite_run();
}
_vglite_signal_task_ready((void *)u->task_act);
/* Cleanup. */
u->task_act = NULL;
/* The draw unit is free now. Request a new dispatching as it can get a new task. */
lv_draw_dispatch_request();
}
}
#endif
#endif /*LV_USE_DRAW_VGLITE*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/vglite/lv_draw_vglite_layer.c | /**
* @file lv_draw_vglite_layer.c
*
*/
/**
* Copyright 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_vglite.h"
#if LV_USE_DRAW_VGLITE
#include "../../../stdlib/lv_string.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_vglite_layer(lv_draw_unit_t * draw_unit, const lv_draw_image_dsc_t * draw_dsc,
const lv_area_t * coords)
{
lv_layer_t * layer_to_draw = (lv_layer_t *)draw_dsc->src;
/*It can happen that nothing was draw on a layer and therefore its buffer is not allocated.
*In this case just return. */
if(layer_to_draw->draw_buf.buf == NULL)
return;
lv_image_dsc_t img_dsc;
img_dsc.header.w = layer_to_draw->draw_buf.width;
img_dsc.header.h = layer_to_draw->draw_buf.height;
img_dsc.header.cf = layer_to_draw->draw_buf.color_format;
img_dsc.header.always_zero = 0;
img_dsc.data = lv_draw_buf_get_buf(&layer_to_draw->draw_buf);
lv_draw_image_dsc_t new_draw_dsc;
lv_memcpy(&new_draw_dsc, draw_dsc, sizeof(lv_draw_image_dsc_t));
new_draw_dsc.src = &img_dsc;
lv_draw_vglite_img(draw_unit, &new_draw_dsc, coords);
}
#endif /*LV_USE_DRAW_VGLITE*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/vglite/lv_vglite_utils.c | /**
* @file lv_vglite_utils.c
*
*/
/**
* Copyright 2022, 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_vglite_utils.h"
#if LV_USE_DRAW_VGLITE
#include "lv_vglite_buf.h"
#include "../../../core/lv_refr.h"
#if LV_USE_OS
#include "vg_lite_gpu.h"
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
#if LV_USE_OS
static volatile bool _cmd_buf_flushed = false;
#endif
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
#if LV_USE_OS
bool vglite_cmd_buf_is_flushed(void)
{
return _cmd_buf_flushed;
}
#endif
void vglite_run(void)
{
#if LV_USE_OS
vg_lite_gpu_state_t gpu_state = vg_lite_get_gpu_state();
if(gpu_state == VG_LITE_GPU_BUSY) {
_cmd_buf_flushed = false;
return;
}
#endif
/*
* For multithreading version (with OS), we simply flush the command buffer
* and the vglite draw thread will signal the dispatcher for completed tasks.
* Without OS, we process the tasks and signal them as complete one by one.
*/
#if LV_USE_OS
LV_ASSERT_MSG(vg_lite_flush() == VG_LITE_SUCCESS, "Flush failed.");
_cmd_buf_flushed = true;
#else
LV_ASSERT_MSG(vg_lite_finish() == VG_LITE_SUCCESS, "Finish failed.");
#endif
}
vg_lite_color_t vglite_get_color(lv_color32_t lv_col32, bool gradient)
{
vg_lite_color_t vg_col32;
/* Only pre-multiply color if hardware pre-multiplication is not present */
if(!vg_lite_query_feature(gcFEATURE_BIT_VG_PE_PREMULTIPLY)) {
lv_col32.red = (uint8_t)((lv_col32.red * lv_col32.alpha) >> 8);
lv_col32.green = (uint8_t)((lv_col32.green * lv_col32.alpha) >> 8);
lv_col32.blue = (uint8_t)((lv_col32.blue * lv_col32.alpha) >> 8);
}
if(!gradient)
/* The color is in ABGR8888 format with red channel in the lower 8 bits. */
vg_col32 = ((vg_lite_color_t)lv_col32.alpha << 24) | ((vg_lite_color_t)lv_col32.blue << 16) |
((vg_lite_color_t)lv_col32.green << 8) | (vg_lite_color_t)lv_col32.red;
else
/* The gradient color is in ARGB8888 format with blue channel in the lower 8 bits. */
vg_col32 = ((vg_lite_color_t)lv_col32.alpha << 24) | ((vg_lite_color_t)lv_col32.red << 16) |
((vg_lite_color_t)lv_col32.green << 8) | (vg_lite_color_t)lv_col32.blue;
return vg_col32;
}
vg_lite_blend_t vglite_get_blend_mode(lv_blend_mode_t lv_blend_mode)
{
vg_lite_blend_t vg_blend_mode;
switch(lv_blend_mode) {
case LV_BLEND_MODE_ADDITIVE:
vg_blend_mode = VG_LITE_BLEND_ADDITIVE;
break;
case LV_BLEND_MODE_SUBTRACTIVE:
vg_blend_mode = VG_LITE_BLEND_SUBTRACT;
break;
case LV_BLEND_MODE_MULTIPLY:
vg_blend_mode = VG_LITE_BLEND_MULTIPLY;
break;
default:
vg_blend_mode = VG_LITE_BLEND_SRC_OVER;
break;
}
return vg_blend_mode;
}
vg_lite_buffer_format_t vglite_get_buf_format(lv_color_format_t cf)
{
vg_lite_buffer_format_t vg_buffer_format = VG_LITE_BGR565;
switch(cf) {
/*<=1 byte (+alpha) formats*/
case LV_COLOR_FORMAT_L8:
vg_buffer_format = VG_LITE_L8;
break;
case LV_COLOR_FORMAT_A8:
vg_buffer_format = VG_LITE_A8;
break;
case LV_COLOR_FORMAT_I1:
vg_buffer_format = VG_LITE_INDEX_1;
break;
case LV_COLOR_FORMAT_I2:
vg_buffer_format = VG_LITE_INDEX_2;
break;
case LV_COLOR_FORMAT_I4:
vg_buffer_format = VG_LITE_INDEX_4;
break;
case LV_COLOR_FORMAT_I8:
vg_buffer_format = VG_LITE_INDEX_8;
break;
/*2 byte (+alpha) formats*/
case LV_COLOR_FORMAT_RGB565:
vg_buffer_format = VG_LITE_BGR565;
break;
case LV_COLOR_FORMAT_RGB565A8:
LV_ASSERT_MSG(false, "Unsupported color format.");
break;
/*3 byte (+alpha) formats*/
case LV_COLOR_FORMAT_RGB888:
LV_ASSERT_MSG(false, "Unsupported color format.");
break;
case LV_COLOR_FORMAT_ARGB8888:
vg_buffer_format = VG_LITE_BGRA8888;
break;
case LV_COLOR_FORMAT_XRGB8888:
vg_buffer_format = VG_LITE_BGRX8888;
break;
default:
LV_ASSERT_MSG(false, "Unsupported color format.");
break;
}
return vg_buffer_format;
}
uint8_t vglite_get_px_size(lv_color_format_t cf)
{
uint8_t bits_per_pixel = LV_COLOR_DEPTH;
switch(cf) {
case LV_COLOR_FORMAT_I1:
bits_per_pixel = 1;
break;
case LV_COLOR_FORMAT_I2:
bits_per_pixel = 2;
break;
case LV_COLOR_FORMAT_I4:
bits_per_pixel = 4;
break;
case LV_COLOR_FORMAT_I8:
case LV_COLOR_FORMAT_A8:
case LV_COLOR_FORMAT_L8:
bits_per_pixel = 8;
break;
case LV_COLOR_FORMAT_RGB565:
bits_per_pixel = 16;
break;
case LV_COLOR_FORMAT_RGB565A8:
case LV_COLOR_FORMAT_RGB888:
bits_per_pixel = 24;
break;
case LV_COLOR_FORMAT_ARGB8888:
case LV_COLOR_FORMAT_XRGB8888:
bits_per_pixel = 32;
break;
case LV_COLOR_FORMAT_NATIVE_REVERSED:
bits_per_pixel = LV_COLOR_DEPTH;
break;
default:
LV_ASSERT_MSG(false, "Unsupported buffer format.");
break;
}
return bits_per_pixel;
}
uint8_t vglite_get_alignment(lv_color_format_t cf)
{
uint8_t align_bytes = LV_COLOR_DEPTH / 8 * 16; //16 pixels
switch(cf) {
case LV_COLOR_FORMAT_I1:
case LV_COLOR_FORMAT_I2:
case LV_COLOR_FORMAT_I4:
align_bytes = 8;
break;
case LV_COLOR_FORMAT_I8:
case LV_COLOR_FORMAT_A8:
case LV_COLOR_FORMAT_L8:
align_bytes = 16;
break;
case LV_COLOR_FORMAT_RGB565:
align_bytes = 32;
break;
case LV_COLOR_FORMAT_RGB565A8:
case LV_COLOR_FORMAT_RGB888:
align_bytes = 48;
break;
case LV_COLOR_FORMAT_ARGB8888:
case LV_COLOR_FORMAT_XRGB8888:
align_bytes = 64;
break;
case LV_COLOR_FORMAT_NATIVE_REVERSED:
align_bytes = LV_COLOR_DEPTH / 8 * 16;
break;
default:
LV_ASSERT_MSG(false, "Unsupported buffer format.");
break;
}
return align_bytes;
}
bool vglite_buf_aligned(const void * buf, uint32_t stride, lv_color_format_t cf)
{
uint8_t align_bytes = vglite_get_alignment(cf);
/* No alignment requirement for destination buffer when using mode VG_LITE_LINEAR */
/* Test for pointer alignment */
if((uintptr_t)buf % align_bytes) {
LV_LOG_ERROR("Buffer address (0x%x) not aligned to %d bytes.",
(size_t)buf, align_bytes);
return false;
}
/* Test for stride alignment */
if(stride % align_bytes) {
LV_LOG_ERROR("Buffer stride (%d bytes) not aligned to %d bytes.",
stride, align_bytes);
return false;
}
return true;
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif /*LV_USE_DRAW_VGLITE*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/vglite/lv_vglite_utils.h | /**
* @file lv_vglite_utils.h
*
*/
/**
* Copyright 2022, 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
#ifndef LV_VGLITE_UTILS_H
#define LV_VGLITE_UTILS_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../../../lv_conf_internal.h"
#if LV_USE_DRAW_VGLITE
#include "../../sw/lv_draw_sw.h"
#include "vg_lite.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**
* Enable scissor and set the clipping box.
*
* @param[in] clip_area Clip area with relative coordinates of destination buffer
*
*/
static inline void vglite_set_scissor(const lv_area_t * clip_area);
/**
* Disable scissor.
*
*/
static inline void vglite_disable_scissor(void);
/**********************
* GLOBAL PROTOTYPES
**********************/
#if LV_USE_OS
/**
* Get VG-Lite command buffer flushed status.
*
*/
bool vglite_cmd_buf_is_flushed(void);
#endif
/**
* Clear cache and flush command to VG-Lite.
*
*/
void vglite_run(void);
/**
* Get vglite color. Premultiplies (if not hw already) and swizzles the given
* LVGL 32bit color to obtain vglite color.
*
* @param[in] lv_col32 The initial LVGL 32bit color
* @param[in] gradient True for gradient color
*
* @retval The vglite 32-bit color value:
*
*/
vg_lite_color_t vglite_get_color(lv_color32_t lv_col32, bool gradient);
/**
* Get vglite blend mode.
*
* @param[in] lv_blend_mode The LVGL blend mode
*
* @retval The vglite blend mode
*
*/
vg_lite_blend_t vglite_get_blend_mode(lv_blend_mode_t lv_blend_mode);
/**
* Get vglite buffer format.
*
* @param[in] cf Color format
*
* @retval The vglite buffer format
*
*/
vg_lite_buffer_format_t vglite_get_buf_format(lv_color_format_t cf);
/**
* Get vglite buffer pixel size.
*
* @param[in] cf Color format
*
* @retval Bits per pixel
*
*/
uint8_t vglite_get_px_size(lv_color_format_t cf);
/**
* Get vglite buffer alignment.
*
* @param[in] cf Color format
*
* @retval Alignment requirement in bytes
*
*/
uint8_t vglite_get_alignment(lv_color_format_t cf);
/**
* Check memory and stride alignment.
*
* @param[in] buf Buffer address
* @param[in] stride Stride of buffer in bytes
* @param[in] cf Color format - to calculate the expected alignment
*
* @retval true Alignment OK
*
*/
bool vglite_buf_aligned(const void * buf, uint32_t stride, lv_color_format_t cf);
/**********************
* MACROS
**********************/
/**********************
* STATIC FUNCTIONS
**********************/
static inline void vglite_set_scissor(const lv_area_t * clip_area)
{
vg_lite_enable_scissor();
vg_lite_set_scissor((int32_t)clip_area->x1, (int32_t)clip_area->y1,
(int32_t)lv_area_get_width(clip_area),
(int32_t)lv_area_get_height(clip_area));
}
static inline void vglite_disable_scissor(void)
{
vg_lite_disable_scissor();
}
#endif /*LV_USE_DRAW_VGLITE*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_VGLITE_UTILS_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/vglite/lv_vglite_buf.h | /**
* @file lv_vglite_buf.h
*
*/
/**
* Copyright 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
#ifndef LV_VGLITE_BUF_H
#define LV_VGLITE_BUF_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../../../lv_conf_internal.h"
#if LV_USE_DRAW_VGLITE
#include "../../sw/lv_draw_sw.h"
#include "vg_lite.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Get vglite destination buffer pointer.
*
* @retval The vglite destination buffer
*
*/
vg_lite_buffer_t * vglite_get_dest_buf(void);
/**
* Get vglite source buffer pointer.
*
* @retval The vglite source buffer
*
*/
vg_lite_buffer_t * vglite_get_src_buf(void);
/**
* Set vglite destination buffer address only.
*
* @param[in] buf Destination buffer address (does not require alignment for VG_LITE_LINEAR mode)
*
*/
void vglite_set_dest_buf_ptr(void * buf);
/**
* Set vglite source buffer address only.
*
* @param[in] buf Source buffer address
*
*/
void vglite_set_src_buf_ptr(const void * buf);
/**
* Set vglite target (destination) buffer.
*
* @param[in] draw_buf Destination draw buffer descriptor
*
*/
void vglite_set_dest_buf(const lv_draw_buf_t * draw_buf);
/**
* Set vglite source buffer.
*
* @param[in] buf Source buffer address
* @param[in] width Source buffer width
* @param[in] height Source buffer height
* @param[in] stride Source buffer stride in bytes
* @param[in] cf Source buffer color format
*
*/
void vglite_set_src_buf(const void * buf, int32_t width, int32_t height, uint32_t stride,
lv_color_format_t cf);
/**
* Set vglite buffer.
*
* @param[in] vgbuf Address of the VGLite buffer object
* @param[in] buf Address of the memory for the VGLite buffer
* @param[in] width Buffer width
* @param[in] height Buffer height
* @param[in] stride Buffer stride in bytes
* @param[in] cf Buffer color format
*
*/
void vglite_set_buf(vg_lite_buffer_t * vgbuf, void * buf,
int32_t width, int32_t height, uint32_t stride,
lv_color_format_t cf);
/**********************
* MACROS
**********************/
#endif /*LV_USE_DRAW_VGLITE*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_VGLITE_BUF_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/vglite/lv_vglite_path.h | /**
* @file lv_vglite_path.h
*
*/
/**
* Copyright 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
#ifndef LV_VGLITE_PATH_H
#define LV_VGLITE_PATH_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../../../lv_conf_internal.h"
#if LV_USE_DRAW_VGLITE
#include "../../sw/lv_draw_sw.h"
/*********************
* DEFINES
*********************/
/* The optimal Bezier control point offset for radial unit
* see: https://spencermortensen.com/articles/bezier-circle/
**/
#define BEZIER_OPTIM_CIRCLE 0.551915024494f
/* Draw lines for control points of Bezier curves */
#define BEZIER_DBG_CONTROL_POINTS 0
/* Path data sizes for different elements */
#define CUBIC_PATH_DATA_SIZE 7 /* 1 opcode, 6 arguments */
#define LINE_PATH_DATA_SIZE 3 /* 1 opcode, 2 arguments */
#define MOVE_PATH_DATA_SIZE 3 /* 1 opcode, 2 arguments */
#define END_PATH_DATA_SIZE 1 /* 1 opcode, 0 arguments */
/* Maximum possible rectangle path size
* is in the rounded rectangle case:
* - 1 move for the path start
* - 4 cubics for the corners
* - 4 lines for the sides
* - 1 end for the path end */
#define RECT_PATH_DATA_MAX_SIZE 1 * MOVE_PATH_DATA_SIZE + 4 * CUBIC_PATH_DATA_SIZE + 4 * LINE_PATH_DATA_SIZE + 1 * END_PATH_DATA_SIZE
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Generates path data for rectangle drawing.
*
* @param[in/out] path The path data to initialize
* @param[in/out] path_size The resulting size of the created path data
* @param[in] dsc The style descriptor for the rectangle to be drawn
* @param[in] coords The coordinates of the rectangle to be drawn
*
*/
void vglite_create_rect_path_data(int32_t * path_data, uint32_t * path_data_size,
int32_t radius,
const lv_area_t * coords);
/**********************
* MACROS
**********************/
/**********************
* STATIC FUNCTIONS
**********************/
#endif /*LV_USE_DRAW_VGLITE*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_VGLITE_PATH_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/vglite/lv_vglite_matrix.h | /**
* @file lv_vglite_matrix.h
*
*/
/**
* Copyright 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
#ifndef LV_VGLITE_MATRIX_H
#define LV_VGLITE_MATRIX_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../../../lv_conf_internal.h"
#if LV_USE_DRAW_VGLITE
#include "../../sw/lv_draw_sw.h"
#include "vg_lite.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
vg_lite_matrix_t * vglite_get_matrix(void);
/**
* Creates matrix that translates to origin of given destination area.
*
* @param[in] dest_area Area with relative coordinates of destination buffer
*
*/
void vglite_set_translation_matrix(const lv_area_t * dest_area);
/**
* Creates matrix that translates to origin of given destination area with transformation (scale or rotate).
*
* @param[in] dest_area Area with relative coordinates of destination buffer
* @param[in] dsc Image descriptor
*
*/
void vglite_set_transformation_matrix(const lv_area_t * dest_area, const lv_draw_image_dsc_t * dsc);
/**********************
* MACROS
**********************/
/**********************
* STATIC FUNCTIONS
**********************/
#endif /*LV_USE_DRAW_VGLITE*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_VGLITE_MATRIX_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/vglite/lv_vglite_matrix.c | /**
* @file lv_vglite_matrix.c
*
*/
/**
* Copyright 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_vglite_matrix.h"
#if LV_USE_DRAW_VGLITE
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static vg_lite_matrix_t _vgmatrix;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
vg_lite_matrix_t * vglite_get_matrix(void)
{
return &_vgmatrix;
}
void vglite_set_translation_matrix(const lv_area_t * dest_area)
{
vg_lite_identity(&_vgmatrix);
vg_lite_translate((vg_lite_float_t)dest_area->x1, (vg_lite_float_t)dest_area->y1, &_vgmatrix);
}
void vglite_set_transformation_matrix(const lv_area_t * dest_area, const lv_draw_image_dsc_t * dsc)
{
vglite_set_translation_matrix(dest_area);
bool has_scale = (dsc->zoom != LV_SCALE_NONE);
bool has_rotation = (dsc->rotation != 0);
vg_lite_translate(dsc->pivot.x, dsc->pivot.y, &_vgmatrix);
if(has_rotation)
vg_lite_rotate(dsc->rotation / 10.0f, &_vgmatrix); /* angle is 1/10 degree */
if(has_scale) {
vg_lite_float_t scale = 1.0f * dsc->zoom / LV_SCALE_NONE;
vg_lite_scale(scale, scale, &_vgmatrix);
}
vg_lite_translate(0.0f - dsc->pivot.x, 0.0f - dsc->pivot.y, &_vgmatrix);
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif /*LV_USE_DRAW_VGLITE*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/vglite/lv_draw_vglite_fill.c | /**
* @file lv_draw_vglite_fill.c
*
*/
/**
* Copyright 2020-2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_vglite.h"
#if LV_USE_DRAW_VGLITE
#include "lv_vglite_buf.h"
#include "lv_vglite_path.h"
#include "lv_vglite_utils.h"
#include "../../../stdlib/lv_string.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**
* Fill area, with optional opacity.
*
* @param[in] dest_area Area with relative coordinates of destination buffer
* @param[in] dsc Description of the area to fill (color, opa)
*
*/
static void _vglite_fill(const lv_area_t * dest_area, const lv_draw_fill_dsc_t * dsc);
/**
* Draw rectangle background with effects (rounded corners, gradient)
*
* @param[in] coords Coordinates of the rectangle background (relative to dest buff)
* @param[in] clip_area Clipping area with relative coordinates to dest buff
* @param[in] dsc Description of the rectangle background
*
*/
static void _vglite_draw_rect(const lv_area_t * coords, const lv_area_t * clip_area,
const lv_draw_fill_dsc_t * dsc);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_vglite_fill(lv_draw_unit_t * draw_unit, const lv_draw_fill_dsc_t * dsc,
const lv_area_t * coords)
{
if(dsc->opa <= (lv_opa_t)LV_OPA_MIN)
return;
lv_layer_t * layer = draw_unit->target_layer;
lv_area_t rel_coords;
lv_area_copy(&rel_coords, coords);
/*If the border fully covers make the bg area 1px smaller to avoid artifacts on the corners*/
//if(dsc->border_width > 1 && dsc->border_opa >= (lv_opa_t)LV_OPA_MAX && dsc->radius != 0) {
// rel_coords.x1 += (dsc->border_side & LV_BORDER_SIDE_LEFT) ? 1 : 0;
// rel_coords.y1 += (dsc->border_side & LV_BORDER_SIDE_TOP) ? 1 : 0;
// rel_coords.x2 -= (dsc->border_side & LV_BORDER_SIDE_RIGHT) ? 1 : 0;
// rel_coords.y2 -= (dsc->border_side & LV_BORDER_SIDE_BOTTOM) ? 1 : 0;
//}
lv_area_move(&rel_coords, -layer->draw_buf_ofs.x, -layer->draw_buf_ofs.y);
lv_area_t rel_clip_area;
lv_area_copy(&rel_clip_area, draw_unit->clip_area);
lv_area_move(&rel_clip_area, -layer->draw_buf_ofs.x, -layer->draw_buf_ofs.y);
lv_area_t clipped_coords;
if(!_lv_area_intersect(&clipped_coords, &rel_coords, &rel_clip_area))
return; /*Fully clipped, nothing to do*/
/*
* Most simple case: just a plain rectangle (no radius, no gradient)
*/
if((dsc->radius == 0) && (dsc->grad.dir == (lv_grad_dir_t)LV_GRAD_DIR_NONE))
_vglite_fill(&clipped_coords, dsc);
else
_vglite_draw_rect(&rel_coords, &rel_clip_area, dsc);
}
/**********************
* STATIC FUNCTIONS
**********************/
static void _vglite_fill(const lv_area_t * dest_area, const lv_draw_fill_dsc_t * dsc)
{
vg_lite_error_t err = VG_LITE_SUCCESS;
vg_lite_buffer_t * vgbuf = vglite_get_dest_buf();
lv_color32_t col32 = lv_color_to_32(dsc->color, dsc->opa);
vg_lite_color_t vgcol = vglite_get_color(col32, false);
if(dsc->opa >= (lv_opa_t)LV_OPA_MAX) { /*Opaque fill*/
vg_lite_rectangle_t rect = {
.x = dest_area->x1,
.y = dest_area->y1,
.width = lv_area_get_width(dest_area),
.height = lv_area_get_height(dest_area)
};
err = vg_lite_clear(vgbuf, &rect, vgcol);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Clear failed.");
vglite_run();
}
else { /*fill with transparency*/
vg_lite_path_t path;
int32_t path_data[] = { /*VG rectangular path*/
VLC_OP_MOVE, dest_area->x1, dest_area->y1,
VLC_OP_LINE, dest_area->x2 + 1, dest_area->y1,
VLC_OP_LINE, dest_area->x2 + 1, dest_area->y2 + 1,
VLC_OP_LINE, dest_area->x1, dest_area->y2 + 1,
VLC_OP_LINE, dest_area->x1, dest_area->y1,
VLC_OP_END
};
err = vg_lite_init_path(&path, VG_LITE_S32, VG_LITE_MEDIUM, sizeof(path_data), path_data,
(vg_lite_float_t) dest_area->x1, (vg_lite_float_t) dest_area->y1,
((vg_lite_float_t) dest_area->x2) + 1.0f, ((vg_lite_float_t) dest_area->y2) + 1.0f);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Init path failed.");
vg_lite_matrix_t matrix;
vg_lite_identity(&matrix);
/*Draw rectangle*/
err = vg_lite_draw(vgbuf, &path, VG_LITE_FILL_EVEN_ODD, &matrix, VG_LITE_BLEND_SRC_OVER, vgcol);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Draw rectangle failed.");
vglite_run();
err = vg_lite_clear_path(&path);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Clear path failed.");
}
}
static void _vglite_draw_rect(const lv_area_t * coords, const lv_area_t * clip_area,
const lv_draw_fill_dsc_t * dsc)
{
vg_lite_error_t err = VG_LITE_SUCCESS;
int32_t width = lv_area_get_width(coords);
int32_t height = lv_area_get_height(coords);
int32_t radius = dsc->radius;
vg_lite_buffer_t * vgbuf = vglite_get_dest_buf();
if(dsc->radius < 0)
return;
/*** Init path ***/
int32_t path_data[RECT_PATH_DATA_MAX_SIZE];
uint32_t path_data_size;
vglite_create_rect_path_data(path_data, &path_data_size, radius, coords);
vg_lite_quality_t path_quality = dsc->radius > 0 ? VG_LITE_HIGH : VG_LITE_MEDIUM;
vg_lite_path_t path;
err = vg_lite_init_path(&path, VG_LITE_S32, path_quality, path_data_size, path_data,
(vg_lite_float_t)clip_area->x1, (vg_lite_float_t)clip_area->y1,
((vg_lite_float_t)clip_area->x2) + 1.0f, ((vg_lite_float_t)clip_area->y2) + 1.0f);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Init path failed.");
vg_lite_matrix_t matrix;
vg_lite_identity(&matrix);
/*** Init Color ***/
lv_color32_t col32 = lv_color_to_32(dsc->color, dsc->opa);
vg_lite_color_t vgcol = vglite_get_color(col32, false);
vglite_set_scissor(clip_area);
vg_lite_linear_gradient_t gradient;
bool has_gradient = (dsc->grad.dir != (lv_grad_dir_t)LV_GRAD_DIR_NONE);
/*** Init Gradient ***/
if(has_gradient) {
vg_lite_matrix_t * grad_matrix;
uint32_t colors[2];
uint32_t stops[2];
lv_color32_t col32[2];
/* Gradient setup */
uint8_t cnt = LV_MAX(dsc->grad.stops_count, 2);
for(uint8_t i = 0; i < cnt; i++) {
stops[i] = dsc->grad.stops[i].frac;
col32[i] = lv_color_to_32(dsc->grad.stops[i].color, dsc->opa);
colors[i] = vglite_get_color(col32[i], true);
}
lv_memset(&gradient, 0, sizeof(vg_lite_linear_gradient_t));
err = vg_lite_init_grad(&gradient);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Init gradient failed");
err = vg_lite_set_grad(&gradient, cnt, colors, stops);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Set gradient failed.");
err = vg_lite_update_grad(&gradient);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Update gradient failed.");
grad_matrix = vg_lite_get_grad_matrix(&gradient);
vg_lite_identity(grad_matrix);
vg_lite_translate((float)coords->x1, (float)coords->y1, grad_matrix);
if(dsc->grad.dir == (lv_grad_dir_t)LV_GRAD_DIR_VER) {
vg_lite_scale(1.0f, (float)height / 256.0f, grad_matrix);
vg_lite_rotate(90.0f, grad_matrix);
}
else { /*LV_GRAD_DIR_HOR*/
vg_lite_scale((float)width / 256.0f, 1.0f, grad_matrix);
}
err = vg_lite_draw_gradient(vgbuf, &path, VG_LITE_FILL_EVEN_ODD, &matrix, &gradient, VG_LITE_BLEND_SRC_OVER);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Draw gradient failed.");
}
else {
err = vg_lite_draw(vgbuf, &path, VG_LITE_FILL_EVEN_ODD, &matrix, VG_LITE_BLEND_SRC_OVER, vgcol);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Draw rectangle failed.");
}
vglite_run();
vglite_disable_scissor();
err = vg_lite_clear_path(&path);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Clear path failed.");
if(has_gradient) {
err = vg_lite_clear_grad(&gradient);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Clear gradient failed.");
}
}
#endif /*LV_USE_DRAW_VGLITE*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/vglite/lv_draw_vglite_arc.c | /**
* @file lv_draw_vglite_arc.c
*
*/
/**
* Copyright 2021-2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_vglite.h"
#if LV_USE_DRAW_VGLITE
#include "lv_vglite_buf.h"
#include "lv_vglite_path.h"
#include "lv_vglite_utils.h"
#include "../../../stdlib/lv_string.h"
#include <math.h>
/*********************
* DEFINES
*********************/
#define T_FRACTION 16384.0f
#define DICHOTO_ITER 5
static const uint16_t TperDegree[90] = {
0, 174, 348, 522, 697, 873, 1049, 1226, 1403, 1581,
1759, 1938, 2117, 2297, 2477, 2658, 2839, 3020, 3202, 3384,
3567, 3749, 3933, 4116, 4300, 4484, 4668, 4852, 5037, 5222,
5407, 5592, 5777, 5962, 6148, 6334, 6519, 6705, 6891, 7077,
7264, 7450, 7636, 7822, 8008, 8193, 8378, 8564, 8750, 8936,
9122, 9309, 9495, 9681, 9867, 10052, 10238, 10424, 10609, 10794,
10979, 11164, 11349, 11534, 11718, 11902, 12086, 12270, 12453, 12637,
12819, 13002, 13184, 13366, 13547, 13728, 13909, 14089, 14269, 14448,
14627, 14805, 14983, 15160, 15337, 15513, 15689, 15864, 16038, 16212
};
/**********************
* TYPEDEFS
**********************/
/* intermediate arc params */
typedef struct _vg_arc {
int32_t angle; /* angle <90deg */
int32_t quarter; /* 0-3 counter-clockwise */
int32_t rad; /* radius */
int32_t p0x; /* point P0 */
int32_t p0y;
int32_t p1x; /* point P1 */
int32_t p1y;
int32_t p2x; /* point P2 */
int32_t p2y;
int32_t p3x; /* point P3 */
int32_t p3y;
} vg_arc;
typedef struct _cubic_cont_pt {
float p0;
float p1;
float p2;
float p3;
} cubic_cont_pt;
/**********************
* STATIC PROTOTYPES
**********************/
/**
* Draw arc shape with effects
*
* @param[in] center Arc center with relative coordinates
* @param[in] clip_area Clipping area with relative coordinates to dest buff
* @param[in] dsc Arc description structure (width, rounded ending, opacity)
*
*/
static void _vglite_draw_arc(const lv_point_t * center, const lv_area_t * clip_area,
const lv_draw_arc_dsc_t * dsc);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_vglite_arc(lv_draw_unit_t * draw_unit, const lv_draw_arc_dsc_t * dsc,
const lv_area_t * coords)
{
LV_UNUSED(coords);
if(dsc->opa <= (lv_opa_t)LV_OPA_MIN)
return;
if(dsc->width == 0)
return;
if(dsc->start_angle == dsc->end_angle)
return;
lv_layer_t * layer = draw_unit->target_layer;
lv_point_t rel_center = {dsc->center.x - layer->draw_buf_ofs.x, dsc->center.y - layer->draw_buf_ofs.y};
lv_area_t rel_clip_area;
lv_area_copy(&rel_clip_area, draw_unit->clip_area);
lv_area_move(&rel_clip_area, -layer->draw_buf_ofs.x, -layer->draw_buf_ofs.y);
_vglite_draw_arc(&rel_center, &rel_clip_area, dsc);
}
/**********************
* STATIC FUNCTIONS
**********************/
static void _copy_arc(vg_arc * dst, vg_arc * src)
{
dst->quarter = src->quarter;
dst->rad = src->rad;
dst->angle = src->angle;
dst->p0x = src->p0x;
dst->p1x = src->p1x;
dst->p2x = src->p2x;
dst->p3x = src->p3x;
dst->p0y = src->p0y;
dst->p1y = src->p1y;
dst->p2y = src->p2y;
dst->p3y = src->p3y;
}
/**
* Rotate the point according given rotation angle rotation center is 0,0
*/
static void _rotate_point(int32_t angle, int32_t * x, int32_t * y)
{
int32_t ori_x = *x;
int32_t ori_y = *y;
int16_t alpha = (int16_t)angle;
*x = ((lv_trigo_cos(alpha) * ori_x) / LV_TRIGO_SIN_MAX) - ((lv_trigo_sin(alpha) * ori_y) / LV_TRIGO_SIN_MAX);
*y = ((lv_trigo_sin(alpha) * ori_x) / LV_TRIGO_SIN_MAX) + ((lv_trigo_cos(alpha) * ori_y) / LV_TRIGO_SIN_MAX);
}
/**
* Set full arc control points depending on quarter.
* Control points match the best approximation of a circle.
* Arc Quarter position is:
* Q2 | Q3
* ---+---
* Q1 | Q0
*/
static void _set_full_arc(vg_arc * fullarc)
{
/* the tangent length for the bezier circle approx */
float tang = ((float)fullarc->rad) * BEZIER_OPTIM_CIRCLE;
switch(fullarc->quarter) {
case 0:
/* first quarter */
fullarc->p0x = fullarc->rad;
fullarc->p0y = 0;
fullarc->p1x = fullarc->rad;
fullarc->p1y = (int32_t)tang;
fullarc->p2x = (int32_t)tang;
fullarc->p2y = fullarc->rad;
fullarc->p3x = 0;
fullarc->p3y = fullarc->rad;
break;
case 1:
/* second quarter */
fullarc->p0x = 0;
fullarc->p0y = fullarc->rad;
fullarc->p1x = 0 - (int32_t)tang;
fullarc->p1y = fullarc->rad;
fullarc->p2x = 0 - fullarc->rad;
fullarc->p2y = (int32_t)tang;
fullarc->p3x = 0 - fullarc->rad;
fullarc->p3y = 0;
break;
case 2:
/* third quarter */
fullarc->p0x = 0 - fullarc->rad;
fullarc->p0y = 0;
fullarc->p1x = 0 - fullarc->rad;
fullarc->p1y = 0 - (int32_t)tang;
fullarc->p2x = 0 - (int32_t)tang;
fullarc->p2y = 0 - fullarc->rad;
fullarc->p3x = 0;
fullarc->p3y = 0 - fullarc->rad;
break;
case 3:
/* fourth quarter */
fullarc->p0x = 0;
fullarc->p0y = 0 - fullarc->rad;
fullarc->p1x = (int32_t)tang;
fullarc->p1y = 0 - fullarc->rad;
fullarc->p2x = fullarc->rad;
fullarc->p2y = 0 - (int32_t)tang;
fullarc->p3x = fullarc->rad;
fullarc->p3y = 0;
break;
default:
LV_ASSERT_MSG(false, "Invalid arc quarter.");
break;
}
}
/**
* Linear interpolation between two points 'a' and 'b'
* 't' parameter is the proportion ratio expressed in range [0 ; T_FRACTION ]
*/
static inline float _lerp(float coord_a, float coord_b, uint16_t t)
{
float tf = (float)t;
return ((T_FRACTION - tf) * coord_a + tf * coord_b) / T_FRACTION;
}
/**
* Computes a point of bezier curve given 't' param
*/
static inline float _comp_bezier_point(float t, cubic_cont_pt cp)
{
float t_sq = t * t;
float inv_t_sq = (1.0f - t) * (1.0f - t);
float apt = (1.0f - t) * inv_t_sq * cp.p0 + 3.0f * inv_t_sq * t * cp.p1 + 3.0f * (1.0f - t) * t_sq * cp.p2 + t * t_sq *
cp.p3;
return apt;
}
/**
* Find parameter 't' in curve at point 'pt'
* proceed by dichotomy on only 1 dimension,
* works only if the curve is monotonic
* bezier curve is defined by control points [p0 p1 p2 p3]
* 'dec' tells if curve is decreasing (true) or increasing (false)
*/
static uint16_t _get_bez_t_from_pos(float pt, cubic_cont_pt cp, bool dec)
{
/* initialize dichotomy with boundary 't' values */
float t_low = 0.0f;
float t_mid = 0.5f;
float t_hig = 1.0f;
float a_pt;
/* dichotomy loop */
for(int i = 0; i < DICHOTO_ITER; i++) {
a_pt = _comp_bezier_point(t_mid, cp);
/* check mid-point position on bezier curve versus targeted point */
if((a_pt > pt) != dec) {
t_hig = t_mid;
}
else {
t_low = t_mid;
}
/* define new 't' param for mid-point */
t_mid = (t_low + t_hig) / 2.0f;
}
/* return parameter 't' in integer range [0 ; T_FRACTION] */
return (uint16_t)floorf(t_mid * T_FRACTION + 0.5f);
}
/**
* Gives relative coords of the control points
* for the sub-arc starting at angle with given angle span
*/
static void _get_subarc_control_points(vg_arc * arc, int32_t span)
{
vg_arc fullarc = {0};
fullarc.angle = arc->angle;
fullarc.quarter = arc->quarter;
fullarc.rad = arc->rad;
_set_full_arc(&fullarc);
/* special case of full arc */
if(arc->angle == 90) {
_copy_arc(arc, &fullarc);
return;
}
/* compute 1st arc using the geometric construction of curve */
uint16_t t2 = TperDegree[arc->angle + span];
/* lerp for A */
float a2x = _lerp((float)fullarc.p0x, (float)fullarc.p1x, t2);
float a2y = _lerp((float)fullarc.p0y, (float)fullarc.p1y, t2);
/* lerp for B */
float b2x = _lerp((float)fullarc.p1x, (float)fullarc.p2x, t2);
float b2y = _lerp((float)fullarc.p1y, (float)fullarc.p2y, t2);
/* lerp for C */
float c2x = _lerp((float)fullarc.p2x, (float)fullarc.p3x, t2);
float c2y = _lerp((float)fullarc.p2y, (float)fullarc.p3y, t2);
/* lerp for D */
float d2x = _lerp(a2x, b2x, t2);
float d2y = _lerp(a2y, b2y, t2);
/* lerp for E */
float e2x = _lerp(b2x, c2x, t2);
float e2y = _lerp(b2y, c2y, t2);
float pt2x = _lerp(d2x, e2x, t2);
float pt2y = _lerp(d2y, e2y, t2);
/* compute sub-arc using the geometric construction of curve */
uint16_t t1 = TperDegree[arc->angle];
/* lerp for A */
float a1x = _lerp((float)fullarc.p0x, (float)fullarc.p1x, t1);
float a1y = _lerp((float)fullarc.p0y, (float)fullarc.p1y, t1);
/* lerp for B */
float b1x = _lerp((float)fullarc.p1x, (float)fullarc.p2x, t1);
float b1y = _lerp((float)fullarc.p1y, (float)fullarc.p2y, t1);
/* lerp for C */
float c1x = _lerp((float)fullarc.p2x, (float)fullarc.p3x, t1);
float c1y = _lerp((float)fullarc.p2y, (float)fullarc.p3y, t1);
/* lerp for D */
float d1x = _lerp(a1x, b1x, t1);
float d1y = _lerp(a1y, b1y, t1);
/* lerp for E */
float e1x = _lerp(b1x, c1x, t1);
float e1y = _lerp(b1y, c1y, t1);
float pt1x = _lerp(d1x, e1x, t1);
float pt1y = _lerp(d1y, e1y, t1);
/* find the 't3' parameter for point P(t1) on the sub-arc [P0 A2 D2 P(t2)] using dichotomy
* use position of x axis only */
uint16_t t3;
t3 = _get_bez_t_from_pos(pt1x,
(cubic_cont_pt) {
.p0 = ((float)fullarc.p0x), .p1 = a2x, .p2 = d2x, .p3 = pt2x
},
(bool)(pt2x < (float)fullarc.p0x));
/* lerp for B */
float b3x = _lerp(a2x, d2x, t3);
float b3y = _lerp(a2y, d2y, t3);
/* lerp for C */
float c3x = _lerp(d2x, pt2x, t3);
float c3y = _lerp(d2y, pt2y, t3);
/* lerp for E */
float e3x = _lerp(b3x, c3x, t3);
float e3y = _lerp(b3y, c3y, t3);
arc->p0x = (int32_t)floorf(0.5f + pt1x);
arc->p0y = (int32_t)floorf(0.5f + pt1y);
arc->p1x = (int32_t)floorf(0.5f + e3x);
arc->p1y = (int32_t)floorf(0.5f + e3y);
arc->p2x = (int32_t)floorf(0.5f + c3x);
arc->p2y = (int32_t)floorf(0.5f + c3y);
arc->p3x = (int32_t)floorf(0.5f + pt2x);
arc->p3y = (int32_t)floorf(0.5f + pt2y);
}
/**
* Gives relative coords of the control points
*/
static void _get_arc_control_points(vg_arc * arc, bool start)
{
vg_arc fullarc = {0};
fullarc.angle = arc->angle;
fullarc.quarter = arc->quarter;
fullarc.rad = arc->rad;
_set_full_arc(&fullarc);
/* special case of full arc */
if(arc->angle == 90) {
_copy_arc(arc, &fullarc);
return;
}
/* compute sub-arc using the geometric construction of curve */
uint16_t t = TperDegree[arc->angle];
/* lerp for A */
float ax = _lerp((float)fullarc.p0x, (float)fullarc.p1x, t);
float ay = _lerp((float)fullarc.p0y, (float)fullarc.p1y, t);
/* lerp for B */
float bx = _lerp((float)fullarc.p1x, (float)fullarc.p2x, t);
float by = _lerp((float)fullarc.p1y, (float)fullarc.p2y, t);
/* lerp for C */
float cx = _lerp((float)fullarc.p2x, (float)fullarc.p3x, t);
float cy = _lerp((float)fullarc.p2y, (float)fullarc.p3y, t);
/* lerp for D */
float dx = _lerp(ax, bx, t);
float dy = _lerp(ay, by, t);
/* lerp for E */
float ex = _lerp(bx, cx, t);
float ey = _lerp(by, cy, t);
/* sub-arc's control points are tangents of DeCasteljau's algorithm */
if(start) {
arc->p0x = (int32_t)floorf(0.5f + _lerp(dx, ex, t));
arc->p0y = (int32_t)floorf(0.5f + _lerp(dy, ey, t));
arc->p1x = (int32_t)floorf(0.5f + ex);
arc->p1y = (int32_t)floorf(0.5f + ey);
arc->p2x = (int32_t)floorf(0.5f + cx);
arc->p2y = (int32_t)floorf(0.5f + cy);
arc->p3x = fullarc.p3x;
arc->p3y = fullarc.p3y;
}
else {
arc->p0x = fullarc.p0x;
arc->p0y = fullarc.p0y;
arc->p1x = (int32_t)floorf(0.5f + ax);
arc->p1y = (int32_t)floorf(0.5f + ay);
arc->p2x = (int32_t)floorf(0.5f + dx);
arc->p2y = (int32_t)floorf(0.5f + dy);
arc->p3x = (int32_t)floorf(0.5f + _lerp(dx, ex, t));
arc->p3y = (int32_t)floorf(0.5f + _lerp(dy, ey, t));
}
}
/**
* Add the arc control points into the path data for vglite,
* taking into account the real center of the arc (translation).
* arc_path: (in/out) the path data array for vglite
* pidx: (in/out) index of last element added in arc_path
* q_arc: (in) the arc data containing control points
* center: (in) the center of the circle in draw coordinates
* cw: (in) true if arc is clockwise
*/
static void _add_split_arc_path(int32_t * arc_path, int * pidx, vg_arc * q_arc, const lv_point_t * center, bool cw)
{
/* assumes first control point already in array arc_path[] */
int idx = *pidx;
if(cw) {
#if BEZIER_DBG_CONTROL_POINTS
arc_path[idx++] = VLC_OP_LINE;
arc_path[idx++] = q_arc->p1x + center->x;
arc_path[idx++] = q_arc->p1y + center->y;
arc_path[idx++] = VLC_OP_LINE;
arc_path[idx++] = q_arc->p2x + center->x;
arc_path[idx++] = q_arc->p2y + center->y;
arc_path[idx++] = VLC_OP_LINE;
arc_path[idx++] = q_arc->p3x + center->x;
arc_path[idx++] = q_arc->p3y + center->y;
#else
arc_path[idx++] = VLC_OP_CUBIC;
arc_path[idx++] = q_arc->p1x + center->x;
arc_path[idx++] = q_arc->p1y + center->y;
arc_path[idx++] = q_arc->p2x + center->x;
arc_path[idx++] = q_arc->p2y + center->y;
arc_path[idx++] = q_arc->p3x + center->x;
arc_path[idx++] = q_arc->p3y + center->y;
#endif
}
else { /* reverse points order when counter-clockwise */
#if BEZIER_DBG_CONTROL_POINTS
arc_path[idx++] = VLC_OP_LINE;
arc_path[idx++] = q_arc->p2x + center->x;
arc_path[idx++] = q_arc->p2y + center->y;
arc_path[idx++] = VLC_OP_LINE;
arc_path[idx++] = q_arc->p1x + center->x;
arc_path[idx++] = q_arc->p1y + center->y;
arc_path[idx++] = VLC_OP_LINE;
arc_path[idx++] = q_arc->p0x + center->x;
arc_path[idx++] = q_arc->p0y + center->y;
#else
arc_path[idx++] = VLC_OP_CUBIC;
arc_path[idx++] = q_arc->p2x + center->x;
arc_path[idx++] = q_arc->p2y + center->y;
arc_path[idx++] = q_arc->p1x + center->x;
arc_path[idx++] = q_arc->p1y + center->y;
arc_path[idx++] = q_arc->p0x + center->x;
arc_path[idx++] = q_arc->p0y + center->y;
#endif
}
/* update index i n path array*/
*pidx = idx;
}
static void _add_arc_path(int32_t * arc_path, int * pidx, int32_t radius,
int32_t start_angle, int32_t end_angle, const lv_point_t * center, bool cw)
{
/* set number of arcs to draw */
vg_arc q_arc;
int32_t start_arc_angle = start_angle % 90;
int32_t end_arc_angle = end_angle % 90;
int32_t inv_start_arc_angle = (start_arc_angle > 0) ? (90 - start_arc_angle) : 0;
int32_t nbarc = (end_angle - start_angle - inv_start_arc_angle - end_arc_angle) / 90;
q_arc.rad = radius;
/* handle special case of start & end point in the same quarter */
if(((start_angle / 90) == (end_angle / 90)) && (nbarc <= 0)) {
q_arc.quarter = (start_angle / 90) % 4;
q_arc.angle = start_arc_angle;
_get_subarc_control_points(&q_arc, end_arc_angle - start_arc_angle);
_add_split_arc_path(arc_path, pidx, &q_arc, center, cw);
return;
}
if(cw) {
/* partial starting arc */
if(start_arc_angle > 0) {
q_arc.quarter = (start_angle / 90) % 4;
q_arc.angle = start_arc_angle;
/* get cubic points relative to center */
_get_arc_control_points(&q_arc, true);
/* put cubic points in arc_path */
_add_split_arc_path(arc_path, pidx, &q_arc, center, cw);
}
/* full arcs */
for(int32_t q = 0; q < nbarc ; q++) {
q_arc.quarter = (q + ((start_angle + 89) / 90)) % 4;
q_arc.angle = 90;
/* get cubic points relative to center */
_get_arc_control_points(&q_arc, true); /* 2nd parameter 'start' ignored */
/* put cubic points in arc_path */
_add_split_arc_path(arc_path, pidx, &q_arc, center, cw);
}
/* partial ending arc */
if(end_arc_angle > 0) {
q_arc.quarter = (end_angle / 90) % 4;
q_arc.angle = end_arc_angle;
/* get cubic points relative to center */
_get_arc_control_points(&q_arc, false);
/* put cubic points in arc_path */
_add_split_arc_path(arc_path, pidx, &q_arc, center, cw);
}
}
else { /* counter clockwise */
/* partial ending arc */
if(end_arc_angle > 0) {
q_arc.quarter = (end_angle / 90) % 4;
q_arc.angle = end_arc_angle;
/* get cubic points relative to center */
_get_arc_control_points(&q_arc, false);
/* put cubic points in arc_path */
_add_split_arc_path(arc_path, pidx, &q_arc, center, cw);
}
/* full arcs */
for(int32_t q = nbarc - 1; q >= 0; q--) {
q_arc.quarter = (q + ((start_angle + 89) / 90)) % 4;
q_arc.angle = 90;
/* get cubic points relative to center */
_get_arc_control_points(&q_arc, true); /* 2nd parameter 'start' ignored */
/* put cubic points in arc_path */
_add_split_arc_path(arc_path, pidx, &q_arc, center, cw);
}
/* partial starting arc */
if(start_arc_angle > 0) {
q_arc.quarter = (start_angle / 90) % 4;
q_arc.angle = start_arc_angle;
/* get cubic points relative to center */
_get_arc_control_points(&q_arc, true);
/* put cubic points in arc_path */
_add_split_arc_path(arc_path, pidx, &q_arc, center, cw);
}
}
}
static void _vglite_draw_arc(const lv_point_t * center, const lv_area_t * clip_area,
const lv_draw_arc_dsc_t * dsc)
{
vg_lite_error_t err = VG_LITE_SUCCESS;
vg_lite_path_t path;
uint16_t start_angle = dsc->start_angle;
uint16_t end_angle = dsc->end_angle;
bool donut = ((end_angle - start_angle) % 360 == 0) ? true : false;
vg_lite_buffer_t * vgbuf = vglite_get_dest_buf();
/* path: max size = 16 cubic bezier (7 words each) */
int32_t arc_path[16 * 7];
lv_memset(arc_path, 0, sizeof(arc_path));
/*** Init path ***/
int32_t width = dsc->width; /* inner arc radius = outer arc radius - width */
uint16_t radius = dsc->radius;
if(width > radius)
width = radius;
int pidx = 0;
int32_t cp_x, cp_y; /* control point coords */
/* first control point of curve */
cp_x = radius;
cp_y = 0;
_rotate_point(start_angle, &cp_x, &cp_y);
arc_path[pidx++] = VLC_OP_MOVE;
arc_path[pidx++] = center->x + cp_x;
arc_path[pidx++] = center->y + cp_y;
/* draw 1-5 outer quarters */
_add_arc_path(arc_path, &pidx, radius, start_angle, end_angle, center, true);
if(donut) {
/* close outer circle */
cp_x = radius;
cp_y = 0;
_rotate_point(start_angle, &cp_x, &cp_y);
arc_path[pidx++] = VLC_OP_LINE;
arc_path[pidx++] = center->x + cp_x;
arc_path[pidx++] = center->y + cp_y;
/* start inner circle */
cp_x = radius - width;
cp_y = 0;
_rotate_point(start_angle, &cp_x, &cp_y);
arc_path[pidx++] = VLC_OP_MOVE;
arc_path[pidx++] = center->x + cp_x;
arc_path[pidx++] = center->y + cp_y;
}
else if(dsc->rounded != 0U) { /* 1st rounded arc ending */
cp_x = radius - width / 2;
cp_y = 0;
_rotate_point(end_angle, &cp_x, &cp_y);
lv_point_t round_center = {center->x + cp_x, center->y + cp_y};
_add_arc_path(arc_path, &pidx, width / 2, end_angle, (end_angle + 180),
&round_center, true);
}
else { /* 1st flat ending */
cp_x = radius - width;
cp_y = 0;
_rotate_point(end_angle, &cp_x, &cp_y);
arc_path[pidx++] = VLC_OP_LINE;
arc_path[pidx++] = center->x + cp_x;
arc_path[pidx++] = center->y + cp_y;
}
/* draw 1-5 inner quarters */
_add_arc_path(arc_path, &pidx, radius - width, start_angle, end_angle, center, false);
/* last control point of curve */
if(donut) { /* close the loop */
cp_x = radius - width;
cp_y = 0;
_rotate_point(start_angle, &cp_x, &cp_y);
arc_path[pidx++] = VLC_OP_LINE;
arc_path[pidx++] = center->x + cp_x;
arc_path[pidx++] = center->y + cp_y;
}
else if(dsc->rounded != 0U) { /* 2nd rounded arc ending */
cp_x = radius - width / 2;
cp_y = 0;
_rotate_point(start_angle, &cp_x, &cp_y);
lv_point_t round_center = {center->x + cp_x, center->y + cp_y};
_add_arc_path(arc_path, &pidx, width / 2, (start_angle + 180), (start_angle + 360),
&round_center, true);
}
else { /* 2nd flat ending */
cp_x = radius;
cp_y = 0;
_rotate_point(start_angle, &cp_x, &cp_y);
arc_path[pidx++] = VLC_OP_LINE;
arc_path[pidx++] = center->x + cp_x;
arc_path[pidx++] = center->y + cp_y;
}
arc_path[pidx++] = VLC_OP_END;
err = vg_lite_init_path(&path, VG_LITE_S32, VG_LITE_HIGH, (uint32_t)pidx * sizeof(int32_t), arc_path,
(vg_lite_float_t)clip_area->x1, (vg_lite_float_t)clip_area->y1,
((vg_lite_float_t)clip_area->x2) + 1.0f, ((vg_lite_float_t)clip_area->y2) + 1.0f);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Init path failed.");
lv_color32_t col32 = lv_color_to_32(dsc->color, dsc->opa);
vg_lite_color_t vgcol = vglite_get_color(col32, false);
vg_lite_matrix_t matrix;
vg_lite_identity(&matrix);
vglite_set_scissor(clip_area);
/*** Draw arc ***/
err = vg_lite_draw(vgbuf, &path, VG_LITE_FILL_NON_ZERO, &matrix, VG_LITE_BLEND_SRC_OVER, vgcol);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Draw arc failed.");
vglite_run();
vglite_disable_scissor();
err = vg_lite_clear_path(&path);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Clear path failed.");
}
#endif /*LV_USE_DRAW_VGLITE*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/vglite/lv_draw_vglite_border.c | /**
* @file lv_draw_vglite_border.c
*
*/
/**
* Copyright 2022, 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_vglite.h"
#if LV_USE_DRAW_VGLITE
#include "lv_vglite_buf.h"
#include "lv_vglite_path.h"
#include "lv_vglite_utils.h"
#include <math.h>
/*********************
* DEFINES
*********************/
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**
* Draw rectangle border/outline shape with effects (rounded corners, opacity)
*
* @param[in] coords Coordinates of the rectangle border/outline (relative to dest buff)
* @param[in] clip_area Clipping area with relative coordinates to dest buff
* @param[in] dsc Description of the rectangle border/outline
*
*/
static void _vglite_draw_border(const lv_area_t * coords, const lv_area_t * clip_area,
const lv_draw_border_dsc_t * dsc);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_vglite_border(lv_draw_unit_t * draw_unit, const lv_draw_border_dsc_t * dsc,
const lv_area_t * coords)
{
if(dsc->opa <= (lv_opa_t)LV_OPA_MIN)
return;
if(dsc->width == 0)
return;
if(dsc->side == (lv_border_side_t)LV_BORDER_SIDE_NONE)
return;
lv_layer_t * layer = draw_unit->target_layer;
lv_area_t rel_coords;
int32_t width = dsc->width;
/* Move border inwards to align with software rendered border */
rel_coords.x1 = coords->x1 + ceil(width / 2.0f);
rel_coords.x2 = coords->x2 - floor(width / 2.0f);
rel_coords.y1 = coords->y1 + ceil(width / 2.0f);
rel_coords.y2 = coords->y2 - floor(width / 2.0f);
/* Move outline outwards to align with software rendered outline */
//int32_t outline_pad = dsc->outline_pad - 1;
//rel_coords.x1 = coords->x1 - outline_pad - floor(dsc->outline_width / 2.0f);
//rel_coords.x2 = coords->x2 + outline_pad + ceil(dsc->outline_width / 2.0f);
//rel_coords.y1 = coords->y1 - outline_pad - floor(dsc->outline_width / 2.0f);
//rel_coords.y2 = coords->y2 + outline_pad + ceil(dsc->outline_width / 2.0f);
lv_area_move(&rel_coords, -layer->draw_buf_ofs.x, -layer->draw_buf_ofs.y);
lv_area_t rel_clip_area;
lv_area_copy(&rel_clip_area, draw_unit->clip_area);
lv_area_move(&rel_clip_area, -layer->draw_buf_ofs.x, -layer->draw_buf_ofs.y);
lv_area_t clipped_coords;
if(!_lv_area_intersect(&clipped_coords, &rel_coords, &rel_clip_area))
return; /*Fully clipped, nothing to do*/
_vglite_draw_border(&rel_coords, &rel_clip_area, dsc);
}
/**********************
* STATIC FUNCTIONS
**********************/
static void _vglite_draw_border(const lv_area_t * coords, const lv_area_t * clip_area,
const lv_draw_border_dsc_t * dsc)
{
vg_lite_error_t err = VG_LITE_SUCCESS;
int32_t radius = dsc->radius;
vg_lite_buffer_t * vgbuf = vglite_get_dest_buf();
if(radius < 0)
return;
int32_t border_half = (int32_t)floor(dsc->width / 2.0f);
if(radius > border_half)
radius = radius - border_half;
//else {
// /* Draw outline - always has radius, leave the same radius in the circle case */
// int32_t outline_half = (int32_t)ceil(dsc->outline_width / 2.0f);
// if(radius < (int32_t)LV_RADIUS_CIRCLE - outline_half)
// radius = radius + outline_half;
//}
vg_lite_cap_style_t cap_style = (radius) ? VG_LITE_CAP_ROUND : VG_LITE_CAP_BUTT;
vg_lite_join_style_t join_style = (radius) ? VG_LITE_JOIN_ROUND : VG_LITE_JOIN_MITER;
/*** Init path ***/
int32_t path_data[RECT_PATH_DATA_MAX_SIZE];
uint32_t path_data_size;
vglite_create_rect_path_data(path_data, &path_data_size, radius, coords);
vg_lite_quality_t path_quality = radius > 0 ? VG_LITE_HIGH : VG_LITE_MEDIUM;
vg_lite_path_t path;
err = vg_lite_init_path(&path, VG_LITE_S32, path_quality, path_data_size, path_data,
(vg_lite_float_t)clip_area->x1, (vg_lite_float_t)clip_area->y1,
((vg_lite_float_t)clip_area->x2) + 1.0f, ((vg_lite_float_t)clip_area->y2) + 1.0f);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Init path failed.");
lv_color32_t col32 = lv_color_to_32(dsc->color, dsc->opa);
vg_lite_color_t vgcol = vglite_get_color(col32, false);
vg_lite_matrix_t matrix;
vg_lite_identity(&matrix);
int32_t line_width = dsc->width;
/*** Draw border ***/
err = vg_lite_set_draw_path_type(&path, VG_LITE_DRAW_STROKE_PATH);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Set draw path type failed.");
err = vg_lite_set_stroke(&path, cap_style, join_style, line_width, 8, NULL, 0, 0, vgcol);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Set stroke failed.");
err = vg_lite_update_stroke(&path);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Update stroke failed.");
vglite_set_scissor(clip_area);
err = vg_lite_draw(vgbuf, &path, VG_LITE_FILL_NON_ZERO, &matrix, VG_LITE_BLEND_SRC_OVER, vgcol);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Draw border failed.");
vglite_run();
vglite_disable_scissor();
err = vg_lite_clear_path(&path);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Clear path failed.");
}
#endif /*LV_USE_DRAW_VGLITE*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/vglite/lv_vglite_buf.c | /**
* @file lv_vglite_buf.c
*
*/
/**
* Copyright 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_vglite_buf.h"
#if LV_USE_DRAW_VGLITE
#include "lv_vglite_utils.h"
#include "../../../stdlib/lv_string.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static inline void _set_vgbuf_ptr(vg_lite_buffer_t * vgbuf, void * buf);
/**********************
* STATIC VARIABLES
**********************/
static vg_lite_buffer_t _dest_vgbuf;
static vg_lite_buffer_t _src_vgbuf;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
vg_lite_buffer_t * vglite_get_dest_buf(void)
{
return &_dest_vgbuf;
}
vg_lite_buffer_t * vglite_get_src_buf(void)
{
return &_src_vgbuf;
}
void vglite_set_dest_buf_ptr(void * buf)
{
_set_vgbuf_ptr(&_dest_vgbuf, buf);
}
void vglite_set_src_buf_ptr(const void * buf)
{
_set_vgbuf_ptr(&_src_vgbuf, (void *)buf);
}
void vglite_set_dest_buf(const lv_draw_buf_t * draw_buf)
{
vglite_set_buf(&_dest_vgbuf, draw_buf->buf, draw_buf->width, draw_buf->height,
lv_draw_buf_get_stride(draw_buf), draw_buf->color_format);
}
void vglite_set_src_buf(const void * buf, int32_t width, int32_t height, uint32_t stride,
lv_color_format_t cf)
{
vglite_set_buf(&_src_vgbuf, (void *)buf, width, height, stride, cf);
}
void vglite_set_buf(vg_lite_buffer_t * vgbuf, void * buf,
int32_t width, int32_t height, uint32_t stride,
lv_color_format_t cf)
{
vg_lite_buffer_format_t vgformat = vglite_get_buf_format(cf);
vgbuf->format = vgformat;
vgbuf->tiled = VG_LITE_LINEAR;
vgbuf->image_mode = VG_LITE_NORMAL_IMAGE_MODE;
vgbuf->transparency_mode = VG_LITE_IMAGE_OPAQUE;
vgbuf->width = (int32_t)width;
vgbuf->height = (int32_t)height;
vgbuf->stride = (int32_t)stride;
lv_memset(&vgbuf->yuv, 0, sizeof(vgbuf->yuv));
vgbuf->memory = buf;
vgbuf->address = (uint32_t)vgbuf->memory;
vgbuf->handle = NULL;
}
/**********************
* STATIC FUNCTIONS
**********************/
static inline void _set_vgbuf_ptr(vg_lite_buffer_t * vgbuf, void * buf)
{
vgbuf->memory = buf;
vgbuf->address = (uint32_t)vgbuf->memory;
}
#endif /*LV_USE_DRAW_VGLITE*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp | repos/zig_workbench/BaseLVGL/lib/lvgl/src/draw/nxp/vglite/lv_draw_vglite_line.c | /**
* @file lv_draw_vglite_line.c
*
*/
/**
* Copyright 2022, 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_vglite.h"
#if LV_USE_DRAW_VGLITE
#include "lv_vglite_buf.h"
#include "lv_vglite_utils.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**
* Draw line shape with effects
*
* @param[in] point1 Starting point with relative coordinates
* @param[in] point2 Ending point with relative coordinates
* @param[in] clip_area Clipping area with relative coordinates to dest buff
* @param[in] dsc Line description structure (width, rounded ending, opacity, ...)
*
*/
static void _vglite_draw_line(const lv_point_t * point1, const lv_point_t * point2,
const lv_area_t * clip_area, const lv_draw_line_dsc_t * dsc);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_vglite_line(lv_draw_unit_t * draw_unit, const lv_draw_line_dsc_t * dsc)
{
if(dsc->width == 0)
return;
if(dsc->opa <= (lv_opa_t)LV_OPA_MIN)
return;
if(dsc->p1.x == dsc->p2.x && dsc->p1.y == dsc->p2.y)
return;
lv_layer_t * layer = draw_unit->target_layer;
lv_area_t rel_clip_area;
rel_clip_area.x1 = LV_MIN(dsc->p1.x, dsc->p2.x) - dsc->width / 2;
rel_clip_area.x2 = LV_MAX(dsc->p1.x, dsc->p2.x) + dsc->width / 2;
rel_clip_area.y1 = LV_MIN(dsc->p1.y, dsc->p2.y) - dsc->width / 2;
rel_clip_area.y2 = LV_MAX(dsc->p1.y, dsc->p2.y) + dsc->width / 2;
if(!_lv_area_intersect(&rel_clip_area, &rel_clip_area, draw_unit->clip_area))
return; /*Fully clipped, nothing to do*/
lv_area_move(&rel_clip_area, -layer->draw_buf_ofs.x, -layer->draw_buf_ofs.y);
lv_point_t rel_point1 = {dsc->p1.x - layer->draw_buf_ofs.x, dsc->p1.y - layer->draw_buf_ofs.y};
lv_point_t rel_point2 = {dsc->p2.x - layer->draw_buf_ofs.x, dsc->p2.y - layer->draw_buf_ofs.y};
_vglite_draw_line(&rel_point1, &rel_point2, &rel_clip_area, dsc);
}
/**********************
* STATIC FUNCTIONS
**********************/
static void _vglite_draw_line(const lv_point_t * point1, const lv_point_t * point2,
const lv_area_t * clip_area, const lv_draw_line_dsc_t * dsc)
{
vg_lite_error_t err = VG_LITE_SUCCESS;
vg_lite_path_t path;
vg_lite_buffer_t * vgbuf = vglite_get_dest_buf();
vg_lite_cap_style_t cap_style = (dsc->round_start || dsc->round_end) ? VG_LITE_CAP_ROUND : VG_LITE_CAP_BUTT;
vg_lite_join_style_t join_style = (dsc->round_start || dsc->round_end) ? VG_LITE_JOIN_ROUND : VG_LITE_JOIN_MITER;
bool is_dashed = (dsc->dash_width && dsc->dash_gap);
vg_lite_float_t stroke_dash_pattern[2] = {0, 0};
uint32_t stroke_dash_count = 0;
vg_lite_float_t stroke_dash_phase = 0;
if(is_dashed) {
stroke_dash_pattern[0] = (vg_lite_float_t)dsc->dash_width;
stroke_dash_pattern[1] = (vg_lite_float_t)dsc->dash_gap;
stroke_dash_count = sizeof(stroke_dash_pattern) / sizeof(vg_lite_float_t);
stroke_dash_phase = (vg_lite_float_t)dsc->dash_width / 2;
}
/* Choose vglite blend mode based on given lvgl blend mode */
vg_lite_blend_t vglite_blend_mode = vglite_get_blend_mode(dsc->blend_mode);
/*** Init path ***/
int32_t width = dsc->width;
int32_t line_path[] = { /*VG line path*/
VLC_OP_MOVE, point1->x, point1->y,
VLC_OP_LINE, point2->x, point2->y,
VLC_OP_END
};
err = vg_lite_init_path(&path, VG_LITE_S32, VG_LITE_HIGH, sizeof(line_path), line_path,
(vg_lite_float_t)clip_area->x1, (vg_lite_float_t)clip_area->y1,
((vg_lite_float_t)clip_area->x2) + 1.0f, ((vg_lite_float_t)clip_area->y2) + 1.0f);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Init path failed.");
lv_color32_t col32 = lv_color_to_32(dsc->color, dsc->opa);
vg_lite_color_t vgcol = vglite_get_color(col32, false);
vg_lite_matrix_t matrix;
vg_lite_identity(&matrix);
/*** Draw line ***/
err = vg_lite_set_draw_path_type(&path, VG_LITE_DRAW_STROKE_PATH);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Set draw path type failed.");
err = vg_lite_set_stroke(&path, cap_style, join_style, width, 8, stroke_dash_pattern, stroke_dash_count,
stroke_dash_phase, vgcol);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Set stroke failed.");
err = vg_lite_update_stroke(&path);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Update stroke failed.");
vglite_set_scissor(clip_area);
err = vg_lite_draw(vgbuf, &path, VG_LITE_FILL_NON_ZERO, &matrix, vglite_blend_mode, vgcol);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Draw line failed.");
vglite_run();
vglite_disable_scissor();
err = vg_lite_clear_path(&path);
LV_ASSERT_MSG(err == VG_LITE_SUCCESS, "Clear path failed.");
}
#endif /*LV_USE_DRAW_VGLITE*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_profiler_builtin.h | /**
* @file lv_profiler_builtin.h
*
*/
#ifndef LV_PROFILER_BUILTIN_H
#define LV_PROFILER_BUILTIN_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#if LV_USE_PROFILER && LV_USE_PROFILER_BUILTIN
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
/*********************
* DEFINES
*********************/
#define LV_PROFILER_BUILTIN_BEGIN_TAG(tag) lv_profiler_builtin_write((tag), 'B')
#define LV_PROFILER_BUILTIN_END_TAG(tag) lv_profiler_builtin_write((tag), 'E')
#define LV_PROFILER_BUILTIN_BEGIN LV_PROFILER_BUILTIN_BEGIN_TAG(__func__)
#define LV_PROFILER_BUILTIN_END LV_PROFILER_BUILTIN_END_TAG(__func__)
/**********************
* TYPEDEFS
**********************/
/**
* @brief LVGL profiler built-in configuration structure
*/
typedef struct {
size_t buf_size; /**< The size of the buffer used for profiling data */
uint32_t tick_per_sec; /**< The number of ticks per second */
uint32_t (*tick_get_cb)(void); /**< Callback function to get the current tick count */
void (*flush_cb)(const char * buf); /**< Callback function to flush the profiling data */
} lv_profiler_builtin_config_t;
/**
* @brief Structure representing a built-in profiler item in LVGL
*/
typedef struct {
char tag; /**< The tag of the profiler item */
uint32_t tick; /**< The tick value of the profiler item */
const char * func; /**< A pointer to the function associated with the profiler item */
} lv_profiler_builtin_item_t;
/**
* @brief Structure representing a context for the LVGL built-in profiler
*/
typedef struct {
lv_profiler_builtin_item_t * item_arr; /**< Pointer to an array of profiler items */
uint32_t item_num; /**< Number of profiler items in the array */
uint32_t cur_index; /**< Index of the current profiler item */
lv_profiler_builtin_config_t config; /**< Configuration for the built-in profiler */
} lv_profiler_builtin_ctx_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* @brief Initialize the configuration of the built-in profiler
* @param config Pointer to the configuration structure of the built-in profiler
*/
void lv_profiler_builtin_config_init(lv_profiler_builtin_config_t * config);
/**
* @brief Initialize the built-in profiler with the given configuration
* @param config Pointer to the configuration structure of the built-in profiler
*/
void lv_profiler_builtin_init(const lv_profiler_builtin_config_t * config);
/**
* @brief Uninitialize the built-in profiler
*/
void lv_profiler_builtin_uninit(void);
/**
* @brief Flush the profiling data to the console
*/
void lv_profiler_builtin_flush(void);
/**
* @brief Write the profiling data for a function with the given tag
* @param func Name of the function being profiled
* @param tag Tag to associate with the profiling data for the function
*/
void lv_profiler_builtin_write(const char * func, char tag);
/**********************
* MACROS
**********************/
#endif /*LV_USE_PROFILER_BUILTIN*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_PROFILER_BUILTIN_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_cache_builtin.c | /**
* @file lv_cache_builtin.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_cache.h"
#include "../stdlib/lv_string.h"
#include "../core/lv_global.h"
#include "../misc/lv_ll.h"
#include "../osal/lv_os.h"
/*********************
* DEFINES
*********************/
#define _cache_manager LV_GLOBAL_DEFAULT()->cache_manager
#define dsc LV_GLOBAL_DEFAULT()->cache_builtin_dsc
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static lv_cache_entry_t * add_cb(size_t size);
static lv_cache_entry_t * find_cb(const void * src, lv_cache_src_type_t src_type, uint32_t param1, uint32_t param2);
static void invalidate_cb(lv_cache_entry_t * entry);
static const void * get_data_cb(lv_cache_entry_t * entry);
static void release_cb(lv_cache_entry_t * entry);
static void set_max_size_cb(size_t new_size);
static void empty_cb(void);
static bool drop_youngest(void);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
#if LV_USE_LOG && LV_LOG_TRACE_CACHE
#define LV_TRACE_CACHE(...) LV_LOG_TRACE(__VA_ARGS__)
#else
#define LV_TRACE_CACHE(...)
#endif
/**********************
* GLOBAL FUNCTIONS
**********************/
void _lv_cache_builtin_init(void)
{
lv_memzero(&dsc, sizeof(lv_cache_builtin_dsc_t));
_lv_ll_init(&dsc.entry_ll, sizeof(lv_cache_entry_t));
_cache_manager.add_cb = add_cb;
_cache_manager.find_cb = find_cb;
_cache_manager.invalidate_cb = invalidate_cb;
_cache_manager.get_data_cb = get_data_cb;
_cache_manager.release_cb = release_cb;
_cache_manager.set_max_size_cb = set_max_size_cb;
_cache_manager.empty_cb = empty_cb;
}
/**********************
* STATIC FUNCTIONS
**********************/
static lv_cache_entry_t * add_cb(size_t size)
{
size_t max_size = lv_cache_get_max_size();
/*Can't cache data larger than max size*/
bool temporary = size > max_size ? true : false;
if(!temporary) {
/*Keep dropping items until there is enough space*/
while(dsc.cur_size + size > _cache_manager.max_size) {
bool ret = drop_youngest();
/*No item could be dropped.
*It can happen because the usage_count of the remaining items are not zero.*/
if(ret == false) {
temporary = true;
break;
}
}
}
lv_cache_entry_t * entry = _lv_ll_ins_head(&dsc.entry_ll);
lv_memzero(entry, sizeof(lv_cache_entry_t));
entry->data_size = size;
entry->weight = 1;
entry->temporary = temporary;
if(temporary) {
LV_TRACE_CACHE("Add temporary cache: %lu bytes", (unsigned long)size);
}
else {
LV_TRACE_CACHE("Add cache: %lu bytes", (unsigned long)size);
dsc.cur_size += size;
}
return entry;
}
static lv_cache_entry_t * find_cb(const void * src, lv_cache_src_type_t src_type, uint32_t param1, uint32_t param2)
{
lv_cache_entry_t * entry = _lv_ll_get_head(&dsc.entry_ll);
while(entry) {
if(param1 == entry->param1 && param2 == entry->param2 && src_type == entry->src_type &&
((src_type == LV_CACHE_SRC_TYPE_PTR && src == entry->src) ||
(src_type == LV_CACHE_SRC_TYPE_STR && strcmp(src, entry->src) == 0))) {
return entry;
}
entry = _lv_ll_get_next(&dsc.entry_ll, entry);
}
return NULL;
}
static void invalidate_cb(lv_cache_entry_t * entry)
{
if(entry == NULL) return;
dsc.cur_size -= entry->data_size;
LV_TRACE_CACHE("Drop cache: %u bytes", (uint32_t)entry->data_size);
if(entry->free_src) lv_free((void *)entry->src);
if(entry->free_data) lv_draw_buf_free((void *)entry->data);
_lv_ll_remove(&dsc.entry_ll, entry);
lv_free(entry);
}
static const void * get_data_cb(lv_cache_entry_t * entry)
{
lv_cache_entry_t * e = _lv_ll_get_head(&dsc.entry_ll);
while(e) {
e->life += e->weight;
e = _lv_ll_get_next(&dsc.entry_ll, e);
}
entry->usage_count++;
return entry->data;
}
static void release_cb(lv_cache_entry_t * entry)
{
if(entry == NULL) return;
if(entry->temporary) {
invalidate_cb(entry);
}
else {
if(entry->usage_count == 0) {
LV_LOG_ERROR("More lv_cache_release than lv_cache_get_data");
return;
}
entry->usage_count--;
}
}
static void set_max_size_cb(size_t new_size)
{
while(dsc.cur_size > new_size) {
bool ret = drop_youngest();
/*No item could be dropped.
*It can happen because the usage_count of the remaining items are not zero.*/
if(ret == false) return;
}
}
static void empty_cb(void)
{
lv_cache_entry_t * entry_to_drop = NULL;
lv_cache_entry_t * entry = _lv_ll_get_head(&dsc.entry_ll);
while(entry) {
entry_to_drop = entry;
entry = _lv_ll_get_next(&dsc.entry_ll, entry);
invalidate_cb(entry_to_drop);
}
}
static bool drop_youngest(void)
{
int32_t life_min = INT32_MAX;
lv_cache_entry_t * entry_to_drop = NULL;
lv_cache_entry_t * entry = _lv_ll_get_head(&dsc.entry_ll);
while(entry) {
if(entry->life < life_min && entry->usage_count == 0) entry_to_drop = entry;
entry = _lv_ll_get_next(&dsc.entry_ll, entry);
}
if(entry_to_drop == NULL) {
return false;
}
invalidate_cb(entry_to_drop);
return true;
}
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_text.c | /**
* @file lv_text.c
*
*/
/*********************
* INCLUDES
*********************/
#include <stdarg.h>
#include "lv_text.h"
#include "lv_text_ap.h"
#include "lv_math.h"
#include "lv_log.h"
#include "lv_assert.h"
#include "../stdlib/lv_mem.h"
#include "../stdlib/lv_string.h"
/*********************
* DEFINES
*********************/
#define NO_BREAK_FOUND UINT32_MAX
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
#if LV_TXT_ENC == LV_TXT_ENC_UTF8
static uint8_t lv_text_utf8_size(const char * str);
static uint32_t lv_text_unicode_to_utf8(uint32_t letter_uni);
static uint32_t lv_text_utf8_conv_wc(uint32_t c);
static uint32_t lv_text_utf8_next(const char * txt, uint32_t * i);
static uint32_t lv_text_utf8_prev(const char * txt, uint32_t * i_start);
static uint32_t lv_text_utf8_get_byte_id(const char * txt, uint32_t utf8_id);
static uint32_t lv_text_utf8_get_char_id(const char * txt, uint32_t byte_id);
static uint32_t lv_text_utf8_get_length(const char * txt);
#elif LV_TXT_ENC == LV_TXT_ENC_ASCII
static uint8_t lv_text_iso8859_1_size(const char * str);
static uint32_t lv_text_unicode_to_iso8859_1(uint32_t letter_uni);
static uint32_t lv_text_iso8859_1_conv_wc(uint32_t c);
static uint32_t lv_text_iso8859_1_next(const char * txt, uint32_t * i);
static uint32_t lv_text_iso8859_1_prev(const char * txt, uint32_t * i_start);
static uint32_t lv_text_iso8859_1_get_byte_id(const char * txt, uint32_t utf8_id);
static uint32_t lv_text_iso8859_1_get_char_id(const char * txt, uint32_t byte_id);
static uint32_t lv_text_iso8859_1_get_length(const char * txt);
#endif
/**********************
* STATIC VARIABLES
**********************/
/**********************
* GLOBAL VARIABLES
**********************/
#if LV_TXT_ENC == LV_TXT_ENC_UTF8
uint8_t (*_lv_text_encoded_size)(const char *) = lv_text_utf8_size;
uint32_t (*_lv_text_unicode_to_encoded)(uint32_t) = lv_text_unicode_to_utf8;
uint32_t (*_lv_text_encoded_conv_wc)(uint32_t) = lv_text_utf8_conv_wc;
uint32_t (*_lv_text_encoded_next)(const char *, uint32_t *) = lv_text_utf8_next;
uint32_t (*_lv_text_encoded_prev)(const char *, uint32_t *) = lv_text_utf8_prev;
uint32_t (*_lv_text_encoded_get_byte_id)(const char *, uint32_t) = lv_text_utf8_get_byte_id;
uint32_t (*_lv_text_encoded_get_char_id)(const char *, uint32_t) = lv_text_utf8_get_char_id;
uint32_t (*_lv_text_get_encoded_length)(const char *) = lv_text_utf8_get_length;
#elif LV_TXT_ENC == LV_TXT_ENC_ASCII
uint8_t (*_lv_text_encoded_size)(const char *) = lv_text_iso8859_1_size;
uint32_t (*_lv_text_unicode_to_encoded)(uint32_t) = lv_text_unicode_to_iso8859_1;
uint32_t (*_lv_text_encoded_conv_wc)(uint32_t) = lv_text_iso8859_1_conv_wc;
uint32_t (*_lv_text_encoded_next)(const char *, uint32_t *) = lv_text_iso8859_1_next;
uint32_t (*_lv_text_encoded_prev)(const char *, uint32_t *) = lv_text_iso8859_1_prev;
uint32_t (*_lv_text_encoded_get_byte_id)(const char *, uint32_t) = lv_text_iso8859_1_get_byte_id;
uint32_t (*_lv_text_encoded_get_char_id)(const char *, uint32_t) = lv_text_iso8859_1_get_char_id;
uint32_t (*_lv_text_get_encoded_length)(const char *) = lv_text_iso8859_1_get_length;
#endif
/**********************
* MACROS
**********************/
#define LV_IS_ASCII(value) ((value & 0x80U) == 0x00U)
#define LV_IS_2BYTES_UTF8_CODE(value) ((value & 0xE0U) == 0xC0U)
#define LV_IS_3BYTES_UTF8_CODE(value) ((value & 0xF0U) == 0xE0U)
#define LV_IS_4BYTES_UTF8_CODE(value) ((value & 0xF8U) == 0xF0U)
#define LV_IS_INVALID_UTF8_CODE(value) ((value & 0xC0U) != 0x80U)
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_text_get_size(lv_point_t * size_res, const char * text, const lv_font_t * font, int32_t letter_space,
int32_t line_space, int32_t max_width, lv_text_flag_t flag)
{
size_res->x = 0;
size_res->y = 0;
if(text == NULL) return;
if(font == NULL) return;
if(flag & LV_TEXT_FLAG_EXPAND) max_width = LV_COORD_MAX;
uint32_t line_start = 0;
uint32_t new_line_start = 0;
uint16_t letter_height = lv_font_get_line_height(font);
/*Calc. the height and longest line*/
while(text[line_start] != '\0') {
new_line_start += _lv_text_get_next_line(&text[line_start], font, letter_space, max_width, NULL, flag);
if((unsigned long)size_res->y + (unsigned long)letter_height + (unsigned long)line_space > LV_MAX_OF(int32_t)) {
LV_LOG_WARN("integer overflow while calculating text height");
return;
}
else {
size_res->y += letter_height;
size_res->y += line_space;
}
/*Calculate the longest line*/
int32_t act_line_length = lv_text_get_width(&text[line_start], new_line_start - line_start, font, letter_space);
size_res->x = LV_MAX(act_line_length, size_res->x);
line_start = new_line_start;
}
/*Make the text one line taller if the last character is '\n' or '\r'*/
if((line_start != 0) && (text[line_start - 1] == '\n' || text[line_start - 1] == '\r')) {
size_res->y += letter_height + line_space;
}
/*Correction with the last line space or set the height manually if the text is empty*/
if(size_res->y == 0)
size_res->y = letter_height;
else
size_res->y -= line_space;
}
/**
* Get the next word of text. A word is delimited by break characters.
*
* If the word cannot fit in the max_width space, obey LV_TXT_LINE_BREAK_LONG_* rules.
*
* If the next word cannot fit anything, return 0.
*
* If the first character is a break character, returns the next index.
*
* Example calls from lv_text_get_next_line() assuming sufficient max_width and
* txt = "Test text\n"
* 0123456789
*
* Calls would be as follows:
* 1. Return i=4, pointing at breakchar ' ', for the string "Test"
* 2. Return i=5, since i=4 was a breakchar.
* 3. Return i=9, pointing at breakchar '\n'
* 4. Parenting lv_text_get_next_line() would detect subsequent '\0'
*
* TODO: Returned word_w_ptr may overestimate the returned word's width when
* max_width is reached. In current usage, this has no impact.
*
* @param txt a '\0' terminated string
* @param font pointer to a font
* @param letter_space letter space
* @param max_width max width of the text (break the lines to fit this size). Set COORD_MAX to avoid line breaks
* @param flags settings for the text from 'txt_flag_type' enum
* @param[out] word_w_ptr width (in pixels) of the parsed word. May be NULL.
* @param force Force return the fraction of the word that can fit in the provided space.
* @return the index of the first char of the next word (in byte index not letter index. With UTF-8 they are different)
*/
static uint32_t lv_text_get_next_word(const char * txt, const lv_font_t * font,
int32_t letter_space, int32_t max_width,
lv_text_flag_t flag, uint32_t * word_w_ptr, bool force)
{
if(txt == NULL || txt[0] == '\0') return 0;
if(font == NULL) return 0;
if(flag & LV_TEXT_FLAG_EXPAND) max_width = LV_COORD_MAX;
uint32_t i = 0, i_next = 0, i_next_next = 0; /*Iterating index into txt*/
uint32_t letter = 0; /*Letter at i*/
uint32_t letter_next = 0; /*Letter at i_next*/
int32_t letter_w;
int32_t cur_w = 0; /*Pixel Width of transversed string*/
uint32_t word_len = 0; /*Number of characters in the transversed word*/
uint32_t break_index = NO_BREAK_FOUND; /*only used for "long" words*/
uint32_t break_letter_count = 0; /*Number of characters up to the long word break point*/
letter = _lv_text_encoded_next(txt, &i_next);
i_next_next = i_next;
/*Obtain the full word, regardless if it fits or not in max_width*/
while(txt[i] != '\0') {
letter_next = _lv_text_encoded_next(txt, &i_next_next);
word_len++;
letter_w = lv_font_get_glyph_width(font, letter, letter_next);
cur_w += letter_w;
if(letter_w > 0) {
cur_w += letter_space;
}
/*Test if this character fits within max_width*/
if(break_index == NO_BREAK_FOUND && (cur_w - letter_space) > max_width) {
break_index = i;
break_letter_count = word_len - 1;
/*break_index is now pointing at the character that doesn't fit*/
}
/*Check for new line chars and breakchars*/
if(letter == '\n' || letter == '\r' || _lv_text_is_break_char(letter)) {
/*Update the output width on the first character if it fits.
*Must do this here in case first letter is a break character.*/
if(i == 0 && break_index == NO_BREAK_FOUND && word_w_ptr != NULL) *word_w_ptr = cur_w;
word_len--;
break;
}
else if(_lv_text_is_a_word(letter_next) || _lv_text_is_a_word(letter)) {
/*Found a word for single letter, usually true for CJK*/
*word_w_ptr = cur_w;
i = i_next;
break;
}
/*Update the output width*/
if(word_w_ptr != NULL && break_index == NO_BREAK_FOUND) *word_w_ptr = cur_w;
i = i_next;
i_next = i_next_next;
letter = letter_next;
}
/*Entire Word fits in the provided space*/
if(break_index == NO_BREAK_FOUND) {
if(word_len == 0 || (letter == '\r' && letter_next == '\n')) i = i_next;
return i;
}
#if LV_TXT_LINE_BREAK_LONG_LEN > 0
/*Word doesn't fit in provided space, but isn't "long"*/
if(word_len < LV_TXT_LINE_BREAK_LONG_LEN) {
if(force) return break_index;
if(word_w_ptr != NULL) *word_w_ptr = 0; /*Return no word*/
return 0;
}
/*Word is "long," but insufficient amounts can fit in provided space*/
if(break_letter_count < LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN) {
if(force) return break_index;
if(word_w_ptr != NULL) *word_w_ptr = 0;
return 0;
}
/*Word is a "long", but letters may need to be better distributed*/
{
i = break_index;
int32_t n_move = LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN - (word_len - break_letter_count);
/*Move pointer "i" backwards*/
for(; n_move > 0; n_move--) {
_lv_text_encoded_prev(txt, &i);
// TODO: it would be appropriate to update the returned word width here
// However, in current usage, this doesn't impact anything.
}
}
return i;
#else
if(force) return break_index;
if(word_w_ptr != NULL) *word_w_ptr = 0; /*Return no word*/
(void) break_letter_count;
return 0;
#endif
}
uint32_t _lv_text_get_next_line(const char * txt, const lv_font_t * font,
int32_t letter_space, int32_t max_width,
int32_t * used_width, lv_text_flag_t flag)
{
if(used_width) *used_width = 0;
if(txt == NULL) return 0;
if(txt[0] == '\0') return 0;
if(font == NULL) return 0;
int32_t line_w = 0;
/*If max_width doesn't matter simply find the new line character
*without thinking about word wrapping*/
if((flag & LV_TEXT_FLAG_EXPAND) || (flag & LV_TEXT_FLAG_FIT)) {
uint32_t i;
for(i = 0; txt[i] != '\n' && txt[i] != '\r' && txt[i] != '\0'; i++) {
/*Just find the new line chars or string ends by incrementing `i`*/
}
if(txt[i] != '\0') i++; /*To go beyond `\n`*/
if(used_width) *used_width = -1;
return i;
}
if(flag & LV_TEXT_FLAG_EXPAND) max_width = LV_COORD_MAX;
uint32_t i = 0; /*Iterating index into txt*/
while(txt[i] != '\0' && max_width > 0) {
uint32_t word_w = 0;
uint32_t advance = lv_text_get_next_word(&txt[i], font, letter_space, max_width, flag, &word_w, i == 0);
max_width -= word_w;
line_w += word_w;
if(advance == 0) {
break;
}
i += advance;
if(txt[0] == '\n' || txt[0] == '\r') break;
if(txt[i] == '\n' || txt[i] == '\r') {
i++; /*Include the following newline in the current line*/
break;
}
}
/*Always step at least one to avoid infinite loops*/
if(i == 0) {
uint32_t letter = _lv_text_encoded_next(txt, &i);
if(used_width != NULL) {
line_w = lv_font_get_glyph_width(font, letter, '\0');
}
}
if(used_width != NULL) {
*used_width = line_w;
}
return i;
}
int32_t lv_text_get_width(const char * txt, uint32_t length, const lv_font_t * font, int32_t letter_space)
{
if(txt == NULL) return 0;
if(font == NULL) return 0;
if(txt[0] == '\0') return 0;
uint32_t i = 0;
int32_t width = 0;
if(length != 0) {
while(i < length) {
uint32_t letter;
uint32_t letter_next;
_lv_text_encoded_letter_next_2(txt, &letter, &letter_next, &i);
int32_t char_width = lv_font_get_glyph_width(font, letter, letter_next);
if(char_width > 0) {
width += char_width;
width += letter_space;
}
}
if(width > 0) {
width -= letter_space; /*Trim the last letter space. Important if the text is center
aligned*/
}
}
return width;
}
void _lv_text_ins(char * txt_buf, uint32_t pos, const char * ins_txt)
{
if(txt_buf == NULL || ins_txt == NULL) return;
size_t old_len = lv_strlen(txt_buf);
size_t ins_len = lv_strlen(ins_txt);
if(ins_len == 0) return;
size_t new_len = ins_len + old_len;
pos = _lv_text_encoded_get_byte_id(txt_buf, pos); /*Convert to byte index instead of letter index*/
/*Copy the second part into the end to make place to text to insert*/
size_t i;
for(i = new_len; i >= pos + ins_len; i--) {
txt_buf[i] = txt_buf[i - ins_len];
}
/*Copy the text into the new space*/
lv_memcpy(txt_buf + pos, ins_txt, ins_len);
}
void _lv_text_cut(char * txt, uint32_t pos, uint32_t len)
{
if(txt == NULL) return;
size_t old_len = lv_strlen(txt);
pos = _lv_text_encoded_get_byte_id(txt, pos); /*Convert to byte index instead of letter index*/
len = _lv_text_encoded_get_byte_id(&txt[pos], len);
/*Copy the second part into the end to make place to text to insert*/
uint32_t i;
for(i = pos; i <= old_len - len; i++) {
txt[i] = txt[i + len];
}
}
char * _lv_text_set_text_vfmt(const char * fmt, va_list ap)
{
/*Allocate space for the new text by using trick from C99 standard section 7.19.6.12*/
va_list ap_copy;
va_copy(ap_copy, ap);
uint32_t len = lv_vsnprintf(NULL, 0, fmt, ap_copy);
va_end(ap_copy);
char * text = 0;
#if LV_USE_ARABIC_PERSIAN_CHARS
/*Put together the text according to the format string*/
char * raw_txt = lv_malloc(len + 1);
LV_ASSERT_MALLOC(raw_txt);
if(raw_txt == NULL) {
return NULL;
}
lv_vsnprintf(raw_txt, len + 1, fmt, ap);
/*Get the size of the Arabic text and process it*/
size_t len_ap = _lv_text_ap_calc_bytes_cnt(raw_txt);
text = lv_malloc(len_ap + 1);
LV_ASSERT_MALLOC(text);
if(text == NULL) {
return NULL;
}
_lv_text_ap_proc(raw_txt, text);
lv_free(raw_txt);
#else
text = lv_malloc(len + 1);
LV_ASSERT_MALLOC(text);
if(text == NULL) {
return NULL;
}
lv_vsnprintf(text, len + 1, fmt, ap);
#endif
return text;
}
void _lv_text_encoded_letter_next_2(const char * txt, uint32_t * letter, uint32_t * letter_next, uint32_t * ofs)
{
*letter = _lv_text_encoded_next(txt, ofs);
*letter_next = *letter != '\0' ? _lv_text_encoded_next(&txt[*ofs], NULL) : 0;
}
#if LV_TXT_ENC == LV_TXT_ENC_UTF8
/*******************************
* UTF-8 ENCODER/DECODER
******************************/
/**
* Give the size of an UTF-8 coded character
* @param str pointer to a character in a string
* @return length of the UTF-8 character (1,2,3 or 4), 0 on invalid code.
*/
static uint8_t lv_text_utf8_size(const char * str)
{
if(LV_IS_ASCII(str[0]))
return 1;
else if(LV_IS_2BYTES_UTF8_CODE(str[0]))
return 2;
else if(LV_IS_3BYTES_UTF8_CODE(str[0]))
return 3;
else if(LV_IS_4BYTES_UTF8_CODE(str[0]))
return 4;
return 0;
}
/**
* Convert a Unicode letter to UTF-8.
* @param letter_uni a Unicode letter
* @return UTF-8 coded character in Little Endian to be compatible with C chars (e.g. 'Á', 'Ű')
*/
static uint32_t lv_text_unicode_to_utf8(uint32_t letter_uni)
{
if(letter_uni < 128) return letter_uni;
uint8_t bytes[4];
if(letter_uni < 0x0800) {
bytes[0] = ((letter_uni >> 6) & 0x1F) | 0xC0;
bytes[1] = ((letter_uni >> 0) & 0x3F) | 0x80;
bytes[2] = 0;
bytes[3] = 0;
}
else if(letter_uni < 0x010000) {
bytes[0] = ((letter_uni >> 12) & 0x0F) | 0xE0;
bytes[1] = ((letter_uni >> 6) & 0x3F) | 0x80;
bytes[2] = ((letter_uni >> 0) & 0x3F) | 0x80;
bytes[3] = 0;
}
else if(letter_uni < 0x110000) {
bytes[0] = ((letter_uni >> 18) & 0x07) | 0xF0;
bytes[1] = ((letter_uni >> 12) & 0x3F) | 0x80;
bytes[2] = ((letter_uni >> 6) & 0x3F) | 0x80;
bytes[3] = ((letter_uni >> 0) & 0x3F) | 0x80;
}
else {
return 0;
}
uint32_t * res_p = (uint32_t *)bytes;
return *res_p;
}
/**
* Convert a wide character, e.g. 'Á' little endian to be UTF-8 compatible
* @param c a wide character or a Little endian number
* @return `c` in big endian
*/
static uint32_t lv_text_utf8_conv_wc(uint32_t c)
{
#if LV_BIG_ENDIAN_SYSTEM == 0
/*Swap the bytes (UTF-8 is big endian, but the MCUs are little endian)*/
if((c & 0x80) != 0) {
uint32_t swapped;
uint8_t c8[4];
lv_memcpy(c8, &c, 4);
swapped = (c8[0] << 24) + (c8[1] << 16) + (c8[2] << 8) + (c8[3]);
uint8_t i;
for(i = 0; i < 4; i++) {
if((swapped & 0xFF) == 0)
swapped = (swapped >> 8); /*Ignore leading zeros (they were in the end originally)*/
}
c = swapped;
}
#endif
return c;
}
/**
* Decode an UTF-8 character from a string.
* @param txt pointer to '\0' terminated string
* @param i start byte index in 'txt' where to start.
* After call it will point to the next UTF-8 char in 'txt'.
* NULL to use txt[0] as index
* @return the decoded Unicode character or 0 on invalid UTF-8 code
*/
static uint32_t lv_text_utf8_next(const char * txt, uint32_t * i)
{
/**
* Unicode to UTF-8
* 00000000 00000000 00000000 0xxxxxxx -> 0xxxxxxx
* 00000000 00000000 00000yyy yyxxxxxx -> 110yyyyy 10xxxxxx
* 00000000 00000000 zzzzyyyy yyxxxxxx -> 1110zzzz 10yyyyyy 10xxxxxx
* 00000000 000wwwzz zzzzyyyy yyxxxxxx -> 11110www 10zzzzzz 10yyyyyy 10xxxxxx
*/
uint32_t result = 0;
/*Dummy 'i' pointer is required*/
uint32_t i_tmp = 0;
if(i == NULL) i = &i_tmp;
/*Normal ASCII*/
if(LV_IS_ASCII(txt[*i])) {
result = txt[*i];
(*i)++;
}
/*Real UTF-8 decode*/
else {
/*2 bytes UTF-8 code*/
if(LV_IS_2BYTES_UTF8_CODE(txt[*i])) {
result = (uint32_t)(txt[*i] & 0x1F) << 6;
(*i)++;
if(LV_IS_INVALID_UTF8_CODE(txt[*i])) return 0;
result += (txt[*i] & 0x3F);
(*i)++;
}
/*3 bytes UTF-8 code*/
else if(LV_IS_3BYTES_UTF8_CODE(txt[*i])) {
result = (uint32_t)(txt[*i] & 0x0F) << 12;
(*i)++;
if(LV_IS_INVALID_UTF8_CODE(txt[*i])) return 0;
result += (uint32_t)(txt[*i] & 0x3F) << 6;
(*i)++;
if(LV_IS_INVALID_UTF8_CODE(txt[*i])) return 0;
result += (txt[*i] & 0x3F);
(*i)++;
}
/*4 bytes UTF-8 code*/
else if(LV_IS_4BYTES_UTF8_CODE(txt[*i])) {
result = (uint32_t)(txt[*i] & 0x07) << 18;
(*i)++;
if(LV_IS_INVALID_UTF8_CODE(txt[*i])) return 0;
result += (uint32_t)(txt[*i] & 0x3F) << 12;
(*i)++;
if(LV_IS_INVALID_UTF8_CODE(txt[*i])) return 0;
result += (uint32_t)(txt[*i] & 0x3F) << 6;
(*i)++;
if(LV_IS_INVALID_UTF8_CODE(txt[*i])) return 0;
result += txt[*i] & 0x3F;
(*i)++;
}
else {
(*i)++; /*Not UTF-8 char. Go the next.*/
}
}
return result;
}
/**
* Get previous UTF-8 character form a string.
* @param txt pointer to '\0' terminated string
* @param i start byte index in 'txt' where to start. After the call it will point to the previous
* UTF-8 char in 'txt'.
* @return the decoded Unicode character or 0 on invalid UTF-8 code
*/
static uint32_t lv_text_utf8_prev(const char * txt, uint32_t * i)
{
uint8_t c_size;
uint8_t cnt = 0;
/*Try to find a !0 long UTF-8 char by stepping one character back*/
(*i)--;
do {
if(cnt >= 4) return 0; /*No UTF-8 char found before the initial*/
c_size = _lv_text_encoded_size(&txt[*i]);
if(c_size == 0) {
if(*i != 0)
(*i)--;
else
return 0;
}
cnt++;
} while(c_size == 0);
uint32_t i_tmp = *i;
uint32_t letter = _lv_text_encoded_next(txt, &i_tmp); /*Character found, get it*/
return letter;
}
/**
* Convert a character index (in an UTF-8 text) to byte index.
* E.g. in "AÁRT" index of 'R' is 2th char but start at byte 3 because 'Á' is 2 bytes long
* @param txt a '\0' terminated UTF-8 string
* @param utf8_id character index
* @return byte index of the 'utf8_id'th letter
*/
static uint32_t lv_text_utf8_get_byte_id(const char * txt, uint32_t utf8_id)
{
uint32_t i;
uint32_t byte_cnt = 0;
for(i = 0; i < utf8_id && txt[byte_cnt] != '\0'; i++) {
uint8_t c_size = _lv_text_encoded_size(&txt[byte_cnt]);
/* If the char was invalid tell it's 1 byte long*/
byte_cnt += c_size ? c_size : 1;
}
return byte_cnt;
}
/**
* Convert a byte index (in an UTF-8 text) to character index.
* E.g. in "AÁRT" index of 'R' is 2th char but start at byte 3 because 'Á' is 2 bytes long
* @param txt a '\0' terminated UTF-8 string
* @param byte_id byte index
* @return character index of the letter at 'byte_id'th position
*/
static uint32_t lv_text_utf8_get_char_id(const char * txt, uint32_t byte_id)
{
uint32_t i = 0;
uint32_t char_cnt = 0;
while(i < byte_id) {
_lv_text_encoded_next(txt, &i); /*'i' points to the next letter so use the prev. value*/
char_cnt++;
}
return char_cnt;
}
/**
* Get the number of characters (and NOT bytes) in a string. Decode it with UTF-8 if enabled.
* E.g.: "ÁBC" is 3 characters (but 4 bytes)
* @param txt a '\0' terminated char string
* @return number of characters
*/
static uint32_t lv_text_utf8_get_length(const char * txt)
{
uint32_t len = 0;
uint32_t i = 0;
while(txt[i] != '\0') {
_lv_text_encoded_next(txt, &i);
len++;
}
return len;
}
#elif LV_TXT_ENC == LV_TXT_ENC_ASCII
/*******************************
* ASCII ENCODER/DECODER
******************************/
/**
* Give the size of an ISO8859-1 coded character
* @param str pointer to a character in a string
* @return length of the UTF-8 character (1,2,3 or 4). O on invalid code
*/
static uint8_t lv_text_iso8859_1_size(const char * str)
{
LV_UNUSED(str); /*Unused*/
return 1;
}
/**
* Convert a Unicode letter to ISO8859-1.
* @param letter_uni a Unicode letter
* @return ISO8859-1 coded character in Little Endian to be compatible with C chars (e.g. 'Á', 'Ű')
*/
static uint32_t lv_text_unicode_to_iso8859_1(uint32_t letter_uni)
{
if(letter_uni < 256)
return letter_uni;
else
return ' ';
}
/**
* Convert wide characters to ASCII, however wide characters in ASCII range (e.g. 'A') are ASCII compatible by default.
* So this function does nothing just returns with `c`.
* @param c a character, e.g. 'A'
* @return same as `c`
*/
static uint32_t lv_text_iso8859_1_conv_wc(uint32_t c)
{
return c;
}
/**
* Decode an ISO8859-1 character from a string.
* @param txt pointer to '\0' terminated string
* @param i start byte index in 'txt' where to start.
* After call it will point to the next UTF-8 char in 'txt'.
* NULL to use txt[0] as index
* @return the decoded Unicode character or 0 on invalid UTF-8 code
*/
static uint32_t lv_text_iso8859_1_next(const char * txt, uint32_t * i)
{
if(i == NULL) return txt[0]; /*Get the next char*/
uint8_t letter = txt[*i];
(*i)++;
return letter;
}
/**
* Get previous ISO8859-1 character form a string.
* @param txt pointer to '\0' terminated string
* @param i start byte index in 'txt' where to start. After the call it will point to the previous UTF-8 char in 'txt'.
* @return the decoded Unicode character or 0 on invalid UTF-8 code
*/
static uint32_t lv_text_iso8859_1_prev(const char * txt, uint32_t * i)
{
if(i == NULL) return *(txt - 1); /*Get the prev. char*/
(*i)--;
uint8_t letter = txt[*i];
return letter;
}
/**
* Convert a character index (in an ISO8859-1 text) to byte index.
* E.g. in "AÁRT" index of 'R' is 2th char but start at byte 3 because 'Á' is 2 bytes long
* @param txt a '\0' terminated UTF-8 string
* @param utf8_id character index
* @return byte index of the 'utf8_id'th letter
*/
static uint32_t lv_text_iso8859_1_get_byte_id(const char * txt, uint32_t utf8_id)
{
LV_UNUSED(txt); /*Unused*/
return utf8_id; /*In Non encoded no difference*/
}
/**
* Convert a byte index (in an ISO8859-1 text) to character index.
* E.g. in "AÁRT" index of 'R' is 2th char but start at byte 3 because 'Á' is 2 bytes long
* @param txt a '\0' terminated UTF-8 string
* @param byte_id byte index
* @return character index of the letter at 'byte_id'th position
*/
static uint32_t lv_text_iso8859_1_get_char_id(const char * txt, uint32_t byte_id)
{
LV_UNUSED(txt); /*Unused*/
return byte_id; /*In Non encoded no difference*/
}
/**
* Get the number of characters (and NOT bytes) in a string. Decode it with UTF-8 if enabled.
* E.g.: "ÁBC" is 3 characters (but 4 bytes)
* @param txt a '\0' terminated char string
* @return number of characters
*/
static uint32_t lv_text_iso8859_1_get_length(const char * txt)
{
return lv_strlen(txt);
}
#else
#error "Invalid character encoding. See `LV_TXT_ENC` in `lv_conf.h`"
#endif
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_bidi.c | /**
* @file lv_bidi.c
*
*/
/*********************
* INCLUDES
*********************/
#include <stddef.h>
#include "lv_bidi.h"
#include "lv_text.h"
#include "../stdlib/lv_mem.h"
#include "../stdlib/lv_string.h"
#if LV_USE_BIDI
/*********************
* DEFINES
*********************/
#define LV_BIDI_BRACKLET_DEPTH 4
// Highest bit of the 16-bit pos_conv value specifies whether this pos is RTL or not
#define GET_POS(x) ((x) & 0x7FFF)
#define IS_RTL_POS(x) (((x) & 0x8000) != 0)
#define SET_RTL_POS(x, is_rtl) (GET_POS(x) | ((is_rtl)? 0x8000: 0))
/**********************
* TYPEDEFS
**********************/
typedef struct {
uint32_t bracklet_pos;
lv_base_dir_t dir;
} bracket_stack_t;
typedef struct {
bracket_stack_t br_stack[LV_BIDI_BRACKLET_DEPTH];
uint8_t br_stack_p;
} lv_bidi_ctx_t;
/**********************
* STATIC PROTOTYPES
**********************/
static uint32_t lv_bidi_get_next_paragraph(const char * txt);
static lv_base_dir_t lv_bidi_get_letter_dir(uint32_t letter);
static bool lv_bidi_letter_is_weak(uint32_t letter);
static bool lv_bidi_letter_is_rtl(uint32_t letter);
static bool lv_bidi_letter_is_neutral(uint32_t letter);
static lv_base_dir_t get_next_run(lv_bidi_ctx_t * ctx, const char * txt, lv_base_dir_t base_dir, uint32_t max_len,
uint32_t * len,
uint16_t * pos_conv_len);
static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t * pos_conv_out, uint16_t pos_conv_rd_base,
uint16_t pos_conv_len);
static uint32_t char_change_to_pair(uint32_t letter);
static lv_base_dir_t bracket_process(lv_bidi_ctx_t * ctx, const char * txt, uint32_t next_pos, uint32_t len,
uint32_t letter,
lv_base_dir_t base_dir);
static void fill_pos_conv(uint16_t * out, uint16_t len, uint16_t index);
static uint32_t get_txt_len(const char * txt, uint32_t max_len);
/**********************
* STATIC VARIABLES
**********************/
static const uint8_t bracket_left[] = {"<({["};
static const uint8_t bracket_right[] = {">)}]"};
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Convert a text to get the characters in the correct visual order according to
* Unicode Bidirectional Algorithm
* @param str_in the text to process
* @param str_out store the result here. Has the be `strlen(str_in)` length
* @param base_dir `LV_BASE_DIR_LTR` or `LV_BASE_DIR_RTL`
*/
void _lv_bidi_process(const char * str_in, char * str_out, lv_base_dir_t base_dir)
{
if(base_dir == LV_BASE_DIR_AUTO) base_dir = _lv_bidi_detect_base_dir(str_in);
uint32_t par_start = 0;
uint32_t par_len;
while(str_in[par_start] == '\n' || str_in[par_start] == '\r') {
str_out[par_start] = str_in[par_start];
par_start ++;
}
while(str_in[par_start] != '\0') {
par_len = lv_bidi_get_next_paragraph(&str_in[par_start]);
_lv_bidi_process_paragraph(&str_in[par_start], &str_out[par_start], par_len, base_dir, NULL, 0);
par_start += par_len;
while(str_in[par_start] == '\n' || str_in[par_start] == '\r') {
str_out[par_start] = str_in[par_start];
par_start ++;
}
}
str_out[par_start] = '\0';
}
/**
* Auto-detect the direction of a text based on the first strong character
* @param txt the text to process
* @return `LV_BASE_DIR_LTR` or `LV_BASE_DIR_RTL`
*/
lv_base_dir_t _lv_bidi_detect_base_dir(const char * txt)
{
uint32_t i = 0;
uint32_t letter;
while(txt[i] != '\0') {
letter = _lv_text_encoded_next(txt, &i);
lv_base_dir_t dir;
dir = lv_bidi_get_letter_dir(letter);
if(dir == LV_BASE_DIR_RTL || dir == LV_BASE_DIR_LTR) return dir;
}
/*If there were no strong char earlier return with the default base dir*/
if(LV_BIDI_BASE_DIR_DEF == LV_BASE_DIR_AUTO) return LV_BASE_DIR_LTR;
else return LV_BIDI_BASE_DIR_DEF;
}
/**
* Get the logical position of a character in a line
* @param str_in the input string. Can be only one line.
* @param bidi_txt internally the text is bidi processed which buffer can be get here.
* If not required anymore has to freed with `lv_free()`
* Can be `NULL` is unused
* @param len length of the line in character count
* @param base_dir base direction of the text: `LV_BASE_DIR_LTR` or `LV_BASE_DIR_RTL`
* @param visual_pos the visual character position which logical position should be get
* @param is_rtl tell the char at `visual_pos` is RTL or LTR context
* @return the logical character position
*/
uint16_t _lv_bidi_get_logical_pos(const char * str_in, char ** bidi_txt, uint32_t len, lv_base_dir_t base_dir,
uint32_t visual_pos, bool * is_rtl)
{
uint32_t pos_conv_len = get_txt_len(str_in, len);
char * buf = lv_malloc(len + 1);
if(buf == NULL) return (uint16_t) -1;
uint16_t * pos_conv_buf = lv_malloc(pos_conv_len * sizeof(uint16_t));
if(pos_conv_buf == NULL) {
lv_free(buf);
return (uint16_t) -1;
}
if(bidi_txt) *bidi_txt = buf;
_lv_bidi_process_paragraph(str_in, bidi_txt ? *bidi_txt : NULL, len, base_dir, pos_conv_buf, pos_conv_len);
if(is_rtl) *is_rtl = IS_RTL_POS(pos_conv_buf[visual_pos]);
if(bidi_txt == NULL) lv_free(buf);
uint16_t res = GET_POS(pos_conv_buf[visual_pos]);
lv_free(pos_conv_buf);
return res;
}
/**
* Get the visual position of a character in a line
* @param str_in the input string. Can be only one line.
* @param bidi_txt internally the text is bidi processed which buffer can be get here.
* If not required anymore has to freed with `lv_free()`
* Can be `NULL` is unused
* @param len length of the line in character count
* @param base_dir base direction of the text: `LV_BASE_DIR_LTR` or `LV_BASE_DIR_RTL`
* @param logical_pos the logical character position which visual position should be get
* @param is_rtl tell the char at `logical_pos` is RTL or LTR context
* @return the visual character position
*/
uint16_t _lv_bidi_get_visual_pos(const char * str_in, char ** bidi_txt, uint16_t len, lv_base_dir_t base_dir,
uint32_t logical_pos, bool * is_rtl)
{
uint32_t pos_conv_len = get_txt_len(str_in, len);
char * buf = lv_malloc(len + 1);
if(buf == NULL) return (uint16_t) -1;
uint16_t * pos_conv_buf = lv_malloc(pos_conv_len * sizeof(uint16_t));
if(pos_conv_buf == NULL) {
lv_free(buf);
return (uint16_t) -1;
}
if(bidi_txt) *bidi_txt = buf;
_lv_bidi_process_paragraph(str_in, bidi_txt ? *bidi_txt : NULL, len, base_dir, pos_conv_buf, pos_conv_len);
for(uint16_t i = 0; i < pos_conv_len; i++) {
if(GET_POS(pos_conv_buf[i]) == logical_pos) {
if(is_rtl) *is_rtl = IS_RTL_POS(pos_conv_buf[i]);
lv_free(pos_conv_buf);
if(bidi_txt == NULL) lv_free(buf);
return i;
}
}
lv_free(pos_conv_buf);
if(bidi_txt == NULL) lv_free(buf);
return (uint16_t) -1;
}
/**
* Bidi process a paragraph of text
* @param str_in the string to process
* @param str_out store the result here
* @param len length of the text
* @param base_dir base dir of the text
* @param pos_conv_out an `uint16_t` array to store the related logical position of the character.
* Can be `NULL` if unused
* @param pos_conv_len length of `pos_conv_out` in element count
*/
void _lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len, lv_base_dir_t base_dir,
uint16_t * pos_conv_out, uint16_t pos_conv_len)
{
uint32_t run_len = 0;
lv_base_dir_t run_dir;
uint32_t rd = 0;
uint32_t wr;
uint16_t pos_conv_run_len = 0;
uint16_t pos_conv_rd = 0;
uint16_t pos_conv_wr;
if(base_dir == LV_BASE_DIR_AUTO) base_dir = _lv_bidi_detect_base_dir(str_in);
if(base_dir == LV_BASE_DIR_RTL) {
wr = len;
pos_conv_wr = pos_conv_len;
}
else {
wr = 0;
pos_conv_wr = 0;
}
if(str_out) str_out[len] = '\0';
lv_base_dir_t dir = base_dir;
/*Empty the bracket stack*/
lv_bidi_ctx_t ctx;
lv_memzero(&ctx, sizeof(ctx));
/*Process neutral chars in the beginning*/
while(rd < len) {
uint32_t letter = _lv_text_encoded_next(str_in, &rd);
pos_conv_rd++;
dir = lv_bidi_get_letter_dir(letter);
if(dir == LV_BASE_DIR_NEUTRAL) dir = bracket_process(&ctx, str_in, rd, len, letter, base_dir);
else if(dir != LV_BASE_DIR_WEAK) break;
}
if(rd && str_in[rd] != '\0') {
_lv_text_encoded_prev(str_in, &rd);
pos_conv_rd--;
}
if(rd) {
if(base_dir == LV_BASE_DIR_LTR) {
if(str_out) {
lv_memcpy(&str_out[wr], str_in, rd);
wr += rd;
}
if(pos_conv_out) {
fill_pos_conv(&pos_conv_out[pos_conv_wr], pos_conv_rd, 0);
pos_conv_wr += pos_conv_rd;
}
}
else {
wr -= rd;
pos_conv_wr -= pos_conv_rd;
rtl_reverse(str_out ? &str_out[wr] : NULL, str_in, rd, pos_conv_out ? &pos_conv_out[pos_conv_wr] : NULL, 0,
pos_conv_rd);
}
}
/*Get and process the runs*/
while(rd < len && str_in[rd]) {
run_dir = get_next_run(&ctx, &str_in[rd], base_dir, len - rd, &run_len, &pos_conv_run_len);
if(base_dir == LV_BASE_DIR_LTR) {
if(run_dir == LV_BASE_DIR_LTR) {
if(str_out) lv_memcpy(&str_out[wr], &str_in[rd], run_len);
if(pos_conv_out) fill_pos_conv(&pos_conv_out[pos_conv_wr], pos_conv_run_len, pos_conv_rd);
}
else rtl_reverse(str_out ? &str_out[wr] : NULL, &str_in[rd], run_len, pos_conv_out ? &pos_conv_out[pos_conv_wr] : NULL,
pos_conv_rd, pos_conv_run_len);
wr += run_len;
pos_conv_wr += pos_conv_run_len;
}
else {
wr -= run_len;
pos_conv_wr -= pos_conv_run_len;
if(run_dir == LV_BASE_DIR_LTR) {
if(str_out) lv_memcpy(&str_out[wr], &str_in[rd], run_len);
if(pos_conv_out) fill_pos_conv(&pos_conv_out[pos_conv_wr], pos_conv_run_len, pos_conv_rd);
}
else rtl_reverse(str_out ? &str_out[wr] : NULL, &str_in[rd], run_len, pos_conv_out ? &pos_conv_out[pos_conv_wr] : NULL,
pos_conv_rd, pos_conv_run_len);
}
rd += run_len;
pos_conv_rd += pos_conv_run_len;
}
}
void lv_bidi_calculate_align(lv_text_align_t * align, lv_base_dir_t * base_dir, const char * txt)
{
if(*base_dir == LV_BASE_DIR_AUTO) *base_dir = _lv_bidi_detect_base_dir(txt);
if(*align == LV_TEXT_ALIGN_AUTO) {
if(*base_dir == LV_BASE_DIR_RTL) *align = LV_TEXT_ALIGN_RIGHT;
else *align = LV_TEXT_ALIGN_LEFT;
}
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Get the next paragraph from a text
* @param txt the text to process
* @return the length of the current paragraph in byte count
*/
static uint32_t lv_bidi_get_next_paragraph(const char * txt)
{
uint32_t i = 0;
_lv_text_encoded_next(txt, &i);
while(txt[i] != '\0' && txt[i] != '\n' && txt[i] != '\r') {
_lv_text_encoded_next(txt, &i);
}
return i;
}
/**
* Get the direction of a character
* @param letter a Unicode character
* @return `LV_BASE_DIR_RTL/LTR/WEAK/NEUTRAL`
*/
static lv_base_dir_t lv_bidi_get_letter_dir(uint32_t letter)
{
if(lv_bidi_letter_is_rtl(letter)) return LV_BASE_DIR_RTL;
if(lv_bidi_letter_is_neutral(letter)) return LV_BASE_DIR_NEUTRAL;
if(lv_bidi_letter_is_weak(letter)) return LV_BASE_DIR_WEAK;
return LV_BASE_DIR_LTR;
}
/**
* Tell whether a character is weak or not
* @param letter a Unicode character
* @return true/false
*/
static bool lv_bidi_letter_is_weak(uint32_t letter)
{
uint32_t i = 0;
static const char weaks[] = "0123456789";
do {
uint32_t x = _lv_text_encoded_next(weaks, &i);
if(letter == x) {
return true;
}
} while(weaks[i] != '\0');
return false;
}
/**
* Tell whether a character is RTL or not
* @param letter a Unicode character
* @return true/false
*/
static bool lv_bidi_letter_is_rtl(uint32_t letter)
{
if(letter == 0x202E) return true; /*Unicode of LV_BIDI_RLO*/
/*Check for Persian and Arabic characters [https://en.wikipedia.org/wiki/Arabic_script_in_Unicode]*/
if(letter >= 0x600 && letter <= 0x6FF) return true;
if(letter >= 0xFB50 && letter <= 0xFDFF) return true;
if(letter >= 0xFE70 && letter <= 0xFEFF) return true;
/*Check for Hebrew characters [https://en.wikipedia.org/wiki/Unicode_and_HTML_for_the_Hebrew_alphabet]*/
if(letter >= 0x590 && letter <= 0x5FF) return true;
if(letter >= 0xFB1D && letter <= 0xFB4F) return true;
return false;
}
/**
* Tell whether a character is neutral or not
* @param letter a Unicode character
* @return true/false
*/
static bool lv_bidi_letter_is_neutral(uint32_t letter)
{
uint16_t i;
static const char neutrals[] = " \t\n\r.,:;'\"`!?%/\\-=()[]{}<>@#&$|";
for(i = 0; neutrals[i] != '\0'; i++) {
if(letter == (uint32_t)neutrals[i]) return true;
}
return false;
}
static uint32_t get_txt_len(const char * txt, uint32_t max_len)
{
uint32_t len = 0;
uint32_t i = 0;
while(i < max_len && txt[i] != '\0') {
_lv_text_encoded_next(txt, &i);
len++;
}
return len;
}
static void fill_pos_conv(uint16_t * out, uint16_t len, uint16_t index)
{
uint16_t i;
for(i = 0; i < len; i++) {
out[i] = SET_RTL_POS(index, false);
index++;
}
}
static lv_base_dir_t get_next_run(lv_bidi_ctx_t * ctx, const char * txt, lv_base_dir_t base_dir, uint32_t max_len,
uint32_t * len,
uint16_t * pos_conv_len)
{
uint32_t i = 0;
uint32_t letter;
uint16_t pos_conv_i = 0;
letter = _lv_text_encoded_next(txt, NULL);
lv_base_dir_t dir = lv_bidi_get_letter_dir(letter);
if(dir == LV_BASE_DIR_NEUTRAL) dir = bracket_process(ctx, txt, 0, max_len, letter, base_dir);
/*Find the first strong char. Skip the neutrals*/
while(dir == LV_BASE_DIR_NEUTRAL || dir == LV_BASE_DIR_WEAK) {
letter = _lv_text_encoded_next(txt, &i);
pos_conv_i++;
dir = lv_bidi_get_letter_dir(letter);
if(dir == LV_BASE_DIR_NEUTRAL) dir = bracket_process(ctx, txt, i, max_len, letter, base_dir);
if(dir == LV_BASE_DIR_LTR || dir == LV_BASE_DIR_RTL) break;
if(i >= max_len || txt[i] == '\0' || txt[i] == '\n' || txt[i] == '\r') {
*len = i;
*pos_conv_len = pos_conv_i;
return base_dir;
}
}
lv_base_dir_t run_dir = dir;
uint32_t i_prev = i;
uint32_t i_last_strong = i;
uint16_t pos_conv_i_prev = pos_conv_i;
uint16_t pos_conv_i_last_strong = pos_conv_i;
/*Find the next char which has different direction*/
lv_base_dir_t next_dir = base_dir;
while(i_prev < max_len && txt[i] != '\0' && txt[i] != '\n' && txt[i] != '\r') {
letter = _lv_text_encoded_next(txt, &i);
pos_conv_i++;
next_dir = lv_bidi_get_letter_dir(letter);
if(next_dir == LV_BASE_DIR_NEUTRAL) next_dir = bracket_process(ctx, txt, i, max_len, letter, base_dir);
if(next_dir == LV_BASE_DIR_WEAK) {
if(run_dir == LV_BASE_DIR_RTL) {
if(base_dir == LV_BASE_DIR_RTL) {
next_dir = LV_BASE_DIR_LTR;
}
}
}
/*New dir found?*/
if((next_dir == LV_BASE_DIR_RTL || next_dir == LV_BASE_DIR_LTR) && next_dir != run_dir) {
/*Include neutrals if `run_dir == base_dir`*/
if(run_dir == base_dir) {
*len = i_prev;
*pos_conv_len = pos_conv_i_prev;
}
/*Exclude neutrals if `run_dir != base_dir`*/
else {
*len = i_last_strong;
*pos_conv_len = pos_conv_i_last_strong;
}
return run_dir;
}
if(next_dir != LV_BASE_DIR_NEUTRAL) {
i_last_strong = i;
pos_conv_i_last_strong = pos_conv_i;
}
i_prev = i;
pos_conv_i_prev = pos_conv_i;
}
/*Handle end of of string. Apply `base_dir` on trailing neutrals*/
/*Include neutrals if `run_dir == base_dir`*/
if(run_dir == base_dir) {
*len = i_prev;
*pos_conv_len = pos_conv_i_prev;
}
/*Exclude neutrals if `run_dir != base_dir`*/
else {
*len = i_last_strong;
*pos_conv_len = pos_conv_i_last_strong;
}
return run_dir;
}
static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t * pos_conv_out, uint16_t pos_conv_rd_base,
uint16_t pos_conv_len)
{
uint32_t i = len;
uint32_t wr = 0;
uint16_t pos_conv_i = pos_conv_len;
uint16_t pos_conv_wr = 0;
while(i) {
uint32_t letter = _lv_text_encoded_prev(src, &i);
uint16_t pos_conv_letter = --pos_conv_i;
/*Keep weak letters (numbers) as LTR*/
if(lv_bidi_letter_is_weak(letter)) {
uint32_t last_weak = i;
uint32_t first_weak = i;
uint16_t pos_conv_last_weak = pos_conv_i;
uint16_t pos_conv_first_weak = pos_conv_i;
while(i) {
letter = _lv_text_encoded_prev(src, &i);
pos_conv_letter = --pos_conv_i;
/*No need to call `char_change_to_pair` because there not such chars here*/
/*Finish on non-weak char*/
/*but treat number and currency related chars as weak*/
if(lv_bidi_letter_is_weak(letter) == false && letter != '.' && letter != ',' && letter != '$' && letter != '%') {
_lv_text_encoded_next(src, &i); /*Rewind one letter*/
pos_conv_i++;
first_weak = i;
pos_conv_first_weak = pos_conv_i;
break;
}
}
if(i == 0) {
first_weak = 0;
pos_conv_first_weak = 0;
}
if(dest) lv_memcpy(&dest[wr], &src[first_weak], last_weak - first_weak + 1);
if(pos_conv_out) fill_pos_conv(&pos_conv_out[pos_conv_wr], pos_conv_last_weak - pos_conv_first_weak + 1,
pos_conv_rd_base + pos_conv_first_weak);
wr += last_weak - first_weak + 1;
pos_conv_wr += pos_conv_last_weak - pos_conv_first_weak + 1;
}
/*Simply store in reversed order*/
else {
uint32_t letter_size = _lv_text_encoded_size((const char *)&src[i]);
/*Swap arithmetical symbols*/
if(letter_size == 1) {
uint32_t new_letter = letter = char_change_to_pair(letter);
if(dest) dest[wr] = (uint8_t)new_letter;
if(pos_conv_out) pos_conv_out[pos_conv_wr] = SET_RTL_POS(pos_conv_rd_base + pos_conv_letter, true);
wr++;
pos_conv_wr++;
}
/*Just store the letter*/
else {
if(dest) lv_memcpy(&dest[wr], &src[i], letter_size);
if(pos_conv_out) pos_conv_out[pos_conv_wr] = SET_RTL_POS(pos_conv_rd_base + pos_conv_i, true);
wr += letter_size;
pos_conv_wr++;
}
}
}
}
static uint32_t char_change_to_pair(uint32_t letter)
{
uint8_t i;
for(i = 0; bracket_left[i] != '\0'; i++) {
if(letter == bracket_left[i]) return bracket_right[i];
}
for(i = 0; bracket_right[i] != '\0'; i++) {
if(letter == bracket_right[i]) return bracket_left[i];
}
return letter;
}
static lv_base_dir_t bracket_process(lv_bidi_ctx_t * ctx, const char * txt, uint32_t next_pos, uint32_t len,
uint32_t letter,
lv_base_dir_t base_dir)
{
lv_base_dir_t bracket_dir = LV_BASE_DIR_NEUTRAL;
uint8_t i;
/*Is the letter an opening bracket?*/
for(i = 0; bracket_left[i] != '\0'; i++) {
if(bracket_left[i] == letter) {
/*If so find its matching closing bracket.
*If a char with base dir. direction is found then the brackets will have `base_dir` direction*/
uint32_t txt_i = next_pos;
while(txt_i < len) {
uint32_t letter_next = _lv_text_encoded_next(txt, &txt_i);
if(letter_next == bracket_right[i]) {
/*Closing bracket found*/
break;
}
else {
/*Save the dir*/
lv_base_dir_t letter_dir = lv_bidi_get_letter_dir(letter_next);
if(letter_dir == base_dir) {
bracket_dir = base_dir;
}
}
}
/*There were no matching closing bracket*/
if(txt_i > len) return LV_BASE_DIR_NEUTRAL;
/*There where a strong char with base dir in the bracket so the dir is found.*/
if(bracket_dir != LV_BASE_DIR_NEUTRAL && bracket_dir != LV_BASE_DIR_WEAK) break;
/*If there were no matching strong chars in the brackets then check the previous chars*/
txt_i = next_pos;
if(txt_i) _lv_text_encoded_prev(txt, &txt_i);
while(txt_i > 0) {
uint32_t letter_next = _lv_text_encoded_prev(txt, &txt_i);
lv_base_dir_t letter_dir = lv_bidi_get_letter_dir(letter_next);
if(letter_dir == LV_BASE_DIR_LTR || letter_dir == LV_BASE_DIR_RTL) {
bracket_dir = letter_dir;
break;
}
}
/*There where a previous strong char which can be used*/
if(bracket_dir != LV_BASE_DIR_NEUTRAL) break;
/*There were no strong chars before the bracket, so use the base dir.*/
if(txt_i == 0) bracket_dir = base_dir;
break;
}
}
/*The letter was an opening bracket*/
if(bracket_left[i] != '\0') {
if(bracket_dir == LV_BASE_DIR_NEUTRAL || ctx->br_stack_p == LV_BIDI_BRACKLET_DEPTH) return LV_BASE_DIR_NEUTRAL;
ctx->br_stack[ctx->br_stack_p].bracklet_pos = i;
ctx->br_stack[ctx->br_stack_p].dir = bracket_dir;
ctx->br_stack_p++;
return bracket_dir;
}
else if(ctx->br_stack_p > 0) {
/*Is the letter a closing bracket of the last opening?*/
if(letter == bracket_right[ctx->br_stack[ctx->br_stack_p - 1].bracklet_pos]) {
bracket_dir = ctx->br_stack[ctx->br_stack_p - 1].dir;
ctx->br_stack_p--;
return bracket_dir;
}
}
return LV_BASE_DIR_NEUTRAL;
}
#endif /*LV_USE_BIDI*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_assert.h | /**
* @file lv_assert.h
*
*/
#ifndef LV_ASSERT_H
#define LV_ASSERT_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#include "lv_log.h"
#include "../stdlib/lv_mem.h"
#include LV_ASSERT_HANDLER_INCLUDE
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**********************
* MACROS
**********************/
#define LV_ASSERT(expr) \
do { \
if(!(expr)) { \
LV_LOG_ERROR("Asserted at expression: %s", #expr); \
LV_ASSERT_HANDLER \
} \
} while(0)
#define LV_ASSERT_MSG(expr, msg) \
do { \
if(!(expr)) { \
LV_LOG_ERROR("Asserted at expression: %s (%s)", #expr, msg); \
LV_ASSERT_HANDLER \
} \
} while(0)
/*-----------------
* ASSERTS
*-----------------*/
#if LV_USE_ASSERT_NULL
# define LV_ASSERT_NULL(p) LV_ASSERT_MSG(p != NULL, "NULL pointer");
#else
# define LV_ASSERT_NULL(p)
#endif
#if LV_USE_ASSERT_MALLOC
# define LV_ASSERT_MALLOC(p) LV_ASSERT_MSG(p != NULL, "Out of memory");
#else
# define LV_ASSERT_MALLOC(p)
#endif
#if LV_USE_ASSERT_MEM_INTEGRITY
# define LV_ASSERT_MEM_INTEGRITY() LV_ASSERT_MSG(lv_mem_test() == LV_RESULT_OK, "Memory integrity error");
#else
# define LV_ASSERT_MEM_INTEGRITY()
#endif
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_ASSERT_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_templ.c | /**
* @file lv_templ.c
*
*/
/*********************
* INCLUDES
*********************/
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/*This typedef exists purely to keep -Wpedantic happy when the file is empty.*/
/*It can be removed.*/
typedef int _keep_pedantic_happy;
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**********************
* STATIC FUNCTIONS
**********************/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_area.c | /**
* @file lv_area.c
*
*/
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#include "../core/lv_global.h"
#include "lv_area.h"
#include "lv_math.h"
/*********************
* DEFINES
*********************/
#define trans_cache LV_GLOBAL_DEFAULT()->area_trans_cache
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static bool lv_point_within_circle(const lv_area_t * area, const lv_point_t * p);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize an area
* @param area_p pointer to an area
* @param x1 left coordinate of the area
* @param y1 top coordinate of the area
* @param x2 right coordinate of the area
* @param y2 bottom coordinate of the area
*/
void lv_area_set(lv_area_t * area_p, int32_t x1, int32_t y1, int32_t x2, int32_t y2)
{
area_p->x1 = x1;
area_p->y1 = y1;
area_p->x2 = x2;
area_p->y2 = y2;
}
/**
* Set the width of an area
* @param area_p pointer to an area
* @param w the new width of the area (w == 1 makes x1 == x2)
*/
void lv_area_set_width(lv_area_t * area_p, int32_t w)
{
area_p->x2 = area_p->x1 + w - 1;
}
/**
* Set the height of an area
* @param area_p pointer to an area
* @param h the new height of the area (h == 1 makes y1 == y2)
*/
void lv_area_set_height(lv_area_t * area_p, int32_t h)
{
area_p->y2 = area_p->y1 + h - 1;
}
/**
* Set the position of an area (width and height will be kept)
* @param area_p pointer to an area
* @param x the new x coordinate of the area
* @param y the new y coordinate of the area
*/
void _lv_area_set_pos(lv_area_t * area_p, int32_t x, int32_t y)
{
int32_t w = lv_area_get_width(area_p);
int32_t h = lv_area_get_height(area_p);
area_p->x1 = x;
area_p->y1 = y;
lv_area_set_width(area_p, w);
lv_area_set_height(area_p, h);
}
/**
* Return with area of an area (x * y)
* @param area_p pointer to an area
* @return size of area
*/
uint32_t lv_area_get_size(const lv_area_t * area_p)
{
uint32_t size;
size = (uint32_t)(area_p->x2 - area_p->x1 + 1) * (area_p->y2 - area_p->y1 + 1);
return size;
}
void lv_area_increase(lv_area_t * area, int32_t w_extra, int32_t h_extra)
{
area->x1 -= w_extra;
area->x2 += w_extra;
area->y1 -= h_extra;
area->y2 += h_extra;
}
void lv_area_move(lv_area_t * area, int32_t x_ofs, int32_t y_ofs)
{
area->x1 += x_ofs;
area->x2 += x_ofs;
area->y1 += y_ofs;
area->y2 += y_ofs;
}
/**
* Get the common parts of two areas
* @param res_p pointer to an area, the result will be stored here
* @param a1_p pointer to the first area
* @param a2_p pointer to the second area
* @return false: the two area has NO common parts, res_p is invalid
*/
bool _lv_area_intersect(lv_area_t * res_p, const lv_area_t * a1_p, const lv_area_t * a2_p)
{
/*Get the smaller area from 'a1_p' and 'a2_p'*/
res_p->x1 = LV_MAX(a1_p->x1, a2_p->x1);
res_p->y1 = LV_MAX(a1_p->y1, a2_p->y1);
res_p->x2 = LV_MIN(a1_p->x2, a2_p->x2);
res_p->y2 = LV_MIN(a1_p->y2, a2_p->y2);
/*If x1 or y1 greater than x2 or y2 then the areas union is empty*/
bool union_ok = true;
if((res_p->x1 > res_p->x2) || (res_p->y1 > res_p->y2)) {
union_ok = false;
}
return union_ok;
}
/**
* Get resulting sub areas after removing the common parts of two areas from the first area
* @param res_p pointer to an array of areas with a count of 4, the resulting areas will be stored here
* @param a1_p pointer to the first area
* @param a2_p pointer to the second area
* @return number of results or -1 if no intersect
*/
int8_t _lv_area_diff(lv_area_t res_p[], const lv_area_t * a1_p, const lv_area_t * a2_p)
{
/*Areas have no common parts*/
if(!_lv_area_is_on(a1_p, a2_p)) return -1;
/*No remaining areas after removing common parts*/
if(_lv_area_is_in(a1_p, a2_p, 0)) return 0;
/*Result counter*/
int8_t res_c = 0;
/*Get required information*/
lv_area_t n;
int32_t a1_w = lv_area_get_width(a1_p) - 1;
int32_t a1_h = lv_area_get_height(a1_p) - 1;
/*Compute top rectangle*/
int32_t th = a2_p->y1 - a1_p->y1;
if(th > 0) {
n.x1 = a1_p->x1;
n.y1 = a1_p->y1;
n.x2 = a1_p->x2;
n.y2 = a1_p->y1 + th;
res_p[res_c++] = n;
}
/*Compute the bottom rectangle*/
int32_t bh = a1_h - (a2_p->y2 - a1_p->y1);
if(bh > 0 && a2_p->y2 < a1_p->y2) {
n.x1 = a1_p->x1;
n.y1 = a2_p->y2;
n.x2 = a1_p->x2;
n.y2 = a2_p->y2 + bh;
res_p[res_c++] = n;
}
/*Compute side height*/
int32_t y1 = a2_p->y1 > a1_p->y1 ? a2_p->y1 : a1_p->y1;
int32_t y2 = a2_p->y2 < a1_p->y2 ? a2_p->y2 : a1_p->y2;
int32_t sh = y2 - y1;
/*Compute the left rectangle*/
int32_t lw = a2_p->x1 - a1_p->x1;
if(lw > 0 && sh > 0) {
n.x1 = a1_p->x1;
n.y1 = y1;
n.x2 = a1_p->x1 + lw;
n.y2 = y1 + sh;
res_p[res_c++] = n;
}
/*Compute the right rectangle*/
int32_t rw = a1_w - (a2_p->x2 - a1_p->x1);
if(rw > 0) {
n.x1 = a2_p->x2;
n.y1 = y1;
n.x2 = a2_p->x2 + rw;
n.y2 = y1 + sh;
res_p[res_c++] = n;
}
//Return number of results
return res_c;
}
/**
* Join two areas into a third which involves the other two
* @param res_p pointer to an area, the result will be stored here
* @param a1_p pointer to the first area
* @param a2_p pointer to the second area
*/
void _lv_area_join(lv_area_t * a_res_p, const lv_area_t * a1_p, const lv_area_t * a2_p)
{
a_res_p->x1 = LV_MIN(a1_p->x1, a2_p->x1);
a_res_p->y1 = LV_MIN(a1_p->y1, a2_p->y1);
a_res_p->x2 = LV_MAX(a1_p->x2, a2_p->x2);
a_res_p->y2 = LV_MAX(a1_p->y2, a2_p->y2);
}
/**
* Check if a point is on an area
* @param a_p pointer to an area
* @param p_p pointer to a point
* @param radius radius of area (e.g. for rounded rectangle)
* @return false:the point is out of the area
*/
bool _lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p, int32_t radius)
{
/*First check the basic area*/
bool is_on_rect = false;
if((p_p->x >= a_p->x1 && p_p->x <= a_p->x2) && ((p_p->y >= a_p->y1 && p_p->y <= a_p->y2))) {
is_on_rect = true;
}
if(!is_on_rect)
return false;
/*Now handle potential rounded rectangles*/
if(radius <= 0) {
/*No radius, it is within the rectangle*/
return true;
}
int32_t w = lv_area_get_width(a_p) / 2;
int32_t h = lv_area_get_height(a_p) / 2;
int32_t max_radius = LV_MIN(w, h);
if(radius > max_radius)
radius = max_radius;
/*Check if it's in one of the corners*/
lv_area_t corner_area;
/*Top left*/
corner_area.x1 = a_p->x1;
corner_area.x2 = a_p->x1 + radius;
corner_area.y1 = a_p->y1;
corner_area.y2 = a_p->y1 + radius;
if(_lv_area_is_point_on(&corner_area, p_p, 0)) {
corner_area.x2 += radius;
corner_area.y2 += radius;
return lv_point_within_circle(&corner_area, p_p);
}
/*Bottom left*/
corner_area.y1 = a_p->y2 - radius;
corner_area.y2 = a_p->y2;
if(_lv_area_is_point_on(&corner_area, p_p, 0)) {
corner_area.x2 += radius;
corner_area.y1 -= radius;
return lv_point_within_circle(&corner_area, p_p);
}
/*Bottom right*/
corner_area.x1 = a_p->x2 - radius;
corner_area.x2 = a_p->x2;
if(_lv_area_is_point_on(&corner_area, p_p, 0)) {
corner_area.x1 -= radius;
corner_area.y1 -= radius;
return lv_point_within_circle(&corner_area, p_p);
}
/*Top right*/
corner_area.y1 = a_p->y1;
corner_area.y2 = a_p->y1 + radius;
if(_lv_area_is_point_on(&corner_area, p_p, 0)) {
corner_area.x1 -= radius;
corner_area.y2 += radius;
return lv_point_within_circle(&corner_area, p_p);
}
/*Not within corners*/
return true;
}
/**
* Check if two area has common parts
* @param a1_p pointer to an area.
* @param a2_p pointer to an other area
* @return false: a1_p and a2_p has no common parts
*/
bool _lv_area_is_on(const lv_area_t * a1_p, const lv_area_t * a2_p)
{
if((a1_p->x1 <= a2_p->x2) && (a1_p->x2 >= a2_p->x1) && (a1_p->y1 <= a2_p->y2) && (a1_p->y2 >= a2_p->y1)) {
return true;
}
else {
return false;
}
}
/**
* Check if an area is fully on an other
* @param ain_p pointer to an area which could be in 'aholder_p'
* @param aholder_p pointer to an area which could involve 'ain_p'
* @param radius radius of `aholder_p` (e.g. for rounded rectangle)
* @return true: `ain_p` is fully inside `aholder_p`
*/
bool _lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p, int32_t radius)
{
bool is_in = false;
if(ain_p->x1 >= aholder_p->x1 && ain_p->y1 >= aholder_p->y1 && ain_p->x2 <= aholder_p->x2 &&
ain_p->y2 <= aholder_p->y2) {
is_in = true;
}
if(!is_in) return false;
if(radius == 0) return true;
/*Check if the corner points are inside the radius or not*/
lv_point_t p;
p.x = ain_p->x1;
p.y = ain_p->y1;
if(_lv_area_is_point_on(aholder_p, &p, radius) == false) return false;
p.x = ain_p->x2;
p.y = ain_p->y1;
if(_lv_area_is_point_on(aholder_p, &p, radius) == false) return false;
p.x = ain_p->x1;
p.y = ain_p->y2;
if(_lv_area_is_point_on(aholder_p, &p, radius) == false) return false;
p.x = ain_p->x2;
p.y = ain_p->y2;
if(_lv_area_is_point_on(aholder_p, &p, radius) == false) return false;
return true;
}
/**
* Check if an area is fully out of an other
* @param aout_p pointer to an area which could be in 'aholder_p'
* @param aholder_p pointer to an area which could involve 'ain_p'
* @param radius radius of `aholder_p` (e.g. for rounded rectangle)
* @return true: `aout_p` is fully outside `aholder_p`
*/
bool _lv_area_is_out(const lv_area_t * aout_p, const lv_area_t * aholder_p, int32_t radius)
{
if(aout_p->x2 < aholder_p->x1 || aout_p->y2 < aholder_p->y1 || aout_p->x1 > aholder_p->x2 ||
aout_p->y1 > aholder_p->y2) {
return true;
}
if(radius == 0) return false;
/*Check if the corner points are outside the radius or not*/
lv_point_t p;
p.x = aout_p->x1;
p.y = aout_p->y1;
if(_lv_area_is_point_on(aholder_p, &p, radius)) return false;
p.x = aout_p->x2;
p.y = aout_p->y1;
if(_lv_area_is_point_on(aholder_p, &p, radius)) return false;
p.x = aout_p->x1;
p.y = aout_p->y2;
if(_lv_area_is_point_on(aholder_p, &p, radius)) return false;
p.x = aout_p->x2;
p.y = aout_p->y2;
if(_lv_area_is_point_on(aholder_p, &p, radius)) return false;
return true;
}
bool _lv_area_is_equal(const lv_area_t * a, const lv_area_t * b)
{
return a->x1 == b->x1 && a->x2 == b->x2 && a->y1 == b->y1 && a->y2 == b->y2;
}
/**
* Align an area to an other
* @param base an area where the other will be aligned
* @param to_align the area to align
* @param align `LV_ALIGN_...`
* @param res x/y coordinates where `to_align` align area should be placed
*/
void lv_area_align(const lv_area_t * base, lv_area_t * to_align, lv_align_t align, int32_t ofs_x, int32_t ofs_y)
{
int32_t x;
int32_t y;
switch(align) {
case LV_ALIGN_CENTER:
x = lv_area_get_width(base) / 2 - lv_area_get_width(to_align) / 2;
y = lv_area_get_height(base) / 2 - lv_area_get_height(to_align) / 2;
break;
case LV_ALIGN_TOP_LEFT:
x = 0;
y = 0;
break;
case LV_ALIGN_TOP_MID:
x = lv_area_get_width(base) / 2 - lv_area_get_width(to_align) / 2;
y = 0;
break;
case LV_ALIGN_TOP_RIGHT:
x = lv_area_get_width(base) - lv_area_get_width(to_align);
y = 0;
break;
case LV_ALIGN_BOTTOM_LEFT:
x = 0;
y = lv_area_get_height(base) - lv_area_get_height(to_align);
break;
case LV_ALIGN_BOTTOM_MID:
x = lv_area_get_width(base) / 2 - lv_area_get_width(to_align) / 2;
y = lv_area_get_height(base) - lv_area_get_height(to_align);
break;
case LV_ALIGN_BOTTOM_RIGHT:
x = lv_area_get_width(base) - lv_area_get_width(to_align);
y = lv_area_get_height(base) - lv_area_get_height(to_align);
break;
case LV_ALIGN_LEFT_MID:
x = 0;
y = lv_area_get_height(base) / 2 - lv_area_get_height(to_align) / 2;
break;
case LV_ALIGN_RIGHT_MID:
x = lv_area_get_width(base) - lv_area_get_width(to_align);
y = lv_area_get_height(base) / 2 - lv_area_get_height(to_align) / 2;
break;
case LV_ALIGN_OUT_TOP_LEFT:
x = 0;
y = -lv_area_get_height(to_align);
break;
case LV_ALIGN_OUT_TOP_MID:
x = lv_area_get_width(base) / 2 - lv_area_get_width(to_align) / 2;
y = -lv_area_get_height(to_align);
break;
case LV_ALIGN_OUT_TOP_RIGHT:
x = lv_area_get_width(base) - lv_area_get_width(to_align);
y = -lv_area_get_height(to_align);
break;
case LV_ALIGN_OUT_BOTTOM_LEFT:
x = 0;
y = lv_area_get_height(base);
break;
case LV_ALIGN_OUT_BOTTOM_MID:
x = lv_area_get_width(base) / 2 - lv_area_get_width(to_align) / 2;
y = lv_area_get_height(base);
break;
case LV_ALIGN_OUT_BOTTOM_RIGHT:
x = lv_area_get_width(base) - lv_area_get_width(to_align);
y = lv_area_get_height(base);
break;
case LV_ALIGN_OUT_LEFT_TOP:
x = -lv_area_get_width(to_align);
y = 0;
break;
case LV_ALIGN_OUT_LEFT_MID:
x = -lv_area_get_width(to_align);
y = lv_area_get_height(base) / 2 - lv_area_get_height(to_align) / 2;
break;
case LV_ALIGN_OUT_LEFT_BOTTOM:
x = -lv_area_get_width(to_align);
y = lv_area_get_height(base) - lv_area_get_height(to_align);
break;
case LV_ALIGN_OUT_RIGHT_TOP:
x = lv_area_get_width(base);
y = 0;
break;
case LV_ALIGN_OUT_RIGHT_MID:
x = lv_area_get_width(base);
y = lv_area_get_height(base) / 2 - lv_area_get_height(to_align) / 2;
break;
case LV_ALIGN_OUT_RIGHT_BOTTOM:
x = lv_area_get_width(base);
y = lv_area_get_height(base) - lv_area_get_height(to_align);
break;
default:
x = 0;
y = 0;
break;
}
x += base->x1;
y += base->y1;
int32_t w = lv_area_get_width(to_align);
int32_t h = lv_area_get_height(to_align);
to_align->x1 = x + ofs_x;
to_align->y1 = y + ofs_y;
to_align->x2 = to_align->x1 + w - 1;
to_align->y2 = to_align->y1 + h - 1;
}
#define _LV_TRANSFORM_TRIGO_SHIFT 10
void lv_point_transform(lv_point_t * p, int32_t angle, int32_t scale_x, int32_t scale_y, const lv_point_t * pivot,
bool zoom_first)
{
if(angle == 0 && scale_x == 256 && scale_y == 256) {
return;
}
p->x -= pivot->x;
p->y -= pivot->y;
if(angle == 0) {
p->x = (((int32_t)(p->x) * scale_x) >> 8) + pivot->x;
p->y = (((int32_t)(p->y) * scale_y) >> 8) + pivot->y;
return;
}
lv_area_transform_cache_t * cache = &trans_cache;
if(cache->angle_prev != angle) {
int32_t angle_limited = angle;
if(angle_limited > 3600) angle_limited -= 3600;
if(angle_limited < 0) angle_limited += 3600;
int32_t angle_low = angle_limited / 10;
int32_t angle_high = angle_low + 1;
int32_t angle_rem = angle_limited - (angle_low * 10);
int32_t s1 = lv_trigo_sin(angle_low);
int32_t s2 = lv_trigo_sin(angle_high);
int32_t c1 = lv_trigo_sin(angle_low + 90);
int32_t c2 = lv_trigo_sin(angle_high + 90);
cache->sinma = (s1 * (10 - angle_rem) + s2 * angle_rem) / 10;
cache->cosma = (c1 * (10 - angle_rem) + c2 * angle_rem) / 10;
cache->sinma = cache->sinma >> (LV_TRIGO_SHIFT - _LV_TRANSFORM_TRIGO_SHIFT);
cache->cosma = cache->cosma >> (LV_TRIGO_SHIFT - _LV_TRANSFORM_TRIGO_SHIFT);
cache->angle_prev = angle;
}
int32_t x = p->x;
int32_t y = p->y;
if(scale_x == 256 && scale_y == 256) {
p->x = ((cache->cosma * x - cache->sinma * y) >> _LV_TRANSFORM_TRIGO_SHIFT) + pivot->x;
p->y = ((cache->sinma * x + cache->cosma * y) >> _LV_TRANSFORM_TRIGO_SHIFT) + pivot->y;
}
else {
if(zoom_first) {
x *= scale_x;
y *= scale_y;
p->x = (((cache->cosma * x - cache->sinma * y)) >> (_LV_TRANSFORM_TRIGO_SHIFT + 8)) + pivot->x;
p->y = (((cache->sinma * x + cache->cosma * y)) >> (_LV_TRANSFORM_TRIGO_SHIFT + 8)) + pivot->y;
}
else {
p->x = (((cache->cosma * x - cache->sinma * y) * scale_x) >> (_LV_TRANSFORM_TRIGO_SHIFT + 8)) + pivot->x;
p->y = (((cache->sinma * x + cache->cosma * y) * scale_y) >> (_LV_TRANSFORM_TRIGO_SHIFT + 8)) + pivot->y;
}
}
}
/**********************
* STATIC FUNCTIONS
**********************/
static bool lv_point_within_circle(const lv_area_t * area, const lv_point_t * p)
{
int32_t r = (area->x2 - area->x1) / 2;
/*Circle center*/
int32_t cx = area->x1 + r;
int32_t cy = area->y1 + r;
/*Simplify the code by moving everything to (0, 0)*/
int32_t px = p->x - cx;
int32_t py = p->y - cy;
uint32_t r_sqrd = r * r;
uint32_t dist = (px * px) + (py * py);
if(dist <= r_sqrd)
return true;
else
return false;
}
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_event.h | /**
* @file lv_event.h
*
*/
#ifndef LV_EVENT_H
#define LV_EVENT_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include <stdbool.h>
#include <stdint.h>
#include "lv_types.h"
#include "../lv_conf_internal.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
struct _lv_event_t;
typedef void (*lv_event_cb_t)(struct _lv_event_t * e);
typedef struct {
lv_event_cb_t cb;
void * user_data;
uint32_t filter;
} lv_event_dsc_t;
/**
* Type of event being sent to the object.
*/
typedef enum {
LV_EVENT_ALL = 0,
/** Input device events*/
LV_EVENT_PRESSED, /**< The object has been pressed*/
LV_EVENT_PRESSING, /**< The object is being pressed (called continuously while pressing)*/
LV_EVENT_PRESS_LOST, /**< The object is still being pressed but slid cursor/finger off of the object */
LV_EVENT_SHORT_CLICKED, /**< The object was pressed for a short period of time, then released it. Not called if scrolled.*/
LV_EVENT_LONG_PRESSED, /**< Object has been pressed for at least `long_press_time`. Not called if scrolled.*/
LV_EVENT_LONG_PRESSED_REPEAT, /**< Called after `long_press_time` in every `long_press_repeat_time` ms. Not called if scrolled.*/
LV_EVENT_CLICKED, /**< Called on release if not scrolled (regardless to long press)*/
LV_EVENT_RELEASED, /**< Called in every cases when the object has been released*/
LV_EVENT_SCROLL_BEGIN, /**< Scrolling begins. The event parameter is a pointer to the animation of the scroll. Can be modified*/
LV_EVENT_SCROLL_THROW_BEGIN,
LV_EVENT_SCROLL_END, /**< Scrolling ends*/
LV_EVENT_SCROLL, /**< Scrolling*/
LV_EVENT_GESTURE, /**< A gesture is detected. Get the gesture with `lv_indev_get_gesture_dir(lv_indev_active());` */
LV_EVENT_KEY, /**< A key is sent to the object. Get the key with `lv_indev_get_key(lv_indev_active());`*/
LV_EVENT_FOCUSED, /**< The object is focused*/
LV_EVENT_DEFOCUSED, /**< The object is defocused*/
LV_EVENT_LEAVE, /**< The object is defocused but still selected*/
LV_EVENT_HIT_TEST, /**< Perform advanced hit-testing*/
LV_EVENT_INDEV_RESET, /**< Indev has been reset*/
/** Drawing events*/
LV_EVENT_COVER_CHECK, /**< Check if the object fully covers an area. The event parameter is `lv_cover_check_info_t *`.*/
LV_EVENT_REFR_EXT_DRAW_SIZE, /**< Get the required extra draw area around the object (e.g. for shadow). The event parameter is `int32_t *` to store the size.*/
LV_EVENT_DRAW_MAIN_BEGIN, /**< Starting the main drawing phase*/
LV_EVENT_DRAW_MAIN, /**< Perform the main drawing*/
LV_EVENT_DRAW_MAIN_END, /**< Finishing the main drawing phase*/
LV_EVENT_DRAW_POST_BEGIN, /**< Starting the post draw phase (when all children are drawn)*/
LV_EVENT_DRAW_POST, /**< Perform the post draw phase (when all children are drawn)*/
LV_EVENT_DRAW_POST_END, /**< Finishing the post draw phase (when all children are drawn)*/
LV_EVENT_DRAW_TASK_ADDED, /**< Adding a draw task */
/** Special events*/
LV_EVENT_VALUE_CHANGED, /**< The object's value has changed (i.e. slider moved)*/
LV_EVENT_INSERT, /**< A text is inserted to the object. The event data is `char *` being inserted.*/
LV_EVENT_REFRESH, /**< Notify the object to refresh something on it (for the user)*/
LV_EVENT_READY, /**< A process has finished*/
LV_EVENT_CANCEL, /**< A process has been cancelled */
/** Other events*/
LV_EVENT_DELETE, /**< Object is being deleted*/
LV_EVENT_CHILD_CHANGED, /**< Child was removed, added, or its size, position were changed */
LV_EVENT_CHILD_CREATED, /**< Child was created, always bubbles up to all parents*/
LV_EVENT_CHILD_DELETED, /**< Child was deleted, always bubbles up to all parents*/
LV_EVENT_SCREEN_UNLOAD_START, /**< A screen unload started, fired immediately when scr_load is called*/
LV_EVENT_SCREEN_LOAD_START, /**< A screen load started, fired when the screen change delay is expired*/
LV_EVENT_SCREEN_LOADED, /**< A screen was loaded*/
LV_EVENT_SCREEN_UNLOADED, /**< A screen was unloaded*/
LV_EVENT_SIZE_CHANGED, /**< Object coordinates/size have changed*/
LV_EVENT_STYLE_CHANGED, /**< Object's style has changed*/
LV_EVENT_LAYOUT_CHANGED, /**< The children position has changed due to a layout recalculation*/
LV_EVENT_GET_SELF_SIZE, /**< Get the internal size of a widget*/
/** Events of optional LVGL components*/
LV_EVENT_INVALIDATE_AREA,
LV_EVENT_RENDER_START,
LV_EVENT_RENDER_READY,
LV_EVENT_RESOLUTION_CHANGED,
LV_EVENT_REFR_REQUEST,
LV_EVENT_REFR_START,
LV_EVENT_REFR_FINISH,
LV_EVENT_FLUSH_START,
LV_EVENT_FLUSH_FINISH,
_LV_EVENT_LAST, /** Number of default events*/
LV_EVENT_PREPROCESS = 0x80, /** This is a flag that can be set with an event so it's processed
before the class default event processing */
} lv_event_code_t;
typedef struct {
lv_event_dsc_t * dsc;
uint32_t cnt;
} lv_event_list_t;
typedef struct _lv_event_t {
void * current_target;
void * original_target;
lv_event_code_t code;
void * user_data;
void * param;
struct _lv_event_t * prev;
uint8_t deleted : 1;
uint8_t stop_processing : 1;
uint8_t stop_bubbling : 1;
} lv_event_t;
/**
* @brief Event callback.
* Events are used to notify the user of some action being taken on the object.
* For details, see ::lv_event_t.
*/
/**********************
* GLOBAL PROTOTYPES
**********************/
void _lv_event_push(lv_event_t * e);
void _lv_event_pop(lv_event_t * e);
lv_result_t lv_event_send(lv_event_list_t * list, lv_event_t * e, bool preprocess);
void lv_event_add(lv_event_list_t * list, lv_event_cb_t cb, lv_event_code_t filter, void * user_data);
uint32_t lv_event_get_count(lv_event_list_t * list);
lv_event_dsc_t * lv_event_get_dsc(lv_event_list_t * list, uint32_t index);
lv_event_cb_t lv_event_dsc_get_cb(lv_event_dsc_t * dsc);
void * lv_event_dsc_get_user_data(lv_event_dsc_t * dsc);
bool lv_event_remove(lv_event_list_t * list, uint32_t index);
void lv_event_remove_all(lv_event_list_t * list);
/**
* Get the object originally targeted by the event. It's the same even if the event is bubbled.
* @param e pointer to the event descriptor
* @return the target of the event_code
*/
void * lv_event_get_target(lv_event_t * e);
/**
* Get the current target of the event. It's the object which event handler being called.
* If the event is not bubbled it's the same as "normal" target.
* @param e pointer to the event descriptor
* @return pointer to the current target of the event_code
*/
void * lv_event_get_current_target(lv_event_t * e);
/**
* Get the event code of an event
* @param e pointer to the event descriptor
* @return the event code. (E.g. `LV_EVENT_CLICKED`, `LV_EVENT_FOCUSED`, etc)
*/
lv_event_code_t lv_event_get_code(lv_event_t * e);
/**
* Get the parameter passed when the event was sent
* @param e pointer to the event descriptor
* @return pointer to the parameter
*/
void * lv_event_get_param(lv_event_t * e);
/**
* Get the user_data passed when the event was registered on the object
* @param e pointer to the event descriptor
* @return pointer to the user_data
*/
void * lv_event_get_user_data(lv_event_t * e);
/**
* Stop the event from bubbling.
* This is only valid when called in the middle of an event processing chain.
* @param e pointer to the event descriptor
*/
void lv_event_stop_bubbling(lv_event_t * e);
/**
* Stop processing this event.
* This is only valid when called in the middle of an event processing chain.
* @param e pointer to the event descriptor
*/
void lv_event_stop_processing(lv_event_t * e);
/**
* Register a new, custom event ID.
* It can be used the same way as e.g. `LV_EVENT_CLICKED` to send custom events
* @return the new event id
* @example
* uint32_t LV_EVENT_MINE = 0;
* ...
* e = lv_event_register_id();
* ...
* lv_obj_send_event(obj, LV_EVENT_MINE, &some_data);
*/
uint32_t lv_event_register_id(void);
/**
* Nested events can be called and one of them might belong to an object that is being deleted.
* Mark this object's `event_temp_data` deleted to know that its `lv_obj_send_event` should return `LV_RESULT_INVALID`
* @param target pointer to an event target which was deleted
*/
void _lv_event_mark_deleted(void * target);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_EVENT_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_style_gen.c |
/*
**********************************************************************
* DO NOT EDIT
* This file is automatically generated by "style_api_gen.py"
**********************************************************************
*/
#include "lv_style.h"
void lv_style_set_width(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_WIDTH, v);
}
const lv_style_prop_t _lv_style_const_prop_id_WIDTH = LV_STYLE_WIDTH;
void lv_style_set_min_width(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_MIN_WIDTH, v);
}
const lv_style_prop_t _lv_style_const_prop_id_MIN_WIDTH = LV_STYLE_MIN_WIDTH;
void lv_style_set_max_width(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_MAX_WIDTH, v);
}
const lv_style_prop_t _lv_style_const_prop_id_MAX_WIDTH = LV_STYLE_MAX_WIDTH;
void lv_style_set_height(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_HEIGHT, v);
}
const lv_style_prop_t _lv_style_const_prop_id_HEIGHT = LV_STYLE_HEIGHT;
void lv_style_set_min_height(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_MIN_HEIGHT, v);
}
const lv_style_prop_t _lv_style_const_prop_id_MIN_HEIGHT = LV_STYLE_MIN_HEIGHT;
void lv_style_set_max_height(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_MAX_HEIGHT, v);
}
const lv_style_prop_t _lv_style_const_prop_id_MAX_HEIGHT = LV_STYLE_MAX_HEIGHT;
void lv_style_set_x(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_X, v);
}
const lv_style_prop_t _lv_style_const_prop_id_X = LV_STYLE_X;
void lv_style_set_y(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_Y, v);
}
const lv_style_prop_t _lv_style_const_prop_id_Y = LV_STYLE_Y;
void lv_style_set_align(lv_style_t * style, lv_align_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_ALIGN, v);
}
const lv_style_prop_t _lv_style_const_prop_id_ALIGN = LV_STYLE_ALIGN;
void lv_style_set_transform_width(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_TRANSFORM_WIDTH, v);
}
const lv_style_prop_t _lv_style_const_prop_id_TRANSFORM_WIDTH = LV_STYLE_TRANSFORM_WIDTH;
void lv_style_set_transform_height(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_TRANSFORM_HEIGHT, v);
}
const lv_style_prop_t _lv_style_const_prop_id_TRANSFORM_HEIGHT = LV_STYLE_TRANSFORM_HEIGHT;
void lv_style_set_translate_x(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_TRANSLATE_X, v);
}
const lv_style_prop_t _lv_style_const_prop_id_TRANSLATE_X = LV_STYLE_TRANSLATE_X;
void lv_style_set_translate_y(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_TRANSLATE_Y, v);
}
const lv_style_prop_t _lv_style_const_prop_id_TRANSLATE_Y = LV_STYLE_TRANSLATE_Y;
void lv_style_set_transform_scale_x(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_TRANSFORM_SCALE_X, v);
}
const lv_style_prop_t _lv_style_const_prop_id_TRANSFORM_SCALE_X = LV_STYLE_TRANSFORM_SCALE_X;
void lv_style_set_transform_scale_y(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_TRANSFORM_SCALE_Y, v);
}
const lv_style_prop_t _lv_style_const_prop_id_TRANSFORM_SCALE_Y = LV_STYLE_TRANSFORM_SCALE_Y;
void lv_style_set_transform_rotation(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_TRANSFORM_ROTATION, v);
}
const lv_style_prop_t _lv_style_const_prop_id_TRANSFORM_ROTATION = LV_STYLE_TRANSFORM_ROTATION;
void lv_style_set_transform_pivot_x(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_TRANSFORM_PIVOT_X, v);
}
const lv_style_prop_t _lv_style_const_prop_id_TRANSFORM_PIVOT_X = LV_STYLE_TRANSFORM_PIVOT_X;
void lv_style_set_transform_pivot_y(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_TRANSFORM_PIVOT_Y, v);
}
const lv_style_prop_t _lv_style_const_prop_id_TRANSFORM_PIVOT_Y = LV_STYLE_TRANSFORM_PIVOT_Y;
void lv_style_set_pad_top(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_PAD_TOP, v);
}
const lv_style_prop_t _lv_style_const_prop_id_PAD_TOP = LV_STYLE_PAD_TOP;
void lv_style_set_pad_bottom(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_PAD_BOTTOM, v);
}
const lv_style_prop_t _lv_style_const_prop_id_PAD_BOTTOM = LV_STYLE_PAD_BOTTOM;
void lv_style_set_pad_left(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_PAD_LEFT, v);
}
const lv_style_prop_t _lv_style_const_prop_id_PAD_LEFT = LV_STYLE_PAD_LEFT;
void lv_style_set_pad_right(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_PAD_RIGHT, v);
}
const lv_style_prop_t _lv_style_const_prop_id_PAD_RIGHT = LV_STYLE_PAD_RIGHT;
void lv_style_set_pad_row(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_PAD_ROW, v);
}
const lv_style_prop_t _lv_style_const_prop_id_PAD_ROW = LV_STYLE_PAD_ROW;
void lv_style_set_pad_column(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_PAD_COLUMN, v);
}
const lv_style_prop_t _lv_style_const_prop_id_PAD_COLUMN = LV_STYLE_PAD_COLUMN;
void lv_style_set_margin_top(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_MARGIN_TOP, v);
}
const lv_style_prop_t _lv_style_const_prop_id_MARGIN_TOP = LV_STYLE_MARGIN_TOP;
void lv_style_set_margin_bottom(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_MARGIN_BOTTOM, v);
}
const lv_style_prop_t _lv_style_const_prop_id_MARGIN_BOTTOM = LV_STYLE_MARGIN_BOTTOM;
void lv_style_set_margin_left(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_MARGIN_LEFT, v);
}
const lv_style_prop_t _lv_style_const_prop_id_MARGIN_LEFT = LV_STYLE_MARGIN_LEFT;
void lv_style_set_margin_right(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_MARGIN_RIGHT, v);
}
const lv_style_prop_t _lv_style_const_prop_id_MARGIN_RIGHT = LV_STYLE_MARGIN_RIGHT;
void lv_style_set_bg_color(lv_style_t * style, lv_color_t value)
{
lv_style_value_t v = {
.color = value
};
lv_style_set_prop(style, LV_STYLE_BG_COLOR, v);
}
const lv_style_prop_t _lv_style_const_prop_id_BG_COLOR = LV_STYLE_BG_COLOR;
void lv_style_set_bg_opa(lv_style_t * style, lv_opa_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_BG_OPA, v);
}
const lv_style_prop_t _lv_style_const_prop_id_BG_OPA = LV_STYLE_BG_OPA;
void lv_style_set_bg_grad_color(lv_style_t * style, lv_color_t value)
{
lv_style_value_t v = {
.color = value
};
lv_style_set_prop(style, LV_STYLE_BG_GRAD_COLOR, v);
}
const lv_style_prop_t _lv_style_const_prop_id_BG_GRAD_COLOR = LV_STYLE_BG_GRAD_COLOR;
void lv_style_set_bg_grad_dir(lv_style_t * style, lv_grad_dir_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_BG_GRAD_DIR, v);
}
const lv_style_prop_t _lv_style_const_prop_id_BG_GRAD_DIR = LV_STYLE_BG_GRAD_DIR;
void lv_style_set_bg_main_stop(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_BG_MAIN_STOP, v);
}
const lv_style_prop_t _lv_style_const_prop_id_BG_MAIN_STOP = LV_STYLE_BG_MAIN_STOP;
void lv_style_set_bg_grad_stop(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_BG_GRAD_STOP, v);
}
const lv_style_prop_t _lv_style_const_prop_id_BG_GRAD_STOP = LV_STYLE_BG_GRAD_STOP;
void lv_style_set_bg_main_opa(lv_style_t * style, lv_opa_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_BG_MAIN_OPA, v);
}
const lv_style_prop_t _lv_style_const_prop_id_BG_MAIN_OPA = LV_STYLE_BG_MAIN_OPA;
void lv_style_set_bg_grad_opa(lv_style_t * style, lv_opa_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_BG_GRAD_OPA, v);
}
const lv_style_prop_t _lv_style_const_prop_id_BG_GRAD_OPA = LV_STYLE_BG_GRAD_OPA;
void lv_style_set_bg_grad(lv_style_t * style, const lv_grad_dsc_t * value)
{
lv_style_value_t v = {
.ptr = value
};
lv_style_set_prop(style, LV_STYLE_BG_GRAD, v);
}
const lv_style_prop_t _lv_style_const_prop_id_BG_GRAD = LV_STYLE_BG_GRAD;
void lv_style_set_bg_image_src(lv_style_t * style, const void * value)
{
lv_style_value_t v = {
.ptr = value
};
lv_style_set_prop(style, LV_STYLE_BG_IMAGE_SRC, v);
}
const lv_style_prop_t _lv_style_const_prop_id_BG_IMAGE_SRC = LV_STYLE_BG_IMAGE_SRC;
void lv_style_set_bg_image_opa(lv_style_t * style, lv_opa_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_BG_IMAGE_OPA, v);
}
const lv_style_prop_t _lv_style_const_prop_id_BG_IMAGE_OPA = LV_STYLE_BG_IMAGE_OPA;
void lv_style_set_bg_image_recolor(lv_style_t * style, lv_color_t value)
{
lv_style_value_t v = {
.color = value
};
lv_style_set_prop(style, LV_STYLE_BG_IMAGE_RECOLOR, v);
}
const lv_style_prop_t _lv_style_const_prop_id_BG_IMAGE_RECOLOR = LV_STYLE_BG_IMAGE_RECOLOR;
void lv_style_set_bg_image_recolor_opa(lv_style_t * style, lv_opa_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_BG_IMAGE_RECOLOR_OPA, v);
}
const lv_style_prop_t _lv_style_const_prop_id_BG_IMAGE_RECOLOR_OPA = LV_STYLE_BG_IMAGE_RECOLOR_OPA;
void lv_style_set_bg_image_tiled(lv_style_t * style, bool value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_BG_IMAGE_TILED, v);
}
const lv_style_prop_t _lv_style_const_prop_id_BG_IMAGE_TILED = LV_STYLE_BG_IMAGE_TILED;
void lv_style_set_border_color(lv_style_t * style, lv_color_t value)
{
lv_style_value_t v = {
.color = value
};
lv_style_set_prop(style, LV_STYLE_BORDER_COLOR, v);
}
const lv_style_prop_t _lv_style_const_prop_id_BORDER_COLOR = LV_STYLE_BORDER_COLOR;
void lv_style_set_border_opa(lv_style_t * style, lv_opa_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_BORDER_OPA, v);
}
const lv_style_prop_t _lv_style_const_prop_id_BORDER_OPA = LV_STYLE_BORDER_OPA;
void lv_style_set_border_width(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_BORDER_WIDTH, v);
}
const lv_style_prop_t _lv_style_const_prop_id_BORDER_WIDTH = LV_STYLE_BORDER_WIDTH;
void lv_style_set_border_side(lv_style_t * style, lv_border_side_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_BORDER_SIDE, v);
}
const lv_style_prop_t _lv_style_const_prop_id_BORDER_SIDE = LV_STYLE_BORDER_SIDE;
void lv_style_set_border_post(lv_style_t * style, bool value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_BORDER_POST, v);
}
const lv_style_prop_t _lv_style_const_prop_id_BORDER_POST = LV_STYLE_BORDER_POST;
void lv_style_set_outline_width(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_OUTLINE_WIDTH, v);
}
const lv_style_prop_t _lv_style_const_prop_id_OUTLINE_WIDTH = LV_STYLE_OUTLINE_WIDTH;
void lv_style_set_outline_color(lv_style_t * style, lv_color_t value)
{
lv_style_value_t v = {
.color = value
};
lv_style_set_prop(style, LV_STYLE_OUTLINE_COLOR, v);
}
const lv_style_prop_t _lv_style_const_prop_id_OUTLINE_COLOR = LV_STYLE_OUTLINE_COLOR;
void lv_style_set_outline_opa(lv_style_t * style, lv_opa_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_OUTLINE_OPA, v);
}
const lv_style_prop_t _lv_style_const_prop_id_OUTLINE_OPA = LV_STYLE_OUTLINE_OPA;
void lv_style_set_outline_pad(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_OUTLINE_PAD, v);
}
const lv_style_prop_t _lv_style_const_prop_id_OUTLINE_PAD = LV_STYLE_OUTLINE_PAD;
void lv_style_set_shadow_width(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_SHADOW_WIDTH, v);
}
const lv_style_prop_t _lv_style_const_prop_id_SHADOW_WIDTH = LV_STYLE_SHADOW_WIDTH;
void lv_style_set_shadow_offset_x(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_SHADOW_OFFSET_X, v);
}
const lv_style_prop_t _lv_style_const_prop_id_SHADOW_OFFSET_X = LV_STYLE_SHADOW_OFFSET_X;
void lv_style_set_shadow_offset_y(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_SHADOW_OFFSET_Y, v);
}
const lv_style_prop_t _lv_style_const_prop_id_SHADOW_OFFSET_Y = LV_STYLE_SHADOW_OFFSET_Y;
void lv_style_set_shadow_spread(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_SHADOW_SPREAD, v);
}
const lv_style_prop_t _lv_style_const_prop_id_SHADOW_SPREAD = LV_STYLE_SHADOW_SPREAD;
void lv_style_set_shadow_color(lv_style_t * style, lv_color_t value)
{
lv_style_value_t v = {
.color = value
};
lv_style_set_prop(style, LV_STYLE_SHADOW_COLOR, v);
}
const lv_style_prop_t _lv_style_const_prop_id_SHADOW_COLOR = LV_STYLE_SHADOW_COLOR;
void lv_style_set_shadow_opa(lv_style_t * style, lv_opa_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_SHADOW_OPA, v);
}
const lv_style_prop_t _lv_style_const_prop_id_SHADOW_OPA = LV_STYLE_SHADOW_OPA;
void lv_style_set_image_opa(lv_style_t * style, lv_opa_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_IMAGE_OPA, v);
}
const lv_style_prop_t _lv_style_const_prop_id_IMAGE_OPA = LV_STYLE_IMAGE_OPA;
void lv_style_set_image_recolor(lv_style_t * style, lv_color_t value)
{
lv_style_value_t v = {
.color = value
};
lv_style_set_prop(style, LV_STYLE_IMAGE_RECOLOR, v);
}
const lv_style_prop_t _lv_style_const_prop_id_IMAGE_RECOLOR = LV_STYLE_IMAGE_RECOLOR;
void lv_style_set_image_recolor_opa(lv_style_t * style, lv_opa_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_IMAGE_RECOLOR_OPA, v);
}
const lv_style_prop_t _lv_style_const_prop_id_IMAGE_RECOLOR_OPA = LV_STYLE_IMAGE_RECOLOR_OPA;
void lv_style_set_line_width(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_LINE_WIDTH, v);
}
const lv_style_prop_t _lv_style_const_prop_id_LINE_WIDTH = LV_STYLE_LINE_WIDTH;
void lv_style_set_line_dash_width(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_LINE_DASH_WIDTH, v);
}
const lv_style_prop_t _lv_style_const_prop_id_LINE_DASH_WIDTH = LV_STYLE_LINE_DASH_WIDTH;
void lv_style_set_line_dash_gap(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_LINE_DASH_GAP, v);
}
const lv_style_prop_t _lv_style_const_prop_id_LINE_DASH_GAP = LV_STYLE_LINE_DASH_GAP;
void lv_style_set_line_rounded(lv_style_t * style, bool value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_LINE_ROUNDED, v);
}
const lv_style_prop_t _lv_style_const_prop_id_LINE_ROUNDED = LV_STYLE_LINE_ROUNDED;
void lv_style_set_line_color(lv_style_t * style, lv_color_t value)
{
lv_style_value_t v = {
.color = value
};
lv_style_set_prop(style, LV_STYLE_LINE_COLOR, v);
}
const lv_style_prop_t _lv_style_const_prop_id_LINE_COLOR = LV_STYLE_LINE_COLOR;
void lv_style_set_line_opa(lv_style_t * style, lv_opa_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_LINE_OPA, v);
}
const lv_style_prop_t _lv_style_const_prop_id_LINE_OPA = LV_STYLE_LINE_OPA;
void lv_style_set_arc_width(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_ARC_WIDTH, v);
}
const lv_style_prop_t _lv_style_const_prop_id_ARC_WIDTH = LV_STYLE_ARC_WIDTH;
void lv_style_set_arc_rounded(lv_style_t * style, bool value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_ARC_ROUNDED, v);
}
const lv_style_prop_t _lv_style_const_prop_id_ARC_ROUNDED = LV_STYLE_ARC_ROUNDED;
void lv_style_set_arc_color(lv_style_t * style, lv_color_t value)
{
lv_style_value_t v = {
.color = value
};
lv_style_set_prop(style, LV_STYLE_ARC_COLOR, v);
}
const lv_style_prop_t _lv_style_const_prop_id_ARC_COLOR = LV_STYLE_ARC_COLOR;
void lv_style_set_arc_opa(lv_style_t * style, lv_opa_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_ARC_OPA, v);
}
const lv_style_prop_t _lv_style_const_prop_id_ARC_OPA = LV_STYLE_ARC_OPA;
void lv_style_set_arc_image_src(lv_style_t * style, const void * value)
{
lv_style_value_t v = {
.ptr = value
};
lv_style_set_prop(style, LV_STYLE_ARC_IMAGE_SRC, v);
}
const lv_style_prop_t _lv_style_const_prop_id_ARC_IMAGE_SRC = LV_STYLE_ARC_IMAGE_SRC;
void lv_style_set_text_color(lv_style_t * style, lv_color_t value)
{
lv_style_value_t v = {
.color = value
};
lv_style_set_prop(style, LV_STYLE_TEXT_COLOR, v);
}
const lv_style_prop_t _lv_style_const_prop_id_TEXT_COLOR = LV_STYLE_TEXT_COLOR;
void lv_style_set_text_opa(lv_style_t * style, lv_opa_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_TEXT_OPA, v);
}
const lv_style_prop_t _lv_style_const_prop_id_TEXT_OPA = LV_STYLE_TEXT_OPA;
void lv_style_set_text_font(lv_style_t * style, const lv_font_t * value)
{
lv_style_value_t v = {
.ptr = value
};
lv_style_set_prop(style, LV_STYLE_TEXT_FONT, v);
}
const lv_style_prop_t _lv_style_const_prop_id_TEXT_FONT = LV_STYLE_TEXT_FONT;
void lv_style_set_text_letter_space(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_TEXT_LETTER_SPACE, v);
}
const lv_style_prop_t _lv_style_const_prop_id_TEXT_LETTER_SPACE = LV_STYLE_TEXT_LETTER_SPACE;
void lv_style_set_text_line_space(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_TEXT_LINE_SPACE, v);
}
const lv_style_prop_t _lv_style_const_prop_id_TEXT_LINE_SPACE = LV_STYLE_TEXT_LINE_SPACE;
void lv_style_set_text_decor(lv_style_t * style, lv_text_decor_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_TEXT_DECOR, v);
}
const lv_style_prop_t _lv_style_const_prop_id_TEXT_DECOR = LV_STYLE_TEXT_DECOR;
void lv_style_set_text_align(lv_style_t * style, lv_text_align_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_TEXT_ALIGN, v);
}
const lv_style_prop_t _lv_style_const_prop_id_TEXT_ALIGN = LV_STYLE_TEXT_ALIGN;
void lv_style_set_radius(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_RADIUS, v);
}
const lv_style_prop_t _lv_style_const_prop_id_RADIUS = LV_STYLE_RADIUS;
void lv_style_set_clip_corner(lv_style_t * style, bool value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_CLIP_CORNER, v);
}
const lv_style_prop_t _lv_style_const_prop_id_CLIP_CORNER = LV_STYLE_CLIP_CORNER;
void lv_style_set_opa(lv_style_t * style, lv_opa_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_OPA, v);
}
const lv_style_prop_t _lv_style_const_prop_id_OPA = LV_STYLE_OPA;
void lv_style_set_opa_layered(lv_style_t * style, lv_opa_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_OPA_LAYERED, v);
}
const lv_style_prop_t _lv_style_const_prop_id_OPA_LAYERED = LV_STYLE_OPA_LAYERED;
void lv_style_set_color_filter_dsc(lv_style_t * style, const lv_color_filter_dsc_t * value)
{
lv_style_value_t v = {
.ptr = value
};
lv_style_set_prop(style, LV_STYLE_COLOR_FILTER_DSC, v);
}
const lv_style_prop_t _lv_style_const_prop_id_COLOR_FILTER_DSC = LV_STYLE_COLOR_FILTER_DSC;
void lv_style_set_color_filter_opa(lv_style_t * style, lv_opa_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_COLOR_FILTER_OPA, v);
}
const lv_style_prop_t _lv_style_const_prop_id_COLOR_FILTER_OPA = LV_STYLE_COLOR_FILTER_OPA;
void lv_style_set_anim(lv_style_t * style, const lv_anim_t * value)
{
lv_style_value_t v = {
.ptr = value
};
lv_style_set_prop(style, LV_STYLE_ANIM, v);
}
const lv_style_prop_t _lv_style_const_prop_id_ANIM = LV_STYLE_ANIM;
void lv_style_set_anim_time(lv_style_t * style, uint32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_ANIM_TIME, v);
}
const lv_style_prop_t _lv_style_const_prop_id_ANIM_TIME = LV_STYLE_ANIM_TIME;
void lv_style_set_anim_speed(lv_style_t * style, uint32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_ANIM_SPEED, v);
}
const lv_style_prop_t _lv_style_const_prop_id_ANIM_SPEED = LV_STYLE_ANIM_SPEED;
void lv_style_set_transition(lv_style_t * style, const lv_style_transition_dsc_t * value)
{
lv_style_value_t v = {
.ptr = value
};
lv_style_set_prop(style, LV_STYLE_TRANSITION, v);
}
const lv_style_prop_t _lv_style_const_prop_id_TRANSITION = LV_STYLE_TRANSITION;
void lv_style_set_blend_mode(lv_style_t * style, lv_blend_mode_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_BLEND_MODE, v);
}
const lv_style_prop_t _lv_style_const_prop_id_BLEND_MODE = LV_STYLE_BLEND_MODE;
void lv_style_set_layout(lv_style_t * style, uint16_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_LAYOUT, v);
}
const lv_style_prop_t _lv_style_const_prop_id_LAYOUT = LV_STYLE_LAYOUT;
void lv_style_set_base_dir(lv_style_t * style, lv_base_dir_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_BASE_DIR, v);
}
const lv_style_prop_t _lv_style_const_prop_id_BASE_DIR = LV_STYLE_BASE_DIR;
void lv_style_set_flex_flow(lv_style_t * style, lv_flex_flow_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_FLEX_FLOW, v);
}
const lv_style_prop_t _lv_style_const_prop_id_FLEX_FLOW = LV_STYLE_FLEX_FLOW;
void lv_style_set_flex_main_place(lv_style_t * style, lv_flex_align_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_FLEX_MAIN_PLACE, v);
}
const lv_style_prop_t _lv_style_const_prop_id_FLEX_MAIN_PLACE = LV_STYLE_FLEX_MAIN_PLACE;
void lv_style_set_flex_cross_place(lv_style_t * style, lv_flex_align_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_FLEX_CROSS_PLACE, v);
}
const lv_style_prop_t _lv_style_const_prop_id_FLEX_CROSS_PLACE = LV_STYLE_FLEX_CROSS_PLACE;
void lv_style_set_flex_track_place(lv_style_t * style, lv_flex_align_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_FLEX_TRACK_PLACE, v);
}
const lv_style_prop_t _lv_style_const_prop_id_FLEX_TRACK_PLACE = LV_STYLE_FLEX_TRACK_PLACE;
void lv_style_set_flex_grow(lv_style_t * style, uint8_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_FLEX_GROW, v);
}
const lv_style_prop_t _lv_style_const_prop_id_FLEX_GROW = LV_STYLE_FLEX_GROW;
void lv_style_set_grid_column_dsc_array(lv_style_t * style, const int32_t * value)
{
lv_style_value_t v = {
.ptr = value
};
lv_style_set_prop(style, LV_STYLE_GRID_COLUMN_DSC_ARRAY, v);
}
const lv_style_prop_t _lv_style_const_prop_id_GRID_COLUMN_DSC_ARRAY = LV_STYLE_GRID_COLUMN_DSC_ARRAY;
void lv_style_set_grid_column_align(lv_style_t * style, lv_grid_align_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_GRID_COLUMN_ALIGN, v);
}
const lv_style_prop_t _lv_style_const_prop_id_GRID_COLUMN_ALIGN = LV_STYLE_GRID_COLUMN_ALIGN;
void lv_style_set_grid_row_dsc_array(lv_style_t * style, const int32_t * value)
{
lv_style_value_t v = {
.ptr = value
};
lv_style_set_prop(style, LV_STYLE_GRID_ROW_DSC_ARRAY, v);
}
const lv_style_prop_t _lv_style_const_prop_id_GRID_ROW_DSC_ARRAY = LV_STYLE_GRID_ROW_DSC_ARRAY;
void lv_style_set_grid_row_align(lv_style_t * style, lv_grid_align_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_GRID_ROW_ALIGN, v);
}
const lv_style_prop_t _lv_style_const_prop_id_GRID_ROW_ALIGN = LV_STYLE_GRID_ROW_ALIGN;
void lv_style_set_grid_cell_column_pos(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_GRID_CELL_COLUMN_POS, v);
}
const lv_style_prop_t _lv_style_const_prop_id_GRID_CELL_COLUMN_POS = LV_STYLE_GRID_CELL_COLUMN_POS;
void lv_style_set_grid_cell_x_align(lv_style_t * style, lv_grid_align_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_GRID_CELL_X_ALIGN, v);
}
const lv_style_prop_t _lv_style_const_prop_id_GRID_CELL_X_ALIGN = LV_STYLE_GRID_CELL_X_ALIGN;
void lv_style_set_grid_cell_column_span(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_GRID_CELL_COLUMN_SPAN, v);
}
const lv_style_prop_t _lv_style_const_prop_id_GRID_CELL_COLUMN_SPAN = LV_STYLE_GRID_CELL_COLUMN_SPAN;
void lv_style_set_grid_cell_row_pos(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_GRID_CELL_ROW_POS, v);
}
const lv_style_prop_t _lv_style_const_prop_id_GRID_CELL_ROW_POS = LV_STYLE_GRID_CELL_ROW_POS;
void lv_style_set_grid_cell_y_align(lv_style_t * style, lv_grid_align_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_GRID_CELL_Y_ALIGN, v);
}
const lv_style_prop_t _lv_style_const_prop_id_GRID_CELL_Y_ALIGN = LV_STYLE_GRID_CELL_Y_ALIGN;
void lv_style_set_grid_cell_row_span(lv_style_t * style, int32_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_GRID_CELL_ROW_SPAN, v);
}
const lv_style_prop_t _lv_style_const_prop_id_GRID_CELL_ROW_SPAN = LV_STYLE_GRID_CELL_ROW_SPAN;
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_anim.h | /**
* @file lv_anim.h
*
*/
#ifndef LV_ANIM_H
#define LV_ANIM_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#include "lv_math.h"
#include "lv_timer.h"
#include "lv_ll.h"
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
/*********************
* DEFINES
*********************/
#define LV_ANIM_REPEAT_INFINITE 0xFFFF
#define LV_ANIM_PLAYTIME_INFINITE 0xFFFFFFFF
/*
* Macros used to set cubic-bezier anim parameter.
* Parameters come from https://easings.net/
*
* Usage:
*
* lv_anim_t a;
* lv_anim_init(&a);
* ...
* lv_anim_set_path_cb(&a, lv_anim_path_custom_bezier3);
* LV_ANIM_SET_EASE_IN_SINE(&a); //Set cubic-bezier anim parameter to easeInSine
* ...
* lv_anim_start(&a);
*/
#define _PARA(a, x1, y1, x2, y2) ((a)->parameter.bezier3 = \
(struct _lv_anim_bezier3_para_t) { \
LV_BEZIER_VAL_FLOAT(x1), LV_BEZIER_VAL_FLOAT(y1), \
LV_BEZIER_VAL_FLOAT(x2), LV_BEZIER_VAL_FLOAT(y2) } \
)
#define LV_ANIM_SET_EASE_IN_SINE(a) _PARA(a, 0.12, 0, 0.39, 0)
#define LV_ANIM_SET_EASE_OUT_SINE(a) _PARA(a, 0.61, 1, 0.88, 1)
#define LV_ANIM_SET_EASE_IN_OUT_SINE(a) _PARA(a, 0.37, 0, 0.63, 1)
#define LV_ANIM_SET_EASE_IN_QUAD(a) _PARA(a, 0.11, 0, 0.5, 0)
#define LV_ANIM_SET_EASE_OUT_QUAD(a) _PARA(a, 0.5, 1, 0.89, 1)
#define LV_ANIM_SET_EASE_IN_OUT_QUAD(a) _PARA(a, 0.45, 0, 0.55, 1)
#define LV_ANIM_SET_EASE_IN_CUBIC(a) _PARA(a, 0.32, 0, 0.67, 0)
#define LV_ANIM_SET_EASE_OUT_CUBIC(a) _PARA(a, 0.33, 1, 0.68, 1)
#define LV_ANIM_SET_EASE_IN_OUT_CUBIC(a) _PARA(a, 0.65, 0, 0.35, 1)
#define LV_ANIM_SET_EASE_IN_QUART(a) _PARA(a, 0.5, 0, 0.75, 0)
#define LV_ANIM_SET_EASE_OUT_QUART(a) _PARA(a, 0.25, 1, 0.5, 1)
#define LV_ANIM_SET_EASE_IN_OUT_QUART(a) _PARA(a, 0.76, 0, 0.24, 1)
#define LV_ANIM_SET_EASE_IN_QUINT(a) _PARA(a, 0.64, 0, 0.78, 0)
#define LV_ANIM_SET_EASE_OUT_QUINT(a) _PARA(a, 0.22, 1, 0.36, 1)
#define LV_ANIM_SET_EASE_IN_OUT_QUINT(a) _PARA(a, 0.83, 0, 0.17, 1)
#define LV_ANIM_SET_EASE_IN_EXPO(a) _PARA(a, 0.7, 0, 0.84, 0)
#define LV_ANIM_SET_EASE_OUT_EXPO(a) _PARA(a, 0.16, 1, 0.3, 1)
#define LV_ANIM_SET_EASE_IN_OUT_EXPO(a) _PARA(a, 0.87, 0, 0.13, 1)
#define LV_ANIM_SET_EASE_IN_CIRC(a) _PARA(a, 0.55, 0, 1, 0.45)
#define LV_ANIM_SET_EASE_OUT_CIRC(a) _PARA(a, 0, 0.55, 0.45, 1)
#define LV_ANIM_SET_EASE_IN_OUT_CIRC(a) _PARA(a, 0.85, 0, 0.15, 1)
#define LV_ANIM_SET_EASE_IN_BACK(a) _PARA(a, 0.36, 0, 0.66, -0.56)
#define LV_ANIM_SET_EASE_OUT_BACK(a) _PARA(a, 0.34, 1.56, 0.64, 1)
#define LV_ANIM_SET_EASE_IN_OUT_BACK(a) _PARA(a, 0.68, -0.6, 0.32, 1.6)
LV_EXPORT_CONST_INT(LV_ANIM_REPEAT_INFINITE);
LV_EXPORT_CONST_INT(LV_ANIM_PLAYTIME_INFINITE);
/**********************
* TYPEDEFS
**********************/
/** Can be used to indicate if animations are enabled or disabled in a case*/
typedef enum {
LV_ANIM_OFF,
LV_ANIM_ON,
} lv_anim_enable_t;
struct _lv_anim_t;
struct _lv_timer_t;
typedef struct {
bool anim_list_changed;
bool anim_run_round;
struct _lv_timer_t * timer;
lv_ll_t anim_ll;
} lv_anim_state_t;
/** Get the current value during an animation*/
typedef int32_t (*lv_anim_path_cb_t)(const struct _lv_anim_t *);
/** Generic prototype of "animator" functions.
* First parameter is the variable to animate.
* Second parameter is the value to set.
* Compatible with `lv_xxx_set_yyy(obj, value)` functions
* The `x` in `_xcb_t` means it's not a fully generic prototype because
* it doesn't receive `lv_anim_t *` as its first argument*/
typedef void (*lv_anim_exec_xcb_t)(void *, int32_t);
/** Same as `lv_anim_exec_xcb_t` but receives `lv_anim_t *` as the first parameter.
* It's more consistent but less convenient. Might be used by binding generator functions.*/
typedef void (*lv_anim_custom_exec_cb_t)(struct _lv_anim_t *, int32_t);
/** Callback to call when the animation is ready*/
typedef void (*lv_anim_ready_cb_t)(struct _lv_anim_t *);
/** Callback to call when the animation really stars (considering `delay`)*/
typedef void (*lv_anim_start_cb_t)(struct _lv_anim_t *);
/** Callback used when the animation values are relative to get the current value*/
typedef int32_t (*lv_anim_get_value_cb_t)(struct _lv_anim_t *);
/** Callback used when the animation is deleted*/
typedef void (*lv_anim_deleted_cb_t)(struct _lv_anim_t *);
typedef struct _lv_anim_bezier3_para_t {
int16_t x1;
int16_t y1;
int16_t x2;
int16_t y2;
} lv_anim_bezier3_para_t; /**< Parameter used when path is custom_bezier*/
/** Describes an animation*/
typedef struct _lv_anim_t {
void * var; /**<Variable to animate*/
lv_anim_exec_xcb_t exec_cb; /**< Function to execute to animate*/
lv_anim_start_cb_t start_cb; /**< Call it when the animation is starts (considering `delay`)*/
lv_anim_ready_cb_t ready_cb; /**< Call it when the animation is ready*/
lv_anim_deleted_cb_t deleted_cb; /**< Call it when the animation is deleted*/
lv_anim_get_value_cb_t get_value_cb; /**< Get the current value in relative mode*/
void * user_data; /**< Custom user data*/
lv_anim_path_cb_t path_cb; /**< Describe the path (curve) of animations*/
int32_t start_value; /**< Start value*/
int32_t current_value; /**< Current value*/
int32_t end_value; /**< End value*/
int32_t time; /**< Animation time in ms*/
int32_t act_time; /**< Current time in animation. Set to negative to make delay.*/
uint32_t playback_delay; /**< Wait before play back*/
uint32_t playback_time; /**< Duration of playback animation*/
uint32_t repeat_delay; /**< Wait before repeat*/
uint16_t repeat_cnt; /**< Repeat count for the animation*/
union _lv_anim_path_para_t {
lv_anim_bezier3_para_t bezier3; /**< Parameter used when path is custom_bezier*/
} parameter;
uint8_t early_apply : 1; /**< 1: Apply start value immediately even is there is `delay`*/
/*Animation system use these - user shouldn't set*/
uint32_t last_timer_run;
uint8_t playback_now : 1; /**< Play back is in progress*/
uint8_t run_round : 1; /**< Indicates the animation has run in this round*/
uint8_t start_cb_called : 1; /**< Indicates that the `start_cb` was already called*/
} lv_anim_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Init. the animation module
*/
void _lv_anim_core_init(void);
/**
* Initialize an animation variable.
* E.g.:
* lv_anim_t a;
* lv_anim_init(&a);
* lv_anim_set_...(&a);
* lv_anim_start(&a);
* @param a pointer to an `lv_anim_t` variable to initialize
*/
void lv_anim_init(lv_anim_t * a);
/**
* Set a variable to animate
* @param a pointer to an initialized `lv_anim_t` variable
* @param var pointer to a variable to animate
*/
static inline void lv_anim_set_var(lv_anim_t * a, void * var)
{
a->var = var;
}
/**
* Set a function to animate `var`
* @param a pointer to an initialized `lv_anim_t` variable
* @param exec_cb a function to execute during animation
* LVGL's built-in functions can be used.
* E.g. lv_obj_set_x
*/
static inline void lv_anim_set_exec_cb(lv_anim_t * a, lv_anim_exec_xcb_t exec_cb)
{
a->exec_cb = exec_cb;
}
/**
* Set the duration of an animation
* @param a pointer to an initialized `lv_anim_t` variable
* @param duration duration of the animation in milliseconds
*/
static inline void lv_anim_set_time(lv_anim_t * a, uint32_t duration)
{
a->time = duration;
}
/**
* Set a delay before starting the animation
* @param a pointer to an initialized `lv_anim_t` variable
* @param delay delay before the animation in milliseconds
*/
static inline void lv_anim_set_delay(lv_anim_t * a, uint32_t delay)
{
a->act_time = -(int32_t)(delay);
}
/**
* Set the start and end values of an animation
* @param a pointer to an initialized `lv_anim_t` variable
* @param start the start value
* @param end the end value
*/
static inline void lv_anim_set_values(lv_anim_t * a, int32_t start, int32_t end)
{
a->start_value = start;
a->current_value = start;
a->end_value = end;
}
/**
* Similar to `lv_anim_set_exec_cb` but `lv_anim_custom_exec_cb_t` receives
* `lv_anim_t * ` as its first parameter instead of `void *`.
* This function might be used when LVGL is bound to other languages because
* it's more consistent to have `lv_anim_t *` as first parameter.
* The variable to animate can be stored in the animation's `user_data`
* @param a pointer to an initialized `lv_anim_t` variable
* @param exec_cb a function to execute.
*/
static inline void lv_anim_set_custom_exec_cb(lv_anim_t * a, lv_anim_custom_exec_cb_t exec_cb)
{
a->var = a;
a->exec_cb = (lv_anim_exec_xcb_t)exec_cb;
}
/**
* Set the path (curve) of the animation.
* @param a pointer to an initialized `lv_anim_t` variable
* @param path_cb a function to set the current value of the animation.
*/
static inline void lv_anim_set_path_cb(lv_anim_t * a, lv_anim_path_cb_t path_cb)
{
a->path_cb = path_cb;
}
/**
* Set a function call when the animation really starts (considering `delay`)
* @param a pointer to an initialized `lv_anim_t` variable
* @param start_cb a function call when the animation starts
*/
static inline void lv_anim_set_start_cb(lv_anim_t * a, lv_anim_start_cb_t start_cb)
{
a->start_cb = start_cb;
}
/**
* Set a function to use the current value of the variable and make start and end value
* relative to the returned current value.
* @param a pointer to an initialized `lv_anim_t` variable
* @param get_value_cb a function call when the animation starts
*/
static inline void lv_anim_set_get_value_cb(lv_anim_t * a, lv_anim_get_value_cb_t get_value_cb)
{
a->get_value_cb = get_value_cb;
}
/**
* Set a function call when the animation is ready
* @param a pointer to an initialized `lv_anim_t` variable
* @param ready_cb a function call when the animation is ready
*/
static inline void lv_anim_set_ready_cb(lv_anim_t * a, lv_anim_ready_cb_t ready_cb)
{
a->ready_cb = ready_cb;
}
/**
* Set a function call when the animation is deleted.
* @param a pointer to an initialized `lv_anim_t` variable
* @param deleted_cb a function call when the animation is deleted
*/
static inline void lv_anim_set_deleted_cb(lv_anim_t * a, lv_anim_deleted_cb_t deleted_cb)
{
a->deleted_cb = deleted_cb;
}
/**
* Make the animation to play back to when the forward direction is ready
* @param a pointer to an initialized `lv_anim_t` variable
* @param time the duration of the playback animation in milliseconds. 0: disable playback
*/
static inline void lv_anim_set_playback_time(lv_anim_t * a, uint32_t time)
{
a->playback_time = time;
}
/**
* Make the animation to play back to when the forward direction is ready
* @param a pointer to an initialized `lv_anim_t` variable
* @param delay delay in milliseconds before starting the playback animation.
*/
static inline void lv_anim_set_playback_delay(lv_anim_t * a, uint32_t delay)
{
a->playback_delay = delay;
}
/**
* Make the animation repeat itself.
* @param a pointer to an initialized `lv_anim_t` variable
* @param cnt repeat count or `LV_ANIM_REPEAT_INFINITE` for infinite repetition. 0: to disable repetition.
*/
static inline void lv_anim_set_repeat_count(lv_anim_t * a, uint16_t cnt)
{
a->repeat_cnt = cnt;
}
/**
* Set a delay before repeating the animation.
* @param a pointer to an initialized `lv_anim_t` variable
* @param delay delay in milliseconds before repeating the animation.
*/
static inline void lv_anim_set_repeat_delay(lv_anim_t * a, uint32_t delay)
{
a->repeat_delay = delay;
}
/**
* Set a whether the animation's should be applied immediately or only when the delay expired.
* @param a pointer to an initialized `lv_anim_t` variable
* @param en true: apply the start value immediately in `lv_anim_start`;
* false: apply the start value only when `delay` ms is elapsed and the animations really starts
*/
static inline void lv_anim_set_early_apply(lv_anim_t * a, bool en)
{
a->early_apply = en;
}
/**
* Set the custom user data field of the animation.
* @param a pointer to an initialized `lv_anim_t` variable
* @param user_data pointer to the new user_data.
*/
static inline void lv_anim_set_user_data(lv_anim_t * a, void * user_data)
{
a->user_data = user_data;
}
/**
* Set parameter for cubic bezier path
* @param a pointer to an initialized `lv_anim_t` variable
* @param x1 first control point
* @param y1
* @param y1 second control point
*/
static inline void lv_anim_set_bezier3_param(lv_anim_t * a, int16_t x1, int16_t y1, int16_t x2, int16_t y2)
{
struct _lv_anim_bezier3_para_t * para = &a->parameter.bezier3;
para->x1 = x1;
para->x2 = x2;
para->y1 = y1;
para->y2 = y2;
}
/**
* Create an animation
* @param a an initialized 'anim_t' variable. Not required after call.
* @return pointer to the created animation (different from the `a` parameter)
*/
lv_anim_t * lv_anim_start(const lv_anim_t * a);
/**
* Get a delay before starting the animation
* @param a pointer to an initialized `lv_anim_t` variable
* @return delay before the animation in milliseconds
*/
static inline uint32_t lv_anim_get_delay(lv_anim_t * a)
{
return -a->act_time;
}
/**
* Get the time used to play the animation.
* @param a pointer to an animation.
* @return the play time in milliseconds.
*/
uint32_t lv_anim_get_playtime(lv_anim_t * a);
/**
* Get the duration of an animation
* @param a pointer to an initialized `lv_anim_t` variable
* @return the duration of the animation in milliseconds
*/
static inline uint32_t lv_anim_get_time(lv_anim_t * a)
{
return a->time;
}
/**
* Get the repeat count of the animation.
* @param a pointer to an initialized `lv_anim_t` variable
* @return the repeat count or `LV_ANIM_REPEAT_INFINITE` for infinite repetition. 0: disabled repetition.
*/
static inline uint16_t lv_anim_get_repeat_count(lv_anim_t * a)
{
return a->repeat_cnt;
}
/**
* Get the user_data field of the animation
* @param a pointer to an initialized `lv_anim_t` variable
* @return the pointer to the custom user_data of the animation
*/
static inline void * lv_anim_get_user_data(lv_anim_t * a)
{
return a->user_data;
}
/**
* Delete an animation of a variable with a given animator function
* @param var pointer to variable
* @param exec_cb a function pointer which is animating 'var',
* or NULL to ignore it and delete all the animations of 'var
* @return true: at least 1 animation is deleted, false: no animation is deleted
*/
bool lv_anim_delete(void * var, lv_anim_exec_xcb_t exec_cb);
/**
* Delete all the animations
*/
void lv_anim_delete_all(void);
/**
* Get the animation of a variable and its `exec_cb`.
* @param var pointer to variable
* @param exec_cb a function pointer which is animating 'var', or NULL to return first matching 'var'
* @return pointer to the animation.
*/
lv_anim_t * lv_anim_get(void * var, lv_anim_exec_xcb_t exec_cb);
/**
* Get global animation refresher timer.
* @return pointer to the animation refresher timer.
*/
struct _lv_timer_t * lv_anim_get_timer(void);
/**
* Delete an animation by getting the animated variable from `a`.
* Only animations with `exec_cb` will be deleted.
* This function exists because it's logical that all anim. functions receives an
* `lv_anim_t` as their first parameter. It's not practical in C but might make
* the API more consequent and makes easier to generate bindings.
* @param a pointer to an animation.
* @param exec_cb a function pointer which is animating 'var',
* or NULL to ignore it and delete all the animations of 'var
* @return true: at least 1 animation is deleted, false: no animation is deleted
*/
static inline bool lv_anim_custom_delete(lv_anim_t * a, lv_anim_custom_exec_cb_t exec_cb)
{
return lv_anim_delete(a ? a->var : NULL, (lv_anim_exec_xcb_t)exec_cb);
}
/**
* Get the animation of a variable and its `exec_cb`.
* This function exists because it's logical that all anim. functions receives an
* `lv_anim_t` as their first parameter. It's not practical in C but might make
* the API more consequent and makes easier to generate bindings.
* @param a pointer to an animation.
* @param exec_cb a function pointer which is animating 'var', or NULL to return first matching 'var'
* @return pointer to the animation.
*/
static inline lv_anim_t * lv_anim_custom_get(lv_anim_t * a, lv_anim_custom_exec_cb_t exec_cb)
{
return lv_anim_get(a ? a->var : NULL, (lv_anim_exec_xcb_t)exec_cb);
}
/**
* Get the number of currently running animations
* @return the number of running animations
*/
uint16_t lv_anim_count_running(void);
/**
* Calculate the time of an animation with a given speed and the start and end values
* @param speed speed of animation in unit/sec
* @param start start value of the animation
* @param end end value of the animation
* @return the required time [ms] for the animation with the given parameters
*/
uint32_t lv_anim_speed_to_time(uint32_t speed, int32_t start, int32_t end);
/**
* Manually refresh the state of the animations.
* Useful to make the animations running in a blocking process where
* `lv_timer_handler` can't run for a while.
* Shouldn't be used directly because it is called in `lv_refr_now()`.
*/
void lv_anim_refr_now(void);
/**
* Calculate the current value of an animation applying linear characteristic
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_linear(const lv_anim_t * a);
/**
* Calculate the current value of an animation slowing down the start phase
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_ease_in(const lv_anim_t * a);
/**
* Calculate the current value of an animation slowing down the end phase
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_ease_out(const lv_anim_t * a);
/**
* Calculate the current value of an animation applying an "S" characteristic (cosine)
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_ease_in_out(const lv_anim_t * a);
/**
* Calculate the current value of an animation with overshoot at the end
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_overshoot(const lv_anim_t * a);
/**
* Calculate the current value of an animation with 3 bounces
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_bounce(const lv_anim_t * a);
/**
* Calculate the current value of an animation applying step characteristic.
* (Set end value on the end of the animation)
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_step(const lv_anim_t * a);
/**
* A custom cubic bezier animation path, need to specify cubic-parameters in a->parameter.bezier3
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_custom_bezier3(const lv_anim_t * a);
/**********************
* GLOBAL VARIABLES
**********************/
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_ANIM_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_utils.h | /**
* @file lv_utils.h
*
*/
#ifndef LV_UTILS_H
#define LV_UTILS_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include <stdint.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/** Searches base[0] to base[n - 1] for an item that matches *key.
*
* @note The function cmp must return negative if it's first
* argument (the search key) is less that it's second (a table entry),
* zero if equal, and positive if greater.
*
* @note Items in the array must be in ascending order.
*
* @param key Pointer to item being searched for
* @param base Pointer to first element to search
* @param n Number of elements
* @param size Size of each element
* @param cmp Pointer to comparison function (see #unicode_list_compare as a comparison function
* example)
*
* @return a pointer to a matching item, or NULL if none exists.
*/
void * _lv_utils_bsearch(const void * key, const void * base, uint32_t n, uint32_t size,
int32_t (*cmp)(const void * pRef, const void * pElement));
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_profiler.h | /**
* @file lv_profiler.h
*
*/
#ifndef LV_PROFILER_H
#define LV_PROFILER_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#if LV_USE_PROFILER
#include LV_PROFILER_INCLUDE
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**********************
* MACROS
**********************/
#else
#define LV_PROFILER_BEGIN
#define LV_PROFILER_END
#define LV_PROFILER_BEGIN_TAG(tag) LV_UNUSED(tag)
#define LV_PROFILER_END_TAG(tag) LV_UNUSED(tag)
#endif /*LV_USE_PROFILER*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_PROFILER_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_types.h | /**
* @file lv_types.h
*
*/
#ifndef LV_TYPES_H
#define LV_TYPES_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include <stdint.h>
/*********************
* DEFINES
*********************/
// If __UINTPTR_MAX__ or UINTPTR_MAX are available, use them to determine arch size
#if defined(__UINTPTR_MAX__) && __UINTPTR_MAX__ > 0xFFFFFFFF
#define LV_ARCH_64
#elif defined(UINTPTR_MAX) && UINTPTR_MAX > 0xFFFFFFFF
#define LV_ARCH_64
// Otherwise use compiler-dependent means to determine arch size
#elif defined(_WIN64) || defined(__x86_64__) || defined(__ppc64__) || defined (__aarch64__)
#define LV_ARCH_64
#endif
#define LV_OS_NONE 0
#define LV_OS_PTHREAD 1
#define LV_OS_FREERTOS 2
#define LV_OS_CMSIS_RTOS2 3
#define LV_OS_RTTHREAD 4
#define LV_OS_CUSTOM 255
#define LV_STDLIB_BUILTIN 0
#define LV_STDLIB_CLIB 1
#define LV_STDLIB_MICROPYTHON 2
#define LV_STDLIB_CUSTOM 255
#define LV_DRAW_SW_ASM_NONE 0
#define LV_DRAW_SW_ASM_NEON 1
#define LV_DRAW_SW_ASM_MVE 2
#define LV_DRAW_SW_ASM_CUSTOM 255
/**********************
* TYPEDEFS
**********************/
/**
* LVGL error codes.
*/
enum _lv_result_t {
LV_RESULT_INVALID = 0, /*Typically indicates that the object is deleted (become invalid) in the action
function or an operation was failed*/
LV_RESULT_OK, /*The object is valid (no deleted) after the action*/
};
#ifdef DOXYGEN
typedef _lv_result_t lv_result_t;
#else
typedef uint8_t lv_result_t;
#endif /*DOXYGEN*/
#if defined(__cplusplus) || __STDC_VERSION__ >= 199901L
// If c99 or newer, use the definition of uintptr_t directly from <stdint.h>
typedef uintptr_t lv_uintptr_t;
typedef intptr_t lv_intptr_t;
#else
// Otherwise, use the arch size determination
#ifdef LV_ARCH_64
typedef uint64_t lv_uintptr_t;
typedef int64_t lv_intptr_t;
#else
typedef uint32_t lv_uintptr_t;
typedef int32_t lv_intptr_t;
#endif
#endif
/**********************
* GLOBAL PROTOTYPES
**********************/
/**********************
* MACROS
**********************/
#define LV_UNUSED(x) ((void)x)
#define _LV_CONCAT(x, y) x ## y
#define LV_CONCAT(x, y) _LV_CONCAT(x, y)
#define _LV_CONCAT3(x, y, z) x ## y ## z
#define LV_CONCAT3(x, y, z) _LV_CONCAT3(x, y, z)
#if defined(PYCPARSER) || defined(__CC_ARM)
#define LV_FORMAT_ATTRIBUTE(fmtstr, vararg)
#elif defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 4) || __GNUC__ > 4)
#define LV_FORMAT_ATTRIBUTE(fmtstr, vararg) __attribute__((format(gnu_printf, fmtstr, vararg)))
#elif (defined(__clang__) || defined(__GNUC__) || defined(__GNUG__))
#define LV_FORMAT_ATTRIBUTE(fmtstr, vararg) __attribute__((format(printf, fmtstr, vararg)))
#else
#define LV_FORMAT_ATTRIBUTE(fmtstr, vararg)
#endif
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_TYPES_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_text.h | /**
* @file lv_text.h
*
*/
#ifndef LV_TEXT_H
#define LV_TEXT_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#include <stdbool.h>
#include <stdarg.h>
#include "lv_area.h"
#include "../font/lv_font.h"
#include "../stdlib/lv_sprintf.h"
#include "lv_types.h"
/*********************
* DEFINES
*********************/
#define LV_TXT_ENC_UTF8 1
#define LV_TXT_ENC_ASCII 2
/**********************
* TYPEDEFS
**********************/
/**
* Options for text rendering.
*/
enum _lv_text_flag_t {
LV_TEXT_FLAG_NONE = 0x00,
LV_TEXT_FLAG_RECOLOR = 0x01, /**< Enable parsing of recolor command*/
LV_TEXT_FLAG_EXPAND = 0x02, /**< Ignore max-width to avoid automatic word wrapping*/
LV_TEXT_FLAG_FIT = 0x04, /**< Max-width is already equal to the longest line. (Used to skip some calculation)*/
};
#ifdef DOXYGEN
typedef _lv_text_flag_t lv_text_flag_t;
#else
typedef uint8_t lv_text_flag_t;
#endif /*DOXYGEN*/
/** Label align policy*/
enum _lv_text_align_t {
LV_TEXT_ALIGN_AUTO, /**< Align text auto*/
LV_TEXT_ALIGN_LEFT, /**< Align text to left*/
LV_TEXT_ALIGN_CENTER, /**< Align text to center*/
LV_TEXT_ALIGN_RIGHT, /**< Align text to right*/
};
#ifdef DOXYGEN
typedef _lv_text_align_t lv_text_align_t;
#else
typedef uint8_t lv_text_align_t;
#endif /*DOXYGEN*/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Get size of a text
* @param size_res pointer to a 'point_t' variable to store the result
* @param text pointer to a text
* @param font pointer to font of the text
* @param letter_space letter space of the text
* @param line_space line space of the text
* @param max_width max width of the text (break the lines to fit this size). Set COORD_MAX to avoid
* @param flag settings for the text from ::lv_text_flag_t
* line breaks
*/
void lv_text_get_size(lv_point_t * size_res, const char * text, const lv_font_t * font, int32_t letter_space,
int32_t line_space, int32_t max_width, lv_text_flag_t flag);
/**
* Get the next line of text. Check line length and break chars too.
* @param txt a '\0' terminated string
* @param font pointer to a font
* @param letter_space letter space
* @param max_width max width of the text (break the lines to fit this size). Set COORD_MAX to avoid
* line breaks
* @param used_width When used_width != NULL, save the width of this line if
* flag == LV_TEXT_FLAG_NONE, otherwise save -1.
* @param flag settings for the text from 'txt_flag_type' enum
* @return the index of the first char of the new line (in byte index not letter index. With UTF-8
* they are different)
*/
uint32_t _lv_text_get_next_line(const char * txt, const lv_font_t * font, int32_t letter_space,
int32_t max_width, int32_t * used_width, lv_text_flag_t flag);
/**
* Give the length of a text with a given font
* @param txt a '\0' terminate string
* @param length length of 'txt' in byte count and not characters (Á is 1 character but 2 bytes in
* UTF-8)
* @param font pointer to a font
* @param letter_space letter space
* @return length of a char_num long text
*/
int32_t lv_text_get_width(const char * txt, uint32_t length, const lv_font_t * font, int32_t letter_space);
/**
* Insert a string into an other
* @param txt_buf the original text (must be big enough for the result text and NULL terminated)
* @param pos position to insert (0: before the original text, 1: after the first char etc.)
* @param ins_txt text to insert, must be '\0' terminated
*/
void _lv_text_ins(char * txt_buf, uint32_t pos, const char * ins_txt);
/**
* Delete a part of a string
* @param txt string to modify, must be '\0' terminated and should point to a heap or stack frame, not read-only memory.
* @param pos position where to start the deleting (0: before the first char, 1: after the first
* char etc.)
* @param len number of characters to delete
*/
void _lv_text_cut(char * txt, uint32_t pos, uint32_t len);
/**
* return a new formatted text. Memory will be allocated to store the text.
* @param fmt `printf`-like format
* @param ap items to print
* @return pointer to the allocated text string.
*/
char * _lv_text_set_text_vfmt(const char * fmt, va_list ap) LV_FORMAT_ATTRIBUTE(1, 0);
/**
* Decode two encoded character from a string.
* @param txt pointer to '\0' terminated string
* @param letter the first decoded Unicode character or 0 on invalid data code
* @param letter_next the second decoded Unicode character or 0 on invalid data code
* @param ofs start index in 'txt' where to start.
* After the call it will point to the next encoded char in 'txt'.
* NULL to use txt[0] as index
*/
void _lv_text_encoded_letter_next_2(const char * txt, uint32_t * letter, uint32_t * letter_next, uint32_t * ofs);
/**
* Test if char is break char or not (a text can broken here or not)
* @param letter a letter
* @return false: 'letter' is not break char
*/
static inline bool _lv_text_is_break_char(uint32_t letter)
{
uint8_t i;
bool ret = false;
/*Compare the letter to TXT_BREAK_CHARS*/
for(i = 0; LV_TXT_BREAK_CHARS[i] != '\0'; i++) {
if(letter == (uint32_t)LV_TXT_BREAK_CHARS[i]) {
ret = true; /*If match then it is break char*/
break;
}
}
return ret;
}
/**
* Test if char is break char or not (a text can broken here or not)
* @param letter a letter
* @return false: 'letter' is not break char
*/
static inline bool _lv_text_is_a_word(uint32_t letter)
{
/*Cheap check on invalid letter*/
if(letter == 0) return false;
/*Chinese characters*/
if(letter >= 0x4E00 && letter <= 0x9FA5) {
return true;
}
/*Fullwidth ASCII variants*/
if(letter >= 0xFF01 && letter <= 0xFF5E) {
return true;
}
/*CJK symbols and punctuation*/
if(letter >= 0x3000 && letter <= 0x303F) {
return true;
}
return false;
}
/***************************************************************
* GLOBAL FUNCTION POINTERS FOR CHARACTER ENCODING INTERFACE
***************************************************************/
/**
* Give the size of an encoded character
* @param str pointer to a character in a string
* @return length of the encoded character (1,2,3 ...). O in invalid
*/
extern uint8_t (*_lv_text_encoded_size)(const char *);
/**
* Convert a Unicode letter to encoded
* @param letter_uni a Unicode letter
* @return Encoded character in Little Endian to be compatible with C chars (e.g. 'Á', 'Ü')
*/
extern uint32_t (*_lv_text_unicode_to_encoded)(uint32_t);
/**
* Convert a wide character, e.g. 'Á' little endian to be compatible with the encoded format.
* @param c a wide character
* @return `c` in the encoded format
*/
extern uint32_t (*_lv_text_encoded_conv_wc)(uint32_t c);
/**
* Decode the next encoded character from a string.
* @param txt pointer to '\0' terminated string
* @param i start index in 'txt' where to start.
* After the call it will point to the next encoded char in 'txt'.
* NULL to use txt[0] as index
* @return the decoded Unicode character or 0 on invalid data code
*/
extern uint32_t (*_lv_text_encoded_next)(const char *, uint32_t *);
/**
* Get the previous encoded character form a string.
* @param txt pointer to '\0' terminated string
* @param i_start index in 'txt' where to start. After the call it will point to the previous
* encoded char in 'txt'.
* @return the decoded Unicode character or 0 on invalid data
*/
extern uint32_t (*_lv_text_encoded_prev)(const char *, uint32_t *);
/**
* Convert a letter index (in the encoded text) to byte index.
* E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long
* @param txt a '\0' terminated UTF-8 string
* @param enc_id letter index
* @return byte index of the 'enc_id'th letter
*/
extern uint32_t (*_lv_text_encoded_get_byte_id)(const char *, uint32_t);
/**
* Convert a byte index (in an encoded text) to character index.
* E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long
* @param txt a '\0' terminated UTF-8 string
* @param byte_id byte index
* @return character index of the letter at 'byte_id'th position
*/
extern uint32_t (*_lv_text_encoded_get_char_id)(const char *, uint32_t);
/**
* Get the number of characters (and NOT bytes) in a string.
* E.g. in UTF-8 "ÁBC" is 3 characters (but 4 bytes)
* @param txt a '\0' terminated char string
* @return number of characters
*/
extern uint32_t (*_lv_text_get_encoded_length)(const char *);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_TEXT_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_text_ap.c | /**
* @file lv_text_ap.c
*
*/
/*********************
* INCLUDES
*********************/
#include <stddef.h>
#include "lv_bidi.h"
#include "lv_text.h"
#include "lv_text_ap.h"
#include "../stdlib/lv_mem.h"
#include "../draw/lv_draw.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef struct {
uint8_t char_offset;
uint16_t char_end_form;
int8_t char_beginning_form_offset;
int8_t char_middle_form_offset;
int8_t char_isolated_form_offset;
struct {
uint8_t conj_to_previous;
uint8_t conj_to_next;
} ap_chars_conjunction;
} ap_chars_map_t;
/**********************
* STATIC PROTOTYPES
**********************/
#if LV_USE_ARABIC_PERSIAN_CHARS == 1
static uint32_t lv_ap_get_char_index(uint16_t c);
static uint32_t lv_text_lam_alef(uint32_t ch_curr, uint32_t ch_next);
static bool lv_text_is_arabic_vowel(uint16_t c);
/**********************
* STATIC VARIABLES
**********************/
const ap_chars_map_t ap_chars_map[] = {
/*{Key Offset, End, Beginning, Middle, Isolated, {conjunction}}*/
{1, 0xFE84, -1, 0, -1, {1, 0}}, // أ
{2, 0xFE86, -1, 0, -1, {1, 0}}, // ؤ
{3, 0xFE88, -1, 0, -1, {1, 0}}, // ﺇ
{4, 0xFE8A, 1, 2, -1, {1, 0}}, // ئ
{5, 0xFE8E, -1, 0, -1, {1, 0}}, // آ
{6, 0xFE90, 1, 2, -1, {1, 1}}, // ب
{92, 0xFB57, 1, 2, -1, {1, 1}}, // پ
{8, 0xFE96, 1, 2, -1, {1, 1}}, // ت
{9, 0xFE9A, 1, 2, -1, {1, 1}}, // ث
{10, 0xFE9E, 1, 2, -1, {1, 1}}, // ج
{100, 0xFB7B, 1, 2, -1, {1, 1}}, // چ
{11, 0xFEA2, 1, 2, -1, {1, 1}}, // ح
{12, 0xFEA6, 1, 2, -1, {1, 1}}, // خ
{13, 0xFEAA, -1, 0, -1, {1, 0}}, // د
{14, 0xFEAC, -1, 0, -1, {1, 0}}, // ذ
{15, 0xFEAE, -1, 0, -1, {1, 0}}, // ر
{16, 0xFEB0, -1, 0, -1, {1, 0}}, // ز
{118, 0xFB8B, -1, 0, -1, {1, 0}}, // ژ
{17, 0xFEB2, 1, 2, -1, {1, 1}}, // س
{18, 0xFEB6, 1, 2, -1, {1, 1}}, // ش
{19, 0xFEBA, 1, 2, -1, {1, 1}}, // ص
{20, 0xFEBE, 1, 2, -1, {1, 1}}, // ض
{21, 0xFEC2, 1, 2, -1, {1, 1}}, // ط
{22, 0xFEC6, 1, 2, -1, {1, 1}}, // ظ
{23, 0xFECA, 1, 2, -1, {1, 1}}, // ع
{24, 0xFECE, 1, 2, -1, {1, 1}}, // غ
{30, 0x0640, 0, 0, 0, {1, 1}}, // - (mad, hyphen)
{31, 0xFED2, 1, 2, -1, {1, 1}}, // ف
{32, 0xFED6, 1, 2, -1, {1, 1}}, // ق
{135, 0xFB8F, 1, 2, -1, {1, 1}}, // ک
{33, 0xFEDA, 1, 2, -1, {1, 1}}, // ﻙ
{141, 0xFB93, 1, 2, -1, {1, 1}}, // گ
{34, 0xFEDE, 1, 2, -1, {1, 1}}, // ل
{35, 0xFEE2, 1, 2, -1, {1, 1}}, // م
{36, 0xFEE6, 1, 2, -1, {1, 1}}, // ن
{38, 0xFEEE, -1, 0, -1, {1, 0}}, // و
{37, 0xFEEA, 1, 2, -1, {1, 1}}, // ه
{39, 0xFEF0, 0, 0, -1, {1, 0}}, // ى
{40, 0xFEF2, 1, 2, -1, {1, 1}}, // ي
{170, 0xFBFD, 1, 2, -1, {1, 1}}, // ی
{7, 0xFE94, 1, 2, -1, {1, 0}}, // ة
{206, 0x06F0, 1, 2, -1, {0, 0}}, // ۰
{207, 0x06F1, 0, 0, 0, {0, 0}}, // ۱
{208, 0x06F2, 0, 0, 0, {0, 0}}, // ۲
{209, 0x06F3, 0, 0, 0, {0, 0}}, // ۳
{210, 0x06F4, 0, 0, 0, {0, 0}}, // ۴
{211, 0x06F5, 0, 0, 0, {0, 0}}, // ۵
{212, 0x06F6, 0, 0, 0, {0, 0}}, // ۶
{213, 0x06F7, 0, 0, 0, {0, 0}}, // ۷
{214, 0x06F8, 0, 0, 0, {0, 0}}, // ۸
{215, 0x06F9, 0, 0, 0, {0, 0}}, // ۹
LV_AP_END_CHARS_LIST
};
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
uint32_t _lv_text_ap_calc_bytes_cnt(const char * txt)
{
uint32_t txt_length = 0;
uint32_t chars_cnt = 0;
uint32_t current_ap_idx = 0;
uint32_t i, j;
uint32_t ch_enc;
txt_length = _lv_text_get_encoded_length(txt);
i = 0;
j = 0;
while(i < txt_length) {
ch_enc = _lv_text_encoded_next(txt, &j);
current_ap_idx = lv_ap_get_char_index(ch_enc);
if(current_ap_idx != LV_UNDEF_ARABIC_PERSIAN_CHARS)
ch_enc = ap_chars_map[current_ap_idx].char_end_form;
if(ch_enc < 0x80)
chars_cnt++;
else if(ch_enc < 0x0800)
chars_cnt += 2;
else if(ch_enc < 0x010000)
chars_cnt += 3;
else
chars_cnt += 4;
i++;
}
return chars_cnt + 1;
}
void _lv_text_ap_proc(const char * txt, char * txt_out)
{
uint32_t txt_length = 0;
uint32_t index_current, idx_next, idx_previous, i, j;
uint32_t * ch_enc;
uint32_t * ch_fin;
char * txt_out_temp;
txt_length = _lv_text_get_encoded_length(txt);
ch_enc = (uint32_t *)lv_malloc(sizeof(uint32_t) * (txt_length + 1));
ch_fin = (uint32_t *)lv_malloc(sizeof(uint32_t) * (txt_length + 1));
i = 0;
j = 0;
while(j < txt_length)
ch_enc[j++] = _lv_text_encoded_next(txt, &i);
ch_enc[j] = 0;
i = 0;
j = 0;
idx_previous = LV_UNDEF_ARABIC_PERSIAN_CHARS;
while(i < txt_length) {
index_current = lv_ap_get_char_index(ch_enc[i]);
idx_next = lv_ap_get_char_index(ch_enc[i + 1]);
if(lv_text_is_arabic_vowel(ch_enc[i])) { // Current character is a vowel
ch_fin[j] = ch_enc[i];
i++;
j++;
continue; // Skip this character
}
else if(lv_text_is_arabic_vowel(ch_enc[i + 1])) { // Next character is a vowel
idx_next = lv_ap_get_char_index(ch_enc[i + 2]); // Skip the vowel character to join with the character after it
}
if(index_current == LV_UNDEF_ARABIC_PERSIAN_CHARS) {
ch_fin[j] = ch_enc[i];
j++;
i++;
idx_previous = LV_UNDEF_ARABIC_PERSIAN_CHARS;
continue;
}
uint8_t conjunction_to_previuse = (i == 0 ||
idx_previous == LV_UNDEF_ARABIC_PERSIAN_CHARS) ? 0 : ap_chars_map[idx_previous].ap_chars_conjunction.conj_to_next;
uint8_t conjunction_to_next = ((i == txt_length - 1) ||
idx_next == LV_UNDEF_ARABIC_PERSIAN_CHARS) ? 0 : ap_chars_map[idx_next].ap_chars_conjunction.conj_to_previous;
uint32_t lam_alef = lv_text_lam_alef(index_current, idx_next);
if(lam_alef) {
if(conjunction_to_previuse) {
lam_alef ++;
}
ch_fin[j] = lam_alef;
idx_previous = LV_UNDEF_ARABIC_PERSIAN_CHARS;
i += 2;
j++;
continue;
}
if(conjunction_to_previuse && conjunction_to_next)
ch_fin[j] = ap_chars_map[index_current].char_end_form + ap_chars_map[index_current].char_middle_form_offset;
else if(!conjunction_to_previuse && conjunction_to_next)
ch_fin[j] = ap_chars_map[index_current].char_end_form + ap_chars_map[index_current].char_beginning_form_offset;
else if(conjunction_to_previuse && !conjunction_to_next)
ch_fin[j] = ap_chars_map[index_current].char_end_form;
else
ch_fin[j] = ap_chars_map[index_current].char_end_form + ap_chars_map[index_current].char_isolated_form_offset;
idx_previous = index_current;
i++;
j++;
}
ch_fin[j] = 0;
for(i = 0; i < txt_length; i++)
ch_enc[i] = 0;
for(i = 0; i < j; i++)
ch_enc[i] = ch_fin[i];
lv_free(ch_fin);
txt_out_temp = txt_out;
i = 0;
while(i < txt_length) {
if(ch_enc[i] < 0x80) {
*(txt_out_temp++) = ch_enc[i] & 0xFF;
}
else if(ch_enc[i] < 0x0800) {
*(txt_out_temp++) = ((ch_enc[i] >> 6) & 0x1F) | 0xC0;
*(txt_out_temp++) = ((ch_enc[i] >> 0) & 0x3F) | 0x80;
}
else if(ch_enc[i] < 0x010000) {
*(txt_out_temp++) = ((ch_enc[i] >> 12) & 0x0F) | 0xE0;
*(txt_out_temp++) = ((ch_enc[i] >> 6) & 0x3F) | 0x80;
*(txt_out_temp++) = ((ch_enc[i] >> 0) & 0x3F) | 0x80;
}
else if(ch_enc[i] < 0x110000) {
*(txt_out_temp++) = ((ch_enc[i] >> 18) & 0x07) | 0xF0;
*(txt_out_temp++) = ((ch_enc[i] >> 12) & 0x3F) | 0x80;
*(txt_out_temp++) = ((ch_enc[i] >> 6) & 0x3F) | 0x80;
*(txt_out_temp++) = ((ch_enc[i] >> 0) & 0x3F) | 0x80;
}
i++;
}
*(txt_out_temp) = '\0';
lv_free(ch_enc);
}
/**********************
* STATIC FUNCTIONS
**********************/
static uint32_t lv_ap_get_char_index(uint16_t c)
{
for(uint8_t i = 0; ap_chars_map[i].char_end_form; i++) {
if(c == (ap_chars_map[i].char_offset + LV_AP_ALPHABET_BASE_CODE))
return i;
else if(c == ap_chars_map[i].char_end_form //is it an End form
|| c == (ap_chars_map[i].char_end_form + ap_chars_map[i].char_beginning_form_offset) //is it a Beginning form
|| c == (ap_chars_map[i].char_end_form + ap_chars_map[i].char_middle_form_offset) //is it a middle form
|| c == (ap_chars_map[i].char_end_form + ap_chars_map[i].char_isolated_form_offset)) { //is it an isolated form
return i;
}
}
return LV_UNDEF_ARABIC_PERSIAN_CHARS;
}
static uint32_t lv_text_lam_alef(uint32_t ch_curr, uint32_t ch_next)
{
uint32_t ch_code = 0;
if(ap_chars_map[ch_curr].char_offset != 34) {
return 0;
}
if(ch_next == LV_UNDEF_ARABIC_PERSIAN_CHARS) {
return 0;
}
ch_code = ap_chars_map[ch_next].char_offset + LV_AP_ALPHABET_BASE_CODE;
if(ch_code == 0x0622) {
return 0xFEF5; // (lam-alef) mad
}
if(ch_code == 0x0623) {
return 0xFEF7; // (lam-alef) top hamza
}
if(ch_code == 0x0625) {
return 0xFEF9; // (lam-alef) bot hamza
}
if(ch_code == 0x0627) {
return 0xFEFB; // (lam-alef) alef
}
return 0;
}
static bool lv_text_is_arabic_vowel(uint16_t c)
{
return (c >= 0x064B) && (c <= 0x0652);
}
#endif
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_cache_builtin.h | /**
* @file lv_cache_builtin.h
*
*/
#ifndef LV_CACHE_BUILTIN_H
#define LV_CACHE_BUILTIN_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lv_ll.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef struct {
uint32_t cur_size;
lv_ll_t entry_ll;
} lv_cache_builtin_dsc_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
void _lv_cache_builtin_init(void);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_CACHE_BUILTIN_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_bidi.h | /**
* @file lv_bidi.h
*
*/
#ifndef LV_BIDI_H
#define LV_BIDI_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#include <stdbool.h>
#include <stdint.h>
#include "lv_text.h"
/*********************
* DEFINES
*********************/
/*Special non printable strong characters.
*They can be inserted to texts to affect the run's direction*/
#define LV_BIDI_LRO "\xE2\x80\xAD" /*U+202D*/
#define LV_BIDI_RLO "\xE2\x80\xAE" /*U+202E*/
/**********************
* TYPEDEFS
**********************/
enum _lv_base_dir_t {
LV_BASE_DIR_LTR = 0x00,
LV_BASE_DIR_RTL = 0x01,
LV_BASE_DIR_AUTO = 0x02,
LV_BASE_DIR_NEUTRAL = 0x20,
LV_BASE_DIR_WEAK = 0x21,
};
#ifdef DOXYGEN
typedef _lv_base_dir_t lv_base_dir_t;
#else
typedef uint8_t lv_base_dir_t;
#endif /*DOXYGEN*/
/**********************
* GLOBAL PROTOTYPES
**********************/
#if LV_USE_BIDI
/**
* Convert a text to get the characters in the correct visual order according to
* Unicode Bidirectional Algorithm
* @param str_in the text to process
* @param str_out store the result here. Has the be `strlen(str_in)` length
* @param base_dir `LV_BASE_DIR_LTR` or `LV_BASE_DIR_RTL`
*/
void _lv_bidi_process(const char * str_in, char * str_out, lv_base_dir_t base_dir);
/**
* Auto-detect the direction of a text based on the first strong character
* @param txt the text to process
* @return `LV_BASE_DIR_LTR` or `LV_BASE_DIR_RTL`
*/
lv_base_dir_t _lv_bidi_detect_base_dir(const char * txt);
/**
* Get the logical position of a character in a line
* @param str_in the input string. Can be only one line.
* @param bidi_txt internally the text is bidi processed which buffer can be get here.
* If not required anymore has to freed with `lv_free()`
* Can be `NULL` is unused
* @param len length of the line in character count
* @param base_dir base direction of the text: `LV_BASE_DIR_LTR` or `LV_BASE_DIR_RTL`
* @param visual_pos the visual character position which logical position should be get
* @param is_rtl tell the char at `visual_pos` is RTL or LTR context
* @return the logical character position
*/
uint16_t _lv_bidi_get_logical_pos(const char * str_in, char ** bidi_txt, uint32_t len, lv_base_dir_t base_dir,
uint32_t visual_pos, bool * is_rtl);
/**
* Get the visual position of a character in a line
* @param str_in the input string. Can be only one line.
* @param bidi_txt internally the text is bidi processed which buffer can be get here.
* If not required anymore has to freed with `lv_free()`
* Can be `NULL` is unused
* @param len length of the line in character count
* @param base_dir base direction of the text: `LV_BASE_DIR_LTR` or `LV_BASE_DIR_RTL`
* @param logical_pos the logical character position which visual position should be get
* @param is_rtl tell the char at `logical_pos` is RTL or LTR context
* @return the visual character position
*/
uint16_t _lv_bidi_get_visual_pos(const char * str_in, char ** bidi_txt, uint16_t len, lv_base_dir_t base_dir,
uint32_t logical_pos, bool * is_rtl);
/**
* Bidi process a paragraph of text
* @param str_in the string to process
* @param str_out store the result here
* @param len length of the text
* @param base_dir base dir of the text
* @param pos_conv_out an `uint16_t` array to store the related logical position of the character.
* Can be `NULL` is unused
* @param pos_conv_len length of `pos_conv_out` in element count
*/
void _lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len, lv_base_dir_t base_dir,
uint16_t * pos_conv_out, uint16_t pos_conv_len);
/**
* Get the real text alignment from the a text alignment, base direction and a text.
* @param align LV_TEXT_ALIGN_..., write back the calculated align here (LV_TEXT_ALIGN_LEFT/RIGHT/CENTER)
* @param base_dir LV_BASE_DIR_..., write the calculated base dir here (LV_BASE_DIR_LTR/RTL)
* @param txt a text, used with LV_BASE_DIR_AUTO to determine the base direction
*/
void lv_bidi_calculate_align(lv_text_align_t * align, lv_base_dir_t * base_dir, const char * txt);
/**********************
* MACROS
**********************/
#else /*LV_USE_BIDI*/
/**
* For compatibility if LV_USE_BIDI = 0
* Get the real text alignment from the a text alignment, base direction and a text.
* @param align For LV_TEXT_ALIGN_AUTO give LV_TEXT_ALIGN_LEFT else leave unchanged, write back the calculated align here
* @param base_dir Unused
* @param txt Unused
*/
static inline void lv_bidi_calculate_align(lv_text_align_t * align, lv_base_dir_t * base_dir, const char * txt)
{
LV_UNUSED(txt);
LV_UNUSED(base_dir);
if(*align == LV_TEXT_ALIGN_AUTO) * align = LV_TEXT_ALIGN_LEFT;
}
#endif /*LV_USE_BIDI*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_BIDI_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_profiler_builtin.c | /**
* @file lv_profiler_builtin.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_profiler_builtin.h"
#include "../lvgl.h"
#include "../core/lv_global.h"
/*********************
* DEFINES
*********************/
#if LV_USE_PROFILER && LV_USE_PROFILER_BUILTIN
#define profiler_ctx LV_GLOBAL_DEFAULT()->profiler_context
#define LV_PROFILER_STR_MAX_LEN 128
#define LV_PROFILER_TICK_PER_SEC_MAX 1000000
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void default_flush_cb(const char * buf);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_profiler_builtin_config_init(lv_profiler_builtin_config_t * config)
{
LV_ASSERT_NULL(config);
lv_memzero(config, sizeof(lv_profiler_builtin_config_t));
config->buf_size = LV_PROFILER_BUILTIN_BUF_SIZE;
config->tick_per_sec = 1000;
config->tick_get_cb = lv_tick_get;
config->flush_cb = default_flush_cb;
}
void lv_profiler_builtin_init(const lv_profiler_builtin_config_t * config)
{
LV_ASSERT_NULL(config);
LV_ASSERT_NULL(config->tick_get_cb);
uint32_t num = config->buf_size / sizeof(lv_profiler_builtin_item_t);
if(num == 0) {
LV_LOG_WARN("buf_size must > %d", (int)sizeof(lv_profiler_builtin_item_t));
return;
}
if(config->tick_per_sec == 0 || config->tick_per_sec > LV_PROFILER_TICK_PER_SEC_MAX) {
LV_LOG_WARN("tick_per_sec range must be between 1~%d", LV_PROFILER_TICK_PER_SEC_MAX);
return;
}
/*Free the old item_arr memory*/
if(profiler_ctx.item_arr != NULL) {
lv_profiler_builtin_uninit();
}
lv_memzero(&profiler_ctx, sizeof(profiler_ctx));
profiler_ctx.item_arr = lv_malloc(num * sizeof(lv_profiler_builtin_item_t));
LV_ASSERT_MALLOC(profiler_ctx.item_arr);
if(profiler_ctx.item_arr == NULL) {
LV_LOG_ERROR("malloc failed for item_arr");
return;
}
profiler_ctx.item_num = num;
profiler_ctx.config = *config;
LV_LOG_INFO("init OK, item_num = %d", (int)num);
}
void lv_profiler_builtin_uninit(void)
{
LV_ASSERT_NULL(profiler_ctx.item_arr);
lv_free(profiler_ctx.item_arr);
lv_memzero(&profiler_ctx, sizeof(profiler_ctx));
}
void lv_profiler_builtin_flush(void)
{
LV_ASSERT_NULL(profiler_ctx.item_arr);
if(!profiler_ctx.config.flush_cb) {
LV_LOG_WARN("flush_cb is not registered");
return;
}
uint32_t cur = 0;
char buf[LV_PROFILER_STR_MAX_LEN];
uint32_t tick_per_sec = profiler_ctx.config.tick_per_sec;
while(cur < profiler_ctx.cur_index) {
lv_profiler_builtin_item_t * item = &profiler_ctx.item_arr[cur++];
uint32_t sec = item->tick / tick_per_sec;
uint32_t usec = (item->tick % tick_per_sec) * (LV_PROFILER_TICK_PER_SEC_MAX / tick_per_sec);
lv_snprintf(buf, sizeof(buf),
"LVGL-1 [0] %" LV_PRIu32 ".%06" LV_PRIu32 ": tracing_mark_write: %c|1|%s\n",
sec,
usec,
item->tag,
item->func);
profiler_ctx.config.flush_cb(buf);
}
}
void lv_profiler_builtin_write(const char * func, char tag)
{
LV_ASSERT_NULL(profiler_ctx.item_arr);
LV_ASSERT_NULL(func);
if(profiler_ctx.cur_index >= profiler_ctx.item_num) {
lv_profiler_builtin_flush();
profiler_ctx.cur_index = 0;
}
lv_profiler_builtin_item_t * item = &profiler_ctx.item_arr[profiler_ctx.cur_index];
item->func = func;
item->tag = tag;
item->tick = profiler_ctx.config.tick_get_cb();
profiler_ctx.cur_index++;
}
/**********************
* STATIC FUNCTIONS
**********************/
static void default_flush_cb(const char * buf)
{
LV_LOG("%s", buf);
}
#endif /*LV_USE_PROFILER_BUILTIN*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_color_op.c | /**
* @file lv_color.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_color.h"
#include "lv_log.h"
#include "../misc/lv_color.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_anim_timeline.c | /**
* @file lv_anim_timeline.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_assert.h"
#include "lv_anim_timeline.h"
#include "../stdlib/lv_mem.h"
#include "../stdlib/lv_string.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void lv_anim_timeline_virtual_exec_cb(void * var, int32_t v);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
lv_anim_timeline_t * lv_anim_timeline_create(void)
{
lv_anim_timeline_t * at = (lv_anim_timeline_t *)lv_malloc(sizeof(lv_anim_timeline_t));
LV_ASSERT_MALLOC(at);
if(at) lv_memzero(at, sizeof(lv_anim_timeline_t));
return at;
}
void lv_anim_timeline_delete(lv_anim_timeline_t * at)
{
LV_ASSERT_NULL(at);
lv_anim_timeline_stop(at);
lv_free(at->anim_dsc);
lv_free(at);
}
void lv_anim_timeline_add(lv_anim_timeline_t * at, uint32_t start_time, lv_anim_t * a)
{
LV_ASSERT_NULL(at);
at->anim_dsc_cnt++;
at->anim_dsc = lv_realloc(at->anim_dsc, at->anim_dsc_cnt * sizeof(lv_anim_timeline_dsc_t));
LV_ASSERT_MALLOC(at->anim_dsc);
at->anim_dsc[at->anim_dsc_cnt - 1].anim = *a;
at->anim_dsc[at->anim_dsc_cnt - 1].start_time = start_time;
/*Add default var and virtual exec_cb, used to delete animation.*/
if(a->var == NULL && a->exec_cb == NULL) {
at->anim_dsc[at->anim_dsc_cnt - 1].anim.var = at;
at->anim_dsc[at->anim_dsc_cnt - 1].anim.exec_cb = lv_anim_timeline_virtual_exec_cb;
}
}
uint32_t lv_anim_timeline_start(lv_anim_timeline_t * at)
{
LV_ASSERT_NULL(at);
const uint32_t playtime = lv_anim_timeline_get_playtime(at);
bool reverse = at->reverse;
for(uint32_t i = 0; i < at->anim_dsc_cnt; i++) {
lv_anim_t a = at->anim_dsc[i].anim;
uint32_t start_time = at->anim_dsc[i].start_time;
if(reverse) {
int32_t temp = a.start_value;
a.start_value = a.end_value;
a.end_value = temp;
lv_anim_set_delay(&a, playtime - (start_time + a.time));
}
else {
lv_anim_set_delay(&a, start_time);
}
lv_anim_start(&a);
}
return playtime;
}
void lv_anim_timeline_stop(lv_anim_timeline_t * at)
{
LV_ASSERT_NULL(at);
for(uint32_t i = 0; i < at->anim_dsc_cnt; i++) {
lv_anim_t * a = &(at->anim_dsc[i].anim);
lv_anim_delete(a->var, a->exec_cb);
}
}
void lv_anim_timeline_set_reverse(lv_anim_timeline_t * at, bool reverse)
{
LV_ASSERT_NULL(at);
at->reverse = reverse;
}
void lv_anim_timeline_set_progress(lv_anim_timeline_t * at, uint16_t progress)
{
LV_ASSERT_NULL(at);
const uint32_t playtime = lv_anim_timeline_get_playtime(at);
const uint32_t act_time = progress * playtime / 0xFFFF;
for(uint32_t i = 0; i < at->anim_dsc_cnt; i++) {
lv_anim_t * a = &(at->anim_dsc[i].anim);
if(a->exec_cb == NULL) {
continue;
}
uint32_t start_time = at->anim_dsc[i].start_time;
int32_t value = 0;
if(act_time < start_time) {
value = a->start_value;
}
else if(act_time < (start_time + a->time)) {
a->act_time = act_time - start_time;
value = a->path_cb(a);
}
else {
value = a->end_value;
}
a->exec_cb(a->var, value);
}
}
uint32_t lv_anim_timeline_get_playtime(lv_anim_timeline_t * at)
{
LV_ASSERT_NULL(at);
uint32_t playtime = 0;
for(uint32_t i = 0; i < at->anim_dsc_cnt; i++) {
uint32_t end = lv_anim_get_playtime(&at->anim_dsc[i].anim);
if(end == LV_ANIM_PLAYTIME_INFINITE)
return end;
end += at->anim_dsc[i].start_time;
if(end > playtime) {
playtime = end;
}
}
return playtime;
}
bool lv_anim_timeline_get_reverse(lv_anim_timeline_t * at)
{
LV_ASSERT_NULL(at);
return at->reverse;
}
/**********************
* STATIC FUNCTIONS
**********************/
static void lv_anim_timeline_virtual_exec_cb(void * var, int32_t v)
{
LV_UNUSED(var);
LV_UNUSED(v);
}
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_cache.c | /**
* @file lv_cache.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_cache.h"
#include "../stdlib/lv_string.h"
#include "../osal/lv_os.h"
#include "../core/lv_global.h"
/*********************
* DEFINES
*********************/
#define _cache_manager LV_GLOBAL_DEFAULT()->cache_manager
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void _lv_cache_init(void)
{
lv_memzero(&_cache_manager, sizeof(lv_cache_manager_t));
lv_mutex_init(&_cache_manager.mutex);
}
void lv_cache_set_manager(lv_cache_manager_t * manager)
{
LV_ASSERT(_cache_manager.locked);
if(manager == NULL) return;
if(_cache_manager.empty_cb != NULL) _cache_manager.empty_cb();
else if(_cache_manager.set_max_size_cb != NULL) _cache_manager.set_max_size_cb(0);
_cache_manager.add_cb = manager->add_cb;
_cache_manager.find_cb = manager->find_cb;
_cache_manager.invalidate_cb = manager->invalidate_cb;
_cache_manager.get_data_cb = manager->get_data_cb;
_cache_manager.release_cb = manager->release_cb;
_cache_manager.set_max_size_cb = manager->set_max_size_cb;
_cache_manager.empty_cb = manager->empty_cb;
if(_cache_manager.set_max_size_cb != NULL) _cache_manager.set_max_size_cb(_cache_manager.max_size);
}
lv_cache_entry_t * lv_cache_add(size_t size)
{
LV_ASSERT(_cache_manager.locked);
if(_cache_manager.add_cb == NULL) return NULL;
return _cache_manager.add_cb(size);
}
lv_cache_entry_t * lv_cache_find(const void * src_ptr, lv_cache_src_type_t src_type, uint32_t param1, uint32_t param2)
{
LV_ASSERT(_cache_manager.locked);
if(_cache_manager.find_cb == NULL) return NULL;
return _cache_manager.find_cb(src_ptr, src_type, param1, param2);
}
void lv_cache_invalidate(lv_cache_entry_t * entry)
{
LV_ASSERT(_cache_manager.locked);
if(_cache_manager.invalidate_cb == NULL) return;
_cache_manager.invalidate_cb(entry);
}
const void * lv_cache_get_data(lv_cache_entry_t * entry)
{
LV_ASSERT(_cache_manager.locked);
if(_cache_manager.get_data_cb == NULL) return NULL;
const void * data = _cache_manager.get_data_cb(entry);
return data;
}
void lv_cache_release(lv_cache_entry_t * entry)
{
LV_ASSERT(_cache_manager.locked);
if(_cache_manager.release_cb == NULL) return;
_cache_manager.release_cb(entry);
}
void lv_cache_set_max_size(size_t size)
{
LV_ASSERT(_cache_manager.locked);
if(_cache_manager.set_max_size_cb == NULL) return;
_cache_manager.set_max_size_cb(size);
_cache_manager.max_size = size;
}
size_t lv_cache_get_max_size(void)
{
return _cache_manager.max_size;
}
void lv_cache_lock(void)
{
lv_mutex_lock(&_cache_manager.mutex);
_cache_manager.locked = 1;
}
void lv_cache_unlock(void)
{
_cache_manager.locked = 0;
lv_mutex_unlock(&_cache_manager.mutex);
}
/**********************
* STATIC FUNCTIONS
**********************/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_math.h | /**
* @file lv_math.h
*
*/
#ifndef LV_MATH_H
#define LV_MATH_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#include <stdint.h>
#include "lv_types.h"
/*********************
* DEFINES
*********************/
#define LV_TRIGO_SIN_MAX 32768
#define LV_TRIGO_SHIFT 15 /**< >> LV_TRIGO_SHIFT to normalize*/
#define LV_BEZIER_VAL_SHIFT 10 /**< log2(LV_BEZIER_VAL_MAX): used to normalize up scaled values*/
#define LV_BEZIER_VAL_MAX (1L << LV_BEZIER_VAL_SHIFT) /**< Max time in Bezier functions (not [0..1] to use integers)*/
#define LV_BEZIER_VAL_FLOAT(f) ((int32_t)((f) * LV_BEZIER_VAL_MAX)) /**< Convert const float number cubic-bezier values to fix-point value*/
/**********************
* TYPEDEFS
**********************/
typedef struct {
uint16_t i;
uint16_t f;
} lv_sqrt_res_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
//! @cond Doxygen_Suppress
/**
* Return with sinus of an angle
* @param angle
* @return sinus of 'angle'. sin(-90) = -32767, sin(90) = 32767
*/
LV_ATTRIBUTE_FAST_MEM int32_t lv_trigo_sin(int16_t angle);
static inline LV_ATTRIBUTE_FAST_MEM int32_t lv_trigo_cos(int16_t angle)
{
return lv_trigo_sin(angle + 90);
}
//! @endcond
/**
* Calculate the y value of cubic-bezier(x1, y1, x2, y2) function as specified x.
* @param x time in range of [0..LV_BEZIER_VAL_MAX]
* @param x1 x of control point 1 in range of [0..LV_BEZIER_VAL_MAX]
* @param y1 y of control point 1 in range of [0..LV_BEZIER_VAL_MAX]
* @param x2 x of control point 2 in range of [0..LV_BEZIER_VAL_MAX]
* @param y2 y of control point 2 in range of [0..LV_BEZIER_VAL_MAX]
* @return the value calculated
*/
int32_t lv_cubic_bezier(int32_t x, int32_t x1, int32_t y1, int32_t x2, int32_t y2);
/**
* Calculate a value of a Cubic Bezier function.
* @param t time in range of [0..LV_BEZIER_VAL_MAX]
* @param u0 must be 0
* @param u1 control value 1 values in range of [0..LV_BEZIER_VAL_MAX]
* @param u2 control value 2 in range of [0..LV_BEZIER_VAL_MAX]
* @param u3 must be LV_BEZIER_VAL_MAX
* @return the value calculated from the given parameters in range of [0..LV_BEZIER_VAL_MAX]
*/
static inline int32_t lv_bezier3(int32_t t, int32_t u0, uint32_t u1, int32_t u2, int32_t u3)
{
LV_UNUSED(u0);
LV_UNUSED(u3);
return lv_cubic_bezier(t, 341, u1, 683, u2);
}
/**
* Calculate the atan2 of a vector.
* @param x
* @param y
* @return the angle in degree calculated from the given parameters in range of [0..360]
*/
uint16_t lv_atan2(int x, int y);
//! @cond Doxygen_Suppress
/**
* Get the square root of a number
* @param x integer which square root should be calculated
* @param q store the result here. q->i: integer part, q->f: fractional part in 1/256 unit
* @param mask optional to skip some iterations if the magnitude of the root is known.
* Set to 0x8000 by default.
* If root < 16: mask = 0x80
* If root < 256: mask = 0x800
* Else: mask = 0x8000
*/
LV_ATTRIBUTE_FAST_MEM void lv_sqrt(uint32_t x, lv_sqrt_res_t * q, uint32_t mask);
//! @endcond
/**
* Calculate the integer exponents.
* @param base
* @param exp
* @return base raised to the power exponent
*/
int64_t lv_pow(int64_t base, int8_t exp);
/**
* Get the mapped of a number given an input and output range
* @param x integer which mapped value should be calculated
* @param min_in min input range
* @param max_in max input range
* @param min_out max output range
* @param max_out max output range
* @return the mapped number
*/
int32_t lv_map(int32_t x, int32_t min_in, int32_t max_in, int32_t min_out, int32_t max_out);
/**
* Get a pseudo random number in the given range
* @param min the minimum value
* @param max the maximum value
* @return return the random number. min <= return_value <= max
*/
uint32_t lv_rand(uint32_t min, uint32_t max);
/**********************
* MACROS
**********************/
#define LV_MIN(a, b) ((a) < (b) ? (a) : (b))
#define LV_MIN3(a, b, c) (LV_MIN(LV_MIN(a,b), c))
#define LV_MIN4(a, b, c, d) (LV_MIN(LV_MIN(a,b), LV_MIN(c,d)))
#define LV_MAX(a, b) ((a) > (b) ? (a) : (b))
#define LV_MAX3(a, b, c) (LV_MAX(LV_MAX(a,b), c))
#define LV_MAX4(a, b, c, d) (LV_MAX(LV_MAX(a,b), LV_MAX(c,d)))
#define LV_CLAMP(min, val, max) (LV_MAX(min, (LV_MIN(val, max))))
#define LV_ABS(x) ((x) > 0 ? (x) : (-(x)))
#define LV_UDIV255(x) (((x) * 0x8081U) >> 0x17)
#define LV_IS_SIGNED(t) (((t)(-1)) < ((t)0))
#define LV_UMAX_OF(t) (((0x1ULL << ((sizeof(t) * 8ULL) - 1ULL)) - 1ULL) | (0xFULL << ((sizeof(t) * 8ULL) - 4ULL)))
#define LV_SMAX_OF(t) (((0x1ULL << ((sizeof(t) * 8ULL) - 1ULL)) - 1ULL) | (0x7ULL << ((sizeof(t) * 8ULL) - 4ULL)))
#define LV_MAX_OF(t) ((unsigned long)(LV_IS_SIGNED(t) ? LV_SMAX_OF(t) : LV_UMAX_OF(t)))
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_anim.c | /**
* @file lv_anim.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_anim.h"
#include "../core/lv_global.h"
#include "../tick/lv_tick.h"
#include "lv_assert.h"
#include "lv_timer.h"
#include "lv_math.h"
#include "../stdlib/lv_mem.h"
#include "../stdlib/lv_string.h"
/*********************
* DEFINES
*********************/
#define LV_ANIM_RESOLUTION 1024
#define LV_ANIM_RES_SHIFT 10
#define state LV_GLOBAL_DEFAULT()->anim_state
#define anim_ll_p &(state.anim_ll)
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void anim_timer(lv_timer_t * param);
static void anim_mark_list_change(void);
static void anim_ready_handler(lv_anim_t * a);
static int32_t lv_anim_path_cubic_bezier(const lv_anim_t * a, int32_t x1,
int32_t y1, int32_t x2, int32_t y2);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
#if LV_USE_LOG && LV_LOG_TRACE_ANIM
#define LV_TRACE_ANIM(...) LV_LOG_TRACE(__VA_ARGS__)
#else
#define LV_TRACE_ANIM(...)
#endif
/**********************
* GLOBAL FUNCTIONS
**********************/
void _lv_anim_core_init(void)
{
_lv_ll_init(anim_ll_p, sizeof(lv_anim_t));
state.timer = lv_timer_create(anim_timer, LV_DEF_REFR_PERIOD, NULL);
anim_mark_list_change(); /*Turn off the animation timer*/
state.anim_list_changed = false;
state.anim_run_round = false;
}
void lv_anim_init(lv_anim_t * a)
{
lv_memzero(a, sizeof(lv_anim_t));
a->time = 500;
a->start_value = 0;
a->end_value = 100;
a->repeat_cnt = 1;
a->path_cb = lv_anim_path_linear;
a->early_apply = 1;
}
lv_anim_t * lv_anim_start(const lv_anim_t * a)
{
LV_TRACE_ANIM("begin");
/*Do not let two animations for the same 'var' with the same 'exec_cb'*/
if(a->exec_cb != NULL) lv_anim_delete(a->var, a->exec_cb); /*exec_cb == NULL would delete all animations of var*/
/*Add the new animation to the animation linked list*/
lv_anim_t * new_anim = _lv_ll_ins_head(anim_ll_p);
LV_ASSERT_MALLOC(new_anim);
if(new_anim == NULL) return NULL;
/*Initialize the animation descriptor*/
lv_memcpy(new_anim, a, sizeof(lv_anim_t));
if(a->var == a) new_anim->var = new_anim;
new_anim->run_round = state.anim_run_round;
new_anim->last_timer_run = lv_tick_get();
/*Set the start value*/
if(new_anim->early_apply) {
if(new_anim->get_value_cb) {
int32_t v_ofs = new_anim->get_value_cb(new_anim);
new_anim->start_value += v_ofs;
new_anim->end_value += v_ofs;
}
if(new_anim->exec_cb && new_anim->var) new_anim->exec_cb(new_anim->var, new_anim->start_value);
}
/*Creating an animation changed the linked list.
*It's important if it happens in a ready callback. (see `anim_timer`)*/
anim_mark_list_change();
LV_TRACE_ANIM("finished");
return new_anim;
}
uint32_t lv_anim_get_playtime(lv_anim_t * a)
{
uint32_t playtime = LV_ANIM_PLAYTIME_INFINITE;
if(a->repeat_cnt == LV_ANIM_REPEAT_INFINITE)
return playtime;
playtime = a->time - a->act_time;
if(a->playback_now == 0)
playtime += a->playback_delay + a->playback_time;
if(a->repeat_cnt <= 1)
return playtime;
playtime += (a->repeat_delay + a->time +
a->playback_delay + a->playback_time) *
(a->repeat_cnt - 1);
return playtime;
}
bool lv_anim_delete(void * var, lv_anim_exec_xcb_t exec_cb)
{
lv_anim_t * a;
bool del_any = false;
a = _lv_ll_get_head(anim_ll_p);
while(a != NULL) {
bool del = false;
if((a->var == var || var == NULL) && (a->exec_cb == exec_cb || exec_cb == NULL)) {
_lv_ll_remove(anim_ll_p, a);
if(a->deleted_cb != NULL) a->deleted_cb(a);
lv_free(a);
anim_mark_list_change(); /*Read by `anim_timer`. It need to know if a delete occurred in
the linked list*/
del_any = true;
del = true;
}
/*Always start from the head on delete, because we don't know
*how `anim_ll_p` was changes in `a->deleted_cb` */
a = del ? _lv_ll_get_head(anim_ll_p) : _lv_ll_get_next(anim_ll_p, a);
}
return del_any;
}
void lv_anim_delete_all(void)
{
_lv_ll_clear(anim_ll_p);
anim_mark_list_change();
}
lv_anim_t * lv_anim_get(void * var, lv_anim_exec_xcb_t exec_cb)
{
lv_anim_t * a;
_LV_LL_READ(anim_ll_p, a) {
if(a->var == var && (a->exec_cb == exec_cb || exec_cb == NULL)) {
return a;
}
}
return NULL;
}
struct _lv_timer_t * lv_anim_get_timer(void)
{
return state.timer;
}
uint16_t lv_anim_count_running(void)
{
uint16_t cnt = 0;
lv_anim_t * a;
_LV_LL_READ(anim_ll_p, a) cnt++;
return cnt;
}
uint32_t lv_anim_speed_to_time(uint32_t speed, int32_t start, int32_t end)
{
uint32_t d = LV_ABS(start - end);
uint32_t time = (d * 1000) / speed;
if(time == 0) {
time++;
}
return time;
}
void lv_anim_refr_now(void)
{
anim_timer(NULL);
}
int32_t lv_anim_path_linear(const lv_anim_t * a)
{
/*Calculate the current step*/
int32_t step = lv_map(a->act_time, 0, a->time, 0, LV_ANIM_RESOLUTION);
/*Get the new value which will be proportional to `step`
*and the `start` and `end` values*/
int32_t new_value;
new_value = step * (a->end_value - a->start_value);
new_value = new_value >> LV_ANIM_RES_SHIFT;
new_value += a->start_value;
return new_value;
}
int32_t lv_anim_path_ease_in(const lv_anim_t * a)
{
return lv_anim_path_cubic_bezier(a, LV_BEZIER_VAL_FLOAT(0.42), LV_BEZIER_VAL_FLOAT(0),
LV_BEZIER_VAL_FLOAT(1), LV_BEZIER_VAL_FLOAT(1));
}
int32_t lv_anim_path_ease_out(const lv_anim_t * a)
{
return lv_anim_path_cubic_bezier(a, LV_BEZIER_VAL_FLOAT(0), LV_BEZIER_VAL_FLOAT(0),
LV_BEZIER_VAL_FLOAT(0.58), LV_BEZIER_VAL_FLOAT(1));
}
int32_t lv_anim_path_ease_in_out(const lv_anim_t * a)
{
return lv_anim_path_cubic_bezier(a, LV_BEZIER_VAL_FLOAT(0.42), LV_BEZIER_VAL_FLOAT(0),
LV_BEZIER_VAL_FLOAT(0.58), LV_BEZIER_VAL_FLOAT(1));
}
int32_t lv_anim_path_overshoot(const lv_anim_t * a)
{
return lv_anim_path_cubic_bezier(a, 341, 0, 683, 1300);
}
int32_t lv_anim_path_bounce(const lv_anim_t * a)
{
/*Calculate the current step*/
int32_t t = lv_map(a->act_time, 0, a->time, 0, LV_BEZIER_VAL_MAX);
int32_t diff = (a->end_value - a->start_value);
/*3 bounces has 5 parts: 3 down and 2 up. One part is t / 5 long*/
if(t < 408) {
/*Go down*/
t = (t * 2500) >> LV_BEZIER_VAL_SHIFT; /*[0..1024] range*/
}
else if(t >= 408 && t < 614) {
/*First bounce back*/
t -= 408;
t = t * 5; /*to [0..1024] range*/
t = LV_BEZIER_VAL_MAX - t;
diff = diff / 20;
}
else if(t >= 614 && t < 819) {
/*Fall back*/
t -= 614;
t = t * 5; /*to [0..1024] range*/
diff = diff / 20;
}
else if(t >= 819 && t < 921) {
/*Second bounce back*/
t -= 819;
t = t * 10; /*to [0..1024] range*/
t = LV_BEZIER_VAL_MAX - t;
diff = diff / 40;
}
else if(t >= 921 && t <= LV_BEZIER_VAL_MAX) {
/*Fall back*/
t -= 921;
t = t * 10; /*to [0..1024] range*/
diff = diff / 40;
}
if(t > LV_BEZIER_VAL_MAX) t = LV_BEZIER_VAL_MAX;
if(t < 0) t = 0;
int32_t step = lv_bezier3(t, LV_BEZIER_VAL_MAX, 800, 500, 0);
int32_t new_value;
new_value = step * diff;
new_value = new_value >> LV_BEZIER_VAL_SHIFT;
new_value = a->end_value - new_value;
return new_value;
}
int32_t lv_anim_path_step(const lv_anim_t * a)
{
if(a->act_time >= a->time)
return a->end_value;
else
return a->start_value;
}
int32_t lv_anim_path_custom_bezier3(const lv_anim_t * a)
{
const struct _lv_anim_bezier3_para_t * para = &a->parameter.bezier3;
return lv_anim_path_cubic_bezier(a, para->x1, para->y1, para->x2, para->y2);
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Periodically handle the animations.
* @param param unused
*/
static void anim_timer(lv_timer_t * param)
{
LV_UNUSED(param);
/*Flip the run round*/
state.anim_run_round = state.anim_run_round ? false : true;
lv_anim_t * a = _lv_ll_get_head(anim_ll_p);
while(a != NULL) {
uint32_t elaps = lv_tick_elaps(a->last_timer_run);
a->last_timer_run = lv_tick_get();
/*It can be set by `lv_anim_delete()` typically in `end_cb`. If set then an animation delete
* happened in `anim_ready_handler` which could make this linked list reading corrupt
* because the list is changed meanwhile
*/
state.anim_list_changed = false;
if(a->run_round != state.anim_run_round) {
a->run_round = state.anim_run_round; /*The list readying might be reset so need to know which anim has run already*/
/*The animation will run now for the first time. Call `start_cb`*/
int32_t new_act_time = a->act_time + elaps;
if(!a->start_cb_called && a->act_time <= 0 && new_act_time >= 0) {
if(a->early_apply == 0 && a->get_value_cb) {
int32_t v_ofs = a->get_value_cb(a);
a->start_value += v_ofs;
a->end_value += v_ofs;
}
if(a->start_cb) a->start_cb(a);
a->start_cb_called = 1;
}
a->act_time += elaps;
if(a->act_time >= 0) {
if(a->act_time > a->time) a->act_time = a->time;
int32_t new_value;
new_value = a->path_cb(a);
if(new_value != a->current_value) {
a->current_value = new_value;
/*Apply the calculated value*/
if(a->exec_cb) a->exec_cb(a->var, new_value);
}
/*If the time is elapsed the animation is ready*/
if(a->act_time >= a->time) {
anim_ready_handler(a);
}
}
}
/*If the linked list changed due to anim. delete then it's not safe to continue
*the reading of the list from here -> start from the head*/
if(state.anim_list_changed)
a = _lv_ll_get_head(anim_ll_p);
else
a = _lv_ll_get_next(anim_ll_p, a);
}
}
/**
* Called when an animation is ready to do the necessary thinks
* e.g. repeat, play back, delete etc.
* @param a pointer to an animation descriptor
*/
static void anim_ready_handler(lv_anim_t * a)
{
/*In the end of a forward anim decrement repeat cnt.*/
if(a->playback_now == 0 && a->repeat_cnt > 0 && a->repeat_cnt != LV_ANIM_REPEAT_INFINITE) {
a->repeat_cnt--;
}
/*Delete the animation if
* - no repeat left and no play back (simple one shot animation)
* - no repeat, play back is enabled and play back is ready*/
if(a->repeat_cnt == 0 && (a->playback_time == 0 || a->playback_now == 1)) {
/*Delete the animation from the list.
* This way the `ready_cb` will see the animations like it's animation is ready deleted*/
_lv_ll_remove(anim_ll_p, a);
/*Flag that the list has changed*/
anim_mark_list_change();
/*Call the callback function at the end*/
if(a->ready_cb != NULL) a->ready_cb(a);
if(a->deleted_cb != NULL) a->deleted_cb(a);
lv_free(a);
}
/*If the animation is not deleted then restart it*/
else {
a->act_time = -(int32_t)(a->repeat_delay); /*Restart the animation*/
/*Swap the start and end values in play back mode*/
if(a->playback_time != 0) {
/*If now turning back use the 'playback_pause*/
if(a->playback_now == 0) a->act_time = -(int32_t)(a->playback_delay);
/*Toggle the play back state*/
a->playback_now = a->playback_now == 0 ? 1 : 0;
/*Swap the start and end values*/
int32_t tmp = a->start_value;
a->start_value = a->end_value;
a->end_value = tmp;
/*Swap the time and playback_time*/
tmp = a->time;
a->time = a->playback_time;
a->playback_time = tmp;
}
}
}
static void anim_mark_list_change(void)
{
state.anim_list_changed = true;
if(_lv_ll_get_head(anim_ll_p) == NULL)
lv_timer_pause(state.timer);
else
lv_timer_resume(state.timer);
}
static int32_t lv_anim_path_cubic_bezier(const lv_anim_t * a, int32_t x1, int32_t y1, int32_t x2, int32_t y2)
{
/*Calculate the current step*/
uint32_t t = lv_map(a->act_time, 0, a->time, 0, LV_BEZIER_VAL_MAX);
int32_t step = lv_cubic_bezier(t, x1, y1, x2, y2);
int32_t new_value;
new_value = step * (a->end_value - a->start_value);
new_value = new_value >> LV_BEZIER_VAL_SHIFT;
new_value += a->start_value;
return new_value;
}
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_timer.h | /**
* @file lv_timer.h
*/
#ifndef LV_TIMER_H
#define LV_TIMER_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#include "../tick/lv_tick.h"
#include "lv_ll.h"
#include <stdint.h>
#include <stdbool.h>
/*********************
* DEFINES
*********************/
#ifndef LV_ATTRIBUTE_TIMER_HANDLER
#define LV_ATTRIBUTE_TIMER_HANDLER
#endif
#define LV_NO_TIMER_READY 0xFFFFFFFF
/**********************
* TYPEDEFS
**********************/
struct _lv_timer_t;
/**
* Timers execute this type of functions.
*/
typedef void (*lv_timer_cb_t)(struct _lv_timer_t *);
/**
* Timer handler resume this type of function.
*/
typedef void (*lv_timer_handler_resume_cb_t)(void * data);
/**
* Descriptor of a lv_timer
*/
typedef struct _lv_timer_t {
uint32_t period; /**< How often the timer should run*/
uint32_t last_run; /**< Last time the timer ran*/
lv_timer_cb_t timer_cb; /**< Timer function*/
void * user_data; /**< Custom user data*/
int32_t repeat_count; /**< 1: One time; -1 : infinity; n>0: residual times*/
uint32_t paused : 1;
uint32_t auto_delete : 1;
} lv_timer_t;
typedef struct {
lv_ll_t timer_ll; /*Linked list to store the lv_timers*/
bool lv_timer_run;
uint8_t idle_last;
bool timer_deleted;
bool timer_created;
uint32_t timer_time_until_next;
bool already_running;
uint32_t periodic_last_tick;
uint32_t busy_time;
uint32_t idle_period_start;
uint32_t run_cnt;
lv_timer_handler_resume_cb_t resume_cb;
void * resume_data;
} lv_timer_state_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Init the lv_timer module
*/
void _lv_timer_core_init(void);
//! @cond Doxygen_Suppress
/**
* Call it periodically to handle lv_timers.
* @return time till it needs to be run next (in ms)
*/
LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler(void);
//! @endcond
/**
* Call it in the super-loop of main() or threads. It will run lv_timer_handler()
* with a given period in ms. You can use it with sleep or delay in OS environment.
* This function is used to simplify the porting.
* @param period the period for running lv_timer_handler()
* @return the time after which it must be called again
*/
static inline LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler_run_in_period(uint32_t period)
{
static uint32_t last_tick = 0;
if(lv_tick_elaps(last_tick) >= period) {
last_tick = lv_tick_get();
return lv_timer_handler();
}
return 1;
}
/**
* Call it in the super-loop of main() or threads. It will automatically call lv_timer_handler() at the right time.
* This function is used to simplify the porting.
*/
LV_ATTRIBUTE_TIMER_HANDLER void lv_timer_periodic_handler(void);
/**
* Set the resume callback to the timer handler
* @param cb the function to call when timer handler is resumed
* @param data pointer to a resume data
*/
void lv_timer_handler_set_resume_cb(lv_timer_handler_resume_cb_t cb, void * data);
/**
* Create an "empty" timer. It needs to be initialized with at least
* `lv_timer_set_cb` and `lv_timer_set_period`
* @return pointer to the created timer
*/
lv_timer_t * lv_timer_create_basic(void);
/**
* Create a new lv_timer
* @param timer_xcb a callback to call periodically.
* (the 'x' in the argument name indicates that it's not a fully generic function because it not follows
* the `func_name(object, callback, ...)` convention)
* @param period call period in ms unit
* @param user_data custom parameter
* @return pointer to the new timer
*/
lv_timer_t * lv_timer_create(lv_timer_cb_t timer_xcb, uint32_t period, void * user_data);
/**
* Delete a lv_timer
* @param timer pointer to an lv_timer
*/
void lv_timer_delete(lv_timer_t * timer);
/**
* Pause a timer.
* @param timer pointer to an lv_timer
*/
void lv_timer_pause(lv_timer_t * timer);
/**
* Resume a timer.
* @param timer pointer to an lv_timer
*/
void lv_timer_resume(lv_timer_t * timer);
/**
* Set the callback to the timer (the function to call periodically)
* @param timer pointer to a timer
* @param timer_cb the function to call periodically
*/
void lv_timer_set_cb(lv_timer_t * timer, lv_timer_cb_t timer_cb);
/**
* Set new period for a lv_timer
* @param timer pointer to a lv_timer
* @param period the new period
*/
void lv_timer_set_period(lv_timer_t * timer, uint32_t period);
/**
* Make a lv_timer ready. It will not wait its period.
* @param timer pointer to a lv_timer.
*/
void lv_timer_ready(lv_timer_t * timer);
/**
* Set the number of times a timer will repeat.
* @param timer pointer to a lv_timer.
* @param repeat_count -1 : infinity; 0 : stop ; n>0: residual times
*/
void lv_timer_set_repeat_count(lv_timer_t * timer, int32_t repeat_count);
/**
* Set whether a lv_timer will be deleted automatically when it is called `repeat_count` times.
* @param timer pointer to a lv_timer.
* @param auto_delete true: auto delete; false: timer will be paused when it is called `repeat_count` times.
*/
void lv_timer_set_auto_delete(lv_timer_t * timer, bool auto_delete);
/**
* Set custom parameter to the lv_timer.
* @param timer pointer to a lv_timer.
* @param user_data custom parameter
*/
void lv_timer_set_user_data(lv_timer_t * timer, void * user_data);
/**
* Reset a lv_timer.
* It will be called the previously set period milliseconds later.
* @param timer pointer to a lv_timer.
*/
void lv_timer_reset(lv_timer_t * timer);
/**
* Enable or disable the whole lv_timer handling
* @param en true: lv_timer handling is running, false: lv_timer handling is suspended
*/
void lv_timer_enable(bool en);
/**
* Get idle percentage
* @return the lv_timer idle in percentage
*/
uint8_t lv_timer_get_idle(void);
/**
* Get the time remaining until the next timer will run
* @return the time remaining in ms
*/
uint32_t lv_timer_get_time_until_next(void);
/**
* Iterate through the timers
* @param timer NULL to start iteration or the previous return value to get the next timer
* @return the next timer or NULL if there is no more timer
*/
lv_timer_t * lv_timer_get_next(lv_timer_t * timer);
/**
* Get the user_data passed when the timer was created
* @param timer pointer to the lv_timer
* @return pointer to the user_data
*/
static inline void * lv_timer_get_user_data(lv_timer_t * timer)
{
return timer->user_data;
}
/**
* Get the pause state of a timer
* @param timer pointer to a lv_timer
* @return true: timer is paused; false: timer is running
*/
static inline bool lv_timer_get_paused(lv_timer_t * timer)
{
return timer->paused;
}
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_palette.h | /**
* @file lv_palette.h
*
*/
#ifndef LV_PALETTE_H
#define LV_PALETTE_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lv_color.h"
#include <stdint.h>
#include <stdbool.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef enum {
LV_PALETTE_RED,
LV_PALETTE_PINK,
LV_PALETTE_PURPLE,
LV_PALETTE_DEEP_PURPLE,
LV_PALETTE_INDIGO,
LV_PALETTE_BLUE,
LV_PALETTE_LIGHT_BLUE,
LV_PALETTE_CYAN,
LV_PALETTE_TEAL,
LV_PALETTE_GREEN,
LV_PALETTE_LIGHT_GREEN,
LV_PALETTE_LIME,
LV_PALETTE_YELLOW,
LV_PALETTE_AMBER,
LV_PALETTE_ORANGE,
LV_PALETTE_DEEP_ORANGE,
LV_PALETTE_BROWN,
LV_PALETTE_BLUE_GREY,
LV_PALETTE_GREY,
_LV_PALETTE_LAST,
LV_PALETTE_NONE = 0xff,
} lv_palette_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/*Source: https://vuetifyjs.com/en/styles/colors/#material-colors*/
lv_color_t lv_palette_main(lv_palette_t p);
lv_color_t lv_palette_lighten(lv_palette_t p, uint8_t lvl);
lv_color_t lv_palette_darken(lv_palette_t p, uint8_t lvl);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_PALETTE_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_templ.h | /**
* @file lv_templ.h
*
*/
#ifndef LV_TEMPL_H
#define LV_TEMPL_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_TEMPL_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_lru.h | /**
* @file lv_lru.h
*
*/
#ifndef LV_LRU_H
#define LV_LRU_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#include "lv_types.h"
#include <stdint.h>
#include <stddef.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef enum {
LV_LRU_OK = 0,
LV_LRU_MISSING_CACHE,
LV_LRU_MISSING_KEY,
LV_LRU_MISSING_VALUE,
LV_LRU_LOCK_ERROR,
LV_LRU_VALUE_TOO_LARGE
} lv_lru_res_t;
typedef void (*lv_lru_free_cb_t)(void * v);
typedef struct _lv_lru_item_t lv_lru_item_t;
typedef struct /// @cond
/**
* Tells Doxygen to ignore a duplicate declaration
*/
lv_lru_t
/// @endcond
{
lv_lru_item_t ** items;
uint64_t access_count;
size_t free_memory;
size_t total_memory;
size_t average_item_length;
size_t hash_table_size;
uint32_t seed;
lv_lru_free_cb_t value_free;
lv_lru_free_cb_t key_free;
lv_lru_item_t * free_items;
} lv_lru_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
lv_lru_t * lv_lru_create(size_t cache_size, size_t average_length, lv_lru_free_cb_t value_free,
lv_lru_free_cb_t key_free);
void lv_lru_delete(lv_lru_t * cache);
lv_lru_res_t lv_lru_set(lv_lru_t * cache, const void * key, size_t key_length, void * value, size_t value_length);
lv_lru_res_t lv_lru_get(lv_lru_t * cache, const void * key, size_t key_size, void ** value);
lv_lru_res_t lv_lru_remove(lv_lru_t * cache, const void * key, size_t key_size);
/**
* remove the least recently used item
*
* @todo we can optimise this by finding the n lru items, where n = required_space / average_length
*/
void lv_lru_remove_lru_item(lv_lru_t * cache);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_LRU_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_lru.c | /**
* @file lv_lru.c
*
* @see https://github.com/willcannings/C-LRU-Cache
*/
/*********************
* INCLUDES
*********************/
#include "lv_lru.h"
#include "lv_math.h"
#include "../stdlib/lv_mem.h"
#include "../stdlib/lv_string.h"
#include "lv_assert.h"
#include "lv_log.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
struct _lv_lru_item_t {
void * value;
void * key;
size_t value_length;
size_t key_length;
uint64_t access_count;
struct _lv_lru_item_t * next;
};
/**********************
* STATIC PROTOTYPES
**********************/
/**
* MurmurHash2
* @author Austin Appleby
* @see http://sites.google.com/site/murmurhash/
*/
static uint32_t lv_lru_hash(lv_lru_t * cache, const void * key, uint32_t key_length);
/** compare a key against an existing item's key */
static int lv_lru_cmp_keys(lv_lru_item_t * item, const void * key, uint32_t key_length);
/** remove an item and push it to the free items queue */
static void lv_lru_remove_item(lv_lru_t * cache, lv_lru_item_t * prev, lv_lru_item_t * item, uint32_t hash_index);
/** pop an existing item off the free queue, or create a new one */
static lv_lru_item_t * lv_lru_pop_or_create_item(lv_lru_t * cache);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/* error helpers */
#define error_for(conditions, error) if(conditions) {return error;}
#define test_for_missing_cache() error_for(!cache, LV_LRU_MISSING_CACHE)
#define test_for_missing_key() error_for(!key, LV_LRU_MISSING_KEY)
#define test_for_missing_value() error_for(!value || value_length == 0, LV_LRU_MISSING_VALUE)
#define test_for_value_too_large() error_for(value_length > cache->total_memory, LV_LRU_VALUE_TOO_LARGE)
/**********************
* GLOBAL FUNCTIONS
**********************/
lv_lru_t * lv_lru_create(size_t cache_size, size_t average_length, lv_lru_free_cb_t value_free,
lv_lru_free_cb_t key_free)
{
// create the cache
lv_lru_t * cache = (lv_lru_t *) lv_malloc(sizeof(lv_lru_t));
lv_memzero(cache, sizeof(lv_lru_t));
if(!cache) {
LV_LOG_WARN("LRU Cache unable to create cache object");
return NULL;
}
cache->hash_table_size = cache_size / average_length;
cache->average_item_length = average_length;
cache->free_memory = cache_size;
cache->total_memory = cache_size;
cache->seed = lv_rand(1, UINT32_MAX);
cache->value_free = value_free ? value_free : lv_free;
cache->key_free = key_free ? key_free : lv_free;
// size the hash table to a guestimate of the number of slots required (assuming a perfect hash)
cache->items = (lv_lru_item_t **) lv_malloc(sizeof(lv_lru_item_t *) * cache->hash_table_size);
lv_memzero(cache->items, sizeof(lv_lru_item_t *) * cache->hash_table_size);
if(!cache->items) {
LV_LOG_WARN("LRU Cache unable to create cache hash table");
lv_free(cache);
return NULL;
}
return cache;
}
void lv_lru_delete(lv_lru_t * cache)
{
LV_ASSERT_NULL(cache);
// free each of the cached items, and the hash table
lv_lru_item_t * item = NULL, * next = NULL;
uint32_t i = 0;
if(cache->items) {
for(; i < cache->hash_table_size; i++) {
item = cache->items[i];
while(item) {
next = (lv_lru_item_t *) item->next;
cache->value_free(item->value);
cache->key_free(item->key);
cache->free_memory += item->value_length;
lv_free(item);
item = next;
}
}
lv_free(cache->items);
}
if(cache->free_items) {
item = cache->free_items;
while(item) {
next = (lv_lru_item_t *) item->next;
lv_free(item);
item = next;
}
}
// free the cache
lv_free(cache);
}
lv_lru_res_t lv_lru_set(lv_lru_t * cache, const void * key, size_t key_length, void * value, size_t value_length)
{
test_for_missing_cache();
test_for_missing_key();
test_for_missing_value();
test_for_value_too_large();
// see if the key already exists
uint32_t hash_index = lv_lru_hash(cache, key, key_length);
int required = 0;
lv_lru_item_t * item = NULL, * prev = NULL;
item = cache->items[hash_index];
while(item && lv_lru_cmp_keys(item, key, key_length)) {
prev = item;
item = (lv_lru_item_t *) item->next;
}
if(item) {
// update the value and value_lengths
required = (int)(value_length - item->value_length);
cache->value_free(item->value);
item->value = value;
item->value_length = value_length;
}
else {
// insert a new item
item = lv_lru_pop_or_create_item(cache);
item->value = value;
item->key = lv_malloc(key_length);
memcpy(item->key, key, key_length);
item->value_length = value_length;
item->key_length = key_length;
required = (int) value_length;
if(prev)
prev->next = item;
else
cache->items[hash_index] = item;
}
item->access_count = ++cache->access_count;
// remove as many items as necessary to free enough space
if(required > 0 && (size_t) required > cache->free_memory) {
while(cache->free_memory < (size_t) required)
lv_lru_remove_lru_item(cache);
}
cache->free_memory -= required;
return LV_LRU_OK;
}
lv_lru_res_t lv_lru_get(lv_lru_t * cache, const void * key, size_t key_size, void ** value)
{
test_for_missing_cache();
test_for_missing_key();
// loop until we find the item, or hit the end of a chain
uint32_t hash_index = lv_lru_hash(cache, key, key_size);
lv_lru_item_t * item = cache->items[hash_index];
while(item && lv_lru_cmp_keys(item, key, key_size))
item = (lv_lru_item_t *) item->next;
if(item) {
*value = item->value;
item->access_count = ++cache->access_count;
}
else {
*value = NULL;
}
return LV_LRU_OK;
}
lv_lru_res_t lv_lru_remove(lv_lru_t * cache, const void * key, size_t key_size)
{
test_for_missing_cache();
test_for_missing_key();
// loop until we find the item, or hit the end of a chain
lv_lru_item_t * item = NULL, * prev = NULL;
uint32_t hash_index = lv_lru_hash(cache, key, key_size);
item = cache->items[hash_index];
while(item && lv_lru_cmp_keys(item, key, key_size)) {
prev = item;
item = (lv_lru_item_t *) item->next;
}
if(item) {
lv_lru_remove_item(cache, prev, item, hash_index);
}
return LV_LRU_OK;
}
void lv_lru_remove_lru_item(lv_lru_t * cache)
{
lv_lru_item_t * min_item = NULL, * min_prev = NULL;
lv_lru_item_t * item = NULL, * prev = NULL;
uint32_t i = 0, min_index = -1;
uint64_t min_access_count = -1;
for(; i < cache->hash_table_size; i++) {
item = cache->items[i];
prev = NULL;
while(item) {
if(item->access_count < min_access_count || (int64_t) min_access_count == -1) {
min_access_count = item->access_count;
min_item = item;
min_prev = prev;
min_index = i;
}
prev = item;
item = item->next;
}
}
if(min_item) {
lv_lru_remove_item(cache, min_prev, min_item, min_index);
}
}
/**********************
* STATIC FUNCTIONS
**********************/
static uint32_t lv_lru_hash(lv_lru_t * cache, const void * key, uint32_t key_length)
{
uint32_t m = 0x5bd1e995;
uint32_t r = 24;
uint32_t h = cache->seed ^ key_length;
char * data = (char *) key;
while(key_length >= 4) {
uint32_t k = *(uint32_t *) data;
k *= m;
k ^= k >> r;
k *= m;
h *= m;
h ^= k;
data += 4;
key_length -= 4;
}
if(key_length >= 3) {
h ^= data[2] << 16;
}
if(key_length >= 2) {
h ^= data[1] << 8;
}
if(key_length >= 1) {
h ^= data[0];
h *= m;
}
h ^= h >> 13;
h *= m;
h ^= h >> 15;
return h % cache->hash_table_size;
}
static int lv_lru_cmp_keys(lv_lru_item_t * item, const void * key, uint32_t key_length)
{
if(key_length != item->key_length) {
return 1;
}
else {
return memcmp(key, item->key, key_length);
}
}
static void lv_lru_remove_item(lv_lru_t * cache, lv_lru_item_t * prev, lv_lru_item_t * item, uint32_t hash_index)
{
if(prev) {
prev->next = item->next;
}
else {
cache->items[hash_index] = (lv_lru_item_t *) item->next;
}
// free memory and update the free memory counter
cache->free_memory += item->value_length;
cache->value_free(item->value);
cache->key_free(item->key);
// push the item to the free items queue
lv_memzero(item, sizeof(lv_lru_item_t));
item->next = cache->free_items;
cache->free_items = item;
}
static lv_lru_item_t * lv_lru_pop_or_create_item(lv_lru_t * cache)
{
lv_lru_item_t * item = NULL;
if(cache->free_items) {
item = cache->free_items;
cache->free_items = item->next;
lv_memzero(item, sizeof(lv_lru_item_t));
}
else {
item = (lv_lru_item_t *) lv_malloc(sizeof(lv_lru_item_t));
lv_memzero(item, sizeof(lv_lru_item_t));
}
return item;
}
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_style.c | /**
* @file lv_style.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_style.h"
#include "../core/lv_global.h"
#include "../stdlib/lv_mem.h"
#include "../stdlib/lv_string.h"
#include "lv_assert.h"
#include "lv_types.h"
/*********************
* DEFINES
*********************/
#define _lv_style_custom_prop_flag_lookup_table_size LV_GLOBAL_DEFAULT()->style_custom_table_size
#define _lv_style_custom_prop_flag_lookup_table LV_GLOBAL_DEFAULT()->style_custom_prop_flag_lookup_table
#define last_custom_prop_id LV_GLOBAL_DEFAULT()->style_last_custom_prop_id
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* GLOBAL VARIABLES
**********************/
const lv_style_prop_t lv_style_const_prop_id_inv = LV_STYLE_PROP_INV;
const uint8_t _lv_style_builtin_prop_flag_lookup_table[_LV_STYLE_NUM_BUILT_IN_PROPS] = {
[LV_STYLE_WIDTH] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_MIN_WIDTH] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_MAX_WIDTH] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_HEIGHT] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_MIN_HEIGHT] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_MAX_HEIGHT] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_X] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_Y] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_ALIGN] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_TRANSFORM_WIDTH] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE | LV_STYLE_PROP_FLAG_TRANSFORM,
[LV_STYLE_TRANSFORM_HEIGHT] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE | LV_STYLE_PROP_FLAG_TRANSFORM,
[LV_STYLE_TRANSLATE_X] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE | LV_STYLE_PROP_FLAG_PARENT_LAYOUT_UPDATE,
[LV_STYLE_TRANSLATE_Y] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE | LV_STYLE_PROP_FLAG_PARENT_LAYOUT_UPDATE,
[LV_STYLE_TRANSFORM_SCALE_X] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE | LV_STYLE_PROP_FLAG_LAYER_UPDATE | LV_STYLE_PROP_FLAG_TRANSFORM,
[LV_STYLE_TRANSFORM_SCALE_Y] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE | LV_STYLE_PROP_FLAG_LAYER_UPDATE | LV_STYLE_PROP_FLAG_TRANSFORM,
[LV_STYLE_TRANSFORM_ROTATION] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE | LV_STYLE_PROP_FLAG_LAYER_UPDATE | LV_STYLE_PROP_FLAG_TRANSFORM,
[LV_STYLE_PAD_TOP] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE | LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_PAD_BOTTOM] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE | LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_PAD_LEFT] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE | LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_PAD_RIGHT] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE | LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_PAD_ROW] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE | LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_PAD_COLUMN] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE | LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_MARGIN_TOP] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE | LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_MARGIN_BOTTOM] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE | LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_MARGIN_LEFT] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE | LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_MARGIN_RIGHT] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE | LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_BG_COLOR] = 0,
[LV_STYLE_BG_OPA] = 0,
[LV_STYLE_BG_GRAD_COLOR] = 0,
[LV_STYLE_BG_GRAD_DIR] = 0,
[LV_STYLE_BG_MAIN_STOP] = 0,
[LV_STYLE_BG_GRAD_STOP] = 0,
[LV_STYLE_BG_MAIN_OPA] = 0,
[LV_STYLE_BG_GRAD_OPA] = 0,
[LV_STYLE_BG_GRAD] = 0,
[LV_STYLE_BG_IMAGE_SRC] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE,
[LV_STYLE_BG_IMAGE_OPA] = 0,
[LV_STYLE_BG_IMAGE_RECOLOR] = 0,
[LV_STYLE_BG_IMAGE_RECOLOR_OPA] = 0,
[LV_STYLE_BG_IMAGE_TILED] = 0,
[LV_STYLE_BORDER_COLOR] = 0,
[LV_STYLE_BORDER_OPA] = 0,
[LV_STYLE_BORDER_WIDTH] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_BORDER_SIDE] = 0,
[LV_STYLE_BORDER_POST] = 0,
[LV_STYLE_OUTLINE_WIDTH] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE,
[LV_STYLE_OUTLINE_COLOR] = 0,
[LV_STYLE_OUTLINE_OPA] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE,
[LV_STYLE_OUTLINE_PAD] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE,
[LV_STYLE_SHADOW_WIDTH] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE,
[LV_STYLE_SHADOW_OFFSET_X] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE,
[LV_STYLE_SHADOW_OFFSET_Y] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE,
[LV_STYLE_SHADOW_SPREAD] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE,
[LV_STYLE_SHADOW_COLOR] = 0,
[LV_STYLE_SHADOW_OPA] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE,
[LV_STYLE_IMAGE_OPA] = 0,
[LV_STYLE_IMAGE_RECOLOR] = 0,
[LV_STYLE_IMAGE_RECOLOR_OPA] = 0,
[LV_STYLE_LINE_WIDTH] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE,
[LV_STYLE_LINE_DASH_WIDTH] = 0,
[LV_STYLE_LINE_DASH_GAP] = 0,
[LV_STYLE_LINE_ROUNDED] = 0,
[LV_STYLE_LINE_COLOR] = 0,
[LV_STYLE_LINE_OPA] = 0,
[LV_STYLE_ARC_WIDTH] = LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE,
[LV_STYLE_ARC_ROUNDED] = 0,
[LV_STYLE_ARC_COLOR] = 0,
[LV_STYLE_ARC_OPA] = 0,
[LV_STYLE_ARC_IMAGE_SRC] = 0,
[LV_STYLE_TEXT_COLOR] = LV_STYLE_PROP_FLAG_INHERITABLE,
[LV_STYLE_TEXT_OPA] = LV_STYLE_PROP_FLAG_INHERITABLE,
[LV_STYLE_TEXT_FONT] = LV_STYLE_PROP_FLAG_INHERITABLE | LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_TEXT_LETTER_SPACE] = LV_STYLE_PROP_FLAG_INHERITABLE | LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_TEXT_LINE_SPACE] = LV_STYLE_PROP_FLAG_INHERITABLE | LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_TEXT_DECOR] = LV_STYLE_PROP_FLAG_INHERITABLE,
[LV_STYLE_TEXT_ALIGN] = LV_STYLE_PROP_FLAG_INHERITABLE | LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_RADIUS] = 0,
[LV_STYLE_CLIP_CORNER] = 0,
[LV_STYLE_OPA] = 0,
[LV_STYLE_OPA_LAYERED] = LV_STYLE_PROP_FLAG_LAYER_UPDATE,
[LV_STYLE_COLOR_FILTER_DSC] = LV_STYLE_PROP_FLAG_INHERITABLE,
[LV_STYLE_COLOR_FILTER_OPA] = LV_STYLE_PROP_FLAG_INHERITABLE,
[LV_STYLE_ANIM_TIME] = 0,
[LV_STYLE_ANIM_SPEED] = 0,
[LV_STYLE_TRANSITION] = 0,
[LV_STYLE_BLEND_MODE] = LV_STYLE_PROP_FLAG_LAYER_UPDATE,
[LV_STYLE_LAYOUT] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_BASE_DIR] = LV_STYLE_PROP_FLAG_INHERITABLE | LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_FLEX_FLOW] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_FLEX_MAIN_PLACE] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_FLEX_CROSS_PLACE] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_FLEX_TRACK_PLACE] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_FLEX_GROW] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_GRID_COLUMN_DSC_ARRAY] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_GRID_ROW_DSC_ARRAY] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_GRID_COLUMN_ALIGN] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_GRID_ROW_ALIGN] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_GRID_CELL_ROW_SPAN] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_GRID_CELL_ROW_POS] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_GRID_CELL_COLUMN_SPAN] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_GRID_CELL_COLUMN_POS] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_GRID_CELL_X_ALIGN] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
[LV_STYLE_GRID_CELL_Y_ALIGN] = LV_STYLE_PROP_FLAG_LAYOUT_UPDATE,
};
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_style_init(lv_style_t * style)
{
#if LV_USE_ASSERT_STYLE
if(style->sentinel == LV_STYLE_SENTINEL_VALUE && style->prop_cnt > 1) {
LV_LOG_WARN("Style might be already inited. (Potential memory leak)");
}
#endif
lv_memzero(style, sizeof(lv_style_t));
#if LV_USE_ASSERT_STYLE
style->sentinel = LV_STYLE_SENTINEL_VALUE;
#endif
}
void lv_style_reset(lv_style_t * style)
{
LV_ASSERT_STYLE(style);
if(style->prop_cnt != 255) lv_free(style->values_and_props);
lv_memzero(style, sizeof(lv_style_t));
#if LV_USE_ASSERT_STYLE
style->sentinel = LV_STYLE_SENTINEL_VALUE;
#endif
}
lv_style_prop_t lv_style_register_prop(uint8_t flag)
{
if(_lv_style_custom_prop_flag_lookup_table == NULL) {
_lv_style_custom_prop_flag_lookup_table_size = 0;
last_custom_prop_id = (uint16_t)_LV_STYLE_LAST_BUILT_IN_PROP;
}
// if((last_custom_prop_id + 1) != 0) {
// LV_LOG_ERROR("No more custom property IDs available");
// return LV_STYLE_PROP_INV;
// }
/*
* Allocate the lookup table if it's not yet available.
*/
size_t required_size = (last_custom_prop_id + 1 - _LV_STYLE_LAST_BUILT_IN_PROP);
if(_lv_style_custom_prop_flag_lookup_table_size < required_size) {
/* Round required_size up to the nearest 32-byte value */
required_size = (required_size + 31) & ~31;
LV_ASSERT_MSG(required_size > 0, "required size has become 0?");
uint8_t * old_p = _lv_style_custom_prop_flag_lookup_table;
uint8_t * new_p = lv_realloc(old_p, required_size * sizeof(uint8_t));
if(new_p == NULL) {
LV_LOG_ERROR("Unable to allocate space for custom property lookup table");
return LV_STYLE_PROP_INV;
}
_lv_style_custom_prop_flag_lookup_table = new_p;
_lv_style_custom_prop_flag_lookup_table_size = required_size;
}
last_custom_prop_id++;
/* This should never happen - we should bail out above */
LV_ASSERT_NULL(_lv_style_custom_prop_flag_lookup_table);
_lv_style_custom_prop_flag_lookup_table[last_custom_prop_id - _LV_STYLE_NUM_BUILT_IN_PROPS] = flag;
return last_custom_prop_id;
}
lv_style_prop_t lv_style_get_num_custom_props(void)
{
return last_custom_prop_id - _LV_STYLE_LAST_BUILT_IN_PROP;
}
bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop)
{
LV_ASSERT_STYLE(style);
if(lv_style_is_const(style)) {
LV_LOG_ERROR("Cannot remove prop from const style");
return false;
}
if(style->prop_cnt == 0) return false;
uint8_t * tmp = (lv_style_prop_t *)style->values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
uint8_t * old_props = (uint8_t *)tmp;
uint32_t i;
for(i = 0; i < style->prop_cnt; i++) {
if(old_props[i] == prop) {
lv_style_value_t * old_values = (lv_style_value_t *)style->values_and_props;
size_t size = (style->prop_cnt - 1) * (sizeof(lv_style_value_t) + sizeof(lv_style_prop_t));
uint8_t * new_values_and_props = lv_malloc(size);
if(new_values_and_props == NULL) return false;
style->values_and_props = new_values_and_props;
style->prop_cnt--;
tmp = new_values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
uint8_t * new_props = (uint8_t *)tmp;
lv_style_value_t * new_values = (lv_style_value_t *)new_values_and_props;
uint32_t j;
for(i = j = 0; j <= style->prop_cnt;
j++) { /*<=: because prop_cnt already reduced but all the old props. needs to be checked.*/
if(old_props[j] != prop) {
new_values[i] = old_values[j];
new_props[i++] = old_props[j];
}
}
lv_free(old_values);
return true;
}
}
return false;
}
void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t value)
{
LV_ASSERT_STYLE(style);
if(lv_style_is_const(style)) {
LV_LOG_ERROR("Cannot set property of constant style");
return;
}
LV_ASSERT(prop != LV_STYLE_PROP_INV);
lv_style_prop_t * props;
int32_t i;
if(style->values_and_props) {
props = (lv_style_prop_t *)style->values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
for(i = style->prop_cnt - 1; i >= 0; i--) {
if(props[i] == prop) {
lv_style_value_t * values = (lv_style_value_t *)style->values_and_props;
values[i] = value;
return;
}
}
}
size_t size = (style->prop_cnt + 1) * (sizeof(lv_style_value_t) + sizeof(lv_style_prop_t));
uint8_t * values_and_props = lv_realloc(style->values_and_props, size);
if(values_and_props == NULL) return;
style->values_and_props = values_and_props;
props = values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
/*Shift all props to make place for the value before them*/
for(i = style->prop_cnt - 1; i >= 0; i--) {
props[i + sizeof(lv_style_value_t) / sizeof(lv_style_prop_t)] = props[i];
}
style->prop_cnt++;
/*Go to the new position with the props*/
props = values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
lv_style_value_t * values = (lv_style_value_t *)values_and_props;
/*Set the new property and value*/
props[style->prop_cnt - 1] = prop;
values[style->prop_cnt - 1] = value;
uint32_t group = _lv_style_get_prop_group(prop);
style->has_group |= (uint32_t)1 << group;
}
lv_style_res_t lv_style_get_prop(const lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value)
{
return lv_style_get_prop_inlined(style, prop, value);
}
void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style_prop_t props[],
lv_anim_path_cb_t path_cb, uint32_t time, uint32_t delay, void * user_data)
{
lv_memzero(tr, sizeof(lv_style_transition_dsc_t));
tr->props = props;
tr->path_xcb = path_cb == NULL ? lv_anim_path_linear : path_cb;
tr->time = time;
tr->delay = delay;
tr->user_data = user_data;
}
lv_style_value_t lv_style_prop_get_default(lv_style_prop_t prop)
{
const lv_color_t black = LV_COLOR_MAKE(0x00, 0x00, 0x00);
const lv_color_t white = LV_COLOR_MAKE(0xff, 0xff, 0xff);
switch(prop) {
case LV_STYLE_TRANSFORM_SCALE_X:
case LV_STYLE_TRANSFORM_SCALE_Y:
return (lv_style_value_t) {
.num = LV_SCALE_NONE
};
case LV_STYLE_BG_COLOR:
return (lv_style_value_t) {
.color = black
};
case LV_STYLE_BG_GRAD_COLOR:
case LV_STYLE_BORDER_COLOR:
case LV_STYLE_SHADOW_COLOR:
case LV_STYLE_OUTLINE_COLOR:
case LV_STYLE_ARC_COLOR:
case LV_STYLE_LINE_COLOR:
case LV_STYLE_TEXT_COLOR:
case LV_STYLE_IMAGE_RECOLOR:
return (lv_style_value_t) {
.color = white
};
case LV_STYLE_OPA:
case LV_STYLE_OPA_LAYERED:
case LV_STYLE_BORDER_OPA:
case LV_STYLE_TEXT_OPA:
case LV_STYLE_IMAGE_OPA:
case LV_STYLE_BG_GRAD_OPA:
case LV_STYLE_BG_MAIN_OPA:
case LV_STYLE_BG_IMAGE_OPA:
case LV_STYLE_OUTLINE_OPA:
case LV_STYLE_SHADOW_OPA:
case LV_STYLE_LINE_OPA:
case LV_STYLE_ARC_OPA:
return (lv_style_value_t) {
.num = LV_OPA_COVER
};
case LV_STYLE_BG_GRAD_STOP:
return (lv_style_value_t) {
.num = 255
};
case LV_STYLE_BORDER_SIDE:
return (lv_style_value_t) {
.num = LV_BORDER_SIDE_FULL
};
case LV_STYLE_TEXT_FONT:
return (lv_style_value_t) {
.ptr = LV_FONT_DEFAULT
};
case LV_STYLE_MAX_WIDTH:
case LV_STYLE_MAX_HEIGHT:
return (lv_style_value_t) {
.num = LV_COORD_MAX
};
default:
return (lv_style_value_t) {
.ptr = 0
};
}
}
bool lv_style_is_empty(const lv_style_t * style)
{
LV_ASSERT_STYLE(style);
return style->prop_cnt == 0;
}
uint8_t _lv_style_prop_lookup_flags(lv_style_prop_t prop)
{
if(prop == LV_STYLE_PROP_ANY) return LV_STYLE_PROP_FLAG_ALL; /*Any prop can have any flags*/
if(prop == LV_STYLE_PROP_INV) return 0;
if(prop < _LV_STYLE_NUM_BUILT_IN_PROPS)
return _lv_style_builtin_prop_flag_lookup_table[prop];
prop -= _LV_STYLE_NUM_BUILT_IN_PROPS;
if(_lv_style_custom_prop_flag_lookup_table != NULL && prop < _lv_style_custom_prop_flag_lookup_table_size)
return _lv_style_custom_prop_flag_lookup_table[prop];
return 0;
}
/**********************
* STATIC FUNCTIONS
**********************/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_style_gen.h |
/*
**********************************************************************
* DO NOT EDIT
* This file is automatically generated by "style_api_gen.py"
**********************************************************************
*/
#ifndef LV_STYLE_GEN_H
#define LV_STYLE_GEN_H
void lv_style_set_width(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_WIDTH;
void lv_style_set_min_width(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_MIN_WIDTH;
void lv_style_set_max_width(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_MAX_WIDTH;
void lv_style_set_height(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_HEIGHT;
void lv_style_set_min_height(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_MIN_HEIGHT;
void lv_style_set_max_height(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_MAX_HEIGHT;
void lv_style_set_x(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_X;
void lv_style_set_y(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_Y;
void lv_style_set_align(lv_style_t * style, lv_align_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_ALIGN;
void lv_style_set_transform_width(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_TRANSFORM_WIDTH;
void lv_style_set_transform_height(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_TRANSFORM_HEIGHT;
void lv_style_set_translate_x(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_TRANSLATE_X;
void lv_style_set_translate_y(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_TRANSLATE_Y;
void lv_style_set_transform_scale_x(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_TRANSFORM_SCALE_X;
void lv_style_set_transform_scale_y(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_TRANSFORM_SCALE_Y;
void lv_style_set_transform_rotation(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_TRANSFORM_ROTATION;
void lv_style_set_transform_pivot_x(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_TRANSFORM_PIVOT_X;
void lv_style_set_transform_pivot_y(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_TRANSFORM_PIVOT_Y;
void lv_style_set_pad_top(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_PAD_TOP;
void lv_style_set_pad_bottom(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_PAD_BOTTOM;
void lv_style_set_pad_left(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_PAD_LEFT;
void lv_style_set_pad_right(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_PAD_RIGHT;
void lv_style_set_pad_row(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_PAD_ROW;
void lv_style_set_pad_column(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_PAD_COLUMN;
void lv_style_set_margin_top(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_MARGIN_TOP;
void lv_style_set_margin_bottom(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_MARGIN_BOTTOM;
void lv_style_set_margin_left(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_MARGIN_LEFT;
void lv_style_set_margin_right(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_MARGIN_RIGHT;
void lv_style_set_bg_color(lv_style_t * style, lv_color_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_BG_COLOR;
void lv_style_set_bg_opa(lv_style_t * style, lv_opa_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_BG_OPA;
void lv_style_set_bg_grad_color(lv_style_t * style, lv_color_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_BG_GRAD_COLOR;
void lv_style_set_bg_grad_dir(lv_style_t * style, lv_grad_dir_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_BG_GRAD_DIR;
void lv_style_set_bg_main_stop(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_BG_MAIN_STOP;
void lv_style_set_bg_grad_stop(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_BG_GRAD_STOP;
void lv_style_set_bg_main_opa(lv_style_t * style, lv_opa_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_BG_MAIN_OPA;
void lv_style_set_bg_grad_opa(lv_style_t * style, lv_opa_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_BG_GRAD_OPA;
void lv_style_set_bg_grad(lv_style_t * style, const lv_grad_dsc_t * value);
extern const lv_style_prop_t _lv_style_const_prop_id_BG_GRAD;
void lv_style_set_bg_image_src(lv_style_t * style, const void * value);
extern const lv_style_prop_t _lv_style_const_prop_id_BG_IMAGE_SRC;
void lv_style_set_bg_image_opa(lv_style_t * style, lv_opa_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_BG_IMAGE_OPA;
void lv_style_set_bg_image_recolor(lv_style_t * style, lv_color_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_BG_IMAGE_RECOLOR;
void lv_style_set_bg_image_recolor_opa(lv_style_t * style, lv_opa_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_BG_IMAGE_RECOLOR_OPA;
void lv_style_set_bg_image_tiled(lv_style_t * style, bool value);
extern const lv_style_prop_t _lv_style_const_prop_id_BG_IMAGE_TILED;
void lv_style_set_border_color(lv_style_t * style, lv_color_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_BORDER_COLOR;
void lv_style_set_border_opa(lv_style_t * style, lv_opa_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_BORDER_OPA;
void lv_style_set_border_width(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_BORDER_WIDTH;
void lv_style_set_border_side(lv_style_t * style, lv_border_side_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_BORDER_SIDE;
void lv_style_set_border_post(lv_style_t * style, bool value);
extern const lv_style_prop_t _lv_style_const_prop_id_BORDER_POST;
void lv_style_set_outline_width(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_OUTLINE_WIDTH;
void lv_style_set_outline_color(lv_style_t * style, lv_color_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_OUTLINE_COLOR;
void lv_style_set_outline_opa(lv_style_t * style, lv_opa_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_OUTLINE_OPA;
void lv_style_set_outline_pad(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_OUTLINE_PAD;
void lv_style_set_shadow_width(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_SHADOW_WIDTH;
void lv_style_set_shadow_offset_x(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_SHADOW_OFFSET_X;
void lv_style_set_shadow_offset_y(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_SHADOW_OFFSET_Y;
void lv_style_set_shadow_spread(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_SHADOW_SPREAD;
void lv_style_set_shadow_color(lv_style_t * style, lv_color_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_SHADOW_COLOR;
void lv_style_set_shadow_opa(lv_style_t * style, lv_opa_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_SHADOW_OPA;
void lv_style_set_image_opa(lv_style_t * style, lv_opa_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_IMAGE_OPA;
void lv_style_set_image_recolor(lv_style_t * style, lv_color_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_IMAGE_RECOLOR;
void lv_style_set_image_recolor_opa(lv_style_t * style, lv_opa_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_IMAGE_RECOLOR_OPA;
void lv_style_set_line_width(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_LINE_WIDTH;
void lv_style_set_line_dash_width(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_LINE_DASH_WIDTH;
void lv_style_set_line_dash_gap(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_LINE_DASH_GAP;
void lv_style_set_line_rounded(lv_style_t * style, bool value);
extern const lv_style_prop_t _lv_style_const_prop_id_LINE_ROUNDED;
void lv_style_set_line_color(lv_style_t * style, lv_color_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_LINE_COLOR;
void lv_style_set_line_opa(lv_style_t * style, lv_opa_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_LINE_OPA;
void lv_style_set_arc_width(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_ARC_WIDTH;
void lv_style_set_arc_rounded(lv_style_t * style, bool value);
extern const lv_style_prop_t _lv_style_const_prop_id_ARC_ROUNDED;
void lv_style_set_arc_color(lv_style_t * style, lv_color_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_ARC_COLOR;
void lv_style_set_arc_opa(lv_style_t * style, lv_opa_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_ARC_OPA;
void lv_style_set_arc_image_src(lv_style_t * style, const void * value);
extern const lv_style_prop_t _lv_style_const_prop_id_ARC_IMAGE_SRC;
void lv_style_set_text_color(lv_style_t * style, lv_color_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_TEXT_COLOR;
void lv_style_set_text_opa(lv_style_t * style, lv_opa_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_TEXT_OPA;
void lv_style_set_text_font(lv_style_t * style, const lv_font_t * value);
extern const lv_style_prop_t _lv_style_const_prop_id_TEXT_FONT;
void lv_style_set_text_letter_space(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_TEXT_LETTER_SPACE;
void lv_style_set_text_line_space(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_TEXT_LINE_SPACE;
void lv_style_set_text_decor(lv_style_t * style, lv_text_decor_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_TEXT_DECOR;
void lv_style_set_text_align(lv_style_t * style, lv_text_align_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_TEXT_ALIGN;
void lv_style_set_radius(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_RADIUS;
void lv_style_set_clip_corner(lv_style_t * style, bool value);
extern const lv_style_prop_t _lv_style_const_prop_id_CLIP_CORNER;
void lv_style_set_opa(lv_style_t * style, lv_opa_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_OPA;
void lv_style_set_opa_layered(lv_style_t * style, lv_opa_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_OPA_LAYERED;
void lv_style_set_color_filter_dsc(lv_style_t * style, const lv_color_filter_dsc_t * value);
extern const lv_style_prop_t _lv_style_const_prop_id_COLOR_FILTER_DSC;
void lv_style_set_color_filter_opa(lv_style_t * style, lv_opa_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_COLOR_FILTER_OPA;
void lv_style_set_anim(lv_style_t * style, const lv_anim_t * value);
extern const lv_style_prop_t _lv_style_const_prop_id_ANIM;
void lv_style_set_anim_time(lv_style_t * style, uint32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_ANIM_TIME;
void lv_style_set_anim_speed(lv_style_t * style, uint32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_ANIM_SPEED;
void lv_style_set_transition(lv_style_t * style, const lv_style_transition_dsc_t * value);
extern const lv_style_prop_t _lv_style_const_prop_id_TRANSITION;
void lv_style_set_blend_mode(lv_style_t * style, lv_blend_mode_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_BLEND_MODE;
void lv_style_set_layout(lv_style_t * style, uint16_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_LAYOUT;
void lv_style_set_base_dir(lv_style_t * style, lv_base_dir_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_BASE_DIR;
void lv_style_set_flex_flow(lv_style_t * style, lv_flex_flow_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_FLEX_FLOW;
void lv_style_set_flex_main_place(lv_style_t * style, lv_flex_align_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_FLEX_MAIN_PLACE;
void lv_style_set_flex_cross_place(lv_style_t * style, lv_flex_align_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_FLEX_CROSS_PLACE;
void lv_style_set_flex_track_place(lv_style_t * style, lv_flex_align_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_FLEX_TRACK_PLACE;
void lv_style_set_flex_grow(lv_style_t * style, uint8_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_FLEX_GROW;
void lv_style_set_grid_column_dsc_array(lv_style_t * style, const int32_t * value);
extern const lv_style_prop_t _lv_style_const_prop_id_GRID_COLUMN_DSC_ARRAY;
void lv_style_set_grid_column_align(lv_style_t * style, lv_grid_align_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_GRID_COLUMN_ALIGN;
void lv_style_set_grid_row_dsc_array(lv_style_t * style, const int32_t * value);
extern const lv_style_prop_t _lv_style_const_prop_id_GRID_ROW_DSC_ARRAY;
void lv_style_set_grid_row_align(lv_style_t * style, lv_grid_align_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_GRID_ROW_ALIGN;
void lv_style_set_grid_cell_column_pos(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_GRID_CELL_COLUMN_POS;
void lv_style_set_grid_cell_x_align(lv_style_t * style, lv_grid_align_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_GRID_CELL_X_ALIGN;
void lv_style_set_grid_cell_column_span(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_GRID_CELL_COLUMN_SPAN;
void lv_style_set_grid_cell_row_pos(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_GRID_CELL_ROW_POS;
void lv_style_set_grid_cell_y_align(lv_style_t * style, lv_grid_align_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_GRID_CELL_Y_ALIGN;
void lv_style_set_grid_cell_row_span(lv_style_t * style, int32_t value);
extern const lv_style_prop_t _lv_style_const_prop_id_GRID_CELL_ROW_SPAN;
#define LV_STYLE_CONST_WIDTH(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_WIDTH, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_MIN_WIDTH(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_MIN_WIDTH, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_MAX_WIDTH(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_MAX_WIDTH, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_HEIGHT(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_HEIGHT, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_MIN_HEIGHT(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_MIN_HEIGHT, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_MAX_HEIGHT(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_MAX_HEIGHT, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_X(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_X, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_Y(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_Y, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_ALIGN(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_ALIGN, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TRANSFORM_WIDTH(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_TRANSFORM_WIDTH, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TRANSFORM_HEIGHT(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_TRANSFORM_HEIGHT, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TRANSLATE_X(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_TRANSLATE_X, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TRANSLATE_Y(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_TRANSLATE_Y, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TRANSFORM_SCALE_X(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_TRANSFORM_SCALE_X, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TRANSFORM_SCALE_Y(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_TRANSFORM_SCALE_Y, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TRANSFORM_ROTATION(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_TRANSFORM_ROTATION, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TRANSFORM_PIVOT_X(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_TRANSFORM_PIVOT_X, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TRANSFORM_PIVOT_Y(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_TRANSFORM_PIVOT_Y, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_PAD_TOP(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_PAD_TOP, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_PAD_BOTTOM(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_PAD_BOTTOM, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_PAD_LEFT(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_PAD_LEFT, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_PAD_RIGHT(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_PAD_RIGHT, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_PAD_ROW(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_PAD_ROW, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_PAD_COLUMN(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_PAD_COLUMN, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_MARGIN_TOP(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_MARGIN_TOP, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_MARGIN_BOTTOM(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_MARGIN_BOTTOM, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_MARGIN_LEFT(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_MARGIN_LEFT, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_MARGIN_RIGHT(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_MARGIN_RIGHT, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BG_COLOR(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_BG_COLOR, .value = { .color = val } \
}
#define LV_STYLE_CONST_BG_OPA(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_BG_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BG_GRAD_COLOR(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_BG_GRAD_COLOR, .value = { .color = val } \
}
#define LV_STYLE_CONST_BG_GRAD_DIR(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_BG_GRAD_DIR, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BG_MAIN_STOP(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_BG_MAIN_STOP, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BG_GRAD_STOP(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_BG_GRAD_STOP, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BG_MAIN_OPA(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_BG_MAIN_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BG_GRAD_OPA(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_BG_GRAD_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BG_GRAD(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_BG_GRAD, .value = { .ptr = val } \
}
#define LV_STYLE_CONST_BG_IMAGE_SRC(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_BG_IMAGE_SRC, .value = { .ptr = val } \
}
#define LV_STYLE_CONST_BG_IMAGE_OPA(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_BG_IMAGE_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BG_IMAGE_RECOLOR(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_BG_IMAGE_RECOLOR, .value = { .color = val } \
}
#define LV_STYLE_CONST_BG_IMAGE_RECOLOR_OPA(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_BG_IMAGE_RECOLOR_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BG_IMAGE_TILED(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_BG_IMAGE_TILED, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BORDER_COLOR(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_BORDER_COLOR, .value = { .color = val } \
}
#define LV_STYLE_CONST_BORDER_OPA(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_BORDER_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BORDER_WIDTH(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_BORDER_WIDTH, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BORDER_SIDE(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_BORDER_SIDE, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BORDER_POST(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_BORDER_POST, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_OUTLINE_WIDTH(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_OUTLINE_WIDTH, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_OUTLINE_COLOR(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_OUTLINE_COLOR, .value = { .color = val } \
}
#define LV_STYLE_CONST_OUTLINE_OPA(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_OUTLINE_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_OUTLINE_PAD(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_OUTLINE_PAD, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_SHADOW_WIDTH(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_SHADOW_WIDTH, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_SHADOW_OFFSET_X(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_SHADOW_OFFSET_X, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_SHADOW_OFFSET_Y(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_SHADOW_OFFSET_Y, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_SHADOW_SPREAD(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_SHADOW_SPREAD, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_SHADOW_COLOR(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_SHADOW_COLOR, .value = { .color = val } \
}
#define LV_STYLE_CONST_SHADOW_OPA(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_SHADOW_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_IMAGE_OPA(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_IMAGE_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_IMAGE_RECOLOR(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_IMAGE_RECOLOR, .value = { .color = val } \
}
#define LV_STYLE_CONST_IMAGE_RECOLOR_OPA(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_IMAGE_RECOLOR_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_LINE_WIDTH(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_LINE_WIDTH, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_LINE_DASH_WIDTH(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_LINE_DASH_WIDTH, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_LINE_DASH_GAP(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_LINE_DASH_GAP, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_LINE_ROUNDED(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_LINE_ROUNDED, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_LINE_COLOR(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_LINE_COLOR, .value = { .color = val } \
}
#define LV_STYLE_CONST_LINE_OPA(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_LINE_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_ARC_WIDTH(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_ARC_WIDTH, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_ARC_ROUNDED(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_ARC_ROUNDED, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_ARC_COLOR(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_ARC_COLOR, .value = { .color = val } \
}
#define LV_STYLE_CONST_ARC_OPA(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_ARC_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_ARC_IMAGE_SRC(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_ARC_IMAGE_SRC, .value = { .ptr = val } \
}
#define LV_STYLE_CONST_TEXT_COLOR(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_TEXT_COLOR, .value = { .color = val } \
}
#define LV_STYLE_CONST_TEXT_OPA(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_TEXT_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TEXT_FONT(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_TEXT_FONT, .value = { .ptr = val } \
}
#define LV_STYLE_CONST_TEXT_LETTER_SPACE(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_TEXT_LETTER_SPACE, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TEXT_LINE_SPACE(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_TEXT_LINE_SPACE, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TEXT_DECOR(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_TEXT_DECOR, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TEXT_ALIGN(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_TEXT_ALIGN, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_RADIUS(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_RADIUS, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_CLIP_CORNER(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_CLIP_CORNER, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_OPA(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_OPA_LAYERED(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_OPA_LAYERED, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_COLOR_FILTER_DSC(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_COLOR_FILTER_DSC, .value = { .ptr = val } \
}
#define LV_STYLE_CONST_COLOR_FILTER_OPA(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_COLOR_FILTER_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_ANIM(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_ANIM, .value = { .ptr = val } \
}
#define LV_STYLE_CONST_ANIM_TIME(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_ANIM_TIME, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_ANIM_SPEED(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_ANIM_SPEED, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TRANSITION(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_TRANSITION, .value = { .ptr = val } \
}
#define LV_STYLE_CONST_BLEND_MODE(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_BLEND_MODE, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_LAYOUT(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_LAYOUT, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_BASE_DIR(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_BASE_DIR, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_FLEX_FLOW(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_FLEX_FLOW, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_FLEX_MAIN_PLACE(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_FLEX_MAIN_PLACE, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_FLEX_CROSS_PLACE(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_FLEX_CROSS_PLACE, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_FLEX_TRACK_PLACE(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_FLEX_TRACK_PLACE, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_FLEX_GROW(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_FLEX_GROW, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_GRID_COLUMN_DSC_ARRAY(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_GRID_COLUMN_DSC_ARRAY, .value = { .ptr = val } \
}
#define LV_STYLE_CONST_GRID_COLUMN_ALIGN(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_GRID_COLUMN_ALIGN, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_GRID_ROW_DSC_ARRAY(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_GRID_ROW_DSC_ARRAY, .value = { .ptr = val } \
}
#define LV_STYLE_CONST_GRID_ROW_ALIGN(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_GRID_ROW_ALIGN, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_GRID_CELL_COLUMN_POS(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_GRID_CELL_COLUMN_POS, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_GRID_CELL_X_ALIGN(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_GRID_CELL_X_ALIGN, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_GRID_CELL_COLUMN_SPAN(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_GRID_CELL_COLUMN_SPAN, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_GRID_CELL_ROW_POS(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_GRID_CELL_ROW_POS, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_GRID_CELL_Y_ALIGN(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_GRID_CELL_Y_ALIGN, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_GRID_CELL_ROW_SPAN(val) \
{ \
.prop_ptr = &_lv_style_const_prop_id_GRID_CELL_ROW_SPAN, .value = { .num = (int32_t)val } \
}
#endif /* LV_STYLE_GEN_H */
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_ll.h | /**
* @file lv_ll.h
* Handle linked lists. The nodes are dynamically allocated by the 'lv_mem' module.
*/
#ifndef LV_LL_H
#define LV_LL_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/** Dummy type to make handling easier*/
typedef uint8_t lv_ll_node_t;
/** Description of a linked list*/
typedef struct {
uint32_t n_size;
lv_ll_node_t * head;
lv_ll_node_t * tail;
} lv_ll_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize linked list
* @param ll_p pointer to lv_ll_t variable
* @param node_size the size of 1 node in bytes
*/
void _lv_ll_init(lv_ll_t * ll_p, uint32_t node_size);
/**
* Add a new head to a linked list
* @param ll_p pointer to linked list
* @return pointer to the new head
*/
void * _lv_ll_ins_head(lv_ll_t * ll_p);
/**
* Insert a new node in front of the n_act node
* @param ll_p pointer to linked list
* @param n_act pointer a node
* @return pointer to the new node
*/
void * _lv_ll_ins_prev(lv_ll_t * ll_p, void * n_act);
/**
* Add a new tail to a linked list
* @param ll_p pointer to linked list
* @return pointer to the new tail
*/
void * _lv_ll_ins_tail(lv_ll_t * ll_p);
/**
* Remove the node 'node_p' from 'll_p' linked list.
* It does not free the memory of node.
* @param ll_p pointer to the linked list of 'node_p'
* @param node_p pointer to node in 'll_p' linked list
*/
void _lv_ll_remove(lv_ll_t * ll_p, void * node_p);
/**
* Remove and free all elements from a linked list. The list remain valid but become empty.
* @param ll_p pointer to linked list
*/
void _lv_ll_clear(lv_ll_t * ll_p);
/**
* Move a node to a new linked list
* @param ll_ori_p pointer to the original (old) linked list
* @param ll_new_p pointer to the new linked list
* @param node pointer to a node
* @param head true: be the head in the new list
* false be the tail in the new list
*/
void _lv_ll_chg_list(lv_ll_t * ll_ori_p, lv_ll_t * ll_new_p, void * node, bool head);
/**
* Return with head node of the linked list
* @param ll_p pointer to linked list
* @return pointer to the head of 'll_p'
*/
void * _lv_ll_get_head(const lv_ll_t * ll_p);
/**
* Return with tail node of the linked list
* @param ll_p pointer to linked list
* @return pointer to the tail of 'll_p'
*/
void * _lv_ll_get_tail(const lv_ll_t * ll_p);
/**
* Return with the pointer of the next node after 'n_act'
* @param ll_p pointer to linked list
* @param n_act pointer a node
* @return pointer to the next node
*/
void * _lv_ll_get_next(const lv_ll_t * ll_p, const void * n_act);
/**
* Return with the pointer of the previous node after 'n_act'
* @param ll_p pointer to linked list
* @param n_act pointer a node
* @return pointer to the previous node
*/
void * _lv_ll_get_prev(const lv_ll_t * ll_p, const void * n_act);
/**
* Return the length of the linked list.
* @param ll_p pointer to linked list
* @return length of the linked list
*/
uint32_t _lv_ll_get_len(const lv_ll_t * ll_p);
/**
* TODO
* @param ll_p
* @param n1_p
* @param n2_p
void lv_ll_swap(lv_ll_t * ll_p, void * n1_p, void * n2_p);
*/
/**
* Move a node before an other node in the same linked list
* @param ll_p pointer to a linked list
* @param n_act pointer to node to move
* @param n_after pointer to a node which should be after `n_act`
*/
void _lv_ll_move_before(lv_ll_t * ll_p, void * n_act, void * n_after);
/**
* Check if a linked list is empty
* @param ll_p pointer to a linked list
* @return true: the linked list is empty; false: not empty
*/
bool _lv_ll_is_empty(lv_ll_t * ll_p);
/**********************
* MACROS
**********************/
#define _LV_LL_READ(list, i) for(i = _lv_ll_get_head(list); i != NULL; i = _lv_ll_get_next(list, i))
#define _LV_LL_READ_BACK(list, i) for(i = _lv_ll_get_tail(list); i != NULL; i = _lv_ll_get_prev(list, i))
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_log.c | /**
* @file lv_log.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_log.h"
#if LV_USE_LOG
#include <stdarg.h>
#include <string.h>
#include "../stdlib/lv_sprintf.h"
#include "../stdlib/lv_mem.h"
#include "../stdlib/lv_string.h"
#include "../tick/lv_tick.h"
#include "../core/lv_global.h"
#if LV_LOG_PRINTF
#include <stdio.h>
#endif
/*********************
* DEFINES
*********************/
#if LV_LOG_USE_TIMESTAMP
#define last_log_time LV_GLOBAL_DEFAULT()->log_last_log_time
#endif
#define custom_print_cb LV_GLOBAL_DEFAULT()->custom_log_print_cb
#if LV_LOG_USE_TIMESTAMP
#define LOG_TIMESTAMP_FMT "\t(%" LV_PRIu32 ".%03" LV_PRIu32 ", +%" LV_PRIu32 ")\t"
#define LOG_TIMESTAMP_EXPR t / 1000, t % 1000, t - last_log_time,
#else
#define LOG_TIMESTAMP_FMT
#define LOG_TIMESTAMP_EXPR
#endif
#if LV_LOG_USE_FILE_LINE
#define LOG_FILE_LINE_FMT "\t(in %s line #%d)"
#define LOG_FILE_LINE_EXPR , &file[p], line
#else
#define LOG_FILE_LINE_FMT
#define LOG_FILE_LINE_EXPR
#endif
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Register custom print/write function to call when a log is added.
* It can format its "File path", "Line number" and "Description" as required
* and send the formatted log message to a console or serial port.
* @param print_cb a function pointer to print a log
*/
void lv_log_register_print_cb(lv_log_print_g_cb_t print_cb)
{
custom_print_cb = print_cb;
}
/**
* Add a log
* @param level the level of log. (From `lv_log_level_t` enum)
* @param file name of the file when the log added
* @param line line number in the source code where the log added
* @param func name of the function when the log added
* @param format printf-like format string
* @param ... parameters for `format`
*/
void _lv_log_add(lv_log_level_t level, const char * file, int line, const char * func, const char * format, ...)
{
if(level >= _LV_LOG_LEVEL_NUM) return; /*Invalid level*/
if(level >= LV_LOG_LEVEL) {
va_list args;
va_start(args, format);
#if LV_LOG_USE_FILE_LINE
/*Use only the file name not the path*/
size_t p;
for(p = lv_strlen(file); p > 0; p--) {
if(file[p] == '/' || file[p] == '\\') {
p++; /*Skip the slash*/
break;
}
}
#else
LV_UNUSED(file);
LV_UNUSED(line);
#endif
#if LV_LOG_USE_TIMESTAMP
uint32_t t = lv_tick_get();
#endif
static const char * lvl_prefix[] = {"Trace", "Info", "Warn", "Error", "User"};
#if LV_LOG_PRINTF
printf("[%s]" LOG_TIMESTAMP_FMT " %s: ",
lvl_prefix[level], LOG_TIMESTAMP_EXPR func);
vprintf(format, args);
printf(LOG_FILE_LINE_FMT "\n" LOG_FILE_LINE_EXPR);
#else
if(custom_print_cb) {
char buf[512];
char msg[256];
lv_vsnprintf(msg, sizeof(msg), format, args);
lv_snprintf(buf, sizeof(buf), "[%s]" LOG_TIMESTAMP_FMT " %s: %s" LOG_FILE_LINE_FMT "\n",
lvl_prefix[level], LOG_TIMESTAMP_EXPR func, msg LOG_FILE_LINE_EXPR);
custom_print_cb(level, buf);
}
#endif
#if LV_LOG_USE_TIMESTAMP
last_log_time = t;
#endif
va_end(args);
}
}
void lv_log(const char * format, ...)
{
if(LV_LOG_LEVEL >= LV_LOG_LEVEL_NONE) return; /* disable log */
va_list args;
va_start(args, format);
#if LV_LOG_PRINTF
vprintf(format, args);
#else
if(custom_print_cb) {
char buf[512];
lv_vsnprintf(buf, sizeof(buf), format, args);
custom_print_cb(LV_LOG_LEVEL_USER, buf);
}
#endif
va_end(args);
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif /*LV_USE_LOG*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_fs.c | /**
* @file lv_fs.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_fs.h"
#include <string.h>
#include "../misc/lv_assert.h"
#include "../stdlib/lv_string.h"
#include "lv_ll.h"
#include "../core/lv_global.h"
/*********************
* DEFINES
*********************/
#define fsdrv_ll_p &(LV_GLOBAL_DEFAULT()->fsdrv_ll)
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static const char * lv_fs_get_real_path(const char * path);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void _lv_fs_init(void)
{
_lv_ll_init(fsdrv_ll_p, sizeof(lv_fs_drv_t *));
}
bool lv_fs_is_ready(char letter)
{
lv_fs_drv_t * drv = lv_fs_get_drv(letter);
if(drv == NULL) return false; /*An unknown driver in not ready*/
if(drv->ready_cb == NULL) return true; /*Assume the driver is always ready if no handler provided*/
return drv->ready_cb(drv);
}
lv_fs_res_t lv_fs_open(lv_fs_file_t * file_p, const char * path, lv_fs_mode_t mode)
{
if(path == NULL) {
LV_LOG_WARN("Can't open file: path is NULL");
return LV_FS_RES_INV_PARAM;
}
char letter = path[0];
lv_fs_drv_t * drv = lv_fs_get_drv(letter);
if(drv == NULL) {
LV_LOG_WARN("Can't open file (%s): unknown driver letter", path);
return LV_FS_RES_NOT_EX;
}
if(drv->ready_cb) {
if(drv->ready_cb(drv) == false) {
LV_LOG_WARN("Can't open file (%s): driver not ready", path);
return LV_FS_RES_HW_ERR;
}
}
if(drv->open_cb == NULL) {
LV_LOG_WARN("Can't open file (%s): open function not exists", path);
return LV_FS_RES_NOT_IMP;
}
file_p->drv = drv;
/* For memory-mapped files we set the file handle to our file descriptor so that we can access the cache from the file operations */
if(drv->cache_size == LV_FS_CACHE_FROM_BUFFER) {
file_p->file_d = file_p;
}
else {
const char * real_path = lv_fs_get_real_path(path);
void * file_d = drv->open_cb(drv, real_path, mode);
if(file_d == NULL || file_d == (void *)(-1)) {
return LV_FS_RES_UNKNOWN;
}
file_p->file_d = file_d;
}
if(drv->cache_size) {
file_p->cache = lv_malloc(sizeof(lv_fs_file_cache_t));
LV_ASSERT_MALLOC(file_p->cache);
lv_memzero(file_p->cache, sizeof(lv_fs_file_cache_t));
/* If this is a memory-mapped file, then set "cache" to the memory buffer */
if(drv->cache_size == LV_FS_CACHE_FROM_BUFFER) {
lv_fs_path_ex_t * path_ex = (lv_fs_path_ex_t *)path;
file_p->cache->buffer = (void *)path_ex->buffer;
file_p->cache->start = 0;
file_p->cache->file_position = 0;
file_p->cache->end = path_ex->size;
}
/*Set an invalid range by default*/
else {
file_p->cache->start = UINT32_MAX;
file_p->cache->end = UINT32_MAX - 1;
}
}
return LV_FS_RES_OK;
}
void lv_fs_make_path_from_buffer(lv_fs_path_ex_t * path, char letter, const void * buf, uint32_t size)
{
path->path[0] = letter;
path->path[1] = ':';
path->path[2] = 0;
path->buffer = buf;
path->size = size;
}
lv_fs_res_t lv_fs_close(lv_fs_file_t * file_p)
{
if(file_p->drv == NULL) {
return LV_FS_RES_INV_PARAM;
}
if(file_p->drv->close_cb == NULL) {
return LV_FS_RES_NOT_IMP;
}
lv_fs_res_t res = file_p->drv->close_cb(file_p->drv, file_p->file_d);
if(file_p->drv->cache_size && file_p->cache) {
/* Only free cache if it was pre-allocated (for memory-mapped files it is never allocated) */
if(file_p->drv->cache_size != LV_FS_CACHE_FROM_BUFFER && file_p->cache->buffer) {
lv_free(file_p->cache->buffer);
}
lv_free(file_p->cache);
}
file_p->file_d = NULL;
file_p->drv = NULL;
file_p->cache = NULL;
return res;
}
static lv_fs_res_t lv_fs_read_cached(lv_fs_file_t * file_p, char * buf, uint32_t btr, uint32_t * br)
{
lv_fs_res_t res = LV_FS_RES_OK;
uint32_t file_position = file_p->cache->file_position;
uint32_t start = file_p->cache->start;
uint32_t end = file_p->cache->end;
char * buffer = file_p->cache->buffer;
uint32_t buffer_size = file_p->drv->cache_size;
if(start <= file_position && file_position <= end) {
/* Data can be read from cache buffer */
uint32_t buffer_remaining_length = (uint32_t)end - file_position + 1;
uint32_t buffer_offset = (end - start) - buffer_remaining_length + 1;
/* Do not allow reading beyond the actual memory block for memory-mapped files */
if(file_p->drv->cache_size == LV_FS_CACHE_FROM_BUFFER) {
if(btr > buffer_remaining_length)
btr = buffer_remaining_length - 1;
}
if(btr <= buffer_remaining_length) {
/*Data is in cache buffer, and buffer end not reached, no need to read from FS*/
lv_memcpy(buf, buffer + buffer_offset, btr);
*br = btr;
}
else {
/*First part of data is in cache buffer, but we need to read rest of data from FS*/
lv_memcpy(buf, buffer + buffer_offset, buffer_remaining_length);
file_p->drv->seek_cb(file_p->drv, file_p->file_d, file_p->cache->end + 1,
LV_FS_SEEK_SET);
uint32_t bytes_read_to_buffer = 0;
if(btr - buffer_remaining_length > buffer_size) {
/*If remaining data chuck is bigger than buffer size, then do not use cache, instead read it directly from FS*/
res = file_p->drv->read_cb(file_p->drv, file_p->file_d, (void *)(buf + buffer_remaining_length),
btr - buffer_remaining_length, &bytes_read_to_buffer);
}
else {
/*If remaining data chunk is smaller than buffer size, then read into cache buffer*/
res = file_p->drv->read_cb(file_p->drv, file_p->file_d, (void *)buffer, buffer_size, &bytes_read_to_buffer);
file_p->cache->start = file_p->cache->end + 1;
file_p->cache->end = file_p->cache->start + bytes_read_to_buffer - 1;
uint16_t data_chunk_remaining = LV_MIN(btr - buffer_remaining_length, bytes_read_to_buffer);
lv_memcpy(buf + buffer_remaining_length, buffer, data_chunk_remaining);
}
*br = LV_MIN(buffer_remaining_length + bytes_read_to_buffer, btr);
}
}
else {
file_p->drv->seek_cb(file_p->drv, file_p->file_d, file_p->cache->file_position,
LV_FS_SEEK_SET);
/*Data is not in cache buffer*/
if(btr > buffer_size) {
/*If bigger data is requested, then do not use cache, instead read it directly*/
res = file_p->drv->read_cb(file_p->drv, file_p->file_d, (void *)buf, btr, br);
}
else {
/*If small data is requested, then read from FS into cache buffer*/
if(buffer == NULL) {
file_p->cache->buffer = lv_malloc(buffer_size);
LV_ASSERT_MALLOC(file_p->cache->buffer);
buffer = file_p->cache->buffer;
}
uint32_t bytes_read_to_buffer = 0;
res = file_p->drv->read_cb(file_p->drv, file_p->file_d, (void *)buffer, buffer_size, &bytes_read_to_buffer);
file_p->cache->start = file_position;
file_p->cache->end = file_p->cache->start + bytes_read_to_buffer - 1;
*br = LV_MIN(btr, bytes_read_to_buffer);
lv_memcpy(buf, buffer, *br);
}
}
if(res == LV_FS_RES_OK) {
file_p->cache->file_position += *br;
}
return res;
}
lv_fs_res_t lv_fs_read(lv_fs_file_t * file_p, void * buf, uint32_t btr, uint32_t * br)
{
if(br != NULL) *br = 0;
if(file_p->drv == NULL) return LV_FS_RES_INV_PARAM;
if(file_p->drv->read_cb == NULL) return LV_FS_RES_NOT_IMP;
uint32_t br_tmp = 0;
lv_fs_res_t res;
if(file_p->drv->cache_size) {
res = lv_fs_read_cached(file_p, (char *)buf, btr, &br_tmp);
}
else {
res = file_p->drv->read_cb(file_p->drv, file_p->file_d, buf, btr, &br_tmp);
}
if(br != NULL) *br = br_tmp;
return res;
}
lv_fs_res_t lv_fs_write(lv_fs_file_t * file_p, const void * buf, uint32_t btw, uint32_t * bw)
{
if(bw != NULL) *bw = 0;
if(file_p->drv == NULL) {
return LV_FS_RES_INV_PARAM;
}
if(file_p->drv->write_cb == NULL) {
return LV_FS_RES_NOT_IMP;
}
uint32_t bw_tmp = 0;
lv_fs_res_t res = file_p->drv->write_cb(file_p->drv, file_p->file_d, buf, btw, &bw_tmp);
if(bw != NULL) *bw = bw_tmp;
return res;
}
lv_fs_res_t lv_fs_seek(lv_fs_file_t * file_p, uint32_t pos, lv_fs_whence_t whence)
{
if(file_p->drv == NULL) {
return LV_FS_RES_INV_PARAM;
}
if(file_p->drv->seek_cb == NULL) {
return LV_FS_RES_NOT_IMP;
}
lv_fs_res_t res = LV_FS_RES_OK;
if(file_p->drv->cache_size) {
switch(whence) {
case LV_FS_SEEK_SET: {
file_p->cache->file_position = pos;
/*FS seek if new position is outside cache buffer*/
if(file_p->cache->file_position < file_p->cache->start || file_p->cache->file_position > file_p->cache->end) {
res = file_p->drv->seek_cb(file_p->drv, file_p->file_d, file_p->cache->file_position, LV_FS_SEEK_SET);
}
break;
}
case LV_FS_SEEK_CUR: {
file_p->cache->file_position += pos;
/*FS seek if new position is outside cache buffer*/
if(file_p->cache->file_position < file_p->cache->start || file_p->cache->file_position > file_p->cache->end) {
res = file_p->drv->seek_cb(file_p->drv, file_p->file_d, file_p->cache->file_position, LV_FS_SEEK_SET);
}
break;
}
case LV_FS_SEEK_END: {
/*Because we don't know the file size, we do a little trick: do a FS seek, then get the new file position from FS*/
res = file_p->drv->seek_cb(file_p->drv, file_p->file_d, pos, whence);
if(res == LV_FS_RES_OK) {
uint32_t tmp_position;
res = file_p->drv->tell_cb(file_p->drv, file_p->file_d, &tmp_position);
if(res == LV_FS_RES_OK) {
file_p->cache->file_position = tmp_position;
}
}
break;
}
}
}
else {
res = file_p->drv->seek_cb(file_p->drv, file_p->file_d, pos, whence);
}
return res;
}
lv_fs_res_t lv_fs_tell(lv_fs_file_t * file_p, uint32_t * pos)
{
if(file_p->drv == NULL) {
*pos = 0;
return LV_FS_RES_INV_PARAM;
}
if(file_p->drv->tell_cb == NULL) {
*pos = 0;
return LV_FS_RES_NOT_IMP;
}
lv_fs_res_t res;
if(file_p->drv->cache_size) {
*pos = file_p->cache->file_position;
res = LV_FS_RES_OK;
}
else {
res = file_p->drv->tell_cb(file_p->drv, file_p->file_d, pos);
}
return res;
}
lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t * rddir_p, const char * path)
{
if(path == NULL) return LV_FS_RES_INV_PARAM;
char letter = path[0];
lv_fs_drv_t * drv = lv_fs_get_drv(letter);
if(drv == NULL) {
return LV_FS_RES_NOT_EX;
}
if(drv->ready_cb) {
if(drv->ready_cb(drv) == false) {
return LV_FS_RES_HW_ERR;
}
}
if(drv->dir_open_cb == NULL) {
return LV_FS_RES_NOT_IMP;
}
const char * real_path = lv_fs_get_real_path(path);
void * dir_d = drv->dir_open_cb(drv, real_path);
if(dir_d == NULL || dir_d == (void *)(-1)) {
return LV_FS_RES_UNKNOWN;
}
rddir_p->drv = drv;
rddir_p->dir_d = dir_d;
return LV_FS_RES_OK;
}
lv_fs_res_t lv_fs_dir_read(lv_fs_dir_t * rddir_p, char * fn)
{
if(rddir_p->drv == NULL || rddir_p->dir_d == NULL) {
fn[0] = '\0';
return LV_FS_RES_INV_PARAM;
}
if(rddir_p->drv->dir_read_cb == NULL) {
fn[0] = '\0';
return LV_FS_RES_NOT_IMP;
}
lv_fs_res_t res = rddir_p->drv->dir_read_cb(rddir_p->drv, rddir_p->dir_d, fn);
return res;
}
lv_fs_res_t lv_fs_dir_close(lv_fs_dir_t * rddir_p)
{
if(rddir_p->drv == NULL || rddir_p->dir_d == NULL) {
return LV_FS_RES_INV_PARAM;
}
if(rddir_p->drv->dir_close_cb == NULL) {
return LV_FS_RES_NOT_IMP;
}
lv_fs_res_t res = rddir_p->drv->dir_close_cb(rddir_p->drv, rddir_p->dir_d);
rddir_p->dir_d = NULL;
rddir_p->drv = NULL;
return res;
}
void lv_fs_drv_init(lv_fs_drv_t * drv)
{
lv_memzero(drv, sizeof(lv_fs_drv_t));
}
void lv_fs_drv_register(lv_fs_drv_t * drv_p)
{
/*Save the new driver*/
lv_fs_drv_t ** new_drv;
new_drv = _lv_ll_ins_head(fsdrv_ll_p);
LV_ASSERT_MALLOC(new_drv);
if(new_drv == NULL) return;
*new_drv = drv_p;
}
lv_fs_drv_t * lv_fs_get_drv(char letter)
{
lv_fs_drv_t ** drv;
_LV_LL_READ(fsdrv_ll_p, drv) {
if((*drv)->letter == letter) {
return *drv;
}
}
return NULL;
}
char * lv_fs_get_letters(char * buf)
{
lv_fs_drv_t ** drv;
uint8_t i = 0;
_LV_LL_READ(fsdrv_ll_p, drv) {
buf[i] = (*drv)->letter;
i++;
}
buf[i] = '\0';
return buf;
}
const char * lv_fs_get_ext(const char * fn)
{
size_t i;
for(i = lv_strlen(fn); i > 0; i--) {
if(fn[i] == '.') {
return &fn[i + 1];
}
else if(fn[i] == '/' || fn[i] == '\\') {
return ""; /*No extension if a '\' or '/' found*/
}
}
return ""; /*Empty string if no '.' in the file name.*/
}
char * lv_fs_up(char * path)
{
size_t len = lv_strlen(path);
if(len == 0) return path;
len--; /*Go before the trailing '\0'*/
/*Ignore trailing '/' or '\'*/
while(path[len] == '/' || path[len] == '\\') {
path[len] = '\0';
if(len > 0)
len--;
else
return path;
}
size_t i;
for(i = len; i > 0; i--) {
if(path[i] == '/' || path[i] == '\\') break;
}
if(i > 0) path[i] = '\0';
return path;
}
const char * lv_fs_get_last(const char * path)
{
size_t len = lv_strlen(path);
if(len == 0) return path;
len--; /*Go before the trailing '\0'*/
/*Ignore trailing '/' or '\'*/
while(path[len] == '/' || path[len] == '\\') {
if(len > 0)
len--;
else
return path;
}
size_t i;
for(i = len; i > 0; i--) {
if(path[i] == '/' || path[i] == '\\') break;
}
/*No '/' or '\' in the path so return with path itself*/
if(i == 0) return path;
return &path[i + 1];
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Skip the driver letter and the possible : after the letter
* @param path path string (E.g. S:/folder/file.txt)
* @return pointer to the beginning of the real path (E.g. /folder/file.txt)
*/
static const char * lv_fs_get_real_path(const char * path)
{
path++; /*Ignore the driver letter*/
if(*path == ':') path++;
return path;
}
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_style.h | /**
* @file lv_style.h
*
*/
#ifndef LV_STYLE_H
#define LV_STYLE_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include <stdbool.h>
#include <stdint.h>
#include "../font/lv_font.h"
#include "lv_color.h"
#include "lv_area.h"
#include "lv_anim.h"
#include "lv_text.h"
#include "lv_types.h"
#include "lv_assert.h"
#include "lv_bidi.h"
#include "../layouts/lv_layout.h"
/*********************
* DEFINES
*********************/
#define LV_STYLE_SENTINEL_VALUE 0xAABBCCDD
/**
* Flags for style behavior
*
* The rest of the flags will have _FLAG added to their name in v9.
*/
#define LV_STYLE_PROP_FLAG_NONE (0)
#define LV_STYLE_PROP_FLAG_INHERITABLE (1 << 0) /*Inherited*/
#define LV_STYLE_PROP_FLAG_EXT_DRAW_UPDATE (1 << 1) /*Requires ext. draw size update when changed*/
#define LV_STYLE_PROP_FLAG_LAYOUT_UPDATE (1 << 2) /*Requires layout update when changed*/
#define LV_STYLE_PROP_FLAG_PARENT_LAYOUT_UPDATE (1 << 3) /*Requires layout update on parent when changed*/
#define LV_STYLE_PROP_FLAG_LAYER_UPDATE (1 << 4) /*Affects layer handling*/
#define LV_STYLE_PROP_FLAG_TRANSFORM (1 << 5) /*Affects the object's transformation*/
#define LV_STYLE_PROP_FLAG_ALL (0x3F) /*Indicating all flags*/
/**
* Other constants
*/
#define LV_SCALE_NONE 256 /*Value for not zooming the image*/
LV_EXPORT_CONST_INT(LV_SCALE_NONE);
// *INDENT-OFF*
#if LV_USE_ASSERT_STYLE
#define LV_STYLE_CONST_INIT(var_name, prop_array) \
const lv_style_t var_name = { \
.sentinel = LV_STYLE_SENTINEL_VALUE, \
.values_and_props = (void*)prop_array, \
.has_group = 0xFFFFFFFF, \
.prop_cnt = 255 \
}
#else
#define LV_STYLE_CONST_INIT(var_name, prop_array) \
const lv_style_t var_name = { \
.values_and_props = prop_array, \
.has_group = 0xFFFFFFFF, \
.prop_cnt = 255, \
}
#endif
// *INDENT-ON*
#define LV_STYLE_CONST_PROPS_END { .prop_ptr = NULL, .value = { .num = 0 } }
/**********************
* TYPEDEFS
**********************/
/**
* Possible options how to blend opaque drawings
*/
enum _lv_blend_mode_t {
LV_BLEND_MODE_NORMAL, /**< Simply mix according to the opacity value*/
LV_BLEND_MODE_ADDITIVE, /**< Add the respective color channels*/
LV_BLEND_MODE_SUBTRACTIVE,/**< Subtract the foreground from the background*/
LV_BLEND_MODE_MULTIPLY, /**< Multiply the foreground and background*/
};
#ifdef DOXYGEN
typedef _lv_blend_mode_t lv_blend_mode_t;
#else
typedef uint8_t lv_blend_mode_t;
#endif /*DOXYGEN*/
/**
* Some options to apply decorations on texts.
* 'OR'ed values can be used.
*/
enum _lv_text_decor_t {
LV_TEXT_DECOR_NONE = 0x00,
LV_TEXT_DECOR_UNDERLINE = 0x01,
LV_TEXT_DECOR_STRIKETHROUGH = 0x02,
};
#ifdef DOXYGEN
typedef _lv_text_decor_t lv_text_decor_t;
#else
typedef uint8_t lv_text_decor_t;
#endif /*DOXYGEN*/
/**
* Selects on which sides border should be drawn
* 'OR'ed values can be used.
*/
enum _lv_border_side_t {
LV_BORDER_SIDE_NONE = 0x00,
LV_BORDER_SIDE_BOTTOM = 0x01,
LV_BORDER_SIDE_TOP = 0x02,
LV_BORDER_SIDE_LEFT = 0x04,
LV_BORDER_SIDE_RIGHT = 0x08,
LV_BORDER_SIDE_FULL = 0x0F,
LV_BORDER_SIDE_INTERNAL = 0x10, /**< FOR matrix-like objects (e.g. Button matrix)*/
};
#ifdef DOXYGEN
typedef _lv_border_side_t lv_border_side_t;
#else
typedef uint8_t lv_border_side_t;
#endif /*DOXYGEN*/
/**
* The direction of the gradient.
*/
enum _lv_grad_dir_t {
LV_GRAD_DIR_NONE, /**< No gradient (the `grad_color` property is ignored)*/
LV_GRAD_DIR_VER, /**< Vertical (top to bottom) gradient*/
LV_GRAD_DIR_HOR, /**< Horizontal (left to right) gradient*/
};
#ifdef DOXYGEN
typedef _lv_grad_dir_t lv_grad_dir_t;
#else
typedef uint8_t lv_grad_dir_t;
#endif /*DOXYGEN*/
/** A gradient stop definition.
* This matches a color and a position in a virtual 0-255 scale.
*/
typedef struct {
lv_color_t color; /**< The stop color */
lv_opa_t opa; /**< The opacity of the color*/
uint8_t frac; /**< The stop position in 1/255 unit */
} lv_gradient_stop_t;
/** A descriptor of a gradient. */
typedef struct {
lv_gradient_stop_t stops[LV_GRADIENT_MAX_STOPS]; /**< A gradient stop array */
uint8_t stops_count; /**< The number of used stops in the array */
lv_grad_dir_t dir : 3; /**< The gradient direction.
* Any of LV_GRAD_DIR_HOR, LV_GRAD_DIR_VER, LV_GRAD_DIR_NONE */
} lv_grad_dsc_t;
/**
* A common type to handle all the property types in the same way.
*/
typedef union {
int32_t num; /**< Number integer number (opacity, enums, booleans or "normal" numbers)*/
const void * ptr; /**< Constant pointers (font, cone text, etc)*/
lv_color_t color; /**< Colors*/
} lv_style_value_t;
/**
* Enumeration of all built in style properties
*
* Props are split into groups of 16. When adding a new prop to a group, ensure it does not overflow into the next one.
*/
enum _lv_style_prop_t {
LV_STYLE_PROP_INV = 0,
/*Group 0*/
LV_STYLE_WIDTH = 1,
LV_STYLE_HEIGHT = 2,
LV_STYLE_MIN_WIDTH = 4,
LV_STYLE_MAX_WIDTH = 5,
LV_STYLE_MIN_HEIGHT = 6,
LV_STYLE_MAX_HEIGHT = 7,
LV_STYLE_X = 8,
LV_STYLE_Y = 9,
LV_STYLE_ALIGN = 10,
LV_STYLE_RADIUS = 12,
/*Group 1*/
LV_STYLE_PAD_TOP = 16,
LV_STYLE_PAD_BOTTOM = 17,
LV_STYLE_PAD_LEFT = 18,
LV_STYLE_PAD_RIGHT = 19,
LV_STYLE_PAD_ROW = 20,
LV_STYLE_PAD_COLUMN = 21,
LV_STYLE_LAYOUT = 22,
LV_STYLE_MARGIN_TOP = 24,
LV_STYLE_MARGIN_BOTTOM = 25,
LV_STYLE_MARGIN_LEFT = 26,
LV_STYLE_MARGIN_RIGHT = 27,
/*Group 2*/
LV_STYLE_BG_COLOR = 28,
LV_STYLE_BG_OPA = 29,
LV_STYLE_BG_GRAD_DIR = 32,
LV_STYLE_BG_MAIN_STOP = 33,
LV_STYLE_BG_GRAD_STOP = 34,
LV_STYLE_BG_GRAD_COLOR = 35,
LV_STYLE_BG_MAIN_OPA = 36,
LV_STYLE_BG_GRAD_OPA = 37,
LV_STYLE_BG_GRAD = 38,
LV_STYLE_BASE_DIR = 39,
LV_STYLE_BG_IMAGE_SRC = 40,
LV_STYLE_BG_IMAGE_OPA = 41,
LV_STYLE_BG_IMAGE_RECOLOR = 42,
LV_STYLE_BG_IMAGE_RECOLOR_OPA = 43,
LV_STYLE_BG_IMAGE_TILED = 44,
LV_STYLE_CLIP_CORNER = 45,
/*Group 3*/
LV_STYLE_BORDER_WIDTH = 48,
LV_STYLE_BORDER_COLOR = 49,
LV_STYLE_BORDER_OPA = 50,
LV_STYLE_BORDER_SIDE = 52,
LV_STYLE_BORDER_POST = 53,
LV_STYLE_OUTLINE_WIDTH = 56,
LV_STYLE_OUTLINE_COLOR = 57,
LV_STYLE_OUTLINE_OPA = 58,
LV_STYLE_OUTLINE_PAD = 59,
/*Group 4*/
LV_STYLE_SHADOW_WIDTH = 60,
LV_STYLE_SHADOW_COLOR = 61,
LV_STYLE_SHADOW_OPA = 62,
LV_STYLE_SHADOW_OFFSET_X = 64,
LV_STYLE_SHADOW_OFFSET_Y = 65,
LV_STYLE_SHADOW_SPREAD = 66,
LV_STYLE_IMAGE_OPA = 68,
LV_STYLE_IMAGE_RECOLOR = 69,
LV_STYLE_IMAGE_RECOLOR_OPA = 70,
LV_STYLE_LINE_WIDTH = 72,
LV_STYLE_LINE_DASH_WIDTH = 73,
LV_STYLE_LINE_DASH_GAP = 74,
LV_STYLE_LINE_ROUNDED = 75,
LV_STYLE_LINE_COLOR = 76,
LV_STYLE_LINE_OPA = 77,
/*Group 5*/
LV_STYLE_ARC_WIDTH = 80,
LV_STYLE_ARC_ROUNDED = 81,
LV_STYLE_ARC_COLOR = 82,
LV_STYLE_ARC_OPA = 83,
LV_STYLE_ARC_IMAGE_SRC = 84,
LV_STYLE_TEXT_COLOR = 88,
LV_STYLE_TEXT_OPA = 89,
LV_STYLE_TEXT_FONT = 90,
LV_STYLE_TEXT_LETTER_SPACE = 91,
LV_STYLE_TEXT_LINE_SPACE = 92,
LV_STYLE_TEXT_DECOR = 93,
LV_STYLE_TEXT_ALIGN = 94,
LV_STYLE_OPA = 95,
LV_STYLE_OPA_LAYERED = 96,
LV_STYLE_COLOR_FILTER_DSC = 97,
LV_STYLE_COLOR_FILTER_OPA = 98,
LV_STYLE_ANIM = 99,
LV_STYLE_ANIM_TIME = 100,
LV_STYLE_ANIM_SPEED = 101,
LV_STYLE_TRANSITION = 102,
LV_STYLE_BLEND_MODE = 103,
LV_STYLE_TRANSFORM_WIDTH = 104,
LV_STYLE_TRANSFORM_HEIGHT = 105,
LV_STYLE_TRANSLATE_X = 106,
LV_STYLE_TRANSLATE_Y = 107,
LV_STYLE_TRANSFORM_SCALE_X = 108,
LV_STYLE_TRANSFORM_SCALE_Y = 109,
LV_STYLE_TRANSFORM_ROTATION = 110,
LV_STYLE_TRANSFORM_PIVOT_X = 111,
LV_STYLE_TRANSFORM_PIVOT_Y = 112,
#if LV_USE_FLEX
LV_STYLE_FLEX_FLOW = 113,
LV_STYLE_FLEX_MAIN_PLACE = 114,
LV_STYLE_FLEX_CROSS_PLACE = 115,
LV_STYLE_FLEX_TRACK_PLACE = 116,
LV_STYLE_FLEX_GROW = 117,
#endif
#if LV_USE_GRID
LV_STYLE_GRID_COLUMN_ALIGN = 118,
LV_STYLE_GRID_ROW_ALIGN = 119,
LV_STYLE_GRID_ROW_DSC_ARRAY = 120,
LV_STYLE_GRID_COLUMN_DSC_ARRAY = 121,
LV_STYLE_GRID_CELL_COLUMN_POS = 122,
LV_STYLE_GRID_CELL_COLUMN_SPAN = 123,
LV_STYLE_GRID_CELL_X_ALIGN = 124,
LV_STYLE_GRID_CELL_ROW_POS = 125,
LV_STYLE_GRID_CELL_ROW_SPAN = 126,
LV_STYLE_GRID_CELL_Y_ALIGN = 127,
#endif
_LV_STYLE_LAST_BUILT_IN_PROP = 128,
_LV_STYLE_NUM_BUILT_IN_PROPS = _LV_STYLE_LAST_BUILT_IN_PROP + 1,
LV_STYLE_PROP_ANY = 0xFF,
_LV_STYLE_PROP_CONST = 0xFF /* magic value for const styles */
};
#ifdef DOXYGEN
typedef _lv_style_prop_t lv_style_prop_t;
#else
typedef uint8_t lv_style_prop_t;
#endif /*DOXYGEN*/
enum _lv_style_res_t {
LV_STYLE_RES_NOT_FOUND,
LV_STYLE_RES_FOUND,
};
#ifdef DOXYGEN
typedef _lv_style_res_t lv_style_res_t;
#else
typedef uint8_t lv_style_res_t;
#endif /*DOXYGEN*/
/**
* Descriptor for style transitions
*/
typedef struct {
const lv_style_prop_t * props; /**< An array with the properties to animate.*/
void * user_data; /**< A custom user data that will be passed to the animation's user_data */
lv_anim_path_cb_t path_xcb; /**< A path for the animation.*/
uint32_t time; /**< Duration of the transition in [ms]*/
uint32_t delay; /**< Delay before the transition in [ms]*/
} lv_style_transition_dsc_t;
/**
* Descriptor of a constant style property.
*/
typedef struct {
const lv_style_prop_t * prop_ptr;
lv_style_value_t value;
} lv_style_const_prop_t;
/**
* Descriptor of a style (a collection of properties and values).
*/
typedef struct {
#if LV_USE_ASSERT_STYLE
uint32_t sentinel;
#endif
void * values_and_props;
uint32_t has_group;
uint8_t prop_cnt; /**< 255 means it's a constant style*/
} lv_style_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize a style
* @param style pointer to a style to initialize
* @note Do not call `lv_style_init` on styles that already have some properties
* because this function won't free the used memory, just sets a default state for the style.
* In other words be sure to initialize styles only once!
*/
void lv_style_init(lv_style_t * style);
/**
* Clear all properties from a style and free all allocated memories.
* @param style pointer to a style
*/
void lv_style_reset(lv_style_t * style);
/**
* Check if a style is constant
* @param style pointer to a style
* @return true: the style is constant
*/
static inline bool lv_style_is_const(const lv_style_t * style)
{
if(style->prop_cnt == 255) return true;
return false;
}
/**
* Register a new style property for custom usage
* @return a new property ID, or LV_STYLE_PROP_INV if there are no more available.
* @example
* lv_style_prop_t MY_PROP;
* static inline void lv_style_set_my_prop(lv_style_t * style, lv_color_t value) {
* lv_style_value_t v = {.color = value}; lv_style_set_prop(style, MY_PROP, v); }
*
* ...
* MY_PROP = lv_style_register_prop();
* ...
* lv_style_set_my_prop(&style1, lv_palette_main(LV_PALETTE_RED));
*/
lv_style_prop_t lv_style_register_prop(uint8_t flag);
/**
* Get the number of custom properties that have been registered thus far.
*/
lv_style_prop_t lv_style_get_num_custom_props(void);
/**
* Remove a property from a style
* @param style pointer to a style
* @param prop a style property ORed with a state.
* @return true: the property was found and removed; false: the property wasn't found
*/
bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop);
/**
* Set the value of property in a style.
* This function shouldn't be used directly by the user.
* Instead use `lv_style_set_<prop_name>()`. E.g. `lv_style_set_bg_color()`
* @param style pointer to style
* @param prop the ID of a property (e.g. `LV_STYLE_BG_COLOR`)
* @param value `lv_style_value_t` variable in which a field is set according to the type of `prop`
*/
void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t value);
/**
* Get the value of a property
* @param style pointer to a style
* @param prop the ID of a property
* @param value pointer to a `lv_style_value_t` variable to store the value
* @return LV_RESULT_INVALID: the property wasn't found in the style (`value` is unchanged)
* LV_RESULT_OK: the property was fond, and `value` is set accordingly
* @note For performance reasons there are no sanity check on `style`
*/
lv_style_res_t lv_style_get_prop(const lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value);
/**
* Initialize a transition descriptor.
* @param tr pointer to a transition descriptor to initialize
* @param props an array with the properties to transition. The last element must be zero.
* @param path_cb an animation path (ease) callback. If `NULL` liner path will be used.
* @param time duration of the transition in [ms]
* @param delay delay before the transition in [ms]
* @param user_data any custom data that will be saved in the transition animation and will be available when `path_cb` is called
* @example
* const static lv_style_prop_t trans_props[] = { LV_STYLE_BG_OPA, LV_STYLE_BG_COLOR, 0 };
* static lv_style_transition_dsc_t trans1;
* lv_style_transition_dsc_init(&trans1, trans_props, NULL, 300, 0, NULL);
*/
void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style_prop_t props[],
lv_anim_path_cb_t path_cb, uint32_t time, uint32_t delay, void * user_data);
/**
* Get the default value of a property
* @param prop the ID of a property
* @return the default value
*/
lv_style_value_t lv_style_prop_get_default(lv_style_prop_t prop);
/**
* Get the value of a property
* @param style pointer to a style
* @param prop the ID of a property
* @param value pointer to a `lv_style_value_t` variable to store the value
* @return LV_RESULT_INVALID: the property wasn't found in the style (`value` is unchanged)
* LV_RESULT_OK: the property was fond, and `value` is set accordingly
* @note For performance reasons there are no sanity check on `style`
* @note This function is the same as ::lv_style_get_prop but inlined. Use it only on performance critical places
*/
static inline lv_style_res_t lv_style_get_prop_inlined(const lv_style_t * style, lv_style_prop_t prop,
lv_style_value_t * value)
{
if(lv_style_is_const(style)) {
lv_style_const_prop_t * props = (lv_style_const_prop_t *)style->values_and_props;
uint32_t i;
for(i = 0; props[i].prop_ptr; i++) {
if(*props[i].prop_ptr == prop) {
*value = props[i].value;
return LV_STYLE_RES_FOUND;
}
}
}
else {
lv_style_prop_t * props = (lv_style_prop_t *)style->values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
uint32_t i;
for(i = 0; i < style->prop_cnt; i++) {
if(props[i] == prop) {
lv_style_value_t * values = (lv_style_value_t *)style->values_and_props;
*value = values[i];
return LV_STYLE_RES_FOUND;
}
}
}
return LV_STYLE_RES_NOT_FOUND;
}
/**
* Checks if a style is empty (has no properties)
* @param style pointer to a style
* @return true if the style is empty
*/
bool lv_style_is_empty(const lv_style_t * style);
/**
* Tell the group of a property. If the a property from a group is set in a style the (1 << group) bit of style->has_group is set.
* It allows early skipping the style if the property is not exists in the style at all.
* @param prop a style property
* @return the group [0..30] 30 means all the custom properties with index > 120
*/
static inline uint32_t _lv_style_get_prop_group(lv_style_prop_t prop)
{
uint32_t group = prop >> 2;
if(group > 30) group = 31; /*The MSB marks all the custom properties*/
return group;
}
/**
* Get the flags of a built-in or custom property.
*
* @param prop a style property
* @return the flags of the property
*/
uint8_t _lv_style_prop_lookup_flags(lv_style_prop_t prop);
#include "lv_style_gen.h"
static inline void lv_style_set_size(lv_style_t * style, int32_t width, int32_t height)
{
lv_style_set_width(style, width);
lv_style_set_height(style, height);
}
static inline void lv_style_set_pad_all(lv_style_t * style, int32_t value)
{
lv_style_set_pad_left(style, value);
lv_style_set_pad_right(style, value);
lv_style_set_pad_top(style, value);
lv_style_set_pad_bottom(style, value);
}
static inline void lv_style_set_pad_hor(lv_style_t * style, int32_t value)
{
lv_style_set_pad_left(style, value);
lv_style_set_pad_right(style, value);
}
static inline void lv_style_set_pad_ver(lv_style_t * style, int32_t value)
{
lv_style_set_pad_top(style, value);
lv_style_set_pad_bottom(style, value);
}
static inline void lv_style_set_pad_gap(lv_style_t * style, int32_t value)
{
lv_style_set_pad_row(style, value);
lv_style_set_pad_column(style, value);
}
static inline void lv_style_set_transform_scale(lv_style_t * style, int32_t value)
{
lv_style_set_transform_scale_x(style, value);
lv_style_set_transform_scale_y(style, value);
}
/**
* @brief Check if the style property has a specified behavioral flag.
*
* Do not pass multiple flags to this function as backwards-compatibility is not guaranteed
* for that.
*
* @param prop Property ID
* @param flag Flag
* @return true if the flag is set for this property
*/
static inline bool lv_style_prop_has_flag(lv_style_prop_t prop, uint8_t flag)
{
return _lv_style_prop_lookup_flags(prop) & flag;
}
/*************************
* GLOBAL VARIABLES
*************************/
extern const lv_style_prop_t lv_style_const_prop_id_inv;
/**********************
* MACROS
**********************/
#if LV_USE_ASSERT_STYLE
# define LV_ASSERT_STYLE(style_p) \
do { \
LV_ASSERT_MSG(style_p != NULL, "The style is NULL"); \
LV_ASSERT_MSG(style_p->sentinel == LV_STYLE_SENTINEL_VALUE, "Style is not initialized or corrupted"); \
} while(0)
#else
# define LV_ASSERT_STYLE(p) do{}while(0)
#endif
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_STYLE_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_math.c | /**
* @file lv_math.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_math.h"
#include "../core/lv_global.h"
/*********************
* DEFINES
*********************/
#define rand_seed LV_GLOBAL_DEFAULT()->math_rand_seed
/**********************
* TYPEDEFS
**********************/
#define CUBIC_NEWTON_ITERATIONS 8
#define CUBIC_PRECISION_BITS 10 /* 10 or 14 bits recommended, int64_t calculation is used for >14bit precision */
#if CUBIC_PRECISION_BITS < 10 || CUBIC_PRECISION_BITS > 20
#error "cubic precision bits should be in range of [10, 20] for 32bit/64bit calculations."
#endif
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static const uint16_t sin0_90_table[] = {
0, 572, 1144, 1715, 2286, 2856, 3425, 3993, 4560, 5126, 5690, 6252, 6813, 7371, 7927, 8481,
9032, 9580, 10126, 10668, 11207, 11743, 12275, 12803, 13328, 13848, 14365, 14876, 15384, 15886, 16384, 16877,
17364, 17847, 18324, 18795, 19261, 19720, 20174, 20622, 21063, 21498, 21926, 22348, 22763, 23170, 23571, 23965,
24351, 24730, 25102, 25466, 25822, 26170, 26510, 26842, 27166, 27482, 27789, 28088, 28378, 28660, 28932, 29197,
29452, 29698, 29935, 30163, 30382, 30592, 30792, 30983, 31164, 31336, 31499, 31651, 31795, 31928, 32052, 32166,
32270, 32365, 32449, 32524, 32588, 32643, 32688, 32723, 32748, 32763, 32768
};
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Return with sinus of an angle
* @param angle
* @return sinus of 'angle'. sin(-90) = -32767, sin(90) = 32767
*/
LV_ATTRIBUTE_FAST_MEM int32_t lv_trigo_sin(int16_t angle)
{
int32_t ret = 0;
while(angle < 0) angle += 360;
while(angle >= 360) angle -= 360;
if(angle < 90) {
ret = sin0_90_table[angle];
}
else if(angle >= 90 && angle < 180) {
angle = 180 - angle;
ret = sin0_90_table[angle];
}
else if(angle >= 180 && angle < 270) {
angle = angle - 180;
ret = -sin0_90_table[angle];
}
else { /*angle >=270*/
angle = 360 - angle;
ret = -sin0_90_table[angle];
}
if(ret == 32767) return 32768;
else if(ret == -32767) return -32768;
else return ret;
}
/**
* cubic-bezier Reference:
*
* https://github.com/gre/bezier-easing
* https://opensource.apple.com/source/WebCore/WebCore-955.66/platform/graphics/UnitBezier.h
*
* Copyright (c) 2014 Gaëtan Renaudeau
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
*/
static int32_t do_cubic_bezier(int32_t t, int32_t a, int32_t b, int32_t c)
{
/*a * t^3 + b * t^2 + c * t*/
#if CUBIC_PRECISION_BITS > 14
int64_t ret;
#else
int32_t ret;
#endif
ret = a;
ret = (ret * t) >> CUBIC_PRECISION_BITS;
ret = ((ret + b) * t) >> CUBIC_PRECISION_BITS;
ret = ((ret + c) * t) >> CUBIC_PRECISION_BITS;
return ret;
}
/**
* Calculate the y value of cubic-bezier(x1, y1, x2, y2) function as specified x.
* @param x time in range of [0..LV_BEZIER_VAL_MAX]
* @param x1 x of control point 1 in range of [0..LV_BEZIER_VAL_MAX]
* @param y1 y of control point 1 in range of [0..LV_BEZIER_VAL_MAX]
* @param x2 x of control point 2 in range of [0..LV_BEZIER_VAL_MAX]
* @param y2 y of control point 2 in range of [0..LV_BEZIER_VAL_MAX]
* @return the value calculated
*/
int32_t lv_cubic_bezier(int32_t x, int32_t x1, int32_t y1, int32_t x2, int32_t y2)
{
int32_t ax, bx, cx, ay, by, cy;
int32_t tl, tr, t; /*t in cubic-bezier function, used for bisection */
int32_t xs; /*x sampled on curve */
#if CUBIC_PRECISION_BITS > 14
int64_t d; /*slope value at specified t*/
#else
int32_t d;
#endif
if(x == 0 || x == LV_BEZIER_VAL_MAX) return x;
/* input is always LV_BEZIER_VAL_SHIFT bit precision */
#if CUBIC_PRECISION_BITS != LV_BEZIER_VAL_SHIFT
x <<= CUBIC_PRECISION_BITS - LV_BEZIER_VAL_SHIFT;
x1 <<= CUBIC_PRECISION_BITS - LV_BEZIER_VAL_SHIFT;
x2 <<= CUBIC_PRECISION_BITS - LV_BEZIER_VAL_SHIFT;
y1 <<= CUBIC_PRECISION_BITS - LV_BEZIER_VAL_SHIFT;
y2 <<= CUBIC_PRECISION_BITS - LV_BEZIER_VAL_SHIFT;
#endif
cx = 3 * x1;
bx = 3 * (x2 - x1) - cx;
ax = (1L << CUBIC_PRECISION_BITS) - cx - bx;
cy = 3 * y1;
by = 3 * (y2 - y1) - cy;
ay = (1L << CUBIC_PRECISION_BITS) - cy - by;
/*Try Newton's method firstly */
t = x; /*Make a guess*/
for(int i = 0; i < CUBIC_NEWTON_ITERATIONS; i++) {
/*Check if x on curve at t matches input x*/
xs = do_cubic_bezier(t, ax, bx, cx) - x;
if(LV_ABS(xs) <= 1) goto found;
/* get slop at t, d = 3 * ax * t^2 + 2 * bx + t + cx */
d = ax; /* use 64bit operation if needed. */
d = (3 * d * t) >> CUBIC_PRECISION_BITS;
d = ((d + 2 * bx) * t) >> CUBIC_PRECISION_BITS;
d += cx;
if(LV_ABS(d) <= 1) break;
d = ((int64_t)xs * (1L << CUBIC_PRECISION_BITS)) / d;
if(d == 0) break; /*Reached precision limits*/
t -= d;
}
/*Fallback to bisection method for reliability*/
tl = 0, tr = 1L << CUBIC_PRECISION_BITS, t = x;
if(t < tl) {
t = tl;
goto found;
}
if(t > tr) {
t = tr;
goto found;
}
while(tl < tr) {
xs = do_cubic_bezier(t, ax, bx, cx);
if(LV_ABS(xs - x) <= 1) goto found;
x > xs ? (tl = t) : (tr = t);
t = (tr - tl) / 2 + tl;
if(t == tl) break;
}
/*Failed to find suitable t for given x, return a value anyway.*/
found:
/*Return y at t*/
#if CUBIC_PRECISION_BITS != LV_BEZIER_VAL_SHIFT
return do_cubic_bezier(t, ay, by, cy) >> (CUBIC_PRECISION_BITS - LV_BEZIER_VAL_SHIFT);
#else
return do_cubic_bezier(t, ay, by, cy);
#endif
}
/**
* Get the square root of a number
* @param x integer which square root should be calculated
* @param q store the result here. q->i: integer part, q->f: fractional part in 1/256 unit
* @param mask optional to skip some iterations if the magnitude of the root is known.
* Set to 0x8000 by default.
* If root < 16: mask = 0x80
* If root < 256: mask = 0x800
* Else: mask = 0x8000
*/
LV_ATTRIBUTE_FAST_MEM void lv_sqrt(uint32_t x, lv_sqrt_res_t * q, uint32_t mask)
{
x = x << 8; /*To get 4 bit precision. (sqrt(256) = 16 = 4 bit)*/
uint32_t root = 0;
uint32_t trial;
// http://ww1.microchip.com/...en/AppNotes/91040a.pdf
do {
trial = root + mask;
if(trial * trial <= x) root = trial;
mask = mask >> 1;
} while(mask);
q->i = root >> 4;
q->f = (root & 0xf) << 4;
}
/**
* Calculate the atan2 of a vector.
* @param x
* @param y
* @return the angle in degree calculated from the given parameters in range of [0..360]
*/
uint16_t lv_atan2(int x, int y)
{
// Fast XY vector to integer degree algorithm - Jan 2011 www.RomanBlack.com
// Converts any XY values including 0 to a degree value that should be
// within +/- 1 degree of the accurate value without needing
// large slow trig functions like ArcTan() or ArcCos().
// NOTE! at least one of the X or Y values must be non-zero!
// This is the full version, for all 4 quadrants and will generate
// the angle in integer degrees from 0-360.
// Any values of X and Y are usable including negative values provided
// they are between -1456 and 1456 so the 16bit multiply does not overflow.
unsigned char negflag;
unsigned char tempdegree;
unsigned char comp;
unsigned int degree; // this will hold the result
unsigned int ux;
unsigned int uy;
// Save the sign flags then remove signs and get XY as unsigned ints
negflag = 0;
if(x < 0) {
negflag += 0x01; // x flag bit
x = (0 - x); // is now +
}
ux = x; // copy to unsigned var before multiply
if(y < 0) {
negflag += 0x02; // y flag bit
y = (0 - y); // is now +
}
uy = y; // copy to unsigned var before multiply
// 1. Calc the scaled "degrees"
if(ux > uy) {
degree = (uy * 45) / ux; // degree result will be 0-45 range
negflag += 0x10; // octant flag bit
}
else {
degree = (ux * 45) / uy; // degree result will be 0-45 range
}
// 2. Compensate for the 4 degree error curve
comp = 0;
tempdegree = degree; // use an unsigned char for speed!
if(tempdegree > 22) { // if top half of range
if(tempdegree <= 44) comp++;
if(tempdegree <= 41) comp++;
if(tempdegree <= 37) comp++;
if(tempdegree <= 32) comp++; // max is 4 degrees compensated
}
else { // else is lower half of range
if(tempdegree >= 2) comp++;
if(tempdegree >= 6) comp++;
if(tempdegree >= 10) comp++;
if(tempdegree >= 15) comp++; // max is 4 degrees compensated
}
degree += comp; // degree is now accurate to +/- 1 degree!
// Invert degree if it was X>Y octant, makes 0-45 into 90-45
if(negflag & 0x10) degree = (90 - degree);
// 3. Degree is now 0-90 range for this quadrant,
// need to invert it for whichever quadrant it was in
if(negflag & 0x02) { // if -Y
if(negflag & 0x01) // if -Y -X
degree = (180 + degree);
else // else is -Y +X
degree = (180 - degree);
}
else { // else is +Y
if(negflag & 0x01) // if +Y -X
degree = (360 - degree);
}
return degree;
}
/**
* Calculate the integer exponents.
* @param base
* @param power
* @return base raised to the power exponent
*/
int64_t lv_pow(int64_t base, int8_t exp)
{
int64_t result = 1;
while(exp) {
if(exp & 1)
result *= base;
exp >>= 1;
base *= base;
}
return result;
}
/**
* Get the mapped of a number given an input and output range
* @param x integer which mapped value should be calculated
* @param min_in min input range
* @param max_in max input range
* @param min_out max output range
* @param max_out max output range
* @return the mapped number
*/
int32_t lv_map(int32_t x, int32_t min_in, int32_t max_in, int32_t min_out, int32_t max_out)
{
if(max_in >= min_in && x >= max_in) return max_out;
if(max_in >= min_in && x <= min_in) return min_out;
if(max_in <= min_in && x <= max_in) return max_out;
if(max_in <= min_in && x >= min_in) return min_out;
/**
* The equation should be:
* ((x - min_in) * delta_out) / delta in) + min_out
* To avoid rounding error reorder the operations:
* (x - min_in) * (delta_out / delta_min) + min_out
*/
int32_t delta_in = max_in - min_in;
int32_t delta_out = max_out - min_out;
return ((x - min_in) * delta_out) / delta_in + min_out;
}
uint32_t lv_rand(uint32_t min, uint32_t max)
{
/*Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs"*/
uint32_t x = rand_seed;
x ^= x << 13;
x ^= x >> 17;
x ^= x << 5;
rand_seed = x;
return (rand_seed % (max - min + 1)) + min;
}
/**********************
* STATIC FUNCTIONS
**********************/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_anim_timeline.h | /**
* @file lv_anim_timeline.h
*
*/
#ifndef LV_ANIM_TIMELINE_H
#define LV_ANIM_TIMELINE_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lv_anim.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/*Data of anim_timeline_dsc*/
typedef struct {
lv_anim_t anim;
uint32_t start_time;
} lv_anim_timeline_dsc_t;
/*Data of anim_timeline*/
typedef struct {
lv_anim_timeline_dsc_t * anim_dsc; /**< Dynamically allocated anim dsc array*/
uint32_t anim_dsc_cnt; /**< The length of anim dsc array*/
bool reverse; /**< Reverse playback*/
} lv_anim_timeline_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create an animation timeline.
* @return pointer to the animation timeline.
*/
lv_anim_timeline_t * lv_anim_timeline_create(void);
/**
* Delete animation timeline.
* @param at pointer to the animation timeline.
*/
void lv_anim_timeline_delete(lv_anim_timeline_t * at);
/**
* Add animation to the animation timeline.
* @param at pointer to the animation timeline.
* @param start_time the time the animation started on the timeline, note that start_time will override the value of delay.
* @param a pointer to an animation.
*/
void lv_anim_timeline_add(lv_anim_timeline_t * at, uint32_t start_time, lv_anim_t * a);
/**
* Start the animation timeline.
* @param at pointer to the animation timeline.
* @return total time spent in animation timeline.
*/
uint32_t lv_anim_timeline_start(lv_anim_timeline_t * at);
/**
* Stop the animation timeline.
* @param at pointer to the animation timeline.
*/
void lv_anim_timeline_stop(lv_anim_timeline_t * at);
/**
* Set the playback direction of the animation timeline.
* @param at pointer to the animation timeline.
* @param reverse whether to play in reverse.
*/
void lv_anim_timeline_set_reverse(lv_anim_timeline_t * at, bool reverse);
/**
* Set the progress of the animation timeline.
* @param at pointer to the animation timeline.
* @param progress set value 0~65535 to map 0~100% animation progress.
*/
void lv_anim_timeline_set_progress(lv_anim_timeline_t * at, uint16_t progress);
/**
* Get the time used to play the animation timeline.
* @param at pointer to the animation timeline.
* @return total time spent in animation timeline.
*/
uint32_t lv_anim_timeline_get_playtime(lv_anim_timeline_t * at);
/**
* Get whether the animation timeline is played in reverse.
* @param at pointer to the animation timeline.
* @return return true if it is reverse playback.
*/
bool lv_anim_timeline_get_reverse(lv_anim_timeline_t * at);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_ANIM_TIMELINE_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_cache.h | /**
* @file lv_cache.h
*
*/
#ifndef LV_CACHE_H
#define LV_CACHE_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include <stdint.h>
#include <stddef.h>
#include "../osal/lv_os.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef enum {
LV_CACHE_SRC_TYPE_PTR,
LV_CACHE_SRC_TYPE_STR,
_LV_CACHE_SRC_TYPE_LAST,
} lv_cache_src_type_t;
typedef struct _lv_cache_entry_t {
/**The image source or other source related to the cache content.*/
const void * src;
lv_cache_src_type_t src_type;
/** Some extra parameters to describe the source. E.g. the current frame of an animation*/
uint32_t param1;
uint32_t param2;
/** User processing tag*/
uint32_t process_state;
/** The data to cache*/
const void * data;
/** Size of data in bytes*/
uint32_t data_size;
/** On access to any cache entry, `life` of each cache entry will be incremented by their own `weight` to keep the entry alive longer*/
uint32_t weight;
/** The current `life`. Entries with the smallest life will be purged from the cache if a new entry needs to be cached*/
int32_t life;
/** Count how many times the cached data is being used.
* It will be incremented in lv_cache_get_data and decremented in lv_cache_release.
* A data will dropped from the cache only if its usage_count is zero */
uint32_t usage_count;
/** Call `lv_free` on `src` when the entry is removed from the cache */
uint32_t free_src : 1;
/** Call `lv_draw_buf_free` on `data` when the entry is removed from the cache */
uint32_t free_data : 1;
/** The cache entry was larger then the max cache size so only a temporary entry was allocated
* The entry will be closed and freed in `lv_cache_release` automatically*/
uint32_t temporary : 1;
/**Any user data if needed*/
void * user_data;
} lv_cache_entry_t;
/**
* Add a new entry to the cache with the given size.
* It won't allocate any buffers just free enough space to be a new entry
* with `size` bytes fits.
* @param size the size of the new entry in bytes
* @return a handler for the new cache entry
*/
typedef lv_cache_entry_t * (*lv_cache_add_cb)(size_t size);
/**
* Find a cache entry
* @param src_ptr pointer to the source data
* @param src_type source type (`LV_CACHE_SRC_TYPE_PTR` or `LV_CACHE_SRC_TYPE_STR`)
* @param param1 param1, which was set when the cache was added
* @param param2 param2, which was set when the cache was added
* @return the cache entry with given source and parameters or NULL if not found
*/
typedef lv_cache_entry_t * (*lv_cache_find_cb)(const void * src_ptr, lv_cache_src_type_t src_type, uint32_t param1,
uint32_t param2);
/**
* Invalidate (drop) a cache entry
* @param entry the entry to invalidate. (can be retrieved by `lv_cache_find()`)
*/
typedef void (*lv_cache_invalidate_cb)(lv_cache_entry_t * entry);
/**
* Get the data of a cache entry.
* It is considered a cached data access so the cache manager can count that
* this entry was used on more times, and therefore it's more relevant.
* It also increments entry->usage_count to indicate that the data is being used
* and cannot be dropped.
* @param entry the cache entry whose data should be retrieved
*/
typedef const void * (*lv_cache_get_data_cb)(lv_cache_entry_t * entry);
/**
* Mark the cache entry as unused. It decrements entry->usage_count.
* @param entry the cache entry to invalidate
*/
typedef void (*lv_cache_release_cb)(lv_cache_entry_t * entry);
/**
* Set maximum cache size in bytes.
* @param size the max size in byes
*/
typedef void (*lv_cache_set_max_size_cb)(size_t size);
/**
* Empty the cache.
*/
typedef void (*lv_cache_empty_cb)(void);
typedef struct {
lv_cache_add_cb add_cb;
lv_cache_find_cb find_cb;
lv_cache_invalidate_cb invalidate_cb;
lv_cache_get_data_cb get_data_cb;
lv_cache_release_cb release_cb;
lv_cache_set_max_size_cb set_max_size_cb;
lv_cache_empty_cb empty_cb;
lv_mutex_t mutex;
size_t max_size;
uint32_t locked : 1; /**< Show the mutex state, used to log unlocked cache access*/
} lv_cache_manager_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize the cache module
*/
void _lv_cache_init(void);
/**
* Set new cache manager
* @param manager the new cache manager with callback functions set
*/
void lv_cache_set_manager(lv_cache_manager_t * manager);
/**
* Add a new entry to the cache with the given size.
* It won't allocate any buffers just free enough space to be a new entry
* with `size` bytes fits.
* @param size the size of the new entry in bytes
* @return a handler for the new cache entry
*/
lv_cache_entry_t * lv_cache_add(size_t size);
/**
* Find a cache entry with pointer source type
* @param src_ptr pointer to the source data
* @param src_type source type (`LV_CACHE_SRC_TYPE_PTR` or `LV_CACHE_SRC_TYPE_STR`)
* @param param1 param1, which was set when the cache was added
* @param param2 param2, which was set when the cache was added
* @return the cache entry with given source and parameters or NULL if not found
*/
lv_cache_entry_t * lv_cache_find(const void * src, lv_cache_src_type_t src_type, uint32_t param1, uint32_t param2);
/**
* Invalidate (drop) a cache entry
* @param entry the entry to invalidate. (can be retrieved by `lv_cache_find()`)
*/
void lv_cache_invalidate(lv_cache_entry_t * entry);
/**
* Get the data of a cache entry.
* It is considered a cached data access so the cache manager can count that
* this entry was used on more times, and therefore it's more relevant.
* It also increments entry->usage_count to indicate that the data is being used
* and cannot be dropped.
* @param entry the cache entry whose data should be retrieved
*/
const void * lv_cache_get_data(lv_cache_entry_t * entry);
/**
* Mark the cache entry as unused. It decrements entry->usage_count.
* @param entry
*/
void lv_cache_release(lv_cache_entry_t * entry);
/**
* Set maximum cache size in bytes.
* @param size the max size in byes
*/
void lv_cache_set_max_size(size_t size);
/**
* Get the max size of the cache
* @return the max size in bytes
*/
size_t lv_cache_get_max_size(void);
/**
* Lock the mutex of the cache.
* Needs to be called manually before any cache operation,
*/
void lv_cache_lock(void);
/**
* Unlock the mutex of the cache.
* Needs to be called manually after any cache operation,
*/
void lv_cache_unlock(void);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_CACHE_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_async.h | /**
* @file lv_async.h
*
*/
#ifndef LV_ASYNC_H
#define LV_ASYNC_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lv_types.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**
* Type for async callback.
*/
typedef void (*lv_async_cb_t)(void *);
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Call an asynchronous function the next time lv_timer_handler() is run. This function is likely to return
* **before** the call actually happens!
* @param async_xcb a callback which is the task itself.
* (the 'x' in the argument name indicates that it's not a fully generic function because it not follows
* the `func_name(object, callback, ...)` convention)
* @param user_data custom parameter
*/
lv_result_t lv_async_call(lv_async_cb_t async_xcb, void * user_data);
/**
* Cancel an asynchronous function call
* @param async_xcb a callback which is the task itself.
* @param user_data custom parameter
*/
lv_result_t lv_async_call_cancel(lv_async_cb_t async_xcb, void * user_data);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_ASYNC_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_utils.c | /**
* @file lv_utils.c
*
*/
/*********************
* INCLUDES
*********************/
#include <stddef.h>
#include "lv_utils.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/** Searches base[0] to base[n - 1] for an item that matches *key.
*
* @note The function cmp must return negative if its first
* argument (the search key) is less than its second (a table entry),
* zero if equal, and positive if greater.
*
* @note Items in the array must be in ascending order.
*
* @param key Pointer to item being searched for
* @param base Pointer to first element to search
* @param n Number of elements
* @param size Size of each element
* @param cmp Pointer to comparison function (see #unicode_list_compare as a comparison function
* example)
*
* @return a pointer to a matching item, or NULL if none exists.
*/
void * _lv_utils_bsearch(const void * key, const void * base, uint32_t n, uint32_t size,
int32_t (*cmp)(const void * pRef, const void * pElement))
{
const char * middle;
int32_t c;
for(middle = base; n != 0;) {
middle += (n / 2) * size;
if((c = (*cmp)(key, middle)) > 0) {
n = (n / 2) - ((n & 1) == 0);
base = (middle += size);
}
else if(c < 0) {
n /= 2;
middle = base;
}
else {
return (char *)middle;
}
}
return NULL;
}
/**********************
* STATIC FUNCTIONS
**********************/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_fs.h | /**
* @file lv_fs.h
*
*/
#ifndef LV_FS_H
#define LV_FS_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#include <stdint.h>
#include <stdbool.h>
/*********************
* DEFINES
*********************/
#define LV_FS_MAX_FN_LENGTH 64
#define LV_FS_MAX_PATH_LENGTH 256
#define LV_FS_CACHE_FROM_BUFFER UINT32_MAX
/**********************
* TYPEDEFS
**********************/
/**
* Errors in the file system module.
*/
enum _lv_fs_res_t {
LV_FS_RES_OK = 0,
LV_FS_RES_HW_ERR, /*Low level hardware error*/
LV_FS_RES_FS_ERR, /*Error in the file system structure*/
LV_FS_RES_NOT_EX, /*Driver, file or directory is not exists*/
LV_FS_RES_FULL, /*Disk full*/
LV_FS_RES_LOCKED, /*The file is already opened*/
LV_FS_RES_DENIED, /*Access denied. Check 'fs_open' modes and write protect*/
LV_FS_RES_BUSY, /*The file system now can't handle it, try later*/
LV_FS_RES_TOUT, /*Process time outed*/
LV_FS_RES_NOT_IMP, /*Requested function is not implemented*/
LV_FS_RES_OUT_OF_MEM, /*Not enough memory for an internal operation*/
LV_FS_RES_INV_PARAM, /*Invalid parameter among arguments*/
LV_FS_RES_UNKNOWN, /*Other unknown error*/
};
#ifdef DOXYGEN
typedef _lv_fs_res_t lv_fs_res_t;
#else
typedef uint8_t lv_fs_res_t;
#endif /*DOXYGEN*/
/**
* File open mode.
*/
enum _lv_fs_mode_t {
LV_FS_MODE_WR = 0x01,
LV_FS_MODE_RD = 0x02,
};
#ifdef DOXYGEN
typedef _lv_fs_mode_t lv_fs_mode_t;
#else
typedef uint8_t lv_fs_mode_t;
#endif /*DOXYGEN*/
/**
* Seek modes.
*/
typedef enum {
LV_FS_SEEK_SET = 0x00, /**< Set the position from absolutely (from the start of file)*/
LV_FS_SEEK_CUR = 0x01, /**< Set the position from the current position*/
LV_FS_SEEK_END = 0x02, /**< Set the position from the end of the file*/
} lv_fs_whence_t;
typedef struct _lv_fs_drv_t {
char letter;
uint32_t cache_size;
bool (*ready_cb)(struct _lv_fs_drv_t * drv);
void * (*open_cb)(struct _lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode);
lv_fs_res_t (*close_cb)(struct _lv_fs_drv_t * drv, void * file_p);
lv_fs_res_t (*read_cb)(struct _lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br);
lv_fs_res_t (*write_cb)(struct _lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw);
lv_fs_res_t (*seek_cb)(struct _lv_fs_drv_t * drv, void * file_p, uint32_t pos, lv_fs_whence_t whence);
lv_fs_res_t (*tell_cb)(struct _lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p);
void * (*dir_open_cb)(struct _lv_fs_drv_t * drv, const char * path);
lv_fs_res_t (*dir_read_cb)(struct _lv_fs_drv_t * drv, void * rddir_p, char * fn);
lv_fs_res_t (*dir_close_cb)(struct _lv_fs_drv_t * drv, void * rddir_p);
void * user_data; /**< Custom file user data*/
} lv_fs_drv_t;
typedef struct {
uint32_t start;
uint32_t end;
uint32_t file_position;
void * buffer;
} lv_fs_file_cache_t;
typedef struct {
void * file_d;
lv_fs_drv_t * drv;
lv_fs_file_cache_t * cache;
} lv_fs_file_t;
/* Extended path object to specify the buffer for memory-mapped files */
typedef struct {
char path[4]; /* This is needed to make it compatible with a normal path */
const void * buffer;
uint32_t size;
} lv_fs_path_ex_t;
typedef struct {
void * dir_d;
lv_fs_drv_t * drv;
} lv_fs_dir_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize the File system interface
*/
void _lv_fs_init(void);
/**
* Initialize a file system driver with default values.
* It is used to ensure all fields have known values and not memory junk.
* After it you can set the fields.
* @param drv pointer to driver variable to initialize
*/
void lv_fs_drv_init(lv_fs_drv_t * drv);
/**
* Add a new drive
* @param drv pointer to an lv_fs_drv_t structure which is inited with the
* corresponding function pointers. Only pointer is saved, so the
* driver should be static or dynamically allocated.
*/
void lv_fs_drv_register(lv_fs_drv_t * drv);
/**
* Give a pointer to a driver from its letter
* @param letter the driver letter
* @return pointer to a driver or NULL if not found
*/
lv_fs_drv_t * lv_fs_get_drv(char letter);
/**
* Test if a drive is ready or not. If the `ready` function was not initialized `true` will be
* returned.
* @param letter letter of the drive
* @return true: drive is ready; false: drive is not ready
*/
bool lv_fs_is_ready(char letter);
/**
* Open a file
* @param file_p pointer to a lv_fs_file_t variable
* @param path path to the file beginning with the driver letter (e.g. S:/folder/file.txt)
* @param mode read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_fs_open(lv_fs_file_t * file_p, const char * path, lv_fs_mode_t mode);
/**
* Make a path object for the memory-mapped file compatible with the file system interface
* @param path path to a lv_fs_path_ex object
* @param letter the letter of the driver. E.g. `LV_FS_MEMFS_LETTER`
* @param buf address of the memory buffer
* @param size size of the memory buffer in bytes
*/
void lv_fs_make_path_from_buffer(lv_fs_path_ex_t * path, char letter, const void * buf, uint32_t size);
/**
* Close an already opened file
* @param file_p pointer to a lv_fs_file_t variable
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_fs_close(lv_fs_file_t * file_p);
/**
* Read from a file
* @param file_p pointer to a lv_fs_file_t variable
* @param buf pointer to a buffer where the read bytes are stored
* @param btr Bytes To Read
* @param br the number of real read bytes (Bytes Read). NULL if unused.
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_fs_read(lv_fs_file_t * file_p, void * buf, uint32_t btr, uint32_t * br);
/**
* Write into a file
* @param file_p pointer to a lv_fs_file_t variable
* @param buf pointer to a buffer with the bytes to write
* @param btw Bytes To Write
* @param bw the number of real written bytes (Bytes Written). NULL if unused.
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_fs_write(lv_fs_file_t * file_p, const void * buf, uint32_t btw, uint32_t * bw);
/**
* Set the position of the 'cursor' (read write pointer) in a file
* @param file_p pointer to a lv_fs_file_t variable
* @param pos the new position expressed in bytes index (0: start of file)
* @param whence tells from where set the position. See @lv_fs_whence_t
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_fs_seek(lv_fs_file_t * file_p, uint32_t pos, lv_fs_whence_t whence);
/**
* Give the position of the read write pointer
* @param file_p pointer to a lv_fs_file_t variable
* @param pos pointer to store the position of the read write pointer
* @return LV_FS_RES_OK or any error from 'fs_res_t'
*/
lv_fs_res_t lv_fs_tell(lv_fs_file_t * file_p, uint32_t * pos);
/**
* Initialize a 'fs_dir_t' variable for directory reading
* @param rddir_p pointer to a 'lv_fs_dir_t' variable
* @param path path to a directory
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t * rddir_p, const char * path);
/**
* Read the next filename form a directory.
* The name of the directories will begin with '/'
* @param rddir_p pointer to an initialized 'fs_dir_t' variable
* @param fn pointer to a buffer to store the filename
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_fs_dir_read(lv_fs_dir_t * rddir_p, char * fn);
/**
* Close the directory reading
* @param rddir_p pointer to an initialized 'fs_dir_t' variable
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
lv_fs_res_t lv_fs_dir_close(lv_fs_dir_t * rddir_p);
/**
* Fill a buffer with the letters of existing drivers
* @param buf buffer to store the letters ('\0' added after the last letter)
* @return the buffer
*/
char * lv_fs_get_letters(char * buf);
/**
* Return with the extension of the filename
* @param fn string with a filename
* @return pointer to the beginning extension or empty string if no extension
*/
const char * lv_fs_get_ext(const char * fn);
/**
* Step up one level
* @param path pointer to a file name
* @return the truncated file name
*/
char * lv_fs_up(char * path);
/**
* Get the last element of a path (e.g. U:/folder/file -> file)
* @param path pointer to a file name
* @return pointer to the beginning of the last element in the path
*/
const char * lv_fs_get_last(const char * path);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_FS_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_area.h | /**
* @file lv_area.h
*
*/
#ifndef LV_AREA_H
#define LV_AREA_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#include <stdbool.h>
#include <stdint.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**
* Represents a point on the screen.
*/
typedef struct {
int32_t x;
int32_t y;
} lv_point_t;
typedef struct {
lv_value_precise_t x;
lv_value_precise_t y;
} lv_point_precise_t;
/** Represents an area of the screen.*/
typedef struct {
int32_t x1;
int32_t y1;
int32_t x2;
int32_t y2;
} lv_area_t;
/** Alignments*/
enum _lv_align_t {
LV_ALIGN_DEFAULT = 0,
LV_ALIGN_TOP_LEFT,
LV_ALIGN_TOP_MID,
LV_ALIGN_TOP_RIGHT,
LV_ALIGN_BOTTOM_LEFT,
LV_ALIGN_BOTTOM_MID,
LV_ALIGN_BOTTOM_RIGHT,
LV_ALIGN_LEFT_MID,
LV_ALIGN_RIGHT_MID,
LV_ALIGN_CENTER,
LV_ALIGN_OUT_TOP_LEFT,
LV_ALIGN_OUT_TOP_MID,
LV_ALIGN_OUT_TOP_RIGHT,
LV_ALIGN_OUT_BOTTOM_LEFT,
LV_ALIGN_OUT_BOTTOM_MID,
LV_ALIGN_OUT_BOTTOM_RIGHT,
LV_ALIGN_OUT_LEFT_TOP,
LV_ALIGN_OUT_LEFT_MID,
LV_ALIGN_OUT_LEFT_BOTTOM,
LV_ALIGN_OUT_RIGHT_TOP,
LV_ALIGN_OUT_RIGHT_MID,
LV_ALIGN_OUT_RIGHT_BOTTOM,
};
#ifdef DOXYGEN
typedef _lv_align_t lv_align_t;
#else
typedef uint8_t lv_align_t;
#endif /*DOXYGEN*/
enum _lv_dir_t {
LV_DIR_NONE = 0x00,
LV_DIR_LEFT = (1 << 0),
LV_DIR_RIGHT = (1 << 1),
LV_DIR_TOP = (1 << 2),
LV_DIR_BOTTOM = (1 << 3),
LV_DIR_HOR = LV_DIR_LEFT | LV_DIR_RIGHT,
LV_DIR_VER = LV_DIR_TOP | LV_DIR_BOTTOM,
LV_DIR_ALL = LV_DIR_HOR | LV_DIR_VER,
};
#ifdef DOXYGEN
typedef _lv_dir_t lv_dir_t;
#else
typedef uint8_t lv_dir_t;
#endif /*DOXYGEN*/
typedef struct {
int32_t angle_prev;
int32_t sinma;
int32_t cosma;
} lv_area_transform_cache_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize an area
* @param area_p pointer to an area
* @param x1 left coordinate of the area
* @param y1 top coordinate of the area
* @param x2 right coordinate of the area
* @param y2 bottom coordinate of the area
*/
void lv_area_set(lv_area_t * area_p, int32_t x1, int32_t y1, int32_t x2, int32_t y2);
/**
* Copy an area
* @param dest pointer to the destination area
* @param src pointer to the source area
*/
inline static void lv_area_copy(lv_area_t * dest, const lv_area_t * src)
{
dest->x1 = src->x1;
dest->y1 = src->y1;
dest->x2 = src->x2;
dest->y2 = src->y2;
}
/**
* Get the width of an area
* @param area_p pointer to an area
* @return the width of the area (if x1 == x2 -> width = 1)
*/
static inline int32_t lv_area_get_width(const lv_area_t * area_p)
{
return (int32_t)(area_p->x2 - area_p->x1 + 1);
}
/**
* Get the height of an area
* @param area_p pointer to an area
* @return the height of the area (if y1 == y2 -> height = 1)
*/
static inline int32_t lv_area_get_height(const lv_area_t * area_p)
{
return (int32_t)(area_p->y2 - area_p->y1 + 1);
}
/**
* Set the width of an area
* @param area_p pointer to an area
* @param w the new width of the area (w == 1 makes x1 == x2)
*/
void lv_area_set_width(lv_area_t * area_p, int32_t w);
/**
* Set the height of an area
* @param area_p pointer to an area
* @param h the new height of the area (h == 1 makes y1 == y2)
*/
void lv_area_set_height(lv_area_t * area_p, int32_t h);
/**
* Set the position of an area (width and height will be kept)
* @param area_p pointer to an area
* @param x the new x coordinate of the area
* @param y the new y coordinate of the area
*/
void _lv_area_set_pos(lv_area_t * area_p, int32_t x, int32_t y);
/**
* Return with area of an area (x * y)
* @param area_p pointer to an area
* @return size of area
*/
uint32_t lv_area_get_size(const lv_area_t * area_p);
void lv_area_increase(lv_area_t * area, int32_t w_extra, int32_t h_extra);
void lv_area_move(lv_area_t * area, int32_t x_ofs, int32_t y_ofs);
/**
* Get the common parts of two areas
* @param res_p pointer to an area, the result will be stored her
* @param a1_p pointer to the first area
* @param a2_p pointer to the second area
* @return false: the two area has NO common parts, res_p is invalid
*/
bool _lv_area_intersect(lv_area_t * res_p, const lv_area_t * a1_p, const lv_area_t * a2_p);
/**
* Get resulting sub areas after removing the common parts of two areas from the first area
* @param res_p pointer to an array of areas with a count of 4, the resulting areas will be stored here
* @param a1_p pointer to the first area
* @param a2_p pointer to the second area
* @return number of results (max 4) or -1 if no intersect
*/
int8_t _lv_area_diff(lv_area_t res_p[], const lv_area_t * a1_p, const lv_area_t * a2_p);
/**
* Join two areas into a third which involves the other two
* @param a_res_p pointer to an area, the result will be stored here
* @param a1_p pointer to the first area
* @param a2_p pointer to the second area
*/
void _lv_area_join(lv_area_t * a_res_p, const lv_area_t * a1_p, const lv_area_t * a2_p);
/**
* Check if a point is on an area
* @param a_p pointer to an area
* @param p_p pointer to a point
* @param radius radius of area (e.g. for rounded rectangle)
* @return false:the point is out of the area
*/
bool _lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p, int32_t radius);
/**
* Check if two area has common parts
* @param a1_p pointer to an area.
* @param a2_p pointer to an other area
* @return false: a1_p and a2_p has no common parts
*/
bool _lv_area_is_on(const lv_area_t * a1_p, const lv_area_t * a2_p);
/**
* Check if an area is fully on an other
* @param ain_p pointer to an area which could be in 'aholder_p'
* @param aholder_p pointer to an area which could involve 'ain_p'
* @param radius radius of `aholder_p` (e.g. for rounded rectangle)
* @return true: `ain_p` is fully inside `aholder_p`
*/
bool _lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p, int32_t radius);
/**
* Check if an area is fully out of an other
* @param aout_p pointer to an area which could be in 'aholder_p'
* @param aholder_p pointer to an area which could involve 'ain_p'
* @param radius radius of `aholder_p` (e.g. for rounded rectangle)
* @return true: `aout_p` is fully outside `aholder_p`
*/
bool _lv_area_is_out(const lv_area_t * aout_p, const lv_area_t * aholder_p, int32_t radius);
/**
* Check if 2 area is the same
* @param a pointer to an area
* @param b pointer to another area
*/
bool _lv_area_is_equal(const lv_area_t * a, const lv_area_t * b);
/**
* Align an area to an other
* @param base an area where the other will be aligned
* @param to_align the area to align
* @param align `LV_ALIGN_...`
* @param ofs_x X offset
* @param ofs_y Y offset
*/
void lv_area_align(const lv_area_t * base, lv_area_t * to_align, lv_align_t align, int32_t ofs_x, int32_t ofs_y);
void lv_point_transform(lv_point_t * p, int32_t angle, int32_t scale_x, int32_t scale_y, const lv_point_t * pivot,
bool zoom_first);
/**********************
* MACROS
**********************/
#define _LV_COORD_TYPE_SHIFT (29U)
#define _LV_COORD_TYPE_MASK (3 << _LV_COORD_TYPE_SHIFT)
#define _LV_COORD_TYPE(x) ((x) & _LV_COORD_TYPE_MASK) /*Extract type specifiers*/
#define _LV_COORD_PLAIN(x) ((x) & ~_LV_COORD_TYPE_MASK) /*Remove type specifiers*/
#define _LV_COORD_TYPE_PX (0 << _LV_COORD_TYPE_SHIFT)
#define _LV_COORD_TYPE_SPEC (1 << _LV_COORD_TYPE_SHIFT)
#define _LV_COORD_TYPE_PX_NEG (3 << _LV_COORD_TYPE_SHIFT)
#define LV_COORD_IS_PX(x) (_LV_COORD_TYPE(x) == _LV_COORD_TYPE_PX || _LV_COORD_TYPE(x) == _LV_COORD_TYPE_PX_NEG)
#define LV_COORD_IS_SPEC(x) (_LV_COORD_TYPE(x) == _LV_COORD_TYPE_SPEC)
#define LV_COORD_SET_SPEC(x) ((x) | _LV_COORD_TYPE_SPEC)
/*Special coordinates*/
#define LV_PCT(x) (x < 0 ? LV_COORD_SET_SPEC(1000 - (x)) : LV_COORD_SET_SPEC(x))
#define LV_COORD_IS_PCT(x) ((LV_COORD_IS_SPEC(x) && _LV_COORD_PLAIN(x) <= 2000))
#define LV_COORD_GET_PCT(x) (_LV_COORD_PLAIN(x) > 1000 ? 1000 - _LV_COORD_PLAIN(x) : _LV_COORD_PLAIN(x))
#define LV_SIZE_CONTENT LV_COORD_SET_SPEC(2001)
LV_EXPORT_CONST_INT(LV_SIZE_CONTENT);
/*Max coordinate value*/
#define LV_COORD_MAX ((1 << _LV_COORD_TYPE_SHIFT) - 1)
#define LV_COORD_MIN (-LV_COORD_MAX)
LV_EXPORT_CONST_INT(LV_COORD_MAX);
LV_EXPORT_CONST_INT(LV_COORD_MIN);
/**
* Convert a percentage value to `int32_t`.
* Percentage values are stored in special range
* @param x the percentage (0..1000)
* @return a coordinate that stores the percentage
*/
static inline int32_t lv_pct(int32_t x)
{
return LV_PCT(x);
}
static inline int32_t lv_pct_to_px(int32_t v, int32_t base)
{
if(LV_COORD_IS_PCT(v)) {
return (LV_COORD_GET_PCT(v) * base) / 100;
}
return v;
}
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_ll.c | /**
* @file lv_ll.c
* Handle linked lists.
* The nodes are dynamically allocated by the 'lv_mem' module,
*/
/*********************
* INCLUDES
*********************/
#include "lv_ll.h"
#include "../stdlib/lv_mem.h"
/*********************
* DEFINES
*********************/
#define LL_NODE_META_SIZE (sizeof(lv_ll_node_t *) + sizeof(lv_ll_node_t *))
#define LL_PREV_P_OFFSET(ll_p) (ll_p->n_size)
#define LL_NEXT_P_OFFSET(ll_p) (ll_p->n_size + sizeof(lv_ll_node_t *))
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void node_set_prev(lv_ll_t * ll_p, lv_ll_node_t * act, lv_ll_node_t * prev);
static void node_set_next(lv_ll_t * ll_p, lv_ll_node_t * act, lv_ll_node_t * next);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize linked list
* @param ll_p pointer to lv_ll_t variable
* @param node_size the size of 1 node in bytes
*/
void _lv_ll_init(lv_ll_t * ll_p, uint32_t node_size)
{
ll_p->head = NULL;
ll_p->tail = NULL;
#ifdef LV_ARCH_64
/*Round the size up to 8*/
node_size = (node_size + 7) & (~0x7);
#else
/*Round the size up to 4*/
node_size = (node_size + 3) & (~0x3);
#endif
ll_p->n_size = node_size;
}
/**
* Add a new head to a linked list
* @param ll_p pointer to linked list
* @return pointer to the new head
*/
void * _lv_ll_ins_head(lv_ll_t * ll_p)
{
lv_ll_node_t * n_new;
n_new = lv_malloc(ll_p->n_size + LL_NODE_META_SIZE);
if(n_new != NULL) {
node_set_prev(ll_p, n_new, NULL); /*No prev. before the new head*/
node_set_next(ll_p, n_new, ll_p->head); /*After new comes the old head*/
if(ll_p->head != NULL) { /*If there is old head then before it goes the new*/
node_set_prev(ll_p, ll_p->head, n_new);
}
ll_p->head = n_new; /*Set the new head in the dsc.*/
if(ll_p->tail == NULL) { /*If there is no tail (1. node) set the tail too*/
ll_p->tail = n_new;
}
}
return n_new;
}
/**
* Insert a new node in front of the n_act node
* @param ll_p pointer to linked list
* @param n_act pointer a node
* @return pointer to the new node
*/
void * _lv_ll_ins_prev(lv_ll_t * ll_p, void * n_act)
{
lv_ll_node_t * n_new;
if(NULL == ll_p || NULL == n_act) return NULL;
if(_lv_ll_get_head(ll_p) == n_act) {
n_new = _lv_ll_ins_head(ll_p);
if(n_new == NULL) return NULL;
}
else {
n_new = lv_malloc(ll_p->n_size + LL_NODE_META_SIZE);
if(n_new == NULL) return NULL;
lv_ll_node_t * n_prev;
n_prev = _lv_ll_get_prev(ll_p, n_act);
node_set_next(ll_p, n_prev, n_new);
node_set_prev(ll_p, n_new, n_prev);
node_set_prev(ll_p, n_act, n_new);
node_set_next(ll_p, n_new, n_act);
}
return n_new;
}
/**
* Add a new tail to a linked list
* @param ll_p pointer to linked list
* @return pointer to the new tail
*/
void * _lv_ll_ins_tail(lv_ll_t * ll_p)
{
lv_ll_node_t * n_new;
n_new = lv_malloc(ll_p->n_size + LL_NODE_META_SIZE);
if(n_new != NULL) {
node_set_next(ll_p, n_new, NULL); /*No next after the new tail*/
node_set_prev(ll_p, n_new, ll_p->tail); /*The prev. before new is the old tail*/
if(ll_p->tail != NULL) { /*If there is old tail then the new comes after it*/
node_set_next(ll_p, ll_p->tail, n_new);
}
ll_p->tail = n_new; /*Set the new tail in the dsc.*/
if(ll_p->head == NULL) { /*If there is no head (1. node) set the head too*/
ll_p->head = n_new;
}
}
return n_new;
}
/**
* Remove the node 'node_p' from 'll_p' linked list.
* It does not free the memory of node.
* @param ll_p pointer to the linked list of 'node_p'
* @param node_p pointer to node in 'll_p' linked list
*/
void _lv_ll_remove(lv_ll_t * ll_p, void * node_p)
{
if(ll_p == NULL) return;
if(_lv_ll_get_head(ll_p) == node_p) {
/*The new head will be the node after 'n_act'*/
ll_p->head = _lv_ll_get_next(ll_p, node_p);
if(ll_p->head == NULL) {
ll_p->tail = NULL;
}
else {
node_set_prev(ll_p, ll_p->head, NULL);
}
}
else if(_lv_ll_get_tail(ll_p) == node_p) {
/*The new tail will be the node before 'n_act'*/
ll_p->tail = _lv_ll_get_prev(ll_p, node_p);
if(ll_p->tail == NULL) {
ll_p->head = NULL;
}
else {
node_set_next(ll_p, ll_p->tail, NULL);
}
}
else {
lv_ll_node_t * n_prev = _lv_ll_get_prev(ll_p, node_p);
lv_ll_node_t * n_next = _lv_ll_get_next(ll_p, node_p);
node_set_next(ll_p, n_prev, n_next);
node_set_prev(ll_p, n_next, n_prev);
}
}
/**
* Remove and free all elements from a linked list. The list remain valid but become empty.
* @param ll_p pointer to linked list
*/
void _lv_ll_clear(lv_ll_t * ll_p)
{
void * i;
void * i_next;
i = _lv_ll_get_head(ll_p);
i_next = NULL;
while(i != NULL) {
i_next = _lv_ll_get_next(ll_p, i);
_lv_ll_remove(ll_p, i);
lv_free(i);
i = i_next;
}
}
/**
* Move a node to a new linked list
* @param ll_ori_p pointer to the original (old) linked list
* @param ll_new_p pointer to the new linked list
* @param node pointer to a node
* @param head true: be the head in the new list
* false be the tail in the new list
*/
void _lv_ll_chg_list(lv_ll_t * ll_ori_p, lv_ll_t * ll_new_p, void * node, bool head)
{
_lv_ll_remove(ll_ori_p, node);
if(head) {
/*Set node as head*/
node_set_prev(ll_new_p, node, NULL);
node_set_next(ll_new_p, node, ll_new_p->head);
if(ll_new_p->head != NULL) { /*If there is old head then before it goes the new*/
node_set_prev(ll_new_p, ll_new_p->head, node);
}
ll_new_p->head = node; /*Set the new head in the dsc.*/
if(ll_new_p->tail == NULL) { /*If there is no tail (first node) set the tail too*/
ll_new_p->tail = node;
}
}
else {
/*Set node as tail*/
node_set_prev(ll_new_p, node, ll_new_p->tail);
node_set_next(ll_new_p, node, NULL);
if(ll_new_p->tail != NULL) { /*If there is old tail then after it goes the new*/
node_set_next(ll_new_p, ll_new_p->tail, node);
}
ll_new_p->tail = node; /*Set the new tail in the dsc.*/
if(ll_new_p->head == NULL) { /*If there is no head (first node) set the head too*/
ll_new_p->head = node;
}
}
}
/**
* Return with head node of the linked list
* @param ll_p pointer to linked list
* @return pointer to the head of 'll_p'
*/
void * _lv_ll_get_head(const lv_ll_t * ll_p)
{
if(ll_p == NULL) return NULL;
return ll_p->head;
}
/**
* Return with tail node of the linked list
* @param ll_p pointer to linked list
* @return pointer to the tail of 'll_p'
*/
void * _lv_ll_get_tail(const lv_ll_t * ll_p)
{
if(ll_p == NULL) return NULL;
return ll_p->tail;
}
/**
* Return with the pointer of the next node after 'n_act'
* @param ll_p pointer to linked list
* @param n_act pointer a node
* @return pointer to the next node
*/
void * _lv_ll_get_next(const lv_ll_t * ll_p, const void * n_act)
{
/*Pointer to the next node is stored in the end of this node.
*Go there and return the address found there*/
const lv_ll_node_t * n_act_d = n_act;
n_act_d += LL_NEXT_P_OFFSET(ll_p);
return *((lv_ll_node_t **)n_act_d);
}
/**
* Return with the pointer of the previous node before 'n_act'
* @param ll_p pointer to linked list
* @param n_act pointer a node
* @return pointer to the previous node
*/
void * _lv_ll_get_prev(const lv_ll_t * ll_p, const void * n_act)
{
/*Pointer to the prev. node is stored in the end of this node.
*Go there and return the address found there*/
const lv_ll_node_t * n_act_d = n_act;
n_act_d += LL_PREV_P_OFFSET(ll_p);
return *((lv_ll_node_t **)n_act_d);
}
/**
* Return the length of the linked list.
* @param ll_p pointer to linked list
* @return length of the linked list
*/
uint32_t _lv_ll_get_len(const lv_ll_t * ll_p)
{
uint32_t len = 0;
void * node;
for(node = _lv_ll_get_head(ll_p); node != NULL; node = _lv_ll_get_next(ll_p, node)) {
len++;
}
return len;
}
/**
* Move a node before an other node in the same linked list
* @param ll_p pointer to a linked list
* @param n_act pointer to node to move
* @param n_after pointer to a node which should be after `n_act`
*/
void _lv_ll_move_before(lv_ll_t * ll_p, void * n_act, void * n_after)
{
if(n_act == n_after) return; /*Can't move before itself*/
void * n_before;
if(n_after != NULL)
n_before = _lv_ll_get_prev(ll_p, n_after);
else
n_before = _lv_ll_get_tail(ll_p); /*if `n_after` is NULL `n_act` should be the new tail*/
if(n_act == n_before) return; /*Already before `n_after`*/
/*It's much easier to remove from the list and add again*/
_lv_ll_remove(ll_p, n_act);
/*Add again by setting the prev. and next nodes*/
node_set_next(ll_p, n_before, n_act);
node_set_prev(ll_p, n_act, n_before);
node_set_prev(ll_p, n_after, n_act);
node_set_next(ll_p, n_act, n_after);
/*If `n_act` was moved before NULL then it become the new tail*/
if(n_after == NULL) ll_p->tail = n_act;
/*If `n_act` was moved before `NULL` then it's the new head*/
if(n_before == NULL) ll_p->head = n_act;
}
/**
* Check if a linked list is empty
* @param ll_p pointer to a linked list
* @return true: the linked list is empty; false: not empty
*/
bool _lv_ll_is_empty(lv_ll_t * ll_p)
{
if(ll_p == NULL) return true;
if(ll_p->head == NULL && ll_p->tail == NULL) return true;
return false;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Set the previous node pointer of a node
* @param ll_p pointer to linked list
* @param act pointer to a node which prev. node pointer should be set
* @param prev pointer to a node which should be the previous node before 'act'
*/
static void node_set_prev(lv_ll_t * ll_p, lv_ll_node_t * act, lv_ll_node_t * prev)
{
if(act == NULL) return; /*Can't set the prev node of `NULL`*/
uint8_t * act8 = (uint8_t *)act;
act8 += LL_PREV_P_OFFSET(ll_p);
lv_ll_node_t ** act_node_p = (lv_ll_node_t **) act8;
lv_ll_node_t ** prev_node_p = (lv_ll_node_t **) &prev;
*act_node_p = *prev_node_p;
}
/**
* Set the 'next node pointer' of a node
* @param ll_p pointer to linked list
* @param act pointer to a node which next node pointer should be set
* @param next pointer to a node which should be the next node before 'act'
*/
static void node_set_next(lv_ll_t * ll_p, lv_ll_node_t * act, lv_ll_node_t * next)
{
if(act == NULL) return; /*Can't set the next node of `NULL`*/
uint8_t * act8 = (uint8_t *)act;
act8 += LL_NEXT_P_OFFSET(ll_p);
lv_ll_node_t ** act_node_p = (lv_ll_node_t **) act8;
lv_ll_node_t ** next_node_p = (lv_ll_node_t **) &next;
*act_node_p = *next_node_p;
}
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_log.h | /**
* @file lv_log.h
*
*/
#ifndef LV_LOG_H
#define LV_LOG_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#include <stdint.h>
#include "lv_types.h"
/*********************
* DEFINES
*********************/
/*Possible log level. For compatibility declare it independently from `LV_USE_LOG`*/
#define LV_LOG_LEVEL_TRACE 0 /**< A lot of logs to give detailed information*/
#define LV_LOG_LEVEL_INFO 1 /**< Log important events*/
#define LV_LOG_LEVEL_WARN 2 /**< Log if something unwanted happened but didn't caused problem*/
#define LV_LOG_LEVEL_ERROR 3 /**< Only critical issue, when the system may fail*/
#define LV_LOG_LEVEL_USER 4 /**< Custom logs from the user*/
#define LV_LOG_LEVEL_NONE 5 /**< Do not log anything*/
#define _LV_LOG_LEVEL_NUM 6 /**< Number of log levels*/
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_TRACE);
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_INFO);
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_WARN);
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_ERROR);
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_USER);
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_NONE);
typedef int8_t lv_log_level_t;
#if LV_USE_LOG
#if LV_LOG_USE_FILE_LINE
#define LV_LOG_FILE __FILE__
#define LV_LOG_LINE __LINE__
#else
#define LV_LOG_FILE NULL
#define LV_LOG_LINE 0
#endif
/**********************
* TYPEDEFS
**********************/
/**
* Log print function. Receives a string buffer to print".
*/
typedef void (*lv_log_print_g_cb_t)(lv_log_level_t level, const char * buf);
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Register custom print/write function to call when a log is added.
* It can format its "File path", "Line number" and "Description" as required
* and send the formatted log message to a console or serial port.
* @param print_cb a function pointer to print a log
*/
void lv_log_register_print_cb(lv_log_print_g_cb_t print_cb);
/**
* Print a log message via `printf` if enabled with `LV_LOG_PRINTF` in `lv_conf.h`
* and/or a print callback if registered with `lv_log_register_print_cb`
* @param format printf-like format string
* @param ... parameters for `format`
*/
void lv_log(const char * format, ...) LV_FORMAT_ATTRIBUTE(1, 2);
/**
* Add a log
* @param level the level of log. (From `lv_log_level_t` enum)
* @param file name of the file when the log added
* @param line line number in the source code where the log added
* @param func name of the function when the log added
* @param format printf-like format string
* @param ... parameters for `format`
*/
void _lv_log_add(lv_log_level_t level, const char * file, int line,
const char * func, const char * format, ...) LV_FORMAT_ATTRIBUTE(5, 6);
/**********************
* MACROS
**********************/
#ifndef LV_LOG_TRACE
# if LV_LOG_LEVEL <= LV_LOG_LEVEL_TRACE
# define LV_LOG_TRACE(...) _lv_log_add(LV_LOG_LEVEL_TRACE, LV_LOG_FILE, LV_LOG_LINE, __func__, __VA_ARGS__)
# else
# define LV_LOG_TRACE(...) do {}while(0)
# endif
#endif
#ifndef LV_LOG_INFO
# if LV_LOG_LEVEL <= LV_LOG_LEVEL_INFO
# define LV_LOG_INFO(...) _lv_log_add(LV_LOG_LEVEL_INFO, LV_LOG_FILE, LV_LOG_LINE, __func__, __VA_ARGS__)
# else
# define LV_LOG_INFO(...) do {}while(0)
# endif
#endif
#ifndef LV_LOG_WARN
# if LV_LOG_LEVEL <= LV_LOG_LEVEL_WARN
# define LV_LOG_WARN(...) _lv_log_add(LV_LOG_LEVEL_WARN, LV_LOG_FILE, LV_LOG_LINE, __func__, __VA_ARGS__)
# else
# define LV_LOG_WARN(...) do {}while(0)
# endif
#endif
#ifndef LV_LOG_ERROR
# if LV_LOG_LEVEL <= LV_LOG_LEVEL_ERROR
# define LV_LOG_ERROR(...) _lv_log_add(LV_LOG_LEVEL_ERROR, LV_LOG_FILE, LV_LOG_LINE, __func__, __VA_ARGS__)
# else
# define LV_LOG_ERROR(...) do {}while(0)
# endif
#endif
#ifndef LV_LOG_USER
# if LV_LOG_LEVEL <= LV_LOG_LEVEL_USER
# define LV_LOG_USER(...) _lv_log_add(LV_LOG_LEVEL_USER, LV_LOG_FILE, LV_LOG_LINE, __func__, __VA_ARGS__)
# else
# define LV_LOG_USER(...) do {}while(0)
# endif
#endif
#ifndef LV_LOG
# if LV_LOG_LEVEL < LV_LOG_LEVEL_NONE
# define LV_LOG(...) lv_log(__VA_ARGS__)
# else
# define LV_LOG(...) do {} while(0)
# endif
#endif
#else /*LV_USE_LOG*/
/*Do nothing if `LV_USE_LOG 0`*/
#define _lv_log_add(level, file, line, ...)
#define LV_LOG_TRACE(...) do {}while(0)
#define LV_LOG_INFO(...) do {}while(0)
#define LV_LOG_WARN(...) do {}while(0)
#define LV_LOG_ERROR(...) do {}while(0)
#define LV_LOG_USER(...) do {}while(0)
#define LV_LOG(...) do {}while(0)
#endif /*LV_USE_LOG*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_LOG_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_color_op.h | /**
* @file lv_color_op.h
*
*/
#ifndef LV_COLOR_OP_H
#define LV_COLOR_OP_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lv_assert.h"
#include "lv_math.h"
#include "lv_color.h"
#include <stdint.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
struct _lv_color_filter_dsc_t;
typedef lv_color_t (*lv_color_filter_cb_t)(const struct _lv_color_filter_dsc_t *, lv_color_t, lv_opa_t);
typedef struct _lv_color_filter_dsc_t {
lv_color_filter_cb_t filter_cb;
void * user_data;
} lv_color_filter_dsc_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Mix two colors with a given ratio.
* @param c1 the first color to mix (usually the foreground)
* @param c2 the second color to mix (usually the background)
* @param mix The ratio of the colors. 0: full `c2`, 255: full `c1`, 127: half `c1` and half`c2`
* @return the mixed color
*/
LV_ATTRIBUTE_FAST_MEM static inline lv_color_t lv_color_mix(lv_color_t c1, lv_color_t c2, uint8_t mix)
{
lv_color_t ret;
ret.red = LV_UDIV255((uint16_t)c1.red * mix + c2.red * (255 - mix) + LV_COLOR_MIX_ROUND_OFS);
ret.green = LV_UDIV255((uint16_t)c1.green * mix + c2.green * (255 - mix) + LV_COLOR_MIX_ROUND_OFS);
ret.blue = LV_UDIV255((uint16_t)c1.blue * mix + c2.blue * (255 - mix) + LV_COLOR_MIX_ROUND_OFS);
return ret;
}
/**
*
* @param fg
* @param bg
* @return
* @note Use bg.alpha in the return value
* @note Use fg.alpha as mix ratio
*/
static inline lv_color32_t lv_color_mix32(lv_color32_t fg, lv_color32_t bg)
{
if(fg.alpha >= LV_OPA_MAX) {
fg.alpha = bg.alpha;
return fg;
}
if(fg.alpha <= LV_OPA_MIN) {
return bg;
}
bg.red = (uint32_t)((uint32_t)fg.red * fg.alpha + (uint32_t)bg.red * (255 - fg.alpha)) >> 8;
bg.green = (uint32_t)((uint32_t)fg.green * fg.alpha + (uint32_t)bg.green * (255 - fg.alpha)) >> 8;
bg.blue = (uint32_t)((uint32_t)fg.blue * fg.alpha + (uint32_t)bg.blue * (255 - fg.alpha)) >> 8;
return bg;
}
//! @endcond
/**
* Get the brightness of a color
* @param color a color
* @return the brightness [0..255]
*/
static inline uint8_t lv_color_brightness(lv_color_t c)
{
uint16_t bright = (uint16_t)(3u * c.red + c.green + 4u * c.blue);
return (uint8_t)(bright >> 3);
}
static inline void lv_color_filter_dsc_init(lv_color_filter_dsc_t * dsc, lv_color_filter_cb_t cb)
{
dsc->filter_cb = cb;
}
/**********************
* PREDEFINED COLORS
**********************/
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_COLOR_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_event.c | /**
* @file lv_event.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_event.h"
#include "../core/lv_global.h"
#include "../stdlib/lv_mem.h"
#include "lv_assert.h"
#include <stddef.h>
/*********************
* DEFINES
*********************/
#define event_head LV_GLOBAL_DEFAULT()->event_header
#define event_last_id LV_GLOBAL_DEFAULT()->event_last_register_id
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
#if LV_USE_LOG && LV_LOG_TRACE_EVENT
#define LV_TRACE_EVENT(...) LV_LOG_TRACE(__VA_ARGS__)
#else
#define LV_TRACE_EVENT(...)
#endif
/**********************
* GLOBAL FUNCTIONS
**********************/
void _lv_event_push(lv_event_t * e)
{
/*Build a simple linked list from the objects used in the events
*It's important to know if this object was deleted by a nested event
*called from this `event_cb`.*/
e->prev = event_head;
event_head = e;
}
void _lv_event_pop(lv_event_t * e)
{
event_head = e->prev;
}
lv_result_t lv_event_send(lv_event_list_t * list, lv_event_t * e, bool preprocess)
{
if(list == NULL) return LV_RESULT_OK;
uint32_t i = 0;
for(i = 0; i < list->cnt; i++) {
if(list->dsc[i].cb == NULL) continue;
bool is_preprocessed = (list->dsc[i].filter & LV_EVENT_PREPROCESS) != 0;
if(is_preprocessed != preprocess) continue;
lv_event_code_t filter = list->dsc[i].filter & ~LV_EVENT_PREPROCESS;
if(filter == LV_EVENT_ALL || filter == e->code) {
e->user_data = list->dsc[i].user_data;
list->dsc[i].cb(e);
if(e->stop_processing) return LV_RESULT_OK;
/*Stop if the object is deleted*/
if(e->deleted) return LV_RESULT_INVALID;
}
}
return LV_RESULT_OK;
}
void lv_event_add(lv_event_list_t * list, lv_event_cb_t cb, lv_event_code_t filter,
void * user_data)
{
list->cnt++;
list->dsc = lv_realloc(list->dsc, list->cnt * sizeof(lv_event_dsc_t));
LV_ASSERT_MALLOC(list->dsc);
if(list->dsc == NULL) return;
list->dsc[list->cnt - 1].cb = cb;
list->dsc[list->cnt - 1].filter = filter;
list->dsc[list->cnt - 1].user_data = user_data;
}
uint32_t lv_event_get_count(lv_event_list_t * list)
{
LV_ASSERT_NULL(list);
return list->cnt;
}
lv_event_dsc_t * lv_event_get_dsc(lv_event_list_t * list, uint32_t index)
{
LV_ASSERT_NULL(list);
if(index >= list->cnt) return NULL;
else return &list->dsc[index];
}
lv_event_cb_t lv_event_dsc_get_cb(lv_event_dsc_t * dsc)
{
LV_ASSERT_NULL(dsc);
return dsc->cb;
}
void * lv_event_dsc_get_user_data(lv_event_dsc_t * dsc)
{
LV_ASSERT_NULL(dsc);
return dsc->user_data;
}
bool lv_event_remove(lv_event_list_t * list, uint32_t index)
{
LV_ASSERT_NULL(list);
if(index >= list->cnt) return false;
/*Shift the remaining event handlers forward*/
uint32_t i;
for(i = index; i < list->cnt - 1; i++) {
list->dsc[i] = list->dsc[i + 1];
}
list->cnt--;
list->dsc = lv_realloc(list->dsc, list->cnt * sizeof(lv_event_dsc_t));
LV_ASSERT_MALLOC(list->dsc);
return true;
}
void lv_event_remove_all(lv_event_list_t * list)
{
LV_ASSERT_NULL(list);
if(list && list->dsc) {
lv_free(list->dsc);
list->dsc = NULL;
list->cnt = 0;
}
}
void * lv_event_get_current_target(lv_event_t * e)
{
return e->current_target;
}
void * lv_event_get_target(lv_event_t * e)
{
return e->original_target;
}
lv_event_code_t lv_event_get_code(lv_event_t * e)
{
return e->code & ~LV_EVENT_PREPROCESS;
}
void * lv_event_get_param(lv_event_t * e)
{
return e->param;
}
void * lv_event_get_user_data(lv_event_t * e)
{
return e->user_data;
}
void lv_event_stop_bubbling(lv_event_t * e)
{
e->stop_bubbling = 1;
}
void lv_event_stop_processing(lv_event_t * e)
{
e->stop_processing = 1;
}
uint32_t lv_event_register_id(void)
{
event_last_id ++;
return event_last_id;
}
void _lv_event_mark_deleted(void * target)
{
lv_event_t * e = event_head;
while(e) {
if(e->original_target == target || e->current_target == target) e->deleted = 1;
e = e->prev;
}
}
/**********************
* STATIC FUNCTIONS
**********************/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_text_ap.h | /**
* @file lv_text_ap.h
*
*/
#ifndef LV_TEXT_AP_H
#define LV_TEXT_AP_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include <stddef.h>
#include "lv_text.h"
#include "../draw/lv_draw.h"
#if LV_USE_ARABIC_PERSIAN_CHARS == 1
/*********************
* DEFINES
*********************/
#define LV_UNDEF_ARABIC_PERSIAN_CHARS (UINT32_MAX)
#define LV_AP_ALPHABET_BASE_CODE 0x0622
#define LV_AP_END_CHARS_LIST {0,0,0,0,0,{0,0}}
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
uint32_t _lv_text_ap_calc_bytes_cnt(const char * txt);
void _lv_text_ap_proc(const char * txt, char * txt_out);
/**********************
* MACROS
**********************/
#endif // LV_USE_ARABIC_PERSIAN_CHARS
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_TEXT_AP_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_timer.c | /**
* @file lv_timer.c
*/
/*********************
* INCLUDES
*********************/
#include "lv_timer.h"
#include "../core/lv_global.h"
#include "../tick/lv_tick.h"
#include "../stdlib/lv_mem.h"
#include "../stdlib/lv_sprintf.h"
#include "lv_assert.h"
#include "lv_ll.h"
#include "lv_profiler.h"
/*********************
* DEFINES
*********************/
#define IDLE_MEAS_PERIOD 500 /*[ms]*/
#define DEF_PERIOD 500
#define state LV_GLOBAL_DEFAULT()->timer_state
#define timer_ll_p &(state.timer_ll)
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static bool lv_timer_exec(lv_timer_t * timer);
static uint32_t lv_timer_time_remaining(lv_timer_t * timer);
static void lv_timer_handler_resume(void);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
#if LV_USE_LOG && LV_LOG_TRACE_TIMER
#define LV_TRACE_TIMER(...) LV_LOG_TRACE(__VA_ARGS__)
#else
#define LV_TRACE_TIMER(...)
#endif
/**********************
* GLOBAL FUNCTIONS
**********************/
void _lv_timer_core_init(void)
{
_lv_ll_init(timer_ll_p, sizeof(lv_timer_t));
/*Initially enable the lv_timer handling*/
lv_timer_enable(true);
}
LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler(void)
{
LV_TRACE_TIMER("begin");
lv_timer_state_t * state_p = &state;
/*Avoid concurrent running of the timer handler*/
if(state_p->already_running) {
LV_TRACE_TIMER("already running, concurrent calls are not allow, returning");
return 1;
}
state_p->already_running = true;
if(state_p->lv_timer_run == false) {
state_p->already_running = false; /*Release mutex*/
return 1;
}
LV_PROFILER_BEGIN;
uint32_t handler_start = lv_tick_get();
if(handler_start == 0) {
state.run_cnt++;
if(state.run_cnt > 100) {
state.run_cnt = 0;
LV_LOG_WARN("It seems lv_tick_inc() is not called.");
}
}
/*Run all timer from the list*/
lv_timer_t * next;
lv_timer_t * timer_active;
lv_ll_t * timer_head = timer_ll_p;
do {
state_p->timer_deleted = false;
state_p->timer_created = false;
timer_active = _lv_ll_get_head(timer_head);
while(timer_active) {
/*The timer might be deleted if it runs only once ('repeat_count = 1')
*So get next element until the current is surely valid*/
next = _lv_ll_get_next(timer_head, timer_active);
if(lv_timer_exec(timer_active)) {
/*If a timer was created or deleted then this or the next item might be corrupted*/
if(state_p->timer_created || state_p->timer_deleted) {
LV_TRACE_TIMER("Start from the first timer again because a timer was created or deleted");
break;
}
}
timer_active = next; /*Load the next timer*/
}
} while(timer_active);
uint32_t time_until_next = LV_NO_TIMER_READY;
next = _lv_ll_get_head(timer_head);
while(next) {
if(!next->paused) {
uint32_t delay = lv_timer_time_remaining(next);
if(delay < time_until_next)
time_until_next = delay;
}
next = _lv_ll_get_next(timer_head, next); /*Find the next timer*/
}
state_p->busy_time += lv_tick_elaps(handler_start);
uint32_t idle_period_time = lv_tick_elaps(state_p->idle_period_start);
if(idle_period_time >= IDLE_MEAS_PERIOD) {
state_p->idle_last = (state_p->busy_time * 100) / idle_period_time; /*Calculate the busy percentage*/
state_p->idle_last = state_p->idle_last > 100 ? 0 : 100 - state_p->idle_last; /*But we need idle time*/
state_p->busy_time = 0;
state_p->idle_period_start = lv_tick_get();
}
state_p->timer_time_until_next = time_until_next;
state_p->already_running = false; /*Release the mutex*/
LV_TRACE_TIMER("finished (%" LV_PRIu32 " ms until the next timer call)", time_until_next);
LV_PROFILER_END;
return time_until_next;
}
LV_ATTRIBUTE_TIMER_HANDLER void lv_timer_periodic_handler(void)
{
lv_timer_state_t * state_p = &state;
if(lv_tick_elaps(state_p->periodic_last_tick) >= state_p->timer_time_until_next) {
LV_TRACE_TIMER("calling lv_timer_handler()");
lv_timer_handler();
state_p->periodic_last_tick = lv_tick_get();
}
}
lv_timer_t * lv_timer_create_basic(void)
{
return lv_timer_create(NULL, DEF_PERIOD, NULL);
}
lv_timer_t * lv_timer_create(lv_timer_cb_t timer_xcb, uint32_t period, void * user_data)
{
lv_timer_t * new_timer = NULL;
new_timer = _lv_ll_ins_head(timer_ll_p);
LV_ASSERT_MALLOC(new_timer);
if(new_timer == NULL) return NULL;
new_timer->period = period;
new_timer->timer_cb = timer_xcb;
new_timer->repeat_count = -1;
new_timer->paused = 0;
new_timer->last_run = lv_tick_get();
new_timer->user_data = user_data;
new_timer->auto_delete = true;
state.timer_created = true;
lv_timer_handler_resume();
return new_timer;
}
void lv_timer_set_cb(lv_timer_t * timer, lv_timer_cb_t timer_cb)
{
timer->timer_cb = timer_cb;
}
void lv_timer_delete(lv_timer_t * timer)
{
_lv_ll_remove(timer_ll_p, timer);
state.timer_deleted = true;
lv_free(timer);
}
void lv_timer_pause(lv_timer_t * timer)
{
timer->paused = true;
}
void lv_timer_resume(lv_timer_t * timer)
{
timer->paused = false;
lv_timer_handler_resume();
}
void lv_timer_set_period(lv_timer_t * timer, uint32_t period)
{
timer->period = period;
}
void lv_timer_ready(lv_timer_t * timer)
{
timer->last_run = lv_tick_get() - timer->period - 1;
}
void lv_timer_set_repeat_count(lv_timer_t * timer, int32_t repeat_count)
{
timer->repeat_count = repeat_count;
}
void lv_timer_set_auto_delete(lv_timer_t * timer, bool auto_delete)
{
timer->auto_delete = auto_delete;
}
void lv_timer_set_user_data(lv_timer_t * timer, void * user_data)
{
timer->user_data = user_data;
}
void lv_timer_reset(lv_timer_t * timer)
{
timer->last_run = lv_tick_get();
lv_timer_handler_resume();
}
void lv_timer_enable(bool en)
{
state.lv_timer_run = en;
if(en) lv_timer_handler_resume();
}
uint8_t lv_timer_get_idle(void)
{
return state.idle_last;
}
uint32_t lv_timer_get_time_until_next(void)
{
return state.timer_time_until_next;
}
lv_timer_t * lv_timer_get_next(lv_timer_t * timer)
{
if(timer == NULL) return _lv_ll_get_head(timer_ll_p);
else return _lv_ll_get_next(timer_ll_p, timer);
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Execute timer if its remaining time is zero
* @param timer pointer to lv_timer
* @return true: execute, false: not executed
*/
static bool lv_timer_exec(lv_timer_t * timer)
{
if(timer->paused) return false;
bool exec = false;
if(lv_timer_time_remaining(timer) == 0) {
/* Decrement the repeat count before executing the timer_cb.
* If any timer is deleted `if(timer->repeat_count == 0)` is not executed below
* but at least the repeat count is zero and the timer can be deleted in the next round*/
int32_t original_repeat_count = timer->repeat_count;
if(timer->repeat_count > 0) timer->repeat_count--;
timer->last_run = lv_tick_get();
LV_TRACE_TIMER("calling timer callback: %p", *((void **)&timer->timer_cb));
if(timer->timer_cb && original_repeat_count != 0) timer->timer_cb(timer);
if(!state.timer_deleted) {
LV_TRACE_TIMER("timer callback %p finished", *((void **)&timer->timer_cb));
}
else {
LV_TRACE_TIMER("timer callback finished");
}
LV_ASSERT_MEM_INTEGRITY();
exec = true;
}
if(state.timer_deleted == false) { /*The timer might be deleted by itself as well*/
if(timer->repeat_count == 0) { /*The repeat count is over, delete the timer*/
if(timer->auto_delete) {
LV_TRACE_TIMER("deleting timer with %p callback because the repeat count is over", *((void **)&timer->timer_cb));
lv_timer_delete(timer);
}
else {
LV_TRACE_TIMER("pausing timer with %p callback because the repeat count is over", *((void **)&timer->timer_cb));
lv_timer_pause(timer);
}
}
}
return exec;
}
/**
* Find out how much time remains before a timer must be run.
* @param timer pointer to lv_timer
* @return the time remaining, or 0 if it needs to be run again
*/
static uint32_t lv_timer_time_remaining(lv_timer_t * timer)
{
/*Check if at least 'period' time elapsed*/
uint32_t elp = lv_tick_elaps(timer->last_run);
if(elp >= timer->period)
return 0;
return timer->period - elp;
}
/**
* Call the ready lv_timer
*/
static void lv_timer_handler_resume(void)
{
/*If there is a timer which is ready to run then resume the timer loop*/
state.timer_time_until_next = 0;
if(state.resume_cb) {
state.resume_cb(state.resume_data);
}
}
void lv_timer_handler_set_resume_cb(lv_timer_handler_resume_cb_t cb, void * data)
{
state.resume_cb = cb;
state.resume_data = data;
}
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_color.h | /**
* @file lv_color.h
*
*/
#ifndef LV_COLOR_H
#define LV_COLOR_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#include "lv_assert.h"
#include "lv_math.h"
#include "lv_types.h"
#include <stdint.h>
#include <stdbool.h>
/*********************
* DEFINES
*********************/
LV_EXPORT_CONST_INT(LV_COLOR_DEPTH);
#if LV_COLOR_DEPTH == 8
#define _LV_COLOR_NATIVE_WITH_ALPHA_SIZE 2
#elif LV_COLOR_DEPTH == 16
#define _LV_COLOR_NATIVE_WITH_ALPHA_SIZE 3
#elif LV_COLOR_DEPTH == 24
#define _LV_COLOR_NATIVE_WITH_ALPHA_SIZE 4
#elif LV_COLOR_DEPTH == 32
#define _LV_COLOR_NATIVE_WITH_ALPHA_SIZE 4
#endif
/**
* Opacity percentages.
*/
enum _lv_opa_t {
LV_OPA_TRANSP = 0,
LV_OPA_0 = 0,
LV_OPA_10 = 25,
LV_OPA_20 = 51,
LV_OPA_30 = 76,
LV_OPA_40 = 102,
LV_OPA_50 = 127,
LV_OPA_60 = 153,
LV_OPA_70 = 178,
LV_OPA_80 = 204,
LV_OPA_90 = 229,
LV_OPA_100 = 255,
LV_OPA_COVER = 255,
};
#ifdef DOXYGEN
typedef _lv_opa_t lv_opa_t;
#else
typedef uint8_t lv_opa_t;
#endif /*DOXYGEN*/
#define LV_OPA_MIN 2 /*Opacities below this will be transparent*/
#define LV_OPA_MAX 253 /*Opacities above this will fully cover*/
/**********************
* TYPEDEFS
**********************/
typedef struct {
uint8_t blue;
uint8_t green;
uint8_t red;
} lv_color_t;
typedef struct {
uint16_t blue : 5;
uint16_t green : 6;
uint16_t red : 5;
} lv_color16_t;
typedef struct {
uint8_t blue;
uint8_t green;
uint8_t red;
uint8_t alpha;
} lv_color32_t;
typedef struct {
uint16_t h;
uint8_t s;
uint8_t v;
} lv_color_hsv_t;
enum _lv_color_format_t {
LV_COLOR_FORMAT_UNKNOWN = 0,
LV_COLOR_FORMAT_RAW = 0x01,
LV_COLOR_FORMAT_RAW_ALPHA = 0x02,
/*<=1 byte (+alpha) formats*/
LV_COLOR_FORMAT_L8 = 0x06,
LV_COLOR_FORMAT_I1 = 0x07,
LV_COLOR_FORMAT_I2 = 0x08,
LV_COLOR_FORMAT_I4 = 0x09,
LV_COLOR_FORMAT_I8 = 0x0A,
LV_COLOR_FORMAT_A8 = 0x0E,
/*2 byte (+alpha) formats*/
LV_COLOR_FORMAT_RGB565 = 0x12,
LV_COLOR_FORMAT_RGB565A8 = 0x14 /**< Color array followed by Alpha array*/,
/*3 byte (+alpha) formats*/
LV_COLOR_FORMAT_RGB888 = 0x0F,
LV_COLOR_FORMAT_ARGB8888 = 0x10,
LV_COLOR_FORMAT_XRGB8888 = 0x11,
/*Miscellaneous formats*/
LV_COLOR_FORMAT_NATIVE_REVERSED = 0x1A,
/*Formats not supported by software renderer but kept here so GPU can use it*/
LV_COLOR_FORMAT_A1 = 0x0B,
LV_COLOR_FORMAT_A2 = 0x0C,
LV_COLOR_FORMAT_A4 = 0x0D,
/*Color formats in which LVGL can render*/
#if LV_COLOR_DEPTH == 8
LV_COLOR_FORMAT_NATIVE = LV_COLOR_FORMAT_L8,
#elif LV_COLOR_DEPTH == 16
LV_COLOR_FORMAT_NATIVE = LV_COLOR_FORMAT_RGB565,
LV_COLOR_FORMAT_NATIVE_WITH_ALPHA = LV_COLOR_FORMAT_RGB565A8,
#elif LV_COLOR_DEPTH == 24
LV_COLOR_FORMAT_NATIVE = LV_COLOR_FORMAT_RGB888,
LV_COLOR_FORMAT_NATIVE_WITH_ALPHA = LV_COLOR_FORMAT_ARGB8888,
#elif LV_COLOR_DEPTH == 32
LV_COLOR_FORMAT_NATIVE = LV_COLOR_FORMAT_XRGB8888,
LV_COLOR_FORMAT_NATIVE_WITH_ALPHA = LV_COLOR_FORMAT_ARGB8888,
#endif
};
#ifdef DOXYGEN
typedef _lv_color_format_t lv_color_format_t;
#else
typedef uint8_t lv_color_format_t;
#endif /*DOXYGEN*/
#define LV_COLOR_FORMAT_IS_ALPHA_ONLY(cf) ((cf) >= LV_COLOR_FORMAT_A1 && (cf) <= LV_COLOR_FORMAT_A8)
#define LV_COLOR_FORMAT_IS_INDEXED(cf) ((cf) >= LV_COLOR_FORMAT_I1 && (cf) <= LV_COLOR_FORMAT_I8)
#define LV_COLOR_INDEXED_PALETTE_SIZE(cf) ((cf) == LV_COLOR_FORMAT_I1 ? 2 :\
(cf) == LV_COLOR_FORMAT_I2 ? 4 :\
(cf) == LV_COLOR_FORMAT_I4 ? 16 :\
(cf) == LV_COLOR_FORMAT_I8 ? 256 : 0)
/**********************
* MACROS
**********************/
#define LV_COLOR_MAKE(r8, g8, b8) {b8, g8, r8}
#define LV_OPA_MIX2(a1, a2) (((int32_t)(a1) * (a2)) >> 8)
#define LV_OPA_MIX3(a1, a2, a3) (((int32_t)(a1) * (a2) * (a3)) >> 16)
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Get the pixel size of a color format in bits, bpp
* @param src_cf a color format (`LV_COLOR_FORMAT_...`)
* @return the pixel size in bits
*/
uint8_t lv_color_format_get_bpp(lv_color_format_t cf);
/**
* Get the pixel size of a color format in bytes
* @param src_cf a color format (`LV_COLOR_FORMAT_...`)
* @return the pixel size in bytes
*/
static inline uint8_t lv_color_format_get_size(lv_color_format_t cf)
{
return (lv_color_format_get_bpp(cf) + 7) >> 3;
}
/**
* Check if a color format has alpha channel or not
* @param src_cf a color format (`LV_IMAGE_CF_...`)
* @return true: has alpha channel; false: doesn't have alpha channel
*/
bool lv_color_format_has_alpha(lv_color_format_t src_cf);
lv_color32_t lv_color_to_32(lv_color_t color, lv_opa_t opa);
static inline uint32_t lv_color_to_int(lv_color_t c)
{
uint8_t * tmp = (uint8_t *) &c;
return tmp[0] + (tmp[1] << 8) + (tmp[2] << 16);
}
static inline lv_color_t lv_color_from_int(uint32_t v)
{
void * p = (void *)&v;
return *((lv_color_t *)p);
}
static inline bool lv_color_eq(lv_color_t c1, lv_color_t c2)
{
return lv_color_to_int(c1) == lv_color_to_int(c2);
}
static inline bool lv_color32_eq(lv_color32_t c1, lv_color32_t c2)
{
return *((uint32_t *)&c1) == *((uint32_t *)&c2);
}
static lv_color_t lv_color_hex(uint32_t c)
{
lv_color_t ret;
ret.red = (c >> 16) & 0xff;
ret.green = (c >> 8) & 0xff;
ret.blue = (c >> 0) & 0xff;
return ret;
}
static inline lv_color_t lv_color_make(uint8_t r, uint8_t g, uint8_t b)
{
return lv_color_hex((r << 16) + (g << 8) + b);
}
static inline lv_color_t lv_color_hex3(uint32_t c)
{
return lv_color_make((uint8_t)(((c >> 4) & 0xF0) | ((c >> 8) & 0xF)), (uint8_t)((c & 0xF0) | ((c & 0xF0) >> 4)),
(uint8_t)((c & 0xF) | ((c & 0xF) << 4)));
}
uint16_t lv_color_to_u16(lv_color_t color);
uint32_t lv_color_to_u32(lv_color_t color);
LV_ATTRIBUTE_FAST_MEM static inline uint16_t lv_color_16_16_mix(uint16_t c1, uint16_t c2, uint8_t mix)
{
if(mix == 255) return c1;
if(mix == 0) return c2;
uint16_t ret;
/* Source: https://stackoverflow.com/a/50012418/1999969*/
mix = (uint32_t)((uint32_t)mix + 4) >> 3;
/*0x7E0F81F = 0b00000111111000001111100000011111*/
uint32_t bg = (uint32_t)(c2 | ((uint32_t)c2 << 16)) & 0x7E0F81F;
uint32_t fg = (uint32_t)(c1 | ((uint32_t)c1 << 16)) & 0x7E0F81F;
uint32_t result = ((((fg - bg) * mix) >> 5) + bg) & 0x7E0F81F;
ret = (uint16_t)(result >> 16) | result;
return ret;
}
lv_color_t lv_color_lighten(lv_color_t c, lv_opa_t lvl);
lv_color_t lv_color_darken(lv_color_t c, lv_opa_t lvl);
/**
* Convert a HSV color to RGB
* @param h hue [0..359]
* @param s saturation [0..100]
* @param v value [0..100]
* @return the given RGB color in RGB (with LV_COLOR_DEPTH depth)
*/
lv_color_t lv_color_hsv_to_rgb(uint16_t h, uint8_t s, uint8_t v);
/**
* Convert a 32-bit RGB color to HSV
* @param r8 8-bit red
* @param g8 8-bit green
* @param b8 8-bit blue
* @return the given RGB color in HSV
*/
lv_color_hsv_t lv_color_rgb_to_hsv(uint8_t r8, uint8_t g8, uint8_t b8);
/**
* Convert a color to HSV
* @param color color
* @return the given color in HSV
*/
lv_color_hsv_t lv_color_to_hsv(lv_color_t color);
/*Source: https://vuetifyjs.com/en/styles/colors/#material-colors*/
static inline lv_color_t lv_color_white(void)
{
return lv_color_make(0xff, 0xff, 0xff);
}
static inline lv_color_t lv_color_black(void)
{
return lv_color_make(0x00, 0x00, 0x00);
}
/**********************
* MACROS
**********************/
#include "lv_palette.h"
#include "lv_color_op.h"
extern const lv_color_filter_dsc_t lv_color_filter_shade;
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_COLOR_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_async.c | /**
* @file lv_async.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_async.h"
#include "lv_timer.h"
#include "../stdlib/lv_mem.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef struct _lv_async_info_t {
lv_async_cb_t cb;
void * user_data;
} lv_async_info_t;
/**********************
* STATIC PROTOTYPES
**********************/
static void lv_async_timer_cb(lv_timer_t * timer);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
lv_result_t lv_async_call(lv_async_cb_t async_xcb, void * user_data)
{
/*Allocate an info structure*/
lv_async_info_t * info = lv_malloc(sizeof(lv_async_info_t));
if(info == NULL)
return LV_RESULT_INVALID;
/*Create a new timer*/
lv_timer_t * timer = lv_timer_create(lv_async_timer_cb, 0, info);
if(timer == NULL) {
lv_free(info);
return LV_RESULT_INVALID;
}
info->cb = async_xcb;
info->user_data = user_data;
lv_timer_set_repeat_count(timer, 1);
return LV_RESULT_OK;
}
lv_result_t lv_async_call_cancel(lv_async_cb_t async_xcb, void * user_data)
{
lv_timer_t * timer = lv_timer_get_next(NULL);
lv_result_t res = LV_RESULT_INVALID;
while(timer != NULL) {
/*Find the next timer node*/
lv_timer_t * timer_next = lv_timer_get_next(timer);
/*Find async timer callback*/
if(timer->timer_cb == lv_async_timer_cb) {
lv_async_info_t * info = (lv_async_info_t *)timer->user_data;
/*Match user function callback and user data*/
if(info->cb == async_xcb && info->user_data == user_data) {
lv_timer_delete(timer);
lv_free(info);
res = LV_RESULT_OK;
}
}
timer = timer_next;
}
return res;
}
/**********************
* STATIC FUNCTIONS
**********************/
static void lv_async_timer_cb(lv_timer_t * timer)
{
/*Save the info because an lv_async_call_cancel might delete it in the callback*/
lv_async_info_t * info = (lv_async_info_t *)timer->user_data;
lv_async_info_t info_save = *info;
lv_timer_delete(timer);
lv_free(info);
info_save.cb(info_save.user_data);
}
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_color.c | /**
* @file lv_color.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_color.h"
#include "lv_log.h"
#include "../misc/lv_color.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static lv_color_t lv_color_filter_shade_cb(const lv_color_filter_dsc_t * dsc, lv_color_t c, lv_opa_t opa);
/**********************
* GLOBAL VARIABLES
**********************/
const lv_color_filter_dsc_t lv_color_filter_shade = {.filter_cb = lv_color_filter_shade_cb};
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
uint8_t lv_color_format_get_bpp(lv_color_format_t cf)
{
switch(cf) {
case LV_COLOR_FORMAT_NATIVE_REVERSED:
return LV_COLOR_DEPTH / 8;
case LV_COLOR_FORMAT_I1:
case LV_COLOR_FORMAT_A1:
return 1;
case LV_COLOR_FORMAT_I2:
case LV_COLOR_FORMAT_A2:
return 2;
case LV_COLOR_FORMAT_I4:
case LV_COLOR_FORMAT_A4:
return 4;
case LV_COLOR_FORMAT_L8:
case LV_COLOR_FORMAT_A8:
case LV_COLOR_FORMAT_I8:
return 8;
case LV_COLOR_FORMAT_RGB565:
return 16;
case LV_COLOR_FORMAT_RGB565A8:
case LV_COLOR_FORMAT_RGB888:
return 24;
case LV_COLOR_FORMAT_ARGB8888:
case LV_COLOR_FORMAT_XRGB8888:
return 32;
case LV_COLOR_FORMAT_UNKNOWN:
default:
return 0;
}
}
bool lv_color_format_has_alpha(lv_color_format_t cf)
{
switch(cf) {
case LV_COLOR_FORMAT_A8:
case LV_COLOR_FORMAT_I8:
case LV_COLOR_FORMAT_RGB565A8:
case LV_COLOR_FORMAT_ARGB8888:
return true;
default:
return false;
}
}
lv_color32_t lv_color_to_32(lv_color_t color, lv_opa_t opa)
{
lv_color32_t c32;
c32.red = color.red;
c32.green = color.green;
c32.blue = color.blue;
c32.alpha = opa;
return c32;
}
uint16_t lv_color_to_u16(lv_color_t color)
{
return ((color.red & 0xF8) << 8) + ((color.green & 0xFC) << 3) + ((color.blue & 0xF8) >> 3);
}
uint32_t lv_color_to_u32(lv_color_t color)
{
return (uint32_t)((uint32_t)0xff << 24) + (color.red << 16) + (color.green << 8) + (color.blue);
}
lv_color_t lv_color_lighten(lv_color_t c, lv_opa_t lvl)
{
return lv_color_mix(lv_color_white(), c, lvl);
}
lv_color_t lv_color_darken(lv_color_t c, lv_opa_t lvl)
{
return lv_color_mix(lv_color_black(), c, lvl);
}
/**
* Convert a HSV color to RGB
* @param h hue [0..359]
* @param s saturation [0..100]
* @param v value [0..100]
* @return the given RGB color in RGB (with LV_COLOR_DEPTH depth)
*/
lv_color_t lv_color_hsv_to_rgb(uint16_t h, uint8_t s, uint8_t v)
{
h = (uint32_t)((uint32_t)h * 255) / 360;
s = (uint16_t)((uint16_t)s * 255) / 100;
v = (uint16_t)((uint16_t)v * 255) / 100;
uint8_t r, g, b;
uint8_t region, remainder, p, q, t;
if(s == 0) {
return lv_color_make(v, v, v);
}
region = h / 43;
remainder = (h - (region * 43)) * 6;
p = (v * (255 - s)) >> 8;
q = (v * (255 - ((s * remainder) >> 8))) >> 8;
t = (v * (255 - ((s * (255 - remainder)) >> 8))) >> 8;
switch(region) {
case 0:
r = v;
g = t;
b = p;
break;
case 1:
r = q;
g = v;
b = p;
break;
case 2:
r = p;
g = v;
b = t;
break;
case 3:
r = p;
g = q;
b = v;
break;
case 4:
r = t;
g = p;
b = v;
break;
default:
r = v;
g = p;
b = q;
break;
}
lv_color_t result = lv_color_make(r, g, b);
return result;
}
/**
* Convert a 32-bit RGB color to HSV
* @param r8 8-bit red
* @param g8 8-bit green
* @param b8 8-bit blue
* @return the given RGB color in HSV
*/
lv_color_hsv_t lv_color_rgb_to_hsv(uint8_t r8, uint8_t g8, uint8_t b8)
{
uint16_t r = ((uint32_t)r8 << 10) / 255;
uint16_t g = ((uint32_t)g8 << 10) / 255;
uint16_t b = ((uint32_t)b8 << 10) / 255;
uint16_t rgbMin = r < g ? (r < b ? r : b) : (g < b ? g : b);
uint16_t rgbMax = r > g ? (r > b ? r : b) : (g > b ? g : b);
lv_color_hsv_t hsv;
// https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness
hsv.v = (100 * rgbMax) >> 10;
int32_t delta = rgbMax - rgbMin;
if(delta < 3) {
hsv.h = 0;
hsv.s = 0;
return hsv;
}
// https://en.wikipedia.org/wiki/HSL_and_HSV#Saturation
hsv.s = 100 * delta / rgbMax;
if(hsv.s < 3) {
hsv.h = 0;
return hsv;
}
// https://en.wikipedia.org/wiki/HSL_and_HSV#Hue_and_chroma
int32_t h;
if(rgbMax == r)
h = (((g - b) << 10) / delta) + (g < b ? (6 << 10) : 0); // between yellow & magenta
else if(rgbMax == g)
h = (((b - r) << 10) / delta) + (2 << 10); // between cyan & yellow
else if(rgbMax == b)
h = (((r - g) << 10) / delta) + (4 << 10); // between magenta & cyan
else
h = 0;
h *= 60;
h >>= 10;
if(h < 0) h += 360;
hsv.h = h;
return hsv;
}
/**
* Convert a color to HSV
* @param color color
* @return the given color in HSV
*/
lv_color_hsv_t lv_color_to_hsv(lv_color_t c)
{
return lv_color_rgb_to_hsv(c.red, c.green, c.blue);
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Helper function to easily create color filters
* @param dsc pointer to a color filter descriptor
* @param c the color to modify
* @param opa the intensity of the modification
* - LV_OPA_50: do nothing
* - < LV_OPA_50: darken
* - LV_OPA_0: fully black
* - > LV_OPA_50: lighten
* - LV_OPA_100: fully white
* @return the modified color
*/
static lv_color_t lv_color_filter_shade_cb(const lv_color_filter_dsc_t * dsc, lv_color_t c, lv_opa_t opa)
{
LV_UNUSED(dsc);
if(opa == LV_OPA_50) return c;
if(opa < LV_OPA_50) return lv_color_lighten(c, (LV_OPA_50 - opa) * 2);
else return lv_color_darken(c, (opa - LV_OPA_50 * LV_OPA_50) * 2);
}
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/misc/lv_palette.c | /**
* @file lv_palette.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_palette.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
lv_color_t lv_palette_main(lv_palette_t p)
{
static const lv_color_t colors[] = {
LV_COLOR_MAKE(0xF4, 0x43, 0x36), LV_COLOR_MAKE(0xE9, 0x1E, 0x63), LV_COLOR_MAKE(0x9C, 0x27, 0xB0), LV_COLOR_MAKE(0x67, 0x3A, 0xB7),
LV_COLOR_MAKE(0x3F, 0x51, 0xB5), LV_COLOR_MAKE(0x21, 0x96, 0xF3), LV_COLOR_MAKE(0x03, 0xA9, 0xF4), LV_COLOR_MAKE(0x00, 0xBC, 0xD4),
LV_COLOR_MAKE(0x00, 0x96, 0x88), LV_COLOR_MAKE(0x4C, 0xAF, 0x50), LV_COLOR_MAKE(0x8B, 0xC3, 0x4A), LV_COLOR_MAKE(0xCD, 0xDC, 0x39),
LV_COLOR_MAKE(0xFF, 0xEB, 0x3B), LV_COLOR_MAKE(0xFF, 0xC1, 0x07), LV_COLOR_MAKE(0xFF, 0x98, 0x00), LV_COLOR_MAKE(0xFF, 0x57, 0x22),
LV_COLOR_MAKE(0x79, 0x55, 0x48), LV_COLOR_MAKE(0x60, 0x7D, 0x8B), LV_COLOR_MAKE(0x9E, 0x9E, 0x9E)
};
if(p >= _LV_PALETTE_LAST) {
LV_LOG_WARN("Invalid palette: %d", p);
return lv_color_black();
}
return colors[p];
}
lv_color_t lv_palette_lighten(lv_palette_t p, uint8_t lvl)
{
static const lv_color_t colors[][5] = {
{LV_COLOR_MAKE(0xEF, 0x53, 0x50), LV_COLOR_MAKE(0xE5, 0x73, 0x73), LV_COLOR_MAKE(0xEF, 0x9A, 0x9A), LV_COLOR_MAKE(0xFF, 0xCD, 0xD2), LV_COLOR_MAKE(0xFF, 0xEB, 0xEE)},
{LV_COLOR_MAKE(0xEC, 0x40, 0x7A), LV_COLOR_MAKE(0xF0, 0x62, 0x92), LV_COLOR_MAKE(0xF4, 0x8F, 0xB1), LV_COLOR_MAKE(0xF8, 0xBB, 0xD0), LV_COLOR_MAKE(0xFC, 0xE4, 0xEC)},
{LV_COLOR_MAKE(0xAB, 0x47, 0xBC), LV_COLOR_MAKE(0xBA, 0x68, 0xC8), LV_COLOR_MAKE(0xCE, 0x93, 0xD8), LV_COLOR_MAKE(0xE1, 0xBE, 0xE7), LV_COLOR_MAKE(0xF3, 0xE5, 0xF5)},
{LV_COLOR_MAKE(0x7E, 0x57, 0xC2), LV_COLOR_MAKE(0x95, 0x75, 0xCD), LV_COLOR_MAKE(0xB3, 0x9D, 0xDB), LV_COLOR_MAKE(0xD1, 0xC4, 0xE9), LV_COLOR_MAKE(0xED, 0xE7, 0xF6)},
{LV_COLOR_MAKE(0x5C, 0x6B, 0xC0), LV_COLOR_MAKE(0x79, 0x86, 0xCB), LV_COLOR_MAKE(0x9F, 0xA8, 0xDA), LV_COLOR_MAKE(0xC5, 0xCA, 0xE9), LV_COLOR_MAKE(0xE8, 0xEA, 0xF6)},
{LV_COLOR_MAKE(0x42, 0xA5, 0xF5), LV_COLOR_MAKE(0x64, 0xB5, 0xF6), LV_COLOR_MAKE(0x90, 0xCA, 0xF9), LV_COLOR_MAKE(0xBB, 0xDE, 0xFB), LV_COLOR_MAKE(0xE3, 0xF2, 0xFD)},
{LV_COLOR_MAKE(0x29, 0xB6, 0xF6), LV_COLOR_MAKE(0x4F, 0xC3, 0xF7), LV_COLOR_MAKE(0x81, 0xD4, 0xFA), LV_COLOR_MAKE(0xB3, 0xE5, 0xFC), LV_COLOR_MAKE(0xE1, 0xF5, 0xFE)},
{LV_COLOR_MAKE(0x26, 0xC6, 0xDA), LV_COLOR_MAKE(0x4D, 0xD0, 0xE1), LV_COLOR_MAKE(0x80, 0xDE, 0xEA), LV_COLOR_MAKE(0xB2, 0xEB, 0xF2), LV_COLOR_MAKE(0xE0, 0xF7, 0xFA)},
{LV_COLOR_MAKE(0x26, 0xA6, 0x9A), LV_COLOR_MAKE(0x4D, 0xB6, 0xAC), LV_COLOR_MAKE(0x80, 0xCB, 0xC4), LV_COLOR_MAKE(0xB2, 0xDF, 0xDB), LV_COLOR_MAKE(0xE0, 0xF2, 0xF1)},
{LV_COLOR_MAKE(0x66, 0xBB, 0x6A), LV_COLOR_MAKE(0x81, 0xC7, 0x84), LV_COLOR_MAKE(0xA5, 0xD6, 0xA7), LV_COLOR_MAKE(0xC8, 0xE6, 0xC9), LV_COLOR_MAKE(0xE8, 0xF5, 0xE9)},
{LV_COLOR_MAKE(0x9C, 0xCC, 0x65), LV_COLOR_MAKE(0xAE, 0xD5, 0x81), LV_COLOR_MAKE(0xC5, 0xE1, 0xA5), LV_COLOR_MAKE(0xDC, 0xED, 0xC8), LV_COLOR_MAKE(0xF1, 0xF8, 0xE9)},
{LV_COLOR_MAKE(0xD4, 0xE1, 0x57), LV_COLOR_MAKE(0xDC, 0xE7, 0x75), LV_COLOR_MAKE(0xE6, 0xEE, 0x9C), LV_COLOR_MAKE(0xF0, 0xF4, 0xC3), LV_COLOR_MAKE(0xF9, 0xFB, 0xE7)},
{LV_COLOR_MAKE(0xFF, 0xEE, 0x58), LV_COLOR_MAKE(0xFF, 0xF1, 0x76), LV_COLOR_MAKE(0xFF, 0xF5, 0x9D), LV_COLOR_MAKE(0xFF, 0xF9, 0xC4), LV_COLOR_MAKE(0xFF, 0xFD, 0xE7)},
{LV_COLOR_MAKE(0xFF, 0xCA, 0x28), LV_COLOR_MAKE(0xFF, 0xD5, 0x4F), LV_COLOR_MAKE(0xFF, 0xE0, 0x82), LV_COLOR_MAKE(0xFF, 0xEC, 0xB3), LV_COLOR_MAKE(0xFF, 0xF8, 0xE1)},
{LV_COLOR_MAKE(0xFF, 0xA7, 0x26), LV_COLOR_MAKE(0xFF, 0xB7, 0x4D), LV_COLOR_MAKE(0xFF, 0xCC, 0x80), LV_COLOR_MAKE(0xFF, 0xE0, 0xB2), LV_COLOR_MAKE(0xFF, 0xF3, 0xE0)},
{LV_COLOR_MAKE(0xFF, 0x70, 0x43), LV_COLOR_MAKE(0xFF, 0x8A, 0x65), LV_COLOR_MAKE(0xFF, 0xAB, 0x91), LV_COLOR_MAKE(0xFF, 0xCC, 0xBC), LV_COLOR_MAKE(0xFB, 0xE9, 0xE7)},
{LV_COLOR_MAKE(0x8D, 0x6E, 0x63), LV_COLOR_MAKE(0xA1, 0x88, 0x7F), LV_COLOR_MAKE(0xBC, 0xAA, 0xA4), LV_COLOR_MAKE(0xD7, 0xCC, 0xC8), LV_COLOR_MAKE(0xEF, 0xEB, 0xE9)},
{LV_COLOR_MAKE(0x78, 0x90, 0x9C), LV_COLOR_MAKE(0x90, 0xA4, 0xAE), LV_COLOR_MAKE(0xB0, 0xBE, 0xC5), LV_COLOR_MAKE(0xCF, 0xD8, 0xDC), LV_COLOR_MAKE(0xEC, 0xEF, 0xF1)},
{LV_COLOR_MAKE(0xBD, 0xBD, 0xBD), LV_COLOR_MAKE(0xE0, 0xE0, 0xE0), LV_COLOR_MAKE(0xEE, 0xEE, 0xEE), LV_COLOR_MAKE(0xF5, 0xF5, 0xF5), LV_COLOR_MAKE(0xFA, 0xFA, 0xFA)},
};
if(p >= _LV_PALETTE_LAST) {
LV_LOG_WARN("Invalid palette: %d", p);
return lv_color_black();
}
if(lvl == 0 || lvl > 5) {
LV_LOG_WARN("Invalid level: %d. Must be 1..5", lvl);
return lv_color_black();
}
lvl--;
return colors[p][lvl];
}
lv_color_t lv_palette_darken(lv_palette_t p, uint8_t lvl)
{
static const lv_color_t colors[][4] = {
{LV_COLOR_MAKE(0xE5, 0x39, 0x35), LV_COLOR_MAKE(0xD3, 0x2F, 0x2F), LV_COLOR_MAKE(0xC6, 0x28, 0x28), LV_COLOR_MAKE(0xB7, 0x1C, 0x1C)},
{LV_COLOR_MAKE(0xD8, 0x1B, 0x60), LV_COLOR_MAKE(0xC2, 0x18, 0x5B), LV_COLOR_MAKE(0xAD, 0x14, 0x57), LV_COLOR_MAKE(0x88, 0x0E, 0x4F)},
{LV_COLOR_MAKE(0x8E, 0x24, 0xAA), LV_COLOR_MAKE(0x7B, 0x1F, 0xA2), LV_COLOR_MAKE(0x6A, 0x1B, 0x9A), LV_COLOR_MAKE(0x4A, 0x14, 0x8C)},
{LV_COLOR_MAKE(0x5E, 0x35, 0xB1), LV_COLOR_MAKE(0x51, 0x2D, 0xA8), LV_COLOR_MAKE(0x45, 0x27, 0xA0), LV_COLOR_MAKE(0x31, 0x1B, 0x92)},
{LV_COLOR_MAKE(0x39, 0x49, 0xAB), LV_COLOR_MAKE(0x30, 0x3F, 0x9F), LV_COLOR_MAKE(0x28, 0x35, 0x93), LV_COLOR_MAKE(0x1A, 0x23, 0x7E)},
{LV_COLOR_MAKE(0x1E, 0x88, 0xE5), LV_COLOR_MAKE(0x19, 0x76, 0xD2), LV_COLOR_MAKE(0x15, 0x65, 0xC0), LV_COLOR_MAKE(0x0D, 0x47, 0xA1)},
{LV_COLOR_MAKE(0x03, 0x9B, 0xE5), LV_COLOR_MAKE(0x02, 0x88, 0xD1), LV_COLOR_MAKE(0x02, 0x77, 0xBD), LV_COLOR_MAKE(0x01, 0x57, 0x9B)},
{LV_COLOR_MAKE(0x00, 0xAC, 0xC1), LV_COLOR_MAKE(0x00, 0x97, 0xA7), LV_COLOR_MAKE(0x00, 0x83, 0x8F), LV_COLOR_MAKE(0x00, 0x60, 0x64)},
{LV_COLOR_MAKE(0x00, 0x89, 0x7B), LV_COLOR_MAKE(0x00, 0x79, 0x6B), LV_COLOR_MAKE(0x00, 0x69, 0x5C), LV_COLOR_MAKE(0x00, 0x4D, 0x40)},
{LV_COLOR_MAKE(0x43, 0xA0, 0x47), LV_COLOR_MAKE(0x38, 0x8E, 0x3C), LV_COLOR_MAKE(0x2E, 0x7D, 0x32), LV_COLOR_MAKE(0x1B, 0x5E, 0x20)},
{LV_COLOR_MAKE(0x7C, 0xB3, 0x42), LV_COLOR_MAKE(0x68, 0x9F, 0x38), LV_COLOR_MAKE(0x55, 0x8B, 0x2F), LV_COLOR_MAKE(0x33, 0x69, 0x1E)},
{LV_COLOR_MAKE(0xC0, 0xCA, 0x33), LV_COLOR_MAKE(0xAF, 0xB4, 0x2B), LV_COLOR_MAKE(0x9E, 0x9D, 0x24), LV_COLOR_MAKE(0x82, 0x77, 0x17)},
{LV_COLOR_MAKE(0xFD, 0xD8, 0x35), LV_COLOR_MAKE(0xFB, 0xC0, 0x2D), LV_COLOR_MAKE(0xF9, 0xA8, 0x25), LV_COLOR_MAKE(0xF5, 0x7F, 0x17)},
{LV_COLOR_MAKE(0xFF, 0xB3, 0x00), LV_COLOR_MAKE(0xFF, 0xA0, 0x00), LV_COLOR_MAKE(0xFF, 0x8F, 0x00), LV_COLOR_MAKE(0xFF, 0x6F, 0x00)},
{LV_COLOR_MAKE(0xFB, 0x8C, 0x00), LV_COLOR_MAKE(0xF5, 0x7C, 0x00), LV_COLOR_MAKE(0xEF, 0x6C, 0x00), LV_COLOR_MAKE(0xE6, 0x51, 0x00)},
{LV_COLOR_MAKE(0xF4, 0x51, 0x1E), LV_COLOR_MAKE(0xE6, 0x4A, 0x19), LV_COLOR_MAKE(0xD8, 0x43, 0x15), LV_COLOR_MAKE(0xBF, 0x36, 0x0C)},
{LV_COLOR_MAKE(0x6D, 0x4C, 0x41), LV_COLOR_MAKE(0x5D, 0x40, 0x37), LV_COLOR_MAKE(0x4E, 0x34, 0x2E), LV_COLOR_MAKE(0x3E, 0x27, 0x23)},
{LV_COLOR_MAKE(0x54, 0x6E, 0x7A), LV_COLOR_MAKE(0x45, 0x5A, 0x64), LV_COLOR_MAKE(0x37, 0x47, 0x4F), LV_COLOR_MAKE(0x26, 0x32, 0x38)},
{LV_COLOR_MAKE(0x75, 0x75, 0x75), LV_COLOR_MAKE(0x61, 0x61, 0x61), LV_COLOR_MAKE(0x42, 0x42, 0x42), LV_COLOR_MAKE(0x21, 0x21, 0x21)},
};
if(p >= _LV_PALETTE_LAST) {
LV_LOG_WARN("Invalid palette: %d", p);
return lv_color_black();
}
if(lvl == 0 || lvl > 4) {
LV_LOG_WARN("Invalid level: %d. Must be 1..4", lvl);
return lv_color_black();
}
lvl--;
return colors[p][lvl];
}
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/osal/lv_cmsis_rtos2.h | /**
* @file lv_cmsis_rtos2.h
*
*/
/*
* Copyright (C) 2023 Arm Limited or its affiliates. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef LV_CMSIS_RTOS2_H
#define LV_CMSIS_RTOS2_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#if LV_USE_OS == LV_OS_CMSIS_RTOS2
#include "cmsis_os2.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef osThreadId_t lv_thread_t;
typedef osMutexId_t lv_mutex_t;
typedef osEventFlagsId_t lv_thread_sync_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**********************
* MACROS
**********************/
#endif /*LV_USE_OS == LV_OS_CMSIS_RTOS2*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_OS_CMSIS_RTOS2*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/osal/lv_os.h | /**
* @file lv_os.h
*
*/
#ifndef LV_OS_H
#define LV_OS_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* OS OPTIONS
*********************/
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#include "../misc/lv_types.h"
#include <stddef.h>
#if LV_USE_OS == LV_OS_NONE
#include "lv_os_none.h"
#elif LV_USE_OS == LV_OS_PTHREAD
#include "lv_pthread.h"
#elif LV_USE_OS == LV_OS_FREERTOS
#include "lv_freertos.h"
#elif LV_USE_OS == LV_OS_CMSIS_RTOS2
#include "lv_cmsis_rtos2.h"
#elif LV_USE_OS == LV_OS_RTTHREAD
#include "lv_rtthread.h"
#elif LV_USE_OS == LV_OS_CUSTOM
#include LV_OS_CUSTOM_INCLUDE
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef enum {
LV_THREAD_PRIO_LOWEST,
LV_THREAD_PRIO_LOW,
LV_THREAD_PRIO_MID,
LV_THREAD_PRIO_HIGH,
LV_THREAD_PRIO_HIGHEST,
} lv_thread_prio_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/*----------------------------------------
* These functions needs to be implemented
* for specific operating systems
*---------------------------------------*/
/**
* Create a new thread
* @param thread a variable in which the thread will be stored
* @param prio priority of the thread
* @param callback function of the thread
* @param stack_size stack size in bytes
* @param user_data arbitrary data, will be available in the callback
* @return LV_RESULT_OK: success; LV_RESULT_INVALID: failure
*/
lv_result_t lv_thread_init(lv_thread_t * thread, lv_thread_prio_t prio, void (*callback)(void *), size_t stack_size,
void * user_data);
/**
* Delete a thread
* @param thread the thread to delete
* @return LV_RESULT_OK: success; LV_RESULT_INVALID: failure
*/
lv_result_t lv_thread_delete(lv_thread_t * thread);
/**
* Create a mutex
* @param mutex a variable in which the thread will be stored
* @return LV_RESULT_OK: success; LV_RESULT_INVALID: failure
*/
lv_result_t lv_mutex_init(lv_mutex_t * mutex);
/**
* Lock a mutex
* @param mutex the mutex to lock
* @return LV_RESULT_OK: success; LV_RESULT_INVALID: failure
*/
lv_result_t lv_mutex_lock(lv_mutex_t * mutex);
/**
* Lock a mutex from interrupt
* @param mutex the mutex to lock
* @return LV_RESULT_OK: success; LV_RESULT_INVALID: failure
*/
lv_result_t lv_mutex_lock_isr(lv_mutex_t * mutex);
/**
* Unlock a mutex
* @param mutex the mutex to unlock
* @return LV_RESULT_OK: success; LV_RESULT_INVALID: failure
*/
lv_result_t lv_mutex_unlock(lv_mutex_t * mutex);
/**
* Delete a mutex
* @param mutex the mutex to delete
* @return LV_RESULT_OK: success; LV_RESULT_INVALID: failure
*/
lv_result_t lv_mutex_delete(lv_mutex_t * mutex);
/**
* Create a thread synchronization object
* @param sync a variable in which the sync will be stored
* @return LV_RESULT_OK: success; LV_RESULT_INVALID: failure
*/
lv_result_t lv_thread_sync_init(lv_thread_sync_t * sync);
/**
* Wait for a "signal" on a sync object
* @param sync a sync object
* @return LV_RESULT_OK: success; LV_RESULT_INVALID: failure
*/
lv_result_t lv_thread_sync_wait(lv_thread_sync_t * sync);
/**
* Send a wake-up signal to a sync object
* @param sync a sync object
* @return LV_RESULT_OK: success; LV_RESULT_INVALID: failure
*/
lv_result_t lv_thread_sync_signal(lv_thread_sync_t * sync);
/**
* Delete a sync object
* @param sync a sync object to delete
* @return LV_RESULT_OK: success; LV_RESULT_INVALID: failure
*/
lv_result_t lv_thread_sync_delete(lv_thread_sync_t * sync);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_OS_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/osal/lv_os_none.c | /**
* @file lv_os_none.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_os.h"
#if LV_USE_OS == LV_OS_NONE
#include "../misc/lv_types.h"
#include "../misc/lv_assert.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
lv_result_t lv_thread_init(lv_thread_t * thread, lv_thread_prio_t prio, void (*callback)(void *), size_t stack_size,
void * user_data)
{
LV_UNUSED(thread);
LV_UNUSED(callback);
LV_UNUSED(prio);
LV_UNUSED(stack_size);
LV_UNUSED(user_data);
LV_ASSERT(0);
return LV_RESULT_INVALID;
}
lv_result_t lv_thread_delete(lv_thread_t * thread)
{
LV_UNUSED(thread);
LV_ASSERT(0);
return LV_RESULT_INVALID;
}
lv_result_t lv_mutex_init(lv_mutex_t * mutex)
{
LV_UNUSED(mutex);
return LV_RESULT_OK;
}
lv_result_t lv_mutex_lock(lv_mutex_t * mutex)
{
LV_UNUSED(mutex);
return LV_RESULT_OK;
}
lv_result_t lv_mutex_lock_isr(lv_mutex_t * mutex)
{
LV_UNUSED(mutex);
return LV_RESULT_OK;
}
lv_result_t lv_mutex_unlock(lv_mutex_t * mutex)
{
LV_UNUSED(mutex);
return LV_RESULT_OK;
}
lv_result_t lv_mutex_delete(lv_mutex_t * mutex)
{
LV_UNUSED(mutex);
return LV_RESULT_OK;
}
lv_result_t lv_thread_sync_init(lv_thread_sync_t * sync)
{
LV_UNUSED(sync);
LV_ASSERT(0);
return LV_RESULT_INVALID;
}
lv_result_t lv_thread_sync_wait(lv_thread_sync_t * sync)
{
LV_UNUSED(sync);
LV_ASSERT(0);
return LV_RESULT_INVALID;
}
lv_result_t lv_thread_sync_signal(lv_thread_sync_t * sync)
{
LV_UNUSED(sync);
LV_ASSERT(0);
return LV_RESULT_INVALID;
}
lv_result_t lv_thread_sync_delete(lv_thread_sync_t * sync)
{
LV_UNUSED(sync);
LV_ASSERT(0);
return LV_RESULT_INVALID;
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif /*LV_USE_OS == LV_OS_NONE*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/osal/lv_os_none.h | /**
* @file lv_os_none.h
*
*/
#ifndef LV_OS_NONE_H
#define LV_OS_NONE_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#if LV_USE_OS == LV_OS_NONE
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef int lv_mutex_t;
typedef int lv_thread_t;
typedef int lv_thread_sync_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**********************
* MACROS
**********************/
#endif /*LV_USE_OS == LV_OS_NONE*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_OS_NONE_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/osal/lv_freertos.c | /**
* @file lv_freertos.c
*
*/
/**
* Copyright 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
/*********************
* INCLUDES
*********************/
#include "lv_os.h"
#if LV_USE_OS == LV_OS_FREERTOS
#include "atomic.h"
#include "../misc/lv_log.h"
/*********************
* DEFINES
*********************/
#define ulMAX_COUNT 10U
#ifndef pcTASK_NAME
#define pcTASK_NAME "lvglDraw"
#endif
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void prvRunThread(void * pxArg);
static void prvMutexInit(lv_mutex_t * pxMutex);
static void prvCheckMutexInit(lv_mutex_t * pxMutex);
#if !USE_FREERTOS_TASK_NOTIFY
static void prvCondInit(lv_thread_sync_t * pxCond);
static void prvCheckCondInit(lv_thread_sync_t * pxCond);
static void prvTestAndDecrement(lv_thread_sync_t * pxCond,
uint32_t ulLocalWaitingThreads);
#endif
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
lv_result_t lv_thread_init(lv_thread_t * pxThread, lv_thread_prio_t xSchedPriority,
void (*pvStartRoutine)(void *), size_t usStackSize,
void * xAttr)
{
pxThread->xTaskArg = xAttr;
pxThread->pvStartRoutine = pvStartRoutine;
BaseType_t xTaskCreateStatus = xTaskCreate(
prvRunThread,
pcTASK_NAME,
(uint16_t)usStackSize,
(void *)pxThread,
tskIDLE_PRIORITY + xSchedPriority,
&pxThread->xTaskHandle);
/* Ensure that the FreeRTOS task was successfully created. */
if(xTaskCreateStatus != pdPASS) {
LV_LOG_ERROR("xTaskCreate failed!");
return LV_RESULT_INVALID;
}
return LV_RESULT_OK;
}
lv_result_t lv_thread_delete(lv_thread_t * pxThread)
{
vTaskDelete(pxThread->xTaskHandle);
return LV_RESULT_OK;
}
lv_result_t lv_mutex_init(lv_mutex_t * pxMutex)
{
/* If mutex in uninitialized, perform initialization. */
prvCheckMutexInit(pxMutex);
return LV_RESULT_OK;
}
lv_result_t lv_mutex_lock(lv_mutex_t * pxMutex)
{
/* If mutex in uninitialized, perform initialization. */
prvCheckMutexInit(pxMutex);
BaseType_t xMutexTakeStatus = xSemaphoreTake(pxMutex->xMutex, portMAX_DELAY);
if(xMutexTakeStatus != pdTRUE) {
LV_LOG_ERROR("xSemaphoreTake failed!");
return LV_RESULT_INVALID;
}
return LV_RESULT_OK;
}
lv_result_t lv_mutex_lock_isr(lv_mutex_t * pxMutex)
{
/* If mutex in uninitialized, perform initialization. */
prvCheckMutexInit(pxMutex);
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
BaseType_t xMutexTakeStatus = xSemaphoreTakeFromISR(pxMutex->xMutex, &xHigherPriorityTaskWoken);
if(xMutexTakeStatus != pdTRUE) {
LV_LOG_ERROR("xSemaphoreTake failed!");
return LV_RESULT_INVALID;
}
/* If xHigherPriorityTaskWoken is now set to pdTRUE then a context switch
should be performed to ensure the interrupt returns directly to the highest
priority task. The macro used for this purpose is dependent on the port in
use and may be called portEND_SWITCHING_ISR(). */
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
return LV_RESULT_OK;
}
lv_result_t lv_mutex_unlock(lv_mutex_t * pxMutex)
{
/* If mutex in uninitialized, perform initialization. */
prvCheckMutexInit(pxMutex);
BaseType_t xMutexGiveStatus = xSemaphoreGive(pxMutex->xMutex);
if(xMutexGiveStatus != pdTRUE) {
LV_LOG_ERROR("xSemaphoreGive failed!");
return LV_RESULT_INVALID;
}
return LV_RESULT_OK;
}
lv_result_t lv_mutex_delete(lv_mutex_t * pxMutex)
{
vSemaphoreDelete(pxMutex->xMutex);
pxMutex->xIsInitialized = pdFALSE;
return LV_RESULT_OK;
}
lv_result_t lv_thread_sync_init(lv_thread_sync_t * pxCond)
{
#if USE_FREERTOS_TASK_NOTIFY
/* Store the handle of the calling task. */
pxCond->xTaskToNotify = xTaskGetCurrentTaskHandle();
#else
/* If the cond is uninitialized, perform initialization. */
prvCheckCondInit(pxCond);
#endif
return LV_RESULT_OK;
}
lv_result_t lv_thread_sync_wait(lv_thread_sync_t * pxCond)
{
lv_result_t lvRes = LV_RESULT_OK;
#if USE_FREERTOS_TASK_NOTIFY
LV_UNUSED(pxCond);
/* Wait for other task to notify this task. */
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
#else
uint32_t ulLocalWaitingThreads;
/* If the cond is uninitialized, perform initialization. */
prvCheckCondInit(pxCond);
/* Acquire the mutex. */
xSemaphoreTake(pxCond->xSyncMutex, portMAX_DELAY);
while(!pxCond->xSyncSignal) {
/* Increase the counter of threads blocking on condition variable, then
* release the mutex. */
/* Atomically increments thread waiting by 1, and
* stores number of threads waiting before increment. */
ulLocalWaitingThreads = Atomic_Increment_u32(&pxCond->ulWaitingThreads);
BaseType_t xMutexStatus = xSemaphoreGive(pxCond->xSyncMutex);
/* Wait on the condition variable. */
if(xMutexStatus == pdTRUE) {
BaseType_t xCondWaitStatus = xSemaphoreTake(
pxCond->xCondWaitSemaphore,
portMAX_DELAY);
/* Relock the mutex. */
xSemaphoreTake(pxCond->xSyncMutex, portMAX_DELAY);
if(xCondWaitStatus != pdTRUE) {
LV_LOG_ERROR("xSemaphoreTake(xCondWaitSemaphore) failed!");
lvRes = LV_RESULT_INVALID;
/* Atomically decrements thread waiting by 1.
* If iLocalWaitingThreads is updated by other thread(s) in between,
* this implementation guarantees to decrement by 1 based on the
* value currently in pxCond->ulWaitingThreads. */
prvTestAndDecrement(pxCond, ulLocalWaitingThreads + 1);
}
}
else {
LV_LOG_ERROR("xSemaphoreGive(xSyncMutex) failed!");
lvRes = LV_RESULT_INVALID;
/* Atomically decrements thread waiting by 1.
* If iLocalWaitingThreads is updated by other thread(s) in between,
* this implementation guarantees to decrement by 1 based on the
* value currently in pxCond->ulWaitingThreads. */
prvTestAndDecrement(pxCond, ulLocalWaitingThreads + 1);
}
}
pxCond->xSyncSignal = pdFALSE;
/* Release the mutex. */
xSemaphoreGive(pxCond->xSyncMutex);
#endif
return lvRes;
}
lv_result_t lv_thread_sync_signal(lv_thread_sync_t * pxCond)
{
#if USE_FREERTOS_TASK_NOTIFY
/* Send a notification to the task waiting. */
xTaskNotifyGive(pxCond->xTaskToNotify);
#else
/* If the cond is uninitialized, perform initialization. */
prvCheckCondInit(pxCond);
/* Acquire the mutex. */
xSemaphoreTake(pxCond->xSyncMutex, portMAX_DELAY);
pxCond->xSyncSignal = pdTRUE;
/* Local copy of number of threads waiting. */
uint32_t ulLocalWaitingThreads = pxCond->ulWaitingThreads;
/* Test local copy of threads waiting is larger than zero. */
while(ulLocalWaitingThreads > 0) {
/* Atomically check whether the copy in memory has changed.
* If not, set the copy of threads waiting in memory to zero. */
if(ATOMIC_COMPARE_AND_SWAP_SUCCESS == Atomic_CompareAndSwap_u32(
&pxCond->ulWaitingThreads,
0,
ulLocalWaitingThreads)) {
/* Unblock all. */
for(uint32_t i = 0; i < ulLocalWaitingThreads; i++) {
xSemaphoreGive(pxCond->xCondWaitSemaphore);
}
break;
}
/* Local copy is out dated. Reload from memory and retry. */
ulLocalWaitingThreads = pxCond->ulWaitingThreads;
}
/* Release the mutex. */
xSemaphoreGive(pxCond->xSyncMutex);
#endif
return LV_RESULT_OK;
}
lv_result_t lv_thread_sync_delete(lv_thread_sync_t * pxCond)
{
#if USE_FREERTOS_TASK_NOTIFY
LV_UNUSED(pxCond);
#else
/* Cleanup all resources used by the cond. */
vSemaphoreDelete(pxCond->xCondWaitSemaphore);
vSemaphoreDelete(pxCond->xSyncMutex);
pxCond->ulWaitingThreads = 0;
pxCond->xSyncSignal = pdFALSE;
pxCond->xIsInitialized = pdFALSE;
#endif
return LV_RESULT_OK;
}
/**********************
* STATIC FUNCTIONS
**********************/
static void prvRunThread(void * pxArg)
{
lv_thread_t * pxThread = (lv_thread_t *)pxArg;
/* Run the thread routine. */
pxThread->pvStartRoutine((void *)pxThread->xTaskArg);
vTaskDelete(NULL);
}
static void prvMutexInit(lv_mutex_t * pxMutex)
{
pxMutex->xMutex = xSemaphoreCreateMutex();
/* Ensure that the FreeRTOS mutex was successfully created. */
if(pxMutex->xMutex == NULL) {
LV_LOG_ERROR("xSemaphoreCreateMutex failed!");
return;
}
/* Mutex successfully created. */
pxMutex->xIsInitialized = pdTRUE;
}
static void prvCheckMutexInit(lv_mutex_t * pxMutex)
{
/* Check if the mutex needs to be initialized. */
if(pxMutex->xIsInitialized == pdFALSE) {
/* Mutex initialization must be in a critical section to prevent two threads
* from initializing it at the same time. */
taskENTER_CRITICAL();
/* Check again that the mutex is still uninitialized, i.e. it wasn't
* initialized while this function was waiting to enter the critical
* section. */
if(pxMutex->xIsInitialized == pdFALSE) {
prvMutexInit(pxMutex);
}
/* Exit the critical section. */
taskEXIT_CRITICAL();
}
}
#if !USE_FREERTOS_TASK_NOTIFY
static void prvCondInit(lv_thread_sync_t * pxCond)
{
pxCond->xCondWaitSemaphore = xSemaphoreCreateCounting(ulMAX_COUNT, 0U);
/* Ensure that the FreeRTOS semaphore was successfully created. */
if(pxCond->xCondWaitSemaphore == NULL) {
LV_LOG_ERROR("xSemaphoreCreateCounting failed!");
return;
}
pxCond->xSyncMutex = xSemaphoreCreateMutex();
/* Ensure that the FreeRTOS mutex was successfully created. */
if(pxCond->xSyncMutex == NULL) {
LV_LOG_ERROR("xSemaphoreCreateMutex failed!");
/* Cleanup. */
vSemaphoreDelete(pxCond->xCondWaitSemaphore);
return;
}
/* Condition variable successfully created. */
pxCond->ulWaitingThreads = 0;
pxCond->xSyncSignal = pdFALSE;
pxCond->xIsInitialized = pdTRUE;
}
static void prvCheckCondInit(lv_thread_sync_t * pxCond)
{
BaseType_t xSemCreateStatus = pdTRUE;
/* Check if the condition variable needs to be initialized. */
if(pxCond->xIsInitialized == pdFALSE) {
/* Cond initialization must be in a critical section to prevent two
* threads from initializing it at the same time. */
taskENTER_CRITICAL();
/* Check again that the condition is still uninitialized, i.e. it wasn't
* initialized while this function was waiting to enter the critical
* section. */
if(pxCond->xIsInitialized == pdFALSE) {
prvCondInit(pxCond);
}
/* Exit the critical section. */
taskEXIT_CRITICAL();
}
}
static void prvTestAndDecrement(lv_thread_sync_t * pxCond,
uint32_t ulLocalWaitingThreads)
{
/* Test local copy of threads waiting is larger than zero. */
while(ulLocalWaitingThreads > 0) {
/* Atomically check whether the copy in memory has changed.
* If not, decrease the copy of threads waiting in memory. */
if(ATOMIC_COMPARE_AND_SWAP_SUCCESS == Atomic_CompareAndSwap_u32(
&pxCond->ulWaitingThreads,
ulLocalWaitingThreads - 1,
ulLocalWaitingThreads)) {
/* Signal one succeeded. Break. */
break;
}
/* Local copy may be out dated. Reload from memory and retry. */
ulLocalWaitingThreads = pxCond->ulWaitingThreads;
}
}
#endif
#endif /*LV_USE_OS == LV_OS_FREERTOS*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/osal/lv_rtthread.c | /**
* @file lv_rtthread.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_os.h"
#if LV_USE_OS == LV_OS_RTTHREAD
#include "../misc/lv_log.h"
/*********************
* DEFINES
*********************/
#define THREAD_TIMESLICE 20U
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
lv_result_t lv_thread_init(lv_thread_t * thread, lv_thread_prio_t prio, void (*callback)(void *), size_t stack_size,
void * user_data)
{
thread->thread = rt_thread_create("thread",
callback,
user_data,
stack_size,
prio,
THREAD_TIMESLICE);
rt_err_t ret = rt_thread_startup(thread->thread);
if(ret) {
LV_LOG_WARN("Error: %d", ret);
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_thread_delete(lv_thread_t * thread)
{
rt_err_t ret = rt_thread_delete(thread->thread);
if(ret) {
LV_LOG_WARN("Error: %d", ret);
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_mutex_init(lv_mutex_t * mutex)
{
mutex->mutex = rt_mutex_create("mutex", RT_IPC_FLAG_PRIO);
if(mutex->mutex == RT_NULL) {
LV_LOG_WARN("create mutex failed");
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_mutex_lock(lv_mutex_t * mutex)
{
rt_err_t ret = rt_mutex_take(mutex->mutex, RT_WAITING_NO);
if(ret) {
LV_LOG_WARN("Error: %d", ret);
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_mutex_lock_isr(lv_mutex_t * mutex)
{
rt_err_t ret = rt_mutex_take(mutex->mutex, RT_WAITING_FOREVER);
if(ret) {
LV_LOG_WARN("Error: %d", ret);
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_mutex_unlock(lv_mutex_t * mutex)
{
rt_err_t ret = rt_mutex_release(mutex->mutex);
if(ret) {
LV_LOG_WARN("Error: %d", ret);
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_mutex_delete(lv_mutex_t * mutex)
{
rt_err_t ret = rt_mutex_delete(mutex->mutex);
if(ret) {
LV_LOG_WARN("Error: %d", ret);
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_thread_sync_init(lv_thread_sync_t * sync)
{
sync->sem = rt_sem_create("sem", RT_IPC_FLAG_PRIO);
if(sync->sem == RT_NULL) {
LV_LOG_WARN("create semaphore failed");
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_thread_sync_wait(lv_thread_sync_t * sync)
{
rt_err_t ret = rt_sem_take(sync->sem, RT_WAITING_FOREVER);
if(ret) {
LV_LOG_WARN("Error: %d", ret);
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_thread_sync_signal(lv_thread_sync_t * sync)
{
rt_err_t ret = rt_sem_release(sync->sem);
if(ret) {
LV_LOG_WARN("Error: %d", ret);
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_thread_sync_delete(lv_thread_sync_t * sync)
{
rt_err_t ret = rt_sem_delete(sync->sem);
if(ret) {
LV_LOG_WARN("Error: %d", ret);
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif /*LV_USE_OS == LV_OS_RTTHREAD*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/osal/lv_freertos.h | /**
* @file lv_freertos.h
*
*/
/**
* Copyright 2023 NXP
*
* SPDX-License-Identifier: MIT
*/
#ifndef LV_FREERTOS_H
#define LV_FREERTOS_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lv_os.h"
#if LV_USE_OS == LV_OS_FREERTOS
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
/*********************
* DEFINES
*********************/
/*
* Unblocking an RTOS task with a direct notification is 45% faster and uses less RAM
* than unblocking a task using an intermediary object such as a binary semaphore.
*
* RTOS task notifications can only be used when there is only one task that can be the recipient of the event.
*/
#define USE_FREERTOS_TASK_NOTIFY 1
/**********************
* TYPEDEFS
**********************/
typedef struct {
void (*pvStartRoutine)(void *); /**< Application thread function. */
void * xTaskArg; /**< Arguments for application thread function. */
TaskHandle_t xTaskHandle; /**< FreeRTOS task handle. */
} lv_thread_t;
typedef struct {
BaseType_t xIsInitialized; /**< Set to pdTRUE if this mutex is initialized, pdFALSE otherwise. */
SemaphoreHandle_t xMutex; /**< FreeRTOS mutex. */
} lv_mutex_t;
typedef struct {
#if USE_FREERTOS_TASK_NOTIFY
TaskHandle_t xTaskToNotify;
#else
BaseType_t
xIsInitialized; /**< Set to pdTRUE if this condition variable is initialized, pdFALSE otherwise. */
SemaphoreHandle_t xCondWaitSemaphore; /**< Threads block on this semaphore in lv_thread_sync_wait. */
uint32_t ulWaitingThreads; /**< The number of threads currently waiting on this condition variable. */
SemaphoreHandle_t xSyncMutex; /**< Threads take this mutex before accessing the condition variable. */
BaseType_t xSyncSignal; /**< Set to pdTRUE if the thread is signaled, pdFALSE otherwise. */
#endif
} lv_thread_sync_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**********************
* MACROS
**********************/
#endif /*LV_USE_OS == LV_OS_FREERTOS*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_FREERTOS_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/osal/lv_pthread.c | /**
* @file lv_pthread.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_os.h"
#if LV_USE_OS == LV_OS_PTHREAD
#include <errno.h>
#include "../misc/lv_log.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void * generic_callback(void * user_data);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
lv_result_t lv_thread_init(lv_thread_t * thread, lv_thread_prio_t prio, void (*callback)(void *), size_t stack_size,
void * user_data)
{
LV_UNUSED(prio);
LV_UNUSED(stack_size);
thread->callback = callback;
thread->user_data = user_data;
pthread_create(&thread->thread, NULL, generic_callback, thread);
return LV_RESULT_OK;
}
lv_result_t lv_thread_delete(lv_thread_t * thread)
{
LV_UNUSED(thread);
/*How?*/
return LV_RESULT_OK;
}
lv_result_t lv_mutex_init(lv_mutex_t * mutex)
{
int ret = pthread_mutex_init(mutex, NULL);
if(ret) {
LV_LOG_WARN("Error: %d", ret);
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_mutex_lock(lv_mutex_t * mutex)
{
int ret = pthread_mutex_lock(mutex);
if(ret) {
LV_LOG_WARN("Error: %d", ret);
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_mutex_lock_isr(lv_mutex_t * mutex)
{
int ret = pthread_mutex_lock(mutex);
if(ret) {
LV_LOG_WARN("Error: %d", ret);
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_mutex_unlock(lv_mutex_t * mutex)
{
int ret = pthread_mutex_unlock(mutex);
if(ret) {
LV_LOG_WARN("Error: %d", ret);
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_mutex_delete(lv_mutex_t * mutex)
{
pthread_mutex_destroy(mutex);
return LV_RESULT_OK;
}
lv_result_t lv_thread_sync_init(lv_thread_sync_t * sync)
{
pthread_mutex_init(&sync->mutex, 0);
pthread_cond_init(&sync->cond, 0);
sync->v = false;
return LV_RESULT_OK;
}
lv_result_t lv_thread_sync_wait(lv_thread_sync_t * sync)
{
pthread_mutex_lock(&sync->mutex);
while(!sync->v) {
pthread_cond_wait(&sync->cond, &sync->mutex);
}
sync->v = false;
pthread_mutex_unlock(&sync->mutex);
return LV_RESULT_OK;
}
lv_result_t lv_thread_sync_signal(lv_thread_sync_t * sync)
{
pthread_mutex_lock(&sync->mutex);
sync->v = true;
pthread_cond_signal(&sync->cond);
pthread_mutex_unlock(&sync->mutex);
return LV_RESULT_OK;
}
lv_result_t lv_thread_sync_delete(lv_thread_sync_t * sync)
{
pthread_mutex_destroy(&sync->mutex);
pthread_cond_destroy(&sync->cond);
return LV_RESULT_OK;
}
/**********************
* STATIC FUNCTIONS
**********************/
static void * generic_callback(void * user_data)
{
lv_thread_t * thread = user_data;
thread->callback(thread->user_data);
return NULL;
}
#endif /*LV_USE_OS == LV_OS_PTHREAD*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/osal/lv_rtthread.h | /**
* @file lv_rtthread.h
*
*/
#ifndef LV_RTTHREAD_H
#define LV_RTTHREAD_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#if LV_USE_OS == LV_OS_RTTHREAD
#include <rtthread.h>
#include <stdbool.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef struct {
rt_thread_t thread;
} lv_thread_t;
typedef struct {
rt_mutex_t mutex;
} lv_mutex_t;
typedef struct {
rt_sem_t sem;
} lv_thread_sync_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**********************
* MACROS
**********************/
#endif /*LV_USE_OS == LV_OS_RTTHREAD*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_RTTHREAD_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/osal/lv_pthread.h | /**
* @file lv_pthread.h
*
*/
#ifndef LV_PTHREAD_H
#define LV_PTHREAD_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#if LV_USE_OS == LV_OS_PTHREAD
#include <pthread.h>
#include <semaphore.h>
#include <stdbool.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef struct {
pthread_t thread;
void (*callback)(void *);
void * user_data;
} lv_thread_t;
typedef pthread_mutex_t lv_mutex_t;
typedef struct {
pthread_mutex_t mutex;
pthread_cond_t cond;
bool v;
} lv_thread_sync_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**********************
* MACROS
**********************/
#endif /*LV_USE_OS == LV_OS_PTHREAD*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_PTHREAD_H*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/osal/lv_cmsis_rtos2.c | /**
* @file lv_cmsis_rtos2.c
*
*/
/*
* Copyright (C) 2023 Arm Limited or its affiliates. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
/*********************
* INCLUDES
*********************/
#include "lv_os.h"
#if LV_USE_OS == LV_OS_CMSIS_RTOS2
#include "../misc/lv_log.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
lv_result_t lv_thread_init(lv_thread_t * thread, lv_thread_prio_t prio, void (*callback)(void *), size_t stack_size,
void * user_data)
{
static const osPriority_t prio_map[] = {
[LV_THREAD_PRIO_LOWEST] = osPriorityLow,
[LV_THREAD_PRIO_LOW] = osPriorityBelowNormal,
[LV_THREAD_PRIO_MID] = osPriorityNormal,
[LV_THREAD_PRIO_HIGH] = osPriorityHigh,
[LV_THREAD_PRIO_HIGHEST] = osPriorityRealtime7,
};
osThreadAttr_t c_tThreadAttribute = {
.stack_size = stack_size,
.priority = prio_map[prio],
};
*thread = osThreadNew(callback, user_data, &c_tThreadAttribute);
if(NULL == *thread) {
LV_LOG_WARN("Error: Failed to create a cmsis-rtos2 thread.");
return LV_RESULT_INVALID;
}
return LV_RESULT_OK;
}
lv_result_t lv_thread_delete(lv_thread_t * thread)
{
osThreadDetach(*thread);
osStatus_t status = osThreadTerminate(*thread);
if(status == osOK) {
return LV_RESULT_OK;
}
return LV_RESULT_INVALID;
}
lv_result_t lv_mutex_init(lv_mutex_t * mutex)
{
const osMutexAttr_t Thread_Mutex_attr = {
"LVGLMutex",
osMutexRecursive | osMutexPrioInherit | osMutexRobust,
};
*mutex = osMutexNew(&Thread_Mutex_attr);
if(*mutex == NULL) {
LV_LOG_WARN("Error: failed to create cmsis-rtos mutex");
return LV_RESULT_INVALID;
}
return LV_RESULT_OK;
}
lv_result_t lv_mutex_lock(lv_mutex_t * mutex)
{
osStatus_t status = osMutexAcquire(*mutex, 0U);
if(status != osOK) {
LV_LOG_WARN("Error: failed to lock cmsis-rtos2 mutex %d", (int)status);
return LV_RESULT_INVALID;
}
return LV_RESULT_OK;
}
lv_result_t lv_mutex_lock_isr(lv_mutex_t * mutex)
{
osStatus_t status = osMutexAcquire(*mutex, 0U);
if(status != osOK) {
LV_LOG_WARN("Error: failed to lock cmsis-rtos2 mutex in an ISR %d", (int)status);
return LV_RESULT_INVALID;
}
return LV_RESULT_OK;
}
lv_result_t lv_mutex_unlock(lv_mutex_t * mutex)
{
osStatus_t status = osMutexRelease(*mutex);
if(status != osOK) {
LV_LOG_WARN("Error: failed to release cmsis-rtos2 mutex %d", (int)status);
return LV_RESULT_INVALID;
}
return LV_RESULT_OK;
}
lv_result_t lv_mutex_delete(lv_mutex_t * mutex)
{
osStatus_t status = osMutexDelete(*mutex);
if(status != osOK) {
LV_LOG_WARN("Error: failed to delete cmsis-rtos2 mutex %d", (int)status);
return LV_RESULT_INVALID;
}
return LV_RESULT_OK;
}
lv_result_t lv_thread_sync_init(lv_thread_sync_t * sync)
{
*sync = osEventFlagsNew(NULL);
if(NULL == *sync) {
LV_LOG_WARN("Error: failed to create a cmsis-rtos2 EventFlag");
return LV_RESULT_INVALID;
}
return LV_RESULT_OK;
}
lv_result_t lv_thread_sync_wait(lv_thread_sync_t * sync)
{
uint32_t ret = osEventFlagsWait(*sync, 0x01, osFlagsWaitAny, osWaitForever);
if(ret & (1 << 31)) {
LV_LOG_WARN("Error: failed to wait a cmsis-rtos2 EventFlag %d", ret);
return LV_RESULT_INVALID;
}
return LV_RESULT_OK;
}
lv_result_t lv_thread_sync_signal(lv_thread_sync_t * sync)
{
uint32_t ret = osEventFlagsSet(*sync, 0x01);
if(ret & (1 << 31)) {
LV_LOG_WARN("Error: failed to set a cmsis-rtos2 EventFlag %d", ret);
return LV_RESULT_INVALID;
}
return LV_RESULT_OK;
}
lv_result_t lv_thread_sync_delete(lv_thread_sync_t * sync)
{
osStatus_t status = osEventFlagsDelete(*sync);
if(status != osOK) {
LV_LOG_WARN("Error: failed to delete a cmsis-rtos2 EventFlag %d", (int)status);
return LV_RESULT_INVALID;
}
return LV_RESULT_OK;
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif /*LV_USE_OS == LV_OS_CMSIS_RTOS2*/
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/core/lv_obj.c | /**
* @file lv_obj.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_obj.h"
#include "../indev/lv_indev.h"
#include "../indev/lv_indev_private.h"
#include "lv_refr.h"
#include "lv_group.h"
#include "../display/lv_display.h"
#include "../display/lv_display_private.h"
#include "../themes/lv_theme.h"
#include "../misc/lv_assert.h"
#include "../misc/lv_math.h"
#include "../misc/lv_log.h"
#include "../tick/lv_tick.h"
#include "../stdlib/lv_string.h"
#include <stdint.h>
#include <string.h>
/*********************
* DEFINES
*********************/
#define MY_CLASS &lv_obj_class
#define LV_OBJ_DEF_WIDTH (LV_DPX(100))
#define LV_OBJ_DEF_HEIGHT (LV_DPX(50))
#define STYLE_TRANSITION_MAX 32
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void lv_obj_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj);
static void lv_obj_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj);
static void lv_obj_draw(lv_event_t * e);
static void lv_obj_event(const lv_obj_class_t * class_p, lv_event_t * e);
static void draw_scrollbar(lv_obj_t * obj, lv_layer_t * layer);
static lv_result_t scrollbar_init_draw_dsc(lv_obj_t * obj, lv_draw_rect_dsc_t * dsc);
static bool obj_valid_child(const lv_obj_t * parent, const lv_obj_t * obj_to_find);
static void update_obj_state(lv_obj_t * obj, lv_state_t new_state);
#if LV_USE_OBJ_PROPERTY
static lv_result_t lv_obj_set_any(lv_obj_t *, lv_prop_id_t, const lv_property_t *);
static lv_result_t lv_obj_get_any(const lv_obj_t *, lv_prop_id_t, lv_property_t *);
#endif
/**********************
* STATIC VARIABLES
**********************/
#if LV_USE_OBJ_PROPERTY
static const lv_property_ops_t properties[] = {
{
.id = LV_PROPERTY_OBJ_PARENT,
.setter = lv_obj_set_parent,
.getter = lv_obj_get_parent,
},
{
.id = LV_PROPERTY_ID_ANY,
.setter = lv_obj_set_any,
.getter = lv_obj_get_any,
}
};
#endif
const lv_obj_class_t lv_obj_class = {
.constructor_cb = lv_obj_constructor,
.destructor_cb = lv_obj_destructor,
.event_cb = lv_obj_event,
.width_def = LV_DPI_DEF,
.height_def = LV_DPI_DEF,
.editable = LV_OBJ_CLASS_EDITABLE_FALSE,
.group_def = LV_OBJ_CLASS_GROUP_DEF_FALSE,
.instance_size = (sizeof(lv_obj_t)),
.base_class = NULL,
.name = "obj",
#if LV_USE_OBJ_PROPERTY
.prop_index_start = LV_PROPERTY_OBJ_START,
.prop_index_end = LV_PROPERTY_OBJ_END,
.properties = properties,
.properties_count = sizeof(properties) / sizeof(properties[0]),
#endif
};
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
lv_obj_t * lv_obj_create(lv_obj_t * parent)
{
LV_LOG_INFO("begin");
lv_obj_t * obj = lv_obj_class_create_obj(MY_CLASS, parent);
lv_obj_class_init_obj(obj);
return obj;
}
/*=====================
* Setter functions
*====================*/
/*-----------------
* Attribute set
*----------------*/
void lv_obj_add_flag(lv_obj_t * obj, lv_obj_flag_t f)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
bool was_on_layout = lv_obj_is_layout_positioned(obj);
/* We must invalidate the area occupied by the object before we hide it as calls to invalidate hidden objects are ignored */
if(f & LV_OBJ_FLAG_HIDDEN) lv_obj_invalidate(obj);
obj->flags |= f;
if(f & LV_OBJ_FLAG_HIDDEN) {
if(lv_obj_has_state(obj, LV_STATE_FOCUSED)) {
lv_group_t * group = lv_obj_get_group(obj);
if(group != NULL) {
lv_group_focus_next(group);
lv_obj_t * next_obj = lv_group_get_focused(group);
if(next_obj != NULL) {
lv_obj_invalidate(next_obj);
}
}
}
}
if((was_on_layout != lv_obj_is_layout_positioned(obj)) || (f & (LV_OBJ_FLAG_LAYOUT_1 | LV_OBJ_FLAG_LAYOUT_2))) {
lv_obj_mark_layout_as_dirty(lv_obj_get_parent(obj));
lv_obj_mark_layout_as_dirty(obj);
}
if(f & LV_OBJ_FLAG_SCROLLABLE) {
lv_area_t hor_area, ver_area;
lv_obj_get_scrollbar_area(obj, &hor_area, &ver_area);
lv_obj_invalidate_area(obj, &hor_area);
lv_obj_invalidate_area(obj, &ver_area);
}
}
void lv_obj_remove_flag(lv_obj_t * obj, lv_obj_flag_t f)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
bool was_on_layout = lv_obj_is_layout_positioned(obj);
if(f & LV_OBJ_FLAG_SCROLLABLE) {
lv_area_t hor_area, ver_area;
lv_obj_get_scrollbar_area(obj, &hor_area, &ver_area);
lv_obj_invalidate_area(obj, &hor_area);
lv_obj_invalidate_area(obj, &ver_area);
}
obj->flags &= (~f);
if(f & LV_OBJ_FLAG_HIDDEN) {
lv_obj_invalidate(obj);
if(lv_obj_is_layout_positioned(obj)) {
lv_obj_mark_layout_as_dirty(lv_obj_get_parent(obj));
lv_obj_mark_layout_as_dirty(obj);
}
}
if((was_on_layout != lv_obj_is_layout_positioned(obj)) || (f & (LV_OBJ_FLAG_LAYOUT_1 | LV_OBJ_FLAG_LAYOUT_2))) {
lv_obj_mark_layout_as_dirty(lv_obj_get_parent(obj));
}
}
void lv_obj_update_flag(lv_obj_t * obj, lv_obj_flag_t f, bool v)
{
if(v) lv_obj_add_flag(obj, f);
else lv_obj_remove_flag(obj, f);
}
void lv_obj_add_state(lv_obj_t * obj, lv_state_t state)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_state_t new_state = obj->state | state;
if(obj->state != new_state) {
if(new_state & LV_STATE_DISABLED) {
lv_indev_reset(NULL, obj);
}
update_obj_state(obj, new_state);
}
}
void lv_obj_remove_state(lv_obj_t * obj, lv_state_t state)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_state_t new_state = obj->state & (~state);
if(obj->state != new_state) {
update_obj_state(obj, new_state);
}
}
void lv_obj_set_state(lv_obj_t * obj, lv_state_t state, bool v)
{
if(v) lv_obj_add_state(obj, state);
else lv_obj_remove_state(obj, state);
}
/*=======================
* Getter functions
*======================*/
bool lv_obj_has_flag(const lv_obj_t * obj, lv_obj_flag_t f)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
return (obj->flags & f) == f;
}
bool lv_obj_has_flag_any(const lv_obj_t * obj, lv_obj_flag_t f)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
return !!(obj->flags & f);
}
lv_state_t lv_obj_get_state(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
return obj->state;
}
bool lv_obj_has_state(const lv_obj_t * obj, lv_state_t state)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
return !!(obj->state & state);
}
lv_group_t * lv_obj_get_group(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
if(obj->spec_attr) return obj->spec_attr->group_p;
else return NULL;
}
/*-------------------
* OTHER FUNCTIONS
*------------------*/
void lv_obj_allocate_spec_attr(lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
if(obj->spec_attr == NULL) {
obj->spec_attr = lv_malloc(sizeof(_lv_obj_spec_attr_t));
LV_ASSERT_MALLOC(obj->spec_attr);
if(obj->spec_attr == NULL) return;
lv_memzero(obj->spec_attr, sizeof(_lv_obj_spec_attr_t));
obj->spec_attr->scroll_dir = LV_DIR_ALL;
obj->spec_attr->scrollbar_mode = LV_SCROLLBAR_MODE_AUTO;
}
}
bool lv_obj_check_type(const lv_obj_t * obj, const lv_obj_class_t * class_p)
{
if(obj == NULL) return false;
return obj->class_p == class_p;
}
bool lv_obj_has_class(const lv_obj_t * obj, const lv_obj_class_t * class_p)
{
const lv_obj_class_t * obj_class = obj->class_p;
while(obj_class) {
if(obj_class == class_p) return true;
obj_class = obj_class->base_class;
}
return false;
}
const lv_obj_class_t * lv_obj_get_class(const lv_obj_t * obj)
{
return obj->class_p;
}
bool lv_obj_is_valid(const lv_obj_t * obj)
{
lv_display_t * disp = lv_display_get_next(NULL);
while(disp) {
uint32_t i;
for(i = 0; i < disp->screen_cnt; i++) {
if(disp->screens[i] == obj) return true;
bool found = obj_valid_child(disp->screens[i], obj);
if(found) return true;
}
disp = lv_display_get_next(disp);
}
return false;
}
/**********************
* STATIC FUNCTIONS
**********************/
static void lv_obj_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
{
LV_UNUSED(class_p);
LV_TRACE_OBJ_CREATE("begin");
lv_obj_t * parent = obj->parent;
if(parent) {
int32_t sl = lv_obj_get_scroll_left(parent);
int32_t st = lv_obj_get_scroll_top(parent);
obj->coords.y1 = parent->coords.y1 + lv_obj_get_style_pad_top(parent, LV_PART_MAIN) - st;
obj->coords.y2 = obj->coords.y1 - 1;
obj->coords.x1 = parent->coords.x1 + lv_obj_get_style_pad_left(parent, LV_PART_MAIN) - sl;
obj->coords.x2 = obj->coords.x1 - 1;
}
/*Set attributes*/
obj->flags = LV_OBJ_FLAG_CLICKABLE;
obj->flags |= LV_OBJ_FLAG_SNAPPABLE;
if(parent) obj->flags |= LV_OBJ_FLAG_PRESS_LOCK;
if(parent) obj->flags |= LV_OBJ_FLAG_SCROLL_CHAIN;
obj->flags |= LV_OBJ_FLAG_CLICK_FOCUSABLE;
obj->flags |= LV_OBJ_FLAG_SCROLLABLE;
obj->flags |= LV_OBJ_FLAG_SCROLL_ELASTIC;
obj->flags |= LV_OBJ_FLAG_SCROLL_MOMENTUM;
obj->flags |= LV_OBJ_FLAG_SCROLL_WITH_ARROW;
if(parent) obj->flags |= LV_OBJ_FLAG_GESTURE_BUBBLE;
#if LV_USE_OBJ_ID
lv_obj_assign_id(class_p, obj);
#endif
LV_TRACE_OBJ_CREATE("finished");
}
static void lv_obj_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
{
LV_UNUSED(class_p);
_lv_event_mark_deleted(obj);
/*Remove all style*/
lv_obj_enable_style_refresh(false); /*No need to refresh the style because the object will be deleted*/
lv_obj_remove_style_all(obj);
lv_obj_enable_style_refresh(true);
/*Remove the animations from this object*/
lv_anim_delete(obj, NULL);
/*Delete from the group*/
lv_group_t * group = lv_obj_get_group(obj);
if(group) lv_group_remove_obj(obj);
if(obj->spec_attr) {
if(obj->spec_attr->children) {
lv_free(obj->spec_attr->children);
obj->spec_attr->children = NULL;
}
if(obj->spec_attr->event_list.dsc) {
lv_free(obj->spec_attr->event_list.dsc);
obj->spec_attr->event_list.dsc = NULL;
obj->spec_attr->event_list.cnt = 0;
}
lv_free(obj->spec_attr);
obj->spec_attr = NULL;
}
#if LV_USE_OBJ_ID
lv_obj_free_id(obj);
#endif
}
static void lv_obj_draw(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * obj = lv_event_get_target(e);
if(code == LV_EVENT_COVER_CHECK) {
lv_cover_check_info_t * info = lv_event_get_param(e);
if(info->res == LV_COVER_RES_MASKED) return;
if(lv_obj_get_style_clip_corner(obj, LV_PART_MAIN)) {
info->res = LV_COVER_RES_MASKED;
return;
}
/*Most trivial test. Is the mask fully IN the object? If no it surely doesn't cover it*/
int32_t r = lv_obj_get_style_radius(obj, LV_PART_MAIN);
int32_t w = lv_obj_get_style_transform_width(obj, LV_PART_MAIN);
int32_t h = lv_obj_get_style_transform_height(obj, LV_PART_MAIN);
lv_area_t coords;
lv_area_copy(&coords, &obj->coords);
lv_area_increase(&coords, w, h);
if(_lv_area_is_in(info->area, &coords, r) == false) {
info->res = LV_COVER_RES_NOT_COVER;
return;
}
if(lv_obj_get_style_bg_opa(obj, LV_PART_MAIN) < LV_OPA_MAX) {
info->res = LV_COVER_RES_NOT_COVER;
return;
}
if(lv_obj_get_style_opa(obj, LV_PART_MAIN) < LV_OPA_MAX) {
info->res = LV_COVER_RES_NOT_COVER;
return;
}
info->res = LV_COVER_RES_COVER;
}
else if(code == LV_EVENT_DRAW_MAIN) {
lv_layer_t * layer = lv_event_get_layer(e);
lv_draw_rect_dsc_t draw_dsc;
lv_draw_rect_dsc_init(&draw_dsc);
lv_obj_init_draw_rect_dsc(obj, LV_PART_MAIN, &draw_dsc);
/*If the border is drawn later disable loading its properties*/
if(lv_obj_get_style_border_post(obj, LV_PART_MAIN)) {
draw_dsc.border_post = 1;
}
int32_t w = lv_obj_get_style_transform_width(obj, LV_PART_MAIN);
int32_t h = lv_obj_get_style_transform_height(obj, LV_PART_MAIN);
lv_area_t coords;
lv_area_copy(&coords, &obj->coords);
lv_area_increase(&coords, w, h);
lv_draw_rect(layer, &draw_dsc, &coords);
}
else if(code == LV_EVENT_DRAW_POST) {
lv_layer_t * layer = lv_event_get_layer(e);
draw_scrollbar(obj, layer);
/*If the border is drawn later disable loading other properties*/
if(lv_obj_get_style_border_post(obj, LV_PART_MAIN)) {
lv_draw_rect_dsc_t draw_dsc;
lv_draw_rect_dsc_init(&draw_dsc);
draw_dsc.bg_opa = LV_OPA_TRANSP;
draw_dsc.bg_image_opa = LV_OPA_TRANSP;
draw_dsc.outline_opa = LV_OPA_TRANSP;
draw_dsc.shadow_opa = LV_OPA_TRANSP;
lv_obj_init_draw_rect_dsc(obj, LV_PART_MAIN, &draw_dsc);
int32_t w = lv_obj_get_style_transform_width(obj, LV_PART_MAIN);
int32_t h = lv_obj_get_style_transform_height(obj, LV_PART_MAIN);
lv_area_t coords;
lv_area_copy(&coords, &obj->coords);
lv_area_increase(&coords, w, h);
lv_draw_rect(layer, &draw_dsc, &coords);
}
}
}
static void draw_scrollbar(lv_obj_t * obj, lv_layer_t * layer)
{
lv_area_t hor_area;
lv_area_t ver_area;
lv_obj_get_scrollbar_area(obj, &hor_area, &ver_area);
if(lv_area_get_size(&hor_area) <= 0 && lv_area_get_size(&ver_area) <= 0) return;
lv_draw_rect_dsc_t draw_dsc;
lv_result_t sb_res = scrollbar_init_draw_dsc(obj, &draw_dsc);
if(sb_res != LV_RESULT_OK) return;
if(lv_area_get_size(&hor_area) > 0) {
draw_dsc.base.id1 = 0;
lv_draw_rect(layer, &draw_dsc, &hor_area);
}
if(lv_area_get_size(&ver_area) > 0) {
draw_dsc.base.id1 = 1;
lv_draw_rect(layer, &draw_dsc, &ver_area);
}
}
/**
* Initialize the draw descriptor for the scrollbar
* @param obj pointer to an object
* @param dsc the draw descriptor to initialize
* @return LV_RESULT_OK: the scrollbar is visible; LV_RESULT_INVALID: the scrollbar is not visible
*/
static lv_result_t scrollbar_init_draw_dsc(lv_obj_t * obj, lv_draw_rect_dsc_t * dsc)
{
lv_draw_rect_dsc_init(dsc);
dsc->bg_opa = lv_obj_get_style_bg_opa(obj, LV_PART_SCROLLBAR);
if(dsc->bg_opa > LV_OPA_MIN) {
dsc->bg_color = lv_obj_get_style_bg_color(obj, LV_PART_SCROLLBAR);
}
dsc->border_opa = lv_obj_get_style_border_opa(obj, LV_PART_SCROLLBAR);
if(dsc->border_opa > LV_OPA_MIN) {
dsc->border_width = lv_obj_get_style_border_width(obj, LV_PART_SCROLLBAR);
if(dsc->border_width > 0) {
dsc->border_color = lv_obj_get_style_border_color(obj, LV_PART_SCROLLBAR);
}
else {
dsc->border_opa = LV_OPA_TRANSP;
}
}
dsc->shadow_opa = lv_obj_get_style_shadow_opa(obj, LV_PART_SCROLLBAR);
if(dsc->shadow_opa > LV_OPA_MIN) {
dsc->shadow_width = lv_obj_get_style_shadow_width(obj, LV_PART_SCROLLBAR);
if(dsc->shadow_width > 0) {
dsc->shadow_spread = lv_obj_get_style_shadow_spread(obj, LV_PART_SCROLLBAR);
dsc->shadow_color = lv_obj_get_style_shadow_color(obj, LV_PART_SCROLLBAR);
}
else {
dsc->shadow_opa = LV_OPA_TRANSP;
}
}
lv_opa_t opa = lv_obj_get_style_opa_recursive(obj, LV_PART_SCROLLBAR);
if(opa < LV_OPA_MAX) {
lv_opa_t v = LV_OPA_MIX2(dsc->bg_opa, opa);
dsc->bg_opa = v;
dsc->border_opa = v;
dsc->shadow_opa = v;
}
if(dsc->bg_opa != LV_OPA_TRANSP || dsc->border_opa != LV_OPA_TRANSP || dsc->shadow_opa != LV_OPA_TRANSP) {
dsc->radius = lv_obj_get_style_radius(obj, LV_PART_SCROLLBAR);
return LV_RESULT_OK;
}
else {
return LV_RESULT_INVALID;
}
}
static void lv_obj_event(const lv_obj_class_t * class_p, lv_event_t * e)
{
LV_UNUSED(class_p);
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * obj = lv_event_get_current_target(e);
if(code == LV_EVENT_PRESSED) {
lv_obj_add_state(obj, LV_STATE_PRESSED);
}
else if(code == LV_EVENT_RELEASED) {
lv_obj_remove_state(obj, LV_STATE_PRESSED);
void * param = lv_event_get_param(e);
/*Go the checked state if enabled*/
if(lv_indev_get_scroll_obj(param) == NULL && lv_obj_has_flag(obj, LV_OBJ_FLAG_CHECKABLE)) {
if(!(lv_obj_get_state(obj) & LV_STATE_CHECKED)) lv_obj_add_state(obj, LV_STATE_CHECKED);
else lv_obj_remove_state(obj, LV_STATE_CHECKED);
lv_result_t res = lv_obj_send_event(obj, LV_EVENT_VALUE_CHANGED, NULL);
if(res != LV_RESULT_OK) return;
}
}
else if(code == LV_EVENT_PRESS_LOST) {
lv_obj_remove_state(obj, LV_STATE_PRESSED);
}
else if(code == LV_EVENT_STYLE_CHANGED) {
uint32_t child_cnt = lv_obj_get_child_cnt(obj);
for(uint32_t i = 0; i < child_cnt; i++) {
lv_obj_t * child = obj->spec_attr->children[i];
lv_obj_mark_layout_as_dirty(child);
}
}
else if(code == LV_EVENT_KEY) {
if(lv_obj_has_flag(obj, LV_OBJ_FLAG_CHECKABLE)) {
char c = *((char *)lv_event_get_param(e));
if(c == LV_KEY_RIGHT || c == LV_KEY_UP) {
lv_obj_add_state(obj, LV_STATE_CHECKED);
}
else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) {
lv_obj_remove_state(obj, LV_STATE_CHECKED);
}
/*With Enter LV_EVENT_RELEASED will send VALUE_CHANGE event*/
if(c != LV_KEY_ENTER) {
lv_result_t res = lv_obj_send_event(obj, LV_EVENT_VALUE_CHANGED, NULL);
if(res != LV_RESULT_OK) return;
}
}
else if(lv_obj_has_flag(obj, LV_OBJ_FLAG_SCROLLABLE | LV_OBJ_FLAG_SCROLL_WITH_ARROW) && !lv_obj_is_editable(obj)) {
/*scroll by keypad or encoder*/
lv_anim_enable_t anim_enable = LV_ANIM_OFF;
int32_t sl = lv_obj_get_scroll_left(obj);
int32_t sr = lv_obj_get_scroll_right(obj);
char c = *((char *)lv_event_get_param(e));
if(c == LV_KEY_DOWN) {
/*use scroll_to_x/y functions to enforce scroll limits*/
lv_obj_scroll_to_y(obj, lv_obj_get_scroll_y(obj) + lv_obj_get_height(obj) / 4, anim_enable);
}
else if(c == LV_KEY_UP) {
lv_obj_scroll_to_y(obj, lv_obj_get_scroll_y(obj) - lv_obj_get_height(obj) / 4, anim_enable);
}
else if(c == LV_KEY_RIGHT) {
/*If the object can't be scrolled horizontally then scroll it vertically*/
if(!((lv_obj_get_scroll_dir(obj) & LV_DIR_HOR) && (sl > 0 || sr > 0)))
lv_obj_scroll_to_y(obj, lv_obj_get_scroll_y(obj) + lv_obj_get_height(obj) / 4, anim_enable);
else
lv_obj_scroll_to_x(obj, lv_obj_get_scroll_x(obj) + lv_obj_get_width(obj) / 4, anim_enable);
}
else if(c == LV_KEY_LEFT) {
/*If the object can't be scrolled horizontally then scroll it vertically*/
if(!((lv_obj_get_scroll_dir(obj) & LV_DIR_HOR) && (sl > 0 || sr > 0)))
lv_obj_scroll_to_y(obj, lv_obj_get_scroll_y(obj) - lv_obj_get_height(obj) / 4, anim_enable);
else
lv_obj_scroll_to_x(obj, lv_obj_get_scroll_x(obj) - lv_obj_get_width(obj) / 4, anim_enable);
}
}
}
else if(code == LV_EVENT_FOCUSED) {
if(lv_obj_has_flag(obj, LV_OBJ_FLAG_SCROLL_ON_FOCUS)) {
lv_obj_scroll_to_view_recursive(obj, LV_ANIM_ON);
}
bool editing = false;
editing = lv_group_get_editing(lv_obj_get_group(obj));
lv_state_t state = LV_STATE_FOCUSED;
/* Use the indev for then indev handler.
* But if the obj was focused manually it returns NULL so try to
* use the indev from the event*/
lv_indev_t * indev = lv_indev_active();
if(indev == NULL) indev = lv_event_get_indev(e);
lv_indev_type_t indev_type = lv_indev_get_type(indev);
if(indev_type == LV_INDEV_TYPE_KEYPAD || indev_type == LV_INDEV_TYPE_ENCODER) state |= LV_STATE_FOCUS_KEY;
if(editing) {
state |= LV_STATE_EDITED;
lv_obj_add_state(obj, state);
}
else {
lv_obj_add_state(obj, state);
lv_obj_remove_state(obj, LV_STATE_EDITED);
}
}
else if(code == LV_EVENT_SCROLL_BEGIN) {
lv_obj_add_state(obj, LV_STATE_SCROLLED);
}
else if(code == LV_EVENT_SCROLL_END) {
lv_obj_remove_state(obj, LV_STATE_SCROLLED);
if(lv_obj_get_scrollbar_mode(obj) == LV_SCROLLBAR_MODE_ACTIVE) {
lv_area_t hor_area, ver_area;
lv_obj_get_scrollbar_area(obj, &hor_area, &ver_area);
lv_obj_invalidate_area(obj, &hor_area);
lv_obj_invalidate_area(obj, &ver_area);
}
}
else if(code == LV_EVENT_DEFOCUSED) {
lv_obj_remove_state(obj, LV_STATE_FOCUSED | LV_STATE_EDITED | LV_STATE_FOCUS_KEY);
}
else if(code == LV_EVENT_SIZE_CHANGED) {
int32_t align = lv_obj_get_style_align(obj, LV_PART_MAIN);
uint16_t layout = lv_obj_get_style_layout(obj, LV_PART_MAIN);
if(layout || align) {
lv_obj_mark_layout_as_dirty(obj);
}
uint32_t i;
uint32_t child_cnt = lv_obj_get_child_cnt(obj);
for(i = 0; i < child_cnt; i++) {
lv_obj_t * child = obj->spec_attr->children[i];
lv_obj_mark_layout_as_dirty(child);
}
}
else if(code == LV_EVENT_CHILD_CHANGED) {
int32_t w = lv_obj_get_style_width(obj, LV_PART_MAIN);
int32_t h = lv_obj_get_style_height(obj, LV_PART_MAIN);
int32_t align = lv_obj_get_style_align(obj, LV_PART_MAIN);
uint16_t layout = lv_obj_get_style_layout(obj, LV_PART_MAIN);
if(layout || align || w == LV_SIZE_CONTENT || h == LV_SIZE_CONTENT) {
lv_obj_mark_layout_as_dirty(obj);
}
}
else if(code == LV_EVENT_REFR_EXT_DRAW_SIZE) {
int32_t d = lv_obj_calculate_ext_draw_size(obj, LV_PART_MAIN);
lv_event_set_ext_draw_size(e, d);
}
else if(code == LV_EVENT_DRAW_MAIN || code == LV_EVENT_DRAW_POST || code == LV_EVENT_COVER_CHECK) {
lv_obj_draw(e);
}
else if(code == LV_EVENT_INDEV_RESET) {
lv_obj_remove_state(obj, LV_STATE_PRESSED);
lv_obj_remove_state(obj, LV_STATE_SCROLLED);
}
}
/**
* Set the state (fully overwrite) of an object.
* If specified in the styles, transition animations will be started from the previous state to the current.
* @param obj pointer to an object
* @param state the new state
*/
static void update_obj_state(lv_obj_t * obj, lv_state_t new_state)
{
if(obj->state == new_state) return;
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_state_t prev_state = obj->state;
_lv_style_state_cmp_t cmp_res = _lv_obj_style_state_compare(obj, prev_state, new_state);
/*If there is no difference in styles there is nothing else to do*/
if(cmp_res == _LV_STYLE_STATE_CMP_SAME) {
obj->state = new_state;
return;
}
/*Invalidate the object in their current state*/
lv_obj_invalidate(obj);
obj->state = new_state;
_lv_obj_style_transition_dsc_t * ts = lv_malloc(sizeof(_lv_obj_style_transition_dsc_t) * STYLE_TRANSITION_MAX);
lv_memzero(ts, sizeof(_lv_obj_style_transition_dsc_t) * STYLE_TRANSITION_MAX);
uint32_t tsi = 0;
uint32_t i;
for(i = 0; i < obj->style_cnt && tsi < STYLE_TRANSITION_MAX; i++) {
_lv_obj_style_t * obj_style = &obj->styles[i];
lv_state_t state_act = lv_obj_style_get_selector_state(obj->styles[i].selector);
lv_part_t part_act = lv_obj_style_get_selector_part(obj->styles[i].selector);
if(state_act & (~new_state)) continue; /*Skip unrelated styles*/
if(obj_style->is_trans) continue;
lv_style_value_t v;
if(lv_style_get_prop_inlined(obj_style->style, LV_STYLE_TRANSITION, &v) != LV_STYLE_RES_FOUND) continue;
const lv_style_transition_dsc_t * tr = v.ptr;
/*Add the props to the set if not added yet or added but with smaller weight*/
uint32_t j;
for(j = 0; tr->props[j] != 0 && tsi < STYLE_TRANSITION_MAX; j++) {
uint32_t t;
for(t = 0; t < tsi; t++) {
lv_style_selector_t selector = ts[t].selector;
lv_state_t state_ts = lv_obj_style_get_selector_state(selector);
lv_part_t part_ts = lv_obj_style_get_selector_part(selector);
if(ts[t].prop == tr->props[j] && part_ts == part_act && state_ts >= state_act) break;
}
/*If not found add it*/
if(t == tsi) {
ts[tsi].time = tr->time;
ts[tsi].delay = tr->delay;
ts[tsi].path_cb = tr->path_xcb;
ts[tsi].prop = tr->props[j];
ts[tsi].user_data = tr->user_data;
ts[tsi].selector = obj_style->selector;
tsi++;
}
}
}
for(i = 0; i < tsi; i++) {
lv_part_t part_act = lv_obj_style_get_selector_part(ts[i].selector);
_lv_obj_style_create_transition(obj, part_act, prev_state, new_state, &ts[i]);
}
lv_free(ts);
if(cmp_res == _LV_STYLE_STATE_CMP_DIFF_REDRAW) {
/*Invalidation is not enough, e.g. layer type needs to be updated too*/
lv_obj_refresh_style(obj, LV_PART_ANY, LV_STYLE_PROP_ANY);
}
else if(cmp_res == _LV_STYLE_STATE_CMP_DIFF_LAYOUT) {
lv_obj_refresh_style(obj, LV_PART_ANY, LV_STYLE_PROP_ANY);
}
else if(cmp_res == _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD) {
lv_obj_invalidate(obj);
lv_obj_refresh_ext_draw_size(obj);
}
}
static bool obj_valid_child(const lv_obj_t * parent, const lv_obj_t * obj_to_find)
{
/*Check all children of `parent`*/
uint32_t child_cnt = 0;
if(parent->spec_attr) child_cnt = parent->spec_attr->child_cnt;
uint32_t i;
for(i = 0; i < child_cnt; i++) {
lv_obj_t * child = parent->spec_attr->children[i];
if(child == obj_to_find) {
return true;
}
/*Check the children*/
bool found = obj_valid_child(child, obj_to_find);
if(found) {
return true;
}
}
return false;
}
#if LV_USE_OBJ_PROPERTY
static lv_result_t lv_obj_set_any(lv_obj_t * obj, lv_prop_id_t id, const lv_property_t * prop)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
if(id >= LV_PROPERTY_OBJ_FLAG_START && id <= LV_PROPERTY_OBJ_FLAG_END) {
lv_obj_flag_t flag = 1L << (id - LV_PROPERTY_OBJ_FLAG_START);
if(prop->num) lv_obj_add_flag(obj, flag);
else lv_obj_remove_flag(obj, flag);
return LV_RESULT_OK;
}
else {
return LV_RESULT_INVALID;
}
}
static lv_result_t lv_obj_get_any(const lv_obj_t * obj, lv_prop_id_t id, lv_property_t * prop)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
if(id >= LV_PROPERTY_OBJ_FLAG_START && id <= LV_PROPERTY_OBJ_FLAG_END) {
lv_obj_flag_t flag = 1L << (id - LV_PROPERTY_OBJ_FLAG_START);
prop->id = id;
prop->num = obj->flags & flag;
return LV_RESULT_OK;
}
else {
return LV_RESULT_INVALID;
}
}
#endif
|
0 | repos/zig_workbench/BaseLVGL/lib/lvgl/src | repos/zig_workbench/BaseLVGL/lib/lvgl/src/core/lv_obj_property.h | /**
* @file lv_obj_property.h
*
*/
#ifndef LV_OBJ_PROPERTY_H
#define LV_OBJ_PROPERTY_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../misc/lv_types.h"
#include "../misc/lv_style.h"
#if LV_USE_OBJ_PROPERTY
/*********************
* DEFINES
*********************/
/*All possible property value types*/
#define LV_PROPERTY_TYPE_INVALID 0 /*Use default 0 as invalid to detect program outliers*/
#define LV_PROPERTY_TYPE_INT 1 /*int32_t type*/
#define LV_PROPERTY_TYPE_COLOR 2 /*ARGB8888 type*/
#define LV_PROPERTY_TYPE_POINTER 3 /*void * pointer*/
#define LV_PROPERTY_TYPE_IMGSRC 4 /*Special pointer for image*/
/**********************
* TYPEDEFS
**********************/
struct _lv_obj_t;
#define LV_PROPERTY_ID(clz, name, type, index) LV_PROPERTY_## clz ##_##name = (LV_PROPERTY_## clz ##_START + (index)) | ((type) << 28)
#define LV_PROPERTY_ID_TYPE(id) ((id) >> 28)
#define LV_PROPERTY_ID_INDEX(id) ((id) & 0xfffffff)
/*Set properties from an array of lv_property_t*/
#define LV_OBJ_PROPERTY_ARRAY_SET(obj, array) lv_obj_set_properties(obj, array, sizeof(array)/sizeof(array[0]))
/**
* Group of predefined widget ID start value.
*/
enum {
LV_PROPERTY_ID_INVALID = 0,
/*ID 0 to 0xff are style ID, check lv_style_prop_t*/
LV_PROPERTY_ID_START = 0x100, /*ID little than 0xff is style ID*/
/* lv_obj.c */
LV_PROPERTY_OBJ_START = 1000,
/* lv_image.c */
LV_PROPERTY_IMAGE_START = 1100,
/*Special ID*/
LV_PROPERTY_ID_BUILTIN_LAST, /*Use it to extend ID and make sure it's unique and compile time determinant*/
LV_PROPERTY_ID_ANY = 0x7ffffffe, /*Special ID used by lvgl to intercept all setter/getter call.*/
};
typedef uint32_t lv_prop_id_t;
typedef struct {
lv_prop_id_t id;
union {
int32_t num; /**< Number integer number (opacity, enums, booleans or "normal" numbers)*/
const void * ptr; /**< Constant pointers (font, cone text, etc)*/
lv_color_t color; /**< Colors*/
lv_style_value_t _style; /**< A place holder for style value which is same as property value.*/
};
} lv_property_t;
typedef struct {
lv_prop_id_t id;
void * setter;
void * getter;
} lv_property_ops_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/*=====================
* Setter functions
*====================*/
/**
* Set widget property value.
* @param obj pointer to an object
* @param id ID of which property
* @param value The property value to set
* @return return LV_RESULT_OK if success
*/
lv_result_t lv_obj_set_property(struct _lv_obj_t * obj, const lv_property_t * value);
lv_result_t lv_obj_set_properties(struct _lv_obj_t * obj, const lv_property_t * value, uint32_t count);
/*=====================
* Getter functions
*====================*/
/**
* Read property value from object
* @param obj pointer to an object
* @param id ID of which property
* @param value pointer to a buffer to store the value
* @return ? to be discussed, LV_RESULT_OK or LV_RESULT_INVALID
*/
lv_property_t lv_obj_get_property(struct _lv_obj_t * obj, lv_prop_id_t id);
/**********************
* MACROS
**********************/
#endif /*LV_USE_OBJ_PROPERTY*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_OBJ_PROPERTY_H*/
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.