![]() |
SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
|
Enumerations | |
enum class | FileFormat { DEFAULT , PNG , JPEG , BMP , TGA , HDR , EXR } |
enum class | ResizeEdge { CLAMP = 0 , REFLECT , WRAP , ZERO } |
enum class | ResizeFilter { DEFAULT = 0 , BOX , BILINEAR , CUBIC_BSPLINE , CATMULL_ROM , MITCHELL , POINT_SAMPLE , KAISER = 100 } |
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) |
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 sliceCount) |
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) |
Converts an HDRI into a cubemap. | |
FileFormat | getDefaultFileFormatForImageFormat (ImageFormat format) |
PNG for integer formats, EXR for floating point formats. | |
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. | |
template<ImagePixel::PixelType P> | |
std::vector< std::byte > | extractChannelFromImageData (std::span< const std::byte > imageData, auto P::*channel) |
Extracts a single channel from the given image data. | |
template<ImagePixel::PixelType P> | |
bool | applyChannelToImageData (std::span< std::byte > imageData, std::span< const std::byte > channelData, auto P::*channel) |
Applies a single channel to the given image data. | |
|
strong |
Enumerator | |
---|---|
DEFAULT | |
PNG | |
JPEG | |
BMP | |
TGA | |
HDR | |
EXR |
Definition at line 339 of file ImageConversion.h.
|
strong |
Enumerator | |
---|---|
CLAMP | |
REFLECT | |
WRAP | |
ZERO |
Definition at line 357 of file ImageConversion.h.
|
strong |
Enumerator | |
---|---|
DEFAULT | |
BOX | |
BILINEAR | |
CUBIC_BSPLINE | |
CATMULL_ROM | |
MITCHELL | |
POINT_SAMPLE | |
KAISER |
Definition at line 365 of file ImageConversion.h.
|
strong |
Enumerator | |
---|---|
NONE | |
POWER_OF_TWO_BIGGER | |
POWER_OF_TWO_SMALLER | |
POWER_OF_TWO_NEAREST |
Definition at line 379 of file ImageConversion.h.
bool vtfpp::ImageConversion::applyChannelToImageData | ( | std::span< std::byte > | imageData, |
std::span< const std::byte > | channelData, | ||
auto P::* | channel | ||
) |
Applies a single channel to the given image data.
May have unexpected behavior if called on formats that use bitfields like BGRA5551! Data is packed according to pixel channel C++ type size (e.g. in the case of BGRA5551's green channel, it'll be 2 bytes per green value despite only 5 bits being used in the original data)
Definition at line 427 of file ImageConversion.h.
std::vector< std::byte > vtfpp::ImageConversion::convertFileToImageData | ( | std::span< const std::byte > | fileData, |
ImageFormat & | format, | ||
int & | width, | ||
int & | height, | ||
int & | frameCount | ||
) |
Definition at line 1351 of file ImageConversion.cpp.
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 |
||
) |
Converts an HDRI into a cubemap.
The output image data is in the same image format as the input. The output images have the following order: front, back, left, right, down, up. 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 1019 of file ImageConversion.cpp.
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 |
||
) |
Converts image data to the given file format (PNG or EXR by default).
Definition at line 1140 of file ImageConversion.cpp.
std::vector< std::byte > vtfpp::ImageConversion::convertImageDataToFormat | ( | std::span< const std::byte > | imageData, |
ImageFormat | oldFormat, | ||
ImageFormat | newFormat, | ||
uint16_t | width, | ||
uint16_t | height | ||
) |
Converts an image from one format to another.
Definition at line 916 of file ImageConversion.cpp.
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 | sliceCount | ||
) |
Converts several images from one format to another.
Definition at line 992 of file ImageConversion.cpp.
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 | ||
) |
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 1916 of file ImageConversion.cpp.
std::vector< std::byte > vtfpp::ImageConversion::extractChannelFromImageData | ( | std::span< const std::byte > | imageData, |
auto P::* | channel | ||
) |
Extracts a single channel from the given image data.
May have unexpected behavior if called on formats that use bitfields like BGRA5551! Data is packed according to pixel channel C++ type size (e.g. in the case of BGRA5551's green channel, it'll be 2 bytes per green value despite only 5 bits being used in the original data)
Definition at line 406 of file ImageConversion.h.
ImageConversion::FileFormat vtfpp::ImageConversion::getDefaultFileFormatForImageFormat | ( | ImageFormat | format | ) |
PNG for integer formats, EXR for floating point formats.
Definition at line 1135 of file ImageConversion.cpp.
uint16_t vtfpp::ImageConversion::getResizedDim | ( | uint16_t | n, |
ResizeMethod | method | ||
) |
Get the new image size given a resize method.
Definition at line 1827 of file ImageConversion.cpp.
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 |
||
) |
Resize given image data to the new dimensions.
Definition at line 1842 of file ImageConversion.cpp.
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 |
||
) |
Resize given image data to the new dimensions, where the new width and height are governed by the resize methods.
Definition at line 1906 of file ImageConversion.cpp.
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 1837 of file ImageConversion.cpp.