I’m working on a script that takes a Panda scene screenshot and writes it to some pseudo-device that expects that data to be in SRGB/BGR format. I’m using the following snippet to get the screenshot:
# self is instance of ShowBase props = WindowProperties.getDefault() props.setOrigin(0, 0) props.setSize(width, height) props.setFixedSize(True) offwindow = self.openWindow(props, makeCamera=False, type="offscreen", requireWindow=True) display_region = offwindow.makeDisplayRegion(0.0, 1.0, 0.0, 1.0) self.graphicsEngine.renderFrame() texture = display_region.getScreenshot() numpy_image = memoryview(texture.getRamImage())
The problem is that in order to match the output device’s pixel format I need to convert the obtained image from ABGR to BGR:
numpy_image = np.reshape(numpy_image, (width, height, 4) numpy_image = numpy_image[:, :, 0:3]
and this conversion introduces some significant overhead.
Is there a way to have Panda output screenshots to Texture with some given pixel format (BGR, 3 bytes per pixel)? Also, is it possible to tell Panda to actually output the image to a memory-mapped region rather than to a Texture object?