CARLA
Public Types | Static Public Member Functions | List of all members
FPixelReader Class Reference

Utils for reading pixels from UTextureRenderTarget2D. More...

#include <PixelReader.h>

Public Types

using Payload = std::function< void(void *, uint32, uint32)>
 

Static Public Member Functions

static TUniquePtr< TImagePixelData< FColor > > DumpPixels (UTextureRenderTarget2D &RenderTarget)
 Dump the pixels in RenderTarget. More...
 
static TFuture< bool > SavePixelsToDisk (UTextureRenderTarget2D &RenderTarget, const FString &FilePath)
 Asynchronously save the pixels in RenderTarget to disk. More...
 
static TFuture< bool > SavePixelsToDisk (TUniquePtr< TImagePixelData< FColor >> PixelData, const FString &FilePath)
 Asynchronously save the pixels in PixelData to disk. More...
 
template<typename TSensor , typename TPixel >
static void SendPixelsInRenderThread (TSensor &Sensor, bool use16BitFormat=false, std::function< TArray< TPixel >(void *, uint32)> Conversor={})
 Convenience function to enqueue a render command that sends the pixels down the Sensor's data stream. More...
 
static bool WritePixelsToArray (UTextureRenderTarget2D &RenderTarget, TArray< FColor > &BitMap)
 Copy the pixels in RenderTarget into BitMap. More...
 
static void WritePixelsToBuffer (const UTextureRenderTarget2D &RenderTarget, uint32 Offset, FRHICommandListImmediate &InRHICmdList, FPixelReader::Payload FuncForSending)
 Copy the pixels in RenderTarget into Buffer. More...
 

Detailed Description

Utils for reading pixels from UTextureRenderTarget2D.

Todo:
This class only supports PF_R8G8B8A8 format.

Definition at line 28 of file PixelReader.h.

Member Typedef Documentation

◆ Payload

using FPixelReader::Payload = std::function<void(void *, uint32, uint32)>

Definition at line 32 of file PixelReader.h.

Member Function Documentation

◆ DumpPixels()

TUniquePtr< TImagePixelData< FColor > > FPixelReader::DumpPixels ( UTextureRenderTarget2D &  RenderTarget)
static

Dump the pixels in RenderTarget.

Precondition
To be called from game-thread.

Definition at line 117 of file PixelReader.cpp.

◆ SavePixelsToDisk() [1/2]

TFuture< bool > FPixelReader::SavePixelsToDisk ( UTextureRenderTarget2D &  RenderTarget,
const FString &  FilePath 
)
static

Asynchronously save the pixels in RenderTarget to disk.

Precondition
To be called from game-thread.

Definition at line 130 of file PixelReader.cpp.

Referenced by URoadMap::SaveAsPNG(), and ASceneCaptureSensor::SaveCaptureToDisk().

+ Here is the caller graph for this function:

◆ SavePixelsToDisk() [2/2]

TFuture< bool > FPixelReader::SavePixelsToDisk ( TUniquePtr< TImagePixelData< FColor >>  PixelData,
const FString &  FilePath 
)
static

Asynchronously save the pixels in PixelData to disk.

Precondition
To be called from game-thread.

Definition at line 137 of file PixelReader.cpp.

◆ SendPixelsInRenderThread()

template<typename TSensor , typename TPixel >
void FPixelReader::SendPixelsInRenderThread ( TSensor &  Sensor,
bool  use16BitFormat = false,
std::function< TArray< TPixel >(void *, uint32)>  Conversor = {} 
)
static

Convenience function to enqueue a render command that sends the pixels down the Sensor's data stream.

It expects a sensor derived from ASceneCaptureSensor or compatible.

Note that the serializer needs to define a "header_offset" that it's allocated in front of the buffer.

Precondition
To be called from game-thread.

Blocks until the render thread has finished all it's tasks.

Todo:
Can we make sure the sensor is not going to be destroyed?

Definition at line 88 of file PixelReader.h.

References FCarlaEngine::GetFrameCounter(), and WritePixelsToBuffer().

+ Here is the call graph for this function:

◆ WritePixelsToArray()

bool FPixelReader::WritePixelsToArray ( UTextureRenderTarget2D &  RenderTarget,
TArray< FColor > &  BitMap 
)
static

Copy the pixels in RenderTarget into BitMap.

Precondition
To be called from game-thread.

Definition at line 100 of file PixelReader.cpp.

Referenced by ASceneCaptureSensor::ReadPixels().

+ Here is the caller graph for this function:

◆ WritePixelsToBuffer()

void FPixelReader::WritePixelsToBuffer ( const UTextureRenderTarget2D &  RenderTarget,
uint32  Offset,
FRHICommandListImmediate &  InRHICmdList,
FPixelReader::Payload  FuncForSending 
)
static

Copy the pixels in RenderTarget into Buffer.

Precondition
To be called from render-thread.

Definition at line 40 of file PixelReader.cpp.

References LockTexture::Texture.

Referenced by SendPixelsInRenderThread().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: