commit ca583e3a474425802d73790e0ed62254ff7eb198
parent fef4d2cd186740936d83aeb2fb43fa458b0c7720
Author: Frederic Cambus <fred@statdns.com>
Date: Fri, 19 Jun 2020 23:13:45 +0200
Separate RGB values for palettes, makes color allocation code more readable and efficient.
Diffstat:
5 files changed, 53 insertions(+), 28 deletions(-)
diff --git a/src/config.h b/src/config.h
@@ -15,27 +15,52 @@
#include <stdint.h>
-static const uint8_t ansi_palette[] = {
- 0x00, 0x00, 0x00, 0xaa, 0x00, 0x00, 0x00, 0xaa, 0x00, 0xaa, 0x55, 0x00,
- 0x00, 0x00, 0xaa, 0xaa, 0x00, 0xaa, 0x00, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0x55, 0x55, 0x55, 0xff, 0x55, 0x55, 0x55, 0xff, 0x55, 0xff, 0xff, 0x55,
- 0x55, 0x55, 0xff, 0xff, 0x55, 0xff, 0x55, 0xff, 0xff, 0xff, 0xff, 0xff
+static const uint8_t ansi_palette_red[] = {
+ 0x00, 0xaa, 0x00, 0xaa, 0x00, 0xaa, 0x00, 0xaa,
+ 0x55, 0xff, 0x55, 0xff, 0x55, 0xff, 0x55, 0xff
};
-static const uint8_t workbench_palette[] = {
- 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x66, 0x88, 0xbb,
- 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x66, 0x88, 0xbb,
- 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff
+static const uint8_t ansi_palette_green[] = {
+ 0x00, 0x00, 0xaa, 0x55, 0x00, 0x00, 0xaa, 0xaa,
+ 0x55, 0x55, 0xff, 0xff, 0x55, 0x55, 0xff, 0xff
};
-static const uint8_t vga_palette[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0x00, 0xaa, 0x00, 0x00, 0xaa, 0xaa,
- 0xaa, 0x00, 0x00, 0xaa, 0x00, 0xaa, 0xaa, 0x55, 0x00, 0xaa, 0xaa, 0xaa,
- 0x55, 0x55, 0x55, 0x55, 0x55, 0xff, 0x55, 0xff, 0x55, 0x55, 0xff, 0xff,
- 0xff, 0x55, 0x55, 0xff, 0x55, 0xff, 0xff, 0xff, 0x55, 0xff, 0xff, 0xff
+static const uint8_t ansi_palette_blue[] = {
+ 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0x55, 0x55, 0x55, 0x55, 0xff, 0xff, 0xff, 0xff
};
+static const uint8_t workbench_palette_red[] = {
+ 0xaa, 0x00, 0xff, 0x66, 0x00, 0xff, 0x00, 0xff,
+ 0xaa, 0x00, 0xff, 0x66, 0x00, 0xff, 0x00, 0xff
+};
+
+static const uint8_t workbench_palette_green[] = {
+ 0xaa, 0x00, 0xff, 0x88, 0x00, 0x00, 0xff, 0xff,
+ 0xaa, 0x00, 0xff, 0x88, 0x00, 0x00, 0xff, 0xff
+};
+
+static const uint8_t workbench_palette_blue[] = {
+ 0xaa, 0x00, 0xff, 0xbb, 0xff, 0xff, 0xff, 0xff,
+ 0xaa, 0x00, 0xff, 0xbb, 0xff, 0xff, 0xff, 0xff
+};
+
+static const uint8_t vga_palette_red[] = {
+ 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0x55, 0x55, 0x55, 0x55, 0xff, 0xff, 0xff, 0xff
+};
+
+static const uint8_t vga_palette_green[] = {
+ 0x00, 0x00, 0xaa, 0xaa, 0x00, 0x00, 0x55, 0xaa,
+ 0x55, 0x55, 0xff, 0xff, 0x55, 0x55, 0xff, 0xff
+};
+
+static const uint8_t vga_palette_blue[] = {
+ 0x00, 0xaa, 0x00, 0xaa, 0x00, 0xaa, 0x00, 0xaa,
+ 0x55, 0xff, 0x55, 0xff, 0x55, 0xff, 0x55, 0xff
+};
+
+
static const uint8_t pcb_colors[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
diff --git a/src/loaders/ansi.c b/src/loaders/ansi.c
@@ -486,16 +486,17 @@ ansilove_ansi(struct ansilove_ctx *ctx, struct ansilove_options *options)
gdImageFill(canvas, 0, 0, ced_background);
} else if (workbench) {
for (size_t i = 0; i < 16; i++)
- colors[i] = gdImageColorAllocate(canvas, workbench_palette[i*3],
- workbench_palette[i*3+1],
- workbench_palette[i*3+2]);
+ colors[i] = gdImageColorAllocate(canvas,
+ workbench_palette_red[i],
+ workbench_palette_green[i],
+ workbench_palette_blue[i]);
} else {
/* Allocate standard ANSi color palette */
for (size_t i = 0; i < 16; i++)
- colors[i] = gdImageColorAllocate(canvas, ansi_palette[i*3],
- ansi_palette[i*3+1],
- ansi_palette[i*3+2]);
+ colors[i] = gdImageColorAllocate(canvas,
+ ansi_palette_red[i], ansi_palette_green[i],
+ ansi_palette_blue[i]);
}
/* render ANSi */
diff --git a/src/loaders/binary.c b/src/loaders/binary.c
@@ -55,8 +55,8 @@ ansilove_binary(struct ansilove_ctx *ctx, struct ansilove_options *options)
uint32_t colors[16];
for (size_t i = 0; i < 16; i++) {
- colors[i] = gdImageColorAllocate(canvas, vga_palette[i*3],
- vga_palette[i*3+1], vga_palette[i*3+2]);
+ colors[i] = gdImageColorAllocate(canvas, vga_palette_red[i],
+ vga_palette_green[i], vga_palette_blue[i]);
}
/* process binary */
diff --git a/src/loaders/pcboard.c b/src/loaders/pcboard.c
@@ -165,9 +165,8 @@ ansilove_pcboard(struct ansilove_ctx *ctx, struct ansilove_options *options)
uint32_t colors[16];
for (size_t i = 0; i < 16; i++) {
- colors[i] = gdImageColorAllocate(canvas, ansi_palette[i*3],
- ansi_palette[i*3+1],
- ansi_palette[i*3+2]);
+ colors[i] = gdImageColorAllocate(canvas, ansi_palette_red[i],
+ ansi_palette_green[i], ansi_palette_blue[i]);
}
/* render PCB */
diff --git a/src/loaders/xbin.c b/src/loaders/xbin.c
@@ -94,8 +94,8 @@ ansilove_xbin(struct ansilove_ctx *ctx, struct ansilove_options *options)
} else {
for (size_t i = 0; i < 16; i++) {
colors[i] = gdImageColorAllocate(canvas,
- vga_palette[i*3], vga_palette[i*3+1],
- vga_palette[i*3+2]);
+ vga_palette_red[i], vga_palette_green[i],
+ vga_palette_blue[i]);
}
}