#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.
|
| 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.
|
◆ STB_IMAGE_IMPLEMENTATION
| #define STB_IMAGE_IMPLEMENTATION |
◆ 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
-
| path | The 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
-
| buffer | Pointer to the buffer containing the raw image file data. |
| len | The length of the buffer in bytes. |
- Returns
- A gmImage handle.
◆ gm_image_data_average_color()
Calculates the average color of an image's raw pixel data.
- Parameters
-
- Returns
- The average color as a gmColor.
◆ gm_image_data_free()
Frees the pixel data buffer of a gmImageData struct.
- Parameters
-
- 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
-
| data | A pointer to the gmImageData struct to be filled. |
| path | The 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
-
| data | Pointer to the gmImageData structure to fill. |
| buffer | Pointer to the buffer containing the raw image file data. |
| len | The 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
-
| i | The image to draw. |
| x | The x-coordinate of the center of the image. |
| y | The y-coordinate of the center of the image. |
| w | The width to draw the image. |
| h | The 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
-
| i | The source image to draw from. |
| slice_x | The x-coordinate of the top-left corner of the sub-region. |
| slice_y | The y-coordinate of the top-left corner of the sub-region. |
| slice_width | The width of the sub-region. |
| slice_height | The height of the sub-region. |
| x | The x-coordinate of the center of the destination rectangle. |
| y | The y-coordinate of the center of the destination rectangle. |
| w | The width to draw the sub-region. |
| h | The height to draw the sub-region. |