# lv_draw_sw_blend_private.h (/api/private/draw/sw/blend/lv_draw_sw_blend_private_h)



<RelatedHeaders name="lv_draw_sw_blend.h" isPrivate="true" />

<ApiSummary functions="5" structs="5" macros="3" />

Functions [#functions]

<ApiMember kind="function" name="lv_color32_unpremultiply" file="private/draw/sw/blend/lv_draw_sw_blend_private.h" line="142" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/src/draw/sw/blend/lv_draw_sw_blend_private.h#L142">
  lv_color32_unpremultiply [#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.

  ```c title=" " lineNumbers=1
  static lv_color32_t lv_color32_unpremultiply(lv_color32_t c)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name | Type                            | Description           |
  | ---- | ------------------------------- | --------------------- |
  | `c`  | <ApiLink name="lv_color32_t" /> | a premultiplied pixel |

  **Returns:** <ApiLink name="lv_color32_t" /> — the same pixel with straight channels
</ApiMember>

<ApiMember kind="function" name="lv_color32_lumi_of" file="private/draw/sw/blend/lv_draw_sw_blend_private.h" line="170" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/src/draw/sw/blend/lv_draw_sw_blend_private.h#L170">
  lv_color32_lumi_of [#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.

  ```c title=" " lineNumbers=1
  static uint8_t lv_color32_lumi_of(lv_color32_t c, bool premultiplied)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name            | Type                            | Description                |
  | --------------- | ------------------------------- | -------------------------- |
  | `c`             | <ApiLink name="lv_color32_t" /> | the pixel                  |
  | `premultiplied` | `bool`                          | true: `c` is premultiplied |

  **Returns:** `uint8_t` — the luminance, 0..255
</ApiMember>

<ApiMember kind="function" name="lv_color_16_16_mix_inlined" file="private/draw/sw/blend/lv_draw_sw_blend_private.h" line="187" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/src/draw/sw/blend/lv_draw_sw_blend_private.h#L187">
  lv_color_16_16_mix_inlined [#lv_color_16_16_mix_inlined]

  Inlined version of <ApiLink name="lv_color_16_16_mix" display="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.

  ```c title=" " lineNumbers=1
  static uint16_t lv_color_16_16_mix_inlined(uint16_t c1, uint16_t c2, uint8_t mix)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | 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
</ApiMember>

<ApiMember kind="function" name="lv_color_mix32_inlined" file="private/draw/sw/blend/lv_draw_sw_blend_private.h" line="214" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/src/draw/sw/blend/lv_draw_sw_blend_private.h#L214">
  lv_color_mix32_inlined [#lv_color_mix32_inlined]

  Inlined version of <ApiLink name="lv_color_mix32" display="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

  ```c title=" " lineNumbers=1
  static lv_color32_t lv_color_mix32_inlined(lv_color32_t fg, lv_color32_t bg)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name | Type                            | Description                                     |
  | ---- | ------------------------------- | ----------------------------------------------- |
  | `fg` | <ApiLink name="lv_color32_t" /> | the foreground color, fg.alpha is the mix ratio |
  | `bg` | <ApiLink name="lv_color32_t" /> | the background color                            |

  **Returns:** <ApiLink name="lv_color32_t" /> — the mixed color, the alpha of `bg` is kept
</ApiMember>

<ApiMember kind="function" name="lv_color_mix32_premultiplied_inlined" file="private/draw/sw/blend/lv_draw_sw_blend_private.h" line="240" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/src/draw/sw/blend/lv_draw_sw_blend_private.h#L240">
  lv_color_mix32_premultiplied_inlined [#lv_color_mix32_premultiplied_inlined]

  Inlined version of <ApiLink name="lv_color_mix32_premultiplied" display="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

  ```c title=" " lineNumbers=1
  static lv_color32_t lv_color_mix32_premultiplied_inlined(lv_color32_t fg, lv_color32_t bg)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name | Type                            | Description                                                   |
  | ---- | ------------------------------- | ------------------------------------------------------------- |
  | `fg` | <ApiLink name="lv_color32_t" /> | the premultiplied foreground color, fg.alpha is the mix ratio |
  | `bg` | <ApiLink name="lv_color32_t" /> | the background color                                          |

  **Returns:** <ApiLink name="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
</ApiMember>

Structs [#structs]

<ApiMember kind="struct" name="_lv_draw_sw_blend_dsc_t">
  \_lv_draw_sw_blend_dsc_t [#_lv_draw_sw_blend_dsc_t]

  | Member             | Type                                                     | Description                                                                                      |
  | ------------------ | -------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
  | `blend_area`       | <ApiLink name="lv_area_t" display="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` | <ApiLink name="lv_color_format_t" />                     |                                                                                                  |
  | `src_area`         | <ApiLink name="lv_area_t" display="const lv_area_t *" /> |                                                                                                  |
  | `opa`              | <ApiLink name="lv_opa_t" />                              | The overall opacity                                                                              |
  | `color`            | <ApiLink name="lv_color_t" />                            | Fill color                                                                                       |
  | `mask_buf`         | <ApiLink name="lv_opa_t" display="const lv_opa_t *" />   | NULL if ignored, or an alpha mask to apply on `blend_area`                                       |
  | `mask_res`         | <ApiLink name="lv_draw_sw_mask_res_t" />                 | The result of the previous mask operation                                                        |
  | `mask_area`        | <ApiLink name="lv_area_t" display="const lv_area_t *" /> | The area of `mask_buf` with absolute coordinates                                                 |
  | `mask_stride`      | `int32_t`                                                |                                                                                                  |
  | `blend_mode`       | <ApiLink name="lv_blend_mode_t" />                       | E.g. LV\_BLEND\_MODE\_ADDITIVE                                                                   |
</ApiMember>

<ApiMember kind="struct" name="_lv_draw_sw_blend_fill_dsc_t">
  \_lv_draw_sw_blend_fill_dsc_t [#_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`      | <ApiLink name="lv_opa_t" display="const lv_opa_t *" /> |             |
  | `mask_stride`   | `int32_t`                                              |             |
  | `color`         | <ApiLink name="lv_color_t" />                          |             |
  | `opa`           | <ApiLink name="lv_opa_t" />                            |             |
  | `relative_area` | <ApiLink name="lv_area_t" />                           |             |
</ApiMember>

<ApiMember kind="struct" name="_lv_draw_sw_blend_image_dsc_t">
  \_lv_draw_sw_blend_image_dsc_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`         | <ApiLink name="lv_opa_t" display="const lv_opa_t *" /> |                                                     |
  | `mask_stride`      | `int32_t`                                              |                                                     |
  | `src_buf`          | `const void *`                                         |                                                     |
  | `src_stride`       | `int32_t`                                              |                                                     |
  | `src_color_format` | <ApiLink name="lv_color_format_t" />                   |                                                     |
  | `opa`              | <ApiLink name="lv_opa_t" />                            |                                                     |
  | `blend_mode`       | <ApiLink name="lv_blend_mode_t" />                     |                                                     |
  | `relative_area`    | <ApiLink name="lv_area_t" />                           | The blend area relative to the layer's buffer area. |
  | `src_area`         | <ApiLink name="lv_area_t" />                           | The original src area.                              |
</ApiMember>

<ApiMember kind="struct" name="lv_draw_sw_word_t">
  lv_draw_sw_word_t [#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`  | <ApiLink name="lv_color32_t" /> |             |
</ApiMember>

<ApiMember kind="struct" name="lv_draw_sw_halfword_t">
  lv_draw_sw_halfword_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`  | <ApiLink name="lv_color16_t" /> |             |
</ApiMember>

Macros [#macros]

<ApiMember kind="macro" name="LV_COLOR_MIX_16_PREPARE" file="private/draw/sw/blend/lv_draw_sw_blend_private.h" line="110" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/src/draw/sw/blend/lv_draw_sw_blend_private.h#L110">
  LV_COLOR_MIX_16_PREPARE [#lv_color_mix_16_prepare]

  ```c title=" " lineNumbers=1
  #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](https://stackoverflow.com/a/50012418/1999969)
</ApiMember>

<ApiMember kind="macro" name="LV_COLOR_24_TO_16" file="private/draw/sw/blend/lv_draw_sw_blend_private.h" line="115" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/src/draw/sw/blend/lv_draw_sw_blend_private.h#L115">
  LV_COLOR_24_TO_16 [#lv_color_24_to_16]

  ```c title=" " lineNumbers=1
  #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.
</ApiMember>

<ApiMember kind="macro" name="LV_COLOR_MIX_16_TO_16_PREPARED" file="private/draw/sw/blend/lv_draw_sw_blend_private.h" line="124" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/src/draw/sw/blend/lv_draw_sw_blend_private.h#L124">
  LV_COLOR_MIX_16_TO_16_PREPARED [#lv_color_mix_16_to_16_prepared]

  ```c title=" " lineNumbers=1
  #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](https://stackoverflow.com/a/50012418/1999969)
</ApiMember>

Dependencies [#dependencies]

<FileIncludes includes="[&#x22;lv_draw_sw_blend.h&#x22;, &#x22;lv_draw_sw_mask.h&#x22;]" includedBy="[&#x22;lvgl_private.h&#x22;]" transitiveIncludes="[&#x22;lv_blend_neon.h&#x22;, &#x22;lv_cache.h&#x22;, &#x22;lv_cache_class.h&#x22;, &#x22;lv_cache_entry.h&#x22;, &#x22;lv_cache_lru_ll.h&#x22;, &#x22;lv_cache_lru_rb.h&#x22;, &#x22;lv_cache_sc_da.h&#x22;, &#x22;lv_draw_private.h&#x22;, &#x22;lv_draw_sw.h&#x22;, &#x22;lv_draw_sw_blend_neon_to_rgb565.h&#x22;, &#x22;lv_draw_sw_blend_neon_to_rgb888.h&#x22;, &#x22;lv_image_cache.h&#x22;, &#x22;lv_iter_private.h&#x22;, &#x22;lv_os_private.h&#x22;]" />
