Ignore:
Timestamp:
Apr 18, 2006, 12:02:42 PM (14 years ago)
Author:
Sam Hocevar
Message:
  • Truecolor support for the HTML and HTMLv3 exporters.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/cucul/export.c

    r805 r808  
    195195static void export_html(cucul_t *qq, cucul_buffer_t *ex)
    196196{
    197     static uint16_t const palette[] =
    198     {
    199         0x000, 0x008, 0x080, 0x088, 0x800, 0x808, 0x880, 0x888,
    200         0x444, 0x44f, 0x4f4, 0x4ff, 0xf44, 0xf4f, 0xff4, 0xfff,
    201     };
    202197    char *cur;
    203198    unsigned int x, y, len;
    204199
    205     /* The CSS palette: roughly 13000 bytes
     200    /* The HTML header: less than 1000 bytes
    206201     * A line: 7 chars for "<br />\n"
    207      * A glyph: 18 chars for "<span class='bxx'>"
     202     * A glyph: 47 chars for "<span style="color:#xxx;background-color:#xxx">"
    208203     *          up to 9 chars for "&#xxxxxx;", far less for pure ASCII
    209204     *          7 chars for "</span>" */
    210     ex->size = 13000 + qq->height * (7 + qq->width * (18 + 9 + 7));
     205    ex->size = 1000 + qq->height * (7 + qq->width * (47 + 9 + 7));
    211206    ex->data = malloc(ex->size);
    212207
     
    214209
    215210    /* HTML header */
    216     cur += sprintf(cur, "<html>\n<head>\n<title>Generated by libcaca %s</title>\n", VERSION);
    217 
    218     /* CSS */
    219     cur += sprintf(cur, "<style>\n");
    220     cur += sprintf(cur, ".caca { font-family: monospace, fixed; font-weight: bold; }");
    221     for(x = 0; x < 0x100; x++)
    222     {
    223         cur += sprintf(cur, ".b%02x { color:#%03x; background-color:#%03x; }\n",
    224                        x, palette[x & 0xf ], palette[x >> 4]);
    225     }
    226     cur += sprintf(cur, "</style>\n</head>\n<body>\n");
     211    cur += sprintf(cur, "<html><head>\n");
     212    cur += sprintf(cur, "<title>Generated by libcaca %s</title>\n", VERSION);
     213    cur += sprintf(cur, "</head><body>\n");
    227214
    228215    cur += sprintf(cur, "<div cellpadding='0' cellspacing='0' style='%s'>\n",
     
    236223        for(x = 0; x < qq->width; x += len)
    237224        {
    238             cur += sprintf(cur, "<span class='b%02x'>",
    239                            _cucul_argb32_to_ansi8(lineattr[x]));
     225            cur += sprintf(cur, "<span style=\"color:#%.03x;"
     226                                "background-color:#%.03x\">",
     227                                _cucul_argb32_to_rgb12fg(lineattr[x]),
     228                                _cucul_argb32_to_rgb12bg(lineattr[x]));
    240229
    241230            for(len = 0;
     
    269258static void export_html3(cucul_t *qq, cucul_buffer_t *ex)
    270259{
    271     static uint32_t const palette[] =
    272     {
    273         0x000000, 0x000088, 0x008800, 0x008888,
    274         0x880000, 0x880088, 0x888800, 0x888888,
    275         0x444444, 0x4444ff, 0x44ff44, 0x44ffff,
    276         0xff4444, 0xff44ff, 0xffff44, 0xffffff,
    277     };
    278 
    279260    char *cur;
    280261    unsigned int x, y, len;
    281262
    282     /* The CSS palette: roughly 13000 bytes
     263    /* The HTML table markup: less than 1000 bytes
    283264     * A line: 10 chars for "<tr></tr>\n"
    284265     * A glyph: 40 chars for "<td bgcolor=#xxxxxx><font color=#xxxxxx>"
    285266     *          up to 9 chars for "&#xxxxxx;", far less for pure ASCII
    286267     *          12 chars for "</font></td>" */
    287     ex->size = 13000 + qq->height * (10 + qq->width * (40 + 9 + 12));
     268    ex->size = 1000 + qq->height * (10 + qq->width * (40 + 9 + 12));
    288269    ex->data = malloc(ex->size);
    289270
     
    305286            unsigned int i;
    306287
    307             /* Use colspan option to factorize cells with same attributes
     288            /* Use colspan option to factor cells with same attributes
    308289             * (see below) */
    309290            len = 1;
     
    311292                len++;
    312293
    313             cur += sprintf(cur, "<td bgcolor=#%06x",
    314                            palette[_cucul_argb32_to_ansi4bg(lineattr[x])]);
     294            cur += sprintf(cur, "<td bgcolor=#%.06x",
     295                           _cucul_argb32_to_rgb24bg(lineattr[x]));
    315296
    316297            if(len > 1)
    317298                cur += sprintf(cur, " colspan=%d", len);
    318299
    319             cur += sprintf(cur, "><font color=#%06x>",
    320                            palette[_cucul_argb32_to_ansi4fg(lineattr[x])]);
     300            cur += sprintf(cur, "><font color=#%.06x>",
     301                           _cucul_argb32_to_rgb24fg(lineattr[x]));
    321302
    322303            for(i = 0; i < len; i++)
Note: See TracChangeset for help on using the changeset viewer.