1#ifndef DONUT_GRAPHICS_IMAGE_HPP
2#define DONUT_GRAPHICS_IMAGE_HPP
64 , pixelFormat(pixelFormat)
65 , pixelComponentType(pixelComponentType) {
74 explicit operator bool() const noexcept {
75 return static_cast<bool>(pixels);
87 [[nodiscard]]
constexpr std::size_t
getWidth() const noexcept {
100 [[nodiscard]]
constexpr std::size_t
getHeight() const noexcept {
125 return pixelComponentType;
156 [[nodiscard]]
constexpr const void*
getPixels() const noexcept {
172 switch (pixelFormat) {
194 switch (pixelComponentType) {
233 const void* pixels =
nullptr;
234 std::size_t width = 0;
235 std::size_t height = 0;
545 explicit operator bool() const noexcept {
546 return static_cast<bool>(pixels);
576 [[nodiscard]] std::size_t
getWidth() const noexcept {
614 return pixelComponentType;
709 struct PixelsDeleter {
710 void operator()(
void* handle)
const noexcept;
714 std::size_t width = 0;
715 std::size_t height = 0;
Persistent system for managing the virtual filesystem.
Definition Filesystem.hpp:185
Generic nullable RAII resource handle with exclusive ownership of a resource that is automatically de...
Definition UniqueHandle.hpp:21
constexpr Handle get() const noexcept
Get the value of the underlying resource handle.
Definition UniqueHandle.hpp:152
Read-only non-owning view over a 2D image.
Definition Image.hpp:39
constexpr std::size_t getPixelStride() const noexcept
Get the stride in bytes of the pixels in the image referenced by this view.
Definition Image.hpp:214
constexpr PixelFormat getPixelFormat() const noexcept
Get the pixel format of the image referenced by this view.
Definition Image.hpp:112
constexpr std::size_t getPixelComponentSize() const noexcept
Get the size in bytes of a single component of a pixel in the image referenced by this view.
Definition Image.hpp:192
constexpr std::size_t getHeight() const noexcept
Get the height of the image referenced by this view.
Definition Image.hpp:100
constexpr std::size_t getChannelCount() const noexcept
Get the number of component channels in the pixel format of the image referenced by this view.
Definition Image.hpp:170
constexpr std::size_t getSizeInBytes() const noexcept
Get the size in bytes of the image referenced by this view.
Definition Image.hpp:228
constexpr ImageView() noexcept=default
Construct a view that does not reference an image.
constexpr std::size_t getWidth() const noexcept
Get the width of the image referenced by this view.
Definition Image.hpp:87
constexpr const void * getPixels() const noexcept
Get the pixel data referenced by this view.
Definition Image.hpp:156
constexpr PixelComponentType getPixelComponentType() const noexcept
Get the pixel component type of the image referenced by this view.
Definition Image.hpp:124
Container for a 2D image.
Definition Image.hpp:358
PixelComponentType getPixelComponentType() const noexcept
Get the pixel component type of the image.
Definition Image.hpp:613
static void saveHDR(const ImageView &image, Filesystem &filesystem, const char *filepath, const ImageSaveHDROptions &options={})
Save a floating-point 32-bit-per-channel image to a Radiance HDR RGBE file.
std::size_t getWidth() const noexcept
Get the width of the image.
Definition Image.hpp:576
static void saveTGA(const ImageView &image, Filesystem &filesystem, const char *filepath, const ImageSaveTGAOptions &options={})
Save an 8-bit-per-channel image to a Truevision TARGA file.
PixelFormat getPixelFormat() const noexcept
Get the pixel format of the image.
Definition Image.hpp:601
std::size_t getSizeInBytes() const noexcept
Get the size in bytes of this image.
Definition Image.hpp:704
void * getPixels() noexcept
Get the pixel data of this image.
Definition Image.hpp:632
static void savePNG(const ImageView &image, Filesystem &filesystem, const char *filepath, const ImageSavePNGOptions &options={})
Save an 8-bit-per-channel image to a PNG file.
std::size_t getPixelComponentSize() const noexcept
Get the size in bytes of a single component of a pixel in this image.
Definition Image.hpp:676
static void saveBMP(const ImageView &image, Filesystem &filesystem, const char *filepath, const ImageSaveBMPOptions &options={})
Save an 8-bit-per-channel image to a Windows Bitmap file.
const void * getPixels() const noexcept
Get the pixel data of this image.
Definition Image.hpp:651
std::size_t getPixelStride() const noexcept
Get the stride in bytes of the pixels in this image.
Definition Image.hpp:690
static void save(const ImageView &image, Filesystem &filesystem, const char *filepath, const ImageSaveOptions &options={})
Save an image to a file.
Image() noexcept=default
Construct an empty image without a value.
void reset() noexcept
Remove the value from this image and reset it to an empty image.
Definition Image.hpp:563
std::size_t getHeight() const noexcept
Get the height of the image.
Definition Image.hpp:589
std::size_t getChannelCount() const noexcept
Get the number of component channels in the pixel format of this image.
Definition Image.hpp:663
static void saveJPG(const ImageView &image, Filesystem &filesystem, const char *filepath, const ImageSaveJPGOptions &options={})
Save an 8-bit-per-channel image to a JPEG file.
PixelComponentType
Description of the data type of the pixel components of an image.
Definition Image.hpp:28
@ F32
Each pixel component is a 32-bit floating-point number.
@ F16
Each pixel component is a 16-bit floating-point number.
@ U8
Each pixel component is an 8-bit unsigned integer.
PixelFormat
Description of the number and meaning of the pixel component channels of an image.
Definition Image.hpp:18
@ RGB
Each pixel comprises 3 components: red, green, blue.
@ RG
Each pixel comprises 2 components: red, green.
@ R
Each pixel comprises 1 component: red.
@ RGBA
Each pixel comprises 4 components: red, green, blue, alpha.
Options for loading an image.
Definition Image.hpp:328
bool flipVertically
Flip the loaded image vertically.
Definition Image.hpp:350
bool highDynamicRange
Load and store the image with high dynamic range.
Definition Image.hpp:345
std::optional< PixelFormat > desiredFormat
If set, request the loaded image to be converted to this format.
Definition Image.hpp:332
Options for saving an image in Windows Bitmap format.
Definition Image.hpp:262
bool flipVertically
Flip the saved image vertically.
Definition Image.hpp:266
Options for saving an image in Radiance HDR RGBE format.
Definition Image.hpp:308
bool flipVertically
Flip the saved image vertically.
Definition Image.hpp:312
Options for saving an image in JPEG format.
Definition Image.hpp:290
bool flipVertically
Flip the saved image vertically.
Definition Image.hpp:302
int quality
JPEG quality.
Definition Image.hpp:297
Options for saving an image in any format.
Definition Image.hpp:318
bool flipVertically
Flip the saved image vertically.
Definition Image.hpp:322
Options for saving an image in PNG format.
Definition Image.hpp:243
bool flipVertically
Flip the saved image vertically.
Definition Image.hpp:256
int compressionLevel
PNG compression level.
Definition Image.hpp:251
Options for saving an image in Truevision TARGA format.
Definition Image.hpp:272
bool useRleCompression
Use run-length encoding to compress the image.
Definition Image.hpp:279
bool flipVertically
Flip the saved image vertically.
Definition Image.hpp:284