X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjexer%2Fbackend%2FECMA48Terminal.java;h=f0b3e3cc20d7d936368a528b75062a77db087114;hb=3a4a5f00d46f6376f05c2de1c97e9cc298ea97f9;hp=0cbd4f0502f9ca96a73136b4f1d995efa219a682;hpb=9696a8f6da9a0d204740420d6d8571176ab81944;p=nikiroo-utils.git diff --git a/src/jexer/backend/ECMA48Terminal.java b/src/jexer/backend/ECMA48Terminal.java index 0cbd4f0..f0b3e3c 100644 --- a/src/jexer/backend/ECMA48Terminal.java +++ b/src/jexer/backend/ECMA48Terminal.java @@ -45,7 +45,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.LinkedList; -import java.util.Map; import jexer.TImage; import jexer.bits.Cell; @@ -86,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 -------------------------------------------------------------- @@ -343,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]; @@ -663,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