X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fbackend%2FECMA48Terminal.java;h=f0b3e3cc20d7d936368a528b75062a77db087114;hb=f5b7a696dd45017ae70e6b8e66d919c58bfe6125;hp=518024c5d0099c07d22f5489cb7a69c1ba7a7106;hpb=c88c4ced6e9392a53030a1c680fe114931a1a928;p=nikiroo-utils.git diff --git a/src/jexer/backend/ECMA48Terminal.java b/src/jexer/backend/ECMA48Terminal.java index 518024c..f0b3e3c 100644 --- a/src/jexer/backend/ECMA48Terminal.java +++ b/src/jexer/backend/ECMA48Terminal.java @@ -85,6 +85,8 @@ public class ECMA48Terminal extends LogicalScreen * 1024. */ private static final int MAX_COLOR_REGISTERS = 1024; + // Black-and-white is possible too. + // private static final int MAX_COLOR_REGISTERS = 2; // ------------------------------------------------------------------------ // Variables -------------------------------------------------------------- @@ -342,6 +344,16 @@ public class ECMA48Terminal extends LogicalScreen int green = (color >>> 8) & 0xFF; int blue = color & 0xFF; + if (MAX_COLOR_REGISTERS == 2) { + if (((red * red) + (green * green) + (blue * blue)) < 35568) { + // Black + return 0; + } + // White + return 1; + } + + rgbToHsl(red, green, blue, hsl); int hue = hsl[0]; int sat = hsl[1]; @@ -662,6 +674,14 @@ public class ECMA48Terminal extends LogicalScreen // map the BufferedImage colors to their nearest neighbor in RGB // space. + if (MAX_COLOR_REGISTERS == 2) { + rgbColors.add(0); + rgbColors.add(0xFFFFFF); + rgbSortedIndex[0] = 0; + rgbSortedIndex[1] = 1; + return; + } + // We build a palette using the Hue-Saturation-Luminence model, // with 5+ bits for Hue, 2+ bits for Saturation, and 1+ bit for // Luminance. We convert these colors to 24-bit RGB, sort them