Class cocos.audio.SDL.array.SDL_array

Methods

  __init__(self, ptr, count, ctype)
Construct an array at memory location ptr with count elements of type ctype.
SDL_array as_bytes(self)
Access the array as raw bytes, regardless of the underlying data type.
SDL_array as_int16(self)
Access the array as 16-bit integers, regardless of the underlying data type.
SDL_array as_int32(self)
Access the array as 32-bit integers, regardless of the underlying data type.
ctypes.Array as_ctypes(self)
Access the array as a ctypes array.
bool have_numpy(cls)
Determine if the numpy array module is available.
numpy.ndarray as_numpy(self, shape=None)
Access the array as a numpy array.
string to_string(self)
Return a string with the contents of this array.
  from_string(self, data)
Copy string data into this array.
  __repr__(self)
  __len__(self)
  __getitem__(self, key)
  __setitem__(self, key, value)

Method Details

__init__

(Constructor) __init__(self, ptr, count, ctype)
Construct an array at memory location ptr with count elements of type ctype.
Parameters:
ptr : ctypes.Array, POINTER(ctype) or POINTER(ctypes.Array)
Starting point of the array space. Don't use c_void_p; this will not cast correctly. If ptr is None, the array will be created (filled with random data).
count : int
Number of elements in the array.
ctype : type
ctypes type if each element, e.g., c_ubyte, c_int, etc.

as_bytes

as_bytes(self)

Access the array as raw bytes, regardless of the underlying data type.

This can be useful, for example, in accessing a 32-bit colour buffer by individual components rather than the encoded pixel.

Returns: SDL_array

as_numpy

as_numpy(self, shape=None)

Access the array as a numpy array.

The numpy array shares the same underlying memory buffer, so changes are immediate, and you can use the numpy array as you would normally. To set the entire contents of the array at once, use a [:] slice.

If numpy is not installed, an ImportError will be raised.

Returns: numpy.ndarray

from_string

from_string(self, data)

Copy string data into this array.

The string must have exactly the same length of this array (in bytes). No size checking is performed.

Parameters:
data : str
String data to copy.