MCPcopy Create free account
hub / github.com/NetHack/NetHack / wc_color_name

Function wc_color_name

src/coloratt.c:763–797  ·  view source on GitHub ↗

return the canonical name of a particular color */

Source from the content-addressed store, hash-verified

761
762/* return the canonical name of a particular color */
763const char *
764wc_color_name(int32 colorindx)
765{
766 static char hexcolor[sizeof "#rrggbb"]; /* includes room for '\0' */
767 const char *result = "no-color";
768
769 if (colorindx >= 0) {
770 int32 basicindx = colorindx & ~NH_BASIC_COLOR;
771
772 /* if colorindx has NH_BASIC_COLOR bit set, basicindx won't,
773 so differing implies a basic color */
774 if (basicindx != colorindx) {
775 assert(basicindx < 16);
776 result = colortable[basicindx].name;
777 } else {
778 int indx;
779 long r = (colorindx >> 16) & 0x0000ff, /* shift rrXXXX to rr */
780 g = (colorindx >> 8) & 0x0000ff, /* shift XXggXX to gg */
781 b = colorindx & 0x0000ff; /* mask XXXXbb to bb */
782
783 Snprintf(hexcolor, sizeof hexcolor, "#%02x%02x%02x",
784 (uint8) r, (uint8) g, (uint8) b);
785 result = hexcolor;
786 /* override hex value if this is a named color */
787 for (indx = 16; indx < SIZE(colortable); ++indx)
788 if (colortable[indx].r == r
789 && colortable[indx].g == g
790 && colortable[indx].b == b) {
791 result = colortable[indx].name;
792 break;
793 }
794 }
795 }
796 return result;
797}
798
799/* hexdd[] is defined in decl.c */
800boolean

Callers 1

wc_set_window_colorsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected