Ticket #3145: slang-truecolor-demo.patch

File slang-truecolor-demo.patch, 8.6 KB (added by egmont, 10 years ago)
  • slang-pre2.3.0-110

    diff -ur slang-pre2.3.0-110.orig/src/slang.h slang-pre2.3.0-110/src/slang.h
    old new  
    16521652SL_EXTERN unsigned long SLtt_Num_Chars_Output; 
    16531653SL_EXTERN int SLtt_Baud_Rate; 
    16541654 
    1655 typedef unsigned long SLtt_Char_Type; 
     1655typedef unsigned long long SLtt_Char_Type; 
    16561656 
    1657 #define SLTT_BOLD_MASK  0x01000000UL 
    1658 #define SLTT_BLINK_MASK 0x02000000UL 
    1659 #define SLTT_ULINE_MASK 0x04000000UL 
    1660 #define SLTT_REV_MASK   0x08000000UL 
    1661 #define SLTT_ALTC_MASK  0x10000000UL 
    1662 #define SLTT_ITALIC_MASK  0x20000000UL 
     1657#define SLTT_BOLD_MASK   0x0000000001000000ULL 
     1658#define SLTT_BLINK_MASK  0x0000000002000000ULL 
     1659#define SLTT_ULINE_MASK  0x0000000004000000ULL 
     1660#define SLTT_REV_MASK    0x0000000008000000ULL 
     1661#define SLTT_ALTC_MASK   0x0000000010000000ULL 
     1662#define SLTT_ITALIC_MASK 0x0000000020000000ULL 
    16631663 
    16641664SL_EXTERN int SLtt_Screen_Rows; 
    16651665SL_EXTERN int SLtt_Screen_Cols; 
  • slang-pre2.3.0-110

    diff -ur slang-pre2.3.0-110.orig/src/sldisply.c slang-pre2.3.0-110/src/sldisply.c
    old new  
    8989/* Colors:  These definitions are used for the display.  However, the 
    9090 * application only uses object handles which get mapped to this 
    9191 * internal representation.  The mapping is performed by the Color_Map 
    92  * structure below. */ 
     92 * structure below. 
     93 * 
     94 * Colors are encoded in 25 bits as follows: 
     95 * - Values 0-255 for standard palette 
     96 * - 256 for terminal's default color 
     97 * - 0x1RRGGBB for true colors 
     98 * 
     99 * The bits are split so we can maintain ABI compatibility on 64 bit machines. 
     100 */ 
    93101 
    94 #define CHAR_MASK       0x000000FF 
    95 #define FG_MASK         0x0000FF00 
    96 #define BG_MASK         0x00FF0000 
    97 #define ATTR_MASK       0x3F000000 
    98 #define BGALL_MASK      0x0FFF0000 
     102// FIXME: are the CHAR_MASK bits used at all? If not then the color bits can be 
     103// spread out a little bit more nicely, see the #else branch. 
     104#if 1 
     105 
     106#define CHAR_MASK       0x00000000000000FFULL 
     107#define FG_MASK_LOW     0x0000000000FFFF00ULL 
     108#define FG_MASK_HIGH    0x0000007FC0000000ULL 
     109#define BG_MASK         0xFFFFFF8000000000ULL 
     110#define ATTR_MASK       0x000000003F000000ULL 
     111#define CHAR_INVALID    0x4000000000000000ULL 
     112 
     113#define GET_FG(fgbg) ((((fgbg) & FG_MASK_HIGH) >> 14) | (((fgbg) & FG_MASK_LOW) >> 8)) 
     114#define GET_BG(fgbg) (((fgbg) & BG_MASK) >> 39) 
     115#define MAKE_COLOR(fg, bg) ((((fg) << 14) & FG_MASK_HIGH) | (((fg) << 8) & FG_MASK_LOW) | (((bg) << 39) & BG_MASK)) 
    99116 
    100 /* The 0x10000000 bit represents the alternate character set.  BGALL_MASK does 
    101  * not include this attribute. 
    102  */ 
     117#else 
    103118 
    104 #define GET_FG(fgbg) (((fgbg) & FG_MASK) >> 8) 
    105 #define GET_BG(fgbg) (((fgbg) & BG_MASK) >> 16) 
    106 #define MAKE_COLOR(fg, bg) (((fg) | ((bg) << 8)) << 8) 
     119#define FG_MASK_LOW     0x0000000000FFFFFFULL 
     120#define FG_MASK_HIGH    0x0200000000000000ULL 
     121#define BG_MASK         0x01FFFFFF00000000ULL 
     122#define ATTR_MASK       0x000000003F000000ULL 
     123#define CHAR_INVALID    0xFFFFFFFFFFFFFFFFULL 
     124 
     125#define GET_FG(fgbg) ((((fgbg) & FG_MASK_HIGH) >> 33) | ((fgbg) & FG_MASK_LOW)) 
     126#define GET_BG(fgbg) (((fgbg) & BG_MASK) >> 32) 
     127#define MAKE_COLOR(fg, bg) ((((fg) << 33) & FG_MASK_HIGH) | ((fg) & FG_MASK_LOW) | (((bg) << 32) & BG_MASK)) 
     128 
     129#endif 
    107130 
    108131int SLtt_Screen_Cols = 80; 
    109132int SLtt_Screen_Rows = 24; 
     
    180203 
    181204static SLCONST char *Color_Fg_Str = "\033[3%dm"; 
    182205static SLCONST char *Color_Bg_Str = "\033[4%dm"; 
     206static SLCONST char *Color_RGB_Fg_Str = "\033[38;2;%d;%d;%dm"; 
     207static SLCONST char *Color_RGB_Bg_Str = "\033[48;2;%d;%d;%dm"; 
    183208static SLCONST char *Default_Color_Fg_Str = "\033[39m"; 
    184209static SLCONST char *Default_Color_Bg_Str = "\033[49m"; 
    185210 
     
    247272static int Cursor_r, Cursor_c;         /* 0 based */ 
    248273 
    249274/* current attributes --- initialized to impossible value */ 
    250 static SLtt_Char_Type Current_Fgbg = 0xFFFFFFFFU; 
     275static SLtt_Char_Type Current_Fgbg = CHAR_INVALID; 
    251276 
    252277static int Cursor_Set;                 /* 1 if cursor position known, 0 
    253278                                        * if not.  -1 if only row is known 
     
    10451070     } 
    10461071 
    10471072   if ((Del_Eol_Str != NULL) 
    1048        && (Can_Background_Color_Erase || ((Current_Fgbg & ~0xFFU) == 0))) 
     1073       && (Can_Background_Color_Erase || ((Current_Fgbg & ~0xFFU) == 0)))  // FIXME: do we use CHAR_MASK's bits here? 
    10491074     { 
    10501075        tt_write_string(Del_Eol_Str); 
    10511076        return; 
     
    10621087 
    10631088void SLtt_del_eol (void) 
    10641089{ 
    1065    if (Current_Fgbg != 0xFFFFFFFFU) SLtt_normal_video (); 
     1090   if (Current_Fgbg != CHAR_INVALID) SLtt_normal_video (); 
    10661091   del_eol (); 
    10671092} 
    10681093 
     
    10921117     {"brightmagenta",  SLSMG_COLOR_BRIGHT_CYAN}, 
    10931118     {"brightcyan",     SLSMG_COLOR_BRIGHT_MAGENTA}, 
    10941119     {"white",          SLSMG_COLOR_BRIGHT_WHITE}, 
    1095 #define SLSMG_COLOR_DEFAULT 0xFF 
     1120#define SLSMG_COLOR_DEFAULT 0x100 
    10961121     {"default",                SLSMG_COLOR_DEFAULT} 
    10971122}; 
    10981123 
     
    11501175   Brush_Info_Type *b; 
    11511176 
    11521177   if (NULL == (b = get_brush_info (color))) 
    1153      return (SLtt_Char_Type)-1; 
     1178     return CHAR_INVALID; 
    11541179 
    11551180   if (SLtt_Use_Ansi_Colors) 
    11561181     return b->fgbg; 
     
    13071332 
    13081333   if (Max_Terminfo_Colors != 8) 
    13091334     { 
    1310         if (f != SLSMG_COLOR_DEFAULT) f %= Max_Terminfo_Colors; 
    1311         if (b != SLSMG_COLOR_DEFAULT) b %= Max_Terminfo_Colors; 
    1312         return ((f << 8) | (b << 16)); 
     1335        if (f != SLSMG_COLOR_DEFAULT && !(f & (1 << 24))) f %= Max_Terminfo_Colors; 
     1336        if (b != SLSMG_COLOR_DEFAULT && !(b & (1 << 24))) b %= Max_Terminfo_Colors; 
     1337        return MAKE_COLOR(f,b); 
    13131338     } 
    13141339 
    13151340   /* Otherwise we have 8 ansi colors.  Try to get bright versions 
     
    13311356        b &= 0x7; 
    13321357     } 
    13331358 
    1334    return ((f << 8) | (b << 16) | attr); 
     1359   return MAKE_COLOR(f,b) | attr; 
     1360} 
     1361 
     1362static int parse_hex_digit (char ch) 
     1363{ 
     1364   if ('0' <= ch && ch <= '9')  return      ch - '0'; 
     1365   if ('A' <= ch && ch <= 'F')  return 10 + ch - 'A'; 
     1366   if ('a' <= ch && ch <= 'f')  return 10 + ch - 'a'; 
     1367   return -1; 
    13351368} 
    13361369 
    13371370/* This looks for colors with name form 'colorN'.  If color is of this 
     
    13421375   unsigned int i; 
    13431376   unsigned char ch; 
    13441377 
     1378   if (color[0] == '#') 
     1379     { 
     1380        int h[6]; 
     1381        SLtt_Char_Type rgb; 
     1382        color++; 
     1383        if (strlen(color) != 3 && strlen(color) != 6) 
     1384             return -1; 
     1385        for (i = 0; color[i] != '\0'; i++) 
     1386          { 
     1387             h[i] = parse_hex_digit (color[i]); 
     1388             if (h[i] == -1) 
     1389                  return -1; 
     1390          } 
     1391        if (i == 3) 
     1392             rgb = (h[0] << 20) | (h[0] << 16) | (h[1] << 12) | (h[1] << 8) | (h[2] << 4) | h[2]; 
     1393        else 
     1394             rgb = (h[0] << 20) | (h[1] << 16) | (h[2] << 12) | (h[3] << 8) | (h[4] << 4) | h[5]; 
     1395        *f = (1 << 24) | rgb; 
     1396        return 0; 
     1397     } 
     1398 
    13451399   if (strncmp (color, "color", 5)) 
    13461400     return -1; 
    13471401 
     
    14201474 
    14211475static int make_color_fgbg (SLCONST char *fg, SLCONST char *bg, SLtt_Char_Type *fgbg) 
    14221476{ 
    1423    SLtt_Char_Type f = 0xFFFFFFFFU, b = 0xFFFFFFFFU; 
     1477   SLtt_Char_Type f = CHAR_INVALID, b = CHAR_INVALID; 
    14241478   SLCONST char *dfg, *dbg; 
    14251479   unsigned int i; 
    14261480   char bgbuf[16], fgbuf[16]; 
     
    14641518          } 
    14651519     } 
    14661520 
    1467    if ((f == 0xFFFFFFFFU) || (b == 0xFFFFFFFFU)) 
     1521   if ((f == CHAR_INVALID) || (b == CHAR_INVALID)) 
    14681522     return -1; 
    14691523 
    14701524   *fgbg = fb_to_fgbg (f, b) | fattr | battr; 
     
    15091563{ 
    15101564   int bg0, fg0; 
    15111565   int unknown_attributes; 
     1566   char tmpbuf[32]; 
    15121567 
    15131568   if (Worthless_Highlight) return; 
    15141569   if (fgbg == Current_Fgbg) return; 
     
    15571612          { 
    15581613             if (fg0 == SLSMG_COLOR_DEFAULT) 
    15591614               tt_write_string (Default_Color_Fg_Str); 
     1615             else if (fg0 & (1 << 24)) 
     1616               { 
     1617                  sprintf (tmpbuf, Color_RGB_Fg_Str, 
     1618                           (int) ((fg0 >> 16) & 0xFF), 
     1619                           (int) ((fg0 >> 8) & 0xFF), 
     1620                           (int) (fg0 & 0xFF)); 
     1621                  tt_write_string (tmpbuf); 
     1622               } 
    15601623             else 
    15611624               tt_printf (Color_Fg_Str, COLOR_ARG(fg0, Is_Fg_BGR), 0); 
    15621625          } 
     
    15661629          { 
    15671630             if (bg0 == SLSMG_COLOR_DEFAULT) 
    15681631               tt_write_string (Default_Color_Bg_Str); 
     1632             else if (bg0 & (1 << 24)) 
     1633               { 
     1634                  sprintf (tmpbuf, Color_RGB_Bg_Str, 
     1635                           (int) ((bg0 >> 16) & 0xFF), 
     1636                           (int) ((bg0 >> 8) & 0xFF), 
     1637                           (int) (bg0 & 0xFF)); 
     1638                  tt_write_string (tmpbuf); 
     1639               } 
    15691640             else 
    15701641               tt_printf (Color_Bg_Str, COLOR_ARG(bg0, Is_Bg_BGR), 0); 
    15711642          } 
     
    15891660             tt_write_string (Norm_Vid_Str); 
    15901661          } 
    15911662        else tt_write_string (Rev_Vid_Str); 
    1592         Current_Fgbg = 0xFFFFFFFFU; 
     1663        Current_Fgbg = CHAR_INVALID; 
    15931664        return; 
    15941665     } 
    15951666 
     
    30283099   SLtt_normal_video ();               /* MSKermit requires this  */ 
    30293100   tt_write_string(Norm_Vid_Str); 
    30303101 
    3031    Current_Fgbg = 0xFFFFFFFFU; 
     3102   Current_Fgbg = CHAR_INVALID; 
    30323103   SLtt_set_alt_char_set (0); 
    30333104   if (SLtt_Use_Ansi_Colors) 
    30343105     { 
     
    30403111             else tt_write_string ("\033[0m\033[m"); 
    30413112          } 
    30423113        else tt_write_string (Reset_Color_String); 
    3043         Current_Fgbg = 0xFFFFFFFFU; 
     3114        Current_Fgbg = CHAR_INVALID; 
    30443115     } 
    30453116   SLtt_erase_line (); 
    30463117   SLtt_deinit_keypad ();