NvDialog 0.10.1
A cross-platform modal dialogs library for C/C++ that uses the native OS theme.
Loading...
Searching...
No Matches
nvdialog_image.h
Go to the documentation of this file.
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2025 Aggelos Tselios
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
25#pragma once
26
27
28#ifndef __nvdialog_image_h__
29#define __nvdialog_image_h__ 1
30
31#include <stddef.h>
32#include <stdint.h>
33#include "nvdialog_platform.h"
34
35#ifdef __cplusplus
36extern "C" {
37#endif /* __cplusplus */
38
39/**
40 * @brief Data that can be interpeted as an image.
41 *
42 * The data format is RGBA for library-wide compatibility
43 * across various operating systems. Other formats are supported
44 * and automatically converted.
45 *
46 * @note Using image functionality does not require @ref nvd_init, although
47 * doing anything useful with the image probably does. This may come in handy if
48 * you wish to load images early on and use them later, possibly caching them in
49 * memory.
50 *
51 * @ingroup Image
52 * @since v0.9.0
53 */
54typedef struct _NvdImage NvdImage;
55
56/**
57 * @brief
58 *
59 * @param filename The path to the file to be loaded. For best compatibility,
60 * provide a full path or use @ref NvdFileDialog
61 * @param width A pointer to a variable to hold the width of the image
62 * @param height A pointer to a variable to hold the height of the image
63 * @ingroup Image
64 * @since v0.9.0
65 * @return A pointer to dynamically allocated image data. The returned pointer
66 * must not be freed manually; Instead use @ref nvd_destroy_image.
67 */
68NVD_API const uint8_t *nvd_image_from_filename(const char *filename, int *width,
69 int *height);
70
71/**
72 * @brief Creates an `NvdImage` from the given buffer (data).
73 * Although recommended, it is not necessary to use @ref nvd_image_from_filename
74 * since other libraries can also provide RGBA data.
75 * @warning As described in the @ref NvdImage documentation, the pointer provided in @ref data MUST be in RGBA format. Not using @ref nvd_image_from_filename carries the additional burden of ensuring this manually.
76 * @param data The data to use as the image
77 * @param width The width of the image
78 * @param height The height of the image
79 * @ingroup Image
80 * @return NvdImage* A pointer to an `NvdImage` object.
81 */
82NVD_API NvdImage *nvd_create_image(const uint8_t *data, int width, int height);
83
84/**
85 * @brief Destroys an @ref NvdImage.
86 * @param image The image to destroy
87 * @ingroup Image
88 * @since v0.9.0
89 */
91
92/**
93 * @brief Returns the raw image bytes that the given image contains
94 * @note Format, as with every @ref NvdImage, is always RGBA.
95 * @param image The image to get the bytes from
96 * @ingroup Image
97 * @since v0.10.1
98 */
100
101#ifdef __cplusplus
102}
103#endif /* __cplusplus */
104
105#endif /* __nvdialog_image_h__ */
NVD_API NvdImage * nvd_create_image(const uint8_t *data, int width, int height)
Creates an NvdImage from the given buffer (data). Although recommended, it is not necessary to use nv...
NVD_API uint8_t * nvd_image_to_bytes(NvdImage *image)
Returns the raw image bytes that the given image contains.
NVD_API const uint8_t * nvd_image_from_filename(const char *filename, int *width, int *height)
struct _NvdImage NvdImage
Data that can be interpeted as an image.
Definition: nvdialog_image.h:54
NVD_API void nvd_destroy_image(NvdImage *image)
Destroys an NvdImage.
#define NVD_API
Definition: nvdialog_platform.h:57