Simd Library Documentation.

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

The Image class provides storage and manipulation of images. More...

Public Member Functions

def __init__ (self, format=Simd.PixelFormat.Empty, width=0, height=0, align=0, stride=0, data=ctypes.c_void_p(0))
 Creates a new image. More...
 
def __del__ (self)
 Frees image data. More...
 
def Recreate (self, Simd.PixelFormat format, int width, int height, align=0)
 Recreates the image. More...
 
def FromExternal (self, Simd.PixelFormat format, int width, int height, int stride, ctypes.c_void_p data)
 Recreates a new image on the base of external image. More...
 
bool Compatible (self, other)
 Check if current and other image have the same size and pixel format. More...
 
bool EqualSize (self, other)
 Check if current and other image have the same size. More...
 
def Clear (self)
 Clears image. More...
 
int Width (self)
 Gets image width. More...
 
int Height (self)
 Gets image height. More...
 
int Stride (self)
 Gets image row size in bytes. More...
 
Simd.PixelFormat Format (self)
 Gets image pixel format. More...
 
ctypes.c_void_p Data (self)
 Gets pointer to image pixel data. More...
 
bool Load (self, str path, desiredFormat=Simd.PixelFormat.Empty)
 Loads an image from file. More...
 
bool Save (self, str path, file=Simd.ImageFile.Undefined, quality=100)
 Saves the image to file in given image file format. More...
 
def Region (self, int left, int top, int right, int bottom)
 Creates a new Simd.Image which points to the region of current image bounded by the rectangle with specified coordinates. More...
 
def RegionAt (self, int width, int height, Simd.Position position)
 Creates a new Simd.Image which points to the region of current image with given size at current position. More...
 
def Copy (self, dst=None)
 Copies current image. More...
 
def Convert (self, dst, alpha=255)
 Converts current image to output image. More...
 
def Converted (self, PixelFormat format, alpha=255)
 Gets converted current image in given format. More...
 
def Fill (self, array.array('B') pixel)
 Fills image by value of given pixel. More...
 
def CopyToNumpyArray (self, dst=None)
 Copy image to output numpy.array. More...
 

Detailed Description

The Image class provides storage and manipulation of images.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  format = Simd.PixelFormat.Empty,
  width = 0,
  height = 0,
  align = 0,
  stride = 0,
  data = ctypes.c_void_p(0) 
)

Creates a new image.

Parameters
format- image pixel format.
width- image width.
height- image height.
align- a row size alingnment in bytes (optional).
stride- a row size in bytes of image created on the base of external image (optional).
data- a pointer to external image pixel data (optional).

◆ __del__()

def __del__ (   self)

Frees image data.

Releases image pixel data, sets to zero all fields.

Member Function Documentation

◆ Recreate()

def Recreate (   self,
Simd.PixelFormat  format,
int  width,
int  height,
  align = 0 
)

Recreates the image.

Parameters
format- a new image pixel format.
width- a new image width.
height- a new image height.
align- a row size alingnment in bytes (optional).

◆ FromExternal()

def FromExternal (   self,
Simd.PixelFormat  format,
int  width,
int  height,
int  stride,
ctypes.c_void_p  data 
)

Recreates a new image on the base of external image.

Parameters
format- a new image pixel format.
width- a new image width.
height- a new image height.
stride- a row size in bytes of external image.
data- a pointer to external image pixel data.

◆ Compatible()

bool Compatible (   self,
  other 
)

Check if current and other image have the same size and pixel format.

Parameters
other- other image.
Returns
result of checking.

◆ EqualSize()

bool EqualSize (   self,
  other 
)

Check if current and other image have the same size.

Parameters
other- other image.
Returns
result of checking.

◆ Clear()

def Clear (   self)

Clears image.

Releases image pixel data, sets to zero all fields.

◆ Width()

int Width (   self)

Gets image width.

Returns
image width.

◆ Height()

int Height (   self)

Gets image height.

Returns
image height.

◆ Stride()

int Stride (   self)

Gets image row size in bytes.

Returns
image row size in bytes.

◆ Format()

Simd.PixelFormat Format (   self)

Gets image pixel format.

Returns
image pixel format.

◆ Data()

ctypes.c_void_p Data (   self)

Gets pointer to image pixel data.

Returns
pointer to image pixel data.

◆ Load()

bool Load (   self,
str  path,
  desiredFormat = Simd.PixelFormat.Empty 
)

Loads an image from file.

Parameters
path- a path to input image file.
desiredFormat- a desired pixel format of output image. It can be Simd.PixelFormat.Gray8, Simd.PixelFormat.Bgr24, Simd.PixelFormat.Bgra32, Simd.PixelFormat.Rgb24, Simd.PixelFormat.Rgba32 or Simd.PixelFormat.Empty (use pixel format of input image file).
Returns
result of the operation.

◆ Save()

bool Save (   self,
str  path,
  file = Simd.ImageFile.Undefined,
  quality = 100 
)

Saves the image to file in given image file format.

Note
Supported pixel formats: Simd.PixelFormat.Gray8, Simd.PixelFormat.Bgr24, Simd.PixelFormat.Bgra32, Simd.PixelFormat.Rgb24, Simd.PixelFormat.Rgba32.
Parameters
path- a path to output image file.
file- a format of output image file. To auto choise format of output file set this parameter to Simd.ImageFile.Undefined.
quality- a parameter of compression quality (if file format supports it).
Returns
result of the operation.

◆ Region()

def Region (   self,
int  left,
int  top,
int  right,
int  bottom 
)

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

Parameters
left- a left side of the region.
top- a top side of the region.
right- a right side of the region.
bottom- a bottom side of the region.
Returns
- a new Simd.Image which points to the subregion of current image.

◆ RegionAt()

def RegionAt (   self,
int  width,
int  height,
Simd.Position  position 
)

Creates a new Simd.Image which points to the region of current image with given size at current position.

Parameters
width- a width of the region.
height- a height of the region.
position- a position of the region.
Returns
- a new Simd.Image which points to the subregion of current image.

◆ Copy()

def Copy (   self,
  dst = None 
)

Copies current image.

Parameters
dst- an output image. It can be empty.
Returns
copied image.

◆ Convert()

def Convert (   self,
  dst,
  alpha = 255 
)

Converts current image to output image.

Current image must be in Gray8, BGR-24, BGRA-32, RGB-24, RGBA32 format.

Parameters
dst- an output image in Gray8, BGR-24, BGRA-32, RGB-24, RGBA32 format.
alpha- a value of output alpha channel (optional).

◆ Converted()

def Converted (   self,
PixelFormat  format,
  alpha = 255 
)

Gets converted current image in given format.

Current image must be in Gray8, BGR-24, BGRA-32, RGB-24 or RGBA32 format.

Parameters
format- a format of output image. It can be Gray8, BGR-24, BGRA-32, RGB-24 or RGBA32.
alpha- a value of output alpha channel (optional).
Returns
- converted output image in given format.

◆ Fill()

def Fill (   self,
array.array('B')  pixel 
)

Fills image by value of given pixel.

Parameters
pixel- an array of unsigned 8-bit integer with pixel channels. Its size is in range [1..4].

◆ CopyToNumpyArray()

def CopyToNumpyArray (   self,
  dst = None 
)

Copy image to output numpy.array.

Parameters
dst- an output numpy.array with image copy.
Returns
- output numpy.array with image copy.