1 #ifndef DONUT_GRAPHICS_IMAGE_HPP
2 #define DONUT_GRAPHICS_IMAGE_HPP
65 , pixelFormat(pixelFormat)
66 , pixelComponentType(pixelComponentType) {
75 explicit operator bool() const noexcept {
76 return static_cast<bool>(pixels);
88 [[nodiscard]] constexpr std::size_t
getWidth() const noexcept {
101 [[nodiscard]] constexpr std::size_t
getHeight() const noexcept {
126 return pixelComponentType;
157 [[nodiscard]] constexpr
const void*
getPixels() const noexcept {
173 switch (pixelFormat) {
195 switch (pixelComponentType) {
234 const void* pixels =
nullptr;
235 std::size_t width = 0;
236 std::size_t height = 0;
546 explicit operator bool() const noexcept {
547 return static_cast<bool>(pixels);
577 [[nodiscard]] std::size_t
getWidth() const noexcept {
615 return pixelComponentType;
710 struct PixelsDeleter {
711 void operator()(
void* handle)
const noexcept;
715 std::size_t width = 0;
716 std::size_t height = 0;
Persistent system for managing the virtual filesystem.
Definition: Filesystem.hpp:185
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:40
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:215
constexpr PixelFormat getPixelFormat() const noexcept
Get the pixel format of the image referenced by this view.
Definition: Image.hpp:113
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:193
constexpr std::size_t getHeight() const noexcept
Get the height of the image referenced by this view.
Definition: Image.hpp:101
constexpr const void * getPixels() const noexcept
Get the pixel data referenced by this view.
Definition: Image.hpp:157
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:171
constexpr std::size_t getSizeInBytes() const noexcept
Get the size in bytes of the image referenced by this view.
Definition: Image.hpp:229
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:88
constexpr PixelComponentType getPixelComponentType() const noexcept
Get the pixel component type of the image referenced by this view.
Definition: Image.hpp:125
Container for a 2D image.
Definition: Image.hpp:359
PixelComponentType getPixelComponentType() const noexcept
Get the pixel component type of the image.
Definition: Image.hpp:614
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:577
const void * getPixels() const noexcept
Get the pixel data of this image.
Definition: Image.hpp:652
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:602
std::size_t getSizeInBytes() const noexcept
Get the size in bytes of this image.
Definition: Image.hpp:705
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:677
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.
std::size_t getPixelStride() const noexcept
Get the stride in bytes of the pixels in this image.
Definition: Image.hpp:691
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:564
std::size_t getHeight() const noexcept
Get the height of the image.
Definition: Image.hpp:590
std::size_t getChannelCount() const noexcept
Get the number of component channels in the pixel format of this image.
Definition: Image.hpp:664
void * getPixels() noexcept
Get the pixel data of this image.
Definition: Image.hpp:633
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:29
@ 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:19
@ 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:329
bool flipVertically
Flip the loaded image vertically.
Definition: Image.hpp:351
bool highDynamicRange
Load and store the image with high dynamic range.
Definition: Image.hpp:346
std::optional< PixelFormat > desiredFormat
If set, request the loaded image to be converted to this format.
Definition: Image.hpp:333
Options for saving an image in Windows Bitmap format.
Definition: Image.hpp:263
bool flipVertically
Flip the saved image vertically.
Definition: Image.hpp:267
Options for saving an image in Radiance HDR RGBE format.
Definition: Image.hpp:309
bool flipVertically
Flip the saved image vertically.
Definition: Image.hpp:313
Options for saving an image in JPEG format.
Definition: Image.hpp:291
bool flipVertically
Flip the saved image vertically.
Definition: Image.hpp:303
int quality
JPEG quality.
Definition: Image.hpp:298
Options for saving an image in any format.
Definition: Image.hpp:319
bool flipVertically
Flip the saved image vertically.
Definition: Image.hpp:323
Options for saving an image in PNG format.
Definition: Image.hpp:244
bool flipVertically
Flip the saved image vertically.
Definition: Image.hpp:257
int compressionLevel
PNG compression level.
Definition: Image.hpp:252
Options for saving an image in Truevision TARGA format.
Definition: Image.hpp:273
bool useRleCompression
Use run-length encoding to compress the image.
Definition: Image.hpp:280
bool flipVertically
Flip the saved image vertically.
Definition: Image.hpp:285