lv_draw_sw_blend_private.h

API reference for lv_draw_sw_blend_private.h

Report on GitHub
See Also: Public APIThis is the private implementation. See the public header for the stable interface.lv_draw_sw_blend.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)
Parameters
NameTypeDescription
clv_color32_ta 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)
Parameters
NameTypeDescription
clv_color32_tthe pixel
premultipliedbooltrue: 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)
Parameters
NameTypeDescription
c1uint16_tthe first color (typically the foreground color)
c2uint16_tthe second color (typically the background color)
mixuint8_t0..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)
Parameters
NameTypeDescription
fglv_color32_tthe foreground color, fg.alpha is the mix ratio
bglv_color32_tthe 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)
Parameters
NameTypeDescription
fglv_color32_tthe premultiplied foreground color, fg.alpha is the mix ratio
bglv_color32_tthe 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

struct

_lv_draw_sw_blend_dsc_t

MemberTypeDescription
blend_areaconst lv_area_t *The area with absolute coordinates to draw on layer->buf will be clipped to layer->clip_area
src_bufconst void *Pointer to an image to blend. If set fill_color is ignored
src_strideuint32_t
src_color_formatlv_color_format_t
src_areaconst lv_area_t *
opalv_opa_tThe overall opacity
colorlv_color_tFill color
mask_bufconst lv_opa_t *NULL if ignored, or an alpha mask to apply on blend_area
mask_reslv_draw_sw_mask_res_tThe result of the previous mask operation
mask_areaconst lv_area_t *The area of mask_buf with absolute coordinates
mask_strideint32_t
blend_modelv_blend_mode_tE.g. LV_BLEND_MODE_ADDITIVE
struct

_lv_draw_sw_blend_fill_dsc_t

MemberTypeDescription
dest_bufvoid *
dest_wint32_t
dest_hint32_t
dest_strideint32_t
mask_bufconst lv_opa_t *
mask_strideint32_t
colorlv_color_t
opalv_opa_t
relative_arealv_area_t
struct

_lv_draw_sw_blend_image_dsc_t

MemberTypeDescription
dest_bufvoid *
dest_wint32_t
dest_hint32_t
dest_strideint32_t
mask_bufconst lv_opa_t *
mask_strideint32_t
src_bufconst void *
src_strideint32_t
src_color_formatlv_color_format_t
opalv_opa_t
blend_modelv_blend_mode_t
relative_arealv_area_tThe blend area relative to the layer's buffer area.
src_arealv_area_tThe original src area.
struct

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.

MemberTypeDescription
u32uint32_t
u16uint16_t[2]
u8uint8_t[4]
c32lv_color32_t
struct

lv_draw_sw_halfword_t

The same for two bytes, for the RGB565 buffers.

MemberTypeDescription
u16uint16_t
u8uint8_t[2]
c16lv_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

On this page