MCPcopy Create free account
hub / github.com/vispy/vispy / make_rgba

Function make_rgba

vispy/testing/rendered_array_tester.py:63–85  ·  view source on GitHub ↗

Convert any array to an RGBA array. RGBA arrays have 3 dimensions where the last represents the channels. If an Alpha channel needs to be added it will be made completely opaque. Returns ------- 3D RGBA unsigned 8-bit array

(data_in: ArrayLike)

Source from the content-addressed store, hash-verified

61
62
63def make_rgba(data_in: ArrayLike) -> ArrayLike:
64 """Convert any array to an RGBA array.
65
66 RGBA arrays have 3 dimensions where the last represents the channels. If
67 an Alpha channel needs to be added it will be made completely opaque.
68
69 Returns
70 -------
71 3D RGBA unsigned 8-bit array
72
73 """
74 max_val = max_for_dtype(data_in.dtype)
75 if data_in.ndim == 3 and data_in.shape[-1] == 1:
76 data_in = data_in.squeeze()
77
78 if data_in.ndim == 2:
79 out = np.stack([data_in] * 4, axis=2)
80 out[:, :, 3] = max_val
81 elif data_in.shape[-1] == 3:
82 out = np.concatenate((data_in, np.ones((*data_in.shape[:2], 1)) * max_val), axis=2)
83 else:
84 out = data_in
85 return np.round((out.astype(np.float32) * 255 / max_val)).astype(np.uint8)

Callers 1

compare_renderFunction · 0.85

Calls 1

max_for_dtypeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…