MXVK Vulkan Framework 0.35.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
mxvk_png.hpp
Go to the documentation of this file.
1/**
2 * @file mxvk_png.hpp
3 * @brief PNG image loading and saving utilities via SDL3.
4 */
5#pragma once
6
7#include <SDL3/SDL.h>
8#include <cstddef>
9
10/** @namespace mxvk
11 * @brief Utilities for loading and saving PNG images. */
12namespace mxvk {
13
14 /**
15 * @brief Load a PNG file into an SDL_Surface.
16 * @param file Path to the PNG file.
17 * @return Newly allocated SDL_Surface, or nullptr on failure.
18 */
19 SDL_Surface *LoadPNG(const char *file);
20
21 /**
22 * @brief Save an SDL_Texture to a PNG file.
23 * @param texture Source texture.
24 * @param renderer Renderer used to read back the texture pixels.
25 * @param filename Destination file path.
26 * @param compression_level PNG compression level passed to libpng; 0 favors
27 * speed and 9 favors smaller files. Defaults to 6.
28 * @return @c true on success, @c false on failure.
29 */
30 bool SavePNG(SDL_Texture *texture, SDL_Renderer *renderer, const char *filename, int compression_level = 6);
31
32 /**
33 * @brief Save raw data to a file.
34 * @param filename Output file path
35 * @param buffer Pointer to the source data (read-only)
36 * @param w Width of the image in pixels
37 * @param h Height of the image in pixels
38 * @param bpp Bytes per pixel (e.g., 2 for YUYV, 4 for RGBA)
39 * @return @c true on success, @c false on failure.
40 */
41 bool SaveRawBytes(const char *filename, const void *buffer, size_t w, size_t h, size_t bpp);
42 /**
43 * @brief Save a raw RGBA pixel buffer to a PNG file.
44 * @param filename Destination file path.
45 * @param buffer Pointer to the raw RGBA pixel data.
46 * @param w Image width in pixels.
47 * @param h Image height in pixels.
48 * @param compression_level PNG compression level passed to libpng; 0 favors
49 * speed and 9 favors smaller files. Defaults to 6.
50 * @return @c true on success, @c false on failure.
51 */
52 bool SavePNG_RGBA(const char *filename, void *buffer, int w, int h, int compression_level = 6);
53
54 /**
55 * @brief Save a raw 16-bit RGBA pixel buffer to a PNG file.
56 * @param filename Destination file path.
57 * @param buffer Pointer to the raw 16-bit RGBA pixel data.
58 * @param w Image width in pixels.
59 * @param h Image height in pixels.
60 * @param compression_level PNG compression level passed to libpng; 0 favors
61 * speed and 9 favors smaller files. Defaults to 6.
62 * @return @c true on success, @c false on failure.
63 */
64 bool SavePNG_RGBA16(const char *filename, const void *buffer, int w, int h, int compression_level = 6);
65} // namespace mxvk
Utilities for loading and saving PNG images.
Definition mxvk.hpp:31
bool SavePNG_RGBA16(const char *filename, const void *buffer, int w, int h, int compression_level=6)
Save a raw 16-bit RGBA pixel buffer to a PNG file.
Definition mxvk_png.cpp:284
bool SavePNG_RGBA(const char *filename, void *buffer, int w, int h, int compression_level=6)
Save a raw RGBA pixel buffer to a PNG file.
Definition mxvk_png.cpp:279
SDL_Surface * LoadPNG(const char *file)
Load a PNG file into an SDL_Surface.
Definition mxvk_png.cpp:89
bool SaveRawBytes(const char *filename, const void *buffer, size_t w, size_t h, size_t bpp)
Save raw data to a file.
Definition mxvk_png.cpp:244
bool SavePNG(SDL_Texture *texture, SDL_Renderer *renderer, const char *filename, int compression_level=6)
Save an SDL_Texture to a PNG file.
Definition mxvk_png.cpp:185