summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikael Magnusson <mikachu@gmail.com>2026-05-12 16:18:31 +0200
committerMikael Magnusson <mikachu@gmail.com>2026-05-16 18:28:31 +0200
commit75ebfe8cf1286ca877a6cc8a5b69bc53febb4aa3 (patch)
tree75bc871ee91a07eb134650d02d7028d85b887978
parent54558: ksh93: .sh.match handling with KSHARRAYS set was totally broken (diff)
downloadzsh-75ebfe8cf1286ca877a6cc8a5b69bc53febb4aa3.tar
zsh-75ebfe8cf1286ca877a6cc8a5b69bc53febb4aa3.tar.gz
zsh-75ebfe8cf1286ca877a6cc8a5b69bc53febb4aa3.tar.bz2
zsh-75ebfe8cf1286ca877a6cc8a5b69bc53febb4aa3.tar.lz
zsh-75ebfe8cf1286ca877a6cc8a5b69bc53febb4aa3.tar.xz
zsh-75ebfe8cf1286ca877a6cc8a5b69bc53febb4aa3.tar.zst
zsh-75ebfe8cf1286ca877a6cc8a5b69bc53febb4aa3.zip
54559: nearcolor was missing the third grayscale entry in 88 color mode
Adding a test for this is not trivial since tccolours is set directly from a termcap lookup, and is specifically documented in the code as "may not be set".
-rw-r--r--ChangeLog3
-rw-r--r--Src/Modules/nearcolor.c18
2 files changed, 15 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index f0652bc0e..7120c0df5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2026-05-16 Mikael Magnusson <mikachu@gmail.com>
+ * 54559: Src/Modules/nearcolor.c: nearcolor was missing the
+ third grayscale entry in 88 color mode
+
* 54558: Src/Modules/ksh93.c: ksh93: .sh.match handling with
KSHARRAYS set was totally broken
diff --git a/Src/Modules/nearcolor.c b/Src/Modules/nearcolor.c
index 83d7118b0..08bc7d8b1 100644
--- a/Src/Modules/nearcolor.c
+++ b/Src/Modules/nearcolor.c
@@ -37,13 +37,19 @@ struct cielab {
};
typedef struct cielab *Cielab;
+static inline double
+square(double a)
+{
+ return a*a;
+}
+
static double
deltae(Cielab lab1, Cielab lab2)
{
/* taking square root unnecessary as we're just comparing values */
- return pow(lab1->L - lab2->L, 2) +
- pow(lab1->a - lab2->a, 2) +
- pow(lab1->b - lab2->b, 2);
+ return square(lab1->L - lab2->L) +
+ square(lab1->a - lab2->a) +
+ square(lab1->b - lab2->b);
}
static void
@@ -73,7 +79,7 @@ RGBtoLAB(int red, int green, int blue, Cielab lab)
static int
mapRGBto88(int red, int green, int blue)
{
- int component[] = { 0, 0x8b, 0xcd, 0xff, 0x2e, 0x5c, 0x8b, 0xa2, 0xb9, 0xd0, 0xe7 };
+ int component[] = { 0, 0x8b, 0xcd, 0xff, 0x2e, 0x5c, 0x73, 0x8b, 0xa2, 0xb9, 0xd0, 0xe7 };
struct cielab orig, next;
double nextl, bestl = -1;
int r, g, b;
@@ -83,7 +89,7 @@ mapRGBto88(int red, int green, int blue)
RGBtoLAB(red, green, blue, &orig);
/* try every one of the 72 colours */
- for (r = 0; r < 11; r++) {
+ for (r = 0; r < 12; r++) {
for (g = 0; g <= 3; g++) {
for (b = 0; b <= 3; b++) {
if (r > 3) g = b = r; /* advance inner loops to the block of greys */
@@ -99,7 +105,7 @@ mapRGBto88(int red, int green, int blue)
}
}
- return (comp_r > 3) ? 77 + comp_r :
+ return (comp_r > 3) ? 76 + comp_r :
16 + (comp_r * 16) + (comp_g * 4) + comp_b;
}