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=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, 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... | |
| int | 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 | LoadFromMemory (self, bytes data, desiredFormat=Simd.PixelFormat.Empty) |
| Loads an image from a memory buffer. More... | |
| bool | Save (self, str path, file=Simd.ImageFile.Undefined, quality=100) |
| Saves the image to file in given image file format. More... | |
| bytes | SaveToMemory (self, file=Simd.ImageFile.Png, quality=100) |
| Saves the image to a memory buffer 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 | CopyFrame (self, dst, int frameLeft, int frameTop, int frameRight, int frameBottom) |
| Copies the outer frame region of current image to the destination image, leaving the interior rectangle untouched. 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 | DrawLine (self, int x1, int y1, int x2, int y2, array.array('B') color, width=1) |
| Draws a line at the image. More... | |
| def | DrawRectangle (self, int left, int top, int right, int bottom, array.array('B') color, width=1) |
| Draws a rectangle at the image. More... | |
| def | DrawFilledRectangle (self, int left, int top, int right, int bottom, array.array('B') color) |
| Draws a filled rectangle at the image. 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 = 0 |
|||
| ) |
Creates a new image.
- Parameters
-
format - image pixel format. width - image width. height - image height. align - a row size alignment 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 alignment in bytes (optional).
◆ FromExternal()
| def FromExternal | ( | self, | |
| Simd.PixelFormat | format, | ||
| int | width, | ||
| int | height, | ||
| int | stride, | ||
| 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()
| int Data | ( | self | ) |
Gets pointer to image pixel data.
- Returns
- pointer to image pixel data as an integer address (0 if empty).
◆ 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.
◆ LoadFromMemory()
| bool LoadFromMemory | ( | self, | |
| bytes | data, | ||
desiredFormat = Simd.PixelFormat.Empty |
|||
| ) |
Loads an image from a memory buffer.
- Parameters
-
data - a bytes object with the encoded image data. 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 data).
- 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 choice 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.
◆ SaveToMemory()
| bytes SaveToMemory | ( | self, | |
file = Simd.ImageFile.Png, |
|||
quality = 100 |
|||
| ) |
Saves the image to a memory buffer 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
-
file - a format of output image file. quality - a parameter of compression quality (if file format supports it).
- Returns
- a bytes object with the encoded image data.
◆ 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.
◆ CopyFrame()
| def CopyFrame | ( | self, | |
| dst, | |||
| int | frameLeft, | ||
| int | frameTop, | ||
| int | frameRight, | ||
| int | frameBottom | ||
| ) |
Copies the outer frame region of current image to the destination image, leaving the interior rectangle untouched.
The current and destination images must have the same width, height, and format. The method copies four areas by calling Simd.Image.Copy for the corresponding image regions: rows above frameTop, rows at or below frameBottom, columns before frameLeft inside the frame vertical range, and columns at or after frameRight inside the frame vertical range. The rectangle [frameLeft, frameRight) x [frameTop, frameBottom) is left unchanged.
- Parameters
-
dst - a destination image. frameLeft - a left side of the interior frame. frameTop - a top side of the interior frame. frameRight - a right side of the interior frame. frameBottom - a bottom side of the interior frame.
- Returns
- destination 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.
◆ DrawLine()
| def DrawLine | ( | self, | |
| int | x1, | ||
| int | y1, | ||
| int | x2, | ||
| int | y2, | ||
| array.array('B') | color, | ||
width = 1 |
|||
| ) |
Draws a line at the image.
- Parameters
-
[in] x1 - X coordinate of the first point of the line. [in] y1 - Y coordinate of the first point of the line. [in] x2 - X coordinate of the second point of the line. [in] y2 - Y coordinate of the second point of the line. [in] color - a color of the line. [in] width - a width of the line. By default it is equal to 1.
◆ DrawRectangle()
| def DrawRectangle | ( | self, | |
| int | left, | ||
| int | top, | ||
| int | right, | ||
| int | bottom, | ||
| array.array('B') | color, | ||
width = 1 |
|||
| ) |
Draws a rectangle at the image.
- Parameters
-
left - a left of the rectangle. top - a top of the rectangle. right - a right of the rectangle. bottom - a bottom of the rectangle. color - a pointer to colors of the line. width - a line width of rectangle. By default it is equal to 1.
◆ DrawFilledRectangle()
| def DrawFilledRectangle | ( | self, | |
| int | left, | ||
| int | top, | ||
| int | right, | ||
| int | bottom, | ||
| array.array('B') | color | ||
| ) |
Draws a filled rectangle at the image.
- Parameters
-
left - a left of the rectangle. top - a top of the rectangle. right - a right of the rectangle. bottom - a bottom of the rectangle. color - a pointer to colors of the rectangle.
◆ 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.