public static final int getShadedColor(int color, int lightness, int flag) {
		if (color == 65535) {
			return 0;
		}
		if ((flag & 2) == 2) {
			if (lightness < 0) {
				lightness = 0;
			} else if (lightness > 127) {
				lightness = 127;
			}
			lightness = 127 - lightness;
			return lightness;
		}
		lightness = lightness * (color & 0x7f) >> 7;
		if (lightness < 2) {
			lightness = 2;
		} else if (lightness > 126) {
			lightness = 126;
		}
		return (color & 0xff80) + lightness;
	}