shade = (shade + 1) * 0xFFFF / (NEXTCOLOURS - 216 + 1);
shade = shade * 0x0a0a + 0x0808;
void palette_reset(void *frontend){    struct gui_data *inst = (struct gui_data *)frontend;    /* This maps colour indices in inst->cfg to those used in inst->cols. */    static const int ww[] = {	256, 257, 258, 259, 260, 261,	0, 8, 1, 9, 2, 10, 3, 11,	4, 12, 5, 13, 6, 14, 7, 15    };    gboolean success[NALLCOLOURS];    int i;    assert(lenof(ww) == NCFGCOLOURS);    if (!inst->colmap) {	inst->colmap = gdk_colormap_get_system();    } else {	gdk_colormap_free_colors(inst->colmap, inst->cols, NALLCOLOURS);    }    for (i = 0; i < NCFGCOLOURS; i++) {	inst->cols[ww[i]].red = inst->cfg.colours[i][0] * 0x0101;	inst->cols[ww[i]].green = inst->cfg.colours[i][1] * 0x0101;	inst->cols[ww[i]].blue = inst->cfg.colours[i][2] * 0x0101;    }    for (i = 0; i < NEXTCOLOURS; i++) {	if (i < 216) {	    int r = i / 36, g = (i / 6) % 6, b = i % 6;	    inst->cols[i+16].red = r * 0x3333;	    inst->cols[i+16].green = g * 0x3333;	    inst->cols[i+16].blue = b * 0x3333;	} else {	    int shade = i - 216;	    shade = (shade + 1) * 0xFFFF / (NEXTCOLOURS - 216 + 1);	    inst->cols[i+16].red = inst->cols[i+16].green =		inst->cols[i+16].blue = shade;	}    }    gdk_colormap_alloc_colors(inst->colmap, inst->cols, NALLCOLOURS,			      FALSE, TRUE, success);    for (i = 0; i < NALLCOLOURS; i++) {	if (!success[i])	    g_error("%s: couldn't allocate colour %d (#%02x%02x%02x)\n",                    appname, i, inst->cfg.colours[i][0],                    inst->cfg.colours[i][1], inst->cfg.colours[i][2]);    }    set_window_background(inst);}