lv_draw_sw_blend_private.h
API reference for lv_draw_sw_blend_private.h
Functions
lv_color32_unpremultiply
Undo the alpha scaling of a premultiplied pixel, giving back a straight color. Shared so the output formats that need it can't drift apart.
static lv_color32_t lv_color32_unpremultiply(lv_color32_t c)| Name | Type | Description |
|---|---|---|
c | lv_color32_t | a premultiplied pixel |
Returns: lv_color32_t — the same pixel with straight channels
lv_color32_lumi_of
Luminance of an image pixel for the grayscale and indexed outputs. A premultiplied source has its channels already scaled by its alpha, so undo that first to get the same value a straight source would give.
static uint8_t lv_color32_lumi_of(lv_color32_t c, bool premultiplied)| Name | Type | Description |
|---|---|---|
c | lv_color32_t | the pixel |
premultiplied | bool | true: c is premultiplied |
Returns: uint8_t — the luminance, 0..255
lv_color_16_16_mix_inlined
Inlined version of lv_color_16_16_mix() for the per-pixel blend loops. Identical to the public function, but being in a header it can be inlined and loop-invariant parts (e.g. a constant fill color) can be hoisted out of the loops.
static uint16_t lv_color_16_16_mix_inlined(uint16_t c1, uint16_t c2, uint8_t mix)| Name | Type | Description |
|---|---|---|
c1 | uint16_t | the first color (typically the foreground color) |
c2 | uint16_t | the second color (typically the background color) |
mix | uint8_t | 0..255, the opacity of c1 |
Returns: uint16_t — the mixed color
lv_color_mix32_inlined
Inlined version of lv_color_mix32() for the per-pixel blend loops. Identical to the public function, but being in a header it can be inlined, sparing a function call per pixel. The channels are mixed independently on purpose: superscalar CPUs can compute them in parallel, which is faster than packing them into one 32 bit value.
< Fully cover if opa >= LV_OPA_MAX
< Fully transparent if opa <= LV_OPA_MIN
static lv_color32_t lv_color_mix32_inlined(lv_color32_t fg, lv_color32_t bg)| Name | Type | Description |
|---|---|---|
fg | lv_color32_t | the foreground color, fg.alpha is the mix ratio |
bg | lv_color32_t | the background color |
Returns: lv_color32_t — the mixed color, the alpha of bg is kept
lv_color_mix32_premultiplied_inlined
Inlined version of lv_color_mix32_premultiplied() for the per-pixel blend loops. The premultiplied foreground is added as is and the background is weighted with the remaining alpha.
< Fully cover if opa >= LV_OPA_MAX
< Fully transparent if opa <= LV_OPA_MIN
< Fully cover if opa >= LV_OPA_MAX
static lv_color32_t lv_color_mix32_premultiplied_inlined(lv_color32_t fg, lv_color32_t bg)| Name | Type | Description |
|---|---|---|
fg | lv_color32_t | the premultiplied foreground color, fg.alpha is the mix ratio |
bg | lv_color32_t | the background color |
Returns: lv_color32_t — the mixed color with the alpha of bg, except for an (almost) opaque foreground where fg is returned as it is, so its alpha is kept
Structs
_lv_draw_sw_blend_dsc_t
| Member | Type | Description |
|---|---|---|
blend_area | const lv_area_t * | The area with absolute coordinates to draw on layer->buf will be clipped to layer->clip_area |
src_buf | const void * | Pointer to an image to blend. If set fill_color is ignored |
src_stride | uint32_t | |
src_color_format | lv_color_format_t | |
src_area | const lv_area_t * | |
opa | lv_opa_t | The overall opacity |
color | lv_color_t | Fill color |
mask_buf | const lv_opa_t * | NULL if ignored, or an alpha mask to apply on blend_area |
mask_res | lv_draw_sw_mask_res_t | The result of the previous mask operation |
mask_area | const lv_area_t * | The area of mask_buf with absolute coordinates |
mask_stride | int32_t | |
blend_mode | lv_blend_mode_t | E.g. LV_BLEND_MODE_ADDITIVE |
_lv_draw_sw_blend_fill_dsc_t
| Member | Type | Description |
|---|---|---|
dest_buf | void * | |
dest_w | int32_t | |
dest_h | int32_t | |
dest_stride | int32_t | |
mask_buf | const lv_opa_t * | |
mask_stride | int32_t | |
color | lv_color_t | |
opa | lv_opa_t | |
relative_area | lv_area_t |
_lv_draw_sw_blend_image_dsc_t
| Member | Type | Description |
|---|---|---|
dest_buf | void * | |
dest_w | int32_t | |
dest_h | int32_t | |
dest_stride | int32_t | |
mask_buf | const lv_opa_t * | |
mask_stride | int32_t | |
src_buf | const void * | |
src_stride | int32_t | |
src_color_format | lv_color_format_t | |
opa | lv_opa_t | |
blend_mode | lv_blend_mode_t | |
relative_area | lv_area_t | The blend area relative to the layer's buffer area. |
src_area | lv_area_t | The original src area. |
lv_draw_sw_word_t
Read or write four bytes of a pixel or mask buffer as one word. The caller must align the pointer to a word first.
Through a union and not a cast: C99 6.5p7 lets an object be accessed through an aggregate that has its type among the members, *(uint32_t *)ptr on a uint8_t or uint16_t buffer is undefined and GCC 13 at -O2 really does keep a stale half word across it.
| Member | Type | Description |
|---|---|---|
u32 | uint32_t | |
u16 | uint16_t[2] | |
u8 | uint8_t[4] | |
c32 | lv_color32_t |
lv_draw_sw_halfword_t
The same for two bytes, for the RGB565 buffers.
| Member | Type | Description |
|---|---|---|
u16 | uint16_t | |
u8 | uint8_t[2] | |
c16 | lv_color16_t |
Macros
LV_COLOR_MIX_16_PREPARE
#define LV_COLOR_MIX_16_PREPARE(c) \
((((uint32_t)(c)) | (((uint32_t)(c)) << 16)) & 0x07E0F81Fu)Prepare an RGB565 color for mixing: spread it over 32 bits so each channel gets room to grow and a whole pixel can be mixed with one multiplication. See https://stackoverflow.com/a/50012418/1999969
LV_COLOR_24_TO_16
#define LV_COLOR_24_TO_16(c1) \
((uint16_t)((((c1)[2] & 0xF8) << 8) + (((c1)[1] & 0xFC) << 3) + (((c1)[0] & 0xF8) >> 3)))Convert RGB888 to RGB565.
LV_COLOR_MIX_16_TO_16_PREPARED
#define LV_COLOR_MIX_16_TO_16_PREPARED(res, fg_prep, bg, mix) \
do { \
uint32_t bg_prep_ = LV_COLOR_MIX_16_PREPARE(bg); \
uint32_t mix5_ = ((uint32_t)(mix) + 4) >> 3; \
uint32_t res_ = (((((fg_prep) - bg_prep_) * mix5_) >> 5) + bg_prep_) & 0x07E0F81Fu; \
(res) = (uint16_t)((res_ >> 16) | res_); \
} while(0)Mix a prepared foreground into an RGB565 background. mix must be 1..254, the callers handle 0 and 255 themselves. res may be the same variable as bg. A macro and not a function because -Os inlines neither, and this runs on every pixel. See https://stackoverflow.com/a/50012418/1999969
Dependencies
Last updated on