From 849563285c6dd433aae72198531c3403856d0efd Mon Sep 17 00:00:00 2001 From: Vftdan Date: Wed, 2 Oct 2024 23:57:12 +0200 Subject: [PATCH] Global resizeable palette --- img2cpi.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/img2cpi.c b/img2cpi.c index f2da4e4..ee81cf3 100644 --- a/img2cpi.c +++ b/img2cpi.c @@ -99,6 +99,10 @@ void get_size_keep_aspect(int w, int h, int dw, int dh, int *ow, int *oh); void convert_2x3(const struct image_pal *img, struct cc_char *characters); void convert_8x11(const struct image_pal *img, struct cc_char *characters); +// Only one global custom palette is maintained +struct palette *custom_palette_resize(uint8_t size); +struct palette *custom_palette_from(const struct palette *orig); + const char *known_file_extensions[] = { ".png", ".jpg", ".jpeg", ".jfif", ".jpg", ".gif", ".tga", ".bmp", ".hdr", ".pnm", 0 @@ -632,6 +636,24 @@ void convert_8x11(const struct image_pal *img, struct cc_char *characters) { } } +struct { + uint8_t count; + union color colors[256]; +} custom_palette_data; + +struct palette *custom_palette_resize(uint8_t size) { + custom_palette_data.count = size; + return (struct palette*)&custom_palette_data; +} + +struct palette *custom_palette_from(const struct palette *orig) { + custom_palette_data.count = orig->count; + for (int i = 0; i < custom_palette_data.count; i++) { + custom_palette_data.colors[i] = orig->colors[i]; + } + return (struct palette*)&custom_palette_data; +} + const struct palette DEFAULT_PALETTE = PALETTE( { { 0xf0, 0xf0, 0xf0, 0xff } }, { { 0xf2, 0xb2, 0x33, 0xff } },