diff --git a/include/extern.h b/include/extern.h index acef12e9d..1f69f8940 100644 --- a/include/extern.h +++ b/include/extern.h @@ -319,7 +319,7 @@ extern int count_menucolors(void); extern int32 check_enhanced_colors(char *) NONNULLARG1; extern const char *wc_color_name(int32) NONNULL; extern int32_t rgbstr_to_int32(const char *rgbstr); -extern boolean closest_color(uint32_t lcolor, uint32_t *closecolor, int *clridx); +extern boolean closest_color(uint32_t lcolor, uint32_t *closecolor, uint16 *clridx); extern int color_distance(uint32_t, uint32_t); extern boolean onlyhexdigits(const char *buf); extern uint32 get_nhcolor_from_256_index(int idx); @@ -1098,7 +1098,7 @@ struct customization_detail *find_matching_customization( const char *customization_name, enum customization_types custtype, enum graphics_sets which_set); -int set_map_nhcolor(glyph_map *gm, uint32 nhcolor) NONNULLARG1; +int set_map_customcolor(glyph_map *gm, uint32 nhcolor) NONNULLARG1; extern int unicode_val(const char *); extern int glyphrep(const char *) NONNULLARG1; extern int match_glyph(char *) NONNULLARG1; diff --git a/include/wintype.h b/include/wintype.h index f56865a39..ee72bd6e0 100644 --- a/include/wintype.h +++ b/include/wintype.h @@ -84,6 +84,7 @@ typedef struct glyph_map_entry { unsigned glyphflags; struct classic_representation sym; uint32 customcolor; + uint16 color256idx; short int tileidx; #ifdef ENHANCED_SYMBOLS struct unicode_representation *u; diff --git a/src/coloratt.c b/src/coloratt.c index 13207bf5a..6be07d790 100644 --- a/src/coloratt.c +++ b/src/coloratt.c @@ -853,14 +853,20 @@ rgbstr_to_int32(const char *rgbstr) } int -set_map_nhcolor(glyph_map *gmap, uint32 nhcolor) +set_map_customcolor(glyph_map *gmap, uint32 nhcolor) { glyph_map *tmpgm = gmap; + uint32 closecolor = 0; + uint16 clridx = 0; if (!tmpgm) return 0; gmap->customcolor = nhcolor; + if (closest_color(nhcolor, &closecolor, &clridx)) + gmap->color256idx = clridx; + else + gmap->color256idx = 0; return 1; } @@ -976,7 +982,7 @@ color_distance(uint32_t rgb1, uint32_t rgb2) } boolean -closest_color(uint32 lcolor, uint32 *closecolor, int *clridx) +closest_color(uint32 lcolor, uint32 *closecolor, uint16 *clridx) { int i, color_index = -1, similar = INT_MAX, current; boolean retbool = FALSE; diff --git a/src/display.c b/src/display.c index b6647f8b3..f22bbcb24 100644 --- a/src/display.c +++ b/src/display.c @@ -1566,12 +1566,12 @@ see_traps(void) } /* glyph, ttychar, framecolor, - { glyphflags, { NO_COLOR, sym.symidx }, nhcolor, tileidx, u } */ + { glyphflags, { NO_COLOR, sym.symidx }, customcolor, color256idx, tileidx, u } */ static glyph_info no_ginfo = { NO_GLYPH, ' ', NO_COLOR, { MG_BADXY, { NO_COLOR, 0 }, 0, - 0 + 0U, 0U #ifdef ENHANCED_SYMBOLS , 0 #endif @@ -1602,7 +1602,7 @@ const glyph_info nul_glyphinfo = { MG_UNEXPL, { NO_COLOR, SYM_UNEXPLORED + SYM_OFF_X }, 0, - 0 + 0U, 0U #ifdef ENHANCED_SYMBOLS , 0 #endif @@ -1616,7 +1616,7 @@ extern glyph_map glyphmap[MAX_GLYPH]; /* from tile.c */ glyph_map glyphmap[MAX_GLYPH] = { { 0U, { NO_COLOR, 0 }, 0, - 0 + 0U, 0U #ifdef ENHANCED_SYMBOLS , 0 #endif @@ -2029,7 +2029,7 @@ static gbuf_entry nul_gbuf = { /* glyphinfo.gm */ { MG_UNEXPL, { NO_COLOR, 0 }, 0, - 0 + 0U, 0U #ifdef ENHANCED_SYMBOLS , 0 #endif diff --git a/src/glyphs.c b/src/glyphs.c index 58d467b27..0315b0be0 100644 --- a/src/glyphs.c +++ b/src/glyphs.c @@ -483,7 +483,7 @@ apply_customizations( if (iflags.customcolors && do_colors) { if (sc->custtype == custom_nhcolor) { gmap = &glyphmap[details->content.ccolor.glyphidx]; - (void) set_map_nhcolor(gmap, + (void) set_map_customcolor(gmap, details->content.ccolor.nhcolor); } } @@ -1051,6 +1051,7 @@ clear_all_glyphmap_colors(void) for (glyph = 0; glyph < MAX_GLYPH; ++glyph) { if (glyphmap[glyph].customcolor) glyphmap[glyph].customcolor = 0; + glyphmap[glyph].color256idx = 0; } } diff --git a/win/X11/winmap.c b/win/X11/winmap.c index f82a2688c..110cc8953 100644 --- a/win/X11/winmap.c +++ b/win/X11/winmap.c @@ -139,17 +139,11 @@ X11_print_glyph( if ((glyphinfo->gm.customcolor & NH_BASIC_COLOR) != 0) { /* NH_BASIC_COLOR */ color = COLORVAL(glyphinfo->gm.customcolor); -#if 0 } else if (iflags.colorcount == 256 && (X11_procs.wincap2 & WC2_EXTRACOLORS) != 0 && (glyphinfo->gm.customcolor & NH_BASIC_COLOR) == 0) { - int clr256idx; - uint32 closecolor = 0; - - if (closest_color(COLORVAL(glyphinfo->gm.customcolor), - &closecolor, &clr256idx)) - nhcolor = COLORVAL(closecolor); -#endif + uint32 closecolor = get_nhcolor_from_256_index(glyphinfo->gm.color256idx); + nhcolor = COLORVAL(closecolor); } else { /* 24-bit color, NH_BASIC_COLOR == 0 */ nhcolor = COLORVAL(glyphinfo->gm.customcolor); diff --git a/win/share/tilemap.c b/win/share/tilemap.c index 2a279d782..6fd2a2803 100644 --- a/win/share/tilemap.c +++ b/win/share/tilemap.c @@ -1362,7 +1362,7 @@ main(int argc UNUSED, char *argv[] UNUSED) Fprintf(ofp, "%smaxothtile = %d;\n\n", indent, lastothtile); Fprintf(ofp, "#define NO_CUSTOMCOLOR (0U)\n\n"); Fprintf(ofp, "/* glyph, ttychar, { %s%s } */\n", - "glyphflags, { NO_COLOR, symidx }, NO_CUSTOMCOLOR, ovidx, tileidx", enhanced); + "glyphflags, { NO_COLOR, symidx }, NO_CUSTOMCOLOR, NO_CUSTOMCOLOR, ovidx, tileidx", enhanced); #ifdef ENHANCED_SYMBOLS enhanced = ", 0"; /* replace ", utf8rep" since we're done with that */ #endif @@ -1370,7 +1370,7 @@ main(int argc UNUSED, char *argv[] UNUSED) Fprintf(ofp, "%sNO_GLYPH, ' ', NO_COLOR,\n", indent); Fprintf(ofp, "%s%s/* glyph_map */\n", indent, indent); Fprintf(ofp, "%s%s{ %s, TILE_UNEXPLORED%s }\n", indent, indent, - "MG_UNEXPL, { NO_COLOR, SYM_UNEXPLORED + SYM_OFF_X }, NO_CUSTOMCOLOR", + "MG_UNEXPL, { NO_COLOR, SYM_UNEXPLORED + SYM_OFF_X }, NO_CUSTOMCOLOR, NO_CUSTOMCOLOR", enhanced); Fprintf(ofp, "};\n"); Fprintf(ofp, "\nglyph_map glyphmap[MAX_GLYPH] = {\n"); @@ -1385,7 +1385,7 @@ main(int argc UNUSED, char *argv[] UNUSED) /*NOTREACHED*/ } Fprintf(ofp, - " { 0U, { NO_COLOR, 0 }, NO_CUSTOMCOLOR, %4d%s }, /* [%04d] %s:%03d %s */\n", + " { 0U, { NO_COLOR, 0 }, NO_CUSTOMCOLOR, NO_CUSTOMCOLOR, %4d%s }, /* [%04d] %s:%03d %s */\n", tilenum, enhanced, i, tilesrc_texts[tilelist[tilenum]->src], tilelist[tilenum]->file_entry, diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 1969a1c0d..b2739a468 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -3849,18 +3849,9 @@ tty_print_glyph( if ((glyphinfo->gm.customcolor & NH_BASIC_COLOR) != 0) { /* don't set colordone or nhcolor */ color = COLORVAL(glyphinfo->gm.customcolor); -#if 0 } else if (iflags.colorcount == 256) { - if (closest_color(COLORVAL(glyphinfo->gm.customcolor), - &closecolor, &clridx)) { - if (ttyDisplay->color != NO_COLOR) { - term_end_color(); - } - ttyDisplay->colorflags = 0; - term_start_256color(clridx); - colordone = TRUE; - } -#endif + ttyDisplay->colorflags = 0; /* not NH_BASIC_COLOR */ + term_start_256color(glyphinfo->gm.color256idx); } else { nhcolor = COLORVAL(glyphinfo->gm.customcolor); ttyDisplay->colorflags = 0;