Simd Library Documentation.

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

The View structure provides storage and manipulation of images. More...

Public Types

enum  Format {
  None = 0,
  Gray8,
  Uv16,
  Bgr24,
  Bgra32,
  Int16,
  Int32,
  Int64,
  Float,
  Double,
  BayerGrbg,
  BayerGbrg,
  BayerRggb,
  BayerBggr,
  Hsv24,
  Hsl24
}
 
enum  Position {
  TopLeft,
  TopCenter,
  TopRight,
  MiddleLeft,
  MiddleCenter,
  MiddleRight,
  BottomLeft,
  BottomCenter,
  BottomRight
}
 
typedef A< uint8_t > Allocator
 

Public Member Functions

 View ()
 
 View (const View &view)
 
 View (const cv::Mat &mat)
 
 View (size_t w, size_t h, ptrdiff_t s, Format f, void *d)
 
 View (size_t w, size_t h, Format f, void *d=NULL, size_t align=Allocator::Alignment())
 
 View (const Point< ptrdiff_t > &size, Format f)
 
 ~View ()
 
 operator cv::Mat () const
 
ViewClone () const
 
Viewoperator= (const View &view)
 
Viewoperator= (const cv::Mat &mat)
 
ViewRef ()
 
void Recreate (size_t w, size_t h, Format f, void *d=NULL, size_t align=Allocator::Alignment())
 
void Recreate (const Point< ptrdiff_t > &size, Format f)
 
View Region (ptrdiff_t left, ptrdiff_t top, ptrdiff_t right, ptrdiff_t bottom) const
 
View Region (const Point< ptrdiff_t > &topLeft, const Point< ptrdiff_t > &bottomRight) const
 
View Region (const Rectangle< ptrdiff_t > &rect) const
 
View Region (const Point< ptrdiff_t > &size, Position position) const
 
View Flipped () const
 
Point< ptrdiff_t > Size () const
 
size_t DataSize () const
 
size_t Area () const
 
template<class T >
const T & At (size_t x, size_t y) const
 
template<class T >
T & At (size_t x, size_t y)
 
template<class T >
const T & At (const Point< ptrdiff_t > &p) const
 
template<class T >
T & At (const Point< ptrdiff_t > &p)
 
size_t PixelSize () const
 
size_t ChannelSize () const
 
size_t ChannelCount () const
 
void Swap (View &other)
 
bool Load (const std::string &path)
 
bool Save (const std::string &path) const
 

Static Public Member Functions

static size_t PixelSize (Format format)
 
static size_t ChannelSize (Format format)
 
static size_t ChannelCount (Format format)
 
static int ToOcv (Format format)
 
static Format OcvTo (int type)
 

Data Fields

const size_t width
 A width of the image.
 
const size_t height
 A height of the image.
 
const ptrdiff_t stride
 A row size of the image in bytes.
 
const Format format
 A pixel format types of the image.
 
uint8_t *const data
 A pointer to the pixel data (first row) of the image.
 

Detailed Description

template<template< class > class A>
struct Simd::View< A >

The View structure provides storage and manipulation of images.

In order to have mutual conversion with OpenCV image type (cv::Mat) you have to define macro SIMD_OPENCV_ENABLE:

#include "opencv2/core/core.hpp"
#define SIMD_OPENCV_ENABLE
#include "Simd/SimdView.hpp"

int main()
{
    typedef Simd::View<Simd::Allocator> View;

    View view1(40, 30, View::Bgr24);
    cv::Mat mat1(80, 60, CV_8UC3)

    View view2 = mat1; // view2 will be refer to mat1, it is not a copy!
    cv::Mat mat2 = view1; // mat2 will be refer to view1, it is not a copy!

    return 0;
}

Related Functions.

Member Typedef Documentation

◆ Allocator

typedef A<uint8_t> Allocator

Allocator type definition.

Member Enumeration Documentation

◆ Format

enum Format

Describes pixel format types of an image view.

Note
This type is corresponds to C type SimdPixelFormatType.
Enumerator
None 

An undefined pixel format.

Gray8 

A 8-bit gray pixel format.

Uv16 

A 16-bit (2 8-bit channels) pixel format (UV plane of NV12 pixel format).

Bgr24 

A 24-bit (3 8-bit channels) BGR (Blue, Green, Red) pixel format.

Bgra32 

A 32-bit (4 8-bit channels) BGRA (Blue, Green, Red, Alpha) pixel format.

Int16 

A single channel 16-bit integer pixel format.

Int32 

A single channel 32-bit integer pixel format.

Int64 

A single channel 64-bit integer pixel format.

Float 

A single channel 32-bit float point pixel format.

Double 

A single channel 64-bit float point pixel format.

BayerGrbg 

A 8-bit Bayer pixel format (GRBG).

BayerGbrg 

A 8-bit Bayer pixel format (GBRG).

BayerRggb 

A 8-bit Bayer pixel format (RGGB).

BayerBggr 

A 8-bit Bayer pixel format (BGGR).

Hsv24 

A 24-bit (3 8-bit channels) HSV (Hue, Saturation, Value) pixel format.

Hsl24 

A 24-bit (3 8-bit channels) HSL (Hue, Saturation, Lightness) pixel format.

◆ Position

enum Position

Describes the position of the child image view to the parent image view. This enum is used for creation of sub image view in method Simd::View::Region.

Enumerator
TopLeft 

A position in the top-left corner.

TopCenter 

A position at the top center.

TopRight 

A position in the top-right corner.

MiddleLeft 

A position of the left in the middle.

MiddleCenter 

A central position.

MiddleRight 

A position of the right in the middle.

BottomLeft 

A position in the bottom-left corner.

BottomCenter 

A position at the bottom center.

BottomRight 

A position in the bottom-right corner.

Constructor & Destructor Documentation

◆ View() [1/6]

SIMD_INLINE View ( )

Creates a new empty View structure.

◆ View() [2/6]

View ( const View< A > &  view)

Creates a new View structure on the base of the image view.

Note
This constructor is not create new image view! It only creates a reference to the same image. If you want to create a copy then must use method Simd::View::Clone.
Parameters
[in]view- an original image view.

◆ View() [3/6]

SIMD_INLINE View ( const cv::Mat &  mat)

Creates a new View structure on the base of OpenCV Mat type.

Note
You have to define SIMD_OPENCV_ENABLE in order to use this functionality.
Parameters
[in]mat- an OpenCV Mat.

◆ View() [4/6]

SIMD_INLINE View ( size_t  w,
size_t  h,
ptrdiff_t  s,
Format  f,
void *  d 
)

Creates a new View structure with specified width, height, row size, pixel format and pointer to pixel data.

Parameters
[in]w- a width of created image view.
[in]h- a height of created image view.
[in]s- a stride (row size) of created image view.
[in]f- a pixel format of created image view.
[in]d- a pointer to the external buffer with pixel data. If this pointer is NULL then will be created own buffer.

◆ View() [5/6]

SIMD_INLINE View ( size_t  w,
size_t  h,
Format  f,
void *  d = NULL,
size_t  align = Allocator::Alignment() 
)

Creates a new View structure with specified width, height, pixel format, pointer to pixel data and memory alignment.

Parameters
[in]w- a width of created image view.
[in]h- a height of created image view.
[in]f- a pixel format of created image view.
[in]d- a pointer to the external buffer with pixel data. If this pointer is NULL then will be created own buffer.
[in]align- a required memory alignment. Its default value is determined by function Allocator::Alignment.

◆ View() [6/6]

SIMD_INLINE View ( const Point< ptrdiff_t > &  size,
Format  f 
)

Creates a new View structure with specified width, height and pixel format.

Parameters
[in]size- a size (width and height) of created image view.
[in]f- a pixel format of created image view.

◆ ~View()

SIMD_INLINE ~View ( )

A View destructor.

Member Function Documentation

◆ operator cv::Mat()

SIMD_INLINE operator cv::Mat ( ) const

Creates an OpenCV Mat which references this image.

Note
You have to define SIMD_OPENCV_ENABLE in order to use this functionality.
Returns
an OpenCV Mat which references to this image.

◆ Clone()

SIMD_INLINE View< A > * Clone ( ) const

Gets a copy of current image view.

Returns
a pointer to the new View structure. The user must free this pointer after usage.

◆ operator=() [1/2]

View& operator= ( const View< A > &  view)

Creates view which references to other View structure.

Note
This function is not create copy of image view! It only create a reference to the same image.
Parameters
[in]view- an original image view.
Returns
a reference to itself.

◆ operator=() [2/2]

SIMD_INLINE View< A > & operator= ( const cv::Mat &  mat)

Creates view which references to an OpenCV Mat.

Note
You have to define SIMD_OPENCV_ENABLE in order to use this functionality.
Parameters
[in]mat- an OpenCV Mat.
Returns
a reference to itself.

◆ Ref()

SIMD_INLINE View< A > & Ref ( )

Creates reference to itself.

Returns
a reference to itself.

◆ Recreate() [1/2]

SIMD_INLINE void Recreate ( size_t  w,
size_t  h,
Format  f,
void *  d = NULL,
size_t  align = Allocator::Alignment() 
)

Re-creates a View structure with specified width, height, pixel format, pointer to pixel data and memory alignment.

Parameters
[in]w- a width of re-created image view.
[in]h- a height of re-created image view.
[in]f- a pixel format of re-created image view.
[in]d- a pointer to the external buffer with pixel data. If this pointer is NULL then will be created own buffer.
[in]align- a required memory alignment. Its default value is determined by function Allocator::Alignment.

◆ Recreate() [2/2]

SIMD_INLINE void Recreate ( const Point< ptrdiff_t > &  size,
Format  f 
)

Re-creates a View structure with specified width, height and pixel format.

Parameters
[in]size- a size (width and height) of re-created image view.
[in]f- a pixel format of re-created image view.

◆ Region() [1/4]

SIMD_INLINE View< A > Region ( ptrdiff_t  left,
ptrdiff_t  top,
ptrdiff_t  right,
ptrdiff_t  bottom 
) const

Creates a new View structure which points to the region of current image bounded by the rectangle with specified coordinates.

Parameters
[in]left- a left side of the region.
[in]top- a top side of the region.
[in]right- a right side of the region.
[in]bottom- a bottom side of the region.
Returns
- a new View structure which points to the region of current image.

◆ Region() [2/4]

SIMD_INLINE View< A > Region ( const Point< ptrdiff_t > &  topLeft,
const Point< ptrdiff_t > &  bottomRight 
) const

Creates a new View structure which points to the region of current image bounded by the rectangle with specified coordinates.

Parameters
[in]topLeft- a top-left corner of the region.
[in]bottomRight- a bottom-right corner of the region.
Returns
- a new View structure which points to the region of current image.

◆ Region() [3/4]

SIMD_INLINE View< A > Region ( const Rectangle< ptrdiff_t > &  rect) const

Creates a new View structure which points to the region of current image bounded by the rectangle with specified coordinates.

Parameters
[in]rect- a rectangle which bound the region.
Returns
- a new View structure which points to the region of current image.

◆ Region() [4/4]

SIMD_INLINE View< A > Region ( const Point< ptrdiff_t > &  size,
Position  position 
) const

Creates a new View structure which points to the region of current image bounded by the rectangle with specified coordinates.

Parameters
[in]size- a size (width and height) of the region.
[in]position- a value represents the position of the region (see Simd::View::Position).
Returns
- a new View structure which points to the region of current image.

◆ Flipped()

SIMD_INLINE View< A > Flipped ( ) const

Creates a new View structure which points to the vertically flipped image.

Returns
- a new View structure which points to the flipped image.

◆ Size()

SIMD_INLINE Point< ptrdiff_t > Size ( ) const

Gets size (width and height) of the image.

Returns
- a new Point structure with image width and height.

◆ DataSize()

SIMD_INLINE size_t DataSize ( ) const

Gets size in bytes required to store pixel data of current View structure.

Returns
- a size of data pixels in bytes.

◆ Area()

SIMD_INLINE size_t Area ( ) const

Gets area in pixels of of current View structure.

Returns
- a area of current View in pixels.

◆ At() [1/4]

const T& At ( size_t  x,
size_t  y 
) const

Gets constant reference to the pixel of arbitrary type into current view with specified coordinates.

Parameters
[in]x- a x-coordinate of the pixel.
[in]y- a y-coordinate of the pixel.
Returns
- a const reference to pixel of arbitrary type.

◆ At() [2/4]

T& At ( size_t  x,
size_t  y 
)

Gets reference to the pixel of arbitrary type into current view with specified coordinates.

Parameters
[in]x- a x-coordinate of the pixel.
[in]y- a y-coordinate of the pixel.
Returns
- a reference to pixel of arbitrary type.

◆ At() [3/4]

const T& At ( const Point< ptrdiff_t > &  p) const

Gets constant reference to the pixel of arbitrary type into current view with specified coordinates.

Parameters
[in]p- a point with coordinates of the pixel.
Returns
- a const reference to pixel of arbitrary type.

◆ At() [4/4]

T& At ( const Point< ptrdiff_t > &  p)

Gets reference to the pixel of arbitrary type into current view with specified coordinates.

Parameters
[in]p- a point with coordinates of the pixel.
Returns
- a reference to pixel of arbitrary type.

◆ PixelSize() [1/2]

SIMD_INLINE size_t PixelSize ( Format  format)
static

Gets pixel size in bytes for current pixel format.

Parameters
[in]format- a pixel format.
Returns
- a pixel size in bytes.

◆ PixelSize() [2/2]

SIMD_INLINE size_t PixelSize ( ) const

Gets pixel size in bytes for current image.

Returns
- a pixel size in bytes.

◆ ChannelSize() [1/2]

SIMD_INLINE size_t ChannelSize ( Format  format)
static

Gets pixel channel size in bytes for current pixel format.

Parameters
[in]format- a pixel format.
Returns
- a pixel channel size in bytes.

◆ ChannelSize() [2/2]

SIMD_INLINE size_t ChannelSize ( ) const

Gets pixel channel size in bytes for current image.

Returns
- a pixel channel size in bytes.

◆ ChannelCount() [1/2]

SIMD_INLINE size_t ChannelCount ( Format  format)
static

Gets number of channels in the pixel for current pixel format.

Parameters
[in]format- a pixel format.
Returns
- a number of channels.

◆ ChannelCount() [2/2]

SIMD_INLINE size_t ChannelCount ( ) const

Gets number of channels in the pixel for current image.

Returns
- a number of channels.

◆ ToOcv()

SIMD_INLINE int ToOcv ( Format  format)
static

Converts Simd Library pixel format to OpenCV Matrix type.

Note
You have to define SIMD_OPENCV_ENABLE in order to use this functionality.
Parameters
[in]format- a Simd Library pixel format.
Returns
- an OpenCV Matrix type.

◆ OcvTo()

SIMD_INLINE View< A >::Format OcvTo ( int  type)
static

Converts OpenCV Matrix type to Simd Library pixel format.

Note
You have to define SIMD_OPENCV_ENABLE in order to use this functionality.
Parameters
[in]type- an OpenCV Matrix type.
Returns
- a Simd Library pixel format.

◆ Swap()

SIMD_INLINE void Swap ( View< A > &  other)

Swaps content of two (this and other) View structures.

Parameters
[in]other- an other image view.

◆ Load()

SIMD_INLINE bool Load ( const std::string &  path)

Loads image from file.

Supported formats:

  • PGM(Portable Gray Map) binary(P5) (the file is loaded as 8-bit gray image).
  • PPM(Portable Pixel Map) binary(P6) (the file is loaded as 32-bit BGRA image).
Note
PGM and PPM files with comments are not supported.
Parameters
[in]path- a path to file with PGM or PPM image.
Returns
- a result of loading.

◆ Save()

SIMD_INLINE bool Save ( const std::string &  path) const

Saves image to file.

Supported formats:

  • PGM(Portable Gray Map) binary(P5) (this format is used in order to save 8-bit gray images).
  • PPM(Portable Pixel Map) binary(P6) (this format is used in order to save 24-bit BGR and 32-bit BGRA images).
Parameters
[in]path- a path to file.
Returns
- a result of saving.