SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Loading...
Searching...
No Matches
vtfpp::ImageConversion Namespace Reference

Classes

struct  ResizeBounds

Enumerations

enum class  FileFormat {
  DEFAULT = 0 , PNG = 1 , JPG = 2 , BMP = 3 ,
  TGA = 4 , HDR = 7
}
enum class  ResizeEdge { CLAMP = 0 , REFLECT , WRAP , ZERO }
enum class  ResizeFilter {
  DEFAULT = 0 , BOX , BILINEAR , CUBIC_BSPLINE ,
  CATMULL_ROM , MITCHELL , POINT_SAMPLE , KAISER = 100 ,
  NICE = 101
}
enum class  ResizeMethod { NONE , POWER_OF_TWO_BIGGER , POWER_OF_TWO_SMALLER , POWER_OF_TWO_NEAREST }

Functions

std::vector< std::byte > convertImageDataToFormat (std::span< const std::byte > imageData, ImageFormat oldFormat, ImageFormat newFormat, uint16_t width, uint16_t height, float quality=DEFAULT_COMPRESSED_QUALITY)
 Converts an image from one format to another.
std::vector< std::byte > convertSeveralImageDataToFormat (std::span< const std::byte > imageData, ImageFormat oldFormat, ImageFormat newFormat, uint8_t mipCount, uint16_t frameCount, uint8_t faceCount, uint16_t width, uint16_t height, uint16_t depth, float quality=DEFAULT_COMPRESSED_QUALITY)
 Converts several images from one format to another.
std::array< std::vector< std::byte >, 6 > convertHDRIToCubeMap (std::span< const std::byte > imageData, ImageFormat format, uint16_t width, uint16_t height, uint16_t resolution=0, bool bilinear=true, bool skybox=false)
 Converts an HDRI into six cubemap (or skybox) faces.
std::vector< std::byte > compressBGRA8888HDR (std::span< const std::byte > imageData, float overbrightFactor=16.f)
 Takes in RGBA32323232F format image data, returns SOURCEPP_BGRA8888_HDR compressed HDR image data (alias for BGRA8888).
std::vector< std::byte > decompressBGRA8888HDR (std::span< const std::byte > imageData, float overbrightFactor=16.f)
 Takes in SOURCEPP_BGRA8888_HDR compressed HDR image data (alias for BGRA8888), returns RGBA32323232F format image data.
std::vector< std::byte > compressRGBA16161616HDR (std::span< const std::byte > imageData, bool flipExponentAndSignificand=false)
 Takes in RGBA32323232F format image data, returns SOURCEPP_RGBA16161616_HDR compressed HDR image data (alias for RGBA16161616).
std::vector< std::byte > decompressRGBA16161616HDR (std::span< const std::byte > imageData, bool flipExponentAndSignificand=false)
 Takes in SOURCEPP_RGBA16161616_HDR compressed HDR image data (alias for RGBA16161616), returns RGBA32323232F format image data.
FileFormat getDefaultFileFormatForImageFormat (ImageFormat format)
 PNG for integer formats, EXR for floating point formats (or HDR if EXR support is disabled).
std::vector< std::byte > convertImageDataToFile (std::span< const std::byte > imageData, ImageFormat format, uint16_t width, uint16_t height, FileFormat fileFormat=FileFormat::DEFAULT)
 Converts image data to the given file format (PNG or EXR by default).
std::vector< std::byte > convertFileToImageData (std::span< const std::byte > fileData, ImageFormat &format, int &width, int &height, int &frameCount)
uint16_t getResizedDim (uint16_t n, ResizeMethod method)
 Get the new image size given a resize method.
void setResizedDims (uint16_t &width, ResizeMethod widthResize, uint16_t &height, ResizeMethod heightResize)
 Set the new image dimensions given a resize method.
std::vector< std::byte > resizeImageData (std::span< const std::byte > imageData, ImageFormat format, uint16_t width, uint16_t newWidth, uint16_t height, uint16_t newHeight, bool srgb, ResizeFilter filter, ResizeEdge edge=ResizeEdge::CLAMP)
 Resize given image data to the new dimensions.
std::vector< std::byte > resizeImageDataStrict (std::span< const std::byte > imageData, ImageFormat format, uint16_t width, uint16_t newWidth, uint16_t &widthOut, ResizeMethod widthResize, uint16_t height, uint16_t newHeight, uint16_t &heightOut, ResizeMethod heightResize, bool srgb, ResizeFilter filter, ResizeEdge edge=ResizeEdge::CLAMP)
 Resize given image data to the new dimensions, where the new width and height are governed by the resize methods.
std::vector< std::byte > cropImageData (std::span< const std::byte > imageData, ImageFormat format, uint16_t width, uint16_t newWidth, uint16_t xOffset, uint16_t height, uint16_t newHeight, uint16_t yOffset)
 Crops the given image to the new dimensions. If the image format is compressed it will be converted to its container format before the crop, and converted back before returning.
std::vector< std::byte > padImageData (std::span< const std::byte > imageData, ImageFormat format, uint16_t width, uint16_t widthPad, uint16_t height, uint16_t heightPad)
 Pad the given image with pixels that are the same color as the edge. Padding is applied to the right and bottom of the image.
void gammaCorrectImageData (std::span< std::byte > imageData, ImageFormat format, uint16_t width, uint16_t height, float gamma)
 Perform gamma correction on the given image data. Will not perform gamma correction if the input image format is large, console, P8, A8, UV88, UVLX8888, or UVWQ8888.
void invertGreenChannelForImageData (std::span< std::byte > imageData, ImageFormat format, uint16_t width, uint16_t height)
 Invert the green channel on the given image data. Meant for converting normal maps between OpenGL and DirectX formats.
void hableTonemapImageData (std::span< std::byte > imageData, ImageFormat format, uint16_t width, uint16_t height)
 Perform Hable tonemapping on the given image data.

Variables

constexpr float DEFAULT_COMPRESSED_QUALITY = -1.f

Enumeration Type Documentation

◆ FileFormat

Enumerator
DEFAULT 
PNG 
JPG 
BMP 
TGA 
HDR 

Definition at line 44 of file ImageConversion.h.

◆ ResizeEdge

Enumerator
CLAMP 
REFLECT 
WRAP 
ZERO 

Definition at line 70 of file ImageConversion.h.

◆ ResizeFilter

Enumerator
DEFAULT 
BOX 
BILINEAR 
CUBIC_BSPLINE 
CATMULL_ROM 
MITCHELL 
POINT_SAMPLE 
KAISER 
NICE 

Valve NICE filtering, equivalent to Lanczos-3.

Definition at line 78 of file ImageConversion.h.

◆ ResizeMethod

Enumerator
NONE 
POWER_OF_TWO_BIGGER 
POWER_OF_TWO_SMALLER 
POWER_OF_TWO_NEAREST 

Definition at line 94 of file ImageConversion.h.

Function Documentation

◆ compressBGRA8888HDR()

std::vector< std::byte > vtfpp::ImageConversion::compressBGRA8888HDR ( std::span< const std::byte > imageData,
float overbrightFactor = 16.f )
nodiscard

Takes in RGBA32323232F format image data, returns SOURCEPP_BGRA8888_HDR compressed HDR image data (alias for BGRA8888).

Definition at line 1066 of file ImageConversion.cpp.

◆ compressRGBA16161616HDR()

std::vector< std::byte > vtfpp::ImageConversion::compressRGBA16161616HDR ( std::span< const std::byte > imageData,
bool flipExponentAndSignificand = false )
nodiscard

Takes in RGBA32323232F format image data, returns SOURCEPP_RGBA16161616_HDR compressed HDR image data (alias for RGBA16161616).

Definition at line 1104 of file ImageConversion.cpp.

◆ convertFileToImageData()

std::vector< std::byte > vtfpp::ImageConversion::convertFileToImageData ( std::span< const std::byte > fileData,
ImageFormat & format,
int & width,
int & height,
int & frameCount )
nodiscard

Definition at line 1455 of file ImageConversion.cpp.

◆ convertHDRIToCubeMap()

std::array< std::vector< std::byte >, 6 > vtfpp::ImageConversion::convertHDRIToCubeMap ( std::span< const std::byte > imageData,
ImageFormat format,
uint16_t width,
uint16_t height,
uint16_t resolution = 0,
bool bilinear = true,
bool skybox = false )
nodiscard

Converts an HDRI into six cubemap (or skybox) faces.

The output image data is in the same image format as the input. If in cubemap mode, the output images have the following order: front, back, left, right, down, up. If in skybox mode, the output images have the following order: right, left, back, front, up, down. Resolution is the output size (width, height) of each image slice. 0 leaves it at the input size, the height of the HDRI. Fails (returns empty vectors) if the input data is empty, the given width is not 2x the height, or an error was encountered.

Definition at line 934 of file ImageConversion.cpp.

◆ convertImageDataToFile()

std::vector< std::byte > vtfpp::ImageConversion::convertImageDataToFile ( std::span< const std::byte > imageData,
ImageFormat format,
uint16_t width,
uint16_t height,
FileFormat fileFormat = FileFormat::DEFAULT )
nodiscard

Converts image data to the given file format (PNG or EXR by default).

Definition at line 1160 of file ImageConversion.cpp.

◆ convertImageDataToFormat()

std::vector< std::byte > vtfpp::ImageConversion::convertImageDataToFormat ( std::span< const std::byte > imageData,
ImageFormat oldFormat,
ImageFormat newFormat,
uint16_t width,
uint16_t height,
float quality = DEFAULT_COMPRESSED_QUALITY )
nodiscard

Converts an image from one format to another.

Definition at line 798 of file ImageConversion.cpp.

◆ convertSeveralImageDataToFormat()

std::vector< std::byte > vtfpp::ImageConversion::convertSeveralImageDataToFormat ( std::span< const std::byte > imageData,
ImageFormat oldFormat,
ImageFormat newFormat,
uint8_t mipCount,
uint16_t frameCount,
uint8_t faceCount,
uint16_t width,
uint16_t height,
uint16_t depth,
float quality = DEFAULT_COMPRESSED_QUALITY )
nodiscard

Converts several images from one format to another.

Definition at line 906 of file ImageConversion.cpp.

◆ cropImageData()

std::vector< std::byte > vtfpp::ImageConversion::cropImageData ( std::span< const std::byte > imageData,
ImageFormat format,
uint16_t width,
uint16_t newWidth,
uint16_t xOffset,
uint16_t height,
uint16_t newHeight,
uint16_t yOffset )
nodiscard

Crops the given image to the new dimensions. If the image format is compressed it will be converted to its container format before the crop, and converted back before returning.

Definition at line 2102 of file ImageConversion.cpp.

◆ decompressBGRA8888HDR()

std::vector< std::byte > vtfpp::ImageConversion::decompressBGRA8888HDR ( std::span< const std::byte > imageData,
float overbrightFactor = 16.f )
nodiscard

Takes in SOURCEPP_BGRA8888_HDR compressed HDR image data (alias for BGRA8888), returns RGBA32323232F format image data.

Definition at line 1085 of file ImageConversion.cpp.

◆ decompressRGBA16161616HDR()

std::vector< std::byte > vtfpp::ImageConversion::decompressRGBA16161616HDR ( std::span< const std::byte > imageData,
bool flipExponentAndSignificand = false )
nodiscard

Takes in SOURCEPP_RGBA16161616_HDR compressed HDR image data (alias for RGBA16161616), returns RGBA32323232F format image data.

Definition at line 1128 of file ImageConversion.cpp.

◆ gammaCorrectImageData()

void vtfpp::ImageConversion::gammaCorrectImageData ( std::span< std::byte > imageData,
ImageFormat format,
uint16_t width,
uint16_t height,
float gamma )

Perform gamma correction on the given image data. Will not perform gamma correction if the input image format is large, console, P8, A8, UV88, UVLX8888, or UVWQ8888.

Definition at line 2158 of file ImageConversion.cpp.

◆ getDefaultFileFormatForImageFormat()

ImageConversion::FileFormat vtfpp::ImageConversion::getDefaultFileFormatForImageFormat ( ImageFormat format)
nodiscard

PNG for integer formats, EXR for floating point formats (or HDR if EXR support is disabled).

Definition at line 1151 of file ImageConversion.cpp.

◆ getResizedDim()

uint16_t vtfpp::ImageConversion::getResizedDim ( uint16_t n,
ResizeMethod method )
nodiscard

Get the new image size given a resize method.

Definition at line 2000 of file ImageConversion.cpp.

◆ hableTonemapImageData()

void vtfpp::ImageConversion::hableTonemapImageData ( std::span< std::byte > imageData,
ImageFormat format,
uint16_t width,
uint16_t height )

Perform Hable tonemapping on the given image data.

Definition at line 2332 of file ImageConversion.cpp.

◆ invertGreenChannelForImageData()

void vtfpp::ImageConversion::invertGreenChannelForImageData ( std::span< std::byte > imageData,
ImageFormat format,
uint16_t width,
uint16_t height )

Invert the green channel on the given image data. Meant for converting normal maps between OpenGL and DirectX formats.

Definition at line 2252 of file ImageConversion.cpp.

◆ padImageData()

std::vector< std::byte > vtfpp::ImageConversion::padImageData ( std::span< const std::byte > imageData,
ImageFormat format,
uint16_t width,
uint16_t widthPad,
uint16_t height,
uint16_t heightPad )
nodiscard

Pad the given image with pixels that are the same color as the edge. Padding is applied to the right and bottom of the image.

Definition at line 2121 of file ImageConversion.cpp.

◆ resizeImageData()

std::vector< std::byte > vtfpp::ImageConversion::resizeImageData ( std::span< const std::byte > imageData,
ImageFormat format,
uint16_t width,
uint16_t newWidth,
uint16_t height,
uint16_t newHeight,
bool srgb,
ResizeFilter filter,
ResizeEdge edge = ResizeEdge::CLAMP )
nodiscard

Resize given image data to the new dimensions.

Definition at line 2015 of file ImageConversion.cpp.

◆ resizeImageDataStrict()

std::vector< std::byte > vtfpp::ImageConversion::resizeImageDataStrict ( std::span< const std::byte > imageData,
ImageFormat format,
uint16_t width,
uint16_t newWidth,
uint16_t & widthOut,
ResizeMethod widthResize,
uint16_t height,
uint16_t newHeight,
uint16_t & heightOut,
ResizeMethod heightResize,
bool srgb,
ResizeFilter filter,
ResizeEdge edge = ResizeEdge::CLAMP )
nodiscard

Resize given image data to the new dimensions, where the new width and height are governed by the resize methods.

Definition at line 2092 of file ImageConversion.cpp.

◆ setResizedDims()

void vtfpp::ImageConversion::setResizedDims ( uint16_t & width,
ResizeMethod widthResize,
uint16_t & height,
ResizeMethod heightResize )

Set the new image dimensions given a resize method.

Definition at line 2010 of file ImageConversion.cpp.

Variable Documentation

◆ DEFAULT_COMPRESSED_QUALITY

float vtfpp::ImageConversion::DEFAULT_COMPRESSED_QUALITY = -1.f
constexpr

Definition at line 17 of file ImageConversion.h.