hsv_to_rgb(3)

πŸ“¦ version 4.4.3.1, in fedora 43, fedora 44

✨ hsv_to_rgb(3) ✨

okay bestie, so this one lives in the Allegro manual β€” the Allegro game programming library β€” and it's literally just two lil functions that translate colors back and forth between two whole color languages. πŸ’–


πŸŽ€ NAME πŸŽ€

hsv_to_rgb, rgb_to_hsv β€” converts color values between the HSV and RGB color spaces. it's giving Allegro game programming library. πŸ¦‹


πŸ’… SYNOPSIS πŸ’…

#include <allegro.h>

void hsv_to_rgb(float h, float s, float v, int *r, int *g, int *b);

void rgb_to_hsv(int r, int g, int b, float *h, float *s, float *v);

🌸 DESCRIPTION 🌸

so basically these two convert color values between the HSV and RGB color spaces, no cap. πŸ”₯

here's the vibe check on the ranges, and you literally cannot forget these:

  • RGB values go from 0 to 255
  • hue goes from 0 to 360
  • saturation and value go from 0 to 1

and here's the example, i'm not editing a single character of it, periodt:

int r, g, b;
float hue, saturation, value;
...
/* Convert a reddish color to HSV format. */
rgb_to_hsv(255, 0, 128, &hue, &saturation, &value);

/* Now put our tin foil hat, and verify that. */
hsv_to_rgb(hue, saturation, value, &r, &g, &b);
ASSERT(r == 255);
ASSERT(g == 0);
ASSERT(b == 128);

not the tin foil hat 😭 but fr fr that's the whole thing β€” round trip a color, then assert it came back identical. slay. πŸ‘‘


🫢 SEE ALSO 🫢


ngl the tin foil hat line is iconic and i refuse to paraphrase it πŸ’€

and that's the whole page bestie, mwah πŸ’‹ β€” brought to you by Allegro, version 4.4.3. go forth and convert some colors, you main character. πŸŒˆβ­πŸ’œ

πŸ“¦ where this page comes from