def _get_gl_tex_format(self, texture_format, num_channels): if texture_format and not isinstance(texture_format, str): texture_format = np.dtype(texture_format).type if texture_format not in self._texture_dtype_format: raise ValueError("Can't determine internal texture format for '{}'".format(texture_format)) should_cast_to_f32(texture_format) texture_format = self._texture_dtype_format[texture_format] # adjust internalformat for format of data (RGBA vs L) texture_format = texture_format.replace('r', 'rgba'[:num_channels]) return texture_format
def _scale_data_on_cpu(data, clim, copy=True): if copy: should_cast_to_f32(data.dtype) data = np.array(data, dtype=np.float32, copy=copy) elif not copy and not np.issubdtype(data.dtype, np.floating): raise ValueError("Data must be of floating type for no copying to occur.") if clim[0] != clim[1]: data -= clim[0] data *= 1.0 / (clim[1] - clim[0]) if should_cast_to_f32(data.dtype): data = data.astype(np.float32) return data
def _cast_arrays_if_needed(data_arrays): for data in data_arrays: if data is not None and should_cast_to_f32(data.dtype): data = data.astype(np.float32) yield data