Gama C Library
Gama C API Documentation
image.h File Reference
#include "../stb/stb_image.h"
#include <stdint.h>
#include <string.h>
#include "color.h"
#include "gapi.h"

Go to the source code of this file.

Data Structures

struct  gmImageData
 A container for raw, CPU-side image pixel data. More...
struct  gmImage
 A handle to a GPU-managed image or texture. More...

Macros

#define STB_IMAGE_IMPLEMENTATION

Functions

int32_t gm_image_data_load (gmImageData *data, const char *path)
 Loads image file from disk into a gmImageData struct.
int32_t gm_image_data_load_from_memory (gmImageData *data, const unsigned char *buffer, int len)
 Loads image data from an in-memory buffer.
int32_t gm_image_data_free (gmImageData *d)
 Frees the pixel data buffer of a gmImageData struct.
gmColor gm_image_data_average_color (const gmImageData *data)
 Calculates the average color of an image's raw pixel data.
gmImage gm_image_create (const char *path)
 Creates a GPU-managed image from a file path.
gmImage gm_image_create_from_memory (const unsigned char *buffer, int len)
 Creates a GPU-managed image from in-memory data.
void gm_image_draw (gmImage i, double x, double y, double w, double h)
 Draws an entire image, centered at the specified position.
void gm_image_draw_part (gmImage i, int slice_x, int slice_y, int slice_width, int slice_height, double x, double y, double w, double h)
 Draws a rectangular sub-region of an image.

Macro Definition Documentation

◆ STB_IMAGE_IMPLEMENTATION

#define STB_IMAGE_IMPLEMENTATION

Function Documentation

◆ gm_image_create()

gmImage gm_image_create ( const char * path)

Creates a GPU-managed image from a file path.

This function loads an image file from disk, uploads its data to the GPU, and then discards the CPU-side copy.

Parameters
pathThe file path to the image.
Returns
A gmImage handle.

◆ gm_image_create_from_memory()

gmImage gm_image_create_from_memory ( const unsigned char * buffer,
int len )

Creates a GPU-managed image from in-memory data.

This function decodes an image from a memory buffer, uploads its data to the GPU, and then discards the CPU-side copy.

Parameters
bufferPointer to the buffer containing the raw image file data.
lenThe length of the buffer in bytes.
Returns
A gmImage handle.

◆ gm_image_data_average_color()

gmColor gm_image_data_average_color ( const gmImageData * data)

Calculates the average color of an image's raw pixel data.

Parameters
dataPointer to the gmImageData structure.
Returns
The average color as a gmColor.

◆ gm_image_data_free()

int32_t gm_image_data_free ( gmImageData * d)

Frees the pixel data buffer of a gmImageData struct.

Parameters
dA pointer to the gmImageData struct to free.
Returns
0 on success.

◆ gm_image_data_load()

int32_t gm_image_data_load ( gmImageData * data,
const char * path )

Loads image file from disk into a gmImageData struct.

Parameters
dataA pointer to the gmImageData struct to be filled.
pathThe file path of the image to load.
Returns
0 on success, -1 on failure.

◆ gm_image_data_load_from_memory()

int32_t gm_image_data_load_from_memory ( gmImageData * data,
const unsigned char * buffer,
int len )

Loads image data from an in-memory buffer.

Parameters
dataPointer to the gmImageData structure to fill.
bufferPointer to the buffer containing the raw image file data.
lenThe length of the buffer in bytes.
Returns
0 on success, -1 on failure.

◆ gm_image_draw()

void gm_image_draw ( gmImage i,
double x,
double y,
double w,
double h )

Draws an entire image, centered at the specified position.

Parameters
iThe image to draw.
xThe x-coordinate of the center of the image.
yThe y-coordinate of the center of the image.
wThe width to draw the image.
hThe height to draw the image.

◆ gm_image_draw_part()

void gm_image_draw_part ( gmImage i,
int slice_x,
int slice_y,
int slice_width,
int slice_height,
double x,
double y,
double w,
double h )

Draws a rectangular sub-region of an image.

Parameters
iThe source image to draw from.
slice_xThe x-coordinate of the top-left corner of the sub-region.
slice_yThe y-coordinate of the top-left corner of the sub-region.
slice_widthThe width of the sub-region.
slice_heightThe height of the sub-region.
xThe x-coordinate of the center of the destination rectangle.
yThe y-coordinate of the center of the destination rectangle.
wThe width to draw the sub-region.
hThe height to draw the sub-region.