Open 3D Engine Atom Gem API Reference 24.09.2
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::Utils::PngFile Class Reference

#include <PngFile.h>

Classes

struct  LoadSettings
 
struct  SaveSettings
 

Public Types

enum class  Format { Unknown , RGB , RGBA }
 
using ErrorHandler = AZStd::function<void(const char*)>
 

Public Member Functions

bool Save (const char *path, SaveSettings saveSettings={})
 
bool IsValid () const
 
 operator bool () const
 
uint32_t GetWidth () const
 
uint32_t GetHeight () const
 
Format GetBufferFormat () const
 
const AZStd::vector< uint8_t > & GetBuffer () const
 
AZStd::vector< uint8_t > && TakeBuffer ()
 Returns a r-value reference that can be moved. This will invalidate the PngFile.
 

Static Public Member Functions

static PngFile Load (const char *path, LoadSettings loadSettings={})
 
static PngFile LoadFromBuffer (AZStd::span< const uint8_t > data, LoadSettings loadSettings={})
 
static PngFile Create (const RHI::Size &size, RHI::Format format, AZStd::span< const uint8_t > data, ErrorHandler errorHandler={})
 
static PngFile Create (const RHI::Size &size, RHI::Format format, AZStd::vector< uint8_t > &&data, ErrorHandler errorHandler={})
 

Detailed Description

This is a light wrapper class for libpng, to load and save .png files. Functionality is limited, feel free to add more features as needed.

Member Function Documentation

◆ Create()

static PngFile AZ::Utils::PngFile::Create ( const RHI::Size & size,
RHI::Format format,
AZStd::span< const uint8_t > data,
ErrorHandler errorHandler = {} )
static

Create a PngFile from an RHI data buffer.

Parameters
sizethe dimensions of the image (m_depth is not used, assumed to be 1)
formatindicates the pixel format represented by @data. Only a limited set of formats are supported, see implementation.
datathe buffer of image data. The size of the buffer must match the @size and @format parameters.
errorHandleroptional callback function describing any errors that are encountered
Returns
the created PngFile or an invalid PngFile if there was an error.

◆ Load()

static PngFile AZ::Utils::PngFile::Load ( const char * path,
LoadSettings loadSettings = {} )
static
Returns
the loaded PngFile or an invalid PngFile if there was an error.

◆ LoadFromBuffer()

static PngFile AZ::Utils::PngFile::LoadFromBuffer ( AZStd::span< const uint8_t > data,
LoadSettings loadSettings = {} )
static
Returns
the loaded PngFile or an invalid PngFile if there was an error.

◆ Save()

bool AZ::Utils::PngFile::Save ( const char * path,
SaveSettings saveSettings = {} )
Returns
true if the save operation was successful

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