Browse Source

* Renamed main canvas-related functions so that they have "canvas" in

their name, eg. cucul_create() -> cucul_create_canvas() etc.
  * Moved buffer-related functions to cucul/buffer.c.
tags/v0.99.beta14
Sam Hocevar sam 18 years ago
parent
commit
18f6532dbc
36 changed files with 274 additions and 234 deletions
  1. +2
    -2
      caca/driver_conio.c
  2. +1
    -1
      caca/driver_gl.c
  3. +1
    -1
      caca/driver_ncurses.c
  4. +1
    -1
      caca/driver_slang.c
  5. +1
    -1
      caca/driver_vga.c
  6. +2
    -2
      caca/driver_win32.c
  7. +1
    -1
      caca/driver_x11.c
  8. +1
    -1
      caca/graphics.c
  9. +6
    -6
      cpp/cucul++.cpp
  10. +1
    -0
      cucul/Makefile.am
  11. +67
    -0
      cucul/buffer.c
  12. +18
    -56
      cucul/cucul.c
  13. +6
    -6
      cucul/cucul.h
  14. +1
    -1
      cucul/cucul_internals.h
  15. +2
    -2
      cucul/export.c
  16. +4
    -3
      cucul/font.c
  17. +12
    -11
      src/aafire.c
  18. +7
    -5
      src/cacaball.c
  19. +7
    -5
      src/cacamoir.c
  20. +11
    -7
      src/cacaplas.c
  21. +2
    -2
      src/cacaplay.c
  22. +2
    -2
      src/cacaserver.c
  23. +12
    -10
      src/cacaview.c
  24. +4
    -4
      src/img2irc.c
  25. +2
    -2
      test/colors.c
  26. +41
    -40
      test/demo.c
  27. +4
    -4
      test/dithering.c
  28. +7
    -7
      test/event.c
  29. +4
    -5
      test/export.c
  30. +7
    -7
      test/font.c
  31. +14
    -16
      test/gamma.c
  32. +4
    -5
      test/hsv.c
  33. +5
    -4
      test/spritedit.c
  34. +10
    -10
      test/transform.c
  35. +2
    -2
      test/truecolor.c
  36. +2
    -2
      test/unicode.c

+ 2
- 2
caca/driver_conio.c View File

@@ -56,8 +56,8 @@ static int conio_init_graphics(caca_display_t *dp)
# else # else
/* FIXME */ /* FIXME */
# endif # endif
_cucul_set_size(dp->cv, dp->drv.p->ti.screenwidth,
dp->drv.p->ti.screenheight);
_cucul_set_canvas_size(dp->cv, dp->drv.p->ti.screenwidth,
dp->drv.p->ti.screenheight);
return 0; return 0;
} }




+ 1
- 1
caca/driver_gl.c View File

@@ -96,7 +96,7 @@ static int gl_init_graphics(caca_display_t *dp)
#endif #endif


if(width && height) if(width && height)
_cucul_set_size(dp->cv, width, height);
_cucul_set_canvas_size(dp->cv, width, height);


dp->drv.p->font_width = 9; dp->drv.p->font_width = 9;
dp->drv.p->font_height = 15; dp->drv.p->font_height = 15;


+ 1
- 1
caca/driver_ncurses.c View File

@@ -151,7 +151,7 @@ static int ncurses_init_graphics(caca_display_t *dp)
} }
} }


_cucul_set_size(dp->cv, COLS, LINES);
_cucul_set_canvas_size(dp->cv, COLS, LINES);


return 0; return 0;
} }


+ 1
- 1
caca/driver_slang.c View File

@@ -164,7 +164,7 @@ static int slang_init_graphics(caca_display_t *dp)
SLtt_utf8_enable(1); SLtt_utf8_enable(1);
#endif #endif


_cucul_set_size(dp->cv, SLtt_Screen_Cols, SLtt_Screen_Rows);
_cucul_set_canvas_size(dp->cv, SLtt_Screen_Cols, SLtt_Screen_Rows);


return 0; return 0;
} }


+ 1
- 1
caca/driver_vga.c View File

@@ -74,7 +74,7 @@ static int vga_init_graphics(caca_display_t *dp)
outb(tmp, 0x3d5); outb(tmp, 0x3d5);


/* We don't have much choice */ /* We don't have much choice */
_cucul_set_size(dp->cv, 80, 25);
_cucul_set_canvas_size(dp->cv, 80, 25);


return 0; return 0;
} }


+ 2
- 2
caca/driver_win32.c View File

@@ -124,8 +124,8 @@ static int win32_init_graphics(caca_display_t *dp)
if(!GetConsoleScreenBufferInfo(dp->drv.p->screen, &csbi)) if(!GetConsoleScreenBufferInfo(dp->drv.p->screen, &csbi))
return -1; return -1;


_cucul_set_size(dp->cv, csbi.srWindow.Right - csbi.srWindow.Left + 1,
csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
_cucul_set_canvas_size(dp->cv, csbi.srWindow.Right - csbi.srWindow.Left + 1,
csbi.srWindow.Bottom - csbi.srWindow.Top + 1);


SetConsoleMode(dp->drv.p->screen, 0); SetConsoleMode(dp->drv.p->screen, 0);




+ 1
- 1
caca/driver_x11.c View File

@@ -78,7 +78,7 @@ static int x11_init_graphics(caca_display_t *dp)
#endif #endif


if(width && height) if(width && height)
_cucul_set_size(dp->cv, width, height);
_cucul_set_canvas_size(dp->cv, width, height);


dp->drv.p->dpy = XOpenDisplay(NULL); dp->drv.p->dpy = XOpenDisplay(NULL);
if(dp->drv.p->dpy == NULL) if(dp->drv.p->dpy == NULL)


+ 1
- 1
caca/graphics.c View File

@@ -173,6 +173,6 @@ void _caca_handle_resize(caca_display_t *dp)


/* Tell libcucul we changed size */ /* Tell libcucul we changed size */
if(dp->resize.w != dp->cv->width || dp->resize.h != dp->cv->height) if(dp->resize.w != dp->cv->width || dp->resize.h != dp->cv->height)
_cucul_set_size(dp->cv, dp->resize.w, dp->resize.h);
_cucul_set_canvas_size(dp->cv, dp->resize.w, dp->resize.h);
} }



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

@@ -20,18 +20,18 @@


Cucul::Cucul() Cucul::Cucul()
{ {
cv = cucul_create(0,0);
cv = cucul_create_canvas(0,0);
if(!cv) throw -1; if(!cv) throw -1;
} }
Cucul::Cucul(int width, int height) Cucul::Cucul(int width, int height)
{ {
cv = cucul_create(width, height);
cv = cucul_create_canvas(width, height);
if(!cv) throw -1; if(!cv) throw -1;
} }
Cucul::~Cucul() Cucul::~Cucul()
{ {
if(cv) { if(cv) {
cucul_free(cv);
cucul_free_canvas(cv);
} }
} }


@@ -44,15 +44,15 @@ cucul_canvas_t *Cucul::get_cucul_canvas_t()


void Cucul::set_size(unsigned int width, unsigned int height) void Cucul::set_size(unsigned int width, unsigned int height)
{ {
cucul_set_size (cv, width, height);
cucul_set_canvas_size (cv, width, height);
} }
unsigned int Cucul::get_width(void) unsigned int Cucul::get_width(void)
{ {
return cucul_get_width (cv);
return cucul_get_canvas_width (cv);
} }
unsigned int Cucul::get_height(void) unsigned int Cucul::get_height(void)
{ {
return cucul_get_height (cv);
return cucul_get_canvas_height (cv);
} }
void Cucul::set_color(unsigned int f, unsigned int b) void Cucul::set_color(unsigned int f, unsigned int b)
{ {


+ 1
- 0
cucul/Makefile.am View File

@@ -14,6 +14,7 @@ libcucul_la_SOURCES = \
cucul.c \ cucul.c \
cucul.h \ cucul.h \
cucul_internals.h \ cucul_internals.h \
buffer.c \
canvas.c \ canvas.c \
transform.c \ transform.c \
charset.c \ charset.c \


+ 67
- 0
cucul/buffer.c View File

@@ -0,0 +1,67 @@
/*
* 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 buffer handling functions.
*/

#include "config.h"

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

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

/** \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(buf->data);
free(buf);
}


+ 18
- 56
cucul/cucul.c View File

@@ -31,8 +31,8 @@
* *
* This function initialises internal \e libcucul structures and the backend * This function initialises internal \e libcucul structures and the backend
* that will be used for subsequent graphical operations. It must be the * that will be used for subsequent graphical operations. It must be the
* first \e libcucul function to be called in a function. cucul_free() should
* be called at the end of the program to free all allocated resources.
* first \e libcucul function to be called in a function. cucul_free_canvas()
* should be called at the end of the program to free all allocated resources.
* *
* If one of the desired canvas coordinates is zero, a default canvas size * If one of the desired canvas coordinates is zero, a default canvas size
* of 80x32 is used instead. * of 80x32 is used instead.
@@ -41,7 +41,7 @@
* \param height The desired canvas height * \param height The desired canvas height
* \return A libcucul canvas handle upon success, NULL if an error occurred. * \return A libcucul canvas handle upon success, NULL if an error occurred.
*/ */
cucul_canvas_t * cucul_create(unsigned int width, unsigned int height)
cucul_canvas_t * cucul_create_canvas(unsigned int width, unsigned int height)
{ {
cucul_canvas_t *cv = malloc(sizeof(cucul_canvas_t)); cucul_canvas_t *cv = malloc(sizeof(cucul_canvas_t));


@@ -59,9 +59,9 @@ cucul_canvas_t * cucul_create(unsigned int width, unsigned int height)
* default X11 window. When a graphic driver attaches to us, it can set * default X11 window. When a graphic driver attaches to us, it can set
* a different size. */ * a different size. */
if(width && height) if(width && height)
_cucul_set_size(cv, width, height);
_cucul_set_canvas_size(cv, width, height);
else else
_cucul_set_size(cv, 80, 32);
_cucul_set_canvas_size(cv, 80, 32);


if(_cucul_init_dither()) if(_cucul_init_dither())
{ {
@@ -81,7 +81,7 @@ cucul_canvas_t * cucul_create(unsigned int width, unsigned int height)
* \param size The length of the memory area. * \param size The length of the memory area.
* \return A libcucul canvas, or NULL in case of error. * \return A libcucul canvas, or NULL in case of error.
*/ */
cucul_canvas_t *cucul_load(void *data, unsigned int size)
cucul_canvas_t *cucul_load_canvas(void *data, unsigned int size)
{ {
cucul_canvas_t *cv; cucul_canvas_t *cv;
uint8_t *buf = (uint8_t *)data; uint8_t *buf = (uint8_t *)data;
@@ -108,7 +108,7 @@ cucul_canvas_t *cucul_load(void *data, unsigned int size)
|| buf[size - 2] != 'A' || buf[size - 1] != 'C') || buf[size - 2] != 'A' || buf[size - 1] != 'C')
return NULL; return NULL;


cv = cucul_create(width, height);
cv = cucul_create_canvas(width, height);


if(!cv) if(!cv)
return NULL; return NULL;
@@ -147,12 +147,13 @@ cucul_canvas_t *cucul_load(void *data, unsigned int size)
* \param width The desired canvas width * \param width The desired canvas width
* \param height The desired canvas height * \param height The desired canvas height
*/ */
void cucul_set_size(cucul_canvas_t *cv, unsigned int width, unsigned int height)
void cucul_set_canvas_size(cucul_canvas_t *cv, unsigned int width,
unsigned int height)
{ {
if(cv->refcount) if(cv->refcount)
return; return;


_cucul_set_size(cv, width, height);
_cucul_set_canvas_size(cv, width, height);
} }


/** \brief Get the canvas width. /** \brief Get the canvas width.
@@ -162,7 +163,7 @@ void cucul_set_size(cucul_canvas_t *cv, unsigned int width, unsigned int height)
* \param cv A libcucul canvas * \param cv A libcucul canvas
* \return The canvas width. * \return The canvas width.
*/ */
unsigned int cucul_get_width(cucul_canvas_t *cv)
unsigned int cucul_get_canvas_width(cucul_canvas_t *cv)
{ {
return cv->width; return cv->width;
} }
@@ -174,7 +175,7 @@ unsigned int cucul_get_width(cucul_canvas_t *cv)
* \param cv A libcucul canvas * \param cv A libcucul canvas
* \return The canvas height. * \return The canvas height.
*/ */
unsigned int cucul_get_height(cucul_canvas_t *cv)
unsigned int cucul_get_canvas_height(cucul_canvas_t *cv)
{ {
return cv->height; return cv->height;
} }
@@ -217,13 +218,13 @@ char const *cucul_get_color_name(unsigned int color)


/** \brief Uninitialise \e libcucul. /** \brief Uninitialise \e libcucul.
* *
* This function frees all resources allocated by cucul_create(). After
* cucul_free() has been called, no other \e libcucul functions may be used
* unless a new call to cucul_create() is done.
* This function frees all resources allocated by cucul_create_canvas(). After
* cucul_free_canvas() has been called, no other \e libcucul functions may be
* used unless a new call to cucul_create_canvas() is done.
* *
* \param cv A libcucul canvas * \param cv A libcucul canvas
*/ */
void cucul_free(cucul_canvas_t *cv)
void cucul_free_canvas(cucul_canvas_t *cv)
{ {
_cucul_end_dither(); _cucul_end_dither();


@@ -247,51 +248,12 @@ int cucul_rand(int min, int max)
return min + (int)((1.0*(max-min+1)) * rand() / (RAND_MAX+1.0)); return min + (int)((1.0*(max-min+1)) * rand() / (RAND_MAX+1.0));
} }


/** \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(buf->data);
free(buf);
}

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


void _cucul_set_size(cucul_canvas_t *cv, unsigned int width,
unsigned int height)
void _cucul_set_canvas_size(cucul_canvas_t *cv, unsigned int width,
unsigned int height)
{ {
unsigned int x, y, old_width, old_height, new_size, old_size; unsigned int x, y, old_width, old_height, new_size, old_size;




+ 6
- 6
cucul/cucul.h View File

@@ -73,12 +73,12 @@ typedef struct cucul_font cucul_font_t;
* initialisation, system information retrieval and configuration. * initialisation, system information retrieval and configuration.
* *
* @{ */ * @{ */
cucul_canvas_t * cucul_create(unsigned int, unsigned int);
cucul_canvas_t * cucul_load(void *, unsigned int);
void cucul_set_size(cucul_canvas_t *, unsigned int, unsigned int);
unsigned int cucul_get_width(cucul_canvas_t *);
unsigned int cucul_get_height(cucul_canvas_t *);
void cucul_free(cucul_canvas_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 *);
void cucul_free_canvas(cucul_canvas_t *);
int cucul_rand(int, int); int cucul_rand(int, int);
/* @} */ /* @} */




+ 1
- 1
cucul/cucul_internals.h View File

@@ -51,7 +51,7 @@ extern int _cucul_init_dither(void);
extern int _cucul_end_dither(void); extern int _cucul_end_dither(void);


/* Canvas functions */ /* Canvas functions */
extern void _cucul_set_size(cucul_canvas_t *, unsigned int, unsigned int);
extern void _cucul_set_canvas_size(cucul_canvas_t *, unsigned int, unsigned int);
extern void _cucul_putchar32(cucul_canvas_t *, int, int, uint32_t); extern void _cucul_putchar32(cucul_canvas_t *, int, int, uint32_t);


/* Charset functions */ /* Charset functions */


+ 2
- 2
cucul/export.c View File

@@ -614,8 +614,8 @@ static void export_tga(cucul_canvas_t *cv, cucul_buffer_t *ex)


f = cucul_load_font(fontlist[0], 0); f = cucul_load_font(fontlist[0], 0);


w = cucul_get_width(cv) * cucul_get_font_width(f);
h = cucul_get_height(cv) * cucul_get_font_height(f);
w = cucul_get_canvas_width(cv) * cucul_get_font_width(f);
h = cucul_get_canvas_height(cv) * cucul_get_font_height(f);


ex->size = w * h * 4 + 18; /* 32 bpp + 18 bytes for the header */ ex->size = w * h * 4 + 18; /* 32 bpp + 18 bytes for the header */
ex->data = malloc(ex->size); ex->data = malloc(ex->size);


+ 4
- 3
cucul/font.c View File

@@ -259,9 +259,10 @@ void cucul_free_font(cucul_font_t *f)
* This function renders the given canvas on an image buffer using a specific * This function renders the given canvas on an image buffer using a specific
* font. The pixel format is fixed (32-bit ARGB, 8 bits for each component). * font. The pixel format is fixed (32-bit ARGB, 8 bits for each component).
* *
* The required image width can be computed using \e cucul_get_width(cv) and
* \e cucul_get_font_width(f). The required height can be computed using
* \e cucul_get_height(cv) and \e cucul_get_font_height(f).
* The required image width can be computed using
* \e cucul_get_canvas_width(cv) and \e cucul_get_font_width(f). The required
* height can be computed using \e cucul_get_canvas_height(cv) and
* \e cucul_get_font_height(f).
* *
* Glyphs that do not fit in the image buffer are currently not rendered at * Glyphs that do not fit in the image buffer are currently not rendered at
* all. They may be cropped instead in future versions. * all. They may be cropped instead in future versions.


+ 12
- 11
src/aafire.c View File

@@ -100,7 +100,7 @@ initialize (void)
#endif #endif


#ifdef LIBCACA #ifdef LIBCACA
cv = cucul_create(80, 32);
cv = cucul_create_canvas(80, 32);
if (!cv) if (!cv)
{ {
printf ("Failed to initialize libcucul\n"); printf ("Failed to initialize libcucul\n");
@@ -113,8 +113,8 @@ initialize (void)
exit (1); exit (1);
} }
caca_set_delay(dp, 10000); caca_set_delay(dp, 10000);
XSIZ = cucul_get_width(cv) * 2;
YSIZ = cucul_get_height(cv) * 2 - 4;
XSIZ = cucul_get_canvas_width(cv) * 2;
YSIZ = cucul_get_canvas_height(cv) * 2 - 4;
#else #else
context = aa_autoinit (&aa_defparams); context = aa_autoinit (&aa_defparams);
if (context == NULL) if (context == NULL)
@@ -142,8 +142,10 @@ initialize (void)
#ifdef LIBCACA #ifdef LIBCACA
cucul_dither = cucul_create_dither(8, XSIZ, YSIZ - 2, XSIZ, 0, 0, 0, 0); cucul_dither = cucul_create_dither(8, XSIZ, YSIZ - 2, XSIZ, 0, 0, 0, 0);
cucul_set_dither_palette(cucul_dither, r, g, b, a); cucul_set_dither_palette(cucul_dither, r, g, b, a);
bitmap = malloc(4 * cucul_get_width(cv) * cucul_get_height(cv) * sizeof(char));
memset(bitmap, 0, 4 * cucul_get_width(cv) * cucul_get_height(cv));
bitmap = malloc(4 * cucul_get_canvas_width(cv)
* cucul_get_canvas_height(cv));
memset(bitmap, 0, 4 * cucul_get_canvas_width(cv)
* cucul_get_canvas_height(cv));
#else #else
aa_hidecursor (context); aa_hidecursor (context);
#endif #endif
@@ -153,7 +155,7 @@ uninitialize (void)
{ {
#ifdef LIBCACA #ifdef LIBCACA
caca_detach(dp); caca_detach(dp);
cucul_free(cv);
cucul_free_canvas(cv);
#else #else
aa_close (context); aa_close (context);
#endif #endif
@@ -235,12 +237,11 @@ drawfire (void)
firemain (); firemain ();
#ifdef LIBCACA #ifdef LIBCACA
paused: paused:
cucul_dither_bitmap(cv, 0, 0,
cucul_get_width(cv) - 1, cucul_get_height(cv) - 1,
cucul_dither, bitmap);
cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv) - 1,
cucul_get_canvas_height(cv) - 1, cucul_dither, bitmap);
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(cv, cucul_get_width(cv) - 30, cucul_get_height(cv) - 2,
" -=[ Powered by libcaca ]=- ");
cucul_putstr(cv, cucul_get_canvas_width(cv) - 30,
cucul_get_canvas_height(cv) - 2, " -=[ Powered by libcaca ]=- ");
caca_display(dp); caca_display(dp);
/*XSIZ = caca_get_width() * 2; /*XSIZ = caca_get_width() * 2;


+ 7
- 5
src/cacaball.c View File

@@ -53,7 +53,7 @@ int main(int argc, char **argv)
double frameOffset40[360]; double frameOffset40[360];
double frameOffset80[360]; double frameOffset80[360];


cv = cucul_create(0, 0);
cv = cucul_create_canvas(0, 0);
if(!cv) if(!cv)
return 1; return 1;
dp = caca_attach(cv); dp = caca_attach(cv);
@@ -154,11 +154,13 @@ int main(int argc, char **argv)
paused: paused:
/* Draw our virtual buffer to screen, letting libcucul resize it */ /* Draw our virtual buffer to screen, letting libcucul resize it */
cucul_dither_bitmap(cv, 0, 0, cucul_dither_bitmap(cv, 0, 0,
cucul_get_width(cv) - 1, cucul_get_height(cv) - 1,
cucul_get_canvas_width(cv) - 1,
cucul_get_canvas_height(cv) - 1,
cucul_dither, pixels + (METASIZE / 2) * (1 + XSIZ)); cucul_dither, pixels + (METASIZE / 2) * (1 + XSIZ));
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(cv, cucul_get_width(cv) - 30, cucul_get_height(cv) - 2,
" -=[ Powered by libcaca ]=- ");
cucul_putstr(cv, cucul_get_canvas_width(cv) - 30,
cucul_get_canvas_height(cv) - 2,
" -=[ Powered by libcaca ]=- ");


caca_display(dp); caca_display(dp);
} }
@@ -167,7 +169,7 @@ paused:
end: end:
cucul_free_dither(cucul_dither); cucul_free_dither(cucul_dither);
caca_detach(dp); caca_detach(dp);
cucul_free(cv);
cucul_free_canvas(cv);


return 0; return 0;
} }


+ 7
- 5
src/cacamoir.c View File

@@ -42,7 +42,7 @@ int main (int argc, char **argv)
cucul_dither_t *dither; cucul_dither_t *dither;
int i, x, y, frame = 0, pause = 0; int i, x, y, frame = 0, pause = 0;


cv = cucul_create(0, 0);
cv = cucul_create_canvas(0, 0);
if(!cv) if(!cv)
return 1; return 1;
dp = caca_attach(cv); dp = caca_attach(cv);
@@ -107,18 +107,20 @@ int main (int argc, char **argv)


paused: paused:
cucul_dither_bitmap(cv, 0, 0, cucul_dither_bitmap(cv, 0, 0,
cucul_get_width(cv) - 1, cucul_get_height(cv) - 1,
cucul_get_canvas_width(cv) - 1,
cucul_get_canvas_height(cv) - 1,
dither, screen); dither, screen);
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(cv, cucul_get_width(cv) - 30, cucul_get_height(cv) - 2,
" -=[ Powered by libcaca ]=- ");
cucul_putstr(cv, cucul_get_canvas_width(cv) - 30,
cucul_get_canvas_height(cv) - 2,
" -=[ Powered by libcaca ]=- ");
caca_display(dp); caca_display(dp);
} }


end: end:
cucul_free_dither(dither); cucul_free_dither(dither);
caca_detach(dp); caca_detach(dp);
cucul_free(cv);
cucul_free_canvas(cv);


return 0; return 0;
} }


+ 11
- 7
src/cacaplas.c View File

@@ -46,7 +46,7 @@ int main (int argc, char **argv)
cucul_dither_t *dither; cucul_dither_t *dither;
int i, x, y, frame = 0, pause = 0; int i, x, y, frame = 0, pause = 0;


cv = cucul_create(0, 0);
cv = cucul_create_canvas(0, 0);
if(!cv) if(!cv)
return 1; return 1;
dp = caca_attach(cv); dp = caca_attach(cv);
@@ -55,8 +55,10 @@ int main (int argc, char **argv)


caca_set_delay(dp, 20000); caca_set_delay(dp, 20000);


c2 = cucul_create(cucul_get_width(cv), cucul_get_height(cv));
mask = cucul_create(cucul_get_width(cv), cucul_get_height(cv));
c2 = cucul_create_canvas(cucul_get_canvas_width(cv),
cucul_get_canvas_height(cv));
mask = cucul_create_canvas(cucul_get_canvas_width(cv),
cucul_get_canvas_height(cv));


/* Fill various tables */ /* Fill various tables */
for(i = 0 ; i < 256; i++) for(i = 0 ; i < 256; i++)
@@ -120,7 +122,8 @@ int main (int argc, char **argv)


paused: paused:
cucul_dither_bitmap(cv, 0, 0, cucul_dither_bitmap(cv, 0, 0,
cucul_get_width(cv) - 1, cucul_get_height(cv) - 1,
cucul_get_canvas_width(cv) - 1,
cucul_get_canvas_height(cv) - 1,
dither, screen); dither, screen);


cucul_blit(c2, 0, 0, cv, NULL); cucul_blit(c2, 0, 0, cv, NULL);
@@ -130,15 +133,16 @@ paused:
cucul_blit(cv, 0, 0, c2, mask); cucul_blit(cv, 0, 0, c2, mask);


cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(cv, cucul_get_width(cv) - 30, cucul_get_height(cv) - 2,
" -=[ Powered by libcaca ]=- ");
cucul_putstr(cv, cucul_get_canvas_width(cv) - 30,
cucul_get_canvas_height(cv) - 2,
" -=[ Powered by libcaca ]=- ");
caca_display(dp); caca_display(dp);
} }


end: end:
cucul_free_dither(dither); cucul_free_dither(dither);
caca_detach(dp); caca_detach(dp);
cucul_free(cv);
cucul_free_canvas(cv);


return 0; return 0;
} }


+ 2
- 2
src/cacaplay.c View File

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


buffer = malloc(statbuf.st_size); buffer = malloc(statbuf.st_size);
read(fd, buffer, statbuf.st_size); read(fd, buffer, statbuf.st_size);
cv = cucul_load(buffer, statbuf.st_size);
cv = cucul_load_canvas(buffer, statbuf.st_size);
free(buffer); free(buffer);


if(!cv) if(!cv)
@@ -74,7 +74,7 @@ int main(int argc, char **argv)


/* Clean up */ /* Clean up */
caca_detach(dp); caca_detach(dp);
cucul_free(cv);
cucul_free_canvas(cv);


return 0; return 0;
} }


+ 2
- 2
src/cacaserver.c View File

@@ -224,9 +224,9 @@ int main(void)


/* Free the previous canvas, if any */ /* Free the previous canvas, if any */
if(server->canvas) if(server->canvas)
cucul_free(server->canvas);
cucul_free_canvas(server->canvas);


server->canvas = cucul_load(buf, size);
server->canvas = cucul_load_canvas(buf, size);


if(!server->canvas) if(!server->canvas)
continue; /* Load error */ continue; /* Load error */


+ 12
- 10
src/cacaview.c View File

@@ -68,7 +68,7 @@ int main(int argc, char **argv)
int i; int i;


/* Initialise libcucul */ /* Initialise libcucul */
cv = cucul_create(0, 0);
cv = cucul_create_canvas(0, 0);
if(!cv) if(!cv)
{ {
fprintf(stderr, "%s: unable to initialise libcucul\n", argv[0]); fprintf(stderr, "%s: unable to initialise libcucul\n", argv[0]);
@@ -85,8 +85,8 @@ int main(int argc, char **argv)
/* Set the window title */ /* Set the window title */
caca_set_window_title(dp, "cacaview"); caca_set_window_title(dp, "cacaview");


ww = cucul_get_width(cv);
wh = cucul_get_height(cv);
ww = cucul_get_canvas_width(cv);
wh = cucul_get_canvas_height(cv);


/* Fill the zoom table */ /* Fill the zoom table */
zoomtab[0] = 1.0; zoomtab[0] = 1.0;
@@ -304,8 +304,8 @@ int main(int argc, char **argv)
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(cv, (ww - strlen(buffer)) / 2, wh / 2, buffer); cucul_putstr(cv, (ww - strlen(buffer)) / 2, wh / 2, buffer);
caca_display(dp); caca_display(dp);
ww = cucul_get_width(cv);
wh = cucul_get_height(cv);
ww = cucul_get_canvas_width(cv);
wh = cucul_get_canvas_height(cv);


if(im) if(im)
unload_image(im); unload_image(im);
@@ -409,7 +409,7 @@ int main(int argc, char **argv)
if(im) if(im)
unload_image(im); unload_image(im);
caca_detach(dp); caca_detach(dp);
cucul_free(cv);
cucul_free_canvas(cv);


return 0; return 0;
} }
@@ -472,12 +472,12 @@ static void set_zoom(int new_zoom)
if(zoom > ZOOM_MAX) zoom = ZOOM_MAX; if(zoom > ZOOM_MAX) zoom = ZOOM_MAX;
if(zoom < -ZOOM_MAX) zoom = -ZOOM_MAX; if(zoom < -ZOOM_MAX) zoom = -ZOOM_MAX;


ww = cucul_get_width(cv);
ww = cucul_get_canvas_width(cv);
height = fullscreen ? wh : wh - 3; height = fullscreen ? wh : wh - 3;


xfactor = (zoom < 0) ? 1.0 / zoomtab[-zoom] : zoomtab[zoom]; xfactor = (zoom < 0) ? 1.0 / zoomtab[-zoom] : zoomtab[zoom];
yfactor = xfactor * ww / height * im->h / im->w yfactor = xfactor * ww / height * im->h / im->w
* cucul_get_height(cv) / cucul_get_width(cv)
* cucul_get_canvas_height(cv) / cucul_get_canvas_width(cv)
* caca_get_window_width(dp) / caca_get_window_height(dp); * caca_get_window_width(dp) / caca_get_window_height(dp);


if(yfactor > xfactor) if(yfactor > xfactor)
@@ -506,8 +506,10 @@ static void draw_checkers(int x1, int y1, int x2, int y2)
{ {
int xn, yn; int xn, yn;


if(x2 + 1 > (int)cucul_get_width(cv)) x2 = cucul_get_width(cv) - 1;
if(y2 + 1 > (int)cucul_get_height(cv)) y2 = cucul_get_height(cv) - 1;
if(x2 + 1 > (int)cucul_get_canvas_width(cv))
x2 = cucul_get_canvas_width(cv) - 1;
if(y2 + 1 > (int)cucul_get_canvas_height(cv))
y2 = cucul_get_canvas_height(cv) - 1;


for(yn = y1 > 0 ? y1 : 0; yn <= y2; yn++) for(yn = y1 > 0 ? y1 : 0; yn <= y2; yn++)
for(xn = x1 > 0 ? x1 : 0; xn <= x2; xn++) for(xn = x1 > 0 ? x1 : 0; xn <= x2; xn++)


+ 4
- 4
src/img2irc.c View File

@@ -34,7 +34,7 @@ int main(int argc, char **argv)
return 1; return 1;
} }


cv = cucul_create(0, 0);
cv = cucul_create_canvas(0, 0);
if(!cv) if(!cv)
{ {
fprintf(stderr, "%s: unable to initialise libcucul\n", argv[0]); fprintf(stderr, "%s: unable to initialise libcucul\n", argv[0]);
@@ -45,14 +45,14 @@ int main(int argc, char **argv)
if(!i) if(!i)
{ {
fprintf(stderr, "%s: unable to load %s\n", argv[0], argv[1]); fprintf(stderr, "%s: unable to load %s\n", argv[0], argv[1]);
cucul_free(cv);
cucul_free_canvas(cv);
return 1; return 1;
} }


/* Assume a 6×10 font */ /* Assume a 6×10 font */
lines = cols * i->h * 6 / i->w / 10; lines = cols * i->h * 6 / i->w / 10;


cucul_set_size(cv, cols, lines);
cucul_set_canvas_size(cv, cols, lines);
cucul_clear(cv); cucul_clear(cv);
cucul_dither_bitmap(cv, 0, 0, cols - 1, lines - 1, i->dither, i->pixels); cucul_dither_bitmap(cv, 0, 0, cols - 1, lines - 1, i->dither, i->pixels);


@@ -63,7 +63,7 @@ int main(int argc, char **argv)
cucul_get_buffer_size(export), 1, stdout); cucul_get_buffer_size(export), 1, stdout);
cucul_free_buffer(export); cucul_free_buffer(export);


cucul_free(cv);
cucul_free_canvas(cv);


return 0; return 0;
} }


+ 2
- 2
test/colors.c View File

@@ -27,7 +27,7 @@ int main(int argc, char **argv)
caca_event_t ev; caca_event_t ev;
int i, j; int i, j;


cv = cucul_create(0, 0);
cv = cucul_create_canvas(0, 0);
if(!cv) if(!cv)
return 1; return 1;


@@ -53,7 +53,7 @@ int main(int argc, char **argv)
caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);


caca_detach(dp); caca_detach(dp);
cucul_free(cv);
cucul_free_canvas(cv);


return 0; return 0;
} }


+ 41
- 40
test/demo.c View File

@@ -45,7 +45,7 @@ int main(int argc, char **argv)
void (*demo)(void) = NULL; void (*demo)(void) = NULL;
int quit = 0; int quit = 0;


cv = cucul_create(0, 0);
cv = cucul_create_canvas(0, 0);
if(!cv) if(!cv)
return 1; return 1;
dp = caca_attach(cv); dp = caca_attach(cv);
@@ -174,7 +174,8 @@ int main(int argc, char **argv)
demo(); demo();


cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_draw_thin_box(cv, 1, 1, cucul_get_width(cv) - 2, cucul_get_height(cv) - 2);
cucul_draw_thin_box(cv, 1, 1, cucul_get_canvas_width(cv) - 2,
cucul_get_canvas_height(cv) - 2);
cucul_printf(cv, 4, 1, "[%i.%i fps]----", cucul_printf(cv, 4, 1, "[%i.%i fps]----",
1000000 / caca_get_rendertime(dp), 1000000 / caca_get_rendertime(dp),
(10000000 / caca_get_rendertime(dp)) % 10); (10000000 / caca_get_rendertime(dp)) % 10);
@@ -185,15 +186,15 @@ int main(int argc, char **argv)
/* Clean up */ /* Clean up */
cucul_free_sprite(sprite); cucul_free_sprite(sprite);
caca_detach(dp); caca_detach(dp);
cucul_free(cv);
cucul_free_canvas(cv);


return 0; return 0;
} }


static void display_menu(void) static void display_menu(void)
{ {
int xo = cucul_get_width(cv) - 2;
int yo = cucul_get_height(cv) - 2;
int xo = cucul_get_canvas_width(cv) - 2;
int yo = cucul_get_canvas_height(cv) - 2;


cucul_clear(cv); cucul_clear(cv);
cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
@@ -239,8 +240,8 @@ static void demo_all(void)


/* Draw the sun */ /* Draw the sun */
cucul_set_color(cv, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK); cucul_set_color(cv, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK);
xo = cucul_get_width(cv) / 4;
yo = cucul_get_height(cv) / 4 + 5 * sin(0.03*i);
xo = cucul_get_canvas_width(cv) / 4;
yo = cucul_get_canvas_height(cv) / 4 + 5 * sin(0.03*i);


for(j = 0; j < 16; j++) for(j = 0; j < 16; j++)
{ {
@@ -256,17 +257,17 @@ static void demo_all(void)
cucul_draw_ellipse(cv, xo, yo, j, j / 2, "#"); cucul_draw_ellipse(cv, xo, yo, j, j / 2, "#");


/* Draw the pyramid */ /* Draw the pyramid */
xo = cucul_get_width(cv) * 5 / 8;
xo = cucul_get_canvas_width(cv) * 5 / 8;
yo = 2; yo = 2;


xa = cucul_get_width(cv) / 8 + sin(0.03*i) * 5;
ya = cucul_get_height(cv) / 2 + cos(0.03*i) * 5;
xa = cucul_get_canvas_width(cv) / 8 + sin(0.03*i) * 5;
ya = cucul_get_canvas_height(cv) / 2 + cos(0.03*i) * 5;


xb = cucul_get_width(cv) - 10 - cos(0.02*i) * 10;
yb = cucul_get_height(cv) * 3 / 4 - 5 + sin(0.02*i) * 5;
xb = cucul_get_canvas_width(cv) - 10 - cos(0.02*i) * 10;
yb = cucul_get_canvas_height(cv) * 3 / 4 - 5 + sin(0.02*i) * 5;


xc = cucul_get_width(cv) / 4 - sin(0.02*i) * 5;
yc = cucul_get_height(cv) * 3 / 4 + cos(0.02*i) * 5;
xc = cucul_get_canvas_width(cv) / 4 - sin(0.02*i) * 5;
yc = cucul_get_canvas_height(cv) * 3 / 4 + cos(0.02*i) * 5;


cucul_set_color(cv, CUCUL_COLOR_GREEN, CUCUL_COLOR_BLACK); cucul_set_color(cv, CUCUL_COLOR_GREEN, CUCUL_COLOR_BLACK);
cucul_fill_triangle(cv, xo, yo, xb, yb, xa, ya, "%"); cucul_fill_triangle(cv, xo, yo, xb, yb, xa, ya, "%");
@@ -287,17 +288,17 @@ static void demo_all(void)
xa = 2; xa = 2;
ya = 2; ya = 2;


xb = cucul_get_width(cv) - 3;
yb = cucul_get_height(cv) / 2;
xb = cucul_get_canvas_width(cv) - 3;
yb = cucul_get_canvas_height(cv) / 2;


xc = cucul_get_width(cv) / 3;
yc = cucul_get_height(cv) - 3;
xc = cucul_get_canvas_width(cv) / 3;
yc = cucul_get_canvas_height(cv) - 3;


cucul_set_color(cv, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK); cucul_set_color(cv, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
cucul_draw_thin_triangle(cv, xa, ya, xb, yb, xc, yc); cucul_draw_thin_triangle(cv, xa, ya, xb, yb, xc, yc);


xo = cucul_get_width(cv) / 2 + cos(0.027*i) * cucul_get_width(cv) / 3;
yo = cucul_get_height(cv) / 2 - sin(0.027*i) * cucul_get_height(cv) / 2;
xo = cucul_get_canvas_width(cv) / 2 + cos(0.027*i) * cucul_get_canvas_width(cv) / 3;
yo = cucul_get_canvas_height(cv) / 2 - sin(0.027*i) * cucul_get_canvas_height(cv) / 2;


cucul_draw_thin_line(cv, xa, ya, xo, yo); cucul_draw_thin_line(cv, xa, ya, xo, yo);
cucul_draw_thin_line(cv, xb, yb, xo, yo); cucul_draw_thin_line(cv, xb, yb, xo, yo);
@@ -311,23 +312,23 @@ static void demo_all(void)
{ {
int delta = cucul_rand(-5, 5); int delta = cucul_rand(-5, 5);
cucul_set_color(cv, cucul_rand(0, 15), cucul_rand(0, 15)); cucul_set_color(cv, cucul_rand(0, 15), cucul_rand(0, 15));
cucul_putchar(cv, cucul_get_width(cv) / 2
+ cos(0.02*j) * (delta + cucul_get_width(cv) / 4),
cucul_get_height(cv) / 2
+ sin(0.02*j) * (delta + cucul_get_height(cv) / 3),
cucul_putchar(cv, cucul_get_canvas_width(cv) / 2
+ cos(0.02*j) * (delta + cucul_get_canvas_width(cv) / 4),
cucul_get_canvas_height(cv) / 2
+ sin(0.02*j) * (delta + cucul_get_canvas_height(cv) / 3),
'#'); '#');
} }


/* Draw foreground sprite */ /* Draw foreground sprite */
cucul_draw_sprite(cv, cucul_get_width(cv) / 2 + cos(0.02*i) * cucul_get_width(cv) / 4,
cucul_get_height(cv) / 2 + sin(0.02*i) * cucul_get_height(cv) / 3,
cucul_draw_sprite(cv, cucul_get_canvas_width(cv) / 2 + cos(0.02*i) * cucul_get_canvas_width(cv) / 4,
cucul_get_canvas_height(cv) / 2 + sin(0.02*i) * cucul_get_canvas_height(cv) / 3,
sprite, 0); sprite, 0);
} }


static void demo_dots(void) static void demo_dots(void)
{ {
int xmax = cucul_get_width(cv) - 1;
int ymax = cucul_get_height(cv) - 1;
int xmax = cucul_get_canvas_width(cv) - 1;
int ymax = cucul_get_canvas_height(cv) - 1;
int i; int i;
static char chars[10] = static char chars[10] =
{ {
@@ -364,8 +365,8 @@ static void demo_color(void)


static void demo_lines(void) static void demo_lines(void)
{ {
int w = cucul_get_width(cv);
int h = cucul_get_height(cv);
int w = cucul_get_canvas_width(cv);
int h = cucul_get_canvas_height(cv);
int xa, ya, xb, yb; int xa, ya, xb, yb;


if(bounds) if(bounds)
@@ -388,8 +389,8 @@ static void demo_lines(void)


static void demo_boxes(void) static void demo_boxes(void)
{ {
int w = cucul_get_width(cv);
int h = cucul_get_height(cv);
int w = cucul_get_canvas_width(cv);
int h = cucul_get_canvas_height(cv);
int xa, ya, xb, yb; int xa, ya, xb, yb;


if(bounds) if(bounds)
@@ -415,8 +416,8 @@ static void demo_boxes(void)


static void demo_ellipses(void) static void demo_ellipses(void)
{ {
int w = cucul_get_width(cv);
int h = cucul_get_height(cv);
int w = cucul_get_canvas_width(cv);
int h = cucul_get_canvas_height(cv);
int x, y, a, b; int x, y, a, b;


if(bounds) if(bounds)
@@ -446,8 +447,8 @@ static void demo_ellipses(void)


static void demo_triangles(void) static void demo_triangles(void)
{ {
int w = cucul_get_width(cv);
int h = cucul_get_height(cv);
int w = cucul_get_canvas_width(cv);
int h = cucul_get_canvas_height(cv);
int xa, ya, xb, yb, xc, yc; int xa, ya, xb, yb, xc, yc;


if(bounds) if(bounds)
@@ -476,8 +477,8 @@ static void demo_triangles(void)


static void demo_sprites(void) static void demo_sprites(void)
{ {
cucul_draw_sprite(cv, cucul_rand(0, cucul_get_width(cv) - 1),
cucul_rand(0, cucul_get_height(cv) - 1), sprite, 0);
cucul_draw_sprite(cv, cucul_rand(0, cucul_get_canvas_width(cv) - 1),
cucul_rand(0, cucul_get_canvas_height(cv) - 1), sprite, 0);
} }


#if 0 #if 0
@@ -503,7 +504,7 @@ static void demo_render(void)
cucul_set_dither_invert(dither, 1); cucul_set_dither_invert(dither, 1);
//dither = cucul_create_dither(16, 256, 256, 2 * 256, 0xf800, 0x07e0, 0x001f, 0x0000); //dither = cucul_create_dither(16, 256, 256, 2 * 256, 0xf800, 0x07e0, 0x001f, 0x0000);
dither = cucul_create_dither(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); dither = cucul_create_dither(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
cucul_dither_bitmap(cv, 0, 0, cucul_get_width(cv) - 1, cucul_get_height(cv) - 1,
cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv) - 1, cucul_get_canvas_height(cv) - 1,
dither, buffer); dither, buffer);
cucul_free_dither(dither); cucul_free_dither(dither);
} }
@@ -548,7 +549,7 @@ static void demo_render(void)


dither = cucul_create_dither(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); dither = cucul_create_dither(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
cucul_set_dither_invert(dither, 1); cucul_set_dither_invert(dither, 1);
cucul_dither_bitmap(cv, 0, 0, cucul_get_width(cv) - 1, cucul_get_height(cv) - 1, dither, (char *)buffer);
cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv) - 1, cucul_get_canvas_height(cv) - 1, dither, (char *)buffer);
cucul_free_dither(dither); cucul_free_dither(dither);
} }




+ 4
- 4
test/dithering.c View File

@@ -40,7 +40,7 @@ int main(void)
int neara, dista, nearb, distb, dist; int neara, dista, nearb, distb, dist;
int x, y; int x, y;


cv = cucul_create(0, 0);
cv = cucul_create_canvas(0, 0);
dp = caca_attach(cv); dp = caca_attach(cv);


for(x = 0; x < 100; x++) for(x = 0; x < 100; x++)
@@ -118,8 +118,8 @@ int main(void)
ch = density[dista * 2 * 13 / (dista + distb)]; ch = density[dista * 2 * 13 / (dista + distb)];
cucul_set_color(cv, points[nearb], points[neara]); cucul_set_color(cv, points[nearb], points[neara]);


cucul_putchar(cv, x * cucul_get_width(cv) / 100,
(100 - y) * cucul_get_height(cv) / 100, ch);
cucul_putchar(cv, x * cucul_get_canvas_width(cv) / 100,
(100 - y) * cucul_get_canvas_height(cv) / 100, ch);
} }


caca_display(dp); caca_display(dp);
@@ -127,7 +127,7 @@ int main(void)
caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);


caca_detach(dp); caca_detach(dp);
cucul_free(cv);
cucul_free_canvas(cv);


return 0; return 0;
} }


+ 7
- 7
test/event.c View File

@@ -30,19 +30,19 @@ int main(int argc, char **argv)
caca_event_t *events; caca_event_t *events;
int i, h, quit; int i, h, quit;


cv = cucul_create(0, 0);
cv = cucul_create_canvas(0, 0);
if(!cv) if(!cv)
return 1; return 1;
dp = caca_attach(cv); dp = caca_attach(cv);
if(!dp) if(!dp)
return 1; return 1;


h = cucul_get_height(cv) - 1;
h = cucul_get_canvas_height(cv) - 1;


cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_draw_line(cv, 0, 0, cucul_get_width(cv) - 1, 0, " ");
cucul_draw_line(cv, 0, 0, cucul_get_canvas_width(cv) - 1, 0, " ");


cucul_draw_line(cv, 0, h, cucul_get_width(cv) - 1, h, " ");
cucul_draw_line(cv, 0, h, cucul_get_canvas_width(cv) - 1, h, " ");
cucul_putstr(cv, 0, h, "type \"quit\" to exit"); cucul_putstr(cv, 0, h, "type \"quit\" to exit");


caca_display(dp); caca_display(dp);
@@ -85,10 +85,10 @@ int main(int argc, char **argv)


/* Print current event */ /* Print current event */
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_draw_line(cv, 0, 0, cucul_get_width(cv) - 1, 0, " ");
cucul_draw_line(cv, 0, 0, cucul_get_canvas_width(cv) - 1, 0, " ");
print_event(0, 0, events); print_event(0, 0, events);


cucul_draw_line(cv, 0, h, cucul_get_width(cv) - 1, h, " ");
cucul_draw_line(cv, 0, h, cucul_get_canvas_width(cv) - 1, h, " ");
cucul_printf(cv, 0, h, "type \"quit\" to exit: %s", quit_string[quit]); cucul_printf(cv, 0, h, "type \"quit\" to exit: %s", quit_string[quit]);


/* Print previous events */ /* Print previous events */
@@ -101,7 +101,7 @@ int main(int argc, char **argv)


/* Clean up */ /* Clean up */
caca_detach(dp); caca_detach(dp);
cucul_free(cv);
cucul_free_canvas(cv);


return 0; return 0;
} }


+ 4
- 5
test/export.c View File

@@ -65,7 +65,7 @@ int main(int argc, char *argv[])
exit(-1); exit(-1);
} }


cv = cucul_create(WIDTH, HEIGHT);
cv = cucul_create_canvas(WIDTH, HEIGHT);


for(y = 0; y < 256; y++) for(y = 0; y < 256; y++)
{ {
@@ -80,9 +80,8 @@ int main(int argc, char *argv[])


dither = cucul_create_dither(32, 256, 256, 4 * 256, dither = cucul_create_dither(32, 256, 256, 4 * 256,
0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
cucul_dither_bitmap(cv, 0, 0,
cucul_get_width(cv) - 1, cucul_get_height(cv) - 1,
dither, pixels);
cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv) - 1,
cucul_get_canvas_height(cv) - 1, dither, pixels);
cucul_free_dither(dither); cucul_free_dither(dither);


cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK); cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
@@ -107,7 +106,7 @@ int main(int argc, char *argv[])
cucul_get_buffer_size(buffer), 1, stdout); cucul_get_buffer_size(buffer), 1, stdout);
cucul_free_buffer(buffer); cucul_free_buffer(buffer);


cucul_free(cv);
cucul_free_canvas(cv);


return 0; return 0;
} }


+ 7
- 7
test/font.c View File

@@ -44,7 +44,7 @@ int main(int argc, char *argv[])
char const * const * fonts; char const * const * fonts;


/* Create a canvas */ /* Create a canvas */
cv = cucul_create(8, 2);
cv = cucul_create_canvas(8, 2);


/* Draw stuff on our canvas */ /* Draw stuff on our canvas */
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK); cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
@@ -69,15 +69,15 @@ int main(int argc, char *argv[])
} }


/* Create our bitmap buffer (32-bit ARGB) */ /* Create our bitmap buffer (32-bit ARGB) */
w = cucul_get_width(cv) * cucul_get_font_width(f);
h = cucul_get_height(cv) * cucul_get_font_height(f);
w = cucul_get_canvas_width(cv) * cucul_get_font_width(f);
h = cucul_get_canvas_height(cv) * cucul_get_font_height(f);
buf = malloc(4 * w * h); buf = malloc(4 * w * h);


/* Render the canvas onto our image buffer */ /* Render the canvas onto our image buffer */
cucul_render_canvas(cv, f, buf, w, h, 4 * w); cucul_render_canvas(cv, f, buf, w, h, 4 * w);


/* Just for fun, render the image using libcaca */ /* Just for fun, render the image using libcaca */
cucul_set_size(cv, 80, 32);
cucul_set_canvas_size(cv, 80, 32);
dp = caca_attach(cv); dp = caca_attach(cv);


#if defined(HAVE_ENDIAN_H) #if defined(HAVE_ENDIAN_H)
@@ -93,8 +93,8 @@ int main(int argc, char *argv[])
d = cucul_create_dither(32, w, h, 4 * w, d = cucul_create_dither(32, w, h, 4 * w,
0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff); 0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff);


cucul_dither_bitmap(cv, 0, 0, cucul_get_width(cv) - 1,
cucul_get_height(cv) - 1, d, buf);
cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv) - 1,
cucul_get_canvas_height(cv) - 1, d, buf);
caca_display(dp); caca_display(dp);


caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);
@@ -104,7 +104,7 @@ int main(int argc, char *argv[])
free(buf); free(buf);
cucul_free_dither(d); cucul_free_dither(d);
cucul_free_font(f); cucul_free_font(f);
cucul_free(cv);
cucul_free_canvas(cv);


return 0; return 0;
} }


+ 14
- 16
test/gamma.c View File

@@ -40,11 +40,11 @@ int main(void)
float gam = 1.0; float gam = 1.0;
int x; int x;


cv = cucul_create(0, 0);
cv = cucul_create_canvas(0, 0);
dp = caca_attach(cv); dp = caca_attach(cv);


cw = cucul_create(cucul_get_width(cv), cucul_get_height(cv));
mask = cucul_create(cucul_get_width(cv), cucul_get_height(cv));
cw = cucul_create_canvas(cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
mask = cucul_create_canvas(cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));


for(x = 0; x < 256; x++) for(x = 0; x < 256; x++)
{ {
@@ -77,29 +77,27 @@ int main(void)
} }


/* Resize the spare canvas, just in case the main one changed */ /* Resize the spare canvas, just in case the main one changed */
cucul_set_size(cw, cucul_get_width(cv), cucul_get_height(cv));
cucul_set_size(mask, cucul_get_width(cv), cucul_get_height(cv));
cucul_set_canvas_size(cw, cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
cucul_set_canvas_size(mask, cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));


/* Draw the regular dither on the main canvas */ /* Draw the regular dither on the main canvas */
cucul_dither_bitmap(cv, 0, 0,
cucul_get_width(cv) - 1, cucul_get_height(cv) - 1,
left, buffer);
cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv) - 1,
cucul_get_canvas_height(cv) - 1, left, buffer);


/* Draw the gamma-modified dither on the spare canvas */ /* Draw the gamma-modified dither on the spare canvas */
cucul_set_dither_gamma(right, gam); cucul_set_dither_gamma(right, gam);
cucul_dither_bitmap(cw, 0, 0,
cucul_get_width(cw) - 1, cucul_get_height(cw) - 1,
right, buffer);
cucul_dither_bitmap(cw, 0, 0, cucul_get_canvas_width(cw) - 1,
cucul_get_canvas_height(cw) - 1, right, buffer);


/* Draw something on the mask */ /* Draw something on the mask */
cucul_clear(mask); cucul_clear(mask);
cucul_set_color(mask, CUCUL_COLOR_WHITE, CUCUL_COLOR_WHITE); cucul_set_color(mask, CUCUL_COLOR_WHITE, CUCUL_COLOR_WHITE);
cucul_fill_ellipse(mask, (1.0 + sin(0.05 * (float)x)) cucul_fill_ellipse(mask, (1.0 + sin(0.05 * (float)x))
* 0.5 * cucul_get_width(mask),
* 0.5 * cucul_get_canvas_width(mask),
(1.0 + cos(0.05 * (float)x)) (1.0 + cos(0.05 * (float)x))
* 0.5 * cucul_get_height(mask),
cucul_get_width(mask) / 2,
cucul_get_height(mask) / 2, "#");
* 0.5 * cucul_get_canvas_height(mask),
cucul_get_canvas_width(mask) / 2,
cucul_get_canvas_height(mask) / 2, "#");


/* Blit the spare canvas onto the first one */ /* Blit the spare canvas onto the first one */
cucul_blit(cv, 0, 0, cw, mask); cucul_blit(cv, 0, 0, cw, mask);
@@ -115,7 +113,7 @@ int main(void)
cucul_free_dither(right); cucul_free_dither(right);


caca_detach(dp); caca_detach(dp);
cucul_free(cv);
cucul_free_canvas(cv);


return 0; return 0;
} }


+ 4
- 5
test/hsv.c View File

@@ -35,7 +35,7 @@ int main(void)
cucul_dither_t *dither; cucul_dither_t *dither;
int x, y; int x, y;


cv = cucul_create(0, 0);
cv = cucul_create_canvas(0, 0);
dp = caca_attach(cv); dp = caca_attach(cv);


for(y = 0; y < 256; y++) for(y = 0; y < 256; y++)
@@ -46,9 +46,8 @@ int main(void)


dither = cucul_create_dither(32, 256, 256, 4 * 256, dither = cucul_create_dither(32, 256, 256, 4 * 256,
0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
cucul_dither_bitmap(cv, 0, 0,
cucul_get_width(cv) - 1, cucul_get_height(cv) - 1,
dither, buffer);
cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv) - 1,
cucul_get_canvas_height(cv) - 1, dither, buffer);
cucul_free_dither(dither); cucul_free_dither(dither);


caca_display(dp); caca_display(dp);
@@ -56,7 +55,7 @@ int main(void)
caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);


caca_detach(dp); caca_detach(dp);
cucul_free(cv);
cucul_free_canvas(cv);


return 0; return 0;
} }


+ 5
- 4
test/spritedit.c View File

@@ -37,7 +37,7 @@ int main(int argc, char **argv)
return 1; return 1;
} }


cv = cucul_create(0, 0);
cv = cucul_create_canvas(0, 0);
if(!cv) if(!cv)
return 1; return 1;
dp = caca_attach(cv); dp = caca_attach(cv);
@@ -49,7 +49,7 @@ int main(int argc, char **argv)
if(!sprite) if(!sprite)
{ {
caca_detach(dp); caca_detach(dp);
cucul_free(cv);
cucul_free_canvas(cv);
fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]); fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]);
return 1; return 1;
} }
@@ -103,7 +103,8 @@ int main(int argc, char **argv)
cucul_clear(cv); cucul_clear(cv);


cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_draw_thin_box(cv, 0, 0, cucul_get_width(cv) - 1, cucul_get_height(cv) - 1);
cucul_draw_thin_box(cv, 0, 0, cucul_get_canvas_width(cv) - 1,
cucul_get_canvas_height(cv) - 1);


cucul_putstr(cv, 3, 0, "[ Sprite editor for libcaca ]"); cucul_putstr(cv, 3, 0, "[ Sprite editor for libcaca ]");


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


/* Clean up */ /* Clean up */
caca_detach(dp); caca_detach(dp);
cucul_free(cv);
cucul_free_canvas(cv);


return 0; return 0;
} }


+ 10
- 10
test/transform.c View File

@@ -54,13 +54,13 @@ int main(void)
caca_display_t *dp; caca_display_t *dp;
int i; int i;


cv = cucul_create(0, 0);
cv = cucul_create_canvas(0, 0);
dp = caca_attach(cv); dp = caca_attach(cv);


normal = cucul_create(70, 6);
flip = cucul_create(70, 6);
flop = cucul_create(70, 6);
rotate = cucul_create(70, 6);
normal = cucul_create_canvas(70, 6);
flip = cucul_create_canvas(70, 6);
flop = cucul_create_canvas(70, 6);
rotate = cucul_create_canvas(70, 6);


cucul_set_color(normal, CUCUL_COLOR_LIGHTMAGENTA, CUCUL_COLOR_BLACK); cucul_set_color(normal, CUCUL_COLOR_LIGHTMAGENTA, CUCUL_COLOR_BLACK);
for(i = 0; pig[i]; i++) for(i = 0; pig[i]; i++)
@@ -111,11 +111,11 @@ int main(void)
caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);


caca_detach(dp); caca_detach(dp);
cucul_free(rotate);
cucul_free(flop);
cucul_free(flip);
cucul_free(normal);
cucul_free(cv);
cucul_free_canvas(rotate);
cucul_free_canvas(flop);
cucul_free_canvas(flip);
cucul_free_canvas(normal);
cucul_free_canvas(cv);


return 0; return 0;
} }


+ 2
- 2
test/truecolor.c View File

@@ -32,7 +32,7 @@ int main(void)


int x, y; int x, y;


cv = cucul_create(32, 16);
cv = cucul_create_canvas(32, 16);
dp = caca_attach(cv); dp = caca_attach(cv);


for(y = 0; y < 16; y++) for(y = 0; y < 16; y++)
@@ -53,7 +53,7 @@ int main(void)
caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);


caca_detach(dp); caca_detach(dp);
cucul_free(cv);
cucul_free_canvas(cv);


return 0; return 0;
} }


+ 2
- 2
test/unicode.c View File

@@ -30,7 +30,7 @@ int main(void)
cucul_canvas_t *cv; cucul_canvas_t *cv;
caca_display_t *dp; caca_display_t *dp;


cv = cucul_create(0, 0);
cv = cucul_create_canvas(0, 0);
dp = caca_attach(cv); dp = caca_attach(cv);


cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
@@ -90,7 +90,7 @@ int main(void)
caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);


caca_detach(dp); caca_detach(dp);
cucul_free(cv);
cucul_free_canvas(cv);


return 0; return 0;
} }


Loading…
Cancel
Save