增加QrXXX

This commit is contained in:
Looly
2022-09-15 19:12:50 +08:00
parent eba3332eaf
commit 37e971c4bc
10 changed files with 514 additions and 220 deletions

View File

@@ -10,8 +10,6 @@ import java.util.LinkedHashMap;
* @author Tom Xin
*/
public class Ansi8bitMapping extends AnsiLabMapping {
public static final Ansi8bitMapping INSTANCE = new Ansi8bitMapping();
private static final int[] ANSI_8BIT_COLOR_CODE_LOOKUP = new int[] { 0x000000, 0x800000, 0x008000, 0x808000,
0x000080, 0x800080, 0x008080, 0xc0c0c0, 0x808080, 0xff0000, 0x00ff00, 0xffff00, 0x0000ff, 0xff00ff,
0x00ffff, 0xffffff, 0x000000, 0x00005f, 0x000087, 0x0000af, 0x0000d7, 0x0000ff, 0x005f00, 0x005f5f,
@@ -40,6 +38,8 @@ public class Ansi8bitMapping extends AnsiLabMapping {
0x808080, 0x8a8a8a, 0x949494, 0x9e9e9e, 0xa8a8a8, 0xb2b2b2, 0xbcbcbc, 0xc6c6c6, 0xd0d0d0, 0xdadada,
0xe4e4e4, 0xeeeeee };
public static final Ansi8bitMapping INSTANCE = new Ansi8bitMapping();
public Ansi8bitMapping() {
ansiLabMap = new LinkedHashMap<>(256, 1);
for (int i = 0; i < ANSI_8BIT_COLOR_CODE_LOOKUP.length; i++) {

View File

@@ -197,6 +197,18 @@ public class ColorUtil {
return new Color(random.nextInt(RGB_COLOR_BOUND), random.nextInt(RGB_COLOR_BOUND), random.nextInt(RGB_COLOR_BOUND));
}
/**
* AWT的{@link Color}颜色转换为ANSI颜色由于取最接近颜色故可能有色差
*
* @param rgb RGB颜色
* @param is8Bit 是否8bit的ANSI颜色
* @param isBackground 是否背景色
* @return ANSI颜色
*/
public static AnsiElement toAnsiColor(int rgb, boolean is8Bit, boolean isBackground) {
return toAnsiColor(getColor(rgb), is8Bit, isBackground);
}
/**
* AWT的{@link Color}颜色转换为ANSI颜色由于取最接近颜色故可能有色差
*