Ignore:
Timestamp:
Apr 19, 2006, 11:07:55 AM (14 years ago)
Author:
Sam Hocevar
Message:
  • Added a new "caca" exporter.
  • Removed most code from the raw driver and replaced it with a call to the caca exporter.
  • Slightly changed the caca export format and updated code accordingly.
  • Improved cacaserver error reporting.
File:
1 edited

Legend:

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

    r813 r818  
    2828#include "cucul_internals.h"
    2929
     30static void export_caca(cucul_canvas_t *, cucul_buffer_t *);
    3031static void export_ansi(cucul_canvas_t *, cucul_buffer_t *);
    3132static void export_html(cucul_canvas_t *, cucul_buffer_t *);
     
    4546 *  Valid values for \e format are:
    4647 *
     48 *  \li \e "caca": export native libcaca files.
     49 *
    4750 *  \li \e "ansi": export ANSI art (CP437 charset with ANSI colour codes).
    4851 *
     
    7174    ex->data = NULL;
    7275
    73     if(!strcasecmp("ansi", format))
     76    if(!strcasecmp("caca", format))
     77        export_caca(cv, ex);
     78    else if(!strcasecmp("ansi", format))
    7479        export_ansi(cv, ex);
    7580    else if(!strcasecmp("html", format))
     
    108113    static char const * const list[] =
    109114    {
     115        "caca", "native libcaca format",
    110116        "ansi", "ANSI",
    111117        "html", "HTML",
     
    124130 * XXX: the following functions are local.
    125131 */
     132
     133/* Generate a native libcaca canvas file. */
     134static void export_caca(cucul_canvas_t *cv, cucul_buffer_t *ex)
     135{
     136    uint32_t *attr = cv->attr;
     137    uint32_t *chars = cv->chars;
     138    char *cur;
     139    uint32_t w, h;
     140    unsigned int n;
     141
     142    /* 16 bytes for the canvas, 8 bytes for each character cell. */
     143    ex->size = 16 + 8 * cv->width * cv->height;
     144    ex->data = malloc(ex->size);
     145
     146    cur = ex->data;
     147
     148    w = cv->width;
     149    h = cv->height;
     150
     151    cur += sprintf(cur, "CACACANV%c%c%c%c%c%c%c%c",
     152                   (w >> 24), (w >> 16) & 0xff, (w >> 8) & 0xff, w & 0xff,
     153                   (h >> 24), (h >> 16) & 0xff, (h >> 8) & 0xff, h & 0xff);
     154
     155    for(n = cv->height * cv->width; n--; )
     156    {
     157        uint32_t ch = *chars++;
     158        uint32_t a = *attr++;
     159
     160        *cur++ = ch >> 24;
     161        *cur++ = (ch >> 16) & 0xff;
     162        *cur++ = (ch >> 8) & 0xff;
     163        *cur++ = ch & 0xff;
     164
     165        *cur++ = a >> 24;
     166        *cur++ = (a >> 16) & 0xff;
     167        *cur++ = (a >> 8) & 0xff;
     168        *cur++ = a & 0xff;
     169    }
     170}
    126171
    127172/* Generate ANSI representation of current canvas. */
Note: See TracChangeset for help on using the changeset viewer.