Kore 3
Loading...
Searching...
No Matches
image.h
Go to the documentation of this file.
1#ifndef KORE_IMAGE_HEADER
2#define KORE_IMAGE_HEADER
3
4#include <kore3/global.h>
5
6#include <stdbool.h>
7#include <stddef.h>
8#include <stdint.h>
9
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19typedef enum kore_image_compression {
20 KORE_IMAGE_COMPRESSION_NONE,
21 KORE_IMAGE_COMPRESSION_DXT5,
22 KORE_IMAGE_COMPRESSION_ASTC,
23 KORE_IMAGE_COMPRESSION_PVRTC
24} kore_image_compression;
25
26typedef enum kore_image_format {
27 KORE_IMAGE_FORMAT_RGBA32,
28 KORE_IMAGE_FORMAT_GREY8,
29 KORE_IMAGE_FORMAT_RGB24,
30 KORE_IMAGE_FORMAT_RGBA128,
31 KORE_IMAGE_FORMAT_RGBA64,
32 KORE_IMAGE_FORMAT_A32,
33 KORE_IMAGE_FORMAT_BGRA32,
34 KORE_IMAGE_FORMAT_A16
35} kore_image_format;
36
37typedef struct kore_image {
38 int width, height, depth;
39 kore_image_format format;
40 unsigned internal_format;
41 kore_image_compression compression;
42 void *data;
43 size_t data_size;
45
47 size_t (*read)(void *user_data, void *data, size_t size);
48 void (*seek)(void *user_data, size_t pos);
49 size_t (*pos)(void *user_data);
50 size_t (*size)(void *user_data);
52
53typedef struct kore_image_info {
54 uint32_t width;
55 uint32_t height;
56 size_t data_size;
58
63KORE_FUNC size_t kore_image_init(kore_image *image, void *memory, int width, int height, kore_image_format format);
64
69KORE_FUNC size_t kore_image_init3d(kore_image *image, void *memory, int width, int height, int depth, kore_image_format format);
70
75KORE_FUNC kore_image_info kore_image_info_from_file(const char *filename);
76
81KORE_FUNC kore_image_info kore_image_info_from_callbacks(kore_image_read_callbacks callbacks, void *user_data, const char *format);
82
90KORE_FUNC kore_image_info kore_image_info_from_encoded_bytes(void *data, size_t data_size, const char *format_hint);
91
99KORE_FUNC size_t kore_image_init_from_file(kore_image *image, void *memory, const char *filename);
100
109KORE_FUNC size_t kore_image_init_from_file_with_stride(kore_image *image, void *memory, const char *filename, uint32_t stride);
110
119KORE_FUNC size_t kore_image_init_from_callbacks(kore_image *image, void *memory, kore_image_read_callbacks callbacks, void *user_data, const char *format);
120
130KORE_FUNC size_t kore_image_init_from_callbacks_with_stride(kore_image *image, void *memory, kore_image_read_callbacks callbacks, void *user_data,
131 const char *format, uint32_t stride);
132
141KORE_FUNC size_t kore_image_init_from_encoded_bytes(kore_image *image, void *memory, void *data, size_t data_size, const char *format);
142
152KORE_FUNC size_t kore_image_init_from_encoded_bytes_with_stride(kore_image *image, void *memory, void *data, size_t data_size, const char *format,
153 uint32_t stride);
154
158KORE_FUNC void kore_image_init_from_bytes(kore_image *image, void *data, int width, int height, kore_image_format format);
159
163KORE_FUNC void kore_image_init_from_bytes3d(kore_image *image, void *data, int width, int height, int depth, kore_image_format format);
164
168KORE_FUNC void kore_image_destroy(kore_image *image);
169
174KORE_FUNC uint32_t kore_image_at(kore_image *image, int x, int y);
175
180KORE_FUNC void *kore_image_at_raw(kore_image *image, int x, int y);
181
186KORE_FUNC uint8_t *kore_image_get_pixels(kore_image *image);
187
192KORE_FUNC int kore_image_format_sizeof(kore_image_format format);
193
194#ifdef __cplusplus
195}
196#endif
197
198#endif
Provides basic functionality that's used all over the place. There's usually no need to manually incl...
KORE_FUNC kore_image_info kore_image_info_from_file(const char *filename)
Peeks into an image file and figures out the size it will occupy in memory.
KORE_FUNC void * kore_image_at_raw(kore_image *image, int x, int y)
Gets a pointer to the color-data of one pixel.
KORE_FUNC size_t kore_image_init_from_callbacks(kore_image *image, void *memory, kore_image_read_callbacks callbacks, void *user_data, const char *format)
Loads an image file using callbacks.
KORE_FUNC kore_image_info kore_image_info_from_callbacks(kore_image_read_callbacks callbacks, void *user_data, const char *format)
Peeks into an image that is loaded via callback functions and figures out the size it will occupy in ...
KORE_FUNC uint32_t kore_image_at(kore_image *image, int x, int y)
Gets the color value of a 32 bit pixel. If this doesn't fit the format of the image please use kore_i...
KORE_FUNC size_t kore_image_init_from_callbacks_with_stride(kore_image *image, void *memory, kore_image_read_callbacks callbacks, void *user_data, const char *format, uint32_t stride)
Loads an image file using callbacks with an enforced stride.
KORE_FUNC size_t kore_image_init(kore_image *image, void *memory, int width, int height, kore_image_format format)
Creates a 2D kore_image in the provided memory.
KORE_FUNC size_t kore_image_init3d(kore_image *image, void *memory, int width, int height, int depth, kore_image_format format)
Creates a 3D kore_image in the provided memory.
KORE_FUNC void kore_image_init_from_bytes3d(kore_image *image, void *data, int width, int height, int depth, kore_image_format format)
Creates a 3D image from memory.
KORE_FUNC size_t kore_image_init_from_file_with_stride(kore_image *image, void *memory, const char *filename, uint32_t stride)
Loads an image from a file with an enforced stride.
KORE_FUNC size_t kore_image_init_from_encoded_bytes_with_stride(kore_image *image, void *memory, void *data, size_t data_size, const char *format, uint32_t stride)
Loads an image file from memory with an enforced stride.
KORE_FUNC void kore_image_init_from_bytes(kore_image *image, void *data, int width, int height, kore_image_format format)
Creates a 2D image from memory.
KORE_FUNC size_t kore_image_init_from_encoded_bytes(kore_image *image, void *memory, void *data, size_t data_size, const char *format)
Loads an image file from memory.
KORE_FUNC int kore_image_format_sizeof(kore_image_format format)
Gets the size in bytes of a single pixel for a given image format.
KORE_FUNC void kore_image_destroy(kore_image *image)
Destroys an image. This does not free the user-provided memory.
KORE_FUNC kore_image_info kore_image_info_from_encoded_bytes(void *data, size_t data_size, const char *format_hint)
Peeks into an image file that resides in memory and figures out the size it will occupy in memory onc...
KORE_FUNC uint8_t * kore_image_get_pixels(kore_image *image)
Provides access to the image data.
KORE_FUNC size_t kore_image_init_from_file(kore_image *image, void *memory, const char *filename)
Loads an image from a file.
Definition image.h:53
Definition image.h:46
Definition image.h:37