tinyimg 1.0.0
Lightweight image manipulation library for Cloudflare Workers
Loading...
Searching...
No Matches
color.h File Reference

Color and pixel manipulation utilities. More...

#include <stddef.h>
#include <stdint.h>
#include "tinyimg/image.h"

Go to the source code of this file.

Classes

struct  TinyIccProfile
 A parsed matrix and TRC profile. More...

Functions

int tiny_rgb_to_grayscale (uint8_t r, uint8_t g, uint8_t b)
 Converts RGB color values to a grayscale value using the luminosity method.
int tiny_grayscale_to_rgb (uint8_t grayscale, uint8_t *r, uint8_t *g, uint8_t *b)
 Converts a grayscale value to RGB color values.
int tiny_rgb_to_hsv (uint8_t r, uint8_t g, uint8_t b, float *h, float *s, float *v)
 Converts RGB color values to HSV (Hue, Saturation, Value) color space.
int tiny_hsv_to_rgb (float h, float s, float v, uint8_t *r, uint8_t *g, uint8_t *b)
 Converts HSV (Hue, Saturation, Value) color space values to RGB color values.
int tiny_rgb_to_hsl (uint8_t r, uint8_t g, uint8_t b, float *h, float *s, float *l)
 Converts RGB color values to HSL (Hue, Saturation, Lightness) color space.
int tiny_hsl_to_rgb (float h, float s, float l, uint8_t *r, uint8_t *g, uint8_t *b)
 Converts HSL (Hue, Saturation, Lightness) color space values to RGB color values.
int tiny_rgb_to_cmyk (uint8_t r, uint8_t g, uint8_t b, float *c, float *m, float *y, float *k)
 Converts RGB color values to CMYK (Cyan, Magenta, Yellow, Key/Black) color space.
int tiny_cmyk_to_rgb (float c, float m, float y, float k, uint8_t *r, uint8_t *g, uint8_t *b)
 Converts CMYK (Cyan, Magenta, Yellow, Key/Black) color space values to RGB color values.
int tiny_interpolate_rgb (uint8_t r1, uint8_t g1, uint8_t b1, uint8_t r2, uint8_t g2, uint8_t b2, float t, uint8_t *r_out, uint8_t *g_out, uint8_t *b_out)
 Interpolates between two RGB colors based on a given interpolation factor t.
int tiny_interpolate_hsv (float h1, float s1, float v1, float h2, float s2, float v2, float t, float *h_out, float *s_out, float *v_out)
 Interpolates between two HSV colors based on a given interpolation factor t.
int tiny_interpolate_hsl (float h1, float s1, float l1, float h2, float s2, float l2, float t, float *h_out, float *s_out, float *l_out)
 Interpolates between two HSL colors based on a given interpolation factor t.
int * tiny_gradient_rgb (uint8_t r1, uint8_t g1, uint8_t b1, uint8_t r2, uint8_t g2, uint8_t b2, size_t steps)
 Generates a gradient of RGB colors between two specified colors over a given number of steps.
int * tiny_gradient_rgba (uint8_t r1, uint8_t g1, uint8_t b1, uint8_t a1, uint8_t r2, uint8_t g2, uint8_t b2, uint8_t a2, size_t steps)
 Generates a gradient of RGBA colors between two specified colors over a given number of steps.
float * tiny_gradient_hsv (float h1, float s1, float v1, float h2, float s2, float v2, size_t steps)
 Generates a gradient of HSV colors between two specified colors over a given number of steps.
float * tiny_gradient_hsl (float h1, float s1, float l1, float h2, float s2, float l2, size_t steps)
 Generates a gradient of HSL colors between two specified colors over a given number of steps.
float * tiny_gradient_cmyk (float c1, float m1, float y1, float k1, float c2, float m2, float y2, float k2, size_t steps)
 Generates a gradient of CMYK colors between two specified colors over a given number of steps.
int * tiny_multigradient_rgb (uint8_t *colors, size_t num_colors, size_t steps)
 Generates a multi-gradient of RGB colors based on an array of input colors and a specified number of steps equally distributed across the input colors.
int * tiny_multigradient_rgb_sized (uint8_t *colors, size_t num_colors, size_t steps, float *color_distribution)
 Generates a multi-gradient of RGB colors based on an array of input colors and a specified number of steps distributed based on color_distribution.
int * tiny_multigradient_rgba (uint8_t *colors, size_t num_colors, size_t steps)
 Generates a multi-gradient of RGBA colors based on an array of input colors and a specified number of steps equally distributed across the input colors.
int * tiny_multigradient_rgba_sized (uint8_t *colors, size_t num_colors, size_t steps, float *color_distribution)
 Generates a multi-gradient of RGBA colors based on an array of input colors and a specified number of steps distributed based on color_distribution.
float * tiny_multigradient_hsv (float *colors, size_t num_colors, size_t steps)
 Generates a multi-gradient of HSV colors based on an array of input colors and a specified number of steps equally distributed across the input colors.
float * tiny_multigradient_hsv_sized (float *colors, size_t num_colors, size_t steps, float *color_distribution)
 Generates a multi-gradient of HSV colors based on an array of input colors and a specified number of steps distributed based on color_distribution.
float * tiny_multigradient_hsl (float *colors, size_t num_colors, size_t steps)
 Generates a multi-gradient of HSL colors based on an array of input colors and a specified number of steps equally distributed across the input colors.
float * tiny_multigradient_hsl_sized (float *colors, size_t num_colors, size_t steps, float *color_distribution)
 Generates a multi-gradient of HSL colors based on an array of input colors and a specified number of steps distributed based on color_distribution.
float * tiny_multigradient_cmyk (float *colors, size_t num_colors, size_t steps)
 Generates a multi-gradient of CMYK colors based on an array of input colors and a specified number of steps equally distributed across the input colors.
float * tiny_multigradient_cmyk_sized (float *colors, size_t num_colors, size_t steps, float *color_distribution)
 Generates a multi-gradient of CMYK colors based on an array of input colors and a specified number of steps distributed based on color_distribution.
int tiny_icc_parse (TinyIccProfile *profile, const uint8_t *data, size_t size)
 Reads a matrix and TRC profile.
int tiny_icc_srgb (TinyIccProfile *profile)
 The sRGB profile, without needing a file for it.
int tiny_icc_to_srgb (const TinyIccProfile *profile, const uint8_t *in, uint8_t *out)
 Converts one color from a profile's space to sRGB.
int tiny_icc_convert_image (TinyImage *image, const TinyIccProfile *profile)
 Converts a whole image from a profile's space to sRGB.
int tiny_icc_matrix_between (float *out, const TinyIccProfile *from, const TinyIccProfile *to)
 The matrix taking one profile's RGB to another's.

Detailed Description

Color and pixel manipulation utilities.

Author
Gregory Mitchell (me@gm.nosp@m.itch.nosp@m.215.x.nosp@m.yz)
Version
1.0.0
Date
2026-08-31

Function Documentation

◆ tiny_cmyk_to_rgb()

int tiny_cmyk_to_rgb ( float c,
float m,
float y,
float k,
uint8_t * r,
uint8_t * g,
uint8_t * b )

Converts CMYK (Cyan, Magenta, Yellow, Key/Black) color space values to RGB color values.

The CMYK values are expected to be in the ranges:

  • C: [0, 1]
  • M: [0, 1]
  • Y: [0, 1]
  • K: [0, 1] The resulting RGB values will be in the range [0, 255].
Parameters
cCyan value (0-1)
mMagenta value (0-1)
yYellow value (0-1)
kKey/Black value (0-1)
rPointer to store the Red component (0-255)
gPointer to store the Green component (0-255)
bPointer to store the Blue component (0-255)
Returns
int 0 on success, non-zero on failure

◆ tiny_gradient_cmyk()

float * tiny_gradient_cmyk ( float c1,
float m1,
float y1,
float k1,
float c2,
float m2,
float y2,
float k2,
size_t steps )

Generates a gradient of CMYK colors between two specified colors over a given number of steps.

The function returns a dynamically allocated array of integers, where each entry is four floats: cyan, magenta, yellow and key. The memory comes from the arena, so tiny_arena_reset() or a matching tiny_arena_release() reclaims it and nothing frees it individually.

Parameters
c1Cyan of the starting color (0-1)
m1Magenta of the starting color (0-1)
y1Yellow of the starting color (0-1)
k1Key/Black of the starting color (0-1)
c2Cyan of the ending color (0-1)
m2Magenta of the ending color (0-1)
y2Yellow of the ending color (0-1)
k2Key/Black of the ending color (0-1)
stepsNumber of steps in the gradient (must be greater than 1)
Returns
float* The gradient, or NULL when steps is below two.

◆ tiny_gradient_hsl()

float * tiny_gradient_hsl ( float h1,
float s1,
float l1,
float h2,
float s2,
float l2,
size_t steps )

Generates a gradient of HSL colors between two specified colors over a given number of steps.

The function returns a dynamically allocated array of integers, where each entry is three floats: hue, saturation and lightness. The memory comes from the arena, so tiny_arena_reset() or a matching tiny_arena_release() reclaims it and nothing frees it individually.

Parameters
h1Hue of the starting color (0-360)
s1Saturation of the starting color (0-1)
l1Lightness of the starting color (0-1)
h2Hue of the ending color (0-360)
s2Saturation of the ending color (0-1)
l2Lightness of the ending color (0-1)
stepsNumber of steps in the gradient (must be greater than 1)
Returns
float* The gradient, or NULL when steps is below two.

◆ tiny_gradient_hsv()

float * tiny_gradient_hsv ( float h1,
float s1,
float v1,
float h2,
float s2,
float v2,
size_t steps )

Generates a gradient of HSV colors between two specified colors over a given number of steps.

The function returns a dynamically allocated array of integers, where each entry is three floats: hue, saturation and value. The memory comes from the arena, so tiny_arena_reset() or a matching tiny_arena_release() reclaims it and nothing frees it individually.

Parameters
h1Hue of the starting color (0-360)
s1Saturation of the starting color (0-1)
v1Value (Brightness) of the starting color (0-1)
h2Hue of the ending color (0-360)
s2Saturation of the ending color (0-1)
v2Value (Brightness) of the ending color (0-1)
stepsNumber of steps in the gradient (must be greater than 1)
Returns
float* The gradient, or NULL when steps is below two.

◆ tiny_gradient_rgb()

int * tiny_gradient_rgb ( uint8_t r1,
uint8_t g1,
uint8_t b1,
uint8_t r2,
uint8_t g2,
uint8_t b2,
size_t steps )

Generates a gradient of RGB colors between two specified colors over a given number of steps.

The function returns a dynamically allocated array of integers, where each integer holds one RGB color as 0xRRGGBB. The memory comes from the arena, so tiny_arena_reset() or a matching tiny_arena_release() reclaims it and nothing frees it individually.

Parameters
r1Red component of the starting color (0-255)
g1Green component of the starting color (0-255)
b1Blue component of the starting color (0-255)
r2Red component of the ending color (0-255)
g2Green component of the ending color (0-255)
b2Blue component of the ending color (0-255)
stepsNumber of steps in the gradient (must be greater than 1)
Returns
int* Pointer to an array of integers representing the gradient colors, or NULL on failure (e.g., if steps is less than 2).

◆ tiny_gradient_rgba()

int * tiny_gradient_rgba ( uint8_t r1,
uint8_t g1,
uint8_t b1,
uint8_t a1,
uint8_t r2,
uint8_t g2,
uint8_t b2,
uint8_t a2,
size_t steps )

Generates a gradient of RGBA colors between two specified colors over a given number of steps.

The function returns a dynamically allocated array of integers, where each integer holds one RGBA color as 0xRRGGBBAA. The memory comes from the arena, so tiny_arena_reset() or a matching tiny_arena_release() reclaims it and nothing frees it individually.

Parameters
r1Red component of the starting color (0-255)
g1Green component of the starting color (0-255)
b1Blue component of the starting color (0-255)
a1Alpha component of the starting color (0-255)
r2Red component of the ending color (0-255)
g2Green component of the ending color (0-255)
b2Blue component of the ending color (0-255)
a2Alpha component of the ending color (0-255)
stepsNumber of steps in the gradient (must be greater than 1)
Returns
int* Pointer to an array of integers representing the gradient colors, or NULL on failure.

◆ tiny_grayscale_to_rgb()

int tiny_grayscale_to_rgb ( uint8_t grayscale,
uint8_t * r,
uint8_t * g,
uint8_t * b )

Converts a grayscale value to RGB color values.

The grayscale value is replicated across the R, G, and B channels.

Parameters
grayscaleGrayscale value (0-255)
rPointer to store the Red component (0-255)
gPointer to store the Green component (0-255)
bPointer to store the Blue component (0-255)
Returns
int 0 on success, non-zero on failure

◆ tiny_hsl_to_rgb()

int tiny_hsl_to_rgb ( float h,
float s,
float l,
uint8_t * r,
uint8_t * g,
uint8_t * b )

Converts HSL (Hue, Saturation, Lightness) color space values to RGB color values.

The HSL values are expected to be in the ranges:

  • H: [0, 360)
  • S: [0, 1]
  • L: [0, 1] The resulting RGB values will be in the range [0, 255].
Parameters
hHue value (0-360)
sSaturation value (0-1)
lLightness value (0-1)
rPointer to store the Red component (0-255)
gPointer to store the Green component (0-255)
bPointer to store the Blue component (0-255)
Returns
int 0 on success, non-zero on failure

◆ tiny_hsv_to_rgb()

int tiny_hsv_to_rgb ( float h,
float s,
float v,
uint8_t * r,
uint8_t * g,
uint8_t * b )

Converts HSV (Hue, Saturation, Value) color space values to RGB color values.

The HSV values are expected to be in the ranges:

  • H: [0, 360)
  • S: [0, 1]
  • V: [0, 1] The resulting RGB values will be in the range [0, 255].
Parameters
hHue value (0-360)
sSaturation value (0-1)
vValue (Brightness) value (0-1)
rPointer to store the Red component (0-255)
gPointer to store the Green component (0-255)
bPointer to store the Blue component (0-255)
Returns
int 0 on success, non-zero on failure

◆ tiny_icc_convert_image()

int tiny_icc_convert_image ( TinyImage * image,
const TinyIccProfile * profile )

Converts a whole image from a profile's space to sRGB.

Parameters
imageThe image to convert.
profileThe profile its pixels are in.
Returns
int TINYIMG_OK, TINYIMG_ERR_NULL, or TINYIMG_ERR_NO_CHANNEL when the image has fewer than three channels.

◆ tiny_icc_matrix_between()

int tiny_icc_matrix_between ( float * out,
const TinyIccProfile * from,
const TinyIccProfile * to )

The matrix taking one profile's RGB to another's.

Parameters
outReceives nine weights, row major.
fromThe source profile.
toThe destination profile.
Returns
int TINYIMG_OK, TINYIMG_ERR_NULL, or TINYIMG_ERR_RANGE when the destination's matrix cannot be inverted.

◆ tiny_icc_parse()

int tiny_icc_parse ( TinyIccProfile * profile,
const uint8_t * data,
size_t size )

Reads a matrix and TRC profile.

Parameters
profileReceives the parsed profile.
dataThe profile bytes.
sizeHow many bytes.
Returns
int TINYIMG_OK, TINYIMG_ERR_NULL, TINYIMG_ERR_CORRUPT for a profile that does not parse, or TINYIMG_ERR_UNSUPPORTED_VARIANT for one whose transform is a lookup table rather than a matrix.

◆ tiny_icc_srgb()

int tiny_icc_srgb ( TinyIccProfile * profile)

The sRGB profile, without needing a file for it.

Parameters
profileReceives it.
Returns
int TINYIMG_OK or TINYIMG_ERR_NULL.

◆ tiny_icc_to_srgb()

int tiny_icc_to_srgb ( const TinyIccProfile * profile,
const uint8_t * in,
uint8_t * out )

Converts one color from a profile's space to sRGB.

Parameters
profileThe source profile.
inThree channels in the profile's space.
outReceives three channels of sRGB.
Returns
int TINYIMG_OK or TINYIMG_ERR_NULL.

◆ tiny_interpolate_hsl()

int tiny_interpolate_hsl ( float h1,
float s1,
float l1,
float h2,
float s2,
float l2,
float t,
float * h_out,
float * s_out,
float * l_out )

Interpolates between two HSL colors based on a given interpolation factor t.

The interpolation factor t should be in the range [0, 1], where:

  • t = 0 results in the first color (h1, s1, l1)
  • t = 1 results in the second color (h2, s2, l2)
Parameters
h1Hue of the first color (0-360)
s1Saturation of the first color (0-1)
l1Lightness of the first color (0-1)
h2Hue of the second color (0-360)
s2Saturation of the second color (0-1)
l2Lightness of the second color (0-1)
tInterpolation factor (0-1)
h_outPointer to store the interpolated Hue value (0-360)
s_outPointer to store the interpolated Saturation value (0-1)
l_outPointer to store the interpolated Lightness value (0-1)
Returns
int 0 on success, non-zero on failure

◆ tiny_interpolate_hsv()

int tiny_interpolate_hsv ( float h1,
float s1,
float v1,
float h2,
float s2,
float v2,
float t,
float * h_out,
float * s_out,
float * v_out )

Interpolates between two HSV colors based on a given interpolation factor t.

The interpolation factor t should be in the range [0, 1], where:

  • t = 0 results in the first color (h1, s1, v1)
  • t = 1 results in the second color (h2, s2, v2)
Parameters
h1Hue of the first color (0-360)
s1Saturation of the first color (0-1)
v1Value of the first color (0-1)
h2Hue of the second color (0-360)
s2Saturation of the second color (0-1)
v2Value of the second color (0-1)
tInterpolation factor (0-1)
h_outPointer to store the interpolated Hue value (0-360)
s_outPointer to store the interpolated Saturation value (0-1)
v_outPointer to store the interpolated Value (0-1)
Returns
int 0 on success, non-zero on failure

◆ tiny_interpolate_rgb()

int tiny_interpolate_rgb ( uint8_t r1,
uint8_t g1,
uint8_t b1,
uint8_t r2,
uint8_t g2,
uint8_t b2,
float t,
uint8_t * r_out,
uint8_t * g_out,
uint8_t * b_out )

Interpolates between two RGB colors based on a given interpolation factor t.

The interpolation factor t should be in the range [0, 1], where:

  • t = 0 results in the first color (r1, g1, b1)
  • t = 1 results in the second color (r2, g2, b2)
Parameters
r1Red component of the first color (0-255)
g1Green component of the first color (0-255)
b1Blue component of the first color (0-255)
r2Red component of the second color (0-255)
g2Green component of the second color (0-255)
b2Blue component of the second color (0-255)
tInterpolation factor (0-1)
r_outPointer to store the interpolated Red component (0-255)
g_outPointer to store the interpolated Green component (0-255)
b_outPointer to store the interpolated Blue component (0-255)
Returns
int 0 on success, non-zero on failure

◆ tiny_multigradient_cmyk()

float * tiny_multigradient_cmyk ( float * colors,
size_t num_colors,
size_t steps )

Generates a multi-gradient of CMYK colors based on an array of input colors and a specified number of steps equally distributed across the input colors.

The function returns a dynamically allocated array of integers, where each entry is four floats: cyan, magenta, yellow and key. The memory comes from the arena, so tiny_arena_reset() or a matching tiny_arena_release() reclaims it and nothing frees it individually.

Parameters
colorsPointer to an array of float values representing the input colors. Each color should be represented by four consecutive values (C, M, Y, K).
num_colorsThe number of colors in the input array.
stepsThe total number of steps in the multi-gradient (must be greater than 1).
Returns
float* The gradient, or NULL on failure.

◆ tiny_multigradient_cmyk_sized()

float * tiny_multigradient_cmyk_sized ( float * colors,
size_t num_colors,
size_t steps,
float * color_distribution )

Generates a multi-gradient of CMYK colors based on an array of input colors and a specified number of steps distributed based on color_distribution.

The function returns a dynamically allocated array of integers, where each entry is four floats: cyan, magenta, yellow and key. The memory comes from the arena, so tiny_arena_reset() or a matching tiny_arena_release() reclaims it and nothing frees it individually.

Parameters
colorsPointer to an array of float values representing the input colors. Each color should be represented by four consecutive values (C, M, Y, K).
num_colorsThe number of colors in the input array.
stepsThe total number of steps in the multi-gradient (must be greater than 1).
color_distributionOne weight per transition, so num_colors - 1 of them, each between 0.0 and 1.0 and together summing to 1.0. A transition given a larger weight takes up more of the gradient.
Returns
float* The gradient, or NULL on failure.

◆ tiny_multigradient_hsl()

float * tiny_multigradient_hsl ( float * colors,
size_t num_colors,
size_t steps )

Generates a multi-gradient of HSL colors based on an array of input colors and a specified number of steps equally distributed across the input colors.

The function returns a dynamically allocated array of integers, where each entry is three floats: hue, saturation and lightness. The memory comes from the arena, so tiny_arena_reset() or a matching tiny_arena_release() reclaims it and nothing frees it individually.

Parameters
colorsPointer to an array of float values representing the input colors. Each color should be represented by three consecutive values (H, S, L).
num_colorsThe number of colors in the input array.
stepsThe total number of steps in the multi-gradient (must be greater than 1).
Returns
float* The gradient, or NULL on failure.

◆ tiny_multigradient_hsl_sized()

float * tiny_multigradient_hsl_sized ( float * colors,
size_t num_colors,
size_t steps,
float * color_distribution )

Generates a multi-gradient of HSL colors based on an array of input colors and a specified number of steps distributed based on color_distribution.

The function returns a dynamically allocated array of integers, where each entry is three floats: hue, saturation and lightness. The memory comes from the arena, so tiny_arena_reset() or a matching tiny_arena_release() reclaims it and nothing frees it individually.

Parameters
colorsPointer to an array of float values representing the input colors. Each color should be represented by three consecutive values (H, S, L).
num_colorsThe number of colors in the input array.
stepsThe total number of steps in the multi-gradient (must be greater than 1).
color_distributionOne weight per transition, so num_colors - 1 of them, each between 0.0 and 1.0 and together summing to 1.0. A transition given a larger weight takes up more of the gradient.
Returns
float* The gradient, or NULL on failure.

◆ tiny_multigradient_hsv()

float * tiny_multigradient_hsv ( float * colors,
size_t num_colors,
size_t steps )

Generates a multi-gradient of HSV colors based on an array of input colors and a specified number of steps equally distributed across the input colors.

The function returns a dynamically allocated array of integers, where each entry is three floats: hue, saturation and value. The memory comes from the arena, so tiny_arena_reset() or a matching tiny_arena_release() reclaims it and nothing frees it individually.

Parameters
colorsPointer to an array of float values representing the input colors. Each color should be represented by three consecutive values (H, S, V).
num_colorsThe number of colors in the input array.
stepsThe total number of steps in the multi-gradient (must be greater than 1).
Returns
float* The gradient, or NULL on failure.

◆ tiny_multigradient_hsv_sized()

float * tiny_multigradient_hsv_sized ( float * colors,
size_t num_colors,
size_t steps,
float * color_distribution )

Generates a multi-gradient of HSV colors based on an array of input colors and a specified number of steps distributed based on color_distribution.

The function returns a dynamically allocated array of integers, where each entry is three floats: hue, saturation and value. The memory comes from the arena, so tiny_arena_reset() or a matching tiny_arena_release() reclaims it and nothing frees it individually.

Parameters
colorsPointer to an array of float values representing the input colors. Each color should be represented by three consecutive values (H, S, V).
num_colorsThe number of colors in the input array.
stepsThe total number of steps in the multi-gradient (must be greater than 1).
color_distributionOne weight per transition, so num_colors - 1 of them, each between 0.0 and 1.0 and together summing to 1.0. A transition given a larger weight takes up more of the gradient.
Returns
float* The gradient, or NULL on failure.

◆ tiny_multigradient_rgb()

int * tiny_multigradient_rgb ( uint8_t * colors,
size_t num_colors,
size_t steps )

Generates a multi-gradient of RGB colors based on an array of input colors and a specified number of steps equally distributed across the input colors.

The function returns a dynamically allocated array of integers, where each integer holds one RGB color as 0xRRGGBB. The memory comes from the arena, so tiny_arena_reset() or a matching tiny_arena_release() reclaims it and nothing frees it individually.

Parameters
colorsPointer to an array of uint8_t values representing the input colors. Each color should be represented by three consecutive values (R, G, B).
num_colorsThe number of colors in the input array.
stepsThe total number of steps in the multi-gradient (must be greater than 1).
Returns
int* Pointer to an array of integers representing the multi-gradient colors, or NULL on failure (e.g., if num_colors is less than 2 or if steps is less than 2).

◆ tiny_multigradient_rgb_sized()

int * tiny_multigradient_rgb_sized ( uint8_t * colors,
size_t num_colors,
size_t steps,
float * color_distribution )

Generates a multi-gradient of RGB colors based on an array of input colors and a specified number of steps distributed based on color_distribution.

The function returns a dynamically allocated array of integers, where each integer holds one RGB color as 0xRRGGBB. The memory comes from the arena, so tiny_arena_reset() or a matching tiny_arena_release() reclaims it and nothing frees it individually.

Parameters
colorsPointer to an array of uint8_t values representing the input colors. Each color should be represented by three consecutive values (R, G, B).
num_colorsThe number of colors in the input array.
stepsThe total number of steps in the multi-gradient (must be greater than 1).
color_distributionOne weight per transition, so num_colors - 1 of them, each between 0.0 and 1.0 and together summing to 1.0. A transition given a larger weight takes up more of the gradient.
Returns
int* Pointer to an array of integers representing the multi-gradient colors, or NULL on failure (e.g., if num_colors is less than 2 or if steps is less than 2; if color_distribution is NULL, does not have the correct size, or adds up to 1.0).

◆ tiny_multigradient_rgba()

int * tiny_multigradient_rgba ( uint8_t * colors,
size_t num_colors,
size_t steps )

Generates a multi-gradient of RGBA colors based on an array of input colors and a specified number of steps equally distributed across the input colors.

The function returns a dynamically allocated array of integers, where each integer holds one RGBA color as 0xRRGGBBAA. The memory comes from the arena, so tiny_arena_reset() or a matching tiny_arena_release() reclaims it and nothing frees it individually.

Parameters
colorsPointer to an array of uint8_t values representing the input colors. Each color should be represented by four consecutive values (R, G, B, A).
num_colorsThe number of colors in the input array.
stepsThe total number of steps in the multi-gradient (must be greater than 1).
Returns
int* Pointer to an array of integers representing the multi-gradient colors, or NULL on failure (e.g., if num_colors is less than 2 or if steps is less than 2).

◆ tiny_multigradient_rgba_sized()

int * tiny_multigradient_rgba_sized ( uint8_t * colors,
size_t num_colors,
size_t steps,
float * color_distribution )

Generates a multi-gradient of RGBA colors based on an array of input colors and a specified number of steps distributed based on color_distribution.

The function returns a dynamically allocated array of integers, where each integer holds one RGBA color as 0xRRGGBBAA. The memory comes from the arena, so tiny_arena_reset() or a matching tiny_arena_release() reclaims it and nothing frees it individually.

Parameters
colorsPointer to an array of uint8_t values representing the input colors. Each color should be represented by four consecutive values (R, G, B, A).
num_colorsThe number of colors in the input array.
stepsThe total number of steps in the multi-gradient (must be greater than 1).
color_distributionOne weight per transition, so num_colors - 1 of them, each between 0.0 and 1.0 and together summing to 1.0. A transition given a larger weight takes up more of the gradient.
Returns
int* Pointer to an array of integers representing the multi-gradient colors, or NULL on failure (e.g., if num_colors is less than 2 or if steps is less than 2; if color_distribution is NULL, does not have the correct size, or adds up to 1.0).

◆ tiny_rgb_to_cmyk()

int tiny_rgb_to_cmyk ( uint8_t r,
uint8_t g,
uint8_t b,
float * c,
float * m,
float * y,
float * k )

Converts RGB color values to CMYK (Cyan, Magenta, Yellow, Key/Black) color space.

The RGB values are expected to be in the range [0, 255], and the resulting CMYK values will be in the ranges:

  • C: [0, 1]
  • M: [0, 1]
  • Y: [0, 1]
  • K: [0, 1]
Parameters
rRed component (0-255)
gGreen component (0-255)
bBlue component (0-255)
cPointer to store the Cyan value (0-1)
mPointer to store the Magenta value (0-1)
yPointer to store the Yellow value (0-1)
kPointer to store the Key/Black value (0-1)
Returns
int 0 on success, non-zero on failure

◆ tiny_rgb_to_grayscale()

int tiny_rgb_to_grayscale ( uint8_t r,
uint8_t g,
uint8_t b )

Converts RGB color values to a grayscale value using the luminosity method.

The formula used is: grayscale = 0.21 * R + 0.72 * G + 0.07 * B

Parameters
rRed component (0-255)
gGreen component (0-255)
bBlue component (0-255)
Returns
uint8_t Grayscale value (0-255)

◆ tiny_rgb_to_hsl()

int tiny_rgb_to_hsl ( uint8_t r,
uint8_t g,
uint8_t b,
float * h,
float * s,
float * l )

Converts RGB color values to HSL (Hue, Saturation, Lightness) color space.

The RGB values are expected to be in the range [0, 255], and the resulting HSL values will be in the ranges:

  • H: [0, 360)
  • S: [0, 1]
  • L: [0, 1]
Parameters
rRed component (0-255)
gGreen component (0-255)
bBlue component (0-255)
hPointer to store the Hue value (0-360)
sPointer to store the Saturation value (0-1)
lPointer to store the Lightness value (0-1)
Returns
int 0 on success, non-zero on failure

◆ tiny_rgb_to_hsv()

int tiny_rgb_to_hsv ( uint8_t r,
uint8_t g,
uint8_t b,
float * h,
float * s,
float * v )

Converts RGB color values to HSV (Hue, Saturation, Value) color space.

The RGB values are expected to be in the range [0, 255], and the resulting HSV values will be in the ranges:

  • H: [0, 360)
  • S: [0, 1]
  • V: [0, 1]
Parameters
rRed component (0-255)
gGreen component (0-255)
bBlue component (0-255)
hPointer to store the Hue value (0-360)
sPointer to store the Saturation value (0-1)
vPointer to store the Value (Brightness) value (0-1)
Returns
int 0 on success, non-zero on failure