MXVK Vulkan Framework 0.24.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
mxvk_jpeg.hpp
Go to the documentation of this file.
1/**
2 * @file mxvk_jpeg.hpp
3 * @brief JPEG image loading and saving utilities.
4 */
5#pragma once
6
7#if defined(MXVK_WITH_JPEG) || defined(WITH_JPEG)
8
9#include <SDL3/SDL.h>
10
11namespace mxvk {
12
13 /**
14 * @class VK_JPEG
15 * @brief Static JPEG utility helpers for SDL surfaces and textures.
16 */
17 class VK_JPEG {
18 public:
19 /**
20 * @brief Load a JPEG file into an SDL surface.
21 * @param filename Path to the JPEG file.
22 * @return Newly allocated `SDL_Surface`, or `nullptr` on failure.
23 */
24 static SDL_Surface *Load(const char *filename);
25
26 /**
27 * @brief Save an SDL texture as a JPEG file.
28 * @param texture Source texture.
29 * @param renderer Renderer used to read back texture pixels.
30 * @param filename Destination file path.
31 * @param quality JPEG quality in range [0, 100].
32 * @return `true` on success, `false` on failure.
33 */
34 static bool SaveTexture(SDL_Texture *texture, SDL_Renderer *renderer, const char *filename, int quality = 90);
35
36 /**
37 * @brief Save an SDL surface as a JPEG file.
38 * @param surface Source surface.
39 * @param filename Destination file path.
40 * @param quality JPEG quality in range [0, 100].
41 * @return `true` on success, `false` on failure.
42 */
43 static bool SaveSurface(const SDL_Surface *surface, const char *filename, int quality = 90);
44 };
45
46 // Backward-compatible free-function wrappers.
47 SDL_Surface *LoadJPEG(const char *filename);
48 bool SaveJPEG(SDL_Texture *texture, SDL_Renderer *renderer, const char *filename, int quality = 90);
49
50} // namespace mxvk
51
52namespace jpeg {
53 // Legacy namespace compatibility.
54 inline SDL_Surface *LoadJPEG(const char *filename) {
55 return mxvk::VK_JPEG::Load(filename);
56 }
57
58 inline bool SaveJPEG(SDL_Renderer *renderer, SDL_Texture *texture, const char *filename, int quality = 90) {
59 return mxvk::VK_JPEG::SaveTexture(texture, renderer, filename, quality);
60 }
61} // namespace jpeg
62
63#endif
Utilities for loading and saving PNG images.
Definition mxvk.hpp:30