Browse Source

* Replaced "struct cucul_*" and "struct caca_*" types with opaque typedefs

such as cucul_dither_t instead of struct cucul_dither.
  * Made cucul_buffer_t an opaque structure and implemented the two getters
    cucul_get_buffer_data() and cucul_get_buffer_size().
  * Documented all missing functions and function parameters.
tags/v0.99.beta14
Sam Hocevar sam 19 years ago
parent
commit
17c065a49e
42 changed files with 301 additions and 217 deletions
  1. +20
    -22
      caca/caca.h
  2. +11
    -9
      caca/caca_internals.h
  3. +2
    -2
      caca/driver_conio.c
  4. +1
    -1
      caca/driver_gl.c
  5. +1
    -1
      caca/driver_ncurses.c
  6. +1
    -1
      caca/driver_raw.c
  7. +1
    -1
      caca/driver_slang.c
  8. +1
    -1
      caca/driver_vga.c
  9. +1
    -1
      caca/driver_win32.c
  10. +1
    -1
      caca/driver_x11.c
  11. +8
    -8
      caca/event.c
  12. +1
    -1
      caca/time.c
  13. +73
    -6
      cucul/cucul.c
  14. +52
    -43
      cucul/cucul.h
  15. +13
    -7
      cucul/cucul_internals.h
  16. +24
    -26
      cucul/dither.c
  17. +1
    -1
      cucul/export_ansi.c
  18. +2
    -2
      cucul/export_html.c
  19. +1
    -1
      cucul/export_irc.c
  20. +1
    -1
      cucul/export_ps.c
  21. +1
    -1
      cucul/export_svg.c
  22. +7
    -7
      cucul/font.c
  23. +10
    -10
      cucul/sprite.c
  24. +2
    -2
      src/aafire.c
  25. +2
    -2
      src/cacaball.c
  26. +2
    -2
      src/cacamoir.c
  27. +2
    -2
      src/cacaplas.c
  28. +1
    -1
      src/cacaplay.c
  29. +24
    -22
      src/cacaserver.c
  30. +1
    -1
      src/cacaview.c
  31. +4
    -3
      src/img2irc.c
  32. +1
    -1
      test/colors.c
  33. +4
    -4
      test/demo.c
  34. +1
    -1
      test/dithering.c
  35. +7
    -7
      test/event.c
  36. +5
    -4
      test/export.c
  37. +3
    -3
      test/font.c
  38. +2
    -2
      test/gamma.c
  39. +2
    -2
      test/hsv.c
  40. +2
    -2
      test/spritedit.c
  41. +1
    -1
      test/transform.c
  42. +1
    -1
      test/unicode.c

+ 20
- 22
caca/caca.h View File

@@ -87,23 +87,10 @@ extern "C"
{ {
#endif #endif


/** \brief User event types.
*
* Event types returned by caca_get_event().
*/
enum caca_event_type
{
CACA_EVENT_NONE = 0x0000, /**< No event. */

CACA_EVENT_KEY_PRESS = 0x0001, /**< A key was pressed. */
CACA_EVENT_KEY_RELEASE = 0x0002, /**< A key was released. */
CACA_EVENT_MOUSE_PRESS = 0x0004, /**< A mouse button was pressed. */
CACA_EVENT_MOUSE_RELEASE = 0x0008, /**< A mouse button was released. */
CACA_EVENT_MOUSE_MOTION = 0x0010, /**< The mouse was moved. */
CACA_EVENT_RESIZE = 0x0020, /**< The window was resized. */

CACA_EVENT_ANY = 0xffff /**< Bitmask for any event. */
};
/** \e libcaca context */
typedef struct caca caca_t;
/** event structure */
typedef struct caca_event caca_event_t;


/** \brief User events. /** \brief User events.
* *
@@ -138,7 +125,20 @@ enum caca_event_type
*/ */
struct caca_event struct caca_event
{ {
enum caca_event_type type;
enum caca_event_type
{
CACA_EVENT_NONE = 0x0000, /**< No event. */

CACA_EVENT_KEY_PRESS = 0x0001, /**< A key was pressed. */
CACA_EVENT_KEY_RELEASE = 0x0002, /**< A key was released. */
CACA_EVENT_MOUSE_PRESS = 0x0004, /**< A mouse button was pressed. */
CACA_EVENT_MOUSE_RELEASE = 0x0008, /**< A mouse button was released. */
CACA_EVENT_MOUSE_MOTION = 0x0010, /**< The mouse was moved. */
CACA_EVENT_RESIZE = 0x0020, /**< The window was resized. */

CACA_EVENT_ANY = 0xffff /**< Bitmask for any event. */
} type;

union union
{ {
struct { unsigned int x, y, button; } mouse; struct { unsigned int x, y, button; } mouse;
@@ -194,9 +194,7 @@ enum caca_key
CACA_KEY_F15 = 0x128 /**< The F15 key. */ CACA_KEY_F15 = 0x128 /**< The F15 key. */
}; };


typedef struct caca_context caca_t;

/** \defgroup basic Basic functions
/** \defgroup caca Basic libcaca functions
* *
* These functions provide the basic \e libcaca routines for driver * These functions provide the basic \e libcaca routines for driver
* initialisation, system information retrieval and configuration. * initialisation, system information retrieval and configuration.
@@ -218,7 +216,7 @@ int caca_set_window_title(caca_t *kk, char const *);
* clicks. * clicks.
* *
* @{ */ * @{ */
int caca_get_event(caca_t *kk, unsigned int, struct caca_event *, int);
int caca_get_event(caca_t *kk, unsigned int, caca_event_t *, int);
unsigned int caca_get_mouse_x(caca_t *kk); unsigned int caca_get_mouse_x(caca_t *kk);
unsigned int caca_get_mouse_y(caca_t *kk); unsigned int caca_get_mouse_y(caca_t *kk);
void caca_set_mouse(caca_t *kk, int); void caca_set_mouse(caca_t *kk, int);


+ 11
- 9
caca/caca_internals.h View File

@@ -25,6 +25,8 @@ typedef long int intptr_t;
typedef long unsigned int uintptr_t; typedef long unsigned int uintptr_t;
#endif #endif


typedef struct caca_timer caca_timer_t;

#if !defined(_DOXYGEN_SKIP_ME) #if !defined(_DOXYGEN_SKIP_ME)
# define EVENTBUF_LEN 10 # define EVENTBUF_LEN 10
#endif #endif
@@ -88,7 +90,7 @@ struct caca_timer
}; };


/* Internal caca context */ /* Internal caca context */
struct caca_context
struct caca
{ {
/* A link to our cucul canvas */ /* A link to our cucul canvas */
cucul_t *qq; cucul_t *qq;
@@ -106,7 +108,7 @@ struct caca_context
unsigned int (* get_window_height) (caca_t *); unsigned int (* get_window_height) (caca_t *);
void (* display) (caca_t *); void (* display) (caca_t *);
void (* handle_resize) (caca_t *); void (* handle_resize) (caca_t *);
int (* get_event) (caca_t *, struct caca_event *);
int (* get_event) (caca_t *, caca_event_t *);
void (* set_mouse) (caca_t *, int); void (* set_mouse) (caca_t *, int);
} drv; } drv;


@@ -125,20 +127,20 @@ struct caca_context


/* Framerate handling */ /* Framerate handling */
unsigned int delay, rendertime; unsigned int delay, rendertime;
struct caca_timer timer;
caca_timer_t timer;
int lastticks; int lastticks;


struct events struct events
{ {
#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL) #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
struct caca_event buf[EVENTBUF_LEN];
caca_event_t buf[EVENTBUF_LEN];
int queue; int queue;
#endif #endif
#if defined(USE_SLANG) || defined(USE_NCURSES) #if defined(USE_SLANG) || defined(USE_NCURSES)
struct caca_timer key_timer;
caca_timer_t key_timer;
unsigned int last_key_ticks; unsigned int last_key_ticks;
unsigned int autorepeat_ticks; unsigned int autorepeat_ticks;
struct caca_event last_key_event;
caca_event_t last_key_event;
#endif #endif
#if defined(USE_WIN32) #if defined(USE_WIN32)
unsigned char not_empty_struct; unsigned char not_empty_struct;
@@ -148,13 +150,13 @@ struct caca_context


/* Internal timer functions */ /* Internal timer functions */
extern void _caca_sleep(unsigned int); extern void _caca_sleep(unsigned int);
extern unsigned int _caca_getticks(struct caca_timer *);
extern unsigned int _caca_getticks(caca_timer_t *);


/* Internal event functions */ /* Internal event functions */
extern void _caca_handle_resize(caca_t *); extern void _caca_handle_resize(caca_t *);
#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL) #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
extern void _push_event(caca_t *, struct caca_event *);
extern int _pop_event(caca_t *, struct caca_event *);
extern void _push_event(caca_t *, caca_event_t *);
extern int _pop_event(caca_t *, caca_event_t *);
#endif #endif


#endif /* __CACA_INTERNALS_H__ */ #endif /* __CACA_INTERNALS_H__ */

+ 2
- 2
caca/driver_conio.c View File

@@ -119,10 +119,10 @@ static void conio_handle_resize(caca_t *kk)
kk->resize.h = kk->qq->height; kk->resize.h = kk->qq->height;
} }


static int conio_get_event(caca_t *kk, struct caca_event *ev)
static int conio_get_event(caca_t *kk, caca_event_t *ev)
{ {
unsigned char ch; unsigned char ch;
struct caca_event release;
caca_event_t release;


if(!_conio_kbhit()) if(!_conio_kbhit())
{ {


+ 1
- 1
caca/driver_gl.c View File

@@ -323,7 +323,7 @@ static void gl_handle_resize(caca_t *kk)
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
} }


static int gl_get_event(caca_t *kk, struct caca_event *ev)
static int gl_get_event(caca_t *kk, caca_event_t *ev)
{ {
#ifdef HAVE_GLUTCHECKLOOP #ifdef HAVE_GLUTCHECKLOOP
glutCheckLoop(); glutCheckLoop();


+ 1
- 1
caca/driver_ncurses.c View File

@@ -224,7 +224,7 @@ static void ncurses_handle_resize(caca_t *kk)
kk->resize.h = kk->qq->height; kk->resize.h = kk->qq->height;
} }


static int ncurses_get_event(caca_t *kk, struct caca_event *ev)
static int ncurses_get_event(caca_t *kk, caca_event_t *ev)
{ {
int intkey; int intkey;




+ 1
- 1
caca/driver_raw.c View File

@@ -84,7 +84,7 @@ static void raw_handle_resize(caca_t *kk)
; ;
} }


static int raw_get_event(caca_t *kk, struct caca_event *ev)
static int raw_get_event(caca_t *kk, caca_event_t *ev)
{ {
ev->type = CACA_EVENT_NONE; ev->type = CACA_EVENT_NONE;
return 0; return 0;


+ 1
- 1
caca/driver_slang.c View File

@@ -252,7 +252,7 @@ static void slang_handle_resize(caca_t *kk)
SLsmg_reinit_smg(); SLsmg_reinit_smg();
} }


static int slang_get_event(caca_t *kk, struct caca_event *ev)
static int slang_get_event(caca_t *kk, caca_event_t *ev)
{ {
int intkey; int intkey;




+ 1
- 1
caca/driver_vga.c View File

@@ -132,7 +132,7 @@ static void vga_handle_resize(caca_t *kk)
kk->resize.h = kk->qq->height; kk->resize.h = kk->qq->height;
} }


static int vga_get_event(caca_t *kk, struct caca_event *ev)
static int vga_get_event(caca_t *kk, caca_event-t *ev)
{ {
/* FIXME */ /* FIXME */
ev->type = CACA_EVENT_NONE; ev->type = CACA_EVENT_NONE;


+ 1
- 1
caca/driver_win32.c View File

@@ -233,7 +233,7 @@ static void win32_handle_resize(caca_t *kk)
kk->resize.h = kk->qq->height; kk->resize.h = kk->qq->height;
} }


static int win32_get_event(caca_t *kk, struct caca_event *ev)
static int win32_get_event(caca_t *kk, caca_event_t *ev)
{ {
INPUT_RECORD rec; INPUT_RECORD rec;
DWORD num; DWORD num;


+ 1
- 1
caca/driver_x11.c View File

@@ -404,7 +404,7 @@ static void x11_handle_resize(caca_t *kk)
kk->drv.p->pixmap = new_pixmap; kk->drv.p->pixmap = new_pixmap;
} }


static int x11_get_event(caca_t *kk, struct caca_event *ev)
static int x11_get_event(caca_t *kk, caca_event_t *ev)
{ {
XEvent xevent; XEvent xevent;
char key; char key;


+ 8
- 8
caca/event.c View File

@@ -26,8 +26,8 @@
#include "caca.h" #include "caca.h"
#include "caca_internals.h" #include "caca_internals.h"


static int _get_next_event(caca_t *, struct caca_event *);
static int _lowlevel_event(caca_t *, struct caca_event *);
static int _get_next_event(caca_t *, caca_event_t *);
static int _lowlevel_event(caca_t *, caca_event_t *);


#if !defined(_DOXYGEN_SKIP_ME) #if !defined(_DOXYGEN_SKIP_ME)
/* If no new key was pressed after AUTOREPEAT_THRESHOLD usec, assume the /* If no new key was pressed after AUTOREPEAT_THRESHOLD usec, assume the
@@ -57,9 +57,9 @@ static int _lowlevel_event(caca_t *, struct caca_event *);
* \return The next matching event in the queue, or 0 if no event is pending. * \return The next matching event in the queue, or 0 if no event is pending.
*/ */
int caca_get_event(caca_t *kk, unsigned int event_mask, int caca_get_event(caca_t *kk, unsigned int event_mask,
struct caca_event *ev, int timeout)
caca_event_t *ev, int timeout)
{ {
struct caca_timer timer;
caca_timer_t timer;
int usec = 0; int usec = 0;


if(!event_mask) if(!event_mask)
@@ -141,7 +141,7 @@ unsigned int caca_get_mouse_y(caca_t *kk)
* XXX: The following functions are local. * XXX: The following functions are local.
*/ */


static int _get_next_event(caca_t *kk, struct caca_event *ev)
static int _get_next_event(caca_t *kk, caca_event_t *ev)
{ {
#if defined(USE_SLANG) || defined(USE_NCURSES) #if defined(USE_SLANG) || defined(USE_NCURSES)
unsigned int ticks; unsigned int ticks;
@@ -223,7 +223,7 @@ static int _get_next_event(caca_t *kk, struct caca_event *ev)
#endif #endif
} }


static int _lowlevel_event(caca_t *kk, struct caca_event *ev)
static int _lowlevel_event(caca_t *kk, caca_event_t *ev)
{ {
#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO)
int ret = _pop_event(kk, ev); int ret = _pop_event(kk, ev);
@@ -236,7 +236,7 @@ static int _lowlevel_event(caca_t *kk, struct caca_event *ev)
} }


#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL) #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
void _push_event(caca_t *kk, struct caca_event *ev)
void _push_event(caca_t *kk, caca_event_t *ev)
{ {
if(!ev->type || kk->events.queue == EVENTBUF_LEN) if(!ev->type || kk->events.queue == EVENTBUF_LEN)
return; return;
@@ -244,7 +244,7 @@ void _push_event(caca_t *kk, struct caca_event *ev)
kk->events.queue++; kk->events.queue++;
} }


int _pop_event(caca_t *kk, struct caca_event *ev)
int _pop_event(caca_t *kk, caca_event_t *ev)
{ {
int i; int i;




+ 1
- 1
caca/time.c View File

@@ -45,7 +45,7 @@ void _caca_sleep(unsigned int usec)
#endif #endif
} }


unsigned int _caca_getticks(struct caca_timer *timer)
unsigned int _caca_getticks(caca_timer_t *timer)
{ {
#if defined(HAVE_GETTIMEOFDAY) #if defined(HAVE_GETTIMEOFDAY)
struct timeval tv; struct timeval tv;


+ 73
- 6
cucul/cucul.c View File

@@ -72,6 +72,15 @@ cucul_t * cucul_create(unsigned int width, unsigned int height)
return qq; return qq;
} }


/** \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_t *cucul_load(void *data, unsigned int size) cucul_t *cucul_load(void *data, unsigned int size)
{ {
cucul_t *qq; cucul_t *qq;
@@ -227,11 +236,36 @@ void cucul_free(cucul_t *qq)
free(qq); free(qq);
} }


struct cucul_buffer * cucul_create_export(cucul_t *qq, char const *format)
/** \brief Export a canvas into a foreign format.
*
* This function exports a libcucul canvas into various foreign formats such
* as ANSI art, HTML, IRC colours, etc. One should use cucul_get_buffer_data()
* and cucul_get_buffer_size() to access the buffer contents. The allocated
* data is valid until cucul_free_buffer() is called.
*
* Valid values for \e format are:
*
* \li \e "ansi": export ANSI art (CP437 charset with ANSI colour codes).
*
* \li \e "html": export an HTML page with CSS information.
*
* \li \e "html3": export an HTML table that should be compatible with
* most navigators, including textmode ones.
*
* \li \e "irc": export UTF-8 text with mIRC colour codes.
*
* \li \e "ps": export a PostScript document.
*
* \li \e "svg": export an SVG document.
*
* \param qq A libcucul canvas
* \param format A string describing the requested output format.
*/
cucul_buffer_t * cucul_create_export(cucul_t *qq, char const *format)
{ {
struct cucul_buffer *ex;
cucul_buffer_t *ex;


ex = malloc(sizeof(struct cucul_buffer));
ex = malloc(sizeof(cucul_buffer_t));


if(!strcasecmp("ansi", format)) if(!strcasecmp("ansi", format))
_cucul_get_ansi(qq, ex); _cucul_get_ansi(qq, ex);
@@ -279,10 +313,43 @@ char const * const * cucul_get_export_list(void)
return list; return list;
} }


void cucul_free_export(struct cucul_buffer *ex)
/** \brief Get the buffer size.
*
* This function returns the length (in bytes) of the memory area stored
* in the given \e libcucul buffer.
*
* \param buf A \e libcucul buffer
* \return The buffer data length.
*/
unsigned long int cucul_get_buffer_size(cucul_buffer_t *buf)
{
return buf->size;
}

/** \brief Get the buffer data.
*
* This function returns a pointer to the memory area stored in the given
* \e libcucul buffer.
*
* \param buf A \e libcucul buffer
* \return A pointer to the buffer memory area.
*/
void * cucul_get_buffer_data(cucul_buffer_t *buf)
{
return buf->data;
}

/** \brief Free a buffer.
*
* This function frees the structures associated with the given
* \e libcucul buffer.
*
* \param buf A \e libcucul buffer
*/
void cucul_free_buffer(cucul_buffer_t *buf)
{ {
free(ex->data);
free(ex);
free(buf->data);
free(buf);
} }


/* /*


+ 52
- 43
cucul/cucul.h View File

@@ -31,13 +31,16 @@ extern "C"
{ {
#endif #endif


typedef struct cucul_context cucul_t;

struct cucul_buffer
{
unsigned int size;
char *data;
};
/** \e libcucul context */
typedef struct cucul cucul_t;
/** sprite structure */
typedef struct cucul_sprite cucul_sprite_t;
/** dither structure */
typedef struct cucul_dither cucul_dither_t;
/** data buffer structure */
typedef struct cucul_buffer cucul_buffer_t;
/** font structure */
typedef struct cucul_font cucul_font_t;


/** \defgroup colour Colour definitions /** \defgroup colour Colour definitions
* *
@@ -64,7 +67,7 @@ struct cucul_buffer
#define CUCUL_COLOR_TRANSPARENT 0x20 /**< The transparent colour. */ #define CUCUL_COLOR_TRANSPARENT 0x20 /**< The transparent colour. */
/* @} */ /* @} */


/** \defgroup basic Basic functions
/** \defgroup cucul Basic libcucul functions
* *
* These functions provide the basic \e libcaca routines for library * These functions provide the basic \e libcaca routines for library
* initialisation, system information retrieval and configuration. * initialisation, system information retrieval and configuration.
@@ -78,6 +81,16 @@ unsigned int cucul_get_height(cucul_t *);
void cucul_free(cucul_t *); void cucul_free(cucul_t *);
/* @} */ /* @} */


/** \defgroup buffer Buffer handling
*
* These functions provide methods to handle libcucul buffers.
*
* @{ */
unsigned long int cucul_get_buffer_size(cucul_buffer_t *);
void * cucul_get_buffer_data(cucul_buffer_t *);
void cucul_free_buffer(cucul_buffer_t *);
/* @} */

/** \defgroup canvas Canvas drawing /** \defgroup canvas Canvas drawing
* *
* These functions provide low-level character printing routines and * These functions provide low-level character printing routines and
@@ -144,15 +157,14 @@ unsigned int cucul_sqrt(unsigned int);
* and rendering. * and rendering.
* *
* @{ */ * @{ */
struct cucul_sprite;
struct cucul_sprite * cucul_load_sprite(char const *);
int cucul_get_sprite_frames(struct cucul_sprite const *);
int cucul_get_sprite_width(struct cucul_sprite const *, int);
int cucul_get_sprite_height(struct cucul_sprite const *, int);
int cucul_get_sprite_dx(struct cucul_sprite const *, int);
int cucul_get_sprite_dy(struct cucul_sprite const *, int);
void cucul_draw_sprite(cucul_t *, int, int, struct cucul_sprite const *, int);
void cucul_free_sprite(struct cucul_sprite *);
cucul_sprite_t * cucul_load_sprite(char const *);
int cucul_get_sprite_frames(cucul_sprite_t const *);
int cucul_get_sprite_width(cucul_sprite_t const *, int);
int cucul_get_sprite_height(cucul_sprite_t const *, int);
int cucul_get_sprite_dx(cucul_sprite_t const *, int);
int cucul_get_sprite_dy(cucul_sprite_t const *, int);
void cucul_draw_sprite(cucul_t *, int, int, cucul_sprite_t const *, int);
void cucul_free_sprite(cucul_sprite_t *);
/* @} */ /* @} */


/** \defgroup dither Bitmap dithering /** \defgroup dither Bitmap dithering
@@ -161,29 +173,28 @@ void cucul_free_sprite(struct cucul_sprite *);
* rendering. * rendering.
* *
* @{ */ * @{ */
struct cucul_dither;
struct cucul_dither *cucul_create_dither(unsigned int, unsigned int,
cucul_dither_t *cucul_create_dither(unsigned int, unsigned int,
unsigned int, unsigned int, unsigned int, unsigned int,
unsigned int, unsigned int, unsigned int, unsigned int,
unsigned int, unsigned int); unsigned int, unsigned int);
void cucul_set_dither_palette(struct cucul_dither *,
void cucul_set_dither_palette(cucul_dither_t *,
unsigned int r[], unsigned int g[], unsigned int r[], unsigned int g[],
unsigned int b[], unsigned int a[]); unsigned int b[], unsigned int a[]);
void cucul_set_dither_brightness(struct cucul_dither *, float);
void cucul_set_dither_gamma(struct cucul_dither *, float);
void cucul_set_dither_contrast(struct cucul_dither *, float);
void cucul_set_dither_invert(struct cucul_dither *, int);
void cucul_set_dither_antialias(struct cucul_dither *, char const *);
char const * const * cucul_get_dither_antialias_list(struct cucul_dither const *);
void cucul_set_dither_color(struct cucul_dither *, char const *);
char const * const * cucul_get_dither_color_list(struct cucul_dither const *);
void cucul_set_dither_charset(struct cucul_dither *, char const *);
char const * const * cucul_get_dither_charset_list(struct cucul_dither const *);
void cucul_set_dither_mode(struct cucul_dither *, char const *);
char const * const * cucul_get_dither_mode_list(struct cucul_dither const *);
void cucul_set_dither_brightness(cucul_dither_t *, float);
void cucul_set_dither_gamma(cucul_dither_t *, float);
void cucul_set_dither_contrast(cucul_dither_t *, float);
void cucul_set_dither_invert(cucul_dither_t *, int);
void cucul_set_dither_antialias(cucul_dither_t *, char const *);
char const * const * cucul_get_dither_antialias_list(cucul_dither_t const *);
void cucul_set_dither_color(cucul_dither_t *, char const *);
char const * const * cucul_get_dither_color_list(cucul_dither_t const *);
void cucul_set_dither_charset(cucul_dither_t *, char const *);
char const * const * cucul_get_dither_charset_list(cucul_dither_t const *);
void cucul_set_dither_mode(cucul_dither_t *, char const *);
char const * const * cucul_get_dither_mode_list(cucul_dither_t const *);
void cucul_dither_bitmap(cucul_t *, int, int, int, int, void cucul_dither_bitmap(cucul_t *, int, int, int, int,
struct cucul_dither const *, void *);
void cucul_free_dither(struct cucul_dither *);
cucul_dither_t const *, void *);
void cucul_free_dither(cucul_dither_t *);
/* @} */ /* @} */


/** \defgroup font Font handling /** \defgroup font Font handling
@@ -192,25 +203,23 @@ void cucul_free_dither(struct cucul_dither *);
* canvas to bitmap rendering. * canvas to bitmap rendering.
* *
* @{ */ * @{ */
struct cucul_font;
struct cucul_font *cucul_load_font(void const *, unsigned int);
cucul_font_t *cucul_load_font(void const *, unsigned int);
char const * const * cucul_get_font_list(void); char const * const * cucul_get_font_list(void);
unsigned int cucul_get_font_width(struct cucul_font *);
unsigned int cucul_get_font_height(struct cucul_font *);
void cucul_render_canvas(cucul_t *, struct cucul_font *, unsigned char *,
unsigned int cucul_get_font_width(cucul_font_t *);
unsigned int cucul_get_font_height(cucul_font_t *);
void cucul_render_canvas(cucul_t *, cucul_font_t *, unsigned char *,
unsigned int, unsigned int, unsigned int); unsigned int, unsigned int, unsigned int);
void cucul_free_font(struct cucul_font *);
void cucul_free_font(cucul_font_t *);
/* @} */ /* @} */


/** \defgroup exporter Exporters to various formats /** \defgroup exporter Exporters to various formats
* *
* These functions export the current canvas to various text formats. It * These functions export the current canvas to various text formats. It
* is necessary to call cucul_free_export() to dispose of the data.
* is necessary to call cucul_free_buffer() to dispose of the data.
* *
* @{ */ * @{ */
struct cucul_buffer * cucul_create_export(cucul_t *, char const *);
cucul_buffer_t * cucul_create_export(cucul_t *, char const *);
char const * const * cucul_get_export_list(void); char const * const * cucul_get_export_list(void);
void cucul_free_export(struct cucul_buffer *);
/* @} */ /* @} */


#ifdef __cplusplus #ifdef __cplusplus


+ 13
- 7
cucul/cucul_internals.h View File

@@ -25,7 +25,7 @@ typedef long int intptr_t;
typedef long unsigned int uintptr_t; typedef long unsigned int uintptr_t;
#endif #endif


struct cucul_context
struct cucul
{ {
/* Context size */ /* Context size */
unsigned int width, height; unsigned int width, height;
@@ -40,6 +40,12 @@ struct cucul_context
unsigned int refcount; unsigned int refcount;
}; };


struct cucul_buffer
{
unsigned long int size;
char *data;
};

/* Bitmap functions */ /* Bitmap functions */
extern int _cucul_init_dither(void); extern int _cucul_init_dither(void);
extern int _cucul_end_dither(void); extern int _cucul_end_dither(void);
@@ -62,11 +68,11 @@ uint8_t _cucul_argb32_to_ansi4bg(uint32_t);
void _cucul_argb32_to_argb4(uint32_t, uint8_t[8]); void _cucul_argb32_to_argb4(uint32_t, uint8_t[8]);


/* Export functions */ /* Export functions */
extern void _cucul_get_ansi(cucul_t *, struct cucul_buffer *);
extern void _cucul_get_html(cucul_t *, struct cucul_buffer *);
extern void _cucul_get_html3(cucul_t *, struct cucul_buffer *);
extern void _cucul_get_irc(cucul_t *, struct cucul_buffer *);
extern void _cucul_get_ps(cucul_t *, struct cucul_buffer *);
extern void _cucul_get_svg(cucul_t *, struct cucul_buffer *);
extern void _cucul_get_ansi(cucul_t *, cucul_buffer_t *);
extern void _cucul_get_html(cucul_t *, cucul_buffer_t *);
extern void _cucul_get_html3(cucul_t *, cucul_buffer_t *);
extern void _cucul_get_irc(cucul_t *, cucul_buffer_t *);
extern void _cucul_get_ps(cucul_t *, cucul_buffer_t *);
extern void _cucul_get_svg(cucul_t *, cucul_buffer_t *);


#endif /* __CUCUL_INTERNALS_H__ */ #endif /* __CUCUL_INTERNALS_H__ */

+ 24
- 26
cucul/dither.c View File

@@ -118,7 +118,7 @@ struct cucul_dither
int rmask, gmask, bmask, amask; int rmask, gmask, bmask, amask;
int rright, gright, bright, aright; int rright, gright, bright, aright;
int rleft, gleft, bleft, aleft; int rleft, gleft, bleft, aleft;
void (*get_hsv)(struct cucul_dither *, char *, int, int);
void (*get_hsv)(cucul_dither_t *, char *, int, int);
int red[256], green[256], blue[256], alpha[256]; int red[256], green[256], blue[256], alpha[256];
float gamma; float gamma;
int gammatab[4097]; int gammatab[4097];
@@ -163,7 +163,7 @@ struct cucul_dither
static void mask2shift(unsigned int, int *, int *); static void mask2shift(unsigned int, int *, int *);
static float gammapow(float x, float y); static float gammapow(float x, float y);


static void get_rgba_default(struct cucul_dither const *, uint8_t *, int, int,
static void get_rgba_default(cucul_dither_t const *, uint8_t *, int, int,
unsigned int *); unsigned int *);


/* Dithering methods */ /* Dithering methods */
@@ -245,19 +245,19 @@ static inline void rgb2hsv_default(int r, int g, int b,
* \param amask Bitmask for alpha values. * \param amask Bitmask for alpha values.
* \return Dither object, or NULL upon error. * \return Dither object, or NULL upon error.
*/ */
struct cucul_dither *cucul_create_dither(unsigned int bpp, unsigned int w,
unsigned int h, unsigned int pitch,
unsigned int rmask, unsigned int gmask,
unsigned int bmask, unsigned int amask)
cucul_dither_t *cucul_create_dither(unsigned int bpp, unsigned int w,
unsigned int h, unsigned int pitch,
unsigned int rmask, unsigned int gmask,
unsigned int bmask, unsigned int amask)
{ {
struct cucul_dither *d;
cucul_dither_t *d;
int i; int i;


/* Minor sanity test */ /* Minor sanity test */
if(!w || !h || !pitch || bpp > 32 || bpp < 8) if(!w || !h || !pitch || bpp > 32 || bpp < 8)
return NULL; return NULL;


d = malloc(sizeof(struct cucul_dither));
d = malloc(sizeof(cucul_dither_t));
if(!d) if(!d)
return NULL; return NULL;


@@ -330,7 +330,7 @@ struct cucul_dither *cucul_create_dither(unsigned int bpp, unsigned int w,
* \param blue Array of 256 blue values. * \param blue Array of 256 blue values.
* \param alpha Array of 256 alpha values. * \param alpha Array of 256 alpha values.
*/ */
void cucul_set_dither_palette(struct cucul_dither *d,
void cucul_set_dither_palette(cucul_dither_t *d,
unsigned int red[], unsigned int green[], unsigned int red[], unsigned int green[],
unsigned int blue[], unsigned int alpha[]) unsigned int blue[], unsigned int alpha[])
{ {
@@ -367,7 +367,7 @@ void cucul_set_dither_palette(struct cucul_dither *d,
* \param d Dither object. * \param d Dither object.
* \param brightness brightness value. * \param brightness brightness value.
*/ */
void cucul_set_dither_brightness(struct cucul_dither *d, float brightness)
void cucul_set_dither_brightness(cucul_dither_t *d, float brightness)
{ {
/* FIXME */ /* FIXME */
} }
@@ -379,7 +379,7 @@ void cucul_set_dither_brightness(struct cucul_dither *d, float brightness)
* \param d Dither object. * \param d Dither object.
* \param gamma Gamma value. * \param gamma Gamma value.
*/ */
void cucul_set_dither_gamma(struct cucul_dither *d, float gamma)
void cucul_set_dither_gamma(cucul_dither_t *d, float gamma)
{ {
/* FIXME: we don't need 4096 calls to gammapow(), we can just compute /* FIXME: we don't need 4096 calls to gammapow(), we can just compute
* 128 of them and do linear interpolation for the rest. This will * 128 of them and do linear interpolation for the rest. This will
@@ -402,7 +402,7 @@ void cucul_set_dither_gamma(struct cucul_dither *d, float gamma)
* \param d Dither object. * \param d Dither object.
* \param value 0 for normal behaviour, 1 for invert * \param value 0 for normal behaviour, 1 for invert
*/ */
void cucul_set_dither_invert(struct cucul_dither *d, int value)
void cucul_set_dither_invert(cucul_dither_t *d, int value)
{ {
d->invert = value ? 1 : 0; d->invert = value ? 1 : 0;
} }
@@ -414,7 +414,7 @@ void cucul_set_dither_invert(struct cucul_dither *d, int value)
* \param d Dither object. * \param d Dither object.
* \param contrast contrast value. * \param contrast contrast value.
*/ */
void cucul_set_dither_contrast(struct cucul_dither *d, float contrast)
void cucul_set_dither_contrast(cucul_dither_t *d, float contrast)
{ {
/* FIXME */ /* FIXME */
} }
@@ -433,7 +433,7 @@ void cucul_set_dither_contrast(struct cucul_dither *d, float contrast)
* \param str A string describing the antialiasing method that will be used * \param str A string describing the antialiasing method that will be used
* for the dithering. * for the dithering.
*/ */
void cucul_set_dither_antialias(struct cucul_dither *d, char const *str)
void cucul_set_dither_antialias(cucul_dither_t *d, char const *str)
{ {
if(!strcasecmp(str, "none")) if(!strcasecmp(str, "none"))
d->antialias = 0; d->antialias = 0;
@@ -453,7 +453,7 @@ void cucul_set_dither_antialias(struct cucul_dither *d, char const *str)
* \return An array of strings. * \return An array of strings.
*/ */
char const * const * char const * const *
cucul_get_dither_antialias_list(struct cucul_dither const *d)
cucul_get_dither_antialias_list(cucul_dither_t const *d)
{ {
static char const * const list[] = static char const * const list[] =
{ {
@@ -491,7 +491,7 @@ char const * const *
* \param str A string describing the colour set that will be used * \param str A string describing the colour set that will be used
* for the dithering. * for the dithering.
*/ */
void cucul_set_dither_color(struct cucul_dither *d, char const *str)
void cucul_set_dither_color(cucul_dither_t *d, char const *str)
{ {
if(!strcasecmp(str, "mono")) if(!strcasecmp(str, "mono"))
d->color_mode = COLOR_MODE_MONO; d->color_mode = COLOR_MODE_MONO;
@@ -521,7 +521,7 @@ void cucul_set_dither_color(struct cucul_dither *d, char const *str)
* \return An array of strings. * \return An array of strings.
*/ */
char const * const * char const * const *
cucul_get_dither_color_list(struct cucul_dither const *d)
cucul_get_dither_color_list(cucul_dither_t const *d)
{ {
static char const * const list[] = static char const * const list[] =
{ {
@@ -556,7 +556,7 @@ char const * const *
* \param str A string describing the characters that need to be used * \param str A string describing the characters that need to be used
* for the dithering. * for the dithering.
*/ */
void cucul_set_dither_charset(struct cucul_dither *d, char const *str)
void cucul_set_dither_charset(cucul_dither_t *d, char const *str)
{ {
if(!strcasecmp(str, "shades")) if(!strcasecmp(str, "shades"))
{ {
@@ -586,8 +586,7 @@ void cucul_set_dither_charset(struct cucul_dither *d, char const *str)
* \param d Dither object. * \param d Dither object.
* \return An array of strings. * \return An array of strings.
*/ */
char const * const *
cucul_get_dither_charset_list(struct cucul_dither const *d)
char const * const * cucul_get_dither_charset_list(cucul_dither_t const *d)
{ {
static char const * const list[] = static char const * const list[] =
{ {
@@ -622,7 +621,7 @@ char const * const *
* \param str A string describing the method that needs to be used * \param str A string describing the method that needs to be used
* for the dithering. * for the dithering.
*/ */
void cucul_set_dither_mode(struct cucul_dither *d, char const *str)
void cucul_set_dither_mode(cucul_dither_t *d, char const *str)
{ {
if(!strcasecmp(str, "none")) if(!strcasecmp(str, "none"))
{ {
@@ -673,8 +672,7 @@ void cucul_set_dither_mode(struct cucul_dither *d, char const *str)
* \param d Dither object. * \param d Dither object.
* \return An array of strings. * \return An array of strings.
*/ */
char const * const *
cucul_get_dither_mode_list(struct cucul_dither const *d)
char const * const * cucul_get_dither_mode_list(cucul_dither_t const *d)
{ {
static char const * const list[] = static char const * const list[] =
{ {
@@ -704,7 +702,7 @@ char const * const *
* \param pixels Bitmap's pixels. * \param pixels Bitmap's pixels.
*/ */
void cucul_dither_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2, void cucul_dither_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2,
struct cucul_dither const *d, void *pixels)
cucul_dither_t const *d, void *pixels)
{ {
int *floyd_steinberg, *fs_r, *fs_g, *fs_b; int *floyd_steinberg, *fs_r, *fs_g, *fs_b;
int fs_length; int fs_length;
@@ -955,7 +953,7 @@ void cucul_dither_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2,
* *
* \param d Dither object. * \param d Dither object.
*/ */
void cucul_free_dither(struct cucul_dither *d)
void cucul_free_dither(cucul_dither_t *d)
{ {
if(!d) if(!d)
return; return;
@@ -1056,7 +1054,7 @@ static float gammapow(float x, float y)
#endif #endif
} }


static void get_rgba_default(struct cucul_dither const *d, uint8_t *pixels,
static void get_rgba_default(cucul_dither_t const *d, uint8_t *pixels,
int x, int y, unsigned int *rgba) int x, int y, unsigned int *rgba)
{ {
uint32_t bits; uint32_t bits;


+ 1
- 1
cucul/export_ansi.c View File

@@ -35,7 +35,7 @@
* able to cut/paste the result to a function like printf * able to cut/paste the result to a function like printf
* \return buffer containing generated ANSI codes as a big string * \return buffer containing generated ANSI codes as a big string
*/ */
void _cucul_get_ansi(cucul_t *qq, struct cucul_buffer *ex)
void _cucul_get_ansi(cucul_t *qq, cucul_buffer_t *ex)
{ {
static int const palette[] = static int const palette[] =
{ {


+ 2
- 2
cucul/export_html.c View File

@@ -32,7 +32,7 @@
* This function generates and returns the HTML representation of * This function generates and returns the HTML representation of
* the current image. * the current image.
*/ */
void _cucul_get_html(cucul_t *qq, struct cucul_buffer *ex)
void _cucul_get_html(cucul_t *qq, cucul_buffer_t *ex)
{ {
static int const palette[] = static int const palette[] =
{ {
@@ -111,7 +111,7 @@ void _cucul_get_html(cucul_t *qq, struct cucul_buffer *ex)
* Won't work under gecko (mozilla rendering engine) unless you set * Won't work under gecko (mozilla rendering engine) unless you set
* a correct header. * a correct header.
*/ */
void _cucul_get_html3(cucul_t *qq, struct cucul_buffer *ex)
void _cucul_get_html3(cucul_t *qq, cucul_buffer_t *ex)
{ {
static int const palette[] = static int const palette[] =
{ {


+ 1
- 1
cucul/export_irc.c View File

@@ -32,7 +32,7 @@
* This function generates and returns an IRC representation of * This function generates and returns an IRC representation of
* the current image. * the current image.
*/ */
void _cucul_get_irc(cucul_t *qq, struct cucul_buffer *ex)
void _cucul_get_irc(cucul_t *qq, cucul_buffer_t *ex)
{ {
static int const palette[] = static int const palette[] =
{ {


+ 1
- 1
cucul/export_ps.c View File

@@ -57,7 +57,7 @@ static char const *ps_header =
* This function generates and returns a Postscript representation of * This function generates and returns a Postscript representation of
* the current image. * the current image.
*/ */
void _cucul_get_ps(cucul_t *qq, struct cucul_buffer *ex)
void _cucul_get_ps(cucul_t *qq, cucul_buffer_t *ex)
{ {
static char const * const palette[] = static char const * const palette[] =
{ {


+ 1
- 1
cucul/export_svg.c View File

@@ -42,7 +42,7 @@ static char const svg_header[] =
* This function generates and returns a SVG representation of * This function generates and returns a SVG representation of
* the current image. * the current image.
*/ */
void _cucul_get_svg(cucul_t *qq, struct cucul_buffer *ex)
void _cucul_get_svg(cucul_t *qq, cucul_buffer_t *ex)
{ {
static int const palette[] = static int const palette[] =
{ {


+ 7
- 7
cucul/font.c View File

@@ -106,9 +106,9 @@ DECLARE_UNPACKGLYPH(1)
* \param size The size of the memory area, or 0 if the font name is given. * \param size The size of the memory area, or 0 if the font name is given.
* \return A font handle or NULL in case of error. * \return A font handle or NULL in case of error.
*/ */
struct cucul_font *cucul_load_font(void const *data, unsigned int size)
cucul_font_t *cucul_load_font(void const *data, unsigned int size)
{ {
struct cucul_font *f;
cucul_font_t *f;
unsigned int i; unsigned int i;


if(size == 0) if(size == 0)
@@ -124,7 +124,7 @@ struct cucul_font *cucul_load_font(void const *data, unsigned int size)
if(size < sizeof(struct font_header)) if(size < sizeof(struct font_header))
return NULL; return NULL;


f = malloc(sizeof(struct cucul_font));
f = malloc(sizeof(cucul_font_t));
f->private = (void *)(uintptr_t)data; f->private = (void *)(uintptr_t)data;


memcpy(&f->header, f->private + 8, sizeof(struct font_header)); memcpy(&f->header, f->private + 8, sizeof(struct font_header));
@@ -221,7 +221,7 @@ char const * const * cucul_get_font_list(void)
* \param f The font, as returned by \e cucul_load_font() * \param f The font, as returned by \e cucul_load_font()
* \return The maximum glyph width. * \return The maximum glyph width.
*/ */
unsigned int cucul_get_font_width(struct cucul_font *f)
unsigned int cucul_get_font_width(cucul_font_t *f)
{ {
return f->header.width; return f->header.width;
} }
@@ -233,7 +233,7 @@ unsigned int cucul_get_font_width(struct cucul_font *f)
* \param f The font, as returned by \e cucul_load_font() * \param f The font, as returned by \e cucul_load_font()
* \return The maximum glyph height. * \return The maximum glyph height.
*/ */
unsigned int cucul_get_font_height(struct cucul_font *f)
unsigned int cucul_get_font_height(cucul_font_t *f)
{ {
return f->header.height; return f->header.height;
} }
@@ -247,7 +247,7 @@ unsigned int cucul_get_font_height(struct cucul_font *f)
* *
* \param f The font, as returned by \e cucul_load_font() * \param f The font, as returned by \e cucul_load_font()
*/ */
void cucul_free_font(struct cucul_font *f)
void cucul_free_font(cucul_font_t *f)
{ {
free(f->glyph_list); free(f->glyph_list);
free(f->block_list); free(f->block_list);
@@ -273,7 +273,7 @@ void cucul_free_font(struct cucul_font *f)
* \param height The height (in pixels) of the image buffer * \param height The height (in pixels) of the image buffer
* \param pitch The pitch (in bytes) of an image buffer line. * \param pitch The pitch (in bytes) of an image buffer line.
*/ */
void cucul_render_canvas(cucul_t *qq, struct cucul_font *f,
void cucul_render_canvas(cucul_t *qq, cucul_font_t *f,
unsigned char *buf, unsigned int width, unsigned char *buf, unsigned int width,
unsigned int height, unsigned int pitch) unsigned int height, unsigned int pitch)
{ {


+ 10
- 10
cucul/sprite.c View File

@@ -47,17 +47,17 @@ struct cucul_sprite
* \param file The filename. * \param file The filename.
* \return The sprite, or NULL if an error occured. * \return The sprite, or NULL if an error occured.
*/ */
struct cucul_sprite *cucul_load_sprite(char const *file)
cucul_sprite_t *cucul_load_sprite(char const *file)
{ {
char buf[BUFSIZ]; char buf[BUFSIZ];
struct cucul_sprite *sprite;
cucul_sprite_t *sprite;
FILE *fd; FILE *fd;


fd = fopen(file, "r"); fd = fopen(file, "r");
if(fd == NULL) if(fd == NULL)
return NULL; return NULL;


sprite = malloc(sizeof(struct cucul_sprite));
sprite = malloc(sizeof(cucul_sprite_t));
if(sprite == NULL) if(sprite == NULL)
goto sprite_alloc_failed; goto sprite_alloc_failed;


@@ -167,7 +167,7 @@ sprite_alloc_failed:
* \param sprite The sprite. * \param sprite The sprite.
* \return The number of frames. * \return The number of frames.
*/ */
int cucul_get_sprite_frames(struct cucul_sprite const *sprite)
int cucul_get_sprite_frames(cucul_sprite_t const *sprite)
{ {
if(sprite == NULL) if(sprite == NULL)
return 0; return 0;
@@ -181,7 +181,7 @@ int cucul_get_sprite_frames(struct cucul_sprite const *sprite)
* \param f The frame index. * \param f The frame index.
* \return The width of the given frame of the sprite. * \return The width of the given frame of the sprite.
*/ */
int cucul_get_sprite_width(struct cucul_sprite const *sprite, int f)
int cucul_get_sprite_width(cucul_sprite_t const *sprite, int f)
{ {
if(sprite == NULL) if(sprite == NULL)
return 0; return 0;
@@ -198,7 +198,7 @@ int cucul_get_sprite_width(struct cucul_sprite const *sprite, int f)
* \param f The frame index. * \param f The frame index.
* \return The height of the given frame of the sprite. * \return The height of the given frame of the sprite.
*/ */
int cucul_get_sprite_height(struct cucul_sprite const *sprite, int f)
int cucul_get_sprite_height(cucul_sprite_t const *sprite, int f)
{ {
if(sprite == NULL) if(sprite == NULL)
return 0; return 0;
@@ -215,7 +215,7 @@ int cucul_get_sprite_height(struct cucul_sprite const *sprite, int f)
* \param f The frame index. * \param f The frame index.
* \return The X coordinate of the given frame's handle. * \return The X coordinate of the given frame's handle.
*/ */
int cucul_get_sprite_dx(struct cucul_sprite const *sprite, int f)
int cucul_get_sprite_dx(cucul_sprite_t const *sprite, int f)
{ {
if(sprite == NULL) if(sprite == NULL)
return 0; return 0;
@@ -232,7 +232,7 @@ int cucul_get_sprite_dx(struct cucul_sprite const *sprite, int f)
* \param f The frame index. * \param f The frame index.
* \return The Y coordinate of the given frame's handle. * \return The Y coordinate of the given frame's handle.
*/ */
int cucul_get_sprite_dy(struct cucul_sprite const *sprite, int f)
int cucul_get_sprite_dy(cucul_sprite_t const *sprite, int f)
{ {
if(sprite == NULL) if(sprite == NULL)
return 0; return 0;
@@ -253,7 +253,7 @@ int cucul_get_sprite_dy(struct cucul_sprite const *sprite, int f)
* \param f The frame index. * \param f The frame index.
* \return void * \return void
*/ */
void cucul_draw_sprite(cucul_t *qq, int x, int y, struct cucul_sprite const *sprite, int f)
void cucul_draw_sprite(cucul_t *qq, int x, int y, cucul_sprite_t const *sprite, int f)
{ {
int i, j; int i, j;
unsigned int oldfg, oldbg; unsigned int oldfg, oldbg;
@@ -292,7 +292,7 @@ void cucul_draw_sprite(cucul_t *qq, int x, int y, struct cucul_sprite const *spr
* \param sprite The sprite to be freed. * \param sprite The sprite to be freed.
* \return void * \return void
*/ */
void cucul_free_sprite(struct cucul_sprite *sprite)
void cucul_free_sprite(cucul_sprite_t *sprite)
{ {
int i; int i;




+ 2
- 2
src/aafire.c View File

@@ -42,7 +42,7 @@
static cucul_t *qq; static cucul_t *qq;
static caca_t *kk; static caca_t *kk;
static int XSIZ, YSIZ; static int XSIZ, YSIZ;
static struct cucul_dither *cucul_dither;
static cucul_dither_t *cucul_dither;
static char *bitmap; static char *bitmap;
static int pause = 0; static int pause = 0;
#else #else
@@ -265,7 +265,7 @@ game (void)
#endif #endif
{ {
#ifdef LIBCACA #ifdef LIBCACA
struct caca_event ev;
caca_event_t ev;
if(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0)) if(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0))
{ {
switch(ev.data.key.c) switch(ev.data.key.c)


+ 2
- 2
src/cacaball.c View File

@@ -46,7 +46,7 @@ int main(int argc, char **argv)
unsigned int r[256], g[256], b[256], a[256]; unsigned int r[256], g[256], b[256], a[256];
float d[METABALLS], di[METABALLS], dj[METABALLS], dk[METABALLS]; float d[METABALLS], di[METABALLS], dj[METABALLS], dk[METABALLS];
unsigned int x[METABALLS], y[METABALLS]; unsigned int x[METABALLS], y[METABALLS];
struct cucul_dither *cucul_dither;
cucul_dither_t *cucul_dither;
float i = 10.0, j = 17.0, k = 11.0; float i = 10.0, j = 17.0, k = 11.0;
int p, frame = 0, pause = 0; int p, frame = 0, pause = 0;
double frameOffset[360 + 80]; double frameOffset[360 + 80];
@@ -92,7 +92,7 @@ int main(int argc, char **argv)
/* Go ! */ /* Go ! */
for(;;) for(;;)
{ {
struct caca_event ev;
caca_event_t ev;
if(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0)) if(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0))
{ {
switch(ev.data.key.c) switch(ev.data.key.c)


+ 2
- 2
src/cacamoir.c View File

@@ -39,7 +39,7 @@ int main (int argc, char **argv)
{ {
cucul_t *qq; caca_t *kk; cucul_t *qq; caca_t *kk;
unsigned int red[256], green[256], blue[256], alpha[256]; unsigned int red[256], green[256], blue[256], alpha[256];
struct cucul_dither *dither;
cucul_dither_t *dither;
int i, x, y, frame = 0, pause = 0; int i, x, y, frame = 0, pause = 0;


qq = cucul_create(0, 0); qq = cucul_create(0, 0);
@@ -68,7 +68,7 @@ int main (int argc, char **argv)
/* Main loop */ /* Main loop */
for(;;) for(;;)
{ {
struct caca_event ev;
caca_event_t ev;
if(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0)) if(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0))
{ {
switch(ev.data.key.c) switch(ev.data.key.c)


+ 2
- 2
src/cacaplas.c View File

@@ -43,7 +43,7 @@ int main (int argc, char **argv)
cucul_t *qq, *qq2, *mask; caca_t *kk; cucul_t *qq, *qq2, *mask; caca_t *kk;
unsigned int red[256], green[256], blue[256], alpha[256]; unsigned int red[256], green[256], blue[256], alpha[256];
double r[3], R[6]; double r[3], R[6];
struct cucul_dither *dither;
cucul_dither_t *dither;
int i, x, y, frame = 0, pause = 0; int i, x, y, frame = 0, pause = 0;


qq = cucul_create(0, 0); qq = cucul_create(0, 0);
@@ -84,7 +84,7 @@ int main (int argc, char **argv)
/* Main loop */ /* Main loop */
for(;;) for(;;)
{ {
struct caca_event ev;
caca_event_t ev;
if(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0)) if(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0))
{ {
switch(ev.data.key.c) switch(ev.data.key.c)


+ 1
- 1
src/cacaplay.c View File

@@ -26,7 +26,7 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct stat statbuf; struct stat statbuf;
struct caca_event ev;
caca_event_t ev;
cucul_t *qq; cucul_t *qq;
caca_t *kk; caca_t *kk;
void *buffer; void *buffer;


+ 24
- 22
src/cacaserver.c View File

@@ -105,7 +105,9 @@ struct server
char prefix[sizeof(INIT_PREFIX)]; char prefix[sizeof(INIT_PREFIX)];


cucul_t *qq; cucul_t *qq;
struct cucul_buffer *ex;
cucul_buffer_t *buffer;
unsigned long int buflen;
void *bufdata;


int client_count; int client_count;
struct client *clients; struct client *clients;
@@ -183,7 +185,7 @@ int main(void)
} }


server->qq = NULL; server->qq = NULL;
server->ex = NULL;
server->buffer = NULL;


/* Ignore SIGPIPE */ /* Ignore SIGPIPE */
server->sigpipe_handler = signal(SIGPIPE, SIG_IGN); server->sigpipe_handler = signal(SIGPIPE, SIG_IGN);
@@ -230,16 +232,16 @@ int main(void)
continue; /* Load error */ continue; /* Load error */


/* Free the previous export buffer, if any */ /* Free the previous export buffer, if any */
if(server->ex)
if(server->buffer)
{ {
cucul_free_export(server->ex);
server->ex = NULL;
cucul_free_buffer(server->buffer);
server->buffer = NULL;
} }


/* Get ANSI representation of the image and skip the end-of buffer /* Get ANSI representation of the image and skip the end-of buffer
* linefeed ("\r\n\0", 3 bytes) */ * linefeed ("\r\n\0", 3 bytes) */
server->ex = cucul_create_export(server->qq, "ansi");
server->ex->size -= 3;
server->buffer = cucul_create_export(server->qq, "ansi");
server->buflen -= 3;


for(i = 0; i < server->client_count; i++) for(i = 0; i < server->client_count; i++)
{ {
@@ -266,8 +268,8 @@ int main(void)
server->clients[i].fd = -1; server->clients[i].fd = -1;
} }


if(server->ex)
cucul_free_export(server->ex);
if(server->buffer)
cucul_free_buffer(server->buffer);


/* Restore SIGPIPE handler */ /* Restore SIGPIPE handler */
signal(SIGPIPE, server->sigpipe_handler); signal(SIGPIPE, server->sigpipe_handler);
@@ -395,7 +397,7 @@ static int send_data(struct server *server, struct client *c)
} }


/* No error, there's just nothing to send yet */ /* No error, there's just nothing to send yet */
if(!server->ex)
if(!server->buffer)
return 0; return 0;


/* If we have backlog, send the backlog */ /* If we have backlog, send the backlog */
@@ -420,7 +422,7 @@ static int send_data(struct server *server, struct client *c)
{ {
c->start += ret; c->start += ret;


if(c->stop - c->start + strlen(ANSI_PREFIX) + server->ex->size
if(c->stop - c->start + strlen(ANSI_PREFIX) + server->buflen
> OUTBUFFER) > OUTBUFFER)
{ {
/* Overflow! Empty buffer and start again */ /* Overflow! Empty buffer and start again */
@@ -431,7 +433,7 @@ static int send_data(struct server *server, struct client *c)
} }


/* Need to move? */ /* Need to move? */
if(c->stop + strlen(ANSI_PREFIX) + server->ex->size > OUTBUFFER)
if(c->stop + strlen(ANSI_PREFIX) + server->buflen > OUTBUFFER)
{ {
memmove(c->outbuf, c->outbuf + c->start, c->stop - c->start); memmove(c->outbuf, c->outbuf + c->start, c->stop - c->start);
c->stop -= c->start; c->stop -= c->start;
@@ -440,8 +442,8 @@ static int send_data(struct server *server, struct client *c)


memcpy(c->outbuf + c->stop, ANSI_PREFIX, strlen(ANSI_PREFIX)); memcpy(c->outbuf + c->stop, ANSI_PREFIX, strlen(ANSI_PREFIX));
c->stop += strlen(ANSI_PREFIX); c->stop += strlen(ANSI_PREFIX);
memcpy(c->outbuf + c->stop, server->ex->data, server->ex->size);
c->stop += server->ex->size;
memcpy(c->outbuf + c->stop, server->bufdata, server->buflen);
c->stop += server->buflen;


return 0; return 0;
} }
@@ -461,7 +463,7 @@ static int send_data(struct server *server, struct client *c)


if(ret < (ssize_t)strlen(ANSI_PREFIX)) if(ret < (ssize_t)strlen(ANSI_PREFIX))
{ {
if(strlen(ANSI_PREFIX) + server->ex->size > OUTBUFFER)
if(strlen(ANSI_PREFIX) + server->buflen > OUTBUFFER)
{ {
/* Overflow! Empty buffer and start again */ /* Overflow! Empty buffer and start again */
memcpy(c->outbuf, ANSI_RESET, strlen(ANSI_RESET)); memcpy(c->outbuf, ANSI_RESET, strlen(ANSI_RESET));
@@ -472,14 +474,14 @@ static int send_data(struct server *server, struct client *c)


memcpy(c->outbuf, ANSI_PREFIX, strlen(ANSI_PREFIX) - ret); memcpy(c->outbuf, ANSI_PREFIX, strlen(ANSI_PREFIX) - ret);
c->stop = strlen(ANSI_PREFIX) - ret; c->stop = strlen(ANSI_PREFIX) - ret;
memcpy(c->outbuf + c->stop, server->ex->data, server->ex->size);
c->stop += server->ex->size;
memcpy(c->outbuf + c->stop, server->bufdata, server->buflen);
c->stop += server->buflen;


return 0; return 0;
} }


/* Send actual data */ /* Send actual data */
ret = nonblock_write(c->fd, server->ex->data, server->ex->size);
ret = nonblock_write(c->fd, server->bufdata, server->buflen);
if(ret == -1) if(ret == -1)
{ {
if(errno == EAGAIN) if(errno == EAGAIN)
@@ -488,9 +490,9 @@ static int send_data(struct server *server, struct client *c)
return -1; return -1;
} }


if(ret < (int)server->ex->size)
if(ret < (int)server->buflen)
{ {
if(server->ex->size > OUTBUFFER)
if(server->buflen > OUTBUFFER)
{ {
/* Overflow! Empty buffer and start again */ /* Overflow! Empty buffer and start again */
memcpy(c->outbuf, ANSI_RESET, strlen(ANSI_RESET)); memcpy(c->outbuf, ANSI_RESET, strlen(ANSI_RESET));
@@ -499,8 +501,8 @@ static int send_data(struct server *server, struct client *c)
return 0; return 0;
} }


memcpy(c->outbuf, server->ex->data, server->ex->size - ret);
c->stop = server->ex->size - ret;
memcpy(c->outbuf, server->bufdata, server->buflen - ret);
c->stop = server->buflen - ret;


return 0; return 0;
} }


+ 1
- 1
src/cacaview.c View File

@@ -123,7 +123,7 @@ int main(int argc, char **argv)
/* Go ! */ /* Go ! */
while(!quit) while(!quit)
{ {
struct caca_event ev;
caca_event_t ev;
unsigned int const event_mask = CACA_EVENT_KEY_PRESS unsigned int const event_mask = CACA_EVENT_KEY_PRESS
| CACA_EVENT_RESIZE | CACA_EVENT_RESIZE
| CACA_EVENT_MOUSE_PRESS; | CACA_EVENT_MOUSE_PRESS;


+ 4
- 3
src/img2irc.c View File

@@ -24,7 +24,7 @@ int main(int argc, char **argv)
{ {
/* libcucul context */ /* libcucul context */
cucul_t *qq; cucul_t *qq;
struct cucul_buffer *export;
cucul_buffer_t *export;
struct image *i; struct image *i;
int cols = 56, lines; int cols = 56, lines;


@@ -59,8 +59,9 @@ int main(int argc, char **argv)
unload_image(i); unload_image(i);


export = cucul_create_export(qq, "irc"); export = cucul_create_export(qq, "irc");
fwrite(export->data, export->size, 1, stdout);
cucul_free_export(export);
fwrite(cucul_get_buffer_data(export),
cucul_get_buffer_size(export), 1, stdout);
cucul_free_buffer(export);


cucul_free(qq); cucul_free(qq);




+ 1
- 1
test/colors.c View File

@@ -24,7 +24,7 @@ int main(int argc, char **argv)
{ {
cucul_t *qq; cucul_t *qq;
caca_t *kk; caca_t *kk;
struct caca_event ev;
caca_event_t ev;
int i, j; int i, j;


qq = cucul_create(0, 0); qq = cucul_create(0, 0);


+ 4
- 4
test/demo.c View File

@@ -35,7 +35,7 @@ static void demo_render(void);
int bounds = 0; int bounds = 0;
int outline = 0; int outline = 0;
int dithering = 0; int dithering = 0;
struct cucul_sprite *sprite = NULL;
cucul_sprite_t *sprite = NULL;


cucul_t *qq; cucul_t *qq;
caca_t *kk; caca_t *kk;
@@ -71,7 +71,7 @@ int main(int argc, char **argv)
/* Go ! */ /* Go ! */
while(!quit) while(!quit)
{ {
struct caca_event ev;
caca_event_t ev;
int menu = 0, mouse = 0, xmouse = 0, ymouse = 0; int menu = 0, mouse = 0, xmouse = 0, ymouse = 0;


while(caca_get_event(kk, CACA_EVENT_ANY, &ev, 0)) while(caca_get_event(kk, CACA_EVENT_ANY, &ev, 0))
@@ -483,7 +483,7 @@ static void demo_sprites(void)
#if 0 #if 0
static void demo_render(void) static void demo_render(void)
{ {
struct cucul_dither *dither;
cucul_dither_t *dither;
//short buffer[256*256]; //short buffer[256*256];
//short *dest = buffer; //short *dest = buffer;
int buffer[256*256]; int buffer[256*256];
@@ -513,7 +513,7 @@ static void draw_circle(int *buffer, int xo, int yo, int r, int mask, int val);


static void demo_render(void) static void demo_render(void)
{ {
struct cucul_dither *dither;
cucul_dither_t *dither;
int buffer[256*256]; int buffer[256*256];
int *dest; int *dest;
int x, y, z, xo, yo; int x, y, z, xo, yo;


+ 1
- 1
test/dithering.c View File

@@ -34,7 +34,7 @@ char density[] = " -,+:;o&%w$W@#";


int main(void) int main(void)
{ {
struct caca_event ev;
caca_event_t ev;
cucul_t *qq; cucul_t *qq;
caca_t *kk; caca_t *kk;
int neara, dista, nearb, distb, dist; int neara, dista, nearb, distb, dist;


+ 7
- 7
test/event.c View File

@@ -23,11 +23,11 @@
static cucul_t *qq; static cucul_t *qq;
static caca_t *kk; static caca_t *kk;


static void print_event(int, int, struct caca_event *);
static void print_event(int, int, caca_event_t *);


int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct caca_event *events;
caca_event_t *events;
int i, h, quit; int i, h, quit;


qq = cucul_create(0, 0); qq = cucul_create(0, 0);
@@ -47,12 +47,12 @@ int main(int argc, char **argv)


caca_display(kk); caca_display(kk);


events = malloc(h * sizeof(struct caca_event));
memset(events, 0, h * sizeof(struct caca_event));
events = malloc(h * sizeof(caca_event_t));
memset(events, 0, h * sizeof(caca_event_t));


for(quit = 0; quit < 4; ) for(quit = 0; quit < 4; )
{ {
struct caca_event ev;
caca_event_t ev;
static char const * quit_string[] = { "", "q", "qu", "qui", "quit" }; static char const * quit_string[] = { "", "q", "qu", "qui", "quit" };
int ret = caca_get_event(kk, CACA_EVENT_ANY, &ev, -1); int ret = caca_get_event(kk, CACA_EVENT_ANY, &ev, -1);


@@ -74,7 +74,7 @@ int main(int argc, char **argv)
quit = 0; quit = 0;
} }


memmove(events + 1, events, (h - 1) * sizeof(struct caca_event));
memmove(events + 1, events, (h - 1) * sizeof(caca_event_t));
events[0] = ev; events[0] = ev;


ret = caca_get_event(kk, CACA_EVENT_ANY, &ev, 0); ret = caca_get_event(kk, CACA_EVENT_ANY, &ev, 0);
@@ -106,7 +106,7 @@ int main(int argc, char **argv)
return 0; return 0;
} }


static void print_event(int x, int y, struct caca_event *ev)
static void print_event(int x, int y, caca_event_t *ev)
{ {
int character; int character;




+ 5
- 4
test/export.c View File

@@ -35,8 +35,8 @@ uint32_t pixels[256*256];
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
cucul_t *qq; cucul_t *qq;
struct cucul_dither *dither;
struct cucul_buffer *buffer;
cucul_dither_t *dither;
cucul_buffer_t *buffer;
int x, y; int x, y;


if(argc != 2) if(argc != 2)
@@ -90,8 +90,9 @@ int main(int argc, char *argv[])
cucul_putstr(qq, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA "); cucul_putstr(qq, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");


buffer = cucul_create_export(qq, argv[1]); buffer = cucul_create_export(qq, argv[1]);
fwrite(buffer->data, buffer->size, 1, stdout);
cucul_free_export(buffer);
fwrite(cucul_get_buffer_data(buffer),
cucul_get_buffer_size(buffer), 1, stdout);
cucul_free_buffer(buffer);


cucul_free(qq); cucul_free(qq);




+ 3
- 3
test/font.c View File

@@ -36,9 +36,9 @@ int main(int argc, char *argv[])
{ {
cucul_t *qq; cucul_t *qq;
caca_t *kk; caca_t *kk;
struct cucul_font *f;
struct cucul_dither *d;
struct caca_event ev;
cucul_font_t *f;
cucul_dither_t *d;
caca_event_t ev;
unsigned char *buf; unsigned char *buf;
unsigned int w, h; unsigned int w, h;
char const * const * fonts; char const * const * fonts;


+ 2
- 2
test/gamma.c View File

@@ -33,10 +33,10 @@ uint32_t buffer[256 * 4];


int main(void) int main(void)
{ {
struct caca_event ev;
caca_event_t ev;
cucul_t *qq, *gg, *mask; cucul_t *qq, *gg, *mask;
caca_t *kk; caca_t *kk;
struct cucul_dither *left, *right;
cucul_dither_t *left, *right;
float gam = 1.0; float gam = 1.0;
int x; int x;




+ 2
- 2
test/hsv.c View File

@@ -28,11 +28,11 @@ uint32_t buffer[256*256];


int main(void) int main(void)
{ {
struct caca_event ev;
caca_event_t ev;
cucul_t *qq; cucul_t *qq;
caca_t *kk; caca_t *kk;


struct cucul_dither *dither;
cucul_dither_t *dither;
int x, y; int x, y;


qq = cucul_create(0, 0); qq = cucul_create(0, 0);


+ 2
- 2
test/spritedit.c View File

@@ -26,7 +26,7 @@ int main(int argc, char **argv)
caca_t *kk; caca_t *kk;


int quit = 0; int quit = 0;
struct cucul_sprite *sprite;
cucul_sprite_t *sprite;
int frame = 0; int frame = 0;
unsigned char play = 0; unsigned char play = 0;
unsigned int delay = 0; unsigned int delay = 0;
@@ -57,7 +57,7 @@ int main(int argc, char **argv)
/* Go ! */ /* Go ! */
while(!quit) while(!quit)
{ {
struct caca_event ev;
caca_event_t ev;
int xa, ya, xb, yb; int xa, ya, xb, yb;
char buf[BUFSIZ]; char buf[BUFSIZ];




+ 1
- 1
test/transform.c View File

@@ -49,7 +49,7 @@ static char const *duck[] =


int main(void) int main(void)
{ {
struct caca_event ev;
caca_event_t ev;
cucul_t *qq, *normal, *flip, *flop, *rotate; cucul_t *qq, *normal, *flip, *flop, *rotate;
caca_t *kk; caca_t *kk;
int i; int i;


+ 1
- 1
test/unicode.c View File

@@ -26,7 +26,7 @@ typedef unsigned int uint32_t;


int main(void) int main(void)
{ {
struct caca_event ev;
caca_event_t ev;
cucul_t *qq; cucul_t *qq;
caca_t *kk; caca_t *kk;




Loading…
Cancel
Save