Skip to content
modkitv0.2

image.h

#include <modkit/image.h>23 functions · 1 structs · 1 typedefs

CPU-side image (pixel buffer) API.

A plain RGBA8 pixel buffer you can create, load, edit (resize/crop/blit/color ops/generate) on the CPU, then upload to a GPU texture or save to disk. This is raylib's Image to modkit's mk_texture: modkit otherwise decodes straight to the GPU, so this fills the "manipulate pixels before upload" gap. mk_image owns a tightly-packed, top-left-origin RGBA8 buffer. Always pair a successful create/load/copy/resize/crop/gen with mk_image_free.

Functions

mk_image_blitfunction

void mk_image_blit(mk_image *dst, const mk_image *src, int dx, int dy)

Alpha-blend src over dst at (dx,dy) (clipped).

ParameterTypeDescription
dstmk_image *Value for dst.
srcconst mk_image *Value for src.
dxintValue for dx.
dyintValue for dy.

mk_image_copyfunction

mk_image mk_image_copy(const mk_image *src)

Deep copy.

ParameterTypeDescription
srcconst mk_image *Value for src.

Returns The resulting value.

mk_image_createfunction

mk_image mk_image_create(int w, int h, mk_color fill)

Allocate a w*h image filled with a solid color.

ParameterTypeDescription
wintValue for w.
hintValue for h.
fillmk_colorValue for fill.

Returns The resulting value.

mk_image_cropfunction

mk_image mk_image_crop(const mk_image *src, int x, int y, int w, int h)

Crop a sub-rectangle (clamped to source bounds).

ParameterTypeDescription
srcconst mk_image *Value for src.
xintValue for x.
yintValue for y.
wintValue for w.
hintValue for h.

Returns The resulting value.

mk_image_fillfunction

void mk_image_fill(mk_image *img, mk_color c)

Fill the whole image with a color.

ParameterTypeDescription
imgmk_image *Value for img.
cmk_colorValue for c.

mk_image_fill_rectfunction

void mk_image_fill_rect(mk_image *img, int x, int y, int w, int h, mk_color c)

Fill a rectangle with a color (clipped).

ParameterTypeDescription
imgmk_image *Value for img.
xintValue for x.
yintValue for y.
wintValue for w.
hintValue for h.
cmk_colorValue for c.

mk_image_flip_hfunction

void mk_image_flip_h(mk_image *img)

Perform the image flip h operation.

ParameterTypeDescription
imgmk_image *Value for img.

mk_image_flip_vfunction

void mk_image_flip_v(mk_image *img)

Perform the image flip v operation.

ParameterTypeDescription
imgmk_image *Value for img.

mk_image_freefunction

void mk_image_free(mk_image *img)

Free pixels and zero the struct.

ParameterTypeDescription
imgmk_image *Value for img.

mk_image_gen_checkerfunction

mk_image mk_image_gen_checker(int w, int h, int checks, mk_color a, mk_color b)

Checkerboard of checks cells across the width.

ParameterTypeDescription
wintValue for w.
hintValue for h.
checksintValue for checks.
amk_colorValue for a.
bmk_colorValue for b.

Returns The resulting value.

mk_image_gen_gradient_vfunction

mk_image mk_image_gen_gradient_v(int w, int h, mk_color top, mk_color bottom)

Vertical gradient from top color to bottom color.

ParameterTypeDescription
wintValue for w.
hintValue for h.
topmk_colorValue for top.
bottommk_colorValue for bottom.

Returns The resulting value.

mk_image_gen_perlinfunction

mk_image mk_image_gen_perlin(int w, int h, float scale)

Grayscale Perlin noise (stb_perlin).

ParameterTypeDescription
wintValue for w.
hintValue for h.
scalefloatValue for scale.

Returns The resulting value.

mk_image_getfunction

mk_color mk_image_get(const mk_image *img, int x, int y)

Get state from the image.

ParameterTypeDescription
imgconst mk_image *Value for img.
xintValue for x.
yintValue for y.

Returns The resulting value.

mk_image_grayscalefunction

void mk_image_grayscale(mk_image *img)

Convert to luminance grayscale (alpha preserved).

ParameterTypeDescription
imgmk_image *Value for img.

mk_image_invertfunction

void mk_image_invert(mk_image *img)

Invert RGB (alpha preserved).

ParameterTypeDescription
imgmk_image *Value for img.

mk_image_loadfunction

mk_image mk_image_load(const char *path)

Decode an image file (PNG/JPG/...) to an RGBA8 image.

ParameterTypeDescription
pathconst char *Value for path.

Returns The resulting value.

mk_image_load_memfunction

mk_image mk_image_load_mem(const void *data, size_t size)

Decode encoded image bytes (PNG/JPG/...) to an RGBA8 image.

ParameterTypeDescription
dataconst void *Data buffer.
sizesize_tSize in bytes.

Returns The resulting value.

mk_image_resizefunction

mk_image mk_image_resize(const mk_image *src, int new_w, int new_h)

High-quality resize (stb_image_resize2, sRGB-aware).

ParameterTypeDescription
srcconst mk_image *Value for src.
new_wintValue for new w.
new_hintValue for new h.

Returns The resulting value.

mk_image_save_pngfunction

bool mk_image_save_png(const mk_image *img, const char *path)

Write a PNG to disk (stb_image_write).

ParameterTypeDescription
imgconst mk_image *Value for img.
pathconst char *Value for path.

Returns True when the operation succeeds.

mk_image_setfunction

void mk_image_set(mk_image *img, int x, int y, mk_color c)

Set state on the image.

ParameterTypeDescription
imgmk_image *Value for img.
xintValue for x.
yintValue for y.
cmk_colorValue for c.

mk_image_tintfunction

void mk_image_tint(mk_image *img, mk_color tint)

Multiply every pixel (incl.

ParameterTypeDescription
imgmk_image *Value for img.
tintmk_colorValue for tint.

mk_image_uploadfunction

mk_texture_t mk_image_upload(const mk_image *img, uint32_t flags)

Upload as an RGBA8 GPU texture (wraps mk_texture_create).

ParameterTypeDescription
imgconst mk_image *Value for img.
flagsuint32_tValue for flags.

Returns The resulting handle or value.

mk_image_validfunction

bool mk_image_valid(const mk_image *img)

True if the image holds a valid pixel buffer.

ParameterTypeDescription
imgconst mk_image *Value for img.

Returns True when the operation succeeds.

Structs

mk_imagestruct

CPU pixel buffer: RGBA8, tightly packed (pitch = width*4), top-left origin.

FieldTypeDescription
pixelsuint8_t *The pixels.
widthintThe width.
heightintThe height.

Typedefs

mk_imagetypedef

typedef struct mk_image mk_image

CPU pixel buffer: RGBA8, tightly packed (pitch = width*4), top-left origin.