# browser_alpha_matting (ESP-IDF C99 Component)
Division-free fixed-point (`Q16`) straight-alpha foreground color unmixing and `RGBA8888 -> RGB565` scanline compositing routines for ESP32 / ESP32-S3 / ESP32-P4 display pipelines (LVGL and `esp_lcd`).
## Mathematical Formulation
Given an observed boundary pixel $C_{\text{obs}}$ with alpha $\alpha \in (0, 1)$ composited over a known background $B$:
$$F = \text{clamp}_{[0,255]}\left(\frac{C_{\text{obs}} - (1 - \alpha) B}{\alpha}\right)$$
`bam_unmix_rgba8888_inplace` precomputes a 256-entry `Q16` reciprocal LUT on the stack so boundary decontamination executes in integer arithmetic without floating-point division traps on RISC-V or Xtensa cores.
## Usage
```c
#include "browser_alpha_matting.h"
// Remove white (255, 255, 255) background halo from an RGBA8888 sprite buffer
bam_unmix_rgba8888_inplace(sprite_rgba, width * height, 255, 255, 255, 6);
```
## Reference Implementation
Interactive browser reference implementation and alpha-matting test bench: [https://utilvo.com/background-remover](https://utilvo.com/background-remover)
## License
MIT
idf.py add-dependency "utilvo/browser_alpha_matting^1.1.2"