ARM NEON Compositor  master
Fast SIMD alpha overlay and blending for ARM
Modules | Functions
Alpha Overlay

Functions for overlaying a foreground image with an alpha channel on top of a background channel. More...

+ Collaboration diagram for Alpha Overlay:

Modules

 Rescale
 Functions to rescale the color values by dividing by 255.
 
 C Wrappers
 C language wrappers for the alpha overlay functions.
 

Functions

template<RescaleType rescale_type = RescaleType::Div255_Round>
void overlay_alpha_fast (const uint8_t *bg_img, const uint8_t *fg_img, uint8_t *out_img, size_t n)
 Fast function to overlay two images of the same size, where the number of pixels is a multiple of 8. More...
 
template<RescaleType rescale_type = RescaleType::Div255_Round>
void overlay_alpha_stride (const uint8_t *bg_img, const uint8_t *fg_img, uint8_t *out_img, size_t bg_full_cols, size_t fg_rows, size_t fg_cols, size_t fg_full_cols)
 Overlay a smaller image with an alpha channel over a larger background image. More...
 
void overlay_alpha_stride (const uint8_t(&bg_img)[4], const uint8_t(&fg_img)[4], uint8_t(&out_img)[4], size_t bg_full_cols, size_t fg_rows, size_t fg_cols, size_t fg_full_cols)
 Overlay a smaller image with an alpha channel over a larger background image. More...
 

Detailed Description

Functions for overlaying a foreground image with an alpha channel on top of a background channel.

Function Documentation

◆ overlay_alpha_fast()

void overlay_alpha_fast ( const uint8_t *  bg_img,
const uint8_t *  fg_img,
uint8_t *  out_img,
size_t  n 
)

Fast function to overlay two images of the same size, where the number of pixels is a multiple of 8.

This function writes the blended color values of the background and the foreground to the output image.
The alpha channel of the background image is copied to the output unaltered.

out.B = (bg.B × (255 - fg.A) + fg.B × fg.A) / 255
out.G = (bg.G × (255 - fg.A) + fg.G × fg.A) / 255
out.R = (bg.R × (255 - fg.A) + fg.R × fg.A) / 255
out.A = bg.A

(R = red, G = green, B = blue, A = alpha)

By default, the division is rounded. By specifying a different rescale_type, you can disable rounding, use a faster, approximating rounding division by 255, or approximate even more by using a division by 256 instead of 255.

All images should be passed to this function as contiguous arrays of bytes with the colors as [B, G, R, A] or ARGB as a little-Endian 32-bit number.

Parameters
bg_imgA pointer to the image data of the background image.
fg_imgA pointer to the image data of the foreground image.
out_imgA pointer to the image data of the output image. May be the same as bg_img.
nThe number of pixels. Must be a multiple of eight.
Template Parameters
rescale_typeThe rescaling mode to use. See RescaleType.

Definition at line 101 of file src/alpha-lib/src/overlay_alpha.cpp.

◆ overlay_alpha_stride() [1/2]

void overlay_alpha_stride ( const uint8_t *  bg_img,
const uint8_t *  fg_img,
uint8_t *  out_img,
size_t  bg_full_cols,
size_t  fg_rows,
size_t  fg_cols,
size_t  fg_full_cols 
)

Overlay a smaller image with an alpha channel over a larger background image.

┌────────────────────┐
│ X────────────┬─┐ │ ┬
│ │ foreground │ │ │ │ fg_rows
│ ├────────────┘ │ │ ┴
│ └──────────────┘ │
└────────────────────┘
├────────────────────┤ bg_full_cols
├────────────┤ fg_cols
├──────────────┤ fg_full_cols

This function writes the mixed color values of the background and the foreground to the output image.
The alpha channel of the background image is copied to the output unaltered.

out.B = (bg.B × (255 - fg.A) + fg.B × fg.A) / 255
out.G = (bg.G × (255 - fg.A) + fg.G × fg.A) / 255
out.R = (bg.R × (255 - fg.A) + fg.R × fg.A) / 255
out.A = bg.A

(R = red, G = green, B = blue, A = alpha)

By default, the division is rounded. By specifying a different rescale_type, you can disable rounding, use a faster, approximating rounding division by 255, or approximate even more by using a division by 256 instead of 255.

All images should be passed to this function as contiguous arrays of bytes in column major order, with the colors as [B, G, R, A] or ARGB as a little-Endian 32-bit number.

Parameters
bg_imgA pointer to the image data of the background image.
fg_imgA pointer to the image data of the foreground image.
out_imgA pointer to the image data of the output image. May be the same as bg_img.
bg_full_colsThe total number of columns of the background and the output image. Used as the stride/leading dimension.
fg_rowsThe number of rows of the foreground image to overlay.
fg_colsThe number of columns of the foreground image to overlay.
fg_full_colsThe total number of columns of the foreground image. Used as the stride/leading dimension.
Template Parameters
rescale_typeThe rescaling mode to use. See RescaleType.
Examples
examples/overlay_alpha/overlay_alpha.cpp.

Definition at line 124 of file src/alpha-lib/src/overlay_alpha.cpp.

◆ overlay_alpha_stride() [2/2]

void overlay_alpha_stride ( const uint8_t(&)  bg_img[4],
const uint8_t(&)  fg_img[4],
uint8_t(&)  out_img[4],
size_t  bg_full_cols,
size_t  fg_rows,
size_t  fg_cols,
size_t  fg_full_cols 
)
inline

Overlay a smaller image with an alpha channel over a larger background image.

┌────────────────────┐
│ X────────────┬─┐ │ ┬
│ │ foreground │ │ │ │ fg_rows
│ ├────────────┘ │ │ ┴
│ └──────────────┘ │
└────────────────────┘
├────────────────────┤ bg_full_cols
├────────────┤ fg_cols
├──────────────┤ fg_full_cols

This function writes the mixed color values of the background and the foreground to the output image.
The alpha channel of the background image is copied to the output unaltered.

out.B = (bg.B × (255 - fg.A) + fg.B × fg.A) / 255
out.G = (bg.G × (255 - fg.A) + fg.G × fg.A) / 255
out.R = (bg.R × (255 - fg.A) + fg.R × fg.A) / 255
out.A = bg.A

(R = red, G = green, B = blue, A = alpha)

By default, the division is rounded. By specifying a different rescale_type, you can disable rounding, use a faster, approximating rounding division by 255, or approximate even more by using a division by 256 instead of 255.

All images should be passed to this function as contiguous arrays of bytes in column major order, with the colors as [B, G, R, A] or ARGB as a little-Endian 32-bit number.

Parameters
bg_imgA pointer to the image data of the background image.
fg_imgA pointer to the image data of the foreground image.
out_imgA pointer to the image data of the output image. May be the same as bg_img.
bg_full_colsThe total number of columns of the background and the output image. Used as the stride/leading dimension.
fg_rowsThe number of rows of the foreground image to overlay.
fg_colsThe number of columns of the foreground image to overlay.
fg_full_colsThe total number of columns of the foreground image. Used as the stride/leading dimension.
Template Parameters
rescale_typeThe rescaling mode to use. See RescaleType.

This overload uses references to a specific pixel in the images.

You can use it with the result of cv::Mat::at<uint8_t[4]>(row, col).

Definition at line 119 of file overlay_alpha.hpp.