commit 2046625e2948b915fb5f7b6244e54f79cf2c2a8a
parent 2f8f9b16e1834cdd577d590efc51be17f3013585
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Thu, 21 Dec 2023 19:57:04 +0100
fen.c: optimization for size: do not use true-color where its not needed
- Reduces file size.
- Simplify creating a checkered pattern.
Diffstat:
M | fen.c | | | 77 | +++++++++++++++++++++++------------------------------------------------------ |
1 file changed, 23 insertions(+), 54 deletions(-)
diff --git a/fen.c b/fen.c
@@ -180,17 +180,10 @@ showboard_svg(void)
for (ix = 0; ix < 8; ix++) {
x = flipboard ? 7 - ix : ix;
- if (x % 2 == 0) {
- if (y % 2 == 0)
- color = highlight[y][x] ? lightsquarehi : lightsquare;
- else
- color = highlight[y][x] ? darksquarehi : darksquare;
- } else {
- if (y % 2 == 0)
- color = highlight[y][x] ? darksquarehi : darksquare;
- else
- color = highlight[y][x] ? lightsquarehi : lightsquare;
- }
+ if (((x % 2) ^ (y % 2)) == 0)
+ color = highlight[y][x] ? lightsquarehi : lightsquare;
+ else
+ color = highlight[y][x] ? darksquarehi : darksquare;
printf("<g><rect x=\"%d\" y=\"%d\" width=\"45\" height=\"45\" fill=\"#%02x%02x%02x\"/></g>\n",
ix * 45, iy * 45, color[0], color[1], color[2]);
@@ -211,17 +204,10 @@ showboard_svg(void)
y = flipboard ? 7 - iy : iy;
/* inverse square color for text */
- if (x % 2 == 0) {
- if (y % 2 == 0)
- color = highlight[y][x] ? darksquarehi : darksquare;
- else
- color = highlight[y][x] ? lightsquarehi : lightsquare;
- } else {
- if (y % 2 == 0)
- color = highlight[y][x] ? lightsquarehi : lightsquare;
- else
- color = highlight[y][x] ? darksquarehi : darksquare;
- }
+ if (((x % 2) ^ (y % 2)) == 0)
+ color = highlight[y][x] ? darksquarehi : darksquare;
+ else
+ color = highlight[y][x] ? lightsquarehi : lightsquare;
printf("<text x=\"%d\" y=\"%d\" fill=\"#%02x%02x%02x\" text-anchor=\"end\" style=\"font-family: sans-serif; font-size: 10px\">%c</text>\n",
(ix + 1) * 45 - 2, (iy * 45) + 10, color[0], color[1], color[2], '8' - y);
@@ -293,9 +279,7 @@ showboard_tty(void)
showboardfen();
printf("\n\n");
- color = border;
- SETBGCOLOR(color[0], color[1], color[2]);
- SETFGCOLOR(0xff, 0xff, 0xff);
+ SETBGCOLOR(border[0], border[1], border[2]);
fputs(" ", stdout);
printf("\x1b[0m"); /* reset */
putchar('\n');
@@ -303,34 +287,26 @@ showboard_tty(void)
for (iy = 0; iy < 8; iy++) {
y = flipboard ? 7 - iy : iy;
- color = border;
- SETBGCOLOR(color[0], color[1], color[2]);
- SETFGCOLOR(0xff, 0xff, 0xff);
+ SETBGCOLOR(border[0], border[1], border[2]);
+ fputs("\x1b[97m", stdout); /* bright white */
fputs(" ", stdout);
for (ix = 0; ix < 8; ix++) {
x = flipboard ? 7 - ix : ix;
- if (x % 2 == 0) {
- if (y % 2 == 0)
- color = highlight[y][x] ? lightsquarehi : lightsquare;
- else
- color = highlight[y][x] ? darksquarehi : darksquare;
- } else {
- if (y % 2 == 0)
- color = highlight[y][x] ? darksquarehi : darksquare;
- else
- color = highlight[y][x] ? lightsquarehi : lightsquare;
- }
+ if (((x % 2) ^ (y % 2)) == 0)
+ color = highlight[y][x] ? lightsquarehi : lightsquare;
+ else
+ color = highlight[y][x] ? darksquarehi : darksquare;
SETBGCOLOR(color[0], color[1], color[2]);
fputs(" ", stdout);
piece = getpiece(x, y);
if (piece) {
if (piece >= 'A' && piece <= 'Z')
- SETFGCOLOR(0xff, 0xff, 0xff);
+ fputs("\x1b[97m", stdout); /* bright white */
else
- SETFGCOLOR(0x00, 0x00, 0x00);
+ fputs("\x1b[30m", stdout); /* black */
/* workaround: use black unicode chess symbol, because
the color is filled and better visible */
showpiece_tty(tolower(piece));
@@ -343,8 +319,8 @@ showboard_tty(void)
color = border;
SETBGCOLOR(color[0], color[1], color[2]);
- SETFGCOLOR(0xff, 0xff, 0xff);
if (showcoords) {
+ fputs("\x1b[97m", stdout); /* bright white */
putchar('8' - y);
putchar(' ');
} else {
@@ -356,7 +332,7 @@ showboard_tty(void)
}
color = border;
SETBGCOLOR(color[0], color[1], color[2]);
- SETFGCOLOR(0xff, 0xff, 0xff);
+ fputs("\x1b[97m", stdout); /* bright white */
if (showcoords) {
if (flipboard)
fputs(" h g f e d c b a ", stdout);
@@ -403,17 +379,10 @@ showboard_ascii(void)
for (ix = 0; ix < 8; ix++) {
x = flipboard ? 7 - ix : ix;
- if (x % 2 == 0) {
- if (y % 2 == 0)
- color = highlight[y][x] ? hi : light;
- else
- color = highlight[y][x] ? hi : dark;
- } else {
- if (y % 2 == 0)
- color = highlight[y][x] ? hi : dark;
- else
- color = highlight[y][x] ? hi : light;
- }
+ if (((x % 2) ^ (y % 2)) == 0)
+ color = highlight[y][x] ? hi : light;
+ else
+ color = highlight[y][x] ? hi : dark;
if (ix == 0)
putchar('|');