Simd Library Documentation.

Home | Release Notes | Download | Documentation | Issues | GitHub

Functions for RGB-24 image conversions. More...

Functions

SIMD_API void SimdRgbToBgra (const uint8_t *rgb, size_t width, size_t height, size_t rgbStride, uint8_t *bgra, size_t bgraStride, uint8_t alpha)
 Converts a 24-bit RGB image to a 32-bit BGRA image. More...
 
SIMD_API void SimdRgbToGray (const uint8_t *rgb, size_t width, size_t height, size_t rgbStride, uint8_t *gray, size_t grayStride)
 Converts a 24-bit RGB image to an 8-bit gray image. More...
 
template<template< class > class A>
SIMD_INLINE void RgbToBgr (const View< A > &rgb, View< A > &bgr)
 Converts a 24-bit RGB image to a 24-bit BGR image by swapping the Red and Blue channels. More...
 
template<template< class > class A>
SIMD_INLINE void RgbToBgra (const View< A > &rgb, View< A > &bgra, uint8_t alpha=0xFF)
 Converts a 24-bit RGB image to a 32-bit BGRA image by swapping Red/Blue and adding constant alpha. More...
 
template<template< class > class A>
SIMD_INLINE void RgbToGray (const View< A > &rgb, View< A > &gray)
 Converts a 24-bit RGB image to an 8-bit grayscale image. More...
 
template<template< class > class A>
SIMD_INLINE void RgbToRgba (const View< A > &rgb, View< A > &rgba, uint8_t alpha=0xFF)
 Converts a 24-bit RGB image to a 32-bit RGBA image with constant alpha. More...
 

Detailed Description

Functions for RGB-24 image conversions.

Function Documentation

◆ SimdRgbToBgra()

void SimdRgbToBgra ( const uint8_t *  rgb,
size_t  width,
size_t  height,
size_t  rgbStride,
uint8_t *  bgra,
size_t  bgraStride,
uint8_t  alpha 
)

Converts a 24-bit RGB image to a 32-bit BGRA image.

All images must have the same width and height. For every pixel:

bgra[4*i + 0] = rgb[3*i + 2]; // blue
bgra[4*i + 1] = rgb[3*i + 1]; // green
bgra[4*i + 2] = rgb[3*i + 0]; // red
bgra[4*i + 3] = alpha;

If the input is treated as BGR and the output as RGBA, the same byte shuffle performs BGR-to-RGBA conversion.

Note
This function has C++ wrappers: Simd::RgbToBgra(const View<A>& rgb, View<A>& bgra, uint8_t alpha) and Simd::BgrToRgba(const View<A>& bgr, View<A>& rgba, uint8_t alpha).
Parameters
[in]rgb- a pointer to pixels data of input 24-bit RGB image.
[in]width- an image width.
[in]height- an image height.
[in]rgbStride- a row size of the rgb image in bytes.
[out]bgra- a pointer to pixels data of output 32-bit BGRA image.
[in]bgraStride- a row size of the bgra image in bytes.
[in]alpha- a value of alpha channel.

◆ SimdRgbToGray()

void SimdRgbToGray ( const uint8_t *  rgb,
size_t  width,
size_t  height,
size_t  rgbStride,
uint8_t *  gray,
size_t  grayStride 
)

Converts a 24-bit RGB image to an 8-bit gray image.

All images must have the same width and height. For every pixel:

gray[i] = (0.299*R + 0.587*G + 0.114*B) rounded to nearest integer,
where R = rgb[3*i + 0], G = rgb[3*i + 1], B = rgb[3*i + 2].
Note
This function has a C++ wrapper Simd::RgbToGray(const View<A>& rgb, View<A>& gray).
Parameters
[in]rgb- a pointer to pixels data of input 24-bit RGB image.
[in]width- an image width.
[in]height- an image height.
[in]rgbStride- a row size of the rgb image in bytes.
[out]gray- a pointer to pixels data of output 8-bit gray image.
[in]grayStride- a row size of the gray image in bytes.

◆ RgbToBgr()

void RgbToBgr ( const View< A > &  rgb,
View< A > &  bgr 
)

Converts a 24-bit RGB image to a 24-bit BGR image by swapping the Red and Blue channels.

The function converts a 24-bit RGB (Red, Green, Blue) image to a 24-bit BGR (Blue, Green, Red) image. For each output pixel: bgr[0] = rgb[2], bgr[1] = rgb[1], bgr[2] = rgb[0]. Both images must have the same width and height.

Note
This function is a C++ wrapper for function SimdBgrToRgb.
Parameters
[in]rgb- an input 24-bit RGB image.
[out]bgr- an output 24-bit BGR image.

◆ RgbToBgra()

void RgbToBgra ( const View< A > &  rgb,
View< A > &  bgra,
uint8_t  alpha = 0xFF 
)

Converts a 24-bit RGB image to a 32-bit BGRA image by swapping Red/Blue and adding constant alpha.

For every pixel:

bgra[0] = rgb[2]; // blue
bgra[1] = rgb[1]; // green
bgra[2] = rgb[0]; // red
bgra[3] = alpha;

Both images must have the same width and height.

Note
This function is a C++ wrapper for function SimdRgbToBgra.
Parameters
[in]rgb- an input 24-bit RGB image.
[out]bgra- an output 32-bit BGRA image.
[in]alpha- a constant value to fill the alpha channel of every output pixel. It is equal to 0xFF by default.

◆ RgbToGray()

void RgbToGray ( const View< A > &  rgb,
View< A > &  gray 
)

Converts a 24-bit RGB image to an 8-bit grayscale image.

The luminance value of each pixel is calculated from the Red, Green, and Blue channels using the ITU-R BT.601 standard weighted sum:

gray = round(0.299*red + 0.587*green + 0.114*blue),
where red = rgb[0], green = rgb[1], blue = rgb[2].

Both images must have the same width and height.

Note
This function is a C++ wrapper for function SimdRgbToGray.
Parameters
[in]rgb- an input 24-bit RGB image.
[out]gray- an output 8-bit gray image.

◆ RgbToRgba()

void RgbToRgba ( const View< A > &  rgb,
View< A > &  rgba,
uint8_t  alpha = 0xFF 
)

Converts a 24-bit RGB image to a 32-bit RGBA image with constant alpha.

For each pixel, Red, Green and Blue are copied unchanged and Alpha is set to the constant value specified by the alpha parameter. Both images must have the same width and height.

Note
This function is a C++ wrapper for function SimdBgrToBgra.
Parameters
[in]rgb- an input 24-bit RGB image.
[out]rgba- an output 32-bit RGBA image.
[in]alpha- a constant value to fill the alpha channel of every output pixel. It is equal to 0xFF by default.