2#ifndef STB_IMAGE_IMPLEMENTATION
3#define STB_IMAGE_IMPLEMENTATION
6#include "../stb/stb_image.h"
32 return data->
data ? 0 : -1;
43 const unsigned char *buffer,
int len) {
46 stbi_load_from_memory(buffer, len, &data->
width, &data->
height, NULL, 4);
47 return data->
data ? 0 : -1;
72 long long total_r = 0;
73 long long total_g = 0;
74 long long total_b = 0;
77 for (
size_t i = 0; i < pixel_count; ++i) {
78 total_r += data->
data[i * 4 + 0];
79 total_g += data->
data[i * 4 + 1];
80 total_b += data->
data[i * 4 + 2];
83 unsigned char avg_r = (
unsigned char)(total_r / pixel_count);
84 unsigned char avg_g = (
unsigned char)(total_g / pixel_count);
85 unsigned char avg_b = (
unsigned char)(total_b / pixel_count);
87 return gm_rgb(avg_r, avg_g, avg_b);
172 int slice_height,
double x,
double y,
double w,
uint32_t gmColor
Type definition for color values, stored as a 32-bit unsigned integer. The color components are packe...
Definition color.h:13
Graphics API (GAPI) abstraction layer for Gama.
int32_t gapi_draw_image(uint32_t handle, double x, double y, double width, double height)
Draws an image referenced by its handle on the screen.
uint32_t gapi_create_image(const unsigned char *data, uint32_t width, uint32_t height)
Creates a platform-specific image handle from raw pixel data.
int32_t gapi_draw_image_part(uint32_t handle, uint32_t slice_x, uint32_t slice_y, uint32_t slice_width, uint32_t slice_height, double x, double y, double width, double height)
Draws a part of an image referenced by its handle on the screen.
int32_t gm_image_data_load_from_memory(gmImageData *data, const unsigned char *buffer, int len)
Loads image data from an in-memory buffer.
Definition image.h:42
gmColor gm_image_data_average_color(const gmImageData *data)
Calculates the average color of an image's raw pixel data.
Definition image.h:67
int32_t gm_image_data_free(gmImageData *d)
Frees the pixel data buffer of a gmImageData struct.
Definition image.h:55
int32_t gm_image_data_load(gmImageData *data, const char *path)
Loads image file from disk into a gmImageData struct.
Definition image.h:29
gmImage gm_image_create_from_memory(const unsigned char *buffer, int len)
Creates a GPU-managed image from in-memory data.
Definition image.h:136
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.
Definition image.h:171
gmImage gm_image_create(const char *path)
Creates a GPU-managed image from a file path.
Definition image.h:115
void gm_image_draw(gmImage i, double x, double y, double w, double h)
Draws an entire image, centered at the specified position.
Definition image.h:155
void free(void *ptr)
Custom implementation of free for memory allocated by malloc (this custom version).
Definition malloc.h:189
A container for raw, CPU-side image pixel data.
Definition image.h:18
int32_t width
Definition image.h:19
int32_t height
Definition image.h:19
unsigned char * data
Definition image.h:20
A handle to a GPU-managed image or texture.
Definition image.h:97
uint32_t handle
Definition image.h:98
int width
Definition image.h:99
int height
Definition image.h:100