SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Loading...
Searching...
No Matches
ImageConversion.h File Reference
#include <array>
#include <concepts>
#include <cstddef>
#include <span>
#include <vector>
#include <BufferStream.h>
#include <sourcepp/Templates.h>
#include "ImageFormats.h"
Include dependency graph for ImageConversion.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  vtfpp::ImagePixel::RGBA8888
 
struct  vtfpp::ImagePixel::ABGR8888
 
struct  vtfpp::ImagePixel::RGB888
 
struct  vtfpp::ImagePixel::BGR888
 
struct  vtfpp::ImagePixel::RGB565
 
struct  vtfpp::ImagePixel::I8
 
struct  vtfpp::ImagePixel::IA88
 
struct  vtfpp::ImagePixel::P8
 
struct  vtfpp::ImagePixel::A8
 
struct  vtfpp::ImagePixel::ARGB8888
 
struct  vtfpp::ImagePixel::BGRA8888
 
struct  vtfpp::ImagePixel::BGRX8888
 
struct  vtfpp::ImagePixel::BGR565
 
struct  vtfpp::ImagePixel::BGRX5551
 
struct  vtfpp::ImagePixel::BGRA4444
 
struct  vtfpp::ImagePixel::BGRA5551
 
struct  vtfpp::ImagePixel::UV88
 
struct  vtfpp::ImagePixel::UVWQ8888
 
struct  vtfpp::ImagePixel::RGBA16161616F
 
struct  vtfpp::ImagePixel::RGBA16161616
 
struct  vtfpp::ImagePixel::UVLX8888
 
struct  vtfpp::ImagePixel::R32F
 
struct  vtfpp::ImagePixel::RGB323232F
 
struct  vtfpp::ImagePixel::RGBA32323232F
 
struct  vtfpp::ImagePixel::RG1616F
 
struct  vtfpp::ImagePixel::RG3232F
 
struct  vtfpp::ImagePixel::RGBX8888
 
struct  vtfpp::ImagePixel::RGBA1010102
 
struct  vtfpp::ImagePixel::BGRA1010102
 
struct  vtfpp::ImagePixel::R16F
 
struct  vtfpp::ImagePixel::R8
 

Namespaces

namespace  vtfpp
 
namespace  vtfpp::ImagePixel
 
namespace  vtfpp::ImageConversion
 

Concepts

concept  vtfpp::ImagePixel::PixelType
 

Macros

#define VTFPP_CHECK_SIZE(format)    static_assert(sizeof(format) == ImageFormatDetails::bpp(ImageFormat::format) / 8)
 
#define VTFPP_FORMAT_INHERITED(format, parent)
 

Enumerations

enum class  vtfpp::ImageConversion::FileFormat {
  vtfpp::ImageConversion::DEFAULT , vtfpp::ImageConversion::PNG , vtfpp::ImageConversion::JPEG , vtfpp::ImageConversion::BMP ,
  vtfpp::ImageConversion::TGA , vtfpp::ImageConversion::HDR , vtfpp::ImageConversion::EXR
}
 
enum class  vtfpp::ImageConversion::ResizeEdge { vtfpp::ImageConversion::CLAMP = 0 , vtfpp::ImageConversion::REFLECT , vtfpp::ImageConversion::WRAP , vtfpp::ImageConversion::ZERO }
 
enum class  vtfpp::ImageConversion::ResizeFilter {
  vtfpp::ImageConversion::DEFAULT = 0 , vtfpp::ImageConversion::BOX , vtfpp::ImageConversion::BILINEAR , vtfpp::ImageConversion::CUBIC_BSPLINE ,
  vtfpp::ImageConversion::CATMULL_ROM , vtfpp::ImageConversion::MITCHELL , vtfpp::ImageConversion::POINT_SAMPLE , vtfpp::ImageConversion::KAISER = 100
}
 
enum class  vtfpp::ImageConversion::ResizeMethod { vtfpp::ImageConversion::NONE , vtfpp::ImageConversion::POWER_OF_TWO_BIGGER , vtfpp::ImageConversion::POWER_OF_TWO_SMALLER , vtfpp::ImageConversion::POWER_OF_TWO_NEAREST }
 

Functions

 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (RGBA8888)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (ABGR8888)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (RGB888)
 
 vtfpp::ImagePixel::VTFPP_FORMAT_INHERITED (RGB888_BLUESCREEN, RGB888)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (BGR888)
 
 vtfpp::ImagePixel::VTFPP_FORMAT_INHERITED (BGR888_BLUESCREEN, BGR888)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (RGB565)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (I8)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (IA88)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (P8)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (A8)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (ARGB8888)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (BGRA8888)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (BGRX8888)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (BGR565)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (BGRX5551)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (BGRA4444)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (BGRA5551)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (UV88)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (UVWQ8888)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (RGBA16161616F)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (RGBA16161616)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (UVLX8888)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (R32F)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (RGB323232F)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (RGBA32323232F)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (RG1616F)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (RG3232F)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (RGBX8888)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (RGBA1010102)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (BGRA1010102)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (R16F)
 
 vtfpp::ImagePixel::VTFPP_CHECK_SIZE (R8)
 
 vtfpp::ImagePixel::VTFPP_FORMAT_INHERITED (CONSOLE_BGRX8888_LINEAR, BGRX8888)
 
 vtfpp::ImagePixel::VTFPP_FORMAT_INHERITED (CONSOLE_RGBA8888_LINEAR, RGBA8888)
 
 vtfpp::ImagePixel::VTFPP_FORMAT_INHERITED (CONSOLE_ABGR8888_LINEAR, ABGR8888)
 
 vtfpp::ImagePixel::VTFPP_FORMAT_INHERITED (CONSOLE_ARGB8888_LINEAR, ARGB8888)
 
 vtfpp::ImagePixel::VTFPP_FORMAT_INHERITED (CONSOLE_BGRA8888_LINEAR, BGRA8888)
 
 vtfpp::ImagePixel::VTFPP_FORMAT_INHERITED (CONSOLE_RGB888_LINEAR, RGB888)
 
 vtfpp::ImagePixel::VTFPP_FORMAT_INHERITED (CONSOLE_BGR888_LINEAR, BGR888)
 
 vtfpp::ImagePixel::VTFPP_FORMAT_INHERITED (CONSOLE_BGRX5551_LINEAR, BGRX5551)
 
 vtfpp::ImagePixel::VTFPP_FORMAT_INHERITED (CONSOLE_I8_LINEAR, I8)
 
 vtfpp::ImagePixel::VTFPP_FORMAT_INHERITED (CONSOLE_RGBA16161616_LINEAR, RGBA16161616)
 
 vtfpp::ImagePixel::VTFPP_FORMAT_INHERITED (CONSOLE_BGRX8888_LE, BGRX8888)
 
 vtfpp::ImagePixel::VTFPP_FORMAT_INHERITED (CONSOLE_BGRA8888_LE, BGRA8888)
 
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.
 
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.
 
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.
 
FileFormat vtfpp::ImageConversion::getDefaultFileFormatForImageFormat (ImageFormat format)
 PNG for integer formats, EXR for floating point formats.
 
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).
 
std::vector< std::byte > vtfpp::ImageConversion::convertFileToImageData (std::span< const std::byte > fileData, ImageFormat &format, int &width, int &height, int &frameCount)
 
uint16_t vtfpp::ImageConversion::getResizedDim (uint16_t n, ResizeMethod method)
 Get the new image size given a resize method.
 
void vtfpp::ImageConversion::setResizedDims (uint16_t &width, ResizeMethod widthResize, uint16_t &height, ResizeMethod heightResize)
 Set the new image dimensions given a resize method.
 
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.
 
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.
 
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.
 
template<ImagePixel::PixelType P>
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.
 
template<ImagePixel::PixelType P>
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.
 

Macro Definition Documentation

◆ VTFPP_CHECK_SIZE

#define VTFPP_CHECK_SIZE (   format)     static_assert(sizeof(format) == ImageFormatDetails::bpp(ImageFormat::format) / 8)

Definition at line 18 of file ImageConversion.h.

◆ VTFPP_FORMAT_INHERITED

#define VTFPP_FORMAT_INHERITED (   format,
  parent 
)
Value:
struct format : parent { \
static constexpr auto FORMAT = ImageFormat::format; \
}; \
VTFPP_CHECK_SIZE(format)

Definition at line 21 of file ImageConversion.h.