A module for image masks, suitable for fast pixel-perfect collision detections.
Returns a Mask from the given pygame2.sdl.video.Surface.
Makes the transparent parts of the pygame2.sdl.video.Surface not set, and the opaque parts set. The alpha of each pixel is checked to see if it is greater than the given threshold. If the pygame2.sdl.video.Surface is color keyed, then threshold is not used.
This requires pygame2 to be built with SDL support enabled.
Creates a Mask by thresholding surfaces.
This is a more featureful method of getting a Mask from a pygame2.sdl.video.Surface. If supplied with only one pygame2.sdl.video.Surface, all pixels within the threshold of the supplied color are set in the :class`Mask`. If given the optional thressurface, all pixels in surface that are within the threshold of the corresponding pixel in thressurface are set in the Mask.
Clears all bits in the Mask.
Resets the state of all bits in the Mask to 0.
Returns a Mask of a connected region of pixels.
This uses the SAUF algorithm to find a connected component in the Mask. It checks 8 point connectivity. By default, it will return the largest connected component in the image. Optionally, a coordinate pair of a pixel can be specified, and the connected component containing it will be returned. In the event the pixel at that location is not set, the returned Mask will be empty. The Mask returned is the same size as the original Mask.
Returns a Mask of a connected region of pixels.
Returns a list of masks of connected regions of pixels. An optional minimum number of pixels per connected region can be specified to filter out noise.
Return the convolution with another Mask.
Returns a Mask with the [x-offset[0], y-offset[1]] bit set if shifting mask so that it’s lower right corner pixel is at (x, y) would cause it to overlap with self.
If an outputmask is specified, the output is drawn onto outputmask and outputmask is returned. Otherwise a mask of size size + mask.:attr:size - (1, 1) is created.
Draws the passed Mask onto the Mask.
This performs a bitwise OR operation upon the calling Mask. The passed mask‘s start offset for the draw operation will be the x and y offset passed to the method.
Erases the passed Mask from the Mask.
This performs a bitwise NAND operation upon the calling Mask. The passed mask‘s start offset for the erase operation will be the x and y offset passed to the method.
Returns a list of bounding rects of regions of set pixels.
This gets a bounding rect of connected regions of set bits. A bounding rect is one for which each of the connected pixels is inside the rect.
Gets the points outlining an object on the mask.
Returns a list of points of the outline of the first object it comes across in the Mask. For this to be useful, there should probably only be one connected component of pixels in the Mask. The skip option allows you to skip pixels in the outline. For example, setting it to 10 would return a list of every 10th pixel in the outline.
Returns nonzero if the masks overlap with the given offset.
The overlap tests uses the following offsets (which may be negative):
+----+----------...
|A | yoffset
| +-+----------...
+--|B
|xoffset
| |
| |
: :
Returns the number of overlapping bits of two Masks.
This returns how many pixels overlap with the other mask given. It can be used to see in which direction things collide, or to see how much the two masks collide.
Creates a new scaled Mask with the given width and height.
The quality of the scaling may not be perfect for all circumstances, but it should be reasonable. If either width or height is 0 a clear 1x1 mask is returned.