Simd Library Documentation.

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

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

#include <SimdView.hpp>

Public Types

enum  Format {
  None = 0 ,
  Gray8 ,
  Uv16 ,
  Bgr24 ,
  Bgra32 ,
  Int16 ,
  Int32 ,
  Int64 ,
  Float ,
  Double ,
  BayerGrbg ,
  BayerGbrg ,
  BayerRggb ,
  BayerBggr ,
  Hsv24 ,
  Hsl24 ,
  Rgb24 ,
  Rgba32 ,
  Uyvy16 ,
  Argb32
}
 
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 (View &&view) noexcept
 
 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
 
void ToTFTensor (tensorflow::Tensor &tensor, float shift=0, float scale=1) const
 
void ToTFTensor (tensorflow::Tensor &tensor, int batchIndex, float shift=0, float scale=0) const
 
ViewClone () const
 
ViewClone (const Rectangle< ptrdiff_t > &rect) const
 
ViewClone (View &buffer) const
 
Viewoperator= (const View &view)
 
Viewoperator= (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)
 
template<class T >
const T * Row (size_t row) const
 
template<class T >
T * Row (size_t row)
 
size_t PixelSize () const
 
size_t ChannelSize () const
 
size_t ChannelCount () const
 
void Swap (View &other)
 
bool Load (const std::string &path, Format format=None)
 
bool Load (const uint8_t *src, size_t size, Format format=None)
 
bool Save (const std::string &path, SimdImageFileType type=SimdImageFileUndefined, int quality=100) const
 
void Clear ()
 
uint8_t * Release (size_t *size=NULL)
 
bool Owner () const
 
void Capture (bool copy=true)
 

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.

Rgb24 

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

Rgba32 

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

Uyvy16 

A 16-bit (2 8-bit channels) UYVY422 pixel format.

Argb32 

A 32-bit (4 8-bit channels) ARGB (Alpha, Red, Green, Blue) 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/7]

SIMD_INLINE View

Creates a new empty View structure.

◆ View() [2/7]

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/7]

View ( View< A > &&  view)
noexcept

Move constructor of View structure.

Parameters
[in]view- a moved View.

◆ View() [4/7]

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() [5/7]

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() [6/7]

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() [7/7]

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

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.

◆ ToTFTensor() [1/2]

SIMD_INLINE void ToTFTensor ( tensorflow::Tensor &  tensor,
float  shift = 0,
float  scale = 1 
) const

Creates an Tensorflow Tensor which references this image.

Note
You have to define SIMD_TENSORFLOW_ENABLE in order to use this functionality.

◆ ToTFTensor() [2/2]

SIMD_INLINE void ToTFTensor ( tensorflow::Tensor &  tensor,
int  batchIndex,
float  shift = 0,
float  scale = 0 
) const

Creates an Tensorflow Tensor which references this image.

Note
You have to define SIMD_TENSORFLOW_ENABLE in order to use this functionality.

◆ Clone() [1/3]

SIMD_INLINE View< A > * Clone

Gets a copy of current image view.

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

◆ Clone() [2/3]

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

Gets a copy of region of current image view which bounded by the rectangle with specified coordinates.

Parameters
[in]rect- a rectangle which bound the region.
Returns
- a pointer to the new View structure. The user must free this pointer after usage.

◆ Clone() [3/3]

SIMD_INLINE View< A > * Clone ( View< A > &  buffer) const

Gets a copy of current image view using buffer as a storage.

Parameters
[in]buffer- an external view as a buffer.
Returns
a pointer to the new View structure (not owner). The user must free this pointer after usage.

◆ operator=() [1/3]

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

Creates view which references to other View structure.

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

◆ operator=() [2/3]

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

Moves View structure.

Parameters
[in]view- a moved image view.
Returns
a reference to itself.

◆ operator=() [3/3]

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. It may be useful if we need to create reference to the temporary object:

#include "Simd/SimdLib.hpp"

int main()
{
    typedef Simd::View<Simd::Allocator> View;
    View a(100, 100, View::Gray8);
    View b(100, 100, View::Gray8);
    // Copying of a central part of a to the center of b:
    Simd::Copy(a.Region(20, 20, 80, 80), b.Region(20, 20, 80, 80).Ref());
    return 0;
}
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

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

Gets size (width and height) of the image.

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

◆ DataSize()

SIMD_INLINE size_t DataSize

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

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 constant 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 constant 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.

◆ Row() [1/2]

const T * Row ( size_t  row) const

Gets constant pointer to the first pixel of specified row.

Parameters
[in]row- a row of the image.
Returns
- a constant pointer to the first pixel.

◆ Row() [2/2]

T * Row ( size_t  row)

Gets pointer to the first pixel of specified row.

Parameters
[in]row- a row of the image.
Returns
- a pointer to the first pixel.

◆ 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

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

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

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() [1/2]

SIMD_INLINE bool Load ( const std::string &  path,
Format  format = None 
)

Loads image from file.

Supported formats are described by SimdImageFileType enumeration.

Note
PGM and PPM files with comments are not supported.
Parameters
[in]path- a path to image file.
[in]format- a desired format of loaded image. Supported values are View::Gray8, View::Bgr24, View::Bgra32, View::Rgb24, View::Rgba32 and View::None. Default value is View::None (loads image in native pixel format of image file).
Returns
- a result of loading.

◆ Load() [2/2]

SIMD_INLINE bool Load ( const uint8_t *  src,
size_t  size,
Format  format = None 
)

Loads image from memory buffer.

Supported formats are described by SimdImageFileType enumeration.

Note
PGM and PPM files with comments are not supported.
Parameters
[in]src- a pointer to memory buffer.
[in]size- a buffer size.
[in]format- a desired format of loaded image. Supported values are View::Gray8, View::Bgr24, View::Bgra32, View::Rgb24, View::Rgba32 and View::None. Default value is View::None (loads image in native pixel format of image file).
Returns
- a result of loading.

◆ Save()

SIMD_INLINE bool Save ( const std::string &  path,
SimdImageFileType  type = SimdImageFileUndefined,
int  quality = 100 
) const

Saves image to file.

Parameters
[in]path- a path to file.
[in]type- a image file format. By default is equal to SimdImageFileUndefined (format auto choice).
[in]quality- a parameter of compression quality (if file format supports it).
Returns
- a result of saving.

◆ Clear()

SIMD_INLINE void Clear

Clears View structure (reset all fields) and free memory if it's owner.

◆ Release()

SIMD_INLINE uint8_t * Release ( size_t *  size = NULL)

Releases pixel data and resets all fields.

Parameters
[out]size- a pointer to the size of released pixel data. Can be NULL.
Returns
- a released pointer to pixel data. It must be deleted by function SimdFree.

◆ Owner()

SIMD_INLINE bool Owner

Gets owner flag: is this View owner of the image?

Returns
- an owner flag.

◆ Capture()

SIMD_INLINE void Capture ( bool  copy = true)

Captures image (sets to be the view as owner of current image) if this View is not owner of current image.

Parameters
[in]copy- a flag to make a copy to internal buffer.