Browse Source

* Moved cucul_load_canvas() into cucul/import.c and renamed it into

cucul_import_canvas().
  * Renamed cucul_create_export() into cucul_export_canvas() for consistency.
tags/v0.99.beta14
Sam Hocevar sam 19 years ago
parent
commit
2401f2c732
12 changed files with 145 additions and 71 deletions
  1. +1
    -1
      caca/driver_raw.c
  2. +2
    -2
      cpp/cucul++.cpp
  3. +1
    -1
      cpp/cucul++.h
  4. +1
    -0
      cucul/Makefile.am
  5. +0
    -55
      cucul/cucul.c
  6. +6
    -5
      cucul/cucul.h
  7. +2
    -2
      cucul/export.c
  8. +127
    -0
      cucul/import.c
  9. +1
    -1
      src/cacaplay.c
  10. +2
    -2
      src/cacaserver.c
  11. +1
    -1
      src/img2irc.c
  12. +1
    -1
      test/export.c

+ 1
- 1
caca/driver_raw.c View File

@@ -55,7 +55,7 @@ static void raw_display(caca_display_t *dp)
{
cucul_buffer_t *buffer;

buffer = cucul_create_export(dp->cv, "caca");
buffer = cucul_export_canvas(dp->cv, "caca");
fwrite(cucul_get_buffer_data(buffer),
cucul_get_buffer_size(buffer), 1, stdout);
fflush(stdout);


+ 2
- 2
cpp/cucul++.cpp View File

@@ -350,10 +350,10 @@ void Cucul::free_font ( Cucul::Font *f)
cucul_free_font(f->font);
}

Cucul::Buffer * Cucul::create_export (char const *buf)
Cucul::Buffer * Cucul::export_canvas (char const *buf)
{
Cucul::Buffer *b = new Cucul::Buffer();
b->buffer = cucul_create_export(cv, buf);
b->buffer = cucul_export_canvas(cv, buf);
return b;
}



+ 1
- 1
cpp/cucul++.h View File

@@ -118,7 +118,7 @@ class Cucul {
unsigned int get_font_height (Font *);
void render_canvas ( Font *, unsigned char *, unsigned int, unsigned int, unsigned int);
void free_font (Font *);
Buffer * create_export ( char const *);
Buffer * export_canvas ( char const *);
char const *const * get_export_list (void);




+ 1
- 0
cucul/Makefile.am View File

@@ -28,6 +28,7 @@ libcucul_la_SOURCES = \
font.c \
font_mono9.h \
font_monobold12.h \
import.c \
export.c \
$(NULL)
libcucul_la_LDFLAGS = -no-undefined


+ 0
- 55
cucul/cucul.c View File

@@ -72,61 +72,6 @@ cucul_canvas_t * cucul_create_canvas(unsigned int width, unsigned int height)
return cv;
}

/** \brief Load a memory area into a canvas.
*
* This function loads a memory area containing an exported canvas into
* a new \e libcucul canvas.
*
* \param data The memory area to be loaded into a canvas.
* \param size The length of the memory area.
* \return A libcucul canvas, or NULL in case of error.
*/
cucul_canvas_t *cucul_load_canvas(void *data, unsigned int size)
{
cucul_canvas_t *cv;
uint8_t *buf = (uint8_t *)data;
unsigned int width, height, n;

if(size < 16)
return NULL;

if(buf[0] != 'C' || buf[1] != 'A' || buf[2] != 'C' || buf[3] != 'A')
return NULL;

if(buf[4] != 'C' || buf[5] != 'A' || buf[6] != 'N' || buf[7] != 'V')
return NULL;

width = ((uint32_t)buf[8] << 24) | ((uint32_t)buf[9] << 16)
| ((uint32_t)buf[10] << 8) | (uint32_t)buf[11];
height = ((uint32_t)buf[12] << 24) | ((uint32_t)buf[13] << 16)
| ((uint32_t)buf[14] << 8) | (uint32_t)buf[15];

if(!width || !height)
return NULL;

if(size != 16 + width * height * 8)
return NULL;

cv = cucul_create_canvas(width, height);

if(!cv)
return NULL;

for(n = height * width; n--; )
{
cv->chars[n] = ((uint32_t)buf[16 + 0 + 8 * n] << 24)
| ((uint32_t)buf[16 + 1 + 8 * n] << 16)
| ((uint32_t)buf[16 + 2 + 8 * n] << 8)
| (uint32_t)buf[16 + 3 + 8 * n];
cv->attr[n] = ((uint32_t)buf[16 + 4 + 8 * n] << 24)
| ((uint32_t)buf[16 + 5 + 8 * n] << 16)
| ((uint32_t)buf[16 + 6 + 8 * n] << 8)
| (uint32_t)buf[16 + 7 + 8 * n];
}

return cv;
}

/** \brief Resize a canvas.
*
* This function sets the canvas width and height, in character cells.


+ 6
- 5
cucul/cucul.h View File

@@ -74,7 +74,6 @@ typedef struct cucul_font cucul_font_t;
*
* @{ */
cucul_canvas_t * cucul_create_canvas(unsigned int, unsigned int);
cucul_canvas_t * cucul_load_canvas(void *, unsigned int);
void cucul_set_canvas_size(cucul_canvas_t *, unsigned int, unsigned int);
unsigned int cucul_get_canvas_width(cucul_canvas_t *);
unsigned int cucul_get_canvas_height(cucul_canvas_t *);
@@ -205,14 +204,16 @@ void cucul_render_canvas(cucul_canvas_t *, cucul_font_t *, void *,
void cucul_free_font(cucul_font_t *);
/* @} */

/** \defgroup exporter libcucul exporters to various formats
/** \defgroup importexport libcucul importers/exporters from/to various formats
*
* These functions export the current canvas to various text formats. It
* is necessary to call cucul_free_buffer() to dispose of the data.
* These functions import various file formats into a new canvas, or export
* the current canvas to various text formats.
*
* @{ */
cucul_buffer_t * cucul_create_export(cucul_canvas_t *, char const *);
cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *, char const *);
char const * const * cucul_get_export_list(void);
cucul_canvas_t * cucul_import_canvas(void const *, unsigned int, char const *);
char const * const * cucul_get_import_list(void);
/* @} */

#ifdef __cplusplus


+ 2
- 2
cucul/export.c View File

@@ -65,7 +65,7 @@ static void export_tga(cucul_canvas_t *, cucul_buffer_t *);
* \param cv A libcucul canvas
* \param format A string describing the requested output format.
*/
cucul_buffer_t * cucul_create_export(cucul_canvas_t *cv, char const *format)
cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *cv, char const *format)
{
cucul_buffer_t *ex;

@@ -103,7 +103,7 @@ cucul_buffer_t * cucul_create_export(cucul_canvas_t *cv, char const *format)
*
* Return a list of available export formats. The list is a NULL-terminated
* array of strings, interleaving a string containing the internal value for
* the export format, to be used with cucul_create_export(), and a string
* the export format, to be used with cucul_export_canvas(), and a string
* containing the natural language description for that export format.
*
* \return An array of strings.


+ 127
- 0
cucul/import.c View File

@@ -0,0 +1,127 @@
/*
* libcucul Canvas for ultrafast compositing of Unicode letters
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id$
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Do What The Fuck You Want To
* Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/

/*
* This file contains various import functions.
*/

#include "config.h"

#if !defined(__KERNEL__)
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
#endif

#include "cucul.h"
#include "cucul_internals.h"

static cucul_canvas_t *import_caca(void const *, unsigned int);

/** \brief Import a buffer into a canvas
*
* This function imports a memory area into an internal libcucul canvas.
*
* Valid values for \c format are:
*
* \li \c "caca": import native libcaca files.
*
* \param data The memory area to be loaded into a canvas.
* \param size The length of the memory area.
* \param format A string describing the input format.
* \return A libcucul canvas, or NULL in case of error.
*/
cucul_canvas_t * cucul_import_canvas(void const *data, unsigned int size,
char const *format)
{
if(!strcasecmp("caca", format))
return import_caca(data, size);

/* FIXME: Try to autodetect */
if(!strcasecmp("", format))
return import_caca(data, size);

return NULL;
}

/** \brief Get available import formats
*
* Return a list of available import formats. The list is a NULL-terminated
* array of strings, interleaving a string containing the internal value for
* the import format, to be used with cucul_import_canvas(), and a string
* containing the natural language description for that import format.
*
* \return An array of strings.
*/
char const * const * cucul_get_import_list(void)
{
static char const * const list[] =
{
"", "autodetect",
"caca", "native libcaca format",
NULL, NULL
};

return list;
}

/*
* XXX: the following functions are local.
*/

static cucul_canvas_t *import_caca(void const *data, unsigned int size)
{
cucul_canvas_t *cv;
uint8_t *buf = (uint8_t *)data;
unsigned int width, height, n;

if(size < 16)
return NULL;

if(buf[0] != 'C' || buf[1] != 'A' || buf[2] != 'C' || buf[3] != 'A')
return NULL;

if(buf[4] != 'C' || buf[5] != 'A' || buf[6] != 'N' || buf[7] != 'V')
return NULL;

width = ((uint32_t)buf[8] << 24) | ((uint32_t)buf[9] << 16)
| ((uint32_t)buf[10] << 8) | (uint32_t)buf[11];
height = ((uint32_t)buf[12] << 24) | ((uint32_t)buf[13] << 16)
| ((uint32_t)buf[14] << 8) | (uint32_t)buf[15];

if(!width || !height)
return NULL;

if(size != 16 + width * height * 8)
return NULL;

cv = cucul_create_canvas(width, height);

if(!cv)
return NULL;

for(n = height * width; n--; )
{
cv->chars[n] = ((uint32_t)buf[16 + 0 + 8 * n] << 24)
| ((uint32_t)buf[16 + 1 + 8 * n] << 16)
| ((uint32_t)buf[16 + 2 + 8 * n] << 8)
| (uint32_t)buf[16 + 3 + 8 * n];
cv->attr[n] = ((uint32_t)buf[16 + 4 + 8 * n] << 24)
| ((uint32_t)buf[16 + 5 + 8 * n] << 16)
| ((uint32_t)buf[16 + 6 + 8 * n] << 8)
| (uint32_t)buf[16 + 7 + 8 * n];
}

return cv;
}


+ 1
- 1
src/cacaplay.c View File

@@ -53,7 +53,7 @@ int main(int argc, char **argv)

buffer = malloc(statbuf.st_size);
read(fd, buffer, statbuf.st_size);
cv = cucul_load_canvas(buffer, statbuf.st_size);
cv = cucul_import_canvas(buffer, statbuf.st_size, "caca");
free(buffer);

if(!cv)


+ 2
- 2
src/cacaserver.c View File

@@ -226,7 +226,7 @@ int main(void)
if(server->canvas)
cucul_free_canvas(server->canvas);

server->canvas = cucul_load_canvas(buf, size);
server->canvas = cucul_import_canvas(buf, size, "caca");

if(!server->canvas)
continue; /* Load error */
@@ -240,7 +240,7 @@ int main(void)

/* Get ANSI representation of the image and skip the end-of buffer
* linefeed ("\r\n", 2 bytes) */
server->buffer = cucul_create_export(server->canvas, "ansi");
server->buffer = cucul_export_canvas(server->canvas, "ansi");
server->bufdata = cucul_get_buffer_data(server->buffer);
server->buflen = cucul_get_buffer_size(server->buffer);
server->buflen -= 2;


+ 1
- 1
src/img2irc.c View File

@@ -58,7 +58,7 @@ int main(int argc, char **argv)

unload_image(i);

export = cucul_create_export(cv, "irc");
export = cucul_export_canvas(cv, "irc");
fwrite(cucul_get_buffer_data(export),
cucul_get_buffer_size(export), 1, stdout);
cucul_free_buffer(export);


+ 1
- 1
test/export.c View File

@@ -101,7 +101,7 @@ int main(int argc, char *argv[])
cucul_putstr(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 5, "#");
}

buffer = cucul_create_export(cv, argv[1]);
buffer = cucul_export_canvas(cv, argv[1]);
fwrite(cucul_get_buffer_data(buffer),
cucul_get_buffer_size(buffer), 1, stdout);
cucul_free_buffer(buffer);


Loading…
Cancel
Save