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 |
View * | Clone () const |
View * | Clone (const Rectangle< ptrdiff_t > &rect) const |
View * | Clone (View &buffer) const |
View & | operator= (const View &view) |
View & | operator= (View &&view) |
View & | operator= (const cv::Mat &mat) |
View & | Ref () |
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
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; }
Member Typedef Documentation
◆ Allocator
Member Enumeration Documentation
◆ Format
enum Format |
Describes pixel format types of an image view.
- Note
- This type is corresponds to C type SimdPixelFormatType.
◆ 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.
Constructor & Destructor Documentation
◆ View() [1/7]
◆ View() [2/7]
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() [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]
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]
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()
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]
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]
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]
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]
◆ 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]
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]
◆ Region() [4/4]
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 |
◆ 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 |
◆ 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]
|
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]
|
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]
|
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()
|
static |
◆ OcvTo()
◆ 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]
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]
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.