Skip to content

Commit

Permalink
Fix RGBToString conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
osm committed Feb 26, 2024
1 parent 7a08387 commit 2b5c238
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,16 @@ byte* StringToRGB(char *s)
}

void RGBToString(const byte *rgb, char *s) {
s[0] = '0' + (rgb[0] / 255) * 9.0f;
s[1] = '0' + (rgb[1] / 255) * 9.0f;
s[2] = '0' + (rgb[2] / 255) * 9.0f;
// Scale down each value from 0x0 to 0xff to the range of 0x0 to 0xf.
byte r = rgb[0] * 0xf / 0xff;
byte g = rgb[1] * 0xf / 0xff;
byte b = rgb[2] * 0xf / 0xff;

// Convert the value to its hex representation. The characters will be
// used in a "&cRGB" string.
s[0] = (r < 10) ? ('0' + r) : ('a' + r - 0xa);
s[1] = (g < 10) ? ('0' + g) : ('a' + g - 0xa);
s[2] = (b < 10) ? ('0' + b) : ('a' + b - 0xa);
}

/*
Expand Down

0 comments on commit 2b5c238

Please sign in to comment.