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#include "nvdialog_types.h"
35
36
37/**
38 * @brief Data that can be interpeted as an image.
39 *
40 * The data format is RGBA for library-wide compatibility
41 * across various operating systems. Other formats are supported
42 * and automatically converted.
43 *
44 * @note Using image functionality does not require @ref nvd_init, although
45 * doing anything useful with the image probably does. This may come in handy if
46 * you wish to load images early on and use them later, possibly caching them in
47 * memory.
48 *
49 * @ingroup Image
50 * @since v0.9.0
51 */
52typedef struct _NvdImage NvdImage;
53
54/**
55 * @brief
56 *
57 * @param filename The path to the file to be loaded. For best compatibility,
58 * provide a full path or use @ref NvdFileDialog
59 * @param width A pointer to a variable to hold the width of the image
60 * @param height A pointer to a variable to hold the height of the image
61 * @ingroup Image
62 * @since v0.9.0
63 * @return A pointer to dynamically allocated image data. The returned pointer
64 * must not be freed manually; Instead use @ref nvd_destroy_image.
65 */
66NVD_API const uint8_t *nvd_image_from_filename(const char *filename, int *width,
67 int *height);
68
69/**
70 * @brief Creates an `NvdImage` from the given buffer (data).
71 * Although recommended, it is not necessary to use @ref nvd_image_from_filename
72 * since other libraries can also provide RGBA data.
73 * @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.
74 * @param data The data to use as the image
75 * @param width The width of the image
76 * @param height The height of the image
77 * @ingroup Image
78 * @return NvdImage* A pointer to an `NvdImage` object.
79 */
80NVD_API NvdImage *nvd_create_image(const uint8_t *data, int width, int height);
81
82/**
83 * @brief Destroys an @ref NvdImage.
84 * @param image The image to destroy
85 * @ingroup Image
86 * @since v0.9.0
87 */
89
90/**
91 * @brief Returns the raw image bytes that the given image contains
92 * @note Format, as with every @ref NvdImage, is always RGBA.
93 * @param image The image to get the bytes from
94 * @ingroup Image
95 * @since v0.10.1
96 */
98
99#endif /* __nvdialog_image_h__ */
#define NVD_API
Definition nvdialog.h:113
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:52
NVD_API void nvd_destroy_image(NvdImage *image)
Destroys an NvdImage.