Changeset 4305


Ignore:
Timestamp:
01/27/10 01:47:58 (3 years ago)
Author:
sam
Message:

Generate colour fonts with caca2tlf.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • toilet/trunk/tools/caca2tlf.c

    r4135 r4305  
    2828 
    2929enum mode { GRAY, HALFBLOCKS, QUARTERBLOCKS } mode; 
    30 enum charset { ASCII, UTF8 } charset; 
     30enum charset { SPACES, ASCII, UTF8 } charset; 
    3131 
    3232static void list_fonts(void); 
     
    4747    { 
    4848        fprintf(stderr, 
    49                 "Usage: %s [--half|--quarter] [--ascii|--utf8] <font>\n", 
     49                "Usage: %s [--half|--quarter] [--spaces|--ascii|--utf8] <font>\n", 
    5050                argv[0]); 
    5151        list_fonts(); 
     
    7171    } 
    7272 
    73     if((!strcmp(argv[1], "--ascii") || !strcmp(argv[1], "-a")) && argc > 2) 
     73    if((!strcmp(argv[1], "--spaces") || !strcmp(argv[1], "-s")) && argc > 2) 
     74    { 
     75        flag2 = "--spaces "; 
     76        charset = SPACES; 
     77        argv++; argc--; 
     78    } 
     79    else if((!strcmp(argv[1], "--ascii") || !strcmp(argv[1], "-a")) && argc > 2) 
    7480    { 
    7581        flag2 = "--ascii "; 
     
    191197    static char const * chars[][16] = 
    192198    { 
     199        { "_", "_", "_", "_", " " }, 
     200        { " ", "_", "_", "_" }, 
     201        { " ", "_", "_", "_", "_", "_", "_", "_", 
     202          "_", "_", "_", "_", "_", "_", "_", "_" }, 
    193203        { "#", "$", ":", ".", " " }, 
    194204        { " ", "\"", "m", "#" }, 
     
    201211    }; 
    202212 
     213    static uint8_t fgs[][4] = 
     214    { 
     215        { CACA_DEFAULT, CACA_DARKGRAY, CACA_LIGHTGRAY, CACA_WHITE }, 
     216        { CACA_DEFAULT, CACA_DEFAULT, CACA_DEFAULT, CACA_DEFAULT }, 
     217    }; 
     218 
     219    static uint8_t bgs[][4] = 
     220    { 
     221        { CACA_DEFAULT, CACA_DARKGRAY, CACA_LIGHTGRAY, CACA_WHITE }, 
     222        { CACA_DEFAULT, CACA_DEFAULT, CACA_DEFAULT, CACA_DEFAULT }, 
     223    }; 
     224 
    203225    char const **str; 
    204226    void *buf; 
    205227    size_t len; 
    206228    unsigned int x, y, myw, mygw; 
    207     int off = 0; 
     229    int coff = 0, aoff = 0; 
    208230    int full = caca_utf32_is_fullwidth(ch); 
    209231 
     
    220242    switch(charset) 
    221243    { 
     244    case SPACES: 
     245        coff = 0; aoff = 0; 
     246        break; 
    222247    case ASCII: 
    223         off = 0; 
     248        coff = 3; aoff = 1; 
    224249        break; 
    225250    case UTF8: 
    226         off = 3; 
     251        coff = 6; aoff = 1; 
    227252        break; 
    228253    } 
     
    231256    { 
    232257    case GRAY: 
    233         str = chars[off]; 
     258        str = chars[coff]; 
    234259        for(y = 0; y < h; y++) 
    235260            for(x = 0; x < myw; x++) 
     
    237262            uint8_t c = image[4 * (x + y * iw) + 2]; 
    238263 
    239             if(c >= 0xa0) 
     264            if(c >= 0xc0) 
     265            { 
     266                caca_set_color_ansi(out, fgs[aoff][3], bgs[aoff][3]); 
    240267                caca_put_str(out, x, y, str[0]); 
     268            } 
     269            else if(c >= 0x90) 
     270            { 
     271                caca_set_color_ansi(out, fgs[aoff][2], bgs[aoff][2]); 
     272                caca_put_str(out, x, y, str[0]); 
     273            } 
    241274            else if(c >= 0x80) 
     275            { 
     276                caca_set_color_ansi(out, fgs[aoff][2], bgs[aoff][2]); 
    242277                caca_put_str(out, x, y, str[1]); 
     278            } 
    243279            else if(c >= 0x40) 
     280            { 
     281                caca_set_color_ansi(out, fgs[aoff][1], bgs[aoff][1]); 
    244282                caca_put_str(out, x, y, str[2]); 
     283            } 
    245284            else if(c >= 0x20) 
     285            { 
     286                caca_set_color_ansi(out, fgs[aoff][1], bgs[aoff][1]); 
    246287                caca_put_str(out, x, y, str[3]); 
     288            } 
    247289            else 
     290            { 
     291                caca_set_color_ansi(out, fgs[aoff][0], bgs[aoff][0]); 
    248292                caca_put_str(out, x, y, str[4]); 
     293            } 
    249294        } 
    250295        break; 
    251296    case HALFBLOCKS: 
    252         str = chars[off + 1]; 
     297        str = chars[coff + 1]; 
    253298        for(y = 0; y < gh; y++) 
    254299            for(x = 0; x < mygw; x++) 
     
    261306        break; 
    262307    case QUARTERBLOCKS: 
    263         str = chars[off + 2]; 
     308        str = chars[coff + 2]; 
    264309        for(y = 0; y < gh; y++) 
    265310            for(x = 0; x < mygw; x++) 
     
    276321    } 
    277322 
     323    caca_set_color_ansi(out, CACA_DEFAULT, CACA_DEFAULT); 
     324 
    278325    if(ch == ' ' || ch == 0xa0) 
    279326    { 
Note: See TracChangeset for help on using the changeset viewer.