···
403
+
#ifdef FLANTERM_FB_SUPPORT_BPP
404
+
static __attribute__((always_inline)) uint32_t convert_colour(struct flanterm_context *_ctx, uint32_t colour) {
405
+
struct flanterm_fb_context *ctx = (void *)_ctx;
406
+
uint32_t r = (colour >> 16) & 0xff;
407
+
uint32_t g = (colour >> 8) & 0xff;
408
+
uint32_t b = colour & 0xff;
409
+
return (r << ctx->red_mask_shift) | (g << ctx->green_mask_shift) | (b << ctx->blue_mask_shift);
412
+
#define convert_colour(CTX, COLOUR) (COLOUR)
static void flanterm_fb_save_state(struct flanterm_context *_ctx) {
struct flanterm_fb_context *ctx = (void *)_ctx;
ctx->saved_state_text_fg = ctx->text_fg;
···
static void flanterm_fb_set_text_fg_rgb(struct flanterm_context *_ctx, uint32_t fg) {
struct flanterm_fb_context *ctx = (void *)_ctx;
695
+
ctx->text_fg = convert_colour(_ctx, fg);
static void flanterm_fb_set_text_bg_rgb(struct flanterm_context *_ctx, uint32_t bg) {
struct flanterm_fb_context *ctx = (void *)_ctx;
701
+
ctx->text_bg = convert_colour(_ctx, bg);
static void flanterm_fb_set_text_fg_default(struct flanterm_context *_ctx) {
···
void *(*_malloc)(size_t),
void (*_free)(void *, size_t),
uint32_t *framebuffer, size_t width, size_t height, size_t pitch,
864
+
#ifdef FLANTERM_FB_SUPPORT_BPP
865
+
uint8_t red_mask_size, uint8_t red_mask_shift,
866
+
uint8_t green_mask_size, uint8_t green_mask_shift,
867
+
uint8_t blue_mask_size, uint8_t blue_mask_shift,
#ifndef FLANTERM_FB_DISABLE_CANVAS
···
size_t orig_bump_alloc_ptr = bump_alloc_ptr;
883
+
#ifdef FLANTERM_FB_SUPPORT_BPP
884
+
if (red_mask_size < 8 || red_mask_size != green_mask_size || red_mask_size != blue_mask_size) {
#ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC
···
struct flanterm_context *_ctx = (void *)ctx;
memset(ctx, 0, sizeof(struct flanterm_fb_context));
906
+
#ifdef FLANTERM_FB_SUPPORT_BPP
907
+
ctx->red_mask_size = red_mask_size;
908
+
ctx->red_mask_shift = red_mask_shift + (red_mask_size - 8);
909
+
ctx->green_mask_size = green_mask_size;
910
+
ctx->green_mask_shift = green_mask_shift + (green_mask_size - 8);
911
+
ctx->blue_mask_size = blue_mask_size;
912
+
ctx->blue_mask_shift = blue_mask_shift + (blue_mask_size - 8);
if (ansi_colours != NULL) {
885
-
memcpy(ctx->ansi_colours, ansi_colours, sizeof(ctx->ansi_colours));
916
+
for (size_t i = 0; i < 8; i++) {
917
+
ctx->ansi_colours[i] = convert_colour(_ctx, ansi_colours[i]);
887
-
ctx->ansi_colours[0] = 0x00000000; // black
888
-
ctx->ansi_colours[1] = 0x00aa0000; // red
889
-
ctx->ansi_colours[2] = 0x0000aa00; // green
890
-
ctx->ansi_colours[3] = 0x00aa5500; // brown
891
-
ctx->ansi_colours[4] = 0x000000aa; // blue
892
-
ctx->ansi_colours[5] = 0x00aa00aa; // magenta
893
-
ctx->ansi_colours[6] = 0x0000aaaa; // cyan
894
-
ctx->ansi_colours[7] = 0x00aaaaaa; // grey
920
+
ctx->ansi_colours[0] = convert_colour(_ctx, 0x00000000); // black
921
+
ctx->ansi_colours[1] = convert_colour(_ctx, 0x00aa0000); // red
922
+
ctx->ansi_colours[2] = convert_colour(_ctx, 0x0000aa00); // green
923
+
ctx->ansi_colours[3] = convert_colour(_ctx, 0x00aa5500); // brown
924
+
ctx->ansi_colours[4] = convert_colour(_ctx, 0x000000aa); // blue
925
+
ctx->ansi_colours[5] = convert_colour(_ctx, 0x00aa00aa); // magenta
926
+
ctx->ansi_colours[6] = convert_colour(_ctx, 0x0000aaaa); // cyan
927
+
ctx->ansi_colours[7] = convert_colour(_ctx, 0x00aaaaaa); // grey
if (ansi_bright_colours != NULL) {
898
-
memcpy(ctx->ansi_bright_colours, ansi_bright_colours, sizeof(ctx->ansi_bright_colours));
931
+
for (size_t i = 0; i < 8; i++) {
932
+
ctx->ansi_bright_colours[i] = convert_colour(_ctx, ansi_bright_colours[i]);
900
-
ctx->ansi_bright_colours[0] = 0x00555555; // black
901
-
ctx->ansi_bright_colours[1] = 0x00ff5555; // red
902
-
ctx->ansi_bright_colours[2] = 0x0055ff55; // green
903
-
ctx->ansi_bright_colours[3] = 0x00ffff55; // brown
904
-
ctx->ansi_bright_colours[4] = 0x005555ff; // blue
905
-
ctx->ansi_bright_colours[5] = 0x00ff55ff; // magenta
906
-
ctx->ansi_bright_colours[6] = 0x0055ffff; // cyan
907
-
ctx->ansi_bright_colours[7] = 0x00ffffff; // grey
935
+
ctx->ansi_bright_colours[0] = convert_colour(_ctx, 0x00555555); // black
936
+
ctx->ansi_bright_colours[1] = convert_colour(_ctx, 0x00ff5555); // red
937
+
ctx->ansi_bright_colours[2] = convert_colour(_ctx, 0x0055ff55); // green
938
+
ctx->ansi_bright_colours[3] = convert_colour(_ctx, 0x00ffff55); // brown
939
+
ctx->ansi_bright_colours[4] = convert_colour(_ctx, 0x005555ff); // blue
940
+
ctx->ansi_bright_colours[5] = convert_colour(_ctx, 0x00ff55ff); // magenta
941
+
ctx->ansi_bright_colours[6] = convert_colour(_ctx, 0x0055ffff); // cyan
942
+
ctx->ansi_bright_colours[7] = convert_colour(_ctx, 0x00ffffff); // grey
if (default_bg != NULL) {
911
-
ctx->default_bg = *default_bg;
946
+
ctx->default_bg = convert_colour(_ctx, *default_bg);
ctx->default_bg = 0x00000000; // background (black)
if (default_fg != NULL) {
917
-
ctx->default_fg = *default_fg;
952
+
ctx->default_fg = convert_colour(_ctx, *default_fg);
919
-
ctx->default_fg = 0x00aaaaaa; // foreground (grey)
954
+
ctx->default_fg = convert_colour(_ctx, 0x00aaaaaa); // foreground (grey)
if (default_bg_bright != NULL) {
923
-
ctx->default_bg_bright = *default_bg_bright;
958
+
ctx->default_bg_bright = convert_colour(_ctx, *default_bg_bright);
925
-
ctx->default_bg_bright = 0x00555555; // background (black)
960
+
ctx->default_bg_bright = convert_colour(_ctx, 0x00555555); // background (black)
if (default_fg_bright != NULL) {
929
-
ctx->default_fg_bright = *default_fg_bright;
964
+
ctx->default_fg_bright = convert_colour(_ctx, *default_fg_bright);
931
-
ctx->default_fg_bright = 0x00ffffff; // foreground (grey)
966
+
ctx->default_fg_bright = convert_colour(_ctx, 0x00ffffff); // foreground (grey)
ctx->text_fg = ctx->default_fg;
···
1049
-
memcpy(ctx->canvas, canvas, ctx->canvas_size);
1084
+
for (size_t i = 0; i < ctx->width * ctx->height; i++) {
1085
+
ctx->canvas[i] = convert_colour(_ctx, canvas[i]);
for (size_t i = 0; i < ctx->width * ctx->height; i++) {
ctx->canvas[i] = ctx->default_bg;