def __transform_frame(self, frame): if not (VideoColorMode.is_color_mode_rgb(self.__video_color_mode)): gamma_index = self.__gamma_controller.getGammaIndexForMonochromeFrame( frame) shape = [ Config.get_or_throw('leds.display_height'), Config.get_or_throw('leds.display_width'), 3 ] transformed_frame = np.zeros(shape, np.uint8) # calculate gamma corrected colors if self.__video_color_mode == VideoColorMode.COLOR_MODE_COLOR: transformed_frame[:, :, 0] = np.take(self.__scale_red_gamma_curve, frame[:, :, 0]) transformed_frame[:, :, 1] = np.take(self.__scale_green_gamma_curve, frame[:, :, 1]) transformed_frame[:, :, 2] = np.take(self.__scale_blue_gamma_curve, frame[:, :, 2]) elif self.__video_color_mode == VideoColorMode.COLOR_MODE_R: transformed_frame[:, :, 0] = np.take( self.__scale_red_gamma_curves[gamma_index], frame[:, :]) elif self.__video_color_mode == VideoColorMode.COLOR_MODE_G: transformed_frame[:, :, 1] = np.take( self.__scale_green_gamma_curves[gamma_index], frame[:, :]) elif self.__video_color_mode == VideoColorMode.COLOR_MODE_B: transformed_frame[:, :, 2] = np.take( self.__scale_blue_gamma_curves[gamma_index], frame[:, :]) elif self.__video_color_mode == VideoColorMode.COLOR_MODE_BW: transformed_frame[:, :, 0] = np.take( self.__scale_red_gamma_curves[gamma_index], frame[:, :]) transformed_frame[:, :, 1] = np.take( self.__scale_green_gamma_curves[gamma_index], frame[:, :]) transformed_frame[:, :, 2] = np.take( self.__scale_blue_gamma_curves[gamma_index], frame[:, :]) elif self.__video_color_mode == VideoColorMode.COLOR_MODE_INVERT_COLOR: transformed_frame[:, :, 0] = np.take(self.__scale_red_gamma_curve, 255 - frame[:, :, 0]) transformed_frame[:, :, 1] = np.take(self.__scale_green_gamma_curve, 255 - frame[:, :, 1]) transformed_frame[:, :, 2] = np.take(self.__scale_blue_gamma_curve, 255 - frame[:, :, 2]) elif self.__video_color_mode == VideoColorMode.COLOR_MODE_INVERT_BW: transformed_frame[:, :, 0] = np.take( self.__scale_red_gamma_curves[gamma_index], 255 - frame[:, :]) transformed_frame[:, :, 1] = np.take( self.__scale_green_gamma_curves[gamma_index], 255 - frame[:, :]) transformed_frame[:, :, 2] = np.take( self.__scale_blue_gamma_curves[gamma_index], 255 - frame[:, :]) else: raise Exception( f'Unexpected color mode: {self.__video_color_mode}.') flips = () if Config.get('leds.flip_y', False): flips += (0, ) if Config.get('leds.flip_x', False): flips += (1, ) if flips: transformed_frame = np.flip(transformed_frame, flips) return transformed_frame