Kore
Loading...
Searching...
No Matches
image.h File Reference

Functionality for creating and loading images. Image loading supports PNG, JPEG and the custom K format. K files can contain image data that uses texture-compression (see kinc_image_compression). More...

#include <kinc/global.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  kinc_image
struct  kinc_image_read_callbacks

Typedefs

typedef enum kinc_image_compression kinc_image_compression_t
typedef enum kinc_image_format kinc_image_format_t
typedef struct kinc_image kinc_image_t
typedef struct kinc_image_read_callbacks kinc_image_read_callbacks_t

Enumerations

enum  kinc_image_compression { KINC_IMAGE_COMPRESSION_NONE , KINC_IMAGE_COMPRESSION_DXT5 , KINC_IMAGE_COMPRESSION_ASTC , KINC_IMAGE_COMPRESSION_PVRTC }
enum  kinc_image_format {
  KINC_IMAGE_FORMAT_RGBA32 , KINC_IMAGE_FORMAT_GREY8 , KINC_IMAGE_FORMAT_RGB24 , KINC_IMAGE_FORMAT_RGBA128 ,
  KINC_IMAGE_FORMAT_RGBA64 , KINC_IMAGE_FORMAT_A32 , KINC_IMAGE_FORMAT_BGRA32 , KINC_IMAGE_FORMAT_A16 ,
  KINC_IMAGE_FORMAT_RGBA64U
}

Functions

KINC_FUNC size_t kinc_image_init (kinc_image_t *image, void *memory, int width, int height, kinc_image_format_t format)
 Creates a 2D kinc_image in the provided memory.
KINC_FUNC size_t kinc_image_init3d (kinc_image_t *image, void *memory, int width, int height, int depth, kinc_image_format_t format)
 Creates a 3D kinc_image in the provided memory.
KINC_FUNC size_t kinc_image_size_from_file (const char *filename)
 Peeks into an image file and figures out the size it will occupy in memory.
KINC_FUNC size_t kinc_image_size_from_callbacks (kinc_image_read_callbacks_t 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 memory.
KINC_FUNC size_t kinc_image_size_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 once it is uncompressed.
KINC_FUNC size_t kinc_image_init_from_file (kinc_image_t *image, void *memory, const char *filename)
 Loads an image from a file.
KINC_FUNC size_t kinc_image_init_from_file_with_stride (kinc_image_t *image, void *memory, const char *filename, uint32_t stride)
 Loads an image from a file with an enforced stride.
KINC_FUNC size_t kinc_image_init_from_callbacks (kinc_image_t *image, void *memory, kinc_image_read_callbacks_t callbacks, void *user_data, const char *format)
 Loads an image file using callbacks.
KINC_FUNC size_t kinc_image_init_from_callbacks_with_stride (kinc_image_t *image, void *memory, kinc_image_read_callbacks_t callbacks, void *user_data, const char *format, uint32_t stride)
 Loads an image file using callbacks with an enforced stride.
KINC_FUNC size_t kinc_image_init_from_encoded_bytes (kinc_image_t *image, void *memory, void *data, size_t data_size, const char *format)
 Loads an image file from memory.
KINC_FUNC size_t kinc_image_init_from_encoded_bytes_with_stride (kinc_image_t *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.
KINC_FUNC void kinc_image_init_from_bytes (kinc_image_t *image, void *data, int width, int height, kinc_image_format_t format)
 Creates a 2D image from memory.
KINC_FUNC void kinc_image_init_from_bytes3d (kinc_image_t *image, void *data, int width, int height, int depth, kinc_image_format_t format)
 Creates a 3D image from memory.
KINC_FUNC void kinc_image_destroy (kinc_image_t *image)
 Destroys an image. This does not free the user-provided memory.
KINC_FUNC uint32_t kinc_image_at (kinc_image_t *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 kinc_image_at_raw instead.
KINC_FUNC void * kinc_image_at_raw (kinc_image_t *image, int x, int y)
 Gets a pointer to the color-data of one pixel.
KINC_FUNC uint8_t * kinc_image_get_pixels (kinc_image_t *image)
 Provides access to the image data.
KINC_FUNC int kinc_image_format_sizeof (kinc_image_format_t format)
 Gets the size in bytes of a single pixel for a given image format.

Detailed Description

Functionality for creating and loading images. Image loading supports PNG, JPEG and the custom K format. K files can contain image data that uses texture-compression (see kinc_image_compression).

Function Documentation

◆ kinc_image_at()

KINC_FUNC uint32_t kinc_image_at ( kinc_image_t * 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 kinc_image_at_raw instead.

Returns
One 32 bit color value

◆ kinc_image_at_raw()

KINC_FUNC void * kinc_image_at_raw ( kinc_image_t * image,
int x,
int y )

Gets a pointer to the color-data of one pixel.

Returns
A pointer to the color-data of the pixel pointed to by x and y

◆ kinc_image_format_sizeof()

KINC_FUNC int kinc_image_format_sizeof ( kinc_image_format_t format)

Gets the size in bytes of a single pixel for a given image format.

Returns
The size of one pixel in bytes

◆ kinc_image_get_pixels()

KINC_FUNC uint8_t * kinc_image_get_pixels ( kinc_image_t * image)

Provides access to the image data.

Returns
A pointer to the image data

◆ kinc_image_init()

KINC_FUNC size_t kinc_image_init ( kinc_image_t * image,
void * memory,
int width,
int height,
kinc_image_format_t format )

Creates a 2D kinc_image in the provided memory.

Returns
The size that's occupied by the image in memory in bytes

◆ kinc_image_init3d()

KINC_FUNC size_t kinc_image_init3d ( kinc_image_t * image,
void * memory,
int width,
int height,
int depth,
kinc_image_format_t format )

Creates a 3D kinc_image in the provided memory.

Returns
The size that's occupied by the image in memory in bytes

◆ kinc_image_init_from_callbacks()

KINC_FUNC size_t kinc_image_init_from_callbacks ( kinc_image_t * image,
void * memory,
kinc_image_read_callbacks_t callbacks,
void * user_data,
const char * format )

Loads an image file using callbacks.

Parameters
imageThe image-object to initialize with the data
memoryThe pre-allocated memory to load the image-data into
callbacksThe callbacks that are used to query the data to encode
user_dataAn optional pointer that is passed to the callbacks
Returns
The memory size in bytes that will be used when loading the image

◆ kinc_image_init_from_callbacks_with_stride()

KINC_FUNC size_t kinc_image_init_from_callbacks_with_stride ( kinc_image_t * image,
void * memory,
kinc_image_read_callbacks_t callbacks,
void * user_data,
const char * format,
uint32_t stride )

Loads an image file using callbacks with an enforced stride.

Parameters
imageThe image-object to initialize with the data
memoryThe pre-allocated memory to load the image-data into
callbacksThe callbacks that are used to query the data to encode
user_dataAn optional pointer that is passed to the callbacks
strideThe enforced stride in bytes
Returns
The memory size in bytes that will be used when loading the image

◆ kinc_image_init_from_encoded_bytes()

KINC_FUNC size_t kinc_image_init_from_encoded_bytes ( kinc_image_t * image,
void * memory,
void * data,
size_t data_size,
const char * format )

Loads an image file from memory.

Parameters
imageThe image-object to initialize with the data
memoryThe pre-allocated memory to load the image-data into
dataThe data to encode
data_sizeThe size of the data to encode in bytes
Returns
The memory size in bytes that will be used when loading the image

◆ kinc_image_init_from_encoded_bytes_with_stride()

KINC_FUNC size_t kinc_image_init_from_encoded_bytes_with_stride ( kinc_image_t * 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.

Parameters
imageThe image-object to initialize with the data
memoryThe pre-allocated memory to load the image-data into
dataThe data to encode
data_sizeThe size of the data to encode in bytes
strideThe enforced stride in bytes
Returns
The memory size in bytes that will be used when loading the image

◆ kinc_image_init_from_file()

KINC_FUNC size_t kinc_image_init_from_file ( kinc_image_t * image,
void * memory,
const char * filename )

Loads an image from a file.

Parameters
imageThe image-object to initialize with the data
memoryThe pre-allocated memory to load the image-data into
filenameThe file to load
Returns
The memory size in bytes that will be used when loading the image

◆ kinc_image_init_from_file_with_stride()

KINC_FUNC size_t kinc_image_init_from_file_with_stride ( kinc_image_t * image,
void * memory,
const char * filename,
uint32_t stride )

Loads an image from a file with an enforced stride.

Parameters
imageThe image-object to initialize with the data
memoryThe pre-allocated memory to load the image-data into
filenameThe file to load
strideThe enforced stride in bytes
Returns
The memory size in bytes that will be used when loading the image

◆ kinc_image_size_from_callbacks()

KINC_FUNC size_t kinc_image_size_from_callbacks ( kinc_image_read_callbacks_t 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 memory.

Returns
The memory size in bytes that will be used when loading the image

◆ kinc_image_size_from_encoded_bytes()

KINC_FUNC size_t kinc_image_size_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 once it is uncompressed.

Parameters
dataThe encoded data
data_sizeThe size of the encoded data
format_hintSomething like "png" can help, it also works to just put in the filename
Returns
The memory size in bytes that will be used when loading the image

◆ kinc_image_size_from_file()

KINC_FUNC size_t kinc_image_size_from_file ( const char * filename)

Peeks into an image file and figures out the size it will occupy in memory.

Returns
The memory size in bytes that will be used when loading the image