Simd Library Documentation.

Home | Release Notes | Download | Documentation | Issues | GitHub
Simd::Pixel Namespace Reference

Contains pixel structures for Simd::View formats and drawing colors. More...

Data Structures

struct  Bgr24
 24-bit BGR pixel. More...
 
struct  Bgra32
 32-bit BGRA pixel. More...
 
struct  Hsl24
 24-bit HSL pixel. More...
 
struct  Hsv24
 24-bit HSV pixel. More...
 
struct  Rgb24
 24-bit RGB pixel. More...
 
struct  Rgba32
 32-bit RGBA pixel. More...
 

Detailed Description

Contains pixel structures for Simd::View formats and drawing colors.

Each structure is the memory layout of the matching Simd::View::Format (Bgr24, Bgra32, Hsv24, Hsl24, Rgb24, Rgba32). Channel fields are stored in that order and the structure size is the pixel size, so a value can be written into a view and passed as the color of Simd::DrawLine, Simd::DrawRectangle, Simd::DrawFilledRectangle, Simd::Font::Draw and Simd::FillPixel. Those functions require sizeof(color) to equal the canvas pixel size.

OpenCV frames used by the motion example are BGR. They use Pixel::Bgr24 as the color type. TestMotion paints alarmed objects with Bgr24(0, 0, 255), other objects with Bgr24(0, 255, 255) and event text with Bgr24(255, 255, 255). DrawRectangle, DrawLine and Font::Draw take that color on the Bgr24 frame. The Font example uses Pixel::Bgra32 on a Bgra32 canvas, including FillPixel(image, Bgra32(128, 128, 0)).

Bgr24 and Bgra32 constructors take channels as blue, green, red. Rgb24 and Rgba32 constructors take them as red, green, blue. TestRandom::GetColor therefore builds Bgr24(b, g, r) and Rgb24(r, g, b) from the same (b, g, r) triple, so "B", "G" and "R" labels have the same color on BGR and RGB canvases. Conversion constructors copy the matching channels and exchange red and blue between BGR and RGB layouts. Alpha is omitted when the result is 24-bit. A 24-bit source converted to 32 bits uses alpha 255 unless another value is passed. Bgra32 and Rgba32 conversions copy alpha.

Pixels are read and written with View::At and View::Row. The transform test assigns view.At<Pixel::Bgr24>(x, y) and view.At<Pixel::Bgra32>(x, y). The font test fills a row with View::Row<Pixel::Bgra32>. The static At methods do the same lookup and also require view.format to match the pixel type. col is the x coordinate and row is the y coordinate.

Hsv24 and Hsl24 are the element types of images produced by Simd::BgrToHsv and Simd::BgrToHsl. Every component is an 8-bit value in [0, 255].

Using example:

#include "Simd/SimdFont.hpp"
int main()
{
typedef Simd::Pixel::Bgr24 Color;
View image(320, 240, View::Bgr24);
const Color Red(0, 0, 255), Yellow(0, 255, 255);
Rect object(40, 30, 120, 90);
Simd::DrawRectangle(image, object, Yellow, 1);
Simd::Font font(image.height / 32);
font.Draw(image, "1", Point(object.left, object.top - (ptrdiff_t)font.Height()), Red);
for (size_t y = 0; y < 8; ++y)
for (size_t x = 0; x < image.width; ++x)
{
Color & pixel = image.At<Color>(x, y);
pixel.blue = uint8_t(y);
pixel.green = uint8_t(x);
pixel.red = 255;
}
typedef Simd::Pixel::Bgra32 Color32;
View bgra(320, 240, View::Bgra32);
Simd::FillPixel(bgra, Color32(128, 128, 0));
font.Draw(bgra, "Hello, Simd!", View::MiddleCenter, Color32(0, 0, 255));
uint8_t blue = 0, green = 255, red = 255;
Simd::DrawRectangle(image, Rect(0, 0, 16, 16), Color(blue, green, red));
View rgbImage(16, 16, View::Rgb24);
Simd::FillPixel(rgbImage, Simd::Pixel::Rgb24(red, green, blue));
return 0;
}
The Font class is a C++ wrapper for drawing ASCII text on images.
Definition: SimdFont.hpp:91
SIMD_INLINE void DrawRectangle(View< A > &canvas, ptrdiff_t left, ptrdiff_t top, ptrdiff_t right, ptrdiff_t bottom, const Color &color, size_t width=1)
Draws a clipped rectangle frame on an image.
Definition: SimdDrawing.hpp:107
SIMD_INLINE void FillPixel(View< A > &dst, const Pixel &pixel)
Fills every image pixel with the given pixel value.
Definition: SimdLib.hpp:2011
24-bit BGR pixel.
Definition: SimdPixel.hpp:133
32-bit BGRA pixel.
Definition: SimdPixel.hpp:246
24-bit RGB pixel.
Definition: SimdPixel.hpp:526
2D point (x, y) or size (width, height).
Definition: SimdPoint.hpp:157
Axis-aligned half-open rectangle [left, right) x [top, bottom).
Definition: SimdRectangle.hpp:176
Image: pixel buffer, size, stride, format and ownership.
Definition: SimdView.hpp:200
@ Bgra32
Definition: SimdView.hpp:224
@ Rgb24
Definition: SimdView.hpp:248
@ Bgr24
Definition: SimdView.hpp:222
@ MiddleCenter
Definition: SimdView.hpp:273