Class Image#

Inheritance Relationships#

Derived Types#

Class Documentation#

class Image#

Abstract image base class.

Subclassed by TRAP::INTERNAL::BMPImage, TRAP::INTERNAL::CustomImage, TRAP::INTERNAL::PAMImage, TRAP::INTERNAL::PFMImage, TRAP::INTERNAL::PGMImage, TRAP::INTERNAL::PNGImage, TRAP::INTERNAL::PNMImage, TRAP::INTERNAL::PPMImage, TRAP::INTERNAL::QOIImage, TRAP::INTERNAL::RadianceImage, TRAP::INTERNAL::TGAImage

Public Types

enum class ColorFormat : u32#

Color formats.

Values:

enumerator NONE#
enumerator GrayScale#
enumerator GrayScaleAlpha#
enumerator RGB#
enumerator RGBA#

Public Functions

Image(const Image&) noexcept = default#

Copy constructor.

Image &operator=(const Image&) noexcept = default#

Copy assignment operator.

Image(Image&&) noexcept = default#

Move constructor.

Image &operator=(Image&&) noexcept = default#

Move assignment operator.

virtual ~Image() = default#

Destructor.

virtual constexpr std::span<const u8> GetPixelData() const noexcept = 0#

Retrieve the raw pixel data of the image.

Returns:

Raw pixel data.

constexpr u32 GetBitsPerPixel() const noexcept#

Retrieve the amount of bits used for a single pixel in the image.

Returns:

Amount of bits.

constexpr u32 GetBytesPerPixel() const noexcept#

Retrieve the amount of bytes used for a single pixel in the image.

Returns:

Amount of bytes.

constexpr u32 GetBitsPerChannel() const noexcept#

Retrieve the amount of bits used for a single channel of a pixel in the image.

Returns:

Amount of bits.

constexpr u32 GetBytesPerChannel() const noexcept#

Retrieve the amount of bytes used for a single channel of a pixel in the image.

Returns:

Amount of bytes.

constexpr u32 GetWidth() const noexcept#

Retrieve the width of the image.

Returns:

Width of the image.

constexpr u32 GetHeight() const noexcept#

Retrieve the height of the image.

Returns:

Height of the image.

constexpr Math::Vec2ui GetSize() const noexcept#

Retrieve the size of the image.

Returns:

Size of the image as a Math::Vec2ui.

constexpr bool HasAlphaChannel() const noexcept#

Retrieve whether the image has an alpha channel or not.

Returns:

True if image has an alpha channel, false otherwise.

constexpr bool IsImageGrayScale() const noexcept#

Retrieve whether the image is gray scale or not.

Returns:

True if image is gray scale, false otherwise.

constexpr bool IsImageColored() const noexcept#

Retrieve whether the image is colored or not.

Returns:

True if image is colored, false otherwise.

constexpr bool IsHDR() const noexcept#

Retrieve whether the image is HDR(High Dynamic Range) or not.

Returns:

True if image is HDR, false otherwise.

constexpr bool IsLDR() const noexcept#

Retrieve whether the image is LDR(Low Dynamic Range) or not.

Returns:

True if image is LDR, false otherwise.

const std::filesystem::path &GetFilePath() const noexcept#

Retrieve the file path of the image.

Returns:

Path to the image file, or empty string for custom images.

constexpr ColorFormat GetColorFormat() const noexcept#

Retrieve the color format used by the image.

Returns:

Color format of the image.

Public Static Functions

static Scope<Image> LoadFromFile(const std::filesystem::path &filepath)#

Load an image from disk.

Parameters:

filepath – Path to the image. Supported formats:

  • Portable Maps: PGM, PPM, PNM, PAM, PFM

  • Targa: TGA, ICB, VDA, VST

  • Bitmap: BMP, DIB

  • Portable Network Graphics: PNG

  • Radiance: HDR, PIC

Returns:

Loaded image on success, fallback image otherwise.

static Scope<Image> LoadFromMemory(u32 width, u32 height, ColorFormat format, const std::vector<u8> &pixelData)#

Load an image from memory.

Note

There are no validation checks for images loaded from memory!

Parameters:
  • width – Width for the image.

  • height – Height for the image

  • format – Color format for the image.

  • pixelData – Raw pixel data for the image

Returns:

Loaded image.

static Scope<Image> LoadFromMemory(u32 width, u32 height, ColorFormat format, const std::vector<u16> &pixelData)#

Load an image from memory.

Note

There are no validation checks for images loaded from memory!

Parameters:
  • width – Width for the image.

  • height – Height for the image

  • format – Color format for the image.

  • pixelData – Raw pixel data for the image

Returns:

Loaded Image.

static Scope<Image> LoadFromMemory(u32 width, u32 height, ColorFormat format, const std::vector<f32> &pixelData)#

Load an HDR image from memory.

Note

There are no validation checks for images loaded from memory!

Parameters:
  • width – Width for the image.

  • height – Height for the image

  • format – Color format for the image.

  • pixelData – Raw pixel data for the image

Returns:

Loaded Image.

static Scope<Image> LoadFallback()#

Load the fallback image.

Returns:

Fallback image.

static bool IsSupportedImageFile(const std::filesystem::path &filepath)#

Check if the given file is a supported image.

Parameters:

filepath – Path to a file

Returns:

True if given file is an image, false otherwise.

static Scope<Image> FlipX(const Image *img)#

Flip an image on its X axis.

Parameters:

imgImage to flip.

Returns:

Flipped image.

static Scope<Image> FlipY(const Image *img)#

Flip an image on its Y axis.

Parameters:

imgImage to flip.

Returns:

Flipped image.

static Scope<Image> Rotate90Clockwise(const Image *img)#

Rotate an image by 90 degrees clockwise.

Parameters:

imgImage to flip.

Returns:

Rotated image.

static Scope<Image> Rotate90CounterClockwise(const Image *img)#

Rotate an image by 90 degrees counter clockwise.

Parameters:

imgImage to flip.

Returns:

Rotated image.

static Scope<Image> ConvertRGBToRGBA(const Image *img)#

Convert a RGB image to RGBA.

Parameters:

imgImage to convert.

Returns:

Converted image.

Public Static Attributes

static constexpr std::array<std::string_view, 15> SupportedImageFormatSuffixes{".pgm", ".ppm", ".pnm", ".pam", ".pfm", ".tga", ".icb", ".vda", ".vst", ".bmp", ".dib", ".png", ".hdr", ".pic", ".qoi"}#

Protected Functions

explicit Image(std::filesystem::path filepath)#

Constructor.

Image(std::filesystem::path filepath, u32 width, u32 height, ColorFormat format)#

Constructor.

Protected Attributes

u32 m_width = 0#
u32 m_height = 0#
bool m_isHDR = false#
ColorFormat m_colorFormat = ColorFormat::NONE#
std::filesystem::path m_filepath = {}#
u32 m_bitsPerPixel = 0#

Protected Static Functions

template<typename T>
static std::vector<T> FlipX(u32 width, u32 height, ColorFormat format, std::span<const T> data)#

Flip raw pixel data on X axis.

Template Parameters:

T – u8, u16 or f32.

Parameters:
  • width – Width of image in pixels.

  • height – Height of image in pixels.

  • format – Color format of the image data.

  • data – Raw pixel data.

Returns:

Flipped raw pixel data

template<typename T>
static std::vector<T> FlipY(u32 width, u32 height, ColorFormat format, std::span<const T> data)#

Flip raw pixel data on Y axis.

Template Parameters:

T – u8, u16 or f32.

Parameters:
  • width – Width of image in pixels.

  • height – Height of image in pixels.

  • format – Color format of the image data.

  • data – Raw pixel data.

Returns:

Flipped raw pixel data

template<typename T>
static std::vector<T> Rotate90Clockwise(u32 width, u32 height, ColorFormat format, std::span<const T> data)#

Rotate raw pixel data by 90 degrees clockwise.

Template Parameters:

T – u8, u16 or f32.

Parameters:
  • width – Width of image in pixels.

  • height – Height of image in pixels.

  • format – Color format of the image data.

  • data – Raw pixel data.

Returns:

Rotated raw pixel data

template<typename T>
static std::vector<T> Rotate90CounterClockwise(u32 width, u32 height, ColorFormat format, std::span<const T> data)#

Rotate raw pixel data by 90 degrees counter clockwise.

Template Parameters:

T – u8, u16 or f32.

Parameters:
  • width – Width of image in pixels.

  • height – Height of image in pixels.

  • format – Color format of the image data.

  • data – Raw pixel data.

Returns:

Rotate raw pixel data

template<typename T>
static std::vector<T> ConvertRGBToRGBA(u32 width, u32 height, std::span<const T> data)#

Converts raw RGB pixel data to RGBA.

Template Parameters:

T – u8, u16 or f32.

Parameters:
  • width – Width of image in pixels.

  • height – Height of image in pixels.

  • data – Raw pixel data.

Returns:

Converted RGBA raw pixel data

template<typename T>
static std::vector<T> ConvertRGBAToRGB(u32 width, u32 height, std::span<const T> data)#

Converts raw RGBA pixel data to RGB.

Template Parameters:

T – u8, u16 or f32.

Parameters:
  • width – Width of image in pixels.

  • height – Height of image in pixels.

  • data – Raw pixel data.

Returns:

Converted RGB raw pixel data

static constexpr std::vector<u8> ConvertBGR16ToRGB24(std::vector<u8> &source, u32 width, u32 height)#

Converts BGR16 pixel data to RGB24.

Parameters:
  • source – BGR16 pixel data.

  • width – Width of the image.

  • height – Height of the image.

Returns:

RGB24 pixel data.

static constexpr std::vector<u8> ConvertBGR24ToRGB24(std::vector<u8> &source, u32 width, u32 height)#

Converts BGR24 pixel data to RGB24.

Parameters:
  • source – BGR24 pixel data.

  • width – Width of the image.

  • height – Height of the image.

Returns:

RGB24 pixel data.

static constexpr std::vector<u8> ConvertBGRA32ToRGBA32(std::vector<u8> &source, u32 width, u32 height)#

Converts BGR32 pixel data to RGB32.

Parameters:
  • source – BGR32 pixel data.

  • width – Width of the image.

  • height – Height of the image.

Returns:

RGB32 pixel data.

static constexpr std::vector<u8> DecodeBGRAMap(std::vector<u8> &source, u32 width, u32 height, u32 channels, std::vector<u8> &colorMap)#

Decode BGRA indexed pixel data to RGBA. Output format depends on channel count, if it is 4, output is RGBA, if it is 3, output is RGB and so on.

Parameters:
  • source – Indexed BGRA pixel data.

  • width – Width of the image.

  • height – Height of the image.

  • channels – Amount of channels, i.e. 4 = RGBA, 3 = RGB.

  • colorMap – Color table.

Returns:

Decoded pixel data.