Browse Source

Starting refactoring to get rid of libcucul. The initial reason for the

split is rendered moot by the plugin system: when enabled, binaries do
not link directly with libX11 or libGL. I hope this is a step towards
more consisteny and clarity.
tags/v0.99.beta14
Sam Hocevar sam 16 years ago
parent
commit
f61816ceb7
100 changed files with 2591 additions and 2793 deletions
  1. +3
    -3
      Makefile.am
  2. +2
    -3
      build-kernel
  3. +2
    -5
      caca-config.in
  4. +29
    -8
      caca/Makefile.am
  5. +63
    -63
      caca/attr.c
  6. +32
    -32
      caca/box.c
  7. +26
    -27
      caca/caca.c
  8. +343
    -6
      caca/caca.h
  9. +2
    -2
      caca/caca.pc.in
  10. +29
    -29
      caca/caca0.c
  11. +50
    -50
      caca/caca0.h
  12. +54
    -2
      caca/caca_internals.h
  13. +33
    -33
      caca/caca_types.h.in
  14. +49
    -61
      caca/canvas.c
  15. +9
    -9
      caca/charset.c
  16. +23
    -23
      caca/conic.c
  17. +53
    -53
      caca/dither.c
  18. +23
    -23
      caca/driver_cocoa.m
  19. +14
    -15
      caca/driver_conio.c
  20. +31
    -32
      caca/driver_gl.c
  21. +16
    -17
      caca/driver_ncurses.c
  22. +4
    -5
      caca/driver_raw.c
  23. +27
    -28
      caca/driver_slang.c
  24. +11
    -12
      caca/driver_vga.c
  25. +19
    -20
      caca/driver_win32.c
  26. +24
    -24
      caca/driver_x11.c
  27. +4
    -5
      caca/event.c
  28. +93
    -93
      caca/export.c
  29. +67
    -67
      caca/figfont.c
  30. +14
    -14
      caca/file.c
  31. +29
    -29
      caca/font.c
  32. +24
    -24
      caca/frame.c
  33. +4
    -5
      caca/graphics.c
  34. +101
    -101
      caca/import.c
  35. +35
    -28
      caca/legacy.c
  36. +28
    -28
      caca/line.c
  37. +1
    -1
      caca/mono9.data
  38. +1
    -1
      caca/monobold12.data
  39. +55
    -55
      caca/string.c
  40. +35
    -35
      caca/transform.c
  41. +18
    -18
      caca/triangle.c
  42. +9
    -13
      configure.ac
  43. +6
    -14
      csharp/Makefile.am
  44. +0
    -1
      cucul/.gitignore
  45. +0
    -42
      cucul/Makefile.am
  46. +0
    -383
      cucul/cucul.h
  47. +0
    -12
      cucul/cucul.pc.in
  48. +0
    -80
      cucul/cucul_internals.h
  49. +7
    -12
      cxx/Makefile.am
  50. +4
    -4
      cxx/caca++.cpp
  51. +3
    -4
      cxx/caca++.h
  52. +130
    -130
      cxx/cucul++.cpp
  53. +19
    -19
      cxx/cucul++.h
  54. +5
    -5
      cxx/cxxtest.cpp
  55. +4
    -4
      doc/Makefile.am
  56. +28
    -29
      examples/Makefile.am
  57. +13
    -14
      examples/blit.c
  58. +14
    -15
      examples/canvas.c
  59. +19
    -20
      examples/colors.c
  60. +155
    -156
      examples/demo.c
  61. +17
    -18
      examples/dithering.c
  62. +6
    -7
      examples/driver.c
  63. +24
    -25
      examples/event.c
  64. +45
    -45
      examples/export.c
  65. +9
    -9
      examples/figfont.c
  66. +27
    -28
      examples/font.c
  67. +17
    -17
      examples/font2tga.c
  68. +17
    -18
      examples/frames.c
  69. +23
    -24
      examples/fullwidth.c
  70. +32
    -33
      examples/gamma.c
  71. +6
    -7
      examples/hsv.c
  72. +5
    -6
      examples/import.c
  73. +9
    -10
      examples/input.c
  74. +12
    -13
      examples/spritedit.c
  75. +13
    -14
      examples/swallow.c
  76. +28
    -28
      examples/text.c
  77. +44
    -45
      examples/transform.c
  78. +7
    -8
      examples/truecolor.c
  79. +56
    -57
      examples/unicode.c
  80. +3
    -3
      kernel/kernel.c
  81. +2
    -2
      kernel/kernel.h
  82. +3
    -3
      msvc/Makefile.am
  83. +2
    -2
      msvc/cucul_types.h
  84. +8
    -16
      ruby/Makefile.am
  85. +56
    -56
      ruby/caca-canvas.c
  86. +10
    -0
      ruby/caca-canvas.h
  87. +2
    -2
      ruby/caca-display.c
  88. +9
    -9
      ruby/caca-dither.c
  89. +9
    -0
      ruby/caca-dither.h
  90. +10
    -10
      ruby/caca-font.c
  91. +9
    -0
      ruby/caca-font.h
  92. +30
    -0
      ruby/caca.c
  93. +2
    -2
      ruby/common.h
  94. +0
    -10
      ruby/cucul-canvas.h
  95. +0
    -9
      ruby/cucul-dither.h
  96. +0
    -9
      ruby/cucul-font.h
  97. +0
    -57
      ruby/cucul.c
  98. +8
    -8
      src/Makefile.am
  99. +18
    -19
      src/aafire.c
  100. +117
    -118
      src/cacademo.c

+ 3
- 3
Makefile.am View File

@@ -1,6 +1,6 @@
# $Id$ # $Id$


SUBDIRS = kernel cucul caca src examples tests tools csharp cxx python ruby doc
SUBDIRS = kernel caca src examples tests tools csharp cxx python ruby doc
DIST_SUBDIRS = $(SUBDIRS) msvc DIST_SUBDIRS = $(SUBDIRS) msvc


EXTRA_DIST = NOTES COPYING.GPL COPYING.LGPL bootstrap build-dos build-kernel build-win32 caca-config.in stubs.h libcaca.spec EXTRA_DIST = NOTES COPYING.GPL COPYING.LGPL bootstrap build-dos build-kernel build-win32 caca-config.in stubs.h libcaca.spec
@@ -20,7 +20,7 @@ upload-doc: doc/html FORCE
scp -r doc/html/* $(webhost):$(webdir)/manual/ scp -r doc/html/* $(webhost):$(webdir)/manual/


fonts: tools/makefont fonts: tools/makefont
tools/makefont mono9 "Monospace 9" 96 4 >| $(srcdir)/cucul/mono9.data
tools/makefont monobold12 "Monospace Bold 12" 96 4 >| $(srcdir)/cucul/monobold12.data
tools/makefont mono9 "Monospace 9" 96 4 >| $(srcdir)/caca/mono9.data
tools/makefont monobold12 "Monospace Bold 12" 96 4 >| $(srcdir)/caca/monobold12.data


FORCE: FORCE:

+ 2
- 3
build-kernel View File

@@ -6,7 +6,7 @@
set -x set -x
set -e set -e


CFLAGS="-fno-builtin -O2 -I. -I.. -I../cucul/ -Wall"
CFLAGS="-fno-builtin -O2 -I. -I.. -I../caca/ -Wall"
CPPFLAGS="-D__KERNEL__ -nostdinc -include kernel/kernel.h" CPPFLAGS="-D__KERNEL__ -nostdinc -include kernel/kernel.h"
LDFLAGS="-nostdlib -Wl,-N -Wl,-Ttext -Wl,100000" LDFLAGS="-nostdlib -Wl,-N -Wl,-Ttext -Wl,100000"


@@ -18,7 +18,6 @@ LDFLAGS="-nostdlib -Wl,-N -Wl,-Ttext -Wl,100000"
# We need this. # We need this.
make clean make clean


cd cucul && make && cd ..
cd caca && make && cd .. cd caca && make && cd ..


cd src && make cacademo.o && cd .. cd src && make cacademo.o && cd ..
@@ -28,7 +27,7 @@ cd kernel &&
gcc $CFLAGS $CPPFLAGS -c kernel.c -o kernel.o && gcc $CFLAGS $CPPFLAGS -c kernel.c -o kernel.o &&
cd .. cd ..


gcc $LDFLAGS -o src/cacademo kernel/multiboot.o kernel/kernel.o src/cacademo.o caca/.libs/libcaca.a cucul/.libs/libcucul.a
gcc $LDFLAGS -o src/cacademo kernel/multiboot.o kernel/kernel.o src/cacademo.o caca/.libs/libcaca.a


objcopy -O binary src/cacademo cacademo.boot objcopy -O binary src/cacademo cacademo.boot




+ 2
- 5
caca-config.in View File

@@ -67,11 +67,8 @@ do
--libs | --plugin-libs) --libs | --plugin-libs)
echo_libs=yes echo_libs=yes
;; ;;
cucul)
libs="$libs -lcucul"
;;
caca) caca)
libs="$libs -lcaca -lcucul"
libs="$libs -lcaca"
;; ;;
*) *)
usage 1 1>&2 usage 1 1>&2
@@ -82,7 +79,7 @@ done


if test "$libs" = "" if test "$libs" = ""
then then
libs="-lcaca -lcucul"
libs="-lcaca"
fi fi


if test "$local_prefix" = "yes" if test "$local_prefix" = "yes"


+ 29
- 8
caca/Makefile.am View File

@@ -1,24 +1,41 @@
# $Id$ # $Id$


EXTRA_DIST = caca.pc.in
DISTCLEANFILES = caca.pc
EXTRA_DIST = caca_types.h.in caca.pc.in mono9.data monobold12.data
DISTCLEANFILES = caca_types.h caca.pc


AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/cucul -I../cucul \
-DPLUGINDIR=\"$(plugindir)\"
AM_CPPFLAGS = -I$(top_srcdir) -DPLUGINDIR=\"$(plugindir)\"


pkgconfig_DATA = caca.pc pkgconfig_DATA = caca.pc
pkgconfigdir = $(libdir)/pkgconfig pkgconfigdir = $(libdir)/pkgconfig


include_HEADERS = caca.h caca0.h
include_HEADERS = caca.h caca_types.h caca0.h


lib_LTLIBRARIES = libcaca.la lib_LTLIBRARIES = libcaca.la


libcaca_la_SOURCES = \ libcaca_la_SOURCES = \
caca.c \ caca.c \
caca.h \ caca.h \
caca_types.h \
caca_internals.h \ caca_internals.h \
caca0.c \ caca0.c \
caca0.h \ caca0.h \
canvas.c \
string.c \
legacy.c \
transform.c \
charset.c \
attr.c \
line.c \
box.c \
conic.c \
triangle.c \
frame.c \
dither.c \
font.c \
import.c \
export.c \
file.c \
figfont.c \
graphics.c \ graphics.c \
event.c \ event.c \
time.c \ time.c \
@@ -31,9 +48,13 @@ libcaca_la_SOURCES = \
$(cocoa_source) \ $(cocoa_source) \
$(extra_source) \ $(extra_source) \
$(NULL) $(NULL)
libcaca_la_DEPENDENCIES = \
mono9.data \
monobold12.data \
$(NULL)
libcaca_la_CPPFLAGS = $(AM_CPPFLAGS) @CACA_CFLAGS@ libcaca_la_CPPFLAGS = $(AM_CPPFLAGS) @CACA_CFLAGS@
libcaca_la_LDFLAGS = -no-undefined -version-number @LT_VERSION@ libcaca_la_LDFLAGS = -no-undefined -version-number @LT_VERSION@
libcaca_la_LIBADD = ../cucul/libcucul.la @CACA_LIBS@
libcaca_la_LIBADD = @CACA_LIBS@ $(ZLIB_LIBS)


if USE_PLUGINS if USE_PLUGINS
plugin_LTLIBRARIES = libx11_plugin.la libgl_plugin.la plugin_LTLIBRARIES = libx11_plugin.la libgl_plugin.la
@@ -42,12 +63,12 @@ plugindir = $(libdir)/caca
libx11_plugin_la_SOURCES = driver_x11.c libx11_plugin_la_SOURCES = driver_x11.c
libx11_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(X11_CFLAGS) libx11_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(X11_CFLAGS)
libx11_plugin_la_LDFLAGS = -no-undefined -module -no-version libx11_plugin_la_LDFLAGS = -no-undefined -module -no-version
libx11_plugin_la_LIBADD = libcaca.la ../cucul/libcucul.la $(X11_LIBS)
libx11_plugin_la_LIBADD = libcaca.la $(X11_LIBS)


libgl_plugin_la_SOURCES = driver_gl.c libgl_plugin_la_SOURCES = driver_gl.c
libgl_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(GL_CFLAGS) #$(FTGL_CFLAGS) libgl_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(GL_CFLAGS) #$(FTGL_CFLAGS)
libgl_plugin_la_LDFLAGS = -no-undefined -module -no-version libgl_plugin_la_LDFLAGS = -no-undefined -module -no-version
libgl_plugin_la_LIBADD = libcaca.la ../cucul/libcucul.la $(GL_LIBS) #$(FTGL_LIBS)
libgl_plugin_la_LIBADD = libcaca.la $(GL_LIBS) #$(FTGL_LIBS)
else else
extra_source = driver_x11.c driver_gl.c extra_source = driver_x11.c driver_gl.c
endif endif


cucul/attr.c → caca/attr.c View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Canvas for ultrafast compositing of Unicode letters
* libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -19,8 +19,8 @@


#include "config.h" #include "config.h"


#include "cucul.h"
#include "cucul_internals.h"
#include "caca.h"
#include "caca_internals.h"


static uint8_t nearest_ansi(uint16_t); static uint8_t nearest_ansi(uint16_t);


@@ -42,7 +42,7 @@ static const uint16_t ansitab14[16] =


/** \brief Get the text attribute at the given coordinates. /** \brief Get the text attribute at the given coordinates.
* *
* Get the internal \e libcucul attribute value of the character at the
* Get the internal \e libcaca attribute value of the character at the
* given coordinates. The attribute value has 32 significant bits, * given coordinates. The attribute value has 32 significant bits,
* organised as follows from MSB to LSB: * organised as follows from MSB to LSB:
* - 3 bits for the background alpha * - 3 bits for the background alpha
@@ -60,12 +60,12 @@ static const uint16_t ansitab14[16] =
* *
* This function never fails. * This function never fails.
* *
* \param cv A handle to the libcucul canvas.
* \param cv A handle to the libcaca canvas.
* \param x X coordinate. * \param x X coordinate.
* \param y Y coordinate. * \param y Y coordinate.
* \return The requested attribute. * \return The requested attribute.
*/ */
uint32_t cucul_get_attr(cucul_canvas_t const *cv, int x, int y)
uint32_t caca_get_attr(caca_canvas_t const *cv, int x, int y)
{ {
if(x < 0 || x >= (int)cv->width || y < 0 || y >= (int)cv->height) if(x < 0 || x >= (int)cv->width || y < 0 || y >= (int)cv->height)
return cv->curattr; return cv->curattr;
@@ -82,21 +82,21 @@ uint32_t cucul_get_attr(cucul_canvas_t const *cv, int x, int y)
* will use this attribute. * will use this attribute.
* *
* The value of \e attr is either: * The value of \e attr is either:
* - a 32-bit integer as returned by cucul_get_attr(), in which case it
* - a 32-bit integer as returned by caca_get_attr(), in which case it
* also contains colour information, * also contains colour information,
* - a combination (bitwise OR) of style values (\e CUCUL_UNDERLINE,
* \e CUCUL_BLINK, \e CUCUL_BOLD and \e CUCUL_ITALICS), in which case
* - a combination (bitwise OR) of style values (\e CACA_UNDERLINE,
* \e CACA_BLINK, \e CACA_BOLD and \e CACA_ITALICS), in which case
* setting the attribute does not modify the current colour information. * setting the attribute does not modify the current colour information.
* *
* To retrieve the current attribute value, use cucul_get_attr(-1,-1).
* To retrieve the current attribute value, use caca_get_attr(-1,-1).
* *
* This function never fails. * This function never fails.
* *
* \param cv A handle to the libcucul canvas.
* \param cv A handle to the libcaca canvas.
* \param attr The requested attribute value. * \param attr The requested attribute value.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_set_attr(cucul_canvas_t *cv, uint32_t attr)
int caca_set_attr(caca_canvas_t *cv, uint32_t attr)
{ {
if(attr < 0x00000010) if(attr < 0x00000010)
attr = (cv->curattr & 0xfffffff0) | attr; attr = (cv->curattr & 0xfffffff0) | attr;
@@ -113,21 +113,21 @@ int cucul_set_attr(cucul_canvas_t *cv, uint32_t attr)
* cells' attributes are replaced. * cells' attributes are replaced.
* *
* The value of \e attr is either: * The value of \e attr is either:
* - a 32-bit integer as returned by cucul_get_attr(), in which case it
* - a 32-bit integer as returned by caca_get_attr(), in which case it
* also contains colour information, * also contains colour information,
* - a combination (bitwise OR) of style values (\e CUCUL_UNDERLINE,
* \e CUCUL_BLINK, \e CUCUL_BOLD and \e CUCUL_ITALICS), in which case
* - a combination (bitwise OR) of style values (\e CACA_UNDERLINE,
* \e CACA_BLINK, \e CACA_BOLD and \e CACA_ITALICS), in which case
* setting the attribute does not modify the current colour information. * setting the attribute does not modify the current colour information.
* *
* This function never fails. * This function never fails.
* *
* \param cv A handle to the libcucul canvas.
* \param cv A handle to the libcaca canvas.
* \param x X coordinate. * \param x X coordinate.
* \param y Y coordinate. * \param y Y coordinate.
* \param attr The requested attribute value. * \param attr The requested attribute value.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_put_attr(cucul_canvas_t *cv, int x, int y, uint32_t attr)
int caca_put_attr(caca_canvas_t *cv, int x, int y, uint32_t attr)
{ {
uint32_t *curattr, *curchar; uint32_t *curattr, *curchar;


@@ -142,9 +142,9 @@ int cucul_put_attr(cucul_canvas_t *cv, int x, int y, uint32_t attr)
else else
curattr[0] = attr; curattr[0] = attr;


if(x && curchar[0] == CUCUL_MAGIC_FULLWIDTH)
if(x && curchar[0] == CACA_MAGIC_FULLWIDTH)
curattr[-1] = curattr[0]; curattr[-1] = curattr[0];
else if(x + 1 < (int)cv->width && curchar[1] == CUCUL_MAGIC_FULLWIDTH)
else if(x + 1 < (int)cv->width && curchar[1] == CACA_MAGIC_FULLWIDTH)
curattr[1] = curattr[0]; curattr[1] = curattr[0];


return 0; return 0;
@@ -156,18 +156,18 @@ int cucul_put_attr(cucul_canvas_t *cv, int x, int y, uint32_t attr)
* as caca_printf() and graphical primitive functions such as caca_draw_line() * as caca_printf() and graphical primitive functions such as caca_draw_line()
* will use these attributes. * will use these attributes.
* *
* Color values are those defined in cucul.h, such as CUCUL_RED
* or CUCUL_TRANSPARENT.
* Color values are those defined in caca.h, such as CACA_RED
* or CACA_TRANSPARENT.
* *
* If an error occurs, 0 is returned and \b errno is set accordingly: * If an error occurs, 0 is returned and \b errno is set accordingly:
* - \c EINVAL At least one of the colour values is invalid. * - \c EINVAL At least one of the colour values is invalid.
* *
* \param cv A handle to the libcucul canvas.
* \param cv A handle to the libcaca canvas.
* \param fg The requested ANSI foreground colour. * \param fg The requested ANSI foreground colour.
* \param bg The requested ANSI background colour. * \param bg The requested ANSI background colour.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_set_color_ansi(cucul_canvas_t *cv, uint8_t fg, uint8_t bg)
int caca_set_color_ansi(caca_canvas_t *cv, uint8_t fg, uint8_t bg)
{ {
uint32_t attr; uint32_t attr;


@@ -195,12 +195,12 @@ int cucul_set_color_ansi(cucul_canvas_t *cv, uint8_t fg, uint8_t bg)
* *
* This function never fails. * This function never fails.
* *
* \param cv A handle to the libcucul canvas.
* \param cv A handle to the libcaca canvas.
* \param fg The requested ARGB foreground colour. * \param fg The requested ARGB foreground colour.
* \param bg The requested ARGB background colour. * \param bg The requested ARGB background colour.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_set_color_argb(cucul_canvas_t *cv, uint16_t fg, uint16_t bg)
int caca_set_color_argb(caca_canvas_t *cv, uint16_t fg, uint16_t bg)
{ {
uint32_t attr; uint32_t attr;


@@ -226,9 +226,9 @@ int cucul_set_color_argb(cucul_canvas_t *cv, uint16_t fg, uint16_t bg)
* 4 bits are the foreground colour. * 4 bits are the foreground colour.
* *
* If the attribute has ARGB colours, the nearest colour is used. Special * If the attribute has ARGB colours, the nearest colour is used. Special
* attributes such as \e CUCUL_DEFAULT and \e CUCUL_TRANSPARENT are not
* handled and are both replaced with \e CUCUL_LIGHTGRAY for the foreground
* colour and \e CUCUL_BLACK for the background colour.
* attributes such as \e CACA_DEFAULT and \e CACA_TRANSPARENT are not
* handled and are both replaced with \e CACA_LIGHTGRAY for the foreground
* colour and \e CACA_BLACK for the background colour.
* *
* This function never fails. If the attribute value is outside the expected * This function never fails. If the attribute value is outside the expected
* 32-bit range, higher order bits are simply ignored. * 32-bit range, higher order bits are simply ignored.
@@ -236,21 +236,21 @@ int cucul_set_color_argb(cucul_canvas_t *cv, uint16_t fg, uint16_t bg)
* \param attr The requested attribute value. * \param attr The requested attribute value.
* \return The corresponding DOS ANSI value. * \return The corresponding DOS ANSI value.
*/ */
uint8_t cucul_attr_to_ansi(uint32_t attr)
uint8_t caca_attr_to_ansi(uint32_t attr)
{ {
uint8_t fg = nearest_ansi((attr >> 4) & 0x3fff); uint8_t fg = nearest_ansi((attr >> 4) & 0x3fff);
uint8_t bg = nearest_ansi(attr >> 18); uint8_t bg = nearest_ansi(attr >> 18);


return (fg < 0x10 ? fg : CUCUL_LIGHTGRAY)
| ((bg < 0x10 ? bg : CUCUL_BLACK) << 4);
return (fg < 0x10 ? fg : CACA_LIGHTGRAY)
| ((bg < 0x10 ? bg : CACA_BLACK) << 4);
} }


/** \brief Get ANSI foreground information from attribute. /** \brief Get ANSI foreground information from attribute.
* *
* Get the ANSI foreground colour value for a given attribute. The returned * Get the ANSI foreground colour value for a given attribute. The returned
* value is either one of the \e CUCUL_RED, \e CUCUL_BLACK etc. predefined
* colours, or the special value \e CUCUL_DEFAULT meaning the media's
* default foreground value, or the special value \e CUCUL_TRANSPARENT.
* value is either one of the \e CACA_RED, \e CACA_BLACK etc. predefined
* colours, or the special value \e CACA_DEFAULT meaning the media's
* default foreground value, or the special value \e CACA_TRANSPARENT.
* *
* If the attribute has ARGB colours, the nearest colour is returned. * If the attribute has ARGB colours, the nearest colour is returned.
* *
@@ -260,7 +260,7 @@ uint8_t cucul_attr_to_ansi(uint32_t attr)
* \param attr The requested attribute value. * \param attr The requested attribute value.
* \return The corresponding ANSI foreground value. * \return The corresponding ANSI foreground value.
*/ */
uint8_t cucul_attr_to_ansi_fg(uint32_t attr)
uint8_t caca_attr_to_ansi_fg(uint32_t attr)
{ {
return nearest_ansi(((uint16_t)attr >> 4) & 0x3fff); return nearest_ansi(((uint16_t)attr >> 4) & 0x3fff);
} }
@@ -268,9 +268,9 @@ uint8_t cucul_attr_to_ansi_fg(uint32_t attr)
/** \brief Get ANSI background information from attribute. /** \brief Get ANSI background information from attribute.
* *
* Get the ANSI background colour value for a given attribute. The returned * Get the ANSI background colour value for a given attribute. The returned
* value is either one of the \e CUCUL_RED, \e CUCUL_BLACK etc. predefined
* colours, or the special value \e CUCUL_DEFAULT meaning the media's
* default background value, or the special value \e CUCUL_TRANSPARENT.
* value is either one of the \e CACA_RED, \e CACA_BLACK etc. predefined
* colours, or the special value \e CACA_DEFAULT meaning the media's
* default background value, or the special value \e CACA_TRANSPARENT.
* *
* If the attribute has ARGB colours, the nearest colour is returned. * If the attribute has ARGB colours, the nearest colour is returned.
* *
@@ -280,7 +280,7 @@ uint8_t cucul_attr_to_ansi_fg(uint32_t attr)
* \param attr The requested attribute value. * \param attr The requested attribute value.
* \return The corresponding ANSI background value. * \return The corresponding ANSI background value.
*/ */
uint8_t cucul_attr_to_ansi_bg(uint32_t attr)
uint8_t caca_attr_to_ansi_bg(uint32_t attr)
{ {
return nearest_ansi(attr >> 18); return nearest_ansi(attr >> 18);
} }
@@ -300,18 +300,18 @@ uint8_t cucul_attr_to_ansi_bg(uint32_t attr)
* \param attr The requested attribute value. * \param attr The requested attribute value.
* \return The corresponding 12-bit RGB foreground value. * \return The corresponding 12-bit RGB foreground value.
*/ */
uint16_t cucul_attr_to_rgb12_fg(uint32_t attr)
uint16_t caca_attr_to_rgb12_fg(uint32_t attr)
{ {
uint16_t fg = (attr >> 4) & 0x3fff; uint16_t fg = (attr >> 4) & 0x3fff;


if(fg < (0x10 | 0x40)) if(fg < (0x10 | 0x40))
return ansitab16[fg ^ 0x40] & 0x0fff; return ansitab16[fg ^ 0x40] & 0x0fff;


if(fg == (CUCUL_DEFAULT | 0x40))
return ansitab16[CUCUL_LIGHTGRAY] & 0x0fff;
if(fg == (CACA_DEFAULT | 0x40))
return ansitab16[CACA_LIGHTGRAY] & 0x0fff;


if(fg == (CUCUL_TRANSPARENT | 0x40))
return ansitab16[CUCUL_LIGHTGRAY] & 0x0fff;
if(fg == (CACA_TRANSPARENT | 0x40))
return ansitab16[CACA_LIGHTGRAY] & 0x0fff;


return (fg << 1) & 0x0fff; return (fg << 1) & 0x0fff;
} }
@@ -331,18 +331,18 @@ uint16_t cucul_attr_to_rgb12_fg(uint32_t attr)
* \param attr The requested attribute value. * \param attr The requested attribute value.
* \return The corresponding 12-bit RGB background value. * \return The corresponding 12-bit RGB background value.
*/ */
uint16_t cucul_attr_to_rgb12_bg(uint32_t attr)
uint16_t caca_attr_to_rgb12_bg(uint32_t attr)
{ {
uint16_t bg = attr >> 18; uint16_t bg = attr >> 18;


if(bg < (0x10 | 0x40)) if(bg < (0x10 | 0x40))
return ansitab16[bg ^ 0x40] & 0x0fff; return ansitab16[bg ^ 0x40] & 0x0fff;


if(bg == (CUCUL_DEFAULT | 0x40))
return ansitab16[CUCUL_BLACK] & 0x0fff;
if(bg == (CACA_DEFAULT | 0x40))
return ansitab16[CACA_BLACK] & 0x0fff;


if(bg == (CUCUL_TRANSPARENT | 0x40))
return ansitab16[CUCUL_BLACK] & 0x0fff;
if(bg == (CACA_TRANSPARENT | 0x40))
return ansitab16[CACA_BLACK] & 0x0fff;


return (bg << 1) & 0x0fff; return (bg << 1) & 0x0fff;
} }
@@ -366,16 +366,16 @@ uint16_t cucul_attr_to_rgb12_bg(uint32_t attr)
* \param attr The requested attribute value. * \param attr The requested attribute value.
* \param argb An array of 8-bit integers. * \param argb An array of 8-bit integers.
*/ */
void cucul_attr_to_argb64(uint32_t attr, uint8_t argb[8])
void caca_attr_to_argb64(uint32_t attr, uint8_t argb[8])
{ {
uint16_t fg = (attr >> 4) & 0x3fff; uint16_t fg = (attr >> 4) & 0x3fff;
uint16_t bg = attr >> 18; uint16_t bg = attr >> 18;


if(bg < (0x10 | 0x40)) if(bg < (0x10 | 0x40))
bg = ansitab16[bg ^ 0x40]; bg = ansitab16[bg ^ 0x40];
else if(bg == (CUCUL_DEFAULT | 0x40))
bg = ansitab16[CUCUL_BLACK];
else if(bg == (CUCUL_TRANSPARENT | 0x40))
else if(bg == (CACA_DEFAULT | 0x40))
bg = ansitab16[CACA_BLACK];
else if(bg == (CACA_TRANSPARENT | 0x40))
bg = 0x0fff; bg = 0x0fff;
else else
bg = ((bg << 2) & 0xf000) | ((bg << 1) & 0x0fff); bg = ((bg << 2) & 0xf000) | ((bg << 1) & 0x0fff);
@@ -387,9 +387,9 @@ void cucul_attr_to_argb64(uint32_t attr, uint8_t argb[8])


if(fg < (0x10 | 0x40)) if(fg < (0x10 | 0x40))
fg = ansitab16[fg ^ 0x40]; fg = ansitab16[fg ^ 0x40];
else if(fg == (CUCUL_DEFAULT | 0x40))
fg = ansitab16[CUCUL_LIGHTGRAY];
else if(fg == (CUCUL_TRANSPARENT | 0x40))
else if(fg == (CACA_DEFAULT | 0x40))
fg = ansitab16[CACA_LIGHTGRAY];
else if(fg == (CACA_TRANSPARENT | 0x40))
fg = 0x0fff; fg = 0x0fff;
else else
fg = ((fg << 2) & 0xf000) | ((fg << 1) & 0x0fff); fg = ((fg << 2) & 0xf000) | ((fg << 1) & 0x0fff);
@@ -411,13 +411,13 @@ static uint8_t nearest_ansi(uint16_t argb14)
if(argb14 < (0x10 | 0x40)) if(argb14 < (0x10 | 0x40))
return argb14 ^ 0x40; return argb14 ^ 0x40;


if(argb14 == (CUCUL_DEFAULT | 0x40) || argb14 == (CUCUL_TRANSPARENT | 0x40))
if(argb14 == (CACA_DEFAULT | 0x40) || argb14 == (CACA_TRANSPARENT | 0x40))
return argb14 ^ 0x40; return argb14 ^ 0x40;


if(argb14 < 0x0fff) /* too transparent */ if(argb14 < 0x0fff) /* too transparent */
return CUCUL_TRANSPARENT;
return CACA_TRANSPARENT;


best = CUCUL_DEFAULT;
best = CACA_DEFAULT;
dist = 0x3fff; dist = 0x3fff;
for(i = 0; i < 16; i++) for(i = 0; i < 16; i++)
{ {
@@ -451,13 +451,13 @@ static uint8_t nearest_ansi(uint16_t argb14)
| ((uint32_t)((i & 0x0f0) >> 4) * 0x001100) \ | ((uint32_t)((i & 0x0f0) >> 4) * 0x001100) \
| ((uint32_t)(i & 0x00f) * 0x000011)) | ((uint32_t)(i & 0x00f) * 0x000011))


uint32_t _cucul_attr_to_rgb24fg(uint32_t attr)
uint32_t _caca_attr_to_rgb24fg(uint32_t attr)
{ {
return RGB12TO24(cucul_attr_to_rgb12_fg(attr));
return RGB12TO24(caca_attr_to_rgb12_fg(attr));
} }


uint32_t _cucul_attr_to_rgb24bg(uint32_t attr)
uint32_t _caca_attr_to_rgb24bg(uint32_t attr)
{ {
return RGB12TO24(cucul_attr_to_rgb12_bg(attr));
return RGB12TO24(caca_attr_to_rgb12_bg(attr));
} }



cucul/box.c → caca/box.c View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Canvas for ultrafast compositing of Unicode letters
* libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -22,14 +22,14 @@
# include <stdlib.h> # include <stdlib.h>
#endif #endif


#include "cucul.h"
#include "cucul_internals.h"
#include "caca.h"
#include "caca_internals.h"


/** \brief Draw a box on the canvas using the given character. /** \brief Draw a box on the canvas using the given character.
* *
* This function never fails. * This function never fails.
* *
* \param cv The handle to the libcucul canvas.
* \param cv The handle to the libcaca canvas.
* \param x X coordinate of the upper-left corner of the box. * \param x X coordinate of the upper-left corner of the box.
* \param y Y coordinate of the upper-left corner of the box. * \param y Y coordinate of the upper-left corner of the box.
* \param w Width of the box. * \param w Width of the box.
@@ -37,15 +37,15 @@
* \param ch UTF-32 character to be used to draw the box. * \param ch UTF-32 character to be used to draw the box.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_draw_box(cucul_canvas_t *cv, int x, int y, int w, int h, uint32_t ch)
int caca_draw_box(caca_canvas_t *cv, int x, int y, int w, int h, uint32_t ch)
{ {
int x2 = x + w - 1; int x2 = x + w - 1;
int y2 = y + h - 1; int y2 = y + h - 1;


cucul_draw_line(cv, x, y, x, y2, ch);
cucul_draw_line(cv, x, y2, x2, y2, ch);
cucul_draw_line(cv, x2, y2, x2, y, ch);
cucul_draw_line(cv, x2, y, x, y, ch);
caca_draw_line(cv, x, y, x, y2, ch);
caca_draw_line(cv, x, y2, x2, y2, ch);
caca_draw_line(cv, x2, y2, x2, y, ch);
caca_draw_line(cv, x2, y, x, y, ch);


return 0; return 0;
} }
@@ -54,14 +54,14 @@ int cucul_draw_box(cucul_canvas_t *cv, int x, int y, int w, int h, uint32_t ch)
* *
* This function never fails. * This function never fails.
* *
* \param cv The handle to the libcucul canvas.
* \param cv The handle to the libcaca canvas.
* \param x X coordinate of the upper-left corner of the box. * \param x X coordinate of the upper-left corner of the box.
* \param y Y coordinate of the upper-left corner of the box. * \param y Y coordinate of the upper-left corner of the box.
* \param w Width of the box. * \param w Width of the box.
* \param h Height of the box. * \param h Height of the box.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_draw_thin_box(cucul_canvas_t *cv, int x, int y, int w, int h)
int caca_draw_thin_box(caca_canvas_t *cv, int x, int y, int w, int h)
{ {
int i, j, xmax, ymax; int i, j, xmax, ymax;


@@ -89,25 +89,25 @@ int cucul_draw_thin_box(cucul_canvas_t *cv, int x, int y, int w, int h)
/* Draw edges */ /* Draw edges */
if(y >= 0) if(y >= 0)
for(i = x < 0 ? 1 : x + 1; i < x2 && i < xmax; i++) for(i = x < 0 ? 1 : x + 1; i < x2 && i < xmax; i++)
cucul_put_char(cv, i, y, '-');
caca_put_char(cv, i, y, '-');


if(y2 <= ymax) if(y2 <= ymax)
for(i = x < 0 ? 1 : x + 1; i < x2 && i < xmax; i++) for(i = x < 0 ? 1 : x + 1; i < x2 && i < xmax; i++)
cucul_put_char(cv, i, y2, '-');
caca_put_char(cv, i, y2, '-');


if(x >= 0) if(x >= 0)
for(j = y < 0 ? 1 : y + 1; j < y2 && j < ymax; j++) for(j = y < 0 ? 1 : y + 1; j < y2 && j < ymax; j++)
cucul_put_char(cv, x, j, '|');
caca_put_char(cv, x, j, '|');


if(x2 <= xmax) if(x2 <= xmax)
for(j = y < 0 ? 1 : y + 1; j < y2 && j < ymax; j++) for(j = y < 0 ? 1 : y + 1; j < y2 && j < ymax; j++)
cucul_put_char(cv, x2, j, '|');
caca_put_char(cv, x2, j, '|');


/* Draw corners */ /* Draw corners */
cucul_put_char(cv, x, y, ',');
cucul_put_char(cv, x, y2, '`');
cucul_put_char(cv, x2, y, '.');
cucul_put_char(cv, x2, y2, '\'');
caca_put_char(cv, x, y, ',');
caca_put_char(cv, x, y2, '`');
caca_put_char(cv, x2, y, '.');
caca_put_char(cv, x2, y2, '\'');


return 0; return 0;
} }
@@ -116,14 +116,14 @@ int cucul_draw_thin_box(cucul_canvas_t *cv, int x, int y, int w, int h)
* *
* This function never fails. * This function never fails.
* *
* \param cv The handle to the libcucul canvas.
* \param cv The handle to the libcaca canvas.
* \param x X coordinate of the upper-left corner of the box. * \param x X coordinate of the upper-left corner of the box.
* \param y Y coordinate of the upper-left corner of the box. * \param y Y coordinate of the upper-left corner of the box.
* \param w Width of the box. * \param w Width of the box.
* \param h Height of the box. * \param h Height of the box.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_draw_cp437_box(cucul_canvas_t *cv, int x, int y, int w, int h)
int caca_draw_cp437_box(caca_canvas_t *cv, int x, int y, int w, int h)
{ {
int i, j, xmax, ymax; int i, j, xmax, ymax;


@@ -151,25 +151,25 @@ int cucul_draw_cp437_box(cucul_canvas_t *cv, int x, int y, int w, int h)
/* Draw edges */ /* Draw edges */
if(y >= 0) if(y >= 0)
for(i = x < 0 ? 1 : x + 1; i < x2 && i < xmax; i++) for(i = x < 0 ? 1 : x + 1; i < x2 && i < xmax; i++)
cucul_put_char(cv, i, y, 0x2500); /* ─ */
caca_put_char(cv, i, y, 0x2500); /* ─ */


if(y2 <= ymax) if(y2 <= ymax)
for(i = x < 0 ? 1 : x + 1; i < x2 && i < xmax; i++) for(i = x < 0 ? 1 : x + 1; i < x2 && i < xmax; i++)
cucul_put_char(cv, i, y2, 0x2500); /* ─ */
caca_put_char(cv, i, y2, 0x2500); /* ─ */


if(x >= 0) if(x >= 0)
for(j = y < 0 ? 1 : y + 1; j < y2 && j < ymax; j++) for(j = y < 0 ? 1 : y + 1; j < y2 && j < ymax; j++)
cucul_put_char(cv, x, j, 0x2502); /* │ */
caca_put_char(cv, x, j, 0x2502); /* │ */


if(x2 <= xmax) if(x2 <= xmax)
for(j = y < 0 ? 1 : y + 1; j < y2 && j < ymax; j++) for(j = y < 0 ? 1 : y + 1; j < y2 && j < ymax; j++)
cucul_put_char(cv, x2, j, 0x2502); /* │ */
caca_put_char(cv, x2, j, 0x2502); /* │ */


/* Draw corners */ /* Draw corners */
cucul_put_char(cv, x, y, 0x250c); /* ┌ */
cucul_put_char(cv, x, y2, 0x2514); /* └ */
cucul_put_char(cv, x2, y, 0x2510); /* ┐ */
cucul_put_char(cv, x2, y2, 0x2518); /* ┘ */
caca_put_char(cv, x, y, 0x250c); /* ┌ */
caca_put_char(cv, x, y2, 0x2514); /* └ */
caca_put_char(cv, x2, y, 0x2510); /* ┐ */
caca_put_char(cv, x2, y2, 0x2518); /* ┘ */


return 0; return 0;
} }
@@ -178,7 +178,7 @@ int cucul_draw_cp437_box(cucul_canvas_t *cv, int x, int y, int w, int h)
* *
* This function never fails. * This function never fails.
* *
* \param cv The handle to the libcucul canvas.
* \param cv The handle to the libcaca canvas.
* \param x X coordinate of the upper-left corner of the box. * \param x X coordinate of the upper-left corner of the box.
* \param y Y coordinate of the upper-left corner of the box. * \param y Y coordinate of the upper-left corner of the box.
* \param w Width of the box. * \param w Width of the box.
@@ -186,7 +186,7 @@ int cucul_draw_cp437_box(cucul_canvas_t *cv, int x, int y, int w, int h)
* \param ch UTF-32 character to be used to draw the box. * \param ch UTF-32 character to be used to draw the box.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_fill_box(cucul_canvas_t *cv, int x, int y, int w, int h,
int caca_fill_box(caca_canvas_t *cv, int x, int y, int w, int h,
uint32_t ch) uint32_t ch)
{ {
int i, j, xmax, ymax; int i, j, xmax, ymax;
@@ -219,7 +219,7 @@ int cucul_fill_box(cucul_canvas_t *cv, int x, int y, int w, int h,


for(j = y; j <= y2; j++) for(j = y; j <= y2; j++)
for(i = x; i <= x2; i++) for(i = x; i <= x2; i++)
cucul_put_char(cv, i, j, ch);
caca_put_char(cv, i, j, ch);


return 0; return 0;
} }

+ 26
- 27
caca/caca.c View File

@@ -31,7 +31,6 @@
# endif # endif
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"
#include "caca_internals.h" #include "caca_internals.h"


@@ -48,14 +47,14 @@ static int caca_select_driver(caca_display_t *, char const *);
static int caca_plugin_install(caca_display_t *, char const *); static int caca_plugin_install(caca_display_t *, char const *);
#endif #endif


/** \brief Attach a caca graphical context to a cucul canvas.
/** \brief Attach a caca graphical context to a caca canvas.
* *
* Create a graphical context using device-dependent features (ncurses for * Create a graphical context using device-dependent features (ncurses for
* terminals, an X11 window, a DOS command window...) that attaches to a * terminals, an X11 window, a DOS command window...) that attaches to a
* libcucul canvas. Everything that gets drawn in the libcucul canvas can
* libcaca canvas. Everything that gets drawn in the libcaca canvas can
* then be displayed by the libcaca driver. * then be displayed by the libcaca driver.
* *
* If no cucul canvas is provided, a new one is created. Its handle can be
* If no caca canvas is provided, a new one is created. Its handle can be
* retrieved using caca_get_canvas() and it is automatically destroyed when * retrieved using caca_get_canvas() and it is automatically destroyed when
* caca_free_display() is called. * caca_free_display() is called.
* *
@@ -65,22 +64,22 @@ static int caca_plugin_install(caca_display_t *, char const *);
* - \c ENOMEM Not enough memory. * - \c ENOMEM Not enough memory.
* - \c ENODEV Graphical device could not be initialised. * - \c ENODEV Graphical device could not be initialised.
* *
* \param cv The cucul canvas or NULL to create a canvas automatically.
* \param cv The caca canvas or NULL to create a canvas automatically.
* \return The caca graphical context or NULL if an error occurred. * \return The caca graphical context or NULL if an error occurred.
*/ */
caca_display_t * caca_create_display(cucul_canvas_t *cv)
caca_display_t * caca_create_display(caca_canvas_t *cv)
{ {
return caca_create_display_with_driver(cv, NULL); return caca_create_display_with_driver(cv, NULL);
} }


/** \brief Attach a specific caca graphical context to a cucul canvas.
/** \brief Attach a specific caca graphical context to a caca canvas.
* *
* Create a graphical context using device-dependent features (ncurses for * Create a graphical context using device-dependent features (ncurses for
* terminals, an X11 window, a DOS command window...) that attaches to a * terminals, an X11 window, a DOS command window...) that attaches to a
* libcucul canvas. Everything that gets drawn in the libcucul canvas can
* libcaca canvas. Everything that gets drawn in the libcaca canvas can
* then be displayed by the libcaca driver. * then be displayed by the libcaca driver.
* *
* If no cucul canvas is provided, a new one is created. Its handle can be
* If no caca canvas is provided, a new one is created. Its handle can be
* retrieved using caca_get_canvas() and it is automatically destroyed when * retrieved using caca_get_canvas() and it is automatically destroyed when
* caca_free_display() is called. * caca_free_display() is called.
* *
@@ -93,12 +92,12 @@ caca_display_t * caca_create_display(cucul_canvas_t *cv)
* - \c ENOMEM Not enough memory. * - \c ENOMEM Not enough memory.
* - \c ENODEV Graphical device could not be initialised. * - \c ENODEV Graphical device could not be initialised.
* *
* \param cv The cucul canvas or NULL to create a canvas automatically.
* \param cv The caca canvas or NULL to create a canvas automatically.
* \param driver A string describing the desired output driver or NULL to * \param driver A string describing the desired output driver or NULL to
* choose the best driver automatically. * choose the best driver automatically.
* \return The caca graphical context or NULL if an error occurred. * \return The caca graphical context or NULL if an error occurred.
*/ */
caca_display_t * caca_create_display_with_driver(cucul_canvas_t *cv,
caca_display_t * caca_create_display_with_driver(caca_canvas_t *cv,
char const *driver) char const *driver)
{ {
caca_display_t *dp = malloc(sizeof(caca_display_t)); caca_display_t *dp = malloc(sizeof(caca_display_t));
@@ -111,15 +110,15 @@ caca_display_t * caca_create_display_with_driver(cucul_canvas_t *cv,


if((dp->autorelease = (cv == NULL))) if((dp->autorelease = (cv == NULL)))
{ {
cv = cucul_create_canvas(0, 0);
cv = caca_create_canvas(0, 0);
} }


dp->cv = cv; dp->cv = cv;


if(cucul_manage_canvas(cv, (int (*)(void *))caca_can_resize, (void *)dp))
if(caca_manage_canvas(cv, (int (*)(void *))caca_can_resize, (void *)dp))
{ {
if(dp->autorelease) if(dp->autorelease)
cucul_free_canvas(dp->cv);
caca_free_canvas(dp->cv);
free(dp); free(dp);
seterrno(EBUSY); seterrno(EBUSY);
return NULL; return NULL;
@@ -127,9 +126,9 @@ caca_display_t * caca_create_display_with_driver(cucul_canvas_t *cv,


if(caca_install_driver(dp, driver)) if(caca_install_driver(dp, driver))
{ {
cucul_unmanage_canvas(cv, (int (*)(void *))caca_can_resize, (void *)dp);
caca_unmanage_canvas(cv, (int (*)(void *))caca_can_resize, (void *)dp);
if(dp->autorelease) if(dp->autorelease)
cucul_free_canvas(dp->cv);
caca_free_canvas(dp->cv);
free(dp); free(dp);
seterrno(ENODEV); seterrno(ENODEV);
return NULL; return NULL;
@@ -223,13 +222,13 @@ int caca_set_display_driver(caca_display_t *dp, char const *driver)
return 0; return 0;
} }


/** \brief Detach a caca graphical context from a cucul backend context.
/** \brief Detach a caca graphical context from a caca backend context.
* *
* Detach a graphical context from its cucul backend and destroy it. The
* libcucul canvas continues to exist and other graphical contexts can be
* Detach a graphical context from its caca backend and destroy it. The
* libcaca canvas continues to exist and other graphical contexts can be
* attached to it afterwards. * attached to it afterwards.
* *
* If the cucul canvas was automatically created by caca_create_display(),
* If the caca canvas was automatically created by caca_create_display(),
* it is automatically destroyed and any handle to it becomes invalid. * it is automatically destroyed and any handle to it becomes invalid.
* *
* This function never fails. * This function never fails.
@@ -240,9 +239,9 @@ int caca_set_display_driver(caca_display_t *dp, char const *driver)
int caca_free_display(caca_display_t *dp) int caca_free_display(caca_display_t *dp)
{ {
caca_uninstall_driver(dp); caca_uninstall_driver(dp);
cucul_unmanage_canvas(dp->cv, (int (*)(void *))caca_can_resize, (void *)dp);
caca_unmanage_canvas(dp->cv, (int (*)(void *))caca_can_resize, (void *)dp);
if(dp->autorelease) if(dp->autorelease)
cucul_free_canvas(dp->cv);
caca_free_canvas(dp->cv);
free(dp); free(dp);


return 0; return 0;
@@ -250,15 +249,15 @@ int caca_free_display(caca_display_t *dp)


/** \brief Get the canvas attached to a caca graphical context. /** \brief Get the canvas attached to a caca graphical context.
* *
* Return a handle on the \e cucul_canvas_t object that was either attached
* Return a handle on the \e caca_canvas_t object that was either attached
* or created by caca_create_display(). * or created by caca_create_display().
* *
* This function never fails. * This function never fails.
* *
* \param dp The libcaca graphical context. * \param dp The libcaca graphical context.
* \return The libcucul canvas.
* \return The libcaca canvas.
*/ */
cucul_canvas_t * caca_get_canvas(caca_display_t *dp)
caca_canvas_t * caca_get_canvas(caca_display_t *dp)
{ {
return dp->cv; return dp->cv;
} }
@@ -330,8 +329,8 @@ static int caca_install_driver(caca_display_t *dp, char const *driver)
dp->lastticks = 0; dp->lastticks = 0;


/* Mouse position */ /* Mouse position */
dp->mouse.x = cucul_get_canvas_width(dp->cv) / 2;
dp->mouse.y = cucul_get_canvas_height(dp->cv) / 2;
dp->mouse.x = caca_get_canvas_width(dp->cv) / 2;
dp->mouse.y = caca_get_canvas_height(dp->cv) / 2;


/* Resize events */ /* Resize events */
dp->resize.resized = 0; dp->resize.resized = 0;


+ 343
- 6
caca/caca.h View File

@@ -24,7 +24,7 @@
#ifndef __CACA_H__ #ifndef __CACA_H__
#define __CACA_H__ #define __CACA_H__


#include <cucul.h>
#include <caca_types.h>


#undef __extern #undef __extern
#if defined(_DOXYGEN_SKIP_ME) #if defined(_DOXYGEN_SKIP_ME)
@@ -42,11 +42,49 @@ extern "C"
{ {
#endif #endif


/** \e libcaca canvas */
typedef struct caca_canvas caca_canvas_t;
/** dither structure */
typedef struct caca_dither caca_dither_t;
/** font structure */
typedef struct caca_font caca_font_t;
/** file handle structure */
typedef struct caca_file caca_file_t;
/** \e libcaca display context */ /** \e libcaca display context */
typedef struct caca_display caca_display_t; typedef struct caca_display caca_display_t;
/** \e libcaca event structure */ /** \e libcaca event structure */
typedef struct caca_event caca_event_t; typedef struct caca_event caca_event_t;


/** \defgroup caca_attr libcaca attribute definitions
*
* Colours and styles that can be used with caca_set_attr().
*
* @{ */
#define CACA_BLACK 0x00 /**< The colour index for black. */
#define CACA_BLUE 0x01 /**< The colour index for blue. */
#define CACA_GREEN 0x02 /**< The colour index for green. */
#define CACA_CYAN 0x03 /**< The colour index for cyan. */
#define CACA_RED 0x04 /**< The colour index for red. */
#define CACA_MAGENTA 0x05 /**< The colour index for magenta. */
#define CACA_BROWN 0x06 /**< The colour index for brown. */
#define CACA_LIGHTGRAY 0x07 /**< The colour index for light gray. */
#define CACA_DARKGRAY 0x08 /**< The colour index for dark gray. */
#define CACA_LIGHTBLUE 0x09 /**< The colour index for blue. */
#define CACA_LIGHTGREEN 0x0a /**< The colour index for light green. */
#define CACA_LIGHTCYAN 0x0b /**< The colour index for light cyan. */
#define CACA_LIGHTRED 0x0c /**< The colour index for light red. */
#define CACA_LIGHTMAGENTA 0x0d /**< The colour index for light magenta. */
#define CACA_YELLOW 0x0e /**< The colour index for yellow. */
#define CACA_WHITE 0x0f /**< The colour index for white. */
#define CACA_DEFAULT 0x10 /**< The output driver's default colour. */
#define CACA_TRANSPARENT 0x20 /**< The transparent colour. */

#define CACA_BOLD 0x01 /**< The style mask for bold. */
#define CACA_ITALICS 0x02 /**< The style mask for italics. */
#define CACA_UNDERLINE 0x04 /**< The style mask for underline. */
#define CACA_BLINK 0x08 /**< The style mask for blink. */
/* @} */

/** \brief User event type enumeration. /** \brief User event type enumeration.
* *
* This enum serves two purposes: * This enum serves two purposes:
@@ -158,18 +196,247 @@ enum caca_key


/** \defgroup libcaca libcaca basic functions /** \defgroup libcaca libcaca basic functions
* *
* These functions provide the basic \e libcaca routines for driver
* These functions provide the basic \e libcaca routines for library
* initialisation, system information retrieval and configuration.
*
* @{ */
__extern caca_canvas_t * caca_create_canvas(int, int);
__extern int caca_manage_canvas(caca_canvas_t *, int (*)(void *), void *);
__extern int caca_unmanage_canvas(caca_canvas_t *, int (*)(void *), void *);
__extern int caca_set_canvas_size(caca_canvas_t *, int, int);
__extern int caca_get_canvas_width(caca_canvas_t const *);
__extern int caca_get_canvas_height(caca_canvas_t const *);
__extern uint8_t const * caca_get_canvas_chars(caca_canvas_t const *);
__extern uint8_t const * caca_get_canvas_attrs(caca_canvas_t const *);
__extern int caca_free_canvas(caca_canvas_t *);
__extern int caca_rand(int, int);
__extern char const * caca_get_version(void);
/* @} */

/** \defgroup caca_canvas libcaca canvas drawing
*
* These functions provide low-level character printing routines and
* higher level graphics functions.
*
* @{ */
#define CACA_MAGIC_FULLWIDTH 0x000ffffe /**< Used to indicate that the previous character was a fullwidth glyph. */
__extern int caca_gotoxy(caca_canvas_t *, int, int);
__extern int caca_get_cursor_x(caca_canvas_t const *);
__extern int caca_get_cursor_y(caca_canvas_t const *);
__extern int caca_put_char(caca_canvas_t *, int, int, uint32_t);
__extern uint32_t caca_get_char(caca_canvas_t const *, int, int);
__extern int caca_put_str(caca_canvas_t *, int, int, char const *);
__extern uint32_t caca_get_attr(caca_canvas_t const *, int, int);
__extern int caca_set_attr(caca_canvas_t *, uint32_t);
__extern int caca_put_attr(caca_canvas_t *, int, int, uint32_t);
__extern int caca_set_color_ansi(caca_canvas_t *, uint8_t, uint8_t);
__extern int caca_set_color_argb(caca_canvas_t *, uint16_t, uint16_t);
__extern int caca_printf(caca_canvas_t *, int, int, char const *, ...);
__extern int caca_clear_canvas(caca_canvas_t *);
__extern int caca_set_canvas_handle(caca_canvas_t *, int, int);
__extern int caca_get_canvas_handle_x(caca_canvas_t const *);
__extern int caca_get_canvas_handle_y(caca_canvas_t const *);
__extern int caca_blit(caca_canvas_t *, int, int, caca_canvas_t const *,
caca_canvas_t const *);
__extern int caca_set_canvas_boundaries(caca_canvas_t *, int, int, int, int);
/* @} */

/** \defgroup caca_transform libcaca canvas transformation
*
* These functions perform horizontal and vertical canvas flipping.
*
* @{ */
__extern int caca_invert(caca_canvas_t *);
__extern int caca_flip(caca_canvas_t *);
__extern int caca_flop(caca_canvas_t *);
__extern int caca_rotate_180(caca_canvas_t *);
__extern int caca_rotate_left(caca_canvas_t *);
__extern int caca_rotate_right(caca_canvas_t *);
__extern int caca_stretch_left(caca_canvas_t *);
__extern int caca_stretch_right(caca_canvas_t *);
/* @} */

/** \defgroup caca_attributes libcaca attribute conversions
*
* These functions perform conversions between attribute values.
*
* @{ */
__extern uint8_t caca_attr_to_ansi(uint32_t);
__extern uint8_t caca_attr_to_ansi_fg(uint32_t);
__extern uint8_t caca_attr_to_ansi_bg(uint32_t);
__extern uint16_t caca_attr_to_rgb12_fg(uint32_t);
__extern uint16_t caca_attr_to_rgb12_bg(uint32_t);
__extern void caca_attr_to_argb64(uint32_t, uint8_t[8]);
/* @} */

/** \defgroup caca_charset libcaca character set conversions
*
* These functions perform conversions between usual character sets.
*
* @{ */
__extern uint32_t caca_utf8_to_utf32(char const *, size_t *);
__extern size_t caca_utf32_to_utf8(char *, uint32_t);
__extern uint8_t caca_utf32_to_cp437(uint32_t);
__extern uint32_t caca_cp437_to_utf32(uint8_t);
__extern char caca_utf32_to_ascii(uint32_t);
__extern int caca_utf32_is_fullwidth(uint32_t);
/* @} */

/** \defgroup caca_primitives libcaca primitives drawing
*
* These functions provide routines for primitive drawing, such as lines,
* boxes, triangles and ellipses.
*
* @{ */
__extern int caca_draw_line(caca_canvas_t *, int, int, int, int, uint32_t);
__extern int caca_draw_polyline(caca_canvas_t *, int const x[],
int const y[], int, uint32_t);
__extern int caca_draw_thin_line(caca_canvas_t *, int, int, int, int);
__extern int caca_draw_thin_polyline(caca_canvas_t *, int const x[],
int const y[], int);

__extern int caca_draw_circle(caca_canvas_t *, int, int, int, uint32_t);
__extern int caca_draw_ellipse(caca_canvas_t *, int, int, int, int, uint32_t);
__extern int caca_draw_thin_ellipse(caca_canvas_t *, int, int, int, int);
__extern int caca_fill_ellipse(caca_canvas_t *, int, int, int, int, uint32_t);

__extern int caca_draw_box(caca_canvas_t *, int, int, int, int, uint32_t);
__extern int caca_draw_thin_box(caca_canvas_t *, int, int, int, int);
__extern int caca_draw_cp437_box(caca_canvas_t *, int, int, int, int);
__extern int caca_fill_box(caca_canvas_t *, int, int, int, int, uint32_t);

__extern int caca_draw_triangle(caca_canvas_t *, int, int, int, int, int,
int, uint32_t);
__extern int caca_draw_thin_triangle(caca_canvas_t *, int, int, int, int,
int, int);
__extern int caca_fill_triangle(caca_canvas_t *, int, int, int, int, int,
int, uint32_t);
/* @} */

/** \defgroup caca_frame libcaca canvas frame handling
*
* These functions provide high level routines for canvas frame insertion,
* removal, copying etc.
*
* @{ */
__extern int caca_get_frame_count(caca_canvas_t const *);
__extern int caca_set_frame(caca_canvas_t *, int);
__extern char const *caca_get_frame_name(caca_canvas_t const *);
__extern int caca_set_frame_name(caca_canvas_t *, char const *);
__extern int caca_create_frame(caca_canvas_t *, int);
__extern int caca_free_frame(caca_canvas_t *, int);
/* @} */

/** \defgroup caca_dither libcaca bitmap dithering
*
* These functions provide high level routines for dither allocation and
* rendering.
*
* @{ */
__extern caca_dither_t *caca_create_dither(int, int, int, int,
uint32_t, uint32_t,
uint32_t, uint32_t);
__extern int caca_set_dither_palette(caca_dither_t *,
uint32_t r[], uint32_t g[],
uint32_t b[], uint32_t a[]);
__extern int caca_set_dither_brightness(caca_dither_t *, float);
__extern float caca_get_dither_brightness(caca_dither_t const *);
__extern int caca_set_dither_gamma(caca_dither_t *, float);
__extern float caca_get_dither_gamma(caca_dither_t const *);
__extern int caca_set_dither_contrast(caca_dither_t *, float);
__extern float caca_get_dither_contrast(caca_dither_t const *);
__extern int caca_set_dither_antialias(caca_dither_t *, char const *);
__extern char const * const * caca_get_dither_antialias_list(caca_dither_t
const *);
__extern char const * caca_get_dither_antialias(caca_dither_t const *);
__extern int caca_set_dither_color(caca_dither_t *, char const *);
__extern char const * const * caca_get_dither_color_list(caca_dither_t
const *);
__extern char const * caca_get_dither_color(caca_dither_t const *);
__extern int caca_set_dither_charset(caca_dither_t *, char const *);
__extern char const * const * caca_get_dither_charset_list(caca_dither_t
const *);
__extern char const * caca_get_dither_charset(caca_dither_t const *);
__extern int caca_set_dither_algorithm(caca_dither_t *, char const *);
__extern char const * const * caca_get_dither_algorithm_list(caca_dither_t
const *);
__extern char const * caca_get_dither_algorithm(caca_dither_t const *);
__extern int caca_dither_bitmap(caca_canvas_t *, int, int, int, int,
caca_dither_t const *, void *);
__extern int caca_free_dither(caca_dither_t *);
/* @} */

/** \defgroup caca_font libcaca font handling
*
* These functions provide font handling routines and high quality
* canvas to bitmap rendering.
*
* @{ */
__extern caca_font_t *caca_load_font(void const *, size_t);
__extern char const * const * caca_get_font_list(void);
__extern int caca_get_font_width(caca_font_t const *);
__extern int caca_get_font_height(caca_font_t const *);
__extern uint32_t const *caca_get_font_blocks(caca_font_t const *);
__extern int caca_render_canvas(caca_canvas_t const *, caca_font_t const *,
void *, int, int, int);
__extern int caca_free_font(caca_font_t *);
/* @} */

/** \defgroup caca_figfont libcaca FIGfont handling
*
* These functions provide FIGlet and TOIlet font handling routines.
*
* @{ */
__extern int caca_canvas_set_figfont(caca_canvas_t *, char const *);
__extern int caca_put_figchar(caca_canvas_t *, uint32_t);
__extern int caca_flush_figlet(caca_canvas_t *);
/* @} */

/** \defgroup caca_file libcaca file IO
*
* These functions allow to read and write files in a platform-independent
* way.
* @{ */
__extern caca_file_t *caca_file_open(char const *, const char *);
__extern int caca_file_close(caca_file_t *);
__extern uint64_t caca_file_tell(caca_file_t *);
__extern size_t caca_file_read(caca_file_t *, void *, size_t);
__extern size_t caca_file_write(caca_file_t *, const void *, size_t);
__extern char * caca_file_gets(caca_file_t *, char *, int);
__extern int caca_file_eof(caca_file_t *);
/* @} */

/** \defgroup caca_importexport libcaca importers/exporters from/to various
* formats
*
* These functions import various file formats into a new canvas, or export
* the current canvas to various text formats.
*
* @{ */
__extern ssize_t caca_import_memory(caca_canvas_t *, void const *,
size_t, char const *);
__extern ssize_t caca_import_file(caca_canvas_t *, char const *,
char const *);
__extern char const * const * caca_get_import_list(void);
__extern void *caca_export_memory(caca_canvas_t const *, char const *,
size_t *);
__extern char const * const * caca_get_export_list(void);
/* @} */

/** \defgroup caca_display libcaca display functions
*
* These functions provide the basic \e libcaca routines for display
* initialisation, system information retrieval and configuration. * initialisation, system information retrieval and configuration.
* *
* @{ */ * @{ */
__extern caca_display_t * caca_create_display(cucul_canvas_t *);
__extern caca_display_t * caca_create_display_with_driver(cucul_canvas_t *,
__extern caca_display_t * caca_create_display(caca_canvas_t *);
__extern caca_display_t * caca_create_display_with_driver(caca_canvas_t *,
char const *); char const *);
__extern char const * const * caca_get_display_driver_list(void); __extern char const * const * caca_get_display_driver_list(void);
__extern char const * caca_get_display_driver(caca_display_t *); __extern char const * caca_get_display_driver(caca_display_t *);
__extern int caca_set_display_driver(caca_display_t *, char const *); __extern int caca_set_display_driver(caca_display_t *, char const *);
__extern int caca_free_display(caca_display_t *); __extern int caca_free_display(caca_display_t *);
__extern cucul_canvas_t * caca_get_canvas(caca_display_t *);
__extern caca_canvas_t * caca_get_canvas(caca_display_t *);
__extern int caca_refresh_display(caca_display_t *); __extern int caca_refresh_display(caca_display_t *);
__extern int caca_set_display_time(caca_display_t *, int); __extern int caca_set_display_time(caca_display_t *, int);
__extern int caca_get_display_time(caca_display_t const *); __extern int caca_get_display_time(caca_display_t const *);
@@ -178,7 +445,6 @@ __extern int caca_get_display_height(caca_display_t const *);
__extern int caca_set_display_title(caca_display_t *, char const *); __extern int caca_set_display_title(caca_display_t *, char const *);
__extern int caca_set_mouse(caca_display_t *, int); __extern int caca_set_mouse(caca_display_t *, int);
__extern int caca_set_cursor(caca_display_t *, int); __extern int caca_set_cursor(caca_display_t *, int);
__extern char const * caca_get_version(void);
/* @} */ /* @} */


/** \defgroup caca_event libcaca event handling /** \defgroup caca_event libcaca event handling
@@ -201,6 +467,77 @@ __extern int caca_get_event_resize_width(caca_event_t const *);
__extern int caca_get_event_resize_height(caca_event_t const *); __extern int caca_get_event_resize_height(caca_event_t const *);
/* @} */ /* @} */


#if !defined(_DOXYGEN_SKIP_ME)
/* Legacy stuff from beta versions, will probably disappear in 1.0 */
typedef struct cucul_buffer cucul_buffer_t;
#define cucul_canvas_t caca_canvas_t
#define cucul_dither_t caca_dither_t
#define cucul_font_t caca_font_t
#define cucul_file_t caca_file_t
#define cucul_display_t caca_display_t
#define cucul_event_t caca_event_t

# if defined __GNUC__ && __GNUC__ >= 3
# define CACA_DEPRECATED __attribute__ ((__deprecated__))
# else
# define CACA_DEPRECATED
# endif
__extern int cucul_putchar(cucul_canvas_t *, int, int,
unsigned long int) CACA_DEPRECATED;
__extern unsigned long int cucul_getchar(cucul_canvas_t *,
int, int) CACA_DEPRECATED;
__extern int cucul_putstr(cucul_canvas_t *, int, int,
char const *) CACA_DEPRECATED;
__extern int cucul_set_color(cucul_canvas_t *, unsigned char,
unsigned char) CACA_DEPRECATED;
__extern int cucul_set_truecolor(cucul_canvas_t *, unsigned int,
unsigned int) CACA_DEPRECATED;
__extern unsigned int cucul_get_canvas_frame_count(cucul_canvas_t *)
CACA_DEPRECATED;
__extern int cucul_set_canvas_frame(cucul_canvas_t *,
unsigned int) CACA_DEPRECATED;
__extern int cucul_create_canvas_frame(cucul_canvas_t *,
unsigned int) CACA_DEPRECATED;
__extern int cucul_free_canvas_frame(cucul_canvas_t *,
unsigned int) CACA_DEPRECATED;
__extern cucul_buffer_t *cucul_load_memory(void *,
unsigned long int) CACA_DEPRECATED;
__extern cucul_buffer_t *cucul_load_file(char const *) CACA_DEPRECATED;
__extern unsigned long int cucul_get_buffer_size(cucul_buffer_t *)
CACA_DEPRECATED;
__extern void * cucul_get_buffer_data(cucul_buffer_t *) CACA_DEPRECATED;
__extern int cucul_free_buffer(cucul_buffer_t *) CACA_DEPRECATED;
__extern cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *,
char const *) CACA_DEPRECATED;
__extern cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *,
char const *) CACA_DEPRECATED;
__extern int cucul_rotate(cucul_canvas_t *) CACA_DEPRECATED;
__extern int cucul_set_dither_invert(cucul_dither_t *, int) CACA_DEPRECATED;
__extern int cucul_set_dither_mode(cucul_dither_t *,
char const *) CACA_DEPRECATED;
__extern char const * const * cucul_get_dither_mode_list(cucul_dither_t
const *)
CACA_DEPRECATED;
# define CUCUL_COLOR_BLACK CACA_BLACK
# define CUCUL_COLOR_BLUE CACA_BLUE
# define CUCUL_COLOR_GREEN CACA_GREEN
# define CUCUL_COLOR_CYAN CACA_CYAN
# define CUCUL_COLOR_RED CACA_RED
# define CUCUL_COLOR_MAGENTA CACA_MAGENTA
# define CUCUL_COLOR_BROWN CACA_BROWN
# define CUCUL_COLOR_LIGHTGRAY CACA_LIGHTGRAY
# define CUCUL_COLOR_DARKGRAY CACA_DARKGRAY
# define CUCUL_COLOR_LIGHTBLUE CACA_LIGHTBLUE
# define CUCUL_COLOR_LIGHTGREEN CACA_LIGHTGREEN
# define CUCUL_COLOR_LIGHTCYAN CACA_LIGHTCYAN
# define CUCUL_COLOR_LIGHTRED CACA_LIGHTRED
# define CUCUL_COLOR_LIGHTMAGENTA CACA_LIGHTMAGENTA
# define CUCUL_COLOR_YELLOW CACA_YELLOW
# define CUCUL_COLOR_WHITE CACA_YELLOW
# define CUCUL_COLOR_DEFAULT CACA_DEFAULT
# define CUCUL_COLOR_TRANSPARENT CACA_TRANSPARENT
#endif

#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif


+ 2
- 2
caca/caca.pc.in View File

@@ -6,7 +6,7 @@ includedir=@includedir@
Name: caca Name: caca
Description: Colour ASCII-Art library Description: Colour ASCII-Art library
Version: @VERSION@ Version: @VERSION@
Requires: cucul = @VERSION@
Requires: caca = @VERSION@
Conflicts: Conflicts:
Libs: -L${libdir} -lcaca -lcucul
Libs: -L${libdir} -lcaca -lcaca
Cflags: -I${includedir} Cflags: -I${includedir}

+ 29
- 29
caca/caca0.c View File

@@ -27,10 +27,10 @@
#include "caca_internals.h" #include "caca_internals.h"


/* These variables are needed to emulate old non-thread safe behaviour */ /* These variables are needed to emulate old non-thread safe behaviour */
cucul_canvas_t *__caca0_cv = NULL;
caca_canvas_t *__caca0_cv = NULL;
caca_display_t *__caca0_dp = NULL; caca_display_t *__caca0_dp = NULL;
unsigned char __caca0_fg = CUCUL_LIGHTGRAY;
unsigned char __caca0_bg = CUCUL_BLACK;
unsigned char __caca0_fg = CACA_LIGHTGRAY;
unsigned char __caca0_bg = CACA_BLACK;
char __caca0_utf8[2] = " "; char __caca0_utf8[2] = " ";


/* These functions are needed, too */ /* These functions are needed, too */
@@ -41,28 +41,28 @@ unsigned int __caca0_sqrt(unsigned int);
int __caca0_get_feature(int); int __caca0_get_feature(int);
void __caca0_set_feature(int); void __caca0_set_feature(int);
char const *__caca0_get_feature_name(int); char const *__caca0_get_feature_name(int);
cucul_canvas_t *__caca0_load_sprite(char const *);
cucul_dither_t *__caca0_create_bitmap(unsigned int, unsigned int,
caca_canvas_t *__caca0_load_sprite(char const *);
caca_dither_t *__caca0_create_bitmap(unsigned int, unsigned int,
unsigned int, unsigned int, unsigned long int, unsigned long int, unsigned int, unsigned int, unsigned long int, unsigned long int,
unsigned long int, unsigned long int); unsigned long int, unsigned long int);
void __caca0_free_bitmap(cucul_dither_t *);
void __caca0_free_bitmap(caca_dither_t *);
extern char const *__caca0_get_color_name(unsigned char); extern char const *__caca0_get_color_name(unsigned char);


/* Emulation functions */ /* Emulation functions */
int __caca0_init(void) int __caca0_init(void)
{ {
__caca0_cv = cucul_create_canvas(0, 0);
__caca0_cv = caca_create_canvas(0, 0);
if(!__caca0_cv) if(!__caca0_cv)
return -1; return -1;
__caca0_dp = caca_create_display(__caca0_cv); __caca0_dp = caca_create_display(__caca0_cv);
if(!__caca0_dp) if(!__caca0_dp)
{ {
cucul_free_canvas(__caca0_cv);
caca_free_canvas(__caca0_cv);
__caca0_cv = NULL; __caca0_cv = NULL;
return -1; return -1;
} }
__caca0_fg = CUCUL_LIGHTGRAY;
__caca0_bg = CUCUL_BLACK;
__caca0_fg = CACA_LIGHTGRAY;
__caca0_bg = CACA_BLACK;
return 0; return 0;
} }


@@ -70,7 +70,7 @@ void __caca0_end(void)
{ {
caca_free_display(__caca0_dp); caca_free_display(__caca0_dp);
__caca0_dp = NULL; __caca0_dp = NULL;
cucul_free_canvas(__caca0_cv);
caca_free_canvas(__caca0_cv);
__caca0_cv = NULL; __caca0_cv = NULL;
} }


@@ -144,7 +144,7 @@ static char const *features[] =
NULL, "none", "ordered2", "ordered4", "ordered8", "random" NULL, "none", "ordered2", "ordered4", "ordered8", "random"
}; };


static cucul_dither_t **bitmaps = NULL;
static caca_dither_t **bitmaps = NULL;
static unsigned int nbitmaps = 0; static unsigned int nbitmaps = 0;


static int background = 0x12; static int background = 0x12;
@@ -172,21 +172,21 @@ void __caca0_set_feature(int feature)
case 0x11: case 0x12: case 0x11: case 0x12:
background = feature; background = feature;
for(i = 0; i < nbitmaps; i++) for(i = 0; i < nbitmaps; i++)
cucul_set_dither_color(bitmaps[i], features[feature]);
caca_set_dither_color(bitmaps[i], features[feature]);
break; break;


case 0x20: feature = 0x22; /* CACA_ANTIALIASING_PREFILTER */ case 0x20: feature = 0x22; /* CACA_ANTIALIASING_PREFILTER */
case 0x21: case 0x22: case 0x21: case 0x22:
antialiasing = feature; antialiasing = feature;
for(i = 0; i < nbitmaps; i++) for(i = 0; i < nbitmaps; i++)
cucul_set_dither_antialias(bitmaps[i], features[feature]);
caca_set_dither_antialias(bitmaps[i], features[feature]);
break; break;


case 0x30: feature = 0x33; /* CACA_DITHERING_ORDERED4 */ case 0x30: feature = 0x33; /* CACA_DITHERING_ORDERED4 */
case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35:
dithering = feature; dithering = feature;
for(i = 0; i < nbitmaps; i++) for(i = 0; i < nbitmaps; i++)
cucul_set_dither_algorithm(bitmaps[i], features[feature]);
caca_set_dither_algorithm(bitmaps[i], features[feature]);
break; break;
} }
} }
@@ -211,48 +211,48 @@ char const *__caca0_get_feature_name(int feature)
} }
} }


cucul_canvas_t *__caca0_load_sprite(char const *file)
caca_canvas_t *__caca0_load_sprite(char const *file)
{ {
cucul_canvas_t *cv;
caca_canvas_t *cv;


cv = cucul_create_canvas(0, 0);;
if(cucul_import_file(cv, file, "") < 0)
cv = caca_create_canvas(0, 0);;
if(caca_import_file(cv, file, "") < 0)
{ {
cucul_free_canvas(cv);
caca_free_canvas(cv);
return NULL; return NULL;
} }


return cv; return cv;
} }


cucul_dither_t *__caca0_create_bitmap(unsigned int bpp, unsigned int w,
caca_dither_t *__caca0_create_bitmap(unsigned int bpp, unsigned int w,
unsigned int h, unsigned int pitch, unsigned int h, unsigned int pitch,
unsigned long int r, unsigned long int g, unsigned long int r, unsigned long int g,
unsigned long int b, unsigned long int a) unsigned long int b, unsigned long int a)
{ {
cucul_dither_t *d;
caca_dither_t *d;


d = cucul_create_dither(bpp, w, h, pitch, r, g, b, a);
d = caca_create_dither(bpp, w, h, pitch, r, g, b, a);
if(!d) if(!d)
return NULL; return NULL;


cucul_set_dither_color(d, features[background]);
cucul_set_dither_antialias(d, features[antialiasing]);
cucul_set_dither_algorithm(d, features[dithering]);
caca_set_dither_color(d, features[background]);
caca_set_dither_antialias(d, features[antialiasing]);
caca_set_dither_algorithm(d, features[dithering]);


/* Store bitmap in our list */ /* Store bitmap in our list */
nbitmaps++; nbitmaps++;
bitmaps = realloc(bitmaps, nbitmaps * (sizeof(cucul_dither_t *)));
bitmaps = realloc(bitmaps, nbitmaps * (sizeof(caca_dither_t *)));
bitmaps[nbitmaps - 1] = d; bitmaps[nbitmaps - 1] = d;


return d; return d;
} }


void __caca0_free_bitmap(cucul_dither_t *d)
void __caca0_free_bitmap(caca_dither_t *d)
{ {
unsigned int i, found = 0; unsigned int i, found = 0;


cucul_free_dither(d);
caca_free_dither(d);


/* Remove bitmap from our list */ /* Remove bitmap from our list */
for(i = 0; i + 1 < nbitmaps; i++) for(i = 0; i + 1 < nbitmaps; i++)


+ 50
- 50
caca/caca0.h View File

@@ -35,15 +35,15 @@ extern unsigned int __caca0_sqrt(unsigned int);
extern int __caca0_get_feature(int); extern int __caca0_get_feature(int);
extern void __caca0_set_feature(int); extern void __caca0_set_feature(int);
extern char const *__caca0_get_feature_name(int); extern char const *__caca0_get_feature_name(int);
extern cucul_canvas_t *__caca0_load_sprite(char const *);
extern cucul_dither_t *__caca0_create_bitmap(unsigned int, unsigned int,
extern caca_canvas_t *__caca0_load_sprite(char const *);
extern caca_dither_t *__caca0_create_bitmap(unsigned int, unsigned int,
unsigned int, unsigned int, unsigned long int, unsigned long int, unsigned int, unsigned int, unsigned long int, unsigned long int,
unsigned long int, unsigned long int); unsigned long int, unsigned long int);
extern void __caca0_free_bitmap(cucul_dither_t *);
extern void __caca0_free_bitmap(caca_dither_t *);
extern char const *__caca0_get_color_name(unsigned char); extern char const *__caca0_get_color_name(unsigned char);


/* These variables are needed to emulate old non-thread safe behaviour */ /* These variables are needed to emulate old non-thread safe behaviour */
extern cucul_canvas_t *__caca0_cv;
extern caca_canvas_t *__caca0_cv;
extern caca_display_t *__caca0_dp; extern caca_display_t *__caca0_dp;
extern unsigned char __caca0_fg; extern unsigned char __caca0_fg;
extern unsigned char __caca0_bg; extern unsigned char __caca0_bg;
@@ -51,22 +51,22 @@ extern unsigned char __caca0_bg;
/* These enums and macros changed names or values */ /* These enums and macros changed names or values */
enum caca_color enum caca_color
{ {
CACA_COLOR_BLACK = CUCUL_BLACK,
CACA_COLOR_BLUE = CUCUL_BLUE,
CACA_COLOR_GREEN = CUCUL_GREEN,
CACA_COLOR_CYAN = CUCUL_CYAN,
CACA_COLOR_RED = CUCUL_RED,
CACA_COLOR_MAGENTA = CUCUL_MAGENTA,
CACA_COLOR_BROWN = CUCUL_BROWN,
CACA_COLOR_LIGHTGRAY = CUCUL_LIGHTGRAY,
CACA_COLOR_DARKGRAY = CUCUL_DARKGRAY,
CACA_COLOR_LIGHTBLUE = CUCUL_LIGHTBLUE,
CACA_COLOR_LIGHTGREEN = CUCUL_LIGHTGREEN,
CACA_COLOR_LIGHTCYAN = CUCUL_LIGHTCYAN,
CACA_COLOR_LIGHTRED = CUCUL_LIGHTRED,
CACA_COLOR_LIGHTMAGENTA = CUCUL_LIGHTMAGENTA,
CACA_COLOR_YELLOW = CUCUL_YELLOW,
CACA_COLOR_WHITE = CUCUL_WHITE,
CACA_COLOR_BLACK = CACA_BLACK,
CACA_COLOR_BLUE = CACA_BLUE,
CACA_COLOR_GREEN = CACA_GREEN,
CACA_COLOR_CYAN = CACA_CYAN,
CACA_COLOR_RED = CACA_RED,
CACA_COLOR_MAGENTA = CACA_MAGENTA,
CACA_COLOR_BROWN = CACA_BROWN,
CACA_COLOR_LIGHTGRAY = CACA_LIGHTGRAY,
CACA_COLOR_DARKGRAY = CACA_DARKGRAY,
CACA_COLOR_LIGHTBLUE = CACA_LIGHTBLUE,
CACA_COLOR_LIGHTGREEN = CACA_LIGHTGREEN,
CACA_COLOR_LIGHTCYAN = CACA_LIGHTCYAN,
CACA_COLOR_LIGHTRED = CACA_LIGHTRED,
CACA_COLOR_LIGHTMAGENTA = CACA_LIGHTMAGENTA,
CACA_COLOR_YELLOW = CACA_YELLOW,
CACA_COLOR_WHITE = CACA_WHITE,
}; };


enum caca_feature enum caca_feature
@@ -117,8 +117,8 @@ enum caca_feature
#define caca_set_feature __caca0_set_feature #define caca_set_feature __caca0_set_feature
#define caca_get_feature_name __caca0_get_feature_name #define caca_get_feature_name __caca0_get_feature_name
#define caca_get_rendertime() caca_get_display_time(__caca0_dp) #define caca_get_rendertime() caca_get_display_time(__caca0_dp)
#define caca_get_width() cucul_get_canvas_width(__caca0_cv)
#define caca_get_height() cucul_get_canvas_height(__caca0_cv)
#define caca_get_width() caca_get_canvas_width(__caca0_cv)
#define caca_get_height() caca_get_canvas_height(__caca0_cv)
#define caca_set_window_title(s) caca_set_display_title(__caca0_dp, s) #define caca_set_window_title(s) caca_set_display_title(__caca0_dp, s)
#define caca_get_window_width() caca_get_display_width(__caca0_dp) #define caca_get_window_width() caca_get_display_width(__caca0_dp)
#define caca_get_window_height() caca_get_display_height(__caca0_dp) #define caca_get_window_height() caca_get_display_height(__caca0_dp)
@@ -131,62 +131,62 @@ enum caca_feature
#define caca_get_mouse_y() caca_get_mouse_y(__caca0_dp) #define caca_get_mouse_y() caca_get_mouse_y(__caca0_dp)


#define caca_set_color(x, y) \ #define caca_set_color(x, y) \
(__caca0_fg = (x), __caca0_bg = (y), cucul_set_color_ansi(__caca0_cv, x, y))
(__caca0_fg = (x), __caca0_bg = (y), caca_set_color_ansi(__caca0_cv, x, y))
#define caca_get_fg_color() __caca0_fg #define caca_get_fg_color() __caca0_fg
#define caca_get_bg_color() __caca0_bg #define caca_get_bg_color() __caca0_bg
#define caca_get_color_name __caca0_get_color_name #define caca_get_color_name __caca0_get_color_name
#define caca_putchar(x, y, c) cucul_put_char(__caca0_cv, x, y, c)
#define caca_putstr(x, y, s) cucul_put_str(__caca0_cv, x, y, s)
#define caca_printf(x, y, f, z...) cucul_printf(__caca0_cv, x, y, f, ##z)
#define caca_clear() cucul_clear_canvas(__caca0_cv)
#define caca_putchar(x, y, c) caca_put_char(__caca0_cv, x, y, c)
#define caca_putstr(x, y, s) caca_put_str(__caca0_cv, x, y, s)
#define caca_printf(x, y, f, z...) caca_printf(__caca0_cv, x, y, f, ##z)
#define caca_clear() caca_clear_canvas(__caca0_cv)


#define caca_draw_line(x, y, z, t, c) \ #define caca_draw_line(x, y, z, t, c) \
cucul_draw_line(__caca0_cv, x, y, z, t, c)
caca_draw_line(__caca0_cv, x, y, z, t, c)
#define caca_draw_polyline(x, y, z, c) \ #define caca_draw_polyline(x, y, z, c) \
cucul_draw_polyline(__caca0_cv, x, y, z, c)
caca_draw_polyline(__caca0_cv, x, y, z, c)
#define caca_draw_thin_line(x, y, z, t) \ #define caca_draw_thin_line(x, y, z, t) \
cucul_draw_thin_line(__caca0_cv, x, y, z, t)
caca_draw_thin_line(__caca0_cv, x, y, z, t)
#define caca_draw_thin_polyline(x, y, z) \ #define caca_draw_thin_polyline(x, y, z) \
cucul_draw_thin_polyline(__caca0_cv, x, y, z)
caca_draw_thin_polyline(__caca0_cv, x, y, z)
#define caca_draw_circle(x, y, z, c) \ #define caca_draw_circle(x, y, z, c) \
cucul_draw_circle(__caca0_cv, x, y, z, c)
caca_draw_circle(__caca0_cv, x, y, z, c)
#define caca_draw_ellipse(x, y, z, t, c) \ #define caca_draw_ellipse(x, y, z, t, c) \
cucul_draw_ellipse(__caca0_cv, x, y, z, t, c)
caca_draw_ellipse(__caca0_cv, x, y, z, t, c)
#define caca_draw_thin_ellipse(x, y, z, t) \ #define caca_draw_thin_ellipse(x, y, z, t) \
cucul_draw_thin_ellipse(__caca0_cv, x, y, z, t)
caca_draw_thin_ellipse(__caca0_cv, x, y, z, t)
#define caca_fill_ellipse(x, y, z, t, c) \ #define caca_fill_ellipse(x, y, z, t, c) \
cucul_fill_ellipse(__caca0_cv, x, y, z, t, c)
caca_fill_ellipse(__caca0_cv, x, y, z, t, c)
#define caca_draw_box(x, y, z, t, c) \ #define caca_draw_box(x, y, z, t, c) \
cucul_draw_box(__caca0_cv, x, y, z, t, c)
caca_draw_box(__caca0_cv, x, y, z, t, c)
#define caca_draw_thin_box(x, y, z, t) \ #define caca_draw_thin_box(x, y, z, t) \
cucul_draw_thin_box(__caca0_cv, x, y, z, t)
caca_draw_thin_box(__caca0_cv, x, y, z, t)
#define caca_fill_box(x, y, z, t, c) \ #define caca_fill_box(x, y, z, t, c) \
cucul_fill_box(__caca0_cv, x, y, z, t, c)
caca_fill_box(__caca0_cv, x, y, z, t, c)
#define caca_draw_triangle(x, y, z, t, u, v, c) \ #define caca_draw_triangle(x, y, z, t, u, v, c) \
cucul_draw_triangle(__caca0_cv, x, y, z, t, u, v, c)
caca_draw_triangle(__caca0_cv, x, y, z, t, u, v, c)
#define caca_draw_thin_triangle(x, y, z, t, u, v) \ #define caca_draw_thin_triangle(x, y, z, t, u, v) \
cucul_draw_thin_triangle(__caca0_cv, x, y, z, t, u, v)
caca_draw_thin_triangle(__caca0_cv, x, y, z, t, u, v)
#define caca_fill_triangle(x, y, z, t, u, v, c) \ #define caca_fill_triangle(x, y, z, t, u, v, c) \
cucul_fill_triangle(__caca0_cv, x, y, z, t, u, v, c)
caca_fill_triangle(__caca0_cv, x, y, z, t, u, v, c)


#define caca_rand(a, b) cucul_rand(a, (b)+1)
#define caca_rand(a, b) caca_rand(a, (b)+1)
#define caca_sqrt __caca0_sqrt #define caca_sqrt __caca0_sqrt


#define caca_sprite cucul_canvas
#define caca_sprite caca_canvas
#define caca_load_sprite __caca0_load_sprite #define caca_load_sprite __caca0_load_sprite
#define caca_get_sprite_frames(c) 1 #define caca_get_sprite_frames(c) 1
#define caca_get_sprite_width(c, f) cucul_get_canvas_width(c)
#define caca_get_sprite_height(c, f) cucul_get_canvas_height(c)
#define caca_get_sprite_width(c, f) caca_get_canvas_width(c)
#define caca_get_sprite_height(c, f) caca_get_canvas_height(c)
#define caca_get_sprite_dx(c, f) 0 #define caca_get_sprite_dx(c, f) 0
#define caca_get_sprite_dx(c, f) 0 #define caca_get_sprite_dx(c, f) 0
#define caca_draw_sprite(x, y, c, f) cucul_blit(__caca0_cv, x, y, c, NULL)
#define caca_free_sprite cucul_free_canvas
#define caca_draw_sprite(x, y, c, f) caca_blit(__caca0_cv, x, y, c, NULL)
#define caca_free_sprite caca_free_canvas


#define caca_bitmap cucul_dither
#define caca_bitmap caca_dither
#define caca_create_bitmap __caca0_create_bitmap #define caca_create_bitmap __caca0_create_bitmap
#define caca_set_bitmap_palette cucul_set_dither_palette
#define caca_set_bitmap_palette caca_set_dither_palette
#define caca_draw_bitmap(x, y, z, t, b, p) \ #define caca_draw_bitmap(x, y, z, t, b, p) \
cucul_dither_bitmap(__caca0_cv, x, y, z, t, b, p)
caca_dither_bitmap(__caca0_cv, x, y, z, t, b, p)
#define caca_free_bitmap __caca0_free_bitmap #define caca_free_bitmap __caca0_free_bitmap


#ifdef __cplusplus #ifdef __cplusplus


+ 54
- 2
caca/caca_internals.h View File

@@ -19,11 +19,55 @@


typedef struct caca_timer caca_timer_t; typedef struct caca_timer caca_timer_t;
typedef struct caca_privevent caca_privevent_t; typedef struct caca_privevent caca_privevent_t;
typedef struct caca_figfont caca_figfont_t;


#if !defined(_DOXYGEN_SKIP_ME) #if !defined(_DOXYGEN_SKIP_ME)
# define EVENTBUF_LEN 10 # define EVENTBUF_LEN 10
#endif #endif


struct caca_frame
{
/* Frame size */
int width, height;

/* Cell information */
uint32_t *chars;
uint32_t *attrs;

/* Painting context */
int x, y;
int handlex, handley;
uint32_t curattr;

/* Frame name */
char *name;
};

struct caca_canvas
{
/* XXX: look at caca_set_canvas_boundaries() before adding anything
* to this structure. The function is quite hacky. */

/* Frame information */
int frame, framecount;
struct caca_frame *frames;

/* Canvas management */
int refcount;
int autoinc;
int (*resize_callback)(void *);
void *resize_data;

/* Shortcut to the active frame information */
int width, height;
uint32_t *chars;
uint32_t *attrs;
uint32_t curattr;

/* FIGfont management */
caca_figfont_t *ff;
};

/* Graphics driver */ /* Graphics driver */
enum caca_driver enum caca_driver
{ {
@@ -104,8 +148,8 @@ struct caca_privevent
/* Internal caca display context */ /* Internal caca display context */
struct caca_display struct caca_display
{ {
/* A link to our cucul canvas */
cucul_canvas_t *cv;
/* A link to our caca canvas */
caca_canvas_t *cv;
int autorelease; int autorelease;


#if defined(USE_PLUGINS) #if defined(USE_PLUGINS)
@@ -168,6 +212,14 @@ struct caca_display
} events; } events;
}; };


/* Colour functions */
extern uint32_t _caca_attr_to_rgb24fg(uint32_t);
extern uint32_t _caca_attr_to_rgb24bg(uint32_t);

/* Frames functions */
extern void _caca_save_frame_info(caca_canvas_t *);
extern void _caca_load_frame_info(caca_canvas_t *);

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


cucul/cucul_types.h.in → caca/caca_types.h.in View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Canvas for ultrafast compositing of Unicode letters
* libcaca Colour ASCII-Art library
* libcaca Colour ASCII-Art library * libcaca Colour ASCII-Art library
* Copyright (c) 2008 Sam Hocevar <sam@zoy.org> * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
@@ -16,26 +16,26 @@
* This file contains definitions for the C99 integer types. * This file contains definitions for the C99 integer types.
*/ */


#ifndef __CUCUL_TYPES_H__
#define __CUCUL_TYPES_H__
#ifndef __CACA_TYPES_H__
#define __CACA_TYPES_H__


#ifndef CUCUL_TYPES
# define CUCUL_TYPES @CUCUL_TYPES@
#ifndef CACA_TYPES
# define CACA_TYPES @CACA_TYPES@
#endif #endif


/* mode 1: standard <stdint.h> header is present, just include it */ /* mode 1: standard <stdint.h> header is present, just include it */
#if CUCUL_TYPES == 1
#if CACA_TYPES == 1
# include <stdint.h> # include <stdint.h>
# include <unistd.h> # include <unistd.h>


/* mode 2: standard <inttypes.h> header is present, just include it */ /* mode 2: standard <inttypes.h> header is present, just include it */
#elif CUCUL_TYPES == 2
#elif CACA_TYPES == 2
# include <inttypes.h> # include <inttypes.h>
# include <unistd.h> # include <unistd.h>


/* mode 3: <windows.h> indicates Win32, only (u)intptr_t is present /* mode 3: <windows.h> indicates Win32, only (u)intptr_t is present
* FIXME: Win64 probably doesn't work that way */ * FIXME: Win64 probably doesn't work that way */
#elif CUCUL_TYPES == 3
#elif CACA_TYPES == 3
#include <windows.h> #include <windows.h>


typedef signed char int8_t; typedef signed char int8_t;
@@ -55,47 +55,47 @@ typedef unsigned int size_t;
* sizeof(long) == sizeof(void *). We don't typedef directly because we * sizeof(long) == sizeof(void *). We don't typedef directly because we
* have no idea what other typedefs have already been made. */ * have no idea what other typedefs have already been made. */
#else #else
typedef signed char _cucul_int8_t;
typedef signed short _cucul_int16_t;
typedef signed long int _cucul_int32_t;
typedef signed long long int _cucul_int64_t;
typedef signed char _caca_int8_t;
typedef signed short _caca_int16_t;
typedef signed long int _caca_int32_t;
typedef signed long long int _caca_int64_t;
# undef int8_t # undef int8_t
# define int8_t _cucul_int8_t
# define int8_t _caca_int8_t
# undef int16_t # undef int16_t
# define int16_t _cucul_int16_t
# define int16_t _caca_int16_t
# undef int32_t # undef int32_t
# define int32_t _cucul_int32_t
# define int32_t _caca_int32_t
# undef int64_t # undef int64_t
# define int64_t _cucul_int64_t
# define int64_t _caca_int64_t


typedef unsigned char _cucul_uint8_t;
typedef unsigned short _cucul_uint16_t;
typedef unsigned long int _cucul_uint32_t;
typedef unsigned long long int _cucul_uint64_t;
typedef unsigned char _caca_uint8_t;
typedef unsigned short _caca_uint16_t;
typedef unsigned long int _caca_uint32_t;
typedef unsigned long long int _caca_uint64_t;
# undef uint8_t # undef uint8_t
# define uint8_t _cucul_uint8_t
# define uint8_t _caca_uint8_t
# undef uint16_t # undef uint16_t
# define uint16_t _cucul_uint16_t
# define uint16_t _caca_uint16_t
# undef uint32_t # undef uint32_t
# define uint32_t _cucul_uint32_t
# define uint32_t _caca_uint32_t
# undef uint64_t # undef uint64_t
# define uint64_t _cucul_uint64_t
# define uint64_t _caca_uint64_t


typedef long int _cucul_intptr_t;
typedef unsigned long int _cucul_uintptr_t;
typedef long int _caca_intptr_t;
typedef unsigned long int _caca_uintptr_t;
# undef intptr_t # undef intptr_t
# define intptr_t _cucul_intptr_t
# define intptr_t _caca_intptr_t
# undef uintptr_t # undef uintptr_t
# define uintptr_t _cucul_uintptr_t
# define uintptr_t _caca_uintptr_t


typedef int _cucul_ssize_t;
typedef unsigned int _cucul_size_t;
typedef int _caca_ssize_t;
typedef unsigned int _caca_size_t;
# undef ssize_t # undef ssize_t
# define ssize_t _cucul_ssize_t
# define ssize_t _caca_ssize_t
# undef size_t # undef size_t
# define size_t _cucul_size_t
# define size_t _caca_size_t


#endif #endif


#endif /* __CUCUL_TYPES_H__ */
#endif /* __CACA_TYPES_H__ */



cucul/cucul.c → caca/canvas.c View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Canvas for ultrafast compositing of Unicode letters
* libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -13,7 +13,7 @@
*/ */


/* /*
* This file contains the main functions used by \e libcucul applications
* This file contains the main functions used by \e libcaca applications
* to initialise a drawing context. * to initialise a drawing context.
*/ */


@@ -30,16 +30,16 @@
# endif # endif
#endif #endif


#include "cucul.h"
#include "cucul_internals.h"
#include "caca.h"
#include "caca_internals.h"


static int cucul_resize(cucul_canvas_t *, int, int);
static int caca_resize(caca_canvas_t *, int, int);


/** \brief Initialise a \e libcucul canvas.
/** \brief Initialise a \e libcaca canvas.
* *
* Initialise internal \e libcucul structures and the backend that will
* Initialise internal \e libcaca structures and the backend that will
* be used for subsequent graphical operations. It must be the first * be used for subsequent graphical operations. It must be the first
* \e libcucul function to be called in a function. cucul_free_canvas()
* \e libcaca function to be called in a function. caca_free_canvas()
* should be called at the end of the program to free all allocated resources. * should be called at the end of the program to free all allocated resources.
* *
* Both the cursor and the canvas' handle are initialised at the top-left * Both the cursor and the canvas' handle are initialised at the top-left
@@ -51,11 +51,11 @@ static int cucul_resize(cucul_canvas_t *, int, int);
* *
* \param width The desired canvas width * \param width The desired canvas width
* \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 libcaca canvas handle upon success, NULL if an error occurred.
*/ */
cucul_canvas_t * cucul_create_canvas(int width, int height)
caca_canvas_t * caca_create_canvas(int width, int height)
{ {
cucul_canvas_t *cv;
caca_canvas_t *cv;


if(width < 0 || height < 0) if(width < 0 || height < 0)
{ {
@@ -63,7 +63,7 @@ cucul_canvas_t * cucul_create_canvas(int width, int height)
return NULL; return NULL;
} }


cv = malloc(sizeof(cucul_canvas_t));
cv = malloc(sizeof(caca_canvas_t));


if(!cv) if(!cv)
goto nomem; goto nomem;
@@ -75,7 +75,7 @@ cucul_canvas_t * cucul_create_canvas(int width, int height)


cv->frame = 0; cv->frame = 0;
cv->framecount = 1; cv->framecount = 1;
cv->frames = malloc(sizeof(struct cucul_frame));
cv->frames = malloc(sizeof(struct caca_frame));
if(!cv->frames) if(!cv->frames)
{ {
free(cv); free(cv);
@@ -90,12 +90,12 @@ cucul_canvas_t * cucul_create_canvas(int width, int height)
cv->frames[0].curattr = 0; cv->frames[0].curattr = 0;
cv->frames[0].name = strdup("frame#00000000"); cv->frames[0].name = strdup("frame#00000000");


_cucul_load_frame_info(cv);
cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_TRANSPARENT);
_caca_load_frame_info(cv);
caca_set_color_ansi(cv, CACA_DEFAULT, CACA_TRANSPARENT);


cv->ff = NULL; cv->ff = NULL;


if(cucul_resize(cv, width, height) < 0)
if(caca_resize(cv, width, height) < 0)
{ {
int saved_errno = geterrno(); int saved_errno = geterrno();
free(cv->frames[0].name); free(cv->frames[0].name);
@@ -116,7 +116,7 @@ nomem:
* *
* Lock a canvas to prevent it from being resized. If non-NULL, * Lock a canvas to prevent it from being resized. If non-NULL,
* the \e callback function pointer will be called upon each * the \e callback function pointer will be called upon each
* \e cucul_set_canvas_size call and if the returned value is zero, the
* \e caca_set_canvas_size call and if the returned value is zero, the
* canvas resize request will be denied. * canvas resize request will be denied.
* *
* This function is only useful for display drivers such as the \e libcaca * This function is only useful for display drivers such as the \e libcaca
@@ -125,12 +125,12 @@ nomem:
* If an error occurs, -1 is returned and \b errno is set accordingly: * If an error occurs, -1 is returned and \b errno is set accordingly:
* - \c EBUSY The canvas is already being managed. * - \c EBUSY The canvas is already being managed.
* *
* \param cv A libcucul canvas.
* \param cv A libcaca canvas.
* \param callback An optional callback function pointer. * \param callback An optional callback function pointer.
* \param p The argument to be passed to \e callback. * \param p The argument to be passed to \e callback.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_manage_canvas(cucul_canvas_t *cv, int (*callback)(void *), void *p)
int caca_manage_canvas(caca_canvas_t *cv, int (*callback)(void *), void *p)
{ {
if(cv->refcount) if(cv->refcount)
{ {
@@ -147,9 +147,9 @@ int cucul_manage_canvas(cucul_canvas_t *cv, int (*callback)(void *), void *p)


/** \brief Unmanage a canvas. /** \brief Unmanage a canvas.
* *
* Unlock a canvas previously locked by cucul_manage_canvas(). For safety
* Unlock a canvas previously locked by caca_manage_canvas(). For safety
* reasons, the callback and callback data arguments must be the same as for * reasons, the callback and callback data arguments must be the same as for
* the cucul_manage_canvas() call.
* the caca_manage_canvas() call.
* *
* This function is only useful for display drivers such as the \e libcaca * This function is only useful for display drivers such as the \e libcaca
* library. * library.
@@ -158,13 +158,13 @@ int cucul_manage_canvas(cucul_canvas_t *cv, int (*callback)(void *), void *p)
* - \c EINVAL The canvas is not managed, or the callback arguments do * - \c EINVAL The canvas is not managed, or the callback arguments do
* not match. * not match.
* *
* \param cv A libcucul canvas.
* \param cv A libcaca canvas.
* \param callback The \e callback argument previously passed to * \param callback The \e callback argument previously passed to
cucul_manage_canvas().
* \param p The \e p argument previously passed to cucul_manage_canvas().
caca_manage_canvas().
* \param p The \e p argument previously passed to caca_manage_canvas().
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_unmanage_canvas(cucul_canvas_t *cv, int (*callback)(void *), void *p)
int caca_unmanage_canvas(caca_canvas_t *cv, int (*callback)(void *), void *p)
{ {
if(!cv->refcount if(!cv->refcount
|| cv->resize_callback != callback || cv->resize_data != p) || cv->resize_callback != callback || cv->resize_data != p)
@@ -204,12 +204,12 @@ int cucul_unmanage_canvas(cucul_canvas_t *cv, int (*callback)(void *), void *p)
* - \c ENOMEM Not enough memory for the requested canvas size. If this * - \c ENOMEM Not enough memory for the requested canvas size. If this
* happens, the canvas handle becomes invalid and should not be used. * happens, the canvas handle becomes invalid and should not be used.
* *
* \param cv A libcucul canvas.
* \param cv A libcaca canvas.
* \param width The desired canvas width. * \param width The desired canvas width.
* \param height The desired canvas height. * \param height The desired canvas height.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_set_canvas_size(cucul_canvas_t *cv, int width, int height)
int caca_set_canvas_size(caca_canvas_t *cv, int width, int height)
{ {
if(width < 0 || height < 0) if(width < 0 || height < 0)
{ {
@@ -224,7 +224,7 @@ int cucul_set_canvas_size(cucul_canvas_t *cv, int width, int height)
return -1; return -1;
} }


return cucul_resize(cv, width, height);
return caca_resize(cv, width, height);
} }


/** \brief Get the canvas width. /** \brief Get the canvas width.
@@ -233,10 +233,10 @@ int cucul_set_canvas_size(cucul_canvas_t *cv, int width, int height)
* *
* This function never fails. * This function never fails.
* *
* \param cv A libcucul canvas.
* \param cv A libcaca canvas.
* \return The canvas width. * \return The canvas width.
*/ */
int cucul_get_canvas_width(cucul_canvas_t const *cv)
int caca_get_canvas_width(caca_canvas_t const *cv)
{ {
return cv->width; return cv->width;
} }
@@ -247,10 +247,10 @@ int cucul_get_canvas_width(cucul_canvas_t const *cv)
* *
* This function never fails. * This function never fails.
* *
* \param cv A libcucul canvas.
* \param cv A libcaca canvas.
* \return The canvas height. * \return The canvas height.
*/ */
int cucul_get_canvas_height(cucul_canvas_t const *cv)
int caca_get_canvas_height(caca_canvas_t const *cv)
{ {
return cv->height; return cv->height;
} }
@@ -259,17 +259,17 @@ int cucul_get_canvas_height(cucul_canvas_t const *cv)
* *
* Return the current canvas' internal character array. The array elements * Return the current canvas' internal character array. The array elements
* consist in native endian 32-bit Unicode values as returned by * consist in native endian 32-bit Unicode values as returned by
* cucul_get_char().
* caca_get_char().
* *
* This function is only useful for display drivers such as the \e libcaca * This function is only useful for display drivers such as the \e libcaca
* library. * library.
* *
* This function never fails. * This function never fails.
* *
* \param cv A libcucul canvas.
* \param cv A libcaca canvas.
* \return The canvas character array. * \return The canvas character array.
*/ */
uint8_t const * cucul_get_canvas_chars(cucul_canvas_t const *cv)
uint8_t const * caca_get_canvas_chars(caca_canvas_t const *cv)
{ {
return (uint8_t const *)cv->chars; return (uint8_t const *)cv->chars;
} }
@@ -278,34 +278,34 @@ uint8_t const * cucul_get_canvas_chars(cucul_canvas_t const *cv)
* *
* Returns the current canvas' internal attribute array. The array elements * Returns the current canvas' internal attribute array. The array elements
* consist in native endian 32-bit attribute values as returned by * consist in native endian 32-bit attribute values as returned by
* cucul_get_attr().
* caca_get_attr().
* *
* This function is only useful for display drivers such as the \e libcaca * This function is only useful for display drivers such as the \e libcaca
* library. * library.
* *
* This function never fails. * This function never fails.
* *
* \param cv A libcucul canvas.
* \param cv A libcaca canvas.
* \return The canvas attribute array. * \return The canvas attribute array.
*/ */
uint8_t const * cucul_get_canvas_attrs(cucul_canvas_t const *cv)
uint8_t const * caca_get_canvas_attrs(caca_canvas_t const *cv)
{ {
return (uint8_t const *)cv->attrs; return (uint8_t const *)cv->attrs;
} }


/** \brief Uninitialise \e libcucul.
/** \brief Uninitialise \e libcaca.
* *
* Free all resources allocated by cucul_create_canvas(). After
* this function has been called, no other \e libcucul functions may be
* used unless a new call to cucul_create_canvas() is done.
* Free all resources allocated by caca_create_canvas(). After
* this function has been called, no other \e libcaca functions may be
* used unless a new call to caca_create_canvas() is done.
* *
* If an error occurs, -1 is returned and \b errno is set accordingly: * If an error occurs, -1 is returned and \b errno is set accordingly:
* - \c EBUSY The canvas is in use by a display driver and cannot be freed. * - \c EBUSY The canvas is in use by a display driver and cannot be freed.
* *
* \param cv A libcucul canvas.
* \param cv A libcaca canvas.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_free_canvas(cucul_canvas_t *cv)
int caca_free_canvas(caca_canvas_t *cv)
{ {
int f; int f;


@@ -322,7 +322,7 @@ int cucul_free_canvas(cucul_canvas_t *cv)
free(cv->frames[f].name); free(cv->frames[f].name);
} }


cucul_canvas_set_figfont(cv, NULL);
caca_canvas_set_figfont(cv, NULL);


free(cv->frames); free(cv->frames);
free(cv); free(cv);
@@ -341,7 +341,7 @@ int cucul_free_canvas(cucul_canvas_t *cv)
* \return A random integer comprised between \p min and \p max - 1 * \return A random integer comprised between \p min and \p max - 1
* (inclusive). * (inclusive).
*/ */
int cucul_rand(int min, int max)
int caca_rand(int min, int max)
{ {
static int need_init = 1; static int need_init = 1;


@@ -354,24 +354,12 @@ int cucul_rand(int min, int max)
return min + (int)((1.0 * (max - min)) * rand() / (RAND_MAX + 1.0)); return min + (int)((1.0 * (max - min)) * rand() / (RAND_MAX + 1.0));
} }


/** \brief Return the \e libcucul version.
*
* Return a read-only string with the \e libcucul version information.
*
* This function never fails.
*
* \return The \e libcucul version information.
*/
char const * cucul_get_version(void)
{
return VERSION;
}


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


int cucul_resize(cucul_canvas_t *cv, int width, int height)
int caca_resize(caca_canvas_t *cv, int width, int height)
{ {
int x, y, f, old_width, old_height, new_size, old_size; int x, y, f, old_width, old_height, new_size, old_size;


@@ -379,7 +367,7 @@ int cucul_resize(cucul_canvas_t *cv, int width, int height)
old_height = cv->height; old_height = cv->height;
old_size = old_width * old_height; old_size = old_width * old_height;


_cucul_save_frame_info(cv);
_caca_save_frame_info(cv);


cv->width = width; cv->width = width;
cv->height = height; cv->height = height;
@@ -507,7 +495,7 @@ int cucul_resize(cucul_canvas_t *cv, int width, int height)
} }


/* Reset the current frame shortcuts */ /* Reset the current frame shortcuts */
_cucul_load_frame_info(cv);
_caca_load_frame_info(cv);


return 0; return 0;
} }

cucul/charset.c → caca/charset.c View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Canvas for ultrafast compositing of Unicode letters
* libcaca Colour ASCII-Art library
* Copyright (c) 2002-2007 Sam Hocevar <sam@zoy.org> * Copyright (c) 2002-2007 Sam Hocevar <sam@zoy.org>
* 2007 Ben Wiley Sittler <bsittler@gmail.com> * 2007 Ben Wiley Sittler <bsittler@gmail.com>
* All Rights Reserved * All Rights Reserved
@@ -24,8 +24,8 @@
# include <string.h> # include <string.h>
#endif #endif


#include "cucul.h"
#include "cucul_internals.h"
#include "caca.h"
#include "caca_internals.h"


/* /*
* UTF-8 handling * UTF-8 handling
@@ -111,7 +111,7 @@ static uint32_t const cp437_lookup2[] =
* \return The corresponding UTF-32 character, or zero if the character * \return The corresponding UTF-32 character, or zero if the character
* is incomplete. * is incomplete.
*/ */
uint32_t cucul_utf8_to_utf32(char const *s, size_t *bytes)
uint32_t caca_utf8_to_utf32(char const *s, size_t *bytes)
{ {
int todo = trailing[(int)(unsigned char)*s]; int todo = trailing[(int)(unsigned char)*s];
int i = 0; int i = 0;
@@ -150,7 +150,7 @@ uint32_t cucul_utf8_to_utf32(char const *s, size_t *bytes)
* \param ch The UTF-32 character. * \param ch The UTF-32 character.
* \return The number of bytes written. * \return The number of bytes written.
*/ */
size_t cucul_utf32_to_utf8(char *buf, uint32_t ch)
size_t caca_utf32_to_utf8(char *buf, uint32_t ch)
{ {
static const uint8_t mark[7] = static const uint8_t mark[7] =
{ {
@@ -190,7 +190,7 @@ size_t cucul_utf32_to_utf8(char *buf, uint32_t ch)
* \param ch The UTF-32 character. * \param ch The UTF-32 character.
* \return The corresponding CP437 character, or "?" if not representable. * \return The corresponding CP437 character, or "?" if not representable.
*/ */
uint8_t cucul_utf32_to_cp437(uint32_t ch)
uint8_t caca_utf32_to_cp437(uint32_t ch)
{ {
unsigned int i; unsigned int i;


@@ -222,7 +222,7 @@ uint8_t cucul_utf32_to_cp437(uint32_t ch)
* \param ch The CP437 character. * \param ch The CP437 character.
* \return The corresponding UTF-32 character, or zero if not representable. * \return The corresponding UTF-32 character, or zero if not representable.
*/ */
uint32_t cucul_cp437_to_utf32(uint8_t ch)
uint32_t caca_cp437_to_utf32(uint8_t ch)
{ {
if(ch > 0x7f) if(ch > 0x7f)
return cp437_lookup2[ch - 0x7f]; return cp437_lookup2[ch - 0x7f];
@@ -248,7 +248,7 @@ uint32_t cucul_cp437_to_utf32(uint8_t ch)
* \return The corresponding ASCII character, or a graphically close * \return The corresponding ASCII character, or a graphically close
* equivalent if found, or "?" if not representable. * equivalent if found, or "?" if not representable.
*/ */
char cucul_utf32_to_ascii(uint32_t ch)
char caca_utf32_to_ascii(uint32_t ch)
{ {
/* Standard ASCII */ /* Standard ASCII */
if(ch < 0x80) if(ch < 0x80)
@@ -387,7 +387,7 @@ char cucul_utf32_to_ascii(uint32_t ch)
* \param ch The UTF-32 character. * \param ch The UTF-32 character.
* \return 1 if the character is fullwidth, 0 otherwise. * \return 1 if the character is fullwidth, 0 otherwise.
*/ */
int cucul_utf32_is_fullwidth(uint32_t ch)
int caca_utf32_is_fullwidth(uint32_t ch)
{ {
if(ch < 0x2e80) /* Standard stuff */ if(ch < 0x2e80) /* Standard stuff */
return 0; return 0;

cucul/conic.c → caca/conic.c View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Canvas for ultrafast compositing of Unicode letters
* libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -23,23 +23,23 @@
# include <stdlib.h> # include <stdlib.h>
#endif #endif


#include "cucul.h"
#include "cucul_internals.h"
#include "caca.h"
#include "caca_internals.h"


static void ellipsepoints(cucul_canvas_t *, int, int, int, int, uint32_t, int);
static void ellipsepoints(caca_canvas_t *, int, int, int, int, uint32_t, int);


/** \brief Draw a circle on the canvas using the given character. /** \brief Draw a circle on the canvas using the given character.
* *
* This function never fails. * This function never fails.
* *
* \param cv The handle to the libcucul canvas.
* \param cv The handle to the libcaca canvas.
* \param x Center X coordinate. * \param x Center X coordinate.
* \param y Center Y coordinate. * \param y Center Y coordinate.
* \param r Circle radius. * \param r Circle radius.
* \param ch UTF-32 character to be used to draw the circle outline. * \param ch UTF-32 character to be used to draw the circle outline.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_draw_circle(cucul_canvas_t *cv, int x, int y, int r, uint32_t ch)
int caca_draw_circle(caca_canvas_t *cv, int x, int y, int r, uint32_t ch)
{ {
int test, dx, dy; int test, dx, dy;


@@ -59,7 +59,7 @@ int cucul_draw_circle(cucul_canvas_t *cv, int x, int y, int r, uint32_t ch)
* *
* This function never fails. * This function never fails.
* *
* \param cv The handle to the libcucul canvas.
* \param cv The handle to the libcaca canvas.
* \param xo Center X coordinate. * \param xo Center X coordinate.
* \param yo Center Y coordinate. * \param yo Center Y coordinate.
* \param a Ellipse X radius. * \param a Ellipse X radius.
@@ -67,7 +67,7 @@ int cucul_draw_circle(cucul_canvas_t *cv, int x, int y, int r, uint32_t ch)
* \param ch UTF-32 character to be used to fill the ellipse. * \param ch UTF-32 character to be used to fill the ellipse.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_fill_ellipse(cucul_canvas_t *cv, int xo, int yo, int a, int b,
int caca_fill_ellipse(caca_canvas_t *cv, int xo, int yo, int a, int b,
uint32_t ch) uint32_t ch)
{ {
int d2; int d2;
@@ -84,15 +84,15 @@ int cucul_fill_ellipse(cucul_canvas_t *cv, int xo, int yo, int a, int b,
else else
{ {
d1 += b*b*(2*x*1) + a*a*(-2*y+2); d1 += b*b*(2*x*1) + a*a*(-2*y+2);
cucul_draw_line(cv, xo - x, yo - y, xo + x, yo - y, ch);
cucul_draw_line(cv, xo - x, yo + y, xo + x, yo + y, ch);
caca_draw_line(cv, xo - x, yo - y, xo + x, yo - y, ch);
caca_draw_line(cv, xo - x, yo + y, xo + x, yo + y, ch);
y--; y--;
} }
x++; x++;
} }


cucul_draw_line(cv, xo - x, yo - y, xo + x, yo - y, ch);
cucul_draw_line(cv, xo - x, yo + y, xo + x, yo + y, ch);
caca_draw_line(cv, xo - x, yo - y, xo + x, yo - y, ch);
caca_draw_line(cv, xo - x, yo + y, xo + x, yo + y, ch);


d2 = b*b*(x+0.5)*(x+0.5) + a*a*(y-1)*(y-1) - a*a*b*b; d2 = b*b*(x+0.5)*(x+0.5) + a*a*(y-1)*(y-1) - a*a*b*b;
while(y > 0) while(y > 0)
@@ -108,8 +108,8 @@ int cucul_fill_ellipse(cucul_canvas_t *cv, int xo, int yo, int a, int b,
} }


y--; y--;
cucul_draw_line(cv, xo - x, yo - y, xo + x, yo - y, ch);
cucul_draw_line(cv, xo - x, yo + y, xo + x, yo + y, ch);
caca_draw_line(cv, xo - x, yo - y, xo + x, yo - y, ch);
caca_draw_line(cv, xo - x, yo + y, xo + x, yo + y, ch);
} }


return 0; return 0;
@@ -119,7 +119,7 @@ int cucul_fill_ellipse(cucul_canvas_t *cv, int xo, int yo, int a, int b,
* *
* This function never fails. * This function never fails.
* *
* \param cv The handle to the libcucul canvas.
* \param cv The handle to the libcaca canvas.
* \param xo Center X coordinate. * \param xo Center X coordinate.
* \param yo Center Y coordinate. * \param yo Center Y coordinate.
* \param a Ellipse X radius. * \param a Ellipse X radius.
@@ -127,7 +127,7 @@ int cucul_fill_ellipse(cucul_canvas_t *cv, int xo, int yo, int a, int b,
* \param ch UTF-32 character to be used to draw the ellipse outline. * \param ch UTF-32 character to be used to draw the ellipse outline.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_draw_ellipse(cucul_canvas_t *cv, int xo, int yo, int a, int b,
int caca_draw_ellipse(caca_canvas_t *cv, int xo, int yo, int a, int b,
uint32_t ch) uint32_t ch)
{ {
int d2; int d2;
@@ -176,14 +176,14 @@ int cucul_draw_ellipse(cucul_canvas_t *cv, int xo, int yo, int a, int b,
* *
* This function never fails. * This function never fails.
* *
* \param cv The handle to the libcucul canvas.
* \param cv The handle to the libcaca canvas.
* \param xo Center X coordinate. * \param xo Center X coordinate.
* \param yo Center Y coordinate. * \param yo Center Y coordinate.
* \param a Ellipse X radius. * \param a Ellipse X radius.
* \param b Ellipse Y radius. * \param b Ellipse Y radius.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_draw_thin_ellipse(cucul_canvas_t *cv, int xo, int yo, int a, int b)
int caca_draw_thin_ellipse(caca_canvas_t *cv, int xo, int yo, int a, int b)
{ {
/* FIXME: this is not correct */ /* FIXME: this is not correct */
int d2; int d2;
@@ -234,7 +234,7 @@ int cucul_draw_thin_ellipse(cucul_canvas_t *cv, int xo, int yo, int a, int b)
return 0; return 0;
} }


static void ellipsepoints(cucul_canvas_t *cv, int xo, int yo, int x, int y,
static void ellipsepoints(caca_canvas_t *cv, int xo, int yo, int x, int y,
uint32_t ch, int thin) uint32_t ch, int thin)
{ {
uint8_t b = 0; uint8_t b = 0;
@@ -268,7 +268,7 @@ static void ellipsepoints(cucul_canvas_t *cv, int xo, int yo, int x, int y,
} }


} }
cucul_put_char(cv, xo + x, yo + y, c);
caca_put_char(cv, xo + x, yo + y, c);
} }
if((b & (0x2|0x4)) == (0x2|0x4)) { if((b & (0x2|0x4)) == (0x2|0x4)) {
uint32_t c = ch; uint32_t c = ch;
@@ -290,7 +290,7 @@ static void ellipsepoints(cucul_canvas_t *cv, int xo, int yo, int x, int y,
} }


} }
cucul_put_char(cv, xo - x, yo + y, c);
caca_put_char(cv, xo - x, yo + y, c);
} }




@@ -314,7 +314,7 @@ static void ellipsepoints(cucul_canvas_t *cv, int xo, int yo, int x, int y,
} }


} }
cucul_put_char(cv, xo + x, yo - y, c);
caca_put_char(cv, xo + x, yo - y, c);
} }


if((b & (0x2|0x8)) == (0x2|0x8)) { if((b & (0x2|0x8)) == (0x2|0x8)) {
@@ -337,7 +337,7 @@ static void ellipsepoints(cucul_canvas_t *cv, int xo, int yo, int x, int y,
} }


} }
cucul_put_char(cv, xo - x, yo - y, c);
caca_put_char(cv, xo - x, yo - y, c);
} }



cucul/dither.c → caca/dither.c View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Canvas for ultrafast compositing of Unicode letters
* libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -28,8 +28,8 @@
# include <string.h> # include <string.h>
#endif #endif


#include "cucul.h"
#include "cucul_internals.h"
#include "caca.h"
#include "caca_internals.h"


#define CP437 0 #define CP437 0


@@ -115,14 +115,14 @@ enum color_mode
COLOR_MODE_FULL16 COLOR_MODE_FULL16
}; };


struct cucul_dither
struct caca_dither
{ {
int bpp, has_palette, has_alpha; int bpp, has_palette, has_alpha;
int w, h, pitch; int w, h, pitch;
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)(cucul_dither_t *, char *, int, int);
void (*get_hsv)(caca_dither_t *, char *, int, int);
int red[256], green[256], blue[256], alpha[256]; int red[256], green[256], blue[256], alpha[256];


/* Colour features */ /* Colour features */
@@ -172,7 +172,7 @@ struct cucul_dither
static void mask2shift(uint32_t, int *, int *); static void mask2shift(uint32_t, int *, int *);
static float gammapow(float x, float y); static float gammapow(float x, float y);


static void get_rgba_default(cucul_dither_t const *, uint8_t *, int, int,
static void get_rgba_default(caca_dither_t const *, uint8_t *, int, int,
unsigned int *); unsigned int *);
static int init_lookup(void); static int init_lookup(void);


@@ -242,7 +242,7 @@ static inline void rgb2hsv_default(int r, int g, int b,
* Create a dither structure from its coordinates (depth, width, height and * Create a dither structure from its coordinates (depth, width, height and
* pitch) and pixel mask values. If the depth is 8 bits per pixel, the mask * pitch) and pixel mask values. If the depth is 8 bits per pixel, the mask
* values are ignored and the colour palette should be set using the * values are ignored and the colour palette should be set using the
* cucul_set_dither_palette() function. For depths greater than 8 bits per
* caca_set_dither_palette() function. For depths greater than 8 bits per
* pixel, a zero alpha mask causes the alpha values to be ignored. * pixel, a zero alpha mask causes the alpha values to be ignored.
* *
* If an error occurs, NULL is returned and \b errno is set accordingly: * If an error occurs, NULL is returned and \b errno is set accordingly:
@@ -260,11 +260,11 @@ 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 upon success, NULL if an error occurred. * \return Dither object upon success, NULL if an error occurred.
*/ */
cucul_dither_t *cucul_create_dither(int bpp, int w, int h, int pitch,
caca_dither_t *caca_create_dither(int bpp, int w, int h, int pitch,
uint32_t rmask, uint32_t gmask, uint32_t rmask, uint32_t gmask,
uint32_t bmask, uint32_t amask) uint32_t bmask, uint32_t amask)
{ {
cucul_dither_t *d;
caca_dither_t *d;
int i; int i;


/* Minor sanity test */ /* Minor sanity test */
@@ -274,7 +274,7 @@ cucul_dither_t *cucul_create_dither(int bpp, int w, int h, int pitch,
return NULL; return NULL;
} }


d = malloc(sizeof(cucul_dither_t));
d = malloc(sizeof(caca_dither_t));
if(!d) if(!d)
{ {
seterrno(ENOMEM); seterrno(ENOMEM);
@@ -371,7 +371,7 @@ cucul_dither_t *cucul_create_dither(int bpp, int w, int h, int pitch,
* \param alpha Array of 256 alpha values. * \param alpha Array of 256 alpha values.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_set_dither_palette(cucul_dither_t *d,
int caca_set_dither_palette(caca_dither_t *d,
uint32_t red[], uint32_t green[], uint32_t red[], uint32_t green[],
uint32_t blue[], uint32_t alpha[]) uint32_t blue[], uint32_t alpha[])
{ {
@@ -420,7 +420,7 @@ int cucul_set_dither_palette(cucul_dither_t *d,
* \param brightness brightness value. * \param brightness brightness value.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_set_dither_brightness(cucul_dither_t *d, float brightness)
int caca_set_dither_brightness(caca_dither_t *d, float brightness)
{ {
/* FIXME */ /* FIXME */
d->brightness = brightness; d->brightness = brightness;
@@ -437,7 +437,7 @@ int cucul_set_dither_brightness(cucul_dither_t *d, float brightness)
* \param d Dither object. * \param d Dither object.
* \return Brightness value. * \return Brightness value.
*/ */
float cucul_get_dither_brightness(cucul_dither_t const *d)
float caca_get_dither_brightness(caca_dither_t const *d)
{ {
return d->brightness; return d->brightness;
} }
@@ -454,7 +454,7 @@ float cucul_get_dither_brightness(cucul_dither_t const *d)
* \param gamma Gamma value. * \param gamma Gamma value.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_set_dither_gamma(cucul_dither_t *d, float gamma)
int caca_set_dither_gamma(caca_dither_t *d, float gamma)
{ {
/* FIXME: we don't need 4096 calls to gammapow(), we could just compute /* FIXME: we don't need 4096 calls to gammapow(), we could just compute
* a few of them and do linear interpolation for the rest. This will * a few of them and do linear interpolation for the rest. This will
@@ -489,7 +489,7 @@ int cucul_set_dither_gamma(cucul_dither_t *d, float gamma)
* \param d Dither object. * \param d Dither object.
* \return Gamma value. * \return Gamma value.
*/ */
float cucul_get_dither_gamma(cucul_dither_t const *d)
float caca_get_dither_gamma(caca_dither_t const *d)
{ {
return d->gamma; return d->gamma;
} }
@@ -505,7 +505,7 @@ float cucul_get_dither_gamma(cucul_dither_t const *d)
* \param contrast contrast value. * \param contrast contrast value.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_set_dither_contrast(cucul_dither_t *d, float contrast)
int caca_set_dither_contrast(caca_dither_t *d, float contrast)
{ {
/* FIXME */ /* FIXME */
d->contrast = contrast; d->contrast = contrast;
@@ -522,7 +522,7 @@ int cucul_set_dither_contrast(cucul_dither_t *d, float contrast)
* \param d Dither object. * \param d Dither object.
* \return Contrast value. * \return Contrast value.
*/ */
float cucul_get_dither_contrast(cucul_dither_t const *d)
float caca_get_dither_contrast(caca_dither_t const *d)
{ {
return d->contrast; return d->contrast;
} }
@@ -543,7 +543,7 @@ float cucul_get_dither_contrast(cucul_dither_t const *d)
* for the dithering. * for the dithering.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_set_dither_antialias(cucul_dither_t *d, char const *str)
int caca_set_dither_antialias(caca_dither_t *d, char const *str)
{ {
if(!strcasecmp(str, "none")) if(!strcasecmp(str, "none"))
{ {
@@ -569,7 +569,7 @@ int cucul_set_dither_antialias(cucul_dither_t *d, char const *str)
* Return a list of available antialiasing methods for a given dither. The * Return a list of available antialiasing methods for a given dither. The
* list is a NULL-terminated array of strings, interleaving a string * list is a NULL-terminated array of strings, interleaving a string
* containing the internal value for the antialiasing method to be used with * containing the internal value for the antialiasing method to be used with
* cucul_set_dither_antialias(), and a string containing the natural
* caca_set_dither_antialias(), and a string containing the natural
* language description for that antialiasing method. * language description for that antialiasing method.
* *
* This function never fails. * This function never fails.
@@ -578,7 +578,7 @@ int cucul_set_dither_antialias(cucul_dither_t *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(cucul_dither_t const *d)
caca_get_dither_antialias_list(caca_dither_t const *d)
{ {
static char const * const list[] = static char const * const list[] =
{ {
@@ -599,7 +599,7 @@ char const * const *
* \param d Dither object. * \param d Dither object.
* \return A static string. * \return A static string.
*/ */
char const * cucul_get_dither_antialias(cucul_dither_t const *d)
char const * caca_get_dither_antialias(caca_dither_t const *d)
{ {
return d->antialias_name; return d->antialias_name;
} }
@@ -627,7 +627,7 @@ char const * cucul_get_dither_antialias(cucul_dither_t const *d)
* for the dithering. * for the dithering.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_set_dither_color(cucul_dither_t *d, char const *str)
int caca_set_dither_color(caca_dither_t *d, char const *str)
{ {
if(!strcasecmp(str, "mono")) if(!strcasecmp(str, "mono"))
{ {
@@ -678,7 +678,7 @@ int cucul_set_dither_color(cucul_dither_t *d, char const *str)
* Return a list of available colour modes for a given dither. The list * Return a list of available colour modes for a given dither. The list
* is a NULL-terminated array of strings, interleaving a string containing * is a NULL-terminated array of strings, interleaving a string containing
* the internal value for the colour mode, to be used with * the internal value for the colour mode, to be used with
* cucul_set_dither_color(), and a string containing the natural
* caca_set_dither_color(), and a string containing the natural
* language description for that colour mode. * language description for that colour mode.
* *
* This function never fails. * This function never fails.
@@ -687,7 +687,7 @@ int cucul_set_dither_color(cucul_dither_t *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(cucul_dither_t const *d)
caca_get_dither_color_list(caca_dither_t const *d)
{ {
static char const * const list[] = static char const * const list[] =
{ {
@@ -713,7 +713,7 @@ char const * const *
* \param d Dither object. * \param d Dither object.
* \return A static string. * \return A static string.
*/ */
char const * cucul_get_dither_color(cucul_dither_t const *d)
char const * caca_get_dither_color(caca_dither_t const *d)
{ {
return d->color_name; return d->color_name;
} }
@@ -738,7 +738,7 @@ char const * cucul_get_dither_color(cucul_dither_t const *d)
* for the dithering. * for the dithering.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_set_dither_charset(cucul_dither_t *d, char const *str)
int caca_set_dither_charset(caca_dither_t *d, char const *str)
{ {
if(!strcasecmp(str, "shades")) if(!strcasecmp(str, "shades"))
{ {
@@ -772,7 +772,7 @@ int cucul_set_dither_charset(cucul_dither_t *d, char const *str)
* Return a list of available character sets for a given dither. The list * Return a list of available character sets for a given dither. The list
* is a NULL-terminated array of strings, interleaving a string containing * is a NULL-terminated array of strings, interleaving a string containing
* the internal value for the character set, to be used with * the internal value for the character set, to be used with
* cucul_set_dither_charset(), and a string containing the natural
* caca_set_dither_charset(), and a string containing the natural
* language description for that character set. * language description for that character set.
* *
* This function never fails. * This function never fails.
@@ -780,7 +780,7 @@ int cucul_set_dither_charset(cucul_dither_t *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(cucul_dither_t const *d)
char const * const * caca_get_dither_charset_list(caca_dither_t const *d)
{ {
static char const * const list[] = static char const * const list[] =
{ {
@@ -802,7 +802,7 @@ char const * const * cucul_get_dither_charset_list(cucul_dither_t const *d)
* \param d Dither object. * \param d Dither object.
* \return A static string. * \return A static string.
*/ */
char const * cucul_get_dither_charset(cucul_dither_t const *d)
char const * caca_get_dither_charset(caca_dither_t const *d)
{ {
return d->glyph_name; return d->glyph_name;
} }
@@ -827,7 +827,7 @@ char const * cucul_get_dither_charset(cucul_dither_t const *d)
* for the dithering. * for the dithering.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_set_dither_algorithm(cucul_dither_t *d, char const *str)
int caca_set_dither_algorithm(caca_dither_t *d, char const *str)
{ {
if(!strcasecmp(str, "none")) if(!strcasecmp(str, "none"))
{ {
@@ -885,7 +885,7 @@ int cucul_set_dither_algorithm(cucul_dither_t *d, char const *str)
* Return a list of available dithering algorithms for a given dither. The * Return a list of available dithering algorithms for a given dither. The
* list is a NULL-terminated array of strings, interleaving a string * list is a NULL-terminated array of strings, interleaving a string
* containing the internal value for the dithering algorithm, to be used * containing the internal value for the dithering algorithm, to be used
* with cucul_set_dither_dithering(), and a string containing the natural
* with caca_set_dither_dithering(), and a string containing the natural
* language description for that algorithm. * language description for that algorithm.
* *
* This function never fails. * This function never fails.
@@ -893,7 +893,7 @@ int cucul_set_dither_algorithm(cucul_dither_t *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_algorithm_list(cucul_dither_t const *d)
char const * const * caca_get_dither_algorithm_list(caca_dither_t const *d)
{ {
static char const * const list[] = static char const * const list[] =
{ {
@@ -918,7 +918,7 @@ char const * const * cucul_get_dither_algorithm_list(cucul_dither_t const *d)
* \param d Dither object. * \param d Dither object.
* \return A static string. * \return A static string.
*/ */
char const * cucul_get_dither_algorithm(cucul_dither_t const *d)
char const * caca_get_dither_algorithm(caca_dither_t const *d)
{ {
return d->algo_name; return d->algo_name;
} }
@@ -930,7 +930,7 @@ char const * cucul_get_dither_algorithm(cucul_dither_t const *d)
* *
* This function never fails. * This function never fails.
* *
* \param cv A handle to the libcucul canvas.
* \param cv A handle to the libcaca canvas.
* \param x X coordinate of the upper-left corner of the drawing area. * \param x X coordinate of the upper-left corner of the drawing area.
* \param y Y coordinate of the upper-left corner of the drawing area. * \param y Y coordinate of the upper-left corner of the drawing area.
* \param w Width of the drawing area. * \param w Width of the drawing area.
@@ -939,8 +939,8 @@ char const * cucul_get_dither_algorithm(cucul_dither_t const *d)
* \param pixels Bitmap's pixels. * \param pixels Bitmap's pixels.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_dither_bitmap(cucul_canvas_t *cv, int x, int y, int w, int h,
cucul_dither_t const *d, void *pixels)
int caca_dither_bitmap(caca_canvas_t *cv, int x, int y, int w, int h,
caca_dither_t const *d, void *pixels)
{ {
int *floyd_steinberg, *fs_r, *fs_g, *fs_b; int *floyd_steinberg, *fs_r, *fs_g, *fs_b;
uint32_t savedattr; uint32_t savedattr;
@@ -950,7 +950,7 @@ int cucul_dither_bitmap(cucul_canvas_t *cv, int x, int y, int w, int h,
if(!d || !pixels) if(!d || !pixels)
return 0; return 0;


savedattr = cucul_get_attr(cv, -1, -1);
savedattr = caca_get_attr(cv, -1, -1);


x1 = x; x2 = x + w - 1; x1 = x; x2 = x + w - 1;
y1 = y; y2 = y + h - 1; y1 = y; y2 = y + h - 1;
@@ -1127,7 +1127,7 @@ int cucul_dither_bitmap(cucul_canvas_t *cv, int x, int y, int w, int h,
if(rgba[1] > lum) lum = rgba[1]; if(rgba[1] > lum) lum = rgba[1];
if(rgba[2] > lum) lum = rgba[2]; if(rgba[2] > lum) lum = rgba[2];
outfg = outbg; outfg = outbg;
outbg = CUCUL_BLACK;
outbg = CACA_BLACK;


ch = lum * dchmax / 0x1000; ch = lum * dchmax / 0x1000;
if(ch < 0) if(ch < 0)
@@ -1169,8 +1169,8 @@ int cucul_dither_bitmap(cucul_canvas_t *cv, int x, int y, int w, int h,
} }


/* Now output the character */ /* Now output the character */
cucul_set_color_ansi(cv, outfg, outbg);
cucul_put_char(cv, x, y, outch);
caca_set_color_ansi(cv, outfg, outbg);
caca_put_char(cv, x, y, outch);


d->increment_dither(); d->increment_dither();
} }
@@ -1179,21 +1179,21 @@ int cucul_dither_bitmap(cucul_canvas_t *cv, int x, int y, int w, int h,


free(floyd_steinberg); free(floyd_steinberg);


cucul_set_attr(cv, savedattr);
caca_set_attr(cv, savedattr);


return 0; return 0;
} }


/** \brief Free the memory associated with a dither. /** \brief Free the memory associated with a dither.
* *
* Free the memory allocated by cucul_create_dither().
* Free the memory allocated by caca_create_dither().
* *
* This function never fails. * This function never fails.
* *
* \param d Dither object. * \param d Dither object.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_free_dither(cucul_dither_t *d)
int caca_free_dither(caca_dither_t *d)
{ {
if(!d) if(!d)
return 0; return 0;
@@ -1296,7 +1296,7 @@ static float gammapow(float x, float y)
#endif #endif
} }


static void get_rgba_default(cucul_dither_t const *d, uint8_t *pixels,
static void get_rgba_default(caca_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;
@@ -1493,7 +1493,7 @@ static void init_random_dither(int line)


static int get_random_dither(void) static int get_random_dither(void)
{ {
return cucul_rand(0x00, 0x100);
return caca_rand(0x00, 0x100);
} }


static void increment_random_dither(void) static void increment_random_dither(void)
@@ -1509,16 +1509,16 @@ static int init_lookup(void)
int v, s, h; int v, s, h;


/* These ones are constant */ /* These ones are constant */
lookup_colors[0] = CUCUL_BLACK;
lookup_colors[1] = CUCUL_DARKGRAY;
lookup_colors[2] = CUCUL_LIGHTGRAY;
lookup_colors[3] = CUCUL_WHITE;
lookup_colors[0] = CACA_BLACK;
lookup_colors[1] = CACA_DARKGRAY;
lookup_colors[2] = CACA_LIGHTGRAY;
lookup_colors[3] = CACA_WHITE;


/* These ones will be overwritten */ /* These ones will be overwritten */
lookup_colors[4] = CUCUL_MAGENTA;
lookup_colors[5] = CUCUL_LIGHTMAGENTA;
lookup_colors[6] = CUCUL_RED;
lookup_colors[7] = CUCUL_LIGHTRED;
lookup_colors[4] = CACA_MAGENTA;
lookup_colors[5] = CACA_LIGHTMAGENTA;
lookup_colors[6] = CACA_RED;
lookup_colors[7] = CACA_LIGHTRED;


for(v = 0; v < LOOKUP_VAL; v++) for(v = 0; v < LOOKUP_VAL; v++)
for(s = 0; s < LOOKUP_SAT; s++) for(s = 0; s < LOOKUP_SAT; s++)

+ 23
- 23
caca/driver_cocoa.m View File

@@ -23,7 +23,7 @@


#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>


#include "cucul.h"
#include "caca.h"
#include "caca.h" #include "caca.h"
#include "caca_internals.h" #include "caca_internals.h"


@@ -195,14 +195,14 @@ static BOOL s_quitting = NO;


- (void)resizeIfNeeded:(caca_display_t *)dp - (void)resizeIfNeeded:(caca_display_t *)dp
{ {
if(_w != cucul_get_canvas_width(dp->cv)
|| _h != cucul_get_canvas_height(dp->cv)
if(_w != caca_get_canvas_width(dp->cv)
|| _h != caca_get_canvas_height(dp->cv)
|| !_attrs || !_bkg_rects || !_bkg_colors) || !_attrs || !_bkg_rects || !_bkg_colors)
{ {
debug_log(@"%s resize to %ux%u", _cmd, _w, _h); debug_log(@"%s resize to %ux%u", _cmd, _w, _h);
_w = cucul_get_canvas_width(dp->cv);
_h = cucul_get_canvas_height(dp->cv);
_w = caca_get_canvas_width(dp->cv);
_h = caca_get_canvas_height(dp->cv);


if(_attrs) if(_attrs)
free(_attrs); free(_attrs);
@@ -216,8 +216,8 @@ static BOOL s_quitting = NO;
free(_bkg_colors); free(_bkg_colors);
_bkg_colors = malloc(_w * _h * sizeof(NSColor*)); _bkg_colors = malloc(_w * _h * sizeof(NSColor*));


[[self window] setContentSize: NSMakeSize(cucul_get_canvas_width(dp->cv) * _font_rect.size.width,
cucul_get_canvas_height(dp->cv) * _font_rect.size.height)];
[[self window] setContentSize: NSMakeSize(caca_get_canvas_width(dp->cv) * _font_rect.size.width,
caca_get_canvas_height(dp->cv) * _font_rect.size.height)];
} }
} }


@@ -228,9 +228,9 @@ static BOOL s_quitting = NO;
if(_attrs) if(_attrs)
{ {
_chars = _attrs + _w * _h; _chars = _attrs + _w * _h;
memcpy(_attrs, cucul_get_canvas_attrs(dp->cv),
memcpy(_attrs, caca_get_canvas_attrs(dp->cv),
_w * _h * sizeof(uint32_t)); _w * _h * sizeof(uint32_t));
memcpy(_chars, cucul_get_canvas_chars(dp->cv),
memcpy(_chars, caca_get_canvas_chars(dp->cv),
_w * _h * sizeof(uint32_t)); _w * _h * sizeof(uint32_t));


[self setNeedsDisplay:TRUE]; [self setNeedsDisplay:TRUE];
@@ -270,7 +270,7 @@ static BOOL s_quitting = NO;
attrs = _attrs + x + y * _w; attrs = _attrs + x + y * _w;
NSColor* color = nil; NSColor* color = nil;
#if USE_RGB12_FGBG #if USE_RGB12_FGBG
uint16_t bg = cucul_attr_to_rgb12_bg(*attrs);
uint16_t bg = caca_attr_to_rgb12_bg(*attrs);
if(bg) if(bg)
{ {
# ifdef PRECACHE_WHOLE_COLOR_TABLE # ifdef PRECACHE_WHOLE_COLOR_TABLE
@@ -288,7 +288,7 @@ static BOOL s_quitting = NO;
} }
#else #else
uint8_t argb[8]; uint8_t argb[8];
cucul_attr_to_argb64(*attrs, argb);
caca_attr_to_argb64(*attrs, argb);
color = [NSColor colorWithCalibratedRed:((float)argb[1]) / 15.0 color = [NSColor colorWithCalibratedRed:((float)argb[1]) / 15.0
green:((float)argb[2]) / 15.0 green:((float)argb[2]) / 15.0
blue:((float)argb[3]) / 15.0 blue:((float)argb[3]) / 15.0
@@ -316,7 +316,7 @@ static BOOL s_quitting = NO;
if(*chars <= 0x00000020) if(*chars <= 0x00000020)
continue; continue;


if(*chars == CUCUL_MAGIC_FULLWIDTH)
if(*chars == CACA_MAGIC_FULLWIDTH)
continue; continue;


/* Plain ASCII, no problem. */ /* Plain ASCII, no problem. */
@@ -328,7 +328,7 @@ static BOOL s_quitting = NO;
{ {
NSColor* color = nil; NSColor* color = nil;
#if USE_RGB12_FGBG #if USE_RGB12_FGBG
uint16_t fg = cucul_attr_to_rgb12_fg(*attrs);
uint16_t fg = caca_attr_to_rgb12_fg(*attrs);
# ifdef PRECACHE_WHOLE_COLOR_TABLE # ifdef PRECACHE_WHOLE_COLOR_TABLE
color = _colorCache[fg]; color = _colorCache[fg];
# else // PRECACHE_WHOLE_COLOR_TABLE # else // PRECACHE_WHOLE_COLOR_TABLE
@@ -343,7 +343,7 @@ static BOOL s_quitting = NO;
# endif // PRECACHE_WHOLE_COLOR_TABLE # endif // PRECACHE_WHOLE_COLOR_TABLE
#else // USE_RGB12_FGBG #else // USE_RGB12_FGBG
uint8_t argb[8]; uint8_t argb[8];
cucul_attr_to_argb64(*attrs, argb);
caca_attr_to_argb64(*attrs, argb);
debug_log(@"x,y=[%d,%d] r,g,b back=[%u %u %u] front=[%u %u %u]", debug_log(@"x,y=[%d,%d] r,g,b back=[%u %u %u] front=[%u %u %u]",
x, y, argb[1], argb[2], argb[3], argb[5], argb[6], argb[7]); x, y, argb[1], argb[2], argb[3], argb[5], argb[6], argb[7]);
color = [NSColor colorWithCalibratedRed:((float)argb[5]) / 15.0 color = [NSColor colorWithCalibratedRed:((float)argb[5]) / 15.0
@@ -354,7 +354,7 @@ static BOOL s_quitting = NO;


if(color) if(color)
{ {
NSMutableDictionary* attrDict = (*attrs & CUCUL_UNDERLINE) ?
NSMutableDictionary* attrDict = (*attrs & CACA_UNDERLINE) ?
_attrDictUnderline : _attrDict; _attrDictUnderline : _attrDict;
[attrDict setObject:color forKey:NSForegroundColorAttributeName]; [attrDict setObject:color forKey:NSForegroundColorAttributeName];


@@ -572,8 +572,8 @@ static void create_first_window(caca_display_t *dp)
NSFont* font = [NSFont fontWithName:@"Monaco" size:10]; NSFont* font = [NSFont fontWithName:@"Monaco" size:10];
NSRect fontRect = [font boundingRectForFont]; NSRect fontRect = [font boundingRectForFont];
fontRect = NSMakeRect(0, 0, ceilf(fontRect.size.width), ceilf(fontRect.size.height)); fontRect = NSMakeRect(0, 0, ceilf(fontRect.size.width), ceilf(fontRect.size.height));
NSRect windowRect = NSMakeRect(20, 20, cucul_get_canvas_width(dp->cv) * fontRect.size.width,
cucul_get_canvas_height(dp->cv) * fontRect.size.height);
NSRect windowRect = NSMakeRect(20, 20, caca_get_canvas_width(dp->cv) * fontRect.size.width,
caca_get_canvas_height(dp->cv) * fontRect.size.height);
convert_NSRect(&windowRect); convert_NSRect(&windowRect);


CacaView* view = [[CacaView alloc] initWithFrame:windowRect]; CacaView* view = [[CacaView alloc] initWithFrame:windowRect];
@@ -826,8 +826,8 @@ static BOOL handle_mouse_event(caca_display_t *dp, caca_privevent_t *ev,


static int cocoa_init_graphics(caca_display_t *dp) static int cocoa_init_graphics(caca_display_t *dp)
{ {
int width = cucul_get_canvas_width(dp->cv);
int height = cucul_get_canvas_height(dp->cv);
int width = caca_get_canvas_width(dp->cv);
int height = caca_get_canvas_height(dp->cv);


debug_log(@"%s dp->cv: %ux%u", __PRETTY_FUNCTION__, width, height); debug_log(@"%s dp->cv: %ux%u", __PRETTY_FUNCTION__, width, height);


@@ -838,7 +838,7 @@ static int cocoa_init_graphics(caca_display_t *dp)
return -1; return -1;


dp->resize.allow = 1; dp->resize.allow = 1;
cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 32);
caca_set_canvas_size(dp->cv, width ? width : 80, height ? height : 32);
dp->resize.allow = 0; dp->resize.allow = 0;


// first create a full cocoa app if the host has no bundle // first create a full cocoa app if the host has no bundle
@@ -858,7 +858,7 @@ static int cocoa_init_graphics(caca_display_t *dp)
static int cocoa_end_graphics(caca_display_t *dp) static int cocoa_end_graphics(caca_display_t *dp)
{ {
debug_log(@"%s dp->cv: %ux%u", __PRETTY_FUNCTION__, debug_log(@"%s dp->cv: %ux%u", __PRETTY_FUNCTION__,
cucul_get_canvas_width(dp->cv), cucul_get_canvas_height(dp->cv));
caca_get_canvas_width(dp->cv), caca_get_canvas_height(dp->cv));


NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
[dp->drv.p->window close]; [dp->drv.p->window close];
@@ -958,8 +958,8 @@ static int cocoa_get_event(caca_display_t *dp, caca_privevent_t *ev)
static void cocoa_handle_resize(caca_display_t *dp) static void cocoa_handle_resize(caca_display_t *dp)
{ {
debug_log(@"%s", __PRETTY_FUNCTION__); debug_log(@"%s", __PRETTY_FUNCTION__);
dp->resize.w = cucul_get_canvas_width(dp->cv);
dp->resize.h = cucul_get_canvas_height(dp->cv);
dp->resize.w = caca_get_canvas_width(dp->cv);
dp->resize.h = caca_get_canvas_height(dp->cv);
} }


static int cocoa_set_display_title(caca_display_t *dp, char const *title) static int cocoa_set_display_title(caca_display_t *dp, char const *title)


+ 14
- 15
caca/driver_conio.c View File

@@ -28,7 +28,6 @@


#include <stdlib.h> #include <stdlib.h>


#include "cucul.h"
#include "caca.h" #include "caca.h"
#include "caca_internals.h" #include "caca_internals.h"


@@ -57,7 +56,7 @@ static int conio_init_graphics(caca_display_t *dp)
/* FIXME */ /* FIXME */
# endif # endif
dp->resize.allow = 1; dp->resize.allow = 1;
cucul_set_canvas_size(dp->cv, dp->drv.p->ti.screenwidth,
caca_set_canvas_size(dp->cv, dp->drv.p->ti.screenwidth,
dp->drv.p->ti.screenheight); dp->drv.p->ti.screenheight);
dp->resize.allow = 0; dp->resize.allow = 0;


@@ -69,7 +68,7 @@ static int conio_end_graphics(caca_display_t *dp)
_wscroll = 1; _wscroll = 1;
textcolor((enum COLORS)WHITE); textcolor((enum COLORS)WHITE);
textbackground((enum COLORS)BLACK); textbackground((enum COLORS)BLACK);
gotoxy(cucul_get_canvas_width(dp->cv), cucul_get_canvas_height(dp->cv));
gotoxy(caca_get_canvas_width(dp->cv), caca_get_canvas_height(dp->cv));
cputs("\r\n"); cputs("\r\n");
_setcursortype(_NORMALCURSOR); _setcursortype(_NORMALCURSOR);


@@ -87,37 +86,37 @@ static int conio_set_display_title(caca_display_t *dp, char const *title)
static int conio_get_display_width(caca_display_t const *dp) static int conio_get_display_width(caca_display_t const *dp)
{ {
/* Fallback to a 6x10 font */ /* Fallback to a 6x10 font */
return cucul_get_canvas_width(dp->cv) * 6;
return caca_get_canvas_width(dp->cv) * 6;
} }


static int conio_get_display_height(caca_display_t const *dp) static int conio_get_display_height(caca_display_t const *dp)
{ {
/* Fallback to a 6x10 font */ /* Fallback to a 6x10 font */
return cucul_get_canvas_height(dp->cv) * 10;
return caca_get_canvas_height(dp->cv) * 10;
} }


static void conio_display(caca_display_t *dp) static void conio_display(caca_display_t *dp)
{ {
char *screen = dp->drv.p->screen; char *screen = dp->drv.p->screen;
uint32_t const *chars = (uint32_t const *)cucul_get_canvas_chars(dp->cv);
uint32_t const *attrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv);
int width = cucul_get_canvas_width(dp->cv);
int height = cucul_get_canvas_height(dp->cv);
uint32_t const *chars = (uint32_t const *)caca_get_canvas_chars(dp->cv);
uint32_t const *attrs = (uint32_t const *)caca_get_canvas_attrs(dp->cv);
int width = caca_get_canvas_width(dp->cv);
int height = caca_get_canvas_height(dp->cv);
int n; int n;


for(n = height * width; n--; ) for(n = height * width; n--; )
{ {
char ch = cucul_utf32_to_cp437(*chars++);
if(n && *chars == CUCUL_MAGIC_FULLWIDTH)
char ch = caca_utf32_to_cp437(*chars++);
if(n && *chars == CACA_MAGIC_FULLWIDTH)
{ {
*screen++ = '['; *screen++ = '[';
*screen++ = cucul_attr_to_ansi(*attrs++);
*screen++ = caca_attr_to_ansi(*attrs++);
ch = ']'; ch = ']';
chars++; chars++;
n--; n--;
} }
*screen++ = ch; *screen++ = ch;
*screen++ = cucul_attr_to_ansi(*attrs++);
*screen++ = caca_attr_to_ansi(*attrs++);
} }
# if defined(SCREENUPDATE_IN_PC_H) # if defined(SCREENUPDATE_IN_PC_H)
ScreenUpdate(dp->drv.p->screen); ScreenUpdate(dp->drv.p->screen);
@@ -129,8 +128,8 @@ static void conio_display(caca_display_t *dp)
static void conio_handle_resize(caca_display_t *dp) static void conio_handle_resize(caca_display_t *dp)
{ {
/* We know nothing about our window */ /* We know nothing about our window */
dp->resize.w = cucul_get_canvas_width(dp->cv);
dp->resize.h = cucul_get_canvas_height(dp->cv);
dp->resize.w = caca_get_canvas_width(dp->cv);
dp->resize.h = caca_get_canvas_height(dp->cv);
} }


static int conio_get_event(caca_display_t *dp, caca_privevent_t *ev) static int conio_get_event(caca_display_t *dp, caca_privevent_t *ev)


+ 31
- 32
caca/driver_gl.c View File

@@ -35,7 +35,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>


#include "cucul.h"
#include "caca.h" #include "caca.h"
#include "caca_internals.h" #include "caca_internals.h"


@@ -65,7 +64,7 @@ struct driver_private
int window; int window;
int width, height; int width, height;
int new_width, new_height; int new_width, new_height;
cucul_font_t *f;
caca_font_t *f;
float font_width, font_height; float font_width, font_height;
float incx, incy; float incx, incy;
uint32_t const *blocks; uint32_t const *blocks;
@@ -87,8 +86,8 @@ static int gl_init_graphics(caca_display_t *dp)
char const *geometry; char const *geometry;
char *argv[2] = { "", NULL }; char *argv[2] = { "", NULL };
char const * const * fonts; char const * const * fonts;
int width = cucul_get_canvas_width(dp->cv);
int height = cucul_get_canvas_height(dp->cv);
int width = caca_get_canvas_width(dp->cv);
int height = caca_get_canvas_height(dp->cv);
int argc = 1; int argc = 1;


dp->drv.p = malloc(sizeof(struct driver_private)); dp->drv.p = malloc(sizeof(struct driver_private));
@@ -102,28 +101,28 @@ static int gl_init_graphics(caca_display_t *dp)
#endif #endif


dp->resize.allow = 1; dp->resize.allow = 1;
cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 32);
caca_set_canvas_size(dp->cv, width ? width : 80, height ? height : 32);
dp->resize.allow = 0; dp->resize.allow = 0;


/* Load a libcucul internal font */
fonts = cucul_get_font_list();
/* Load a libcaca internal font */
fonts = caca_get_font_list();
if(fonts[0] == NULL) if(fonts[0] == NULL)
{ {
fprintf(stderr, "error: libcucul was compiled without any fonts\n");
fprintf(stderr, "error: libcaca was compiled without any fonts\n");
return -1; return -1;
} }
dp->drv.p->f = cucul_load_font(fonts[0], 0);
dp->drv.p->f = caca_load_font(fonts[0], 0);
if(dp->drv.p->f == NULL) if(dp->drv.p->f == NULL)
{ {
fprintf(stderr, "error: could not load font \"%s\"\n", fonts[0]); fprintf(stderr, "error: could not load font \"%s\"\n", fonts[0]);
return -1; return -1;
} }


dp->drv.p->font_width = cucul_get_font_width(dp->drv.p->f);
dp->drv.p->font_height = cucul_get_font_height(dp->drv.p->f);
dp->drv.p->font_width = caca_get_font_width(dp->drv.p->f);
dp->drv.p->font_height = caca_get_font_height(dp->drv.p->f);


dp->drv.p->width = cucul_get_canvas_width(dp->cv) * dp->drv.p->font_width;
dp->drv.p->height = cucul_get_canvas_height(dp->cv) * dp->drv.p->font_height;
dp->drv.p->width = caca_get_canvas_width(dp->cv) * dp->drv.p->font_width;
dp->drv.p->height = caca_get_canvas_height(dp->cv) * dp->drv.p->font_height;


#ifdef HAVE_GLUTCLOSEFUNC #ifdef HAVE_GLUTCLOSEFUNC
dp->drv.p->close = 0; dp->drv.p->close = 0;
@@ -192,7 +191,7 @@ static int gl_end_graphics(caca_display_t *dp)
{ {
glutHideWindow(); glutHideWindow();
glutDestroyWindow(dp->drv.p->window); glutDestroyWindow(dp->drv.p->window);
cucul_free_font(dp->drv.p->f);
caca_free_font(dp->drv.p->f);
free(dp->drv.p->txid); free(dp->drv.p->txid);
free(dp->drv.p); free(dp->drv.p);
return 0; return 0;
@@ -216,9 +215,9 @@ static int gl_get_display_height(caca_display_t const *dp)


static void gl_display(caca_display_t *dp) static void gl_display(caca_display_t *dp)
{ {
uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv);
uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv);
int width = cucul_get_canvas_width(dp->cv);
uint32_t const *cvchars = (uint32_t const *)caca_get_canvas_chars(dp->cv);
uint32_t const *cvattrs = (uint32_t const *)caca_get_canvas_attrs(dp->cv);
int width = caca_get_canvas_width(dp->cv);
int x, y, line; int x, y, line;


glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
@@ -232,7 +231,7 @@ static void gl_display(caca_display_t *dp)
/* FIXME: optimise using stride */ /* FIXME: optimise using stride */
for(x = 0; x < dp->drv.p->width; x += dp->drv.p->font_width) for(x = 0; x < dp->drv.p->width; x += dp->drv.p->font_width)
{ {
uint16_t bg = cucul_attr_to_rgb12_bg(*attrs++);
uint16_t bg = caca_attr_to_rgb12_bg(*attrs++);


glColor4b(((bg & 0xf00) >> 8) * 8, glColor4b(((bg & 0xf00) >> 8) * 8,
((bg & 0x0f0) >> 4) * 8, ((bg & 0x0f0) >> 4) * 8,
@@ -266,7 +265,7 @@ static void gl_display(caca_display_t *dp)
uint16_t fg; uint16_t fg;
int i, b, fullwidth; int i, b, fullwidth;


fullwidth = cucul_utf32_is_fullwidth(ch);
fullwidth = caca_utf32_is_fullwidth(ch);


for(b = 0, i = 0; dp->drv.p->blocks[i + 1]; i += 2) for(b = 0, i = 0; dp->drv.p->blocks[i + 1]; i += 2)
{ {
@@ -284,7 +283,7 @@ static void gl_display(caca_display_t *dp)
dp->drv.p->txid[b + ch dp->drv.p->txid[b + ch
- (uint32_t)dp->drv.p->blocks[i]]); - (uint32_t)dp->drv.p->blocks[i]]);


fg = cucul_attr_to_rgb12_fg(*attrs);
fg = caca_attr_to_rgb12_fg(*attrs);
glColor3b(((fg & 0xf00) >> 8) * 8, glColor3b(((fg & 0xf00) >> 8) * 8,
((fg & 0x0f0) >> 4) * 8, ((fg & 0x0f0) >> 4) * 8,
(fg & 0x00f) * 8); (fg & 0x00f) * 8);
@@ -352,8 +351,8 @@ static int gl_get_event(caca_display_t *dp, caca_privevent_t *ev)
if(dp->resize.resized) if(dp->resize.resized)
{ {
ev->type = CACA_EVENT_RESIZE; ev->type = CACA_EVENT_RESIZE;
ev->data.resize.w = cucul_get_canvas_width(dp->cv);
ev->data.resize.h = cucul_get_canvas_height(dp->cv);
ev->data.resize.w = caca_get_canvas_width(dp->cv);
ev->data.resize.h = caca_get_canvas_height(dp->cv);
return 1; return 1;
} }


@@ -513,36 +512,36 @@ static void _display(void)


static void gl_compute_font(caca_display_t *dp) static void gl_compute_font(caca_display_t *dp)
{ {
cucul_canvas_t *cv;
caca_canvas_t *cv;
uint32_t *image; uint32_t *image;
int i, b, w, h, x, y; int i, b, w, h, x, y;


/* Count how many glyphs this font has */ /* Count how many glyphs this font has */
dp->drv.p->blocks = cucul_get_font_blocks(dp->drv.p->f);
dp->drv.p->blocks = caca_get_font_blocks(dp->drv.p->f);


for(b = 0, i = 0; dp->drv.p->blocks[i + 1]; i += 2) for(b = 0, i = 0; dp->drv.p->blocks[i + 1]; i += 2)
b += (int)(dp->drv.p->blocks[i + 1] - dp->drv.p->blocks[i]); b += (int)(dp->drv.p->blocks[i + 1] - dp->drv.p->blocks[i]);


/* Allocate a libcucul canvas and print all the glyphs on it */
cv = cucul_create_canvas(2, b);
cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLACK);
/* Allocate a libcaca canvas and print all the glyphs on it */
cv = caca_create_canvas(2, b);
caca_set_color_ansi(cv, CACA_WHITE, CACA_BLACK);


for(b = 0, i = 0; dp->drv.p->blocks[i + 1]; i += 2) for(b = 0, i = 0; dp->drv.p->blocks[i + 1]; i += 2)
{ {
int j, n = (int)(dp->drv.p->blocks[i + 1] - dp->drv.p->blocks[i]); int j, n = (int)(dp->drv.p->blocks[i + 1] - dp->drv.p->blocks[i]);


for(j = 0; j < n; j++) for(j = 0; j < n; j++)
cucul_put_char(cv, 0, b + j, dp->drv.p->blocks[i] + j);
caca_put_char(cv, 0, b + j, dp->drv.p->blocks[i] + j);


b += n; b += n;
} }


/* Draw the cucul canvas onto an image buffer */
/* Draw the caca canvas onto an image buffer */
image = malloc(b * dp->drv.p->font_height * image = malloc(b * dp->drv.p->font_height *
2 * dp->drv.p->font_width * sizeof(uint32_t)); 2 * dp->drv.p->font_width * sizeof(uint32_t));
cucul_render_canvas(cv, dp->drv.p->f, image, 2 * dp->drv.p->font_width,
caca_render_canvas(cv, dp->drv.p->f, image, 2 * dp->drv.p->font_width,
b * dp->drv.p->font_height, 8 * dp->drv.p->font_width); b * dp->drv.p->font_height, 8 * dp->drv.p->font_width);
cucul_free_canvas(cv);
caca_free_canvas(cv);


/* Convert all glyphs in the image buffer to GL textures */ /* Convert all glyphs in the image buffer to GL textures */
dp->drv.p->txid = malloc(b * sizeof(int)); dp->drv.p->txid = malloc(b * sizeof(int));
@@ -560,7 +559,7 @@ static void gl_compute_font(caca_display_t *dp)
uint32_t *glyph = image + (int)((b + j) * dp->drv.p->font_width * 2 uint32_t *glyph = image + (int)((b + j) * dp->drv.p->font_width * 2
* dp->drv.p->font_height); * dp->drv.p->font_height);
int fullwidth = int fullwidth =
cucul_utf32_is_fullwidth(dp->drv.p->blocks[i] + j);
caca_utf32_is_fullwidth(dp->drv.p->blocks[i] + j);


memset(tmp, 0, 16 * 8 * 16); memset(tmp, 0, 16 * 8 * 16);


+ 16
- 17
caca/driver_ncurses.c View File

@@ -50,7 +50,6 @@
# include <termios.h> # include <termios.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"
#include "caca_internals.h" #include "caca_internals.h"


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


dp->resize.allow = 1; dp->resize.allow = 1;
cucul_set_canvas_size(dp->cv, COLS, LINES);
caca_set_canvas_size(dp->cv, COLS, LINES);
dp->resize.allow = 0; dp->resize.allow = 0;


return 0; return 0;
@@ -335,21 +334,21 @@ static int ncurses_set_display_title(caca_display_t *dp, char const *title)
static int ncurses_get_display_width(caca_display_t const *dp) static int ncurses_get_display_width(caca_display_t const *dp)
{ {
/* Fallback to a 6x10 font */ /* Fallback to a 6x10 font */
return cucul_get_canvas_width(dp->cv) * 6;
return caca_get_canvas_width(dp->cv) * 6;
} }


static int ncurses_get_display_height(caca_display_t const *dp) static int ncurses_get_display_height(caca_display_t const *dp)
{ {
/* Fallback to a 6x10 font */ /* Fallback to a 6x10 font */
return cucul_get_canvas_height(dp->cv) * 10;
return caca_get_canvas_height(dp->cv) * 10;
} }


static void ncurses_display(caca_display_t *dp) static void ncurses_display(caca_display_t *dp)
{ {
uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv);
uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv);
int width = cucul_get_canvas_width(dp->cv);
int height = cucul_get_canvas_height(dp->cv);
uint32_t const *cvchars = (uint32_t const *)caca_get_canvas_chars(dp->cv);
uint32_t const *cvattrs = (uint32_t const *)caca_get_canvas_attrs(dp->cv);
int width = caca_get_canvas_width(dp->cv);
int height = caca_get_canvas_height(dp->cv);
int x, y; int x, y;


for(y = 0; y < (int)height; y++) for(y = 0; y < (int)height; y++)
@@ -357,13 +356,13 @@ static void ncurses_display(caca_display_t *dp)
move(y, 0); move(y, 0);
for(x = width; x--; ) for(x = width; x--; )
{ {
attrset(dp->drv.p->attr[cucul_attr_to_ansi(*cvattrs++)]);
attrset(dp->drv.p->attr[caca_attr_to_ansi(*cvattrs++)]);
ncurses_write_utf32(*cvchars++); ncurses_write_utf32(*cvchars++);
} }
} }
x = cucul_get_cursor_x(dp->cv);
y = cucul_get_cursor_y(dp->cv);
x = caca_get_cursor_x(dp->cv);
y = caca_get_cursor_y(dp->cv);
move(y, x); move(y, x);


refresh(); refresh();
@@ -389,8 +388,8 @@ static void ncurses_handle_resize(caca_display_t *dp)
#endif #endif


/* Fallback */ /* Fallback */
dp->resize.w = cucul_get_canvas_width(dp->cv);
dp->resize.h = cucul_get_canvas_height(dp->cv);
dp->resize.w = caca_get_canvas_width(dp->cv);
dp->resize.h = caca_get_canvas_height(dp->cv);
} }


static int ncurses_get_event(caca_display_t *dp, caca_privevent_t *ev) static int ncurses_get_event(caca_display_t *dp, caca_privevent_t *ev)
@@ -432,7 +431,7 @@ static int ncurses_get_event(caca_display_t *dp, caca_privevent_t *ev)
} }


utf8[i] = '\0'; utf8[i] = '\0';
utf32 = cucul_utf8_to_utf32(utf8, &bytes);
utf32 = caca_utf8_to_utf32(utf8, &bytes);


while(i > bytes) while(i > bytes)
ungetch(keys[--i]); ungetch(keys[--i]);
@@ -615,11 +614,11 @@ static void ncurses_write_utf32(uint32_t ch)
int bytes; int bytes;
#endif #endif


if(ch == CUCUL_MAGIC_FULLWIDTH)
if(ch == CACA_MAGIC_FULLWIDTH)
return; return;


#if defined HAVE_NCURSESW_NCURSES_H #if defined HAVE_NCURSESW_NCURSES_H
bytes = cucul_utf32_to_utf8(buf, ch);
bytes = caca_utf32_to_utf8(buf, ch);
buf[bytes] = '\0'; buf[bytes] = '\0';
addstr(buf); addstr(buf);
#else #else
@@ -814,7 +813,7 @@ static void ncurses_write_utf32(uint32_t ch)
break; break;
} }
addch(cch); addch(cch);
if(cucul_utf32_is_fullwidth(ch))
if(caca_utf32_is_fullwidth(ch))
{ {
addch(cch2); addch(cch2);
} }


+ 4
- 5
caca/driver_raw.c View File

@@ -23,14 +23,13 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>


#include "cucul.h"
#include "caca.h" #include "caca.h"
#include "caca_internals.h" #include "caca_internals.h"


static int raw_init_graphics(caca_display_t *dp) static int raw_init_graphics(caca_display_t *dp)
{ {
int width = cucul_get_canvas_width(dp->cv);
int height = cucul_get_canvas_height(dp->cv);
int width = caca_get_canvas_width(dp->cv);
int height = caca_get_canvas_height(dp->cv);
char const *geometry; char const *geometry;


#if defined(HAVE_GETENV) #if defined(HAVE_GETENV)
@@ -40,7 +39,7 @@ static int raw_init_graphics(caca_display_t *dp)
#endif #endif


dp->resize.allow = 1; dp->resize.allow = 1;
cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 24);
caca_set_canvas_size(dp->cv, width ? width : 80, height ? height : 24);
dp->resize.allow = 0; dp->resize.allow = 0;


return 0; return 0;
@@ -71,7 +70,7 @@ static void raw_display(caca_display_t *dp)
void *buffer; void *buffer;
size_t len; size_t len;


buffer = cucul_export_memory(dp->cv, "caca", &len);
buffer = caca_export_memory(dp->cv, "caca", &len);
if(!buffer) if(!buffer)
return; return;
fwrite(buffer, len, 1, stdout); fwrite(buffer, len, 1, stdout);


+ 27
- 28
caca/driver_slang.c View File

@@ -33,7 +33,6 @@
# include <signal.h> # include <signal.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"
#include "caca_internals.h" #include "caca_internals.h"


@@ -177,7 +176,7 @@ static int slang_init_graphics(caca_display_t *dp)
#endif #endif


dp->resize.allow = 1; dp->resize.allow = 1;
cucul_set_canvas_size(dp->cv, SLtt_Screen_Cols, SLtt_Screen_Rows);
caca_set_canvas_size(dp->cv, SLtt_Screen_Cols, SLtt_Screen_Rows);
dp->resize.allow = 0; dp->resize.allow = 0;


return 0; return 0;
@@ -210,21 +209,21 @@ static int slang_set_display_title(caca_display_t *dp, char const *title)
static int slang_get_display_width(caca_display_t const *dp) static int slang_get_display_width(caca_display_t const *dp)
{ {
/* Fallback to a 6x10 font */ /* Fallback to a 6x10 font */
return cucul_get_canvas_width(dp->cv) * 6;
return caca_get_canvas_width(dp->cv) * 6;
} }


static int slang_get_display_height(caca_display_t const *dp) static int slang_get_display_height(caca_display_t const *dp)
{ {
/* Fallback to a 6x10 font */ /* Fallback to a 6x10 font */
return cucul_get_canvas_height(dp->cv) * 10;
return caca_get_canvas_height(dp->cv) * 10;
} }


static void slang_display(caca_display_t *dp) static void slang_display(caca_display_t *dp)
{ {
uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv);
uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv);
int width = cucul_get_canvas_width(dp->cv);
int height = cucul_get_canvas_height(dp->cv);
uint32_t const *cvchars = (uint32_t const *)caca_get_canvas_chars(dp->cv);
uint32_t const *cvattrs = (uint32_t const *)caca_get_canvas_attrs(dp->cv);
int width = caca_get_canvas_width(dp->cv);
int height = caca_get_canvas_height(dp->cv);
int x, y; int x, y;


for(y = 0; y < (int)height; y++) for(y = 0; y < (int)height; y++)
@@ -241,24 +240,24 @@ static void slang_display(caca_display_t *dp)
* here for, and in cases where SLang does not render * here for, and in cases where SLang does not render
* bright backgrounds, it's just fucked up. */ * bright backgrounds, it's just fucked up. */
#if 0 #if 0
uint8_t fgcolor = cucul_attr_to_ansi_fg(*cvattrs);
uint8_t bgcolor = cucul_attr_to_ansi_bg(*cvattrs);
uint8_t fgcolor = caca_attr_to_ansi_fg(*cvattrs);
uint8_t bgcolor = caca_attr_to_ansi_bg(*cvattrs);


if(fgcolor >= 0x10) if(fgcolor >= 0x10)
fgcolor = CUCUL_LIGHTGRAY;
fgcolor = CACA_LIGHTGRAY;


if(bgcolor >= 0x10) if(bgcolor >= 0x10)
bgcolor = CUCUL_BLACK; /* FIXME: handle transparency */
bgcolor = CACA_BLACK; /* FIXME: handle transparency */


if(fgcolor == bgcolor) if(fgcolor == bgcolor)
{ {
if(fgcolor == CUCUL_BLACK)
fgcolor = CUCUL_WHITE;
else if(fgcolor == CUCUL_WHITE
|| fgcolor <= CUCUL_LIGHTGRAY)
fgcolor = CUCUL_BLACK;
if(fgcolor == CACA_BLACK)
fgcolor = CACA_WHITE;
else if(fgcolor == CACA_WHITE
|| fgcolor <= CACA_LIGHTGRAY)
fgcolor = CACA_BLACK;
else else
fgcolor = CUCUL_WHITE;
fgcolor = CACA_WHITE;
SLsmg_set_color(slang_assoc[fgcolor + 16 * bgcolor]); SLsmg_set_color(slang_assoc[fgcolor + 16 * bgcolor]);
SLsmg_write_char(' '); SLsmg_write_char(' ');
cvattrs++; cvattrs++;
@@ -266,16 +265,16 @@ static void slang_display(caca_display_t *dp)
else else
#endif #endif
{ {
SLsmg_set_color(slang_assoc[cucul_attr_to_ansi(*cvattrs++)]);
SLsmg_set_color(slang_assoc[caca_attr_to_ansi(*cvattrs++)]);
slang_write_utf32(ch); slang_write_utf32(ch);
} }
#else #else
SLsmg_set_color(cucul_attr_to_ansi(*cvattrs++));
SLsmg_set_color(caca_attr_to_ansi(*cvattrs++));
slang_write_utf32(ch); slang_write_utf32(ch);
#endif #endif
} }
} }
SLsmg_gotorc(cucul_get_cursor_y(dp->cv), cucul_get_cursor_x(dp->cv));
SLsmg_gotorc(caca_get_cursor_y(dp->cv), caca_get_cursor_x(dp->cv));
SLsmg_refresh(); SLsmg_refresh();
} }


@@ -285,8 +284,8 @@ static void slang_handle_resize(caca_display_t *dp)
dp->resize.w = SLtt_Screen_Cols; dp->resize.w = SLtt_Screen_Cols;
dp->resize.h = SLtt_Screen_Rows; dp->resize.h = SLtt_Screen_Rows;


if(dp->resize.w != cucul_get_canvas_width(dp->cv)
|| dp->resize.h != cucul_get_canvas_height(dp->cv))
if(dp->resize.w != caca_get_canvas_width(dp->cv)
|| dp->resize.h != caca_get_canvas_height(dp->cv))
SLsmg_reinit_smg(); SLsmg_reinit_smg();
} }


@@ -342,7 +341,7 @@ static int slang_get_event(caca_display_t *dp, caca_privevent_t *ev)
} }


utf8[i] = '\0'; utf8[i] = '\0';
utf32 = cucul_utf8_to_utf32(utf8, &bytes);
utf32 = caca_utf8_to_utf32(utf8, &bytes);


while(i > bytes) while(i > bytes)
SLang_ungetkey(keys[--i]); SLang_ungetkey(keys[--i]);
@@ -482,17 +481,17 @@ static void slang_write_utf32(uint32_t ch)
char ascii; char ascii;
#endif #endif


if(ch == CUCUL_MAGIC_FULLWIDTH)
if(ch == CACA_MAGIC_FULLWIDTH)
return; return;


#ifdef HAVE_SLSMG_UTF8_ENABLE #ifdef HAVE_SLSMG_UTF8_ENABLE
bytes = cucul_utf32_to_utf8(buf, ch);
bytes = caca_utf32_to_utf8(buf, ch);
buf[bytes] = '\0'; buf[bytes] = '\0';
SLsmg_write_string(buf); SLsmg_write_string(buf);
#else #else
ascii = cucul_utf32_to_ascii(ch);
ascii = caca_utf32_to_ascii(ch);
SLsmg_write_char(ascii); SLsmg_write_char(ascii);
if(cucul_utf32_is_fullwidth(ch))
if(caca_utf32_is_fullwidth(ch))
SLsmg_write_char(ascii); SLsmg_write_char(ascii);
#endif #endif
} }


+ 11
- 12
caca/driver_vga.c View File

@@ -20,7 +20,6 @@


#if defined(USE_VGA) #if defined(USE_VGA)


#include "cucul.h"
#include "caca.h" #include "caca.h"
#include "caca_internals.h" #include "caca_internals.h"


@@ -75,7 +74,7 @@ static int vga_init_graphics(caca_display_t *dp)


/* We don't have much choice */ /* We don't have much choice */
dp->resize.allow = 1; dp->resize.allow = 1;
cucul_set_canvas_size(dp->cv, 80, 25);
caca_set_canvas_size(dp->cv, 80, 25);
dp->resize.allow = 0; dp->resize.allow = 0;


return 0; return 0;
@@ -116,33 +115,33 @@ static int vga_get_display_height(caca_display_t const *dp)
static void vga_display(caca_display_t *dp) static void vga_display(caca_display_t *dp)
{ {
char *screen = (char *)(intptr_t)0x000b8000; char *screen = (char *)(intptr_t)0x000b8000;
uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv);
uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv);
int width = cucul_get_canvas_width(dp->cv);
int height = cucul_get_canvas_height(dp->cv);
uint32_t const *cvchars = (uint32_t const *)caca_get_canvas_chars(dp->cv);
uint32_t const *cvattrs = (uint32_t const *)caca_get_canvas_attrs(dp->cv);
int width = caca_get_canvas_width(dp->cv);
int height = caca_get_canvas_height(dp->cv);
int n; int n;


for(n = height * width; n--; ) for(n = height * width; n--; )
{ {
char ch = cucul_utf32_to_cp437(*cvchars++);
if(n && *cvchars == CUCUL_MAGIC_FULLWIDTH)
char ch = caca_utf32_to_cp437(*cvchars++);
if(n && *cvchars == CACA_MAGIC_FULLWIDTH)
{ {
*screen++ = '['; *screen++ = '[';
*screen++ = cucul_attr_to_ansi(*cvattrs++);
*screen++ = caca_attr_to_ansi(*cvattrs++);
ch = ']'; ch = ']';
cvchars++; cvchars++;
n--; n--;
} }
*screen++ = ch; *screen++ = ch;
*screen++ = cucul_attr_to_ansi(*cvattrs++);
*screen++ = caca_attr_to_ansi(*cvattrs++);
} }
} }


static void vga_handle_resize(caca_display_t *dp) static void vga_handle_resize(caca_display_t *dp)
{ {
/* We know nothing about our window */ /* We know nothing about our window */
dp->resize.w = cucul_get_canvas_width(dp->cv);
dp->resize.h = cucul_get_canvas_height(dp->cv);
dp->resize.w = caca_get_canvas_width(dp->cv);
dp->resize.h = caca_get_canvas_height(dp->cv);
} }


static int vga_get_event(caca_display_t *dp, caca_privevent_t *ev) static int vga_get_event(caca_display_t *dp, caca_privevent_t *ev)


+ 19
- 20
caca/driver_win32.c View File

@@ -25,7 +25,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>


#include "cucul.h"
#include "caca.h" #include "caca.h"
#include "caca_internals.h" #include "caca_internals.h"


@@ -82,8 +81,8 @@ struct driver_private


static int win32_init_graphics(caca_display_t *dp) static int win32_init_graphics(caca_display_t *dp)
{ {
int width = cucul_get_canvas_width(dp->cv);
int height = cucul_get_canvas_height(dp->cv);
int width = caca_get_canvas_width(dp->cv);
int height = caca_get_canvas_height(dp->cv);
CONSOLE_SCREEN_BUFFER_INFO csbi; CONSOLE_SCREEN_BUFFER_INFO csbi;
SMALL_RECT rect; SMALL_RECT rect;
COORD size; COORD size;
@@ -122,16 +121,16 @@ static int win32_init_graphics(caca_display_t *dp)
rect.Bottom = size.Y - 1; rect.Bottom = size.Y - 1;
SetConsoleWindowInfo(dp->drv.p->screen, TRUE, &rect); SetConsoleWindowInfo(dp->drv.p->screen, TRUE, &rect);


/* Report our new size to libcucul */
/* Report our new size to libcaca */
if(!GetConsoleScreenBufferInfo(dp->drv.p->screen, &csbi)) if(!GetConsoleScreenBufferInfo(dp->drv.p->screen, &csbi))
return -1; return -1;


dp->resize.allow = 1; dp->resize.allow = 1;
cucul_set_canvas_size(dp->cv,
caca_set_canvas_size(dp->cv,
csbi.srWindow.Right - csbi.srWindow.Left + 1, csbi.srWindow.Right - csbi.srWindow.Left + 1,
csbi.srWindow.Bottom - csbi.srWindow.Top + 1); csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
width = cucul_get_canvas_width(dp->cv);
height = cucul_get_canvas_height(dp->cv);
width = caca_get_canvas_width(dp->cv);
height = caca_get_canvas_height(dp->cv);
dp->resize.allow = 0; dp->resize.allow = 0;


SetConsoleMode(dp->drv.p->screen, 0); SetConsoleMode(dp->drv.p->screen, 0);
@@ -180,7 +179,7 @@ static int win32_get_display_width(caca_display_t const *dp)
/* FIXME */ /* FIXME */


/* Fallback to a 6x10 font */ /* Fallback to a 6x10 font */
return cucul_get_canvas_width(dp->cv) * 6;
return caca_get_canvas_width(dp->cv) * 6;
} }


static int win32_get_display_height(caca_display_t const *dp) static int win32_get_display_height(caca_display_t const *dp)
@@ -188,7 +187,7 @@ static int win32_get_display_height(caca_display_t const *dp)
/* FIXME */ /* FIXME */


/* Fallback to a 6x10 font */ /* Fallback to a 6x10 font */
return cucul_get_canvas_height(dp->cv) * 10;
return caca_get_canvas_height(dp->cv) * 10;
} }


static void win32_display(caca_display_t *dp) static void win32_display(caca_display_t *dp)
@@ -196,18 +195,18 @@ static void win32_display(caca_display_t *dp)
COORD size, pos; COORD size, pos;
SMALL_RECT rect; SMALL_RECT rect;
CHAR_INFO *buffer = dp->drv.p->buffer; CHAR_INFO *buffer = dp->drv.p->buffer;
uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv);
uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv);
int width = cucul_get_canvas_width(dp->cv);
int height = cucul_get_canvas_height(dp->cv);
uint32_t const *cvchars = (uint32_t const *)caca_get_canvas_chars(dp->cv);
uint32_t const *cvattrs = (uint32_t const *)caca_get_canvas_attrs(dp->cv);
int width = caca_get_canvas_width(dp->cv);
int height = caca_get_canvas_height(dp->cv);
int n; int n;


/* Render everything to our screen buffer */ /* Render everything to our screen buffer */
for(n = height * width; n--; ) for(n = height * width; n--; )
{ {
uint32_t ch = *cvchars++; uint32_t ch = *cvchars++;
uint8_t fg = cucul_attr_to_ansi_fg(*cvattrs);
uint8_t bg = cucul_attr_to_ansi_bg(*cvattrs);
uint8_t fg = caca_attr_to_ansi_fg(*cvattrs);
uint8_t bg = caca_attr_to_ansi_bg(*cvattrs);


#if 0 #if 0
if(ch > 0x00000020 && ch < 0x00000080) if(ch > 0x00000020 && ch < 0x00000080)
@@ -215,7 +214,7 @@ static void win32_display(caca_display_t *dp)
else else
dp->drv.p->buffer[i].Char.AsciiChar = ' '; dp->drv.p->buffer[i].Char.AsciiChar = ' ';
#else #else
if(n && *cvchars == CUCUL_MAGIC_FULLWIDTH)
if(n && *cvchars == CACA_MAGIC_FULLWIDTH)
; ;
else if(ch > 0x00000020 && ch < 0x00010000) else if(ch > 0x00000020 && ch < 0x00010000)
buffer->Char.UnicodeChar = (uint16_t)ch; buffer->Char.UnicodeChar = (uint16_t)ch;
@@ -223,8 +222,8 @@ static void win32_display(caca_display_t *dp)
buffer->Char.UnicodeChar = (uint16_t)' '; buffer->Char.UnicodeChar = (uint16_t)' ';
#endif #endif


buffer->Attributes = win32_fg_palette[fg < 0x10 ? fg : CUCUL_LIGHTGRAY]
| win32_bg_palette[bg < 0x10 ? bg : CUCUL_BLACK];
buffer->Attributes = win32_fg_palette[fg < 0x10 ? fg : CACA_LIGHTGRAY]
| win32_bg_palette[bg < 0x10 ? bg : CACA_BLACK];
cvattrs++; cvattrs++;
buffer++; buffer++;
} }
@@ -246,8 +245,8 @@ static void win32_display(caca_display_t *dp)
static void win32_handle_resize(caca_display_t *dp) static void win32_handle_resize(caca_display_t *dp)
{ {
/* FIXME: I don't know what to do here. */ /* FIXME: I don't know what to do here. */
dp->resize.w = cucul_get_canvas_width(dp->cv);
dp->resize.h = cucul_get_canvas_height(dp->cv);
dp->resize.w = caca_get_canvas_width(dp->cv);
dp->resize.h = caca_get_canvas_height(dp->cv);
} }


static int win32_get_event(caca_display_t *dp, caca_privevent_t *ev) static int win32_get_event(caca_display_t *dp, caca_privevent_t *ev)


+ 24
- 24
caca/driver_x11.c View File

@@ -32,7 +32,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>


#include "cucul.h"
#include "caca.h"
#include "caca.h" #include "caca.h"
#include "caca_internals.h" #include "caca_internals.h"


@@ -75,8 +75,8 @@ static int x11_init_graphics(caca_display_t *dp)
int (*old_error_handler)(Display *, XErrorEvent *); int (*old_error_handler)(Display *, XErrorEvent *);
char const *fonts[] = { NULL, "8x13bold", "fixed" }, **parser; char const *fonts[] = { NULL, "8x13bold", "fixed" }, **parser;
char const *geometry; char const *geometry;
int width = cucul_get_canvas_width(dp->cv);
int height = cucul_get_canvas_height(dp->cv);
int width = caca_get_canvas_width(dp->cv);
int height = caca_get_canvas_height(dp->cv);
int i; int i;


dp->drv.p = malloc(sizeof(struct driver_private)); dp->drv.p = malloc(sizeof(struct driver_private));
@@ -88,9 +88,9 @@ static int x11_init_graphics(caca_display_t *dp)
#endif #endif


dp->resize.allow = 1; dp->resize.allow = 1;
cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 32);
width = cucul_get_canvas_width(dp->cv);
height = cucul_get_canvas_height(dp->cv);
caca_set_canvas_size(dp->cv, width ? width : 80, height ? height : 32);
width = caca_get_canvas_width(dp->cv);
height = caca_get_canvas_height(dp->cv);
dp->resize.allow = 0; dp->resize.allow = 0;


dp->drv.p->dpy = XOpenDisplay(NULL); dp->drv.p->dpy = XOpenDisplay(NULL);
@@ -279,20 +279,20 @@ static int x11_set_display_title(caca_display_t *dp, char const *title)


static int x11_get_display_width(caca_display_t const *dp) static int x11_get_display_width(caca_display_t const *dp)
{ {
return cucul_get_canvas_width(dp->cv) * dp->drv.p->font_width;
return caca_get_canvas_width(dp->cv) * dp->drv.p->font_width;
} }


static int x11_get_display_height(caca_display_t const *dp) static int x11_get_display_height(caca_display_t const *dp)
{ {
return cucul_get_canvas_height(dp->cv) * dp->drv.p->font_height;
return caca_get_canvas_height(dp->cv) * dp->drv.p->font_height;
} }


static void x11_display(caca_display_t *dp) static void x11_display(caca_display_t *dp)
{ {
uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv);
uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv);
int width = cucul_get_canvas_width(dp->cv);
int height = cucul_get_canvas_height(dp->cv);
uint32_t const *cvchars = (uint32_t const *)caca_get_canvas_chars(dp->cv);
uint32_t const *cvattrs = (uint32_t const *)caca_get_canvas_attrs(dp->cv);
int width = caca_get_canvas_width(dp->cv);
int height = caca_get_canvas_height(dp->cv);
int x, y, len; int x, y, len;


/* First draw the background colours. Splitting the process in two /* First draw the background colours. Splitting the process in two
@@ -302,11 +302,11 @@ static void x11_display(caca_display_t *dp)
for(x = 0; x < width; x += len) for(x = 0; x < width; x += len)
{ {
uint32_t const *attrs = cvattrs + x + y * width; uint32_t const *attrs = cvattrs + x + y * width;
uint16_t bg = cucul_attr_to_rgb12_bg(*attrs);
uint16_t bg = caca_attr_to_rgb12_bg(*attrs);


len = 1; len = 1;
while(x + len < width while(x + len < width
&& cucul_attr_to_rgb12_bg(attrs[len]) == bg)
&& caca_attr_to_rgb12_bg(attrs[len]) == bg)
len++; len++;


XSetForeground(dp->drv.p->dpy, dp->drv.p->gc, XSetForeground(dp->drv.p->dpy, dp->drv.p->gc,
@@ -330,7 +330,7 @@ static void x11_display(caca_display_t *dp)
for(x = 0; x < width; x++, chars++, attrs++) for(x = 0; x < width; x++, chars++, attrs++)
{ {
XSetForeground(dp->drv.p->dpy, dp->drv.p->gc, XSetForeground(dp->drv.p->dpy, dp->drv.p->gc,
dp->drv.p->colors[cucul_attr_to_rgb12_fg(*attrs)]);
dp->drv.p->colors[caca_attr_to_rgb12_fg(*attrs)]);


x11_put_glyph(dp, x * dp->drv.p->font_width, x11_put_glyph(dp, x * dp->drv.p->font_width,
y * dp->drv.p->font_height, yoff, y * dp->drv.p->font_height, yoff,
@@ -344,8 +344,8 @@ static void x11_display(caca_display_t *dp)
{ {
XSetForeground(dp->drv.p->dpy, dp->drv.p->gc, XSetForeground(dp->drv.p->dpy, dp->drv.p->gc,
dp->drv.p->colors[0xfff]); dp->drv.p->colors[0xfff]);
x = cucul_get_cursor_x(dp->cv);
y = cucul_get_cursor_y(dp->cv);
x = caca_get_cursor_x(dp->cv);
y = caca_get_cursor_y(dp->cv);
XFillRectangle(dp->drv.p->dpy, dp->drv.p->pixmap, dp->drv.p->gc, XFillRectangle(dp->drv.p->dpy, dp->drv.p->pixmap, dp->drv.p->gc,
x * dp->drv.p->font_width, y * dp->drv.p->font_height, x * dp->drv.p->font_width, y * dp->drv.p->font_height,
dp->drv.p->font_width, dp->drv.p->font_height); dp->drv.p->font_width, dp->drv.p->font_height);
@@ -378,8 +378,8 @@ static void x11_handle_resize(caca_display_t *dp)


static int x11_get_event(caca_display_t *dp, caca_privevent_t *ev) static int x11_get_event(caca_display_t *dp, caca_privevent_t *ev)
{ {
int width = cucul_get_canvas_width(dp->cv);
int height = cucul_get_canvas_height(dp->cv);
int width = caca_get_canvas_width(dp->cv);
int height = caca_get_canvas_height(dp->cv);
XEvent xevent; XEvent xevent;
char key; char key;


@@ -610,23 +610,23 @@ static void x11_put_glyph(caca_display_t *dp, int x, int y, int yoff,
XChar2b ch16; XChar2b ch16;


/* Underline */ /* Underline */
if(attr & CUCUL_UNDERLINE)
if(attr & CACA_UNDERLINE)
XFillRectangle(dpy, px, gc, x, y + h - 1, w, 1); XFillRectangle(dpy, px, gc, x, y + h - 1, w, 1);


/* Skip spaces and magic stuff */ /* Skip spaces and magic stuff */
if(ch <= 0x00000020) if(ch <= 0x00000020)
return; return;


if(ch == CUCUL_MAGIC_FULLWIDTH)
if(ch == CACA_MAGIC_FULLWIDTH)
return; return;


fw = w; fw = w;
if(cucul_utf32_is_fullwidth(ch))
if(caca_utf32_is_fullwidth(ch))
fw *= 2; fw *= 2;


/* We want to be able to print a few special Unicode characters /* We want to be able to print a few special Unicode characters
* such as the CP437 gradients and half blocks. For unknown * such as the CP437 gradients and half blocks. For unknown
* characters, print what cucul_utf32_to_ascii() returns. */
* characters, print what caca_utf32_to_ascii() returns. */


if(ch >= 0x2500 && ch <= 0x256c && udlr[ch - 0x2500]) if(ch >= 0x2500 && ch <= 0x256c && udlr[ch - 0x2500])
{ {
@@ -771,7 +771,7 @@ static void x11_put_glyph(caca_display_t *dp, int x, int y, int yoff,
else else
{ {
ch16.byte1 = 0; ch16.byte1 = 0;
ch16.byte2 = cucul_utf32_to_ascii(ch);
ch16.byte2 = caca_utf32_to_ascii(ch);
} }


XDrawString16(dpy, px, gc, x + (ch16.byte1 ? 0 : (fw - w) / 2), yoff, &ch16, 1); XDrawString16(dpy, px, gc, x + (ch16.byte1 ? 0 : (fw - w) / 2), yoff, &ch16, 1);


+ 4
- 5
caca/event.c View File

@@ -23,7 +23,6 @@
# include <string.h> # include <string.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"
#include "caca_internals.h" #include "caca_internals.h"


@@ -129,7 +128,7 @@ int caca_get_event(caca_display_t *dp, int event_mask,
*/ */
int caca_get_mouse_x(caca_display_t const *dp) int caca_get_mouse_x(caca_display_t const *dp)
{ {
int width = cucul_get_canvas_width(dp->cv);
int width = caca_get_canvas_width(dp->cv);


if(dp->mouse.x >= width) if(dp->mouse.x >= width)
return width - 1; return width - 1;
@@ -151,7 +150,7 @@ int caca_get_mouse_x(caca_display_t const *dp)
*/ */
int caca_get_mouse_y(caca_display_t const *dp) int caca_get_mouse_y(caca_display_t const *dp)
{ {
int height = cucul_get_canvas_height(dp->cv);
int height = caca_get_canvas_height(dp->cv);


if(dp->mouse.y >= height) if(dp->mouse.y >= height)
return height - 1; return height - 1;
@@ -335,8 +334,8 @@ static int _get_next_event(caca_display_t *dp, caca_privevent_t *ev)
dp->resize.resized = 0; dp->resize.resized = 0;
_caca_handle_resize(dp); _caca_handle_resize(dp);
ev->type = CACA_EVENT_RESIZE; ev->type = CACA_EVENT_RESIZE;
ev->data.resize.w = cucul_get_canvas_width(dp->cv);
ev->data.resize.h = cucul_get_canvas_height(dp->cv);
ev->data.resize.w = caca_get_canvas_width(dp->cv);
ev->data.resize.h = caca_get_canvas_height(dp->cv);
return 1; return 1;
} }




cucul/export.c → caca/export.c View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Canvas for ultrafast compositing of Unicode letters
* libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* 2006 Jean-Yves Lamoureux <jylam@lnxscene.org> * 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
* All Rights Reserved * All Rights Reserved
@@ -25,8 +25,8 @@
# include <string.h> # include <string.h>
#endif #endif


#include "cucul.h"
#include "cucul_internals.h"
#include "caca.h"
#include "caca_internals.h"


static inline int sprintu32(char *s, uint32_t x) static inline int sprintu32(char *s, uint32_t x)
{ {
@@ -44,20 +44,20 @@ static inline int sprintu16(char *s, uint16_t x)
return 2; return 2;
} }


static void *export_caca(cucul_canvas_t const *, size_t *);
static void *export_ansi(cucul_canvas_t const *, size_t *);
static void *export_utf8(cucul_canvas_t const *, size_t *, int);
static void *export_html(cucul_canvas_t const *, size_t *);
static void *export_html3(cucul_canvas_t const *, size_t *);
static void *export_bbfr(cucul_canvas_t const *, size_t *);
static void *export_irc(cucul_canvas_t const *, size_t *);
static void *export_ps(cucul_canvas_t const *, size_t *);
static void *export_svg(cucul_canvas_t const *, size_t *);
static void *export_tga(cucul_canvas_t const *, size_t *);
static void *export_caca(caca_canvas_t const *, size_t *);
static void *export_ansi(caca_canvas_t const *, size_t *);
static void *export_utf8(caca_canvas_t const *, size_t *, int);
static void *export_html(caca_canvas_t const *, size_t *);
static void *export_html3(caca_canvas_t const *, size_t *);
static void *export_bbfr(caca_canvas_t const *, size_t *);
static void *export_irc(caca_canvas_t const *, size_t *);
static void *export_ps(caca_canvas_t const *, size_t *);
static void *export_svg(caca_canvas_t const *, size_t *);
static void *export_tga(caca_canvas_t const *, size_t *);


/** \brief Export a canvas into a foreign format. /** \brief Export a canvas into a foreign format.
* *
* This function exports a libcucul canvas into various foreign formats such
* This function exports a libcaca canvas into various foreign formats such
* as ANSI art, HTML, IRC colours, etc. The returned pointer should be passed * as ANSI art, HTML, IRC colours, etc. The returned pointer should be passed
* to free() to release the allocated storage when it is no longer needed. * to free() to release the allocated storage when it is no longer needed.
* *
@@ -76,13 +76,13 @@ static void *export_tga(cucul_canvas_t const *, size_t *);
* - \c EINVAL Unsupported format requested. * - \c EINVAL Unsupported format requested.
* - \c ENOMEM Not enough memory to allocate output buffer. * - \c ENOMEM Not enough memory to allocate output buffer.
* *
* \param cv A libcucul canvas
* \param cv A libcaca canvas
* \param format A string describing the requested output format. * \param format A string describing the requested output format.
* \param bytes A pointer to a size_t where the number of allocated bytes * \param bytes A pointer to a size_t where the number of allocated bytes
* will be written. * will be written.
* \return A pointer to the exported memory area, or NULL in case of error. * \return A pointer to the exported memory area, or NULL in case of error.
*/ */
void *cucul_export_memory(cucul_canvas_t const *cv, char const *format,
void *caca_export_memory(caca_canvas_t const *cv, char const *format,
size_t *bytes) size_t *bytes)
{ {
if(!strcasecmp("caca", format)) if(!strcasecmp("caca", format))
@@ -126,14 +126,14 @@ void *cucul_export_memory(cucul_canvas_t const *cv, char const *format,
* *
* Return a list of available export formats. The list is a NULL-terminated * Return a list of available export formats. The list is a NULL-terminated
* array of strings, interleaving a string containing the internal value for * array of strings, interleaving a string containing the internal value for
* the export format, to be used with cucul_export_memory(), and a string
* the export format, to be used with caca_export_memory(), and a string
* containing the natural language description for that export format. * containing the natural language description for that export format.
* *
* This function never fails. * This function never fails.
* *
* \return An array of strings. * \return An array of strings.
*/ */
char const * const * cucul_get_export_list(void)
char const * const * caca_get_export_list(void)
{ {
static char const * const list[] = static char const * const list[] =
{ {
@@ -159,7 +159,7 @@ char const * const * cucul_get_export_list(void)
*/ */


/* Generate a native libcaca canvas file. */ /* Generate a native libcaca canvas file. */
static void *export_caca(cucul_canvas_t const *cv, size_t *bytes)
static void *export_caca(caca_canvas_t const *cv, size_t *bytes)
{ {
char *data, *cur; char *data, *cur;
int f, n; int f, n;
@@ -212,7 +212,7 @@ static void *export_caca(cucul_canvas_t const *cv, size_t *bytes)
} }


/* Generate UTF-8 representation of current canvas. */ /* Generate UTF-8 representation of current canvas. */
static void *export_utf8(cucul_canvas_t const *cv, size_t *bytes,
static void *export_utf8(caca_canvas_t const *cv, size_t *bytes,
int cr) int cr)
{ {
static uint8_t const palette[] = static uint8_t const palette[] =
@@ -244,11 +244,11 @@ static void *export_utf8(cucul_canvas_t const *cv, size_t *bytes,
uint32_t ch = linechar[x]; uint32_t ch = linechar[x];
uint8_t ansifg, ansibg, fg, bg; uint8_t ansifg, ansibg, fg, bg;


if(ch == CUCUL_MAGIC_FULLWIDTH)
if(ch == CACA_MAGIC_FULLWIDTH)
continue; continue;


ansifg = cucul_attr_to_ansi_fg(attr);
ansibg = cucul_attr_to_ansi_bg(attr);
ansifg = caca_attr_to_ansi_fg(attr);
ansibg = caca_attr_to_ansi_bg(attr);


fg = ansifg < 0x10 ? palette[ansifg] : 0x10; fg = ansifg < 0x10 ? palette[ansifg] : 0x10;
bg = ansibg < 0x10 ? palette[ansibg] : 0x10; bg = ansibg < 0x10 ? palette[ansibg] : 0x10;
@@ -271,7 +271,7 @@ static void *export_utf8(cucul_canvas_t const *cv, size_t *bytes,
cur += sprintf(cur, "m"); cur += sprintf(cur, "m");
} }


cur += cucul_utf32_to_utf8(cur, ch);
cur += caca_utf32_to_utf8(cur, ch);


prevfg = fg; prevfg = fg;
prevbg = bg; prevbg = bg;
@@ -293,7 +293,7 @@ static void *export_utf8(cucul_canvas_t const *cv, size_t *bytes,
} }


/* Generate ANSI representation of current canvas. */ /* Generate ANSI representation of current canvas. */
static void *export_ansi(cucul_canvas_t const *cv, size_t *bytes)
static void *export_ansi(caca_canvas_t const *cv, size_t *bytes)
{ {
static uint8_t const palette[] = static uint8_t const palette[] =
{ {
@@ -320,13 +320,13 @@ static void *export_ansi(cucul_canvas_t const *cv, size_t *bytes)


for(x = 0; x < cv->width; x++) for(x = 0; x < cv->width; x++)
{ {
uint8_t ansifg = cucul_attr_to_ansi_fg(lineattr[x]);
uint8_t ansibg = cucul_attr_to_ansi_bg(lineattr[x]);
uint8_t fg = ansifg < 0x10 ? palette[ansifg] : CUCUL_LIGHTGRAY;
uint8_t bg = ansibg < 0x10 ? palette[ansibg] : CUCUL_BLACK;
uint8_t ansifg = caca_attr_to_ansi_fg(lineattr[x]);
uint8_t ansibg = caca_attr_to_ansi_bg(lineattr[x]);
uint8_t fg = ansifg < 0x10 ? palette[ansifg] : CACA_LIGHTGRAY;
uint8_t bg = ansibg < 0x10 ? palette[ansibg] : CACA_BLACK;
uint32_t ch = linechar[x]; uint32_t ch = linechar[x];


if(ch == CUCUL_MAGIC_FULLWIDTH)
if(ch == CACA_MAGIC_FULLWIDTH)
ch = '?'; ch = '?';


if(fg != prevfg || bg != prevbg) if(fg != prevfg || bg != prevbg)
@@ -345,7 +345,7 @@ static void *export_ansi(cucul_canvas_t const *cv, size_t *bytes)
cur += sprintf(cur, "5;1;3%d;4%dm", fg - 8, bg - 8); cur += sprintf(cur, "5;1;3%d;4%dm", fg - 8, bg - 8);
} }


*cur++ = cucul_utf32_to_cp437(ch);
*cur++ = caca_utf32_to_cp437(ch);


prevfg = fg; prevfg = fg;
prevbg = bg; prevbg = bg;
@@ -373,7 +373,7 @@ static void *export_ansi(cucul_canvas_t const *cv, size_t *bytes)
} }


/* Generate HTML representation of current canvas. */ /* Generate HTML representation of current canvas. */
static void *export_html(cucul_canvas_t const *cv, size_t *bytes)
static void *export_html(caca_canvas_t const *cv, size_t *bytes)
{ {
char *data, *cur; char *data, *cur;
int x, y, len; int x, y, len;
@@ -390,7 +390,7 @@ static void *export_html(cucul_canvas_t const *cv, size_t *bytes)
/* HTML header */ /* HTML header */
cur += sprintf(cur, "<html><head>\n"); cur += sprintf(cur, "<html><head>\n");
cur += sprintf(cur, "<title>Generated by libcaca %s</title>\n", cur += sprintf(cur, "<title>Generated by libcaca %s</title>\n",
cucul_get_version());
caca_get_version());
cur += sprintf(cur, "</head><body>\n"); cur += sprintf(cur, "</head><body>\n");


cur += sprintf(cur, "<div cellpadding='0' cellspacing='0' style='%s'>\n", cur += sprintf(cur, "<div cellpadding='0' cellspacing='0' style='%s'>\n",
@@ -404,19 +404,19 @@ static void *export_html(cucul_canvas_t const *cv, size_t *bytes)
for(x = 0; x < cv->width; x += len) for(x = 0; x < cv->width; x += len)
{ {
cur += sprintf(cur, "<span style=\""); cur += sprintf(cur, "<span style=\"");
if(cucul_attr_to_ansi_fg(lineattr[x]) < 0x10)
if(caca_attr_to_ansi_fg(lineattr[x]) < 0x10)
cur += sprintf(cur, ";color:#%.03x", cur += sprintf(cur, ";color:#%.03x",
cucul_attr_to_rgb12_fg(lineattr[x]));
if(cucul_attr_to_ansi_bg(lineattr[x]) < 0x10)
caca_attr_to_rgb12_fg(lineattr[x]));
if(caca_attr_to_ansi_bg(lineattr[x]) < 0x10)
cur += sprintf(cur, ";background-color:#%.03x", cur += sprintf(cur, ";background-color:#%.03x",
cucul_attr_to_rgb12_bg(lineattr[x]));
if(lineattr[x] & CUCUL_BOLD)
caca_attr_to_rgb12_bg(lineattr[x]));
if(lineattr[x] & CACA_BOLD)
cur += sprintf(cur, ";font-weight:bold"); cur += sprintf(cur, ";font-weight:bold");
if(lineattr[x] & CUCUL_ITALICS)
if(lineattr[x] & CACA_ITALICS)
cur += sprintf(cur, ";font-style:italic"); cur += sprintf(cur, ";font-style:italic");
if(lineattr[x] & CUCUL_UNDERLINE)
if(lineattr[x] & CACA_UNDERLINE)
cur += sprintf(cur, ";text-decoration:underline"); cur += sprintf(cur, ";text-decoration:underline");
if(lineattr[x] & CUCUL_BLINK)
if(lineattr[x] & CACA_BLINK)
cur += sprintf(cur, ";text-decoration:blink"); cur += sprintf(cur, ";text-decoration:blink");
cur += sprintf(cur, "\">"); cur += sprintf(cur, "\">");


@@ -424,7 +424,7 @@ static void *export_html(cucul_canvas_t const *cv, size_t *bytes)
x + len < cv->width && lineattr[x + len] == lineattr[x]; x + len < cv->width && lineattr[x + len] == lineattr[x];
len++) len++)
{ {
if(linechar[x + len] == CUCUL_MAGIC_FULLWIDTH)
if(linechar[x + len] == CACA_MAGIC_FULLWIDTH)
; ;
else if(linechar[x + len] <= 0x00000020) else if(linechar[x + len] <= 0x00000020)
cur += sprintf(cur, "&nbsp;"); cur += sprintf(cur, "&nbsp;");
@@ -455,7 +455,7 @@ static void *export_html(cucul_canvas_t const *cv, size_t *bytes)
* but permits viewing in old browsers (or limited ones such as links). It * but permits viewing in old browsers (or limited ones such as links). It
* will not work under gecko (mozilla rendering engine) unless you set a * will not work under gecko (mozilla rendering engine) unless you set a
* correct header. */ * correct header. */
static void *export_html3(cucul_canvas_t const *cv, size_t *bytes)
static void *export_html3(caca_canvas_t const *cv, size_t *bytes)
{ {
char *data, *cur; char *data, *cur;
int x, y, len; int x, y, len;
@@ -492,33 +492,33 @@ static void *export_html3(cucul_canvas_t const *cv, size_t *bytes)


cur += sprintf(cur, "<td"); cur += sprintf(cur, "<td");


if(cucul_attr_to_ansi_fg(lineattr[x]) < 0x10)
if(caca_attr_to_ansi_fg(lineattr[x]) < 0x10)
cur += sprintf(cur, " bgcolor=#%.06lx", (unsigned long int) cur += sprintf(cur, " bgcolor=#%.06lx", (unsigned long int)
_cucul_attr_to_rgb24bg(lineattr[x]));
_caca_attr_to_rgb24bg(lineattr[x]));


if(len > 1) if(len > 1)
cur += sprintf(cur, " colspan=%d", len); cur += sprintf(cur, " colspan=%d", len);


cur += sprintf(cur, ">"); cur += sprintf(cur, ">");


needfont = cucul_attr_to_ansi_bg(lineattr[x]) < 0x10;
needfont = caca_attr_to_ansi_bg(lineattr[x]) < 0x10;


if(needfont) if(needfont)
cur += sprintf(cur, "<font color=#%.06lx>", (unsigned long int) cur += sprintf(cur, "<font color=#%.06lx>", (unsigned long int)
_cucul_attr_to_rgb24fg(lineattr[x]));
_caca_attr_to_rgb24fg(lineattr[x]));


if(lineattr[x] & CUCUL_BOLD)
if(lineattr[x] & CACA_BOLD)
cur += sprintf(cur, "<b>"); cur += sprintf(cur, "<b>");
if(lineattr[x] & CUCUL_ITALICS)
if(lineattr[x] & CACA_ITALICS)
cur += sprintf(cur, "<i>"); cur += sprintf(cur, "<i>");
if(lineattr[x] & CUCUL_UNDERLINE)
if(lineattr[x] & CACA_UNDERLINE)
cur += sprintf(cur, "<u>"); cur += sprintf(cur, "<u>");
if(lineattr[x] & CUCUL_BLINK)
if(lineattr[x] & CACA_BLINK)
cur += sprintf(cur, "<blink>"); cur += sprintf(cur, "<blink>");


for(i = 0; i < len; i++) for(i = 0; i < len; i++)
{ {
if(linechar[x + i] == CUCUL_MAGIC_FULLWIDTH)
if(linechar[x + i] == CACA_MAGIC_FULLWIDTH)
; ;
else if(linechar[x + i] <= 0x00000020) else if(linechar[x + i] <= 0x00000020)
cur += sprintf(cur, "&nbsp;"); cur += sprintf(cur, "&nbsp;");
@@ -528,13 +528,13 @@ static void *export_html3(cucul_canvas_t const *cv, size_t *bytes)
cur += sprintf(cur, "&#%i;", (unsigned int)linechar[x + i]); cur += sprintf(cur, "&#%i;", (unsigned int)linechar[x + i]);
} }


if(lineattr[x] & CUCUL_BLINK)
if(lineattr[x] & CACA_BLINK)
cur += sprintf(cur, "</blink>"); cur += sprintf(cur, "</blink>");
if(lineattr[x] & CUCUL_UNDERLINE)
if(lineattr[x] & CACA_UNDERLINE)
cur += sprintf(cur, "</u>"); cur += sprintf(cur, "</u>");
if(lineattr[x] & CUCUL_ITALICS)
if(lineattr[x] & CACA_ITALICS)
cur += sprintf(cur, "</i>"); cur += sprintf(cur, "</i>");
if(lineattr[x] & CUCUL_BOLD)
if(lineattr[x] & CACA_BOLD)
cur += sprintf(cur, "</b>"); cur += sprintf(cur, "</b>");


if(needfont) if(needfont)
@@ -556,7 +556,7 @@ static void *export_html3(cucul_canvas_t const *cv, size_t *bytes)
return data; return data;
} }


static void *export_bbfr(cucul_canvas_t const *cv, size_t *bytes)
static void *export_bbfr(caca_canvas_t const *cv, size_t *bytes)
{ {
char *data, *cur; char *data, *cur;
int x, y, len; int x, y, len;
@@ -594,46 +594,46 @@ static void *export_bbfr(cucul_canvas_t const *cv, size_t *bytes)
&& linechar[x] != ' ') && linechar[x] != ' ')
len++; len++;


needback = cucul_attr_to_ansi_bg(lineattr[x]) < 0x10;
needfront = cucul_attr_to_ansi_fg(lineattr[x]) < 0x10;
needback = caca_attr_to_ansi_bg(lineattr[x]) < 0x10;
needfront = caca_attr_to_ansi_fg(lineattr[x]) < 0x10;


if(needback) if(needback)
cur += sprintf(cur, "[f=#%.06lx]", (unsigned long int) cur += sprintf(cur, "[f=#%.06lx]", (unsigned long int)
_cucul_attr_to_rgb24bg(lineattr[x]));
_caca_attr_to_rgb24bg(lineattr[x]));


if(linechar[x] == ' ') if(linechar[x] == ' ')
cur += sprintf(cur, "[c=#%.06lx]", (unsigned long int) cur += sprintf(cur, "[c=#%.06lx]", (unsigned long int)
_cucul_attr_to_rgb24bg(lineattr[x]));
_caca_attr_to_rgb24bg(lineattr[x]));
else if(needfront) else if(needfront)
cur += sprintf(cur, "[c=#%.06lx]", (unsigned long int) cur += sprintf(cur, "[c=#%.06lx]", (unsigned long int)
_cucul_attr_to_rgb24fg(lineattr[x]));
_caca_attr_to_rgb24fg(lineattr[x]));


if(lineattr[x] & CUCUL_BOLD)
if(lineattr[x] & CACA_BOLD)
cur += sprintf(cur, "[g]"); cur += sprintf(cur, "[g]");
if(lineattr[x] & CUCUL_ITALICS)
if(lineattr[x] & CACA_ITALICS)
cur += sprintf(cur, "[i]"); cur += sprintf(cur, "[i]");
if(lineattr[x] & CUCUL_UNDERLINE)
if(lineattr[x] & CACA_UNDERLINE)
cur += sprintf(cur, "[s]"); cur += sprintf(cur, "[s]");
if(lineattr[x] & CUCUL_BLINK)
if(lineattr[x] & CACA_BLINK)
; /* FIXME */ ; /* FIXME */


for(i = 0; i < len; i++) for(i = 0; i < len; i++)
{ {
if(linechar[x + i] == CUCUL_MAGIC_FULLWIDTH)
if(linechar[x + i] == CACA_MAGIC_FULLWIDTH)
; ;
else if(linechar[x + i] == ' ') else if(linechar[x + i] == ' ')
*cur++ = '_'; *cur++ = '_';
else else
cur += cucul_utf32_to_utf8(cur, linechar[x + i]);
cur += caca_utf32_to_utf8(cur, linechar[x + i]);
} }


if(lineattr[x] & CUCUL_BLINK)
if(lineattr[x] & CACA_BLINK)
; /* FIXME */ ; /* FIXME */
if(lineattr[x] & CUCUL_UNDERLINE)
if(lineattr[x] & CACA_UNDERLINE)
cur += sprintf(cur, "[/s]"); cur += sprintf(cur, "[/s]");
if(lineattr[x] & CUCUL_ITALICS)
if(lineattr[x] & CACA_ITALICS)
cur += sprintf(cur, "[/i]"); cur += sprintf(cur, "[/i]");
if(lineattr[x] & CUCUL_BOLD)
if(lineattr[x] & CACA_BOLD)
cur += sprintf(cur, "[/g]"); cur += sprintf(cur, "[/g]");


if(linechar[x] == ' ' || needfront) if(linechar[x] == ' ' || needfront)
@@ -657,7 +657,7 @@ static void *export_bbfr(cucul_canvas_t const *cv, size_t *bytes)
} }


/* Export a text file with IRC colours */ /* Export a text file with IRC colours */
static void *export_irc(cucul_canvas_t const *cv, size_t *bytes)
static void *export_irc(caca_canvas_t const *cv, size_t *bytes)
{ {
static uint8_t const palette[] = static uint8_t const palette[] =
{ {
@@ -695,11 +695,11 @@ static void *export_irc(cucul_canvas_t const *cv, size_t *bytes)
uint32_t ch = linechar[x]; uint32_t ch = linechar[x];
uint8_t ansifg, ansibg, fg, bg; uint8_t ansifg, ansibg, fg, bg;


if(ch == CUCUL_MAGIC_FULLWIDTH)
if(ch == CACA_MAGIC_FULLWIDTH)
continue; continue;


ansifg = cucul_attr_to_ansi_fg(attr);
ansibg = cucul_attr_to_ansi_bg(attr);
ansifg = caca_attr_to_ansi_fg(attr);
ansibg = caca_attr_to_ansi_bg(attr);


fg = ansifg < 0x10 ? palette[ansifg] : 0x10; fg = ansifg < 0x10 ? palette[ansifg] : 0x10;
bg = ansibg < 0x10 ? palette[ansibg] : 0x10; bg = ansibg < 0x10 ? palette[ansibg] : 0x10;
@@ -741,7 +741,7 @@ static void *export_irc(cucul_canvas_t const *cv, size_t *bytes)
cur += sprintf(cur, "\x02\x02"); cur += sprintf(cur, "\x02\x02");
} }


cur += cucul_utf32_to_utf8(cur, ch);
cur += caca_utf32_to_utf8(cur, ch);
prevfg = fg; prevfg = fg;
prevbg = bg; prevbg = bg;
} }
@@ -764,7 +764,7 @@ static void *export_irc(cucul_canvas_t const *cv, size_t *bytes)
} }


/* Export a PostScript document. */ /* Export a PostScript document. */
static void *export_ps(cucul_canvas_t const *cv, size_t *bytes)
static void *export_ps(caca_canvas_t const *cv, size_t *bytes)
{ {
static char const *ps_header = static char const *ps_header =
"%!\n" "%!\n"
@@ -810,7 +810,7 @@ static void *export_ps(cucul_canvas_t const *cv, size_t *bytes)
for(x = 0; x < cv->width; x++) for(x = 0; x < cv->width; x++)
{ {
uint8_t argb[8]; uint8_t argb[8];
cucul_attr_to_argb64(*lineattr++, argb);
caca_attr_to_argb64(*lineattr++, argb);
cur += sprintf(cur, "1 0 translate\n %f %f %f csquare\n", cur += sprintf(cur, "1 0 translate\n %f %f %f csquare\n",
(float)argb[1] * (1.0 / 0xf), (float)argb[1] * (1.0 / 0xf),
(float)argb[2] * (1.0 / 0xf), (float)argb[2] * (1.0 / 0xf),
@@ -834,7 +834,7 @@ static void *export_ps(cucul_canvas_t const *cv, size_t *bytes)
uint8_t argb[8]; uint8_t argb[8];
uint32_t ch = *linechar++; uint32_t ch = *linechar++;


cucul_attr_to_argb64(*lineattr++, argb);
caca_attr_to_argb64(*lineattr++, argb);


cur += sprintf(cur, "newpath\n"); cur += sprintf(cur, "newpath\n");
cur += sprintf(cur, "%d %d moveto\n", (x + 1) * 6, y * 10 + 2); cur += sprintf(cur, "%d %d moveto\n", (x + 1) * 6, y * 10 + 2);
@@ -873,7 +873,7 @@ static void *export_ps(cucul_canvas_t const *cv, size_t *bytes)
} }


/* Export an SVG vector image */ /* Export an SVG vector image */
static void *export_svg(cucul_canvas_t const *cv, size_t *bytes)
static void *export_svg(caca_canvas_t const *cv, size_t *bytes)
{ {
static char const svg_header[] = static char const svg_header[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
@@ -905,7 +905,7 @@ static void *export_svg(cucul_canvas_t const *cv, size_t *bytes)
{ {
cur += sprintf(cur, "<rect style=\"fill:#%.03x\" x=\"%d\" y=\"%d\"" cur += sprintf(cur, "<rect style=\"fill:#%.03x\" x=\"%d\" y=\"%d\""
" width=\"6\" height=\"10\"/>\n", " width=\"6\" height=\"10\"/>\n",
cucul_attr_to_rgb12_bg(*lineattr++),
caca_attr_to_rgb12_bg(*lineattr++),
x * 6, y * 10); x * 6, y * 10);
} }
} }
@@ -920,7 +920,7 @@ static void *export_svg(cucul_canvas_t const *cv, size_t *bytes)
{ {
uint32_t ch = *linechar++; uint32_t ch = *linechar++;


if(ch == ' ' || ch == CUCUL_MAGIC_FULLWIDTH)
if(ch == ' ' || ch == CACA_MAGIC_FULLWIDTH)
{ {
lineattr++; lineattr++;
continue; continue;
@@ -928,13 +928,13 @@ static void *export_svg(cucul_canvas_t const *cv, size_t *bytes)


cur += sprintf(cur, "<text style=\"fill:#%.03x\" " cur += sprintf(cur, "<text style=\"fill:#%.03x\" "
"x=\"%d\" y=\"%d\">", "x=\"%d\" y=\"%d\">",
cucul_attr_to_rgb12_fg(*lineattr++),
caca_attr_to_rgb12_fg(*lineattr++),
x * 6, (y * 10) + 8); x * 6, (y * 10) + 8);


if(ch < 0x00000020) if(ch < 0x00000020)
*cur++ = '?'; *cur++ = '?';
else if(ch > 0x0000007f) else if(ch > 0x0000007f)
cur += cucul_utf32_to_utf8(cur, ch);
cur += caca_utf32_to_utf8(cur, ch);
else switch((uint8_t)ch) else switch((uint8_t)ch)
{ {
case '>': cur += sprintf(cur, "&gt;"); break; case '>': cur += sprintf(cur, "&gt;"); break;
@@ -959,24 +959,24 @@ static void *export_svg(cucul_canvas_t const *cv, size_t *bytes)
} }


/* Export a TGA image */ /* Export a TGA image */
static void *export_tga(cucul_canvas_t const *cv, size_t *bytes)
static void *export_tga(caca_canvas_t const *cv, size_t *bytes)
{ {
char const * const *fontlist; char const * const *fontlist;
char *data, *cur; char *data, *cur;
cucul_font_t *f;
caca_font_t *f;
int i, w, h; int i, w, h;


fontlist = cucul_get_font_list();
fontlist = caca_get_font_list();
if(!fontlist[0]) if(!fontlist[0])
{ {
seterrno(EINVAL); seterrno(EINVAL);
return NULL; return NULL;
} }


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


w = cucul_get_canvas_width(cv) * cucul_get_font_width(f);
h = cucul_get_canvas_height(cv) * cucul_get_font_height(f);
w = caca_get_canvas_width(cv) * caca_get_font_width(f);
h = caca_get_canvas_height(cv) * caca_get_font_height(f);


*bytes = w * h * 4 + 18; /* 32 bpp + 18 bytes for the header */ *bytes = w * h * 4 + 18; /* 32 bpp + 18 bytes for the header */
cur = data = malloc(*bytes); cur = data = malloc(*bytes);
@@ -1002,7 +1002,7 @@ static void *export_tga(cucul_canvas_t const *cv, size_t *bytes)
/* Color Map Data: no colormap */ /* Color Map Data: no colormap */


/* Image Data */ /* Image Data */
cucul_render_canvas(cv, f, cur, w, h, 4 * w);
caca_render_canvas(cv, f, cur, w, h, 4 * w);


/* Swap bytes. What a waste of time. */ /* Swap bytes. What a waste of time. */
for(i = 0; i < w * h * 4; i += 4) for(i = 0; i < w * h * 4; i += 4)
@@ -1012,7 +1012,7 @@ static void *export_tga(cucul_canvas_t const *cv, size_t *bytes)
c = cur[i + 1]; cur[i + 1] = cur[i + 2]; cur[i + 2] = c; c = cur[i + 1]; cur[i + 1] = cur[i + 2]; cur[i + 2] = c;
} }


cucul_free_font(f);
caca_free_font(f);


return data; return data;
} }

cucul/figfont.c → caca/figfont.c View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Canvas for ultrafast compositing of Unicode letters
* libcaca Colour ASCII-Art library
* Copyright (c) 2006-2007 Sam Hocevar <sam@zoy.org> * Copyright (c) 2006-2007 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -28,10 +28,10 @@
# include <string.h> # include <string.h>
#endif #endif


#include "cucul.h"
#include "cucul_internals.h"
#include "caca.h"
#include "caca_internals.h"


struct cucul_figfont
struct caca_figfont
{ {
int term_width; int term_width;
int x, y, w, h, lines; int x, y, w, h, lines;
@@ -43,18 +43,18 @@ struct cucul_figfont
int old_layout; int old_layout;
int print_direction, full_layout, codetag_count; int print_direction, full_layout, codetag_count;
int glyphs; int glyphs;
cucul_canvas_t *fontcv, *charcv;
caca_canvas_t *fontcv, *charcv;
int *left, *right; /* Unused yet */ int *left, *right; /* Unused yet */
uint32_t *lookup; uint32_t *lookup;
}; };


static uint32_t hsmush(uint32_t ch1, uint32_t ch2, int rule); static uint32_t hsmush(uint32_t ch1, uint32_t ch2, int rule);
static cucul_figfont_t * open_figfont(char const *);
static int free_figfont(cucul_figfont_t *);
static caca_figfont_t * open_figfont(char const *);
static int free_figfont(caca_figfont_t *);


int cucul_canvas_set_figfont(cucul_canvas_t *cv, char const *path)
int caca_canvas_set_figfont(caca_canvas_t *cv, char const *path)
{ {
cucul_figfont_t *ff = NULL;
caca_figfont_t *ff = NULL;


if(path) if(path)
{ {
@@ -65,7 +65,7 @@ int cucul_canvas_set_figfont(cucul_canvas_t *cv, char const *path)


if(cv->ff) if(cv->ff)
{ {
cucul_free_canvas(cv->ff->charcv);
caca_free_canvas(cv->ff->charcv);
free(cv->ff->left); free(cv->ff->left);
free(cv->ff->right); free(cv->ff->right);
free_figfont(cv->ff); free_figfont(cv->ff);
@@ -84,7 +84,7 @@ int cucul_canvas_set_figfont(cucul_canvas_t *cv, char const *path)
ff->x = ff->y = 0; ff->x = ff->y = 0;
ff->w = ff->h = 0; ff->w = ff->h = 0;
ff->lines = 0; ff->lines = 0;
cucul_set_canvas_size(cv, 0, 0); /* XXX */
caca_set_canvas_size(cv, 0, 0); /* XXX */


/* from TOIlet’s figlet.c */ /* from TOIlet’s figlet.c */
if(ff->full_layout & 0x3f) if(ff->full_layout & 0x3f)
@@ -117,7 +117,7 @@ int cucul_canvas_set_figfont(cucul_canvas_t *cv, char const *path)
break; break;
} }


ff->charcv = cucul_create_canvas(ff->max_length - 2, ff->height);
ff->charcv = caca_create_canvas(ff->max_length - 2, ff->height);


ff->left = malloc(ff->height * sizeof(int)); ff->left = malloc(ff->height * sizeof(int));
ff->right = malloc(ff->height * sizeof(int)); ff->right = malloc(ff->height * sizeof(int));
@@ -127,9 +127,9 @@ int cucul_canvas_set_figfont(cucul_canvas_t *cv, char const *path)
return 0; return 0;
} }


int cucul_put_figchar(cucul_canvas_t *cv, uint32_t ch)
int caca_put_figchar(caca_canvas_t *cv, uint32_t ch)
{ {
cucul_figfont_t *ff = cv->ff;
caca_figfont_t *ff = cv->ff;
int c, w, h, x, y, overlap, extra, xleft, xright; int c, w, h, x, y, overlap, extra, xleft, xright;


switch(ch) switch(ch)
@@ -154,8 +154,8 @@ int cucul_put_figchar(cucul_canvas_t *cv, uint32_t ch)
w = ff->lookup[c * 2 + 1]; w = ff->lookup[c * 2 + 1];
h = ff->height; h = ff->height;


cucul_set_canvas_handle(ff->fontcv, 0, c * ff->height);
cucul_blit(ff->charcv, 0, 0, ff->fontcv, NULL);
caca_set_canvas_handle(ff->fontcv, 0, c * ff->height);
caca_blit(ff->charcv, 0, 0, ff->fontcv, NULL);


/* Check whether we reached the end of the screen */ /* Check whether we reached the end of the screen */
if(ff->x && ff->x + w > ff->term_width) if(ff->x && ff->x + w > ff->term_width)
@@ -176,12 +176,12 @@ int cucul_put_figchar(cucul_canvas_t *cv, uint32_t ch)
{ {
/* Compute how much spaces we can eat from the new glyph */ /* Compute how much spaces we can eat from the new glyph */
for(xright = 0; xright < overlap; xright++) for(xright = 0; xright < overlap; xright++)
if(cucul_get_char(ff->charcv, xright, y) != ' ')
if(caca_get_char(ff->charcv, xright, y) != ' ')
break; break;


/* Compute how much spaces we can eat from the previous glyph */ /* Compute how much spaces we can eat from the previous glyph */
for(xleft = 0; xright + xleft < overlap && xleft < ff->x; xleft++) for(xleft = 0; xright + xleft < overlap && xleft < ff->x; xleft++)
if(cucul_get_char(cv, ff->x - 1 - xleft, ff->y + y) != ' ')
if(caca_get_char(cv, ff->x - 1 - xleft, ff->y + y) != ' ')
break; break;


/* Handle overlapping */ /* Handle overlapping */
@@ -192,8 +192,8 @@ int cucul_put_figchar(cucul_canvas_t *cv, uint32_t ch)
if(ff->hmode == H_SMUSH) if(ff->hmode == H_SMUSH)
{ {
if(xleft < ff->x && if(xleft < ff->x &&
hsmush(cucul_get_char(cv, ff->x - 1 - xleft, ff->y + y),
cucul_get_char(ff->charcv, xright, y),
hsmush(caca_get_char(cv, ff->x - 1 - xleft, ff->y + y),
caca_get_char(ff->charcv, xright, y),
ff->hsmushrule)) ff->hsmushrule))
xleft++; xleft++;
} }
@@ -219,29 +219,29 @@ int cucul_put_figchar(cucul_canvas_t *cv, uint32_t ch)


#if 0 /* deactivated for libcaca insertion */ #if 0 /* deactivated for libcaca insertion */
if(attr) if(attr)
cucul_set_attr(cv, attr);
caca_set_attr(cv, attr);
#endif #endif
cucul_set_canvas_size(cv, ff->w, ff->h);
caca_set_canvas_size(cv, ff->w, ff->h);


/* Render our char (FIXME: create a rect-aware cucul_blit_canvas?) */
/* Render our char (FIXME: create a rect-aware caca_blit_canvas?) */
for(y = 0; y < h; y++) for(y = 0; y < h; y++)
for(x = 0; x < w; x++) for(x = 0; x < w; x++)
{ {
uint32_t ch1, ch2; uint32_t ch1, ch2;
//uint32_t tmpat = cucul_get_attr(ff->fontcv, x, y + c * ff->height);
ch2 = cucul_get_char(ff->charcv, x, y);
//uint32_t tmpat = caca_get_attr(ff->fontcv, x, y + c * ff->height);
ch2 = caca_get_char(ff->charcv, x, y);
if(ch2 == ' ') if(ch2 == ' ')
continue; continue;
ch1 = cucul_get_char(cv, ff->x + x - overlap, ff->y + y);
/* FIXME: this could be changed to cucul_put_attr() when the
* function is fixed in libcucul */
//cucul_set_attr(cv, tmpat);
ch1 = caca_get_char(cv, ff->x + x - overlap, ff->y + y);
/* FIXME: this could be changed to caca_put_attr() when the
* function is fixed in libcaca */
//caca_set_attr(cv, tmpat);
if(ch1 == ' ' || ff->hmode != H_SMUSH) if(ch1 == ' ' || ff->hmode != H_SMUSH)
cucul_put_char(cv, ff->x + x - overlap, ff->y + y, ch2);
caca_put_char(cv, ff->x + x - overlap, ff->y + y, ch2);
else else
cucul_put_char(cv, ff->x + x - overlap, ff->y + y,
caca_put_char(cv, ff->x + x - overlap, ff->y + y,
hsmush(ch1, ch2, ff->hsmushrule)); hsmush(ch1, ch2, ff->hsmushrule));
//cucul_put_attr(cv, ff->x + x, ff->y + y, tmpat);
//caca_put_attr(cv, ff->x + x, ff->y + y, tmpat);
} }


/* Advance cursor */ /* Advance cursor */
@@ -250,32 +250,32 @@ int cucul_put_figchar(cucul_canvas_t *cv, uint32_t ch)
return 0; return 0;
} }


int cucul_flush_figlet(cucul_canvas_t *cv)
int caca_flush_figlet(caca_canvas_t *cv)
{ {
cucul_figfont_t *ff = cv->ff;
caca_figfont_t *ff = cv->ff;
int x, y; int x, y;


//ff->torender = cv; //ff->torender = cv;
//cucul_set_canvas_size(ff->torender, ff->w, ff->h);
cucul_set_canvas_size(cv, ff->w, ff->h);
//caca_set_canvas_size(ff->torender, ff->w, ff->h);
caca_set_canvas_size(cv, ff->w, ff->h);


/* FIXME: do this somewhere else, or record hardblank positions */ /* FIXME: do this somewhere else, or record hardblank positions */
for(y = 0; y < ff->h; y++) for(y = 0; y < ff->h; y++)
for(x = 0; x < ff->w; x++) for(x = 0; x < ff->w; x++)
if(cucul_get_char(cv, x, y) == 0xa0)
if(caca_get_char(cv, x, y) == 0xa0)
{ {
uint32_t attr = cucul_get_attr(cv, x, y);
cucul_put_char(cv, x, y, ' ');
cucul_put_attr(cv, x, y, attr);
uint32_t attr = caca_get_attr(cv, x, y);
caca_put_char(cv, x, y, ' ');
caca_put_attr(cv, x, y, attr);
} }


ff->x = ff->y = 0; ff->x = ff->y = 0;
ff->w = ff->h = 0; ff->w = ff->h = 0;


//cv = cucul_create_canvas(1, 1); /* XXX */
//cv = caca_create_canvas(1, 1); /* XXX */


/* from render.c */ /* from render.c */
ff->lines += cucul_get_canvas_height(cv);
ff->lines += caca_get_canvas_height(cv);


return 0; return 0;
} }
@@ -283,17 +283,17 @@ int cucul_flush_figlet(cucul_canvas_t *cv)
#define STD_GLYPHS (127 - 32) #define STD_GLYPHS (127 - 32)
#define EXT_GLYPHS (STD_GLYPHS + 7) #define EXT_GLYPHS (STD_GLYPHS + 7)


static cucul_figfont_t * open_figfont(char const *path)
static caca_figfont_t * open_figfont(char const *path)
{ {
char altpath[2048]; char altpath[2048];
char buf[2048]; char buf[2048];
char hardblank[10]; char hardblank[10];
cucul_figfont_t *ff;
caca_figfont_t *ff;
char *data = NULL; char *data = NULL;
cucul_file_t *f;
caca_file_t *f;
int i, j, size, comment_lines; int i, j, size, comment_lines;


ff = malloc(sizeof(cucul_figfont_t));
ff = malloc(sizeof(caca_figfont_t));
if(!ff) if(!ff)
{ {
seterrno(ENOMEM); seterrno(ENOMEM);
@@ -301,7 +301,7 @@ static cucul_figfont_t * open_figfont(char const *path)
} }


/* Open font: if not found, try .tlf, then .flf */ /* Open font: if not found, try .tlf, then .flf */
f = cucul_file_open(path, "r");
f = caca_file_open(path, "r");
#if !defined __KERNEL__ && defined HAVE_SNPRINTF #if !defined __KERNEL__ && defined HAVE_SNPRINTF


#if (! defined(snprintf)) && ( defined(_WIN32) || defined(WIN32) ) && (! defined(__CYGWIN__)) #if (! defined(snprintf)) && ( defined(_WIN32) || defined(WIN32) ) && (! defined(__CYGWIN__))
@@ -312,13 +312,13 @@ static cucul_figfont_t * open_figfont(char const *path)
{ {
snprintf(altpath, 2047, "%s.tlf", path); snprintf(altpath, 2047, "%s.tlf", path);
altpath[2047] = '\0'; altpath[2047] = '\0';
f = cucul_file_open(altpath, "r");
f = caca_file_open(altpath, "r");
} }
if(!f) if(!f)
{ {
snprintf(altpath, 2047, "%s.flf", path); snprintf(altpath, 2047, "%s.flf", path);
altpath[2047] = '\0'; altpath[2047] = '\0';
f = cucul_file_open(altpath, "r");
f = caca_file_open(altpath, "r");
} }
#endif #endif
if(!f) if(!f)
@@ -332,14 +332,14 @@ static cucul_figfont_t * open_figfont(char const *path)
ff->print_direction = 0; ff->print_direction = 0;
ff->full_layout = 0; ff->full_layout = 0;
ff->codetag_count = 0; ff->codetag_count = 0;
cucul_file_gets(f, buf, 2048);
caca_file_gets(f, buf, 2048);
if(sscanf(buf, "%*[ft]lf2a%6s %u %u %u %i %u %u %u %u\n", hardblank, if(sscanf(buf, "%*[ft]lf2a%6s %u %u %u %i %u %u %u %u\n", hardblank,
&ff->height, &ff->baseline, &ff->max_length, &ff->height, &ff->baseline, &ff->max_length,
&ff->old_layout, &comment_lines, &ff->print_direction, &ff->old_layout, &comment_lines, &ff->print_direction,
&ff->full_layout, &ff->codetag_count) < 6) &ff->full_layout, &ff->codetag_count) < 6)
{ {
debug("figfont error: `%s' has invalid header: %s", path, buf); debug("figfont error: `%s' has invalid header: %s", path, buf);
cucul_file_close(f);
caca_file_close(f);
free(ff); free(ff);
seterrno(EINVAL); seterrno(EINVAL);
return NULL; return NULL;
@@ -351,24 +351,24 @@ static cucul_figfont_t * open_figfont(char const *path)
{ {
debug("figfont error: `%s' has invalid layout %i/%u", debug("figfont error: `%s' has invalid layout %i/%u",
path, ff->old_layout, ff->full_layout); path, ff->old_layout, ff->full_layout);
cucul_file_close(f);
caca_file_close(f);
free(ff); free(ff);
seterrno(EINVAL); seterrno(EINVAL);
return NULL; return NULL;
} }


ff->hardblank = cucul_utf8_to_utf32(hardblank, NULL);
ff->hardblank = caca_utf8_to_utf32(hardblank, NULL);


/* Skip comment lines */ /* Skip comment lines */
for(i = 0; i < comment_lines; i++) for(i = 0; i < comment_lines; i++)
cucul_file_gets(f, buf, 2048);
caca_file_gets(f, buf, 2048);


/* Read mandatory characters (32-127, 196, 214, 220, 228, 246, 252, 223) /* Read mandatory characters (32-127, 196, 214, 220, 228, 246, 252, 223)
* then read additional characters. */ * then read additional characters. */
ff->glyphs = 0; ff->glyphs = 0;
ff->lookup = NULL; ff->lookup = NULL;


for(i = 0, size = 0; !cucul_file_eof(f); ff->glyphs++)
for(i = 0, size = 0; !caca_file_eof(f); ff->glyphs++)
{ {
if((ff->glyphs % 2048) == 0) if((ff->glyphs % 2048) == 0)
ff->lookup = realloc(ff->lookup, ff->lookup = realloc(ff->lookup,
@@ -385,7 +385,7 @@ static cucul_figfont_t * open_figfont(char const *path)
} }
else else
{ {
if(cucul_file_gets(f, buf, 2048) == NULL)
if(caca_file_gets(f, buf, 2048) == NULL)
break; break;


/* Ignore blank lines, as in jacky.flf */ /* Ignore blank lines, as in jacky.flf */
@@ -396,7 +396,7 @@ static cucul_figfont_t * open_figfont(char const *path)
if(buf[0] == '-') if(buf[0] == '-')
{ {
for(j = 0; j < ff->height; j++) for(j = 0; j < ff->height; j++)
cucul_file_gets(f, buf, 2048);
caca_file_gets(f, buf, 2048);
continue; continue;
} }


@@ -423,12 +423,12 @@ static cucul_figfont_t * open_figfont(char const *path)
if(i + 2048 >= size) if(i + 2048 >= size)
data = realloc(data, size += 2048); data = realloc(data, size += 2048);


cucul_file_gets(f, data + i, 2048);
caca_file_gets(f, data + i, 2048);
i = (uintptr_t)strchr(data + i, 0) - (uintptr_t)data; i = (uintptr_t)strchr(data + i, 0) - (uintptr_t)data;
} }
} }


cucul_file_close(f);
caca_file_close(f);


if(ff->glyphs < EXT_GLYPHS) if(ff->glyphs < EXT_GLYPHS)
{ {
@@ -442,8 +442,8 @@ static cucul_figfont_t * open_figfont(char const *path)
} }


/* Import buffer into canvas */ /* Import buffer into canvas */
ff->fontcv = cucul_create_canvas(0, 0);
cucul_import_memory(ff->fontcv, data, i, "utf8");
ff->fontcv = caca_create_canvas(0, 0);
caca_import_memory(ff->fontcv, data, i, "utf8");
free(data); free(data);


/* Remove EOL characters. For now we ignore hardblanks, don’t do any /* Remove EOL characters. For now we ignore hardblanks, don’t do any
@@ -454,11 +454,11 @@ static cucul_figfont_t * open_figfont(char const *path)


for(i = ff->max_length; i--;) for(i = ff->max_length; i--;)
{ {
ch = cucul_get_char(ff->fontcv, i, j);
ch = caca_get_char(ff->fontcv, i, j);


/* Replace hardblanks with U+00A0 NO-BREAK SPACE */ /* Replace hardblanks with U+00A0 NO-BREAK SPACE */
if(ch == ff->hardblank) if(ch == ff->hardblank)
cucul_put_char(ff->fontcv, i, j, ch = 0xa0);
caca_put_char(ff->fontcv, i, j, ch = 0xa0);


if(oldch && ch != oldch) if(oldch && ch != oldch)
{ {
@@ -466,11 +466,11 @@ static cucul_figfont_t * open_figfont(char const *path)
ff->lookup[j / ff->height * 2 + 1] = i + 1; ff->lookup[j / ff->height * 2 + 1] = i + 1;
} }
else if(oldch && ch == oldch) else if(oldch && ch == oldch)
cucul_put_char(ff->fontcv, i, j, ' ');
caca_put_char(ff->fontcv, i, j, ' ');
else if(ch != ' ') else if(ch != ' ')
{ {
oldch = ch; oldch = ch;
cucul_put_char(ff->fontcv, i, j, ' ');
caca_put_char(ff->fontcv, i, j, ' ');
} }
} }
} }
@@ -478,9 +478,9 @@ static cucul_figfont_t * open_figfont(char const *path)
return ff; return ff;
} }


int free_figfont(cucul_figfont_t *ff)
int free_figfont(caca_figfont_t *ff)
{ {
cucul_free_canvas(ff->fontcv);
caca_free_canvas(ff->fontcv);
free(ff->lookup); free(ff->lookup);
free(ff); free(ff);



cucul/file.c → caca/file.c View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Canvas for ultrafast compositing of Unicode letters
* libcaca Colour ASCII-Art library
* Copyright (c) 2006-2007 Sam Hocevar <sam@zoy.org> * Copyright (c) 2006-2007 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -29,15 +29,15 @@
# endif # endif
#endif #endif


#include "cucul.h"
#include "cucul_internals.h"
#include "caca.h"
#include "caca_internals.h"


#if !defined __KERNEL__ && defined HAVE_ZLIB_H #if !defined __KERNEL__ && defined HAVE_ZLIB_H
static int zipread(cucul_file_t *, void *, unsigned int);
static int zipread(caca_file_t *, void *, unsigned int);
#endif #endif


#if !defined __KERNEL__ #if !defined __KERNEL__
struct cucul_file
struct caca_file
{ {
# if defined HAVE_ZLIB_H # if defined HAVE_ZLIB_H
uint8_t read_buffer[READSIZE]; uint8_t read_buffer[READSIZE];
@@ -50,13 +50,13 @@ struct cucul_file
}; };
#endif #endif


cucul_file_t *cucul_file_open(char const *path, const char *mode)
caca_file_t *caca_file_open(char const *path, const char *mode)
{ {
#if defined __KERNEL__ #if defined __KERNEL__
seterrno(ENOSYS); seterrno(ENOSYS);
return NULL; return NULL;
#else #else
cucul_file_t *fp = malloc(sizeof(*fp));
caca_file_t *fp = malloc(sizeof(*fp));


fp->readonly = !!strchr(mode, 'r'); fp->readonly = !!strchr(mode, 'r');


@@ -125,7 +125,7 @@ cucul_file_t *cucul_file_open(char const *path, const char *mode)
#endif #endif
} }


int cucul_file_close(cucul_file_t *fp)
int caca_file_close(caca_file_t *fp)
{ {
#if defined __KERNEL__ #if defined __KERNEL__
seterrno(ENOSYS); seterrno(ENOSYS);
@@ -143,7 +143,7 @@ int cucul_file_close(cucul_file_t *fp)
#endif #endif
} }


uint64_t cucul_file_tell(cucul_file_t *fp)
uint64_t caca_file_tell(caca_file_t *fp)
{ {
#if defined __KERNEL__ #if defined __KERNEL__
seterrno(ENOSYS); seterrno(ENOSYS);
@@ -157,7 +157,7 @@ uint64_t cucul_file_tell(cucul_file_t *fp)
#endif #endif
} }


size_t cucul_file_read(cucul_file_t *fp, void *ptr, size_t size)
size_t caca_file_read(caca_file_t *fp, void *ptr, size_t size)
{ {
#if defined __KERNEL__ #if defined __KERNEL__
seterrno(ENOSYS); seterrno(ENOSYS);
@@ -171,7 +171,7 @@ size_t cucul_file_read(cucul_file_t *fp, void *ptr, size_t size)
#endif #endif
} }


size_t cucul_file_write(cucul_file_t *fp, const void *ptr, size_t size)
size_t caca_file_write(caca_file_t *fp, const void *ptr, size_t size)
{ {
#if defined __KERNEL__ #if defined __KERNEL__
seterrno(ENOSYS); seterrno(ENOSYS);
@@ -194,7 +194,7 @@ size_t cucul_file_write(cucul_file_t *fp, const void *ptr, size_t size)
#endif #endif
} }


char *cucul_file_gets(cucul_file_t *fp, char *s, int size)
char *caca_file_gets(caca_file_t *fp, char *s, int size)
{ {
#if defined __KERNEL__ #if defined __KERNEL__
seterrno(ENOSYS); seterrno(ENOSYS);
@@ -228,7 +228,7 @@ char *cucul_file_gets(cucul_file_t *fp, char *s, int size)
#endif #endif
} }


int cucul_file_eof(cucul_file_t *fp)
int caca_file_eof(caca_file_t *fp)
{ {
#if defined __KERNEL__ #if defined __KERNEL__
return 1; return 1;
@@ -240,7 +240,7 @@ int cucul_file_eof(cucul_file_t *fp)
} }


#if !defined __KERNEL__ && defined HAVE_ZLIB_H #if !defined __KERNEL__ && defined HAVE_ZLIB_H
static int zipread(cucul_file_t *fp, void *buf, unsigned int len)
static int zipread(caca_file_t *fp, void *buf, unsigned int len)
{ {
unsigned int total_read = 0; unsigned int total_read = 0;



cucul/font.c → caca/font.c View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Canvas for ultrafast compositing of Unicode letters
* libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -27,8 +27,8 @@
# include <string.h> # include <string.h>
#endif #endif


#include "cucul.h"
#include "cucul_internals.h"
#include "caca.h"
#include "caca_internals.h"


/* Internal fonts */ /* Internal fonts */
#include "mono9.data" #include "mono9.data"
@@ -55,7 +55,7 @@ struct glyph_info
uint32_t data_offset; uint32_t data_offset;
}; };


struct cucul_font
struct caca_font
{ {
struct font_header header; struct font_header header;


@@ -91,7 +91,7 @@ DECLARE_UNPACKGLYPH(1)
/** \brief Load a font from memory for future use. /** \brief Load a font from memory for future use.
* *
* This function loads a font and returns a handle to its internal * This function loads a font and returns a handle to its internal
* structure. The handle can then be used with cucul_render_canvas()
* structure. The handle can then be used with caca_render_canvas()
* for bitmap output. * for bitmap output.
* *
* Internal fonts can also be loaded: if \c size is set to 0, \c data must * Internal fonts can also be loaded: if \c size is set to 0, \c data must
@@ -99,7 +99,7 @@ DECLARE_UNPACKGLYPH(1)
* *
* If \c size is non-zero, the \c size bytes of memory at address \c data * If \c size is non-zero, the \c size bytes of memory at address \c data
* are loaded as a font. This memory are must not be freed by the calling * are loaded as a font. This memory are must not be freed by the calling
* program until the font handle has been freed with cucul_free_font().
* program until the font handle has been freed with caca_free_font().
* *
* If an error occurs, NULL is returned and \b errno is set accordingly: * If an error occurs, NULL is returned and \b errno is set accordingly:
* - \c ENOENT Requested built-in font does not exist. * - \c ENOENT Requested built-in font does not exist.
@@ -110,17 +110,17 @@ 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.
*/ */
cucul_font_t *cucul_load_font(void const *data, size_t size)
caca_font_t *caca_load_font(void const *data, size_t size)
{ {
cucul_font_t *f;
caca_font_t *f;
int i; int i;


if(size == 0) if(size == 0)
{ {
if(!strcasecmp(data, "Monospace 9")) if(!strcasecmp(data, "Monospace 9"))
return cucul_load_font((char *)&mono9_data, mono9_size);
return caca_load_font((char *)&mono9_data, mono9_size);
if(!strcasecmp(data, "Monospace Bold 12")) if(!strcasecmp(data, "Monospace Bold 12"))
return cucul_load_font((char *)&monobold12_data, monobold12_size);
return caca_load_font((char *)&monobold12_data, monobold12_size);


seterrno(ENOENT); seterrno(ENOENT);
return NULL; return NULL;
@@ -134,7 +134,7 @@ cucul_font_t *cucul_load_font(void const *data, size_t size)
return NULL; return NULL;
} }


f = malloc(sizeof(cucul_font_t));
f = malloc(sizeof(caca_font_t));
if(!f) if(!f)
{ {
seterrno(ENOMEM); seterrno(ENOMEM);
@@ -301,7 +301,7 @@ cucul_font_t *cucul_load_font(void const *data, size_t size)
* *
* \return An array of strings. * \return An array of strings.
*/ */
char const * const * cucul_get_font_list(void)
char const * const * caca_get_font_list(void)
{ {
static char const * const list[] = static char const * const list[] =
{ {
@@ -320,10 +320,10 @@ char const * const * cucul_get_font_list(void)
* *
* This function never fails. * This function never fails.
* *
* \param f The font, as returned by cucul_load_font()
* \param f The font, as returned by caca_load_font()
* \return The standard glyph width. * \return The standard glyph width.
*/ */
int cucul_get_font_width(cucul_font_t const *f)
int caca_get_font_width(caca_font_t const *f)
{ {
return f->header.width; return f->header.width;
} }
@@ -335,10 +335,10 @@ int cucul_get_font_width(cucul_font_t const *f)
* *
* This function never fails. * This function never fails.
* *
* \param f The font, as returned by cucul_load_font()
* \param f The font, as returned by caca_load_font()
* \return The standard glyph height. * \return The standard glyph height.
*/ */
int cucul_get_font_height(cucul_font_t const *f)
int caca_get_font_height(caca_font_t const *f)
{ {
return f->header.height; return f->header.height;
} }
@@ -360,27 +360,27 @@ int cucul_get_font_height(cucul_font_t const *f)
* *
* This function never fails. * This function never fails.
* *
* \param f The font, as returned by cucul_load_font()
* \param f The font, as returned by caca_load_font()
* \return The list of Unicode blocks supported by the font. * \return The list of Unicode blocks supported by the font.
*/ */
uint32_t const *cucul_get_font_blocks(cucul_font_t const *f)
uint32_t const *caca_get_font_blocks(caca_font_t const *f)
{ {
return (uint32_t const *)f->user_block_list; return (uint32_t const *)f->user_block_list;
} }


/** \brief Free a font structure. /** \brief Free a font structure.
* *
* This function frees all data allocated by cucul_load_font(). The
* font structure is no longer usable by other libcucul functions. Once
* This function frees all data allocated by caca_load_font(). The
* font structure is no longer usable by other libcaca functions. Once
* this function has returned, the memory area that was given to * this function has returned, the memory area that was given to
* cucul_load_font() can be freed.
* caca_load_font() can be freed.
* *
* This function never fails. * This function never fails.
* *
* \param f The font, as returned by cucul_load_font()
* \param f The font, as returned by caca_load_font()
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_free_font(cucul_font_t *f)
int caca_free_font(caca_font_t *f)
{ {
free(f->glyph_list); free(f->glyph_list);
free(f->user_block_list); free(f->user_block_list);
@@ -396,9 +396,9 @@ int cucul_free_font(cucul_font_t *f)
* 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 * The required image width can be computed using
* cucul_get_canvas_width() and cucul_get_font_width(). The required
* height can be computed using cucul_get_canvas_height() and
* cucul_get_font_height().
* caca_get_canvas_width() and caca_get_font_width(). The required
* height can be computed using caca_get_canvas_height() and
* caca_get_font_height().
* *
* 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.
@@ -407,14 +407,14 @@ int cucul_free_font(cucul_font_t *f)
* - \c EINVAL Specified width, height or pitch is invalid. * - \c EINVAL Specified width, height or pitch is invalid.
* *
* \param cv The canvas to render * \param cv The canvas to render
* \param f The font, as returned by cucul_load_font()
* \param f The font, as returned by caca_load_font()
* \param buf The image buffer * \param buf The image buffer
* \param width The width (in pixels) of the image buffer * \param width The width (in pixels) of the image buffer
* \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.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_render_canvas(cucul_canvas_t const *cv, cucul_font_t const *f,
int caca_render_canvas(caca_canvas_t const *cv, caca_font_t const *f,
void *buf, int width, int height, int pitch) void *buf, int width, int height, int pitch)
{ {
uint8_t *glyph = NULL; uint8_t *glyph = NULL;
@@ -471,7 +471,7 @@ int cucul_render_canvas(cucul_canvas_t const *cv, cucul_font_t const *f,
g = &f->glyph_list[f->block_list[b].index g = &f->glyph_list[f->block_list[b].index
+ ch - f->block_list[b].start]; + ch - f->block_list[b].start];


cucul_attr_to_argb64(attr, argb);
caca_attr_to_argb64(attr, argb);


/* Step 1: unpack glyph */ /* Step 1: unpack glyph */
switch(f->header.bpp) switch(f->header.bpp)

cucul/frame.c → caca/frame.c View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Canvas for ultrafast compositing of Unicode letters
* libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -24,8 +24,8 @@
# include <string.h> # include <string.h>
#endif #endif


#include "cucul.h"
#include "cucul_internals.h"
#include "caca.h"
#include "caca_internals.h"


/** \brief Get the number of frames in a canvas. /** \brief Get the number of frames in a canvas.
* *
@@ -33,10 +33,10 @@
* *
* This function never fails. * This function never fails.
* *
* \param cv A libcucul canvas
* \param cv A libcaca canvas
* \return The frame count * \return The frame count
*/ */
int cucul_get_frame_count(cucul_canvas_t const *cv)
int caca_get_frame_count(caca_canvas_t const *cv)
{ {
return cv->framecount; return cv->framecount;
} }
@@ -45,18 +45,18 @@ int cucul_get_frame_count(cucul_canvas_t const *cv)
* *
* Set the active canvas frame. All subsequent drawing operations will * Set the active canvas frame. All subsequent drawing operations will
* be performed on that frame. The current painting context set by * be performed on that frame. The current painting context set by
* cucul_set_attr() is inherited.
* caca_set_attr() is inherited.
* *
* If the frame index is outside the canvas' frame range, nothing happens. * If the frame index is outside the canvas' frame range, nothing happens.
* *
* If an error occurs, -1 is returned and \b errno is set accordingly: * If an error occurs, -1 is returned and \b errno is set accordingly:
* - \c EINVAL Requested frame is out of range. * - \c EINVAL Requested frame is out of range.
* *
* \param cv A libcucul canvas
* \param cv A libcaca canvas
* \param id The canvas frame to activate * \param id The canvas frame to activate
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_set_frame(cucul_canvas_t *cv, int id)
int caca_set_frame(caca_canvas_t *cv, int id)
{ {
if(id < 0 || id >= cv->framecount) if(id < 0 || id >= cv->framecount)
{ {
@@ -64,9 +64,9 @@ int cucul_set_frame(cucul_canvas_t *cv, int id)
return -1; return -1;
} }


_cucul_save_frame_info(cv);
_caca_save_frame_info(cv);
cv->frame = id; cv->frame = id;
_cucul_load_frame_info(cv);
_caca_load_frame_info(cv);


return 0; return 0;
} }
@@ -74,15 +74,15 @@ int cucul_set_frame(cucul_canvas_t *cv, int id)
/** \brief Get the current frame's name. /** \brief Get the current frame's name.
* *
* Return the current frame's name. The returned string is valid until * Return the current frame's name. The returned string is valid until
* the frame is deleted or cucul_set_frame_name() is called to change
* the frame is deleted or caca_set_frame_name() is called to change
* the frame name again. * the frame name again.
* *
* This function never fails. * This function never fails.
* *
* \param cv A libcucul canvas.
* \param cv A libcaca canvas.
* \return The current frame's name. * \return The current frame's name.
*/ */
char const *cucul_get_frame_name(cucul_canvas_t const *cv)
char const *caca_get_frame_name(caca_canvas_t const *cv)
{ {
return cv->frames[cv->frame].name; return cv->frames[cv->frame].name;
} }
@@ -96,11 +96,11 @@ char const *cucul_get_frame_name(cucul_canvas_t const *cv)
* If an error occurs, -1 is returned and \b errno is set accordingly: * If an error occurs, -1 is returned and \b errno is set accordingly:
* - \c ENOMEM Not enough memory to allocate new frame. * - \c ENOMEM Not enough memory to allocate new frame.
* *
* \param cv A libcucul canvas.
* \param cv A libcaca canvas.
* \param name The name to give to the current frame. * \param name The name to give to the current frame.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_set_frame_name(cucul_canvas_t *cv, char const *name)
int caca_set_frame_name(caca_canvas_t *cv, char const *name)
{ {
char *newname = strdup(name); char *newname = strdup(name);


@@ -133,11 +133,11 @@ int cucul_set_frame_name(cucul_canvas_t *cv, char const *name)
* If an error occurs, -1 is returned and \b errno is set accordingly: * If an error occurs, -1 is returned and \b errno is set accordingly:
* - \c ENOMEM Not enough memory to allocate new frame. * - \c ENOMEM Not enough memory to allocate new frame.
* *
* \param cv A libcucul canvas
* \param cv A libcaca canvas
* \param id The index where to insert the new frame * \param id The index where to insert the new frame
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_create_frame(cucul_canvas_t *cv, int id)
int caca_create_frame(caca_canvas_t *cv, int id)
{ {
int size = cv->width * cv->height; int size = cv->width * cv->height;
int f; int f;
@@ -149,7 +149,7 @@ int cucul_create_frame(cucul_canvas_t *cv, int id)


cv->framecount++; cv->framecount++;
cv->frames = realloc(cv->frames, cv->frames = realloc(cv->frames,
sizeof(struct cucul_frame) * cv->framecount);
sizeof(struct caca_frame) * cv->framecount);


for(f = cv->framecount - 1; f > id; f--) for(f = cv->framecount - 1; f > id; f--)
cv->frames[f] = cv->frames[f - 1]; cv->frames[f] = cv->frames[f - 1];
@@ -193,11 +193,11 @@ int cucul_create_frame(cucul_canvas_t *cv, int id)
* - \c EINVAL Requested frame is out of range, or attempt to delete the * - \c EINVAL Requested frame is out of range, or attempt to delete the
* last frame of the canvas. * last frame of the canvas.
* *
* \param cv A libcucul canvas
* \param cv A libcaca canvas
* \param id The index of the frame to delete * \param id The index of the frame to delete
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_free_frame(cucul_canvas_t *cv, int id)
int caca_free_frame(caca_canvas_t *cv, int id)
{ {
int f; int f;


@@ -222,14 +222,14 @@ int cucul_free_frame(cucul_canvas_t *cv, int id)


cv->framecount--; cv->framecount--;
cv->frames = realloc(cv->frames, cv->frames = realloc(cv->frames,
sizeof(struct cucul_frame) * cv->framecount);
sizeof(struct caca_frame) * cv->framecount);


if(cv->frame > id) if(cv->frame > id)
cv->frame--; cv->frame--;
else if(cv->frame == id) else if(cv->frame == id)
{ {
cv->frame = 0; cv->frame = 0;
_cucul_load_frame_info(cv);
_caca_load_frame_info(cv);
} }


return 0; return 0;
@@ -239,7 +239,7 @@ int cucul_free_frame(cucul_canvas_t *cv, int id)
* XXX: the following functions are local. * XXX: the following functions are local.
*/ */


void _cucul_save_frame_info(cucul_canvas_t *cv)
void _caca_save_frame_info(caca_canvas_t *cv)
{ {
cv->frames[cv->frame].width = cv->width; cv->frames[cv->frame].width = cv->width;
cv->frames[cv->frame].height = cv->height; cv->frames[cv->frame].height = cv->height;
@@ -247,7 +247,7 @@ void _cucul_save_frame_info(cucul_canvas_t *cv)
cv->frames[cv->frame].curattr = cv->curattr; cv->frames[cv->frame].curattr = cv->curattr;
} }


void _cucul_load_frame_info(cucul_canvas_t *cv)
void _caca_load_frame_info(caca_canvas_t *cv)
{ {
cv->width = cv->frames[cv->frame].width; cv->width = cv->frames[cv->frame].width;
cv->height = cv->frames[cv->frame].height; cv->height = cv->frames[cv->frame].height;

+ 4
- 5
caca/graphics.c View File

@@ -24,7 +24,6 @@
# include <string.h> # include <string.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"
#include "caca_internals.h" #include "caca_internals.h"


@@ -241,12 +240,12 @@ void _caca_handle_resize(caca_display_t *dp)
{ {
dp->drv.handle_resize(dp); dp->drv.handle_resize(dp);


/* Tell libcucul we changed size */
if(dp->resize.w != cucul_get_canvas_width(dp->cv)
|| dp->resize.h != cucul_get_canvas_height(dp->cv))
/* Tell libcaca we changed size */
if(dp->resize.w != caca_get_canvas_width(dp->cv)
|| dp->resize.h != caca_get_canvas_height(dp->cv))
{ {
dp->resize.allow = 1; dp->resize.allow = 1;
cucul_set_canvas_size(dp->cv, dp->resize.w, dp->resize.h);
caca_set_canvas_size(dp->cv, dp->resize.w, dp->resize.h);
dp->resize.allow = 0; dp->resize.allow = 0;
} }
} }


cucul/import.c → caca/import.c View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Canvas for ultrafast compositing of Unicode letters
* libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -23,8 +23,8 @@
# include <string.h> # include <string.h>
#endif #endif


#include "cucul.h"
#include "cucul_internals.h"
#include "caca.h"
#include "caca_internals.h"


static inline uint32_t sscanu32(void const *s) static inline uint32_t sscanu32(void const *s)
{ {
@@ -51,16 +51,16 @@ struct import
uint8_t faint, strike, proportional; /* unsupported */ uint8_t faint, strike, proportional; /* unsupported */
}; };


static ssize_t import_caca(cucul_canvas_t *, void const *, size_t);
static ssize_t import_text(cucul_canvas_t *, void const *, size_t);
static ssize_t import_ansi(cucul_canvas_t *, void const *, size_t, int);
static ssize_t import_caca(caca_canvas_t *, void const *, size_t);
static ssize_t import_text(caca_canvas_t *, void const *, size_t);
static ssize_t import_ansi(caca_canvas_t *, void const *, size_t, int);


static void ansi_parse_grcm(cucul_canvas_t *, struct import *,
static void ansi_parse_grcm(caca_canvas_t *, struct import *,
unsigned int, unsigned int const *); unsigned int, unsigned int const *);


/** \brief Import a memory buffer into a canvas /** \brief Import a memory buffer into a canvas
* *
* Import a memory buffer into the given libcucul canvas's current
* Import a memory buffer into the given libcaca canvas's current
* frame. The current frame is resized accordingly and its contents are * frame. The current frame is resized accordingly and its contents are
* replaced with the imported data. * replaced with the imported data.
* *
@@ -78,14 +78,14 @@ static void ansi_parse_grcm(cucul_canvas_t *, struct import *,
* - \c ENOMEM Not enough memory to allocate canvas. * - \c ENOMEM Not enough memory to allocate canvas.
* - \c EINVAL Invalid format requested. * - \c EINVAL Invalid format requested.
* *
* \param cv A libcucul canvas in which to import the file.
* \param cv A libcaca canvas in which to import the file.
* \param data A memory area containing the data to be loaded into the canvas. * \param data A memory area containing the data to be loaded into the canvas.
* \param len The size in bytes of the memory area. * \param len The size in bytes of the memory area.
* \param format A string describing the input format. * \param format A string describing the input format.
* \return The number of bytes read, or 0 if there was not enough data, * \return The number of bytes read, or 0 if there was not enough data,
* or -1 if an error occurred. * or -1 if an error occurred.
*/ */
ssize_t cucul_import_memory(cucul_canvas_t *cv, void const *data,
ssize_t caca_import_memory(caca_canvas_t *cv, void const *data,
size_t len, char const *format) size_t len, char const *format)
{ {
if(!strcasecmp("caca", format)) if(!strcasecmp("caca", format))
@@ -123,7 +123,7 @@ ssize_t cucul_import_memory(cucul_canvas_t *cv, void const *data,


/** \brief Import a file into a canvas /** \brief Import a file into a canvas
* *
* Import a file into the given libcucul canvas's current frame. The
* Import a file into the given libcaca canvas's current frame. The
* current frame is resized accordingly and its contents are replaced * current frame is resized accordingly and its contents are replaced
* with the imported data. * with the imported data.
* *
@@ -141,48 +141,48 @@ ssize_t cucul_import_memory(cucul_canvas_t *cv, void const *data,
* - \c ENOSYS File access is not implemented on this system. * - \c ENOSYS File access is not implemented on this system.
* - \c ENOMEM Not enough memory to allocate canvas. * - \c ENOMEM Not enough memory to allocate canvas.
* - \c EINVAL Invalid format requested. * - \c EINVAL Invalid format requested.
* cucul_import_file() may also fail and set \b errno for any of the
* caca_import_file() may also fail and set \b errno for any of the
* errors specified for the routine fopen(). * errors specified for the routine fopen().
* *
* \param cv A libcucul canvas in which to import the file.
* \param cv A libcaca canvas in which to import the file.
* \param filename The name of the file to load. * \param filename The name of the file to load.
* \param format A string describing the input format. * \param format A string describing the input format.
* \return The number of bytes read, or 0 if there was not enough data, * \return The number of bytes read, or 0 if there was not enough data,
* or -1 if an error occurred. * or -1 if an error occurred.
*/ */
ssize_t cucul_import_file(cucul_canvas_t *cv, char const *filename,
ssize_t caca_import_file(caca_canvas_t *cv, char const *filename,
char const *format) char const *format)
{ {
#if defined __KERNEL__ #if defined __KERNEL__
seterrno(ENOSYS); seterrno(ENOSYS);
return -1; return -1;
#else #else
cucul_file_t *f;
caca_file_t *f;
char *data = NULL; char *data = NULL;
ssize_t size = 0; ssize_t size = 0;
int ret; int ret;


f = cucul_file_open(filename, "rb");
f = caca_file_open(filename, "rb");
if(!f) if(!f)
return -1; /* fopen already set errno */ return -1; /* fopen already set errno */


while(!cucul_file_eof(f))
while(!caca_file_eof(f))
{ {
data = realloc(data, size + 1024); data = realloc(data, size + 1024);
if(!data) if(!data)
{ {
cucul_file_close(f);
caca_file_close(f);
seterrno(ENOMEM); seterrno(ENOMEM);
return -1; return -1;
} }


ret = cucul_file_read(f, data + size, 1024);
ret = caca_file_read(f, data + size, 1024);
if(ret >= 0) if(ret >= 0)
size += ret; size += ret;
} }
cucul_file_close(f);
caca_file_close(f);


ret = cucul_import_memory(cv, data, size, format);
ret = caca_import_memory(cv, data, size, format);
free(data); free(data);


return ret; return ret;
@@ -193,14 +193,14 @@ ssize_t cucul_import_file(cucul_canvas_t *cv, char const *filename,
* *
* Return a list of available import formats. The list is a NULL-terminated * Return a list of available import formats. The list is a NULL-terminated
* array of strings, interleaving a string containing the internal value for * array of strings, interleaving a string containing the internal value for
* the import format, to be used with cucul_import_canvas(), and a string
* the import format, to be used with caca_import_canvas(), and a string
* containing the natural language description for that import format. * containing the natural language description for that import format.
* *
* This function never fails. * This function never fails.
* *
* \return An array of strings. * \return An array of strings.
*/ */
char const * const * cucul_get_import_list(void)
char const * const * caca_get_import_list(void)
{ {
static char const * const list[] = static char const * const list[] =
{ {
@@ -219,7 +219,7 @@ char const * const * cucul_get_import_list(void)
* XXX: the following functions are local. * XXX: the following functions are local.
*/ */


static ssize_t import_caca(cucul_canvas_t *cv, void const *data, size_t size)
static ssize_t import_caca(caca_canvas_t *cv, void const *data, size_t size)
{ {
uint8_t const *buf = (uint8_t const *)data; uint8_t const *buf = (uint8_t const *)data;
size_t control_size, data_size, expected_size; size_t control_size, data_size, expected_size;
@@ -284,12 +284,12 @@ static ssize_t import_caca(cucul_canvas_t *cv, void const *data, size_t size)
goto invalid_caca; goto invalid_caca;
} }


cucul_set_canvas_size(cv, 0, 0);
cucul_set_canvas_size(cv, xmax - xmin, ymax - ymin);
caca_set_canvas_size(cv, 0, 0);
caca_set_canvas_size(cv, xmax - xmin, ymax - ymin);


for (f = cucul_get_frame_count(cv); f--; )
for (f = caca_get_frame_count(cv); f--; )
{ {
cucul_free_frame(cv, f);
caca_free_frame(cv, f);
} }


for (offset = 0, f = 0; f < frames; f ++) for (offset = 0, f = 0; f < frames; f ++)
@@ -298,8 +298,8 @@ static ssize_t import_caca(cucul_canvas_t *cv, void const *data, size_t size)


width = sscanu32(buf + 4 + 16 + f * 32); width = sscanu32(buf + 4 + 16 + f * 32);
height = sscanu32(buf + 4 + 16 + f * 32 + 4); height = sscanu32(buf + 4 + 16 + f * 32 + 4);
cucul_create_frame(cv, f);
cucul_set_frame(cv, f);
caca_create_frame(cv, f);
caca_set_frame(cv, f);


cv->curattr = sscanu32(buf + 4 + 16 + f * 32 + 12); cv->curattr = sscanu32(buf + 4 + 16 + f * 32 + 12);
cv->frames[f].x = (int32_t)sscanu32(buf + 4 + 16 + f * 32 + 16); cv->frames[f].x = (int32_t)sscanu32(buf + 4 + 16 + f * 32 + 16);
@@ -314,9 +314,9 @@ static ssize_t import_caca(cucul_canvas_t *cv, void const *data, size_t size)
int x = (n % width) - cv->frames[f].handlex - xmin; int x = (n % width) - cv->frames[f].handlex - xmin;
int y = (n / width) - cv->frames[f].handley - ymin; int y = (n / width) - cv->frames[f].handley - ymin;


cucul_put_char(cv, x, y, sscanu32(buf + 4 + control_size
caca_put_char(cv, x, y, sscanu32(buf + 4 + control_size
+ offset + 8 * n)); + offset + 8 * n));
cucul_put_attr(cv, x, y, sscanu32(buf + 4 + control_size
caca_put_attr(cv, x, y, sscanu32(buf + 4 + control_size
+ offset + 8 * n + 4)); + offset + 8 * n + 4));
} }
offset += width * height * 8; offset += width * height * 8;
@@ -327,7 +327,7 @@ static ssize_t import_caca(cucul_canvas_t *cv, void const *data, size_t size)
cv->frames[f].handley = -ymin; cv->frames[f].handley = -ymin;
} }


cucul_set_frame(cv, 0);
caca_set_frame(cv, 0);


return 4 + control_size + data_size; return 4 + control_size + data_size;


@@ -336,12 +336,12 @@ invalid_caca:
return -1; return -1;
} }


static ssize_t import_text(cucul_canvas_t *cv, void const *data, size_t size)
static ssize_t import_text(caca_canvas_t *cv, void const *data, size_t size)
{ {
char const *text = (char const *)data; char const *text = (char const *)data;
unsigned int width = 0, height = 0, x = 0, y = 0, i; unsigned int width = 0, height = 0, x = 0, y = 0, i;


cucul_set_canvas_size(cv, width, height);
caca_set_canvas_size(cv, width, height);


for(i = 0; i < size; i++) for(i = 0; i < size; i++)
{ {
@@ -365,20 +365,20 @@ static ssize_t import_text(cucul_canvas_t *cv, void const *data, size_t size)
if(y >= height) if(y >= height)
height = y + 1; height = y + 1;


cucul_set_canvas_size(cv, width, height);
caca_set_canvas_size(cv, width, height);
} }


cucul_put_char(cv, x, y, ch);
caca_put_char(cv, x, y, ch);
x++; x++;
} }


if(y > height) if(y > height)
cucul_set_canvas_size(cv, width, height = y);
caca_set_canvas_size(cv, width, height = y);


return size; return size;
} }


static ssize_t import_ansi(cucul_canvas_t *cv, void const *data,
static ssize_t import_ansi(caca_canvas_t *cv, void const *data,
size_t size, int utf8) size_t size, int utf8)
{ {
struct import im; struct import im;
@@ -399,24 +399,24 @@ static ssize_t import_ansi(cucul_canvas_t *cv, void const *data,
} }
else else
{ {
cucul_set_canvas_size(cv, width = 80, height = 0);
caca_set_canvas_size(cv, width = 80, height = 0);
growx = 0; growx = 0;
growy = 1; growy = 1;
} }


if(utf8) if(utf8)
{ {
im.dfg = CUCUL_DEFAULT;
im.dbg = CUCUL_TRANSPARENT;
im.dfg = CACA_DEFAULT;
im.dbg = CACA_TRANSPARENT;
} }
else else
{ {
im.dfg = CUCUL_LIGHTGRAY;
im.dbg = CUCUL_BLACK;
im.dfg = CACA_LIGHTGRAY;
im.dbg = CACA_BLACK;
} }


cucul_set_color_ansi(cv, im.dfg, im.dbg);
im.clearattr = cucul_get_attr(cv, -1, -1);
caca_set_color_ansi(cv, im.dfg, im.dbg);
im.clearattr = caca_get_attr(cv, -1, -1);


ansi_parse_grcm(cv, &im, 1, &dummy); ansi_parse_grcm(cv, &im, 1, &dummy);


@@ -554,31 +554,31 @@ static ssize_t import_ansi(cucul_canvas_t *cv, void const *data,
x = (argc && argv[0] > 0) ? argv[0] - 1 : 0; x = (argc && argv[0] > 0) ? argv[0] - 1 : 0;
break; break;
case 'J': /* ED (0x4a) - Erase In Page */ case 'J': /* ED (0x4a) - Erase In Page */
savedattr = cucul_get_attr(cv, -1, -1);
cucul_set_attr(cv, im.clearattr);
savedattr = caca_get_attr(cv, -1, -1);
caca_set_attr(cv, im.clearattr);
if(!argc || argv[0] == 0) if(!argc || argv[0] == 0)
{ {
cucul_draw_line(cv, x, y, width, y, ' ');
cucul_fill_box(cv, 0, y + 1, width - 1, height - 1, ' ');
caca_draw_line(cv, x, y, width, y, ' ');
caca_fill_box(cv, 0, y + 1, width - 1, height - 1, ' ');
} }
else if(argv[0] == 1) else if(argv[0] == 1)
{ {
cucul_fill_box(cv, 0, 0, width - 1, y - 1, ' ');
cucul_draw_line(cv, 0, y, x, y, ' ');
caca_fill_box(cv, 0, 0, width - 1, y - 1, ' ');
caca_draw_line(cv, 0, y, x, y, ' ');
} }
else if(argv[0] == 2) else if(argv[0] == 2)
//x = y = 0; //x = y = 0;
cucul_fill_box(cv, 0, 0, width - 1, height - 1, ' ');
cucul_set_attr(cv, savedattr);
caca_fill_box(cv, 0, 0, width - 1, height - 1, ' ');
caca_set_attr(cv, savedattr);
break; break;
case 'K': /* EL (0x4b) - Erase In Line */ case 'K': /* EL (0x4b) - Erase In Line */
if(!argc || argv[0] == 0) if(!argc || argv[0] == 0)
cucul_draw_line(cv, x, y, width, y, ' ');
caca_draw_line(cv, x, y, width, y, ' ');
else if(argv[0] == 1) else if(argv[0] == 1)
cucul_draw_line(cv, 0, y, x, y, ' ');
caca_draw_line(cv, 0, y, x, y, ' ');
else if(argv[0] == 2) else if(argv[0] == 2)
if((unsigned int)x < width) if((unsigned int)x < width)
cucul_draw_line(cv, x, y, width - 1, y, ' ');
caca_draw_line(cv, x, y, width - 1, y, ' ');
//x = width; //x = width;
break; break;
case 'P': /* DCH (0x50) - Delete Character */ case 'P': /* DCH (0x50) - Delete Character */
@@ -586,25 +586,25 @@ static ssize_t import_ansi(cucul_canvas_t *cv, void const *data,
argv[0] = 1; /* echo -ne 'foobar\r\e[0P\n' */ argv[0] = 1; /* echo -ne 'foobar\r\e[0P\n' */
for(j = 0; (unsigned int)(j + argv[0]) < width; j++) for(j = 0; (unsigned int)(j + argv[0]) < width; j++)
{ {
cucul_put_char(cv, j, y,
cucul_get_char(cv, j + argv[0], y));
cucul_put_attr(cv, j, y,
cucul_get_attr(cv, j + argv[0], y));
caca_put_char(cv, j, y,
caca_get_char(cv, j + argv[0], y));
caca_put_attr(cv, j, y,
caca_get_attr(cv, j + argv[0], y));
} }
#if 0 #if 0
savedattr = cucul_get_attr(cv, -1, -1);
cucul_set_attr(cv, im.clearattr);
savedattr = caca_get_attr(cv, -1, -1);
caca_set_attr(cv, im.clearattr);
for( ; (unsigned int)j < width; j++) for( ; (unsigned int)j < width; j++)
cucul_put_char(cv, j, y, ' ');
cucul_set_attr(cv, savedattr);
caca_put_char(cv, j, y, ' ');
caca_set_attr(cv, savedattr);
#endif #endif
case 'X': /* ECH (0x58) - Erase Character */ case 'X': /* ECH (0x58) - Erase Character */
if(argc && argv[0]) if(argc && argv[0])
{ {
savedattr = cucul_get_attr(cv, -1, -1);
cucul_set_attr(cv, im.clearattr);
cucul_draw_line(cv, x, y, x + argv[0] - 1, y, ' ');
cucul_set_attr(cv, savedattr);
savedattr = caca_get_attr(cv, -1, -1);
caca_set_attr(cv, im.clearattr);
caca_draw_line(cv, x, y, x + argv[0] - 1, y, ' ');
caca_set_attr(cv, savedattr);
} }
case 'd': /* VPA (0x64) - Line Position Absolute */ case 'd': /* VPA (0x64) - Line Position Absolute */
y = (argc && argv[0] > 0) ? argv[0] - 1 : 0; y = (argc && argv[0] > 0) ? argv[0] - 1 : 0;
@@ -683,14 +683,14 @@ static ssize_t import_ansi(cucul_canvas_t *cv, void const *data,
size_t bytes; size_t bytes;


if(i + 6 < size) if(i + 6 < size)
ch = cucul_utf8_to_utf32((char const *)(buffer + i), &bytes);
ch = caca_utf8_to_utf32((char const *)(buffer + i), &bytes);
else else
{ {
/* Add a trailing zero to what we're going to read */ /* Add a trailing zero to what we're going to read */
char tmp[7]; char tmp[7];
memcpy(tmp, buffer + i, size - i); memcpy(tmp, buffer + i, size - i);
tmp[size - i] = '\0'; tmp[size - i] = '\0';
ch = cucul_utf8_to_utf32(tmp, &bytes);
ch = caca_utf8_to_utf32(tmp, &bytes);
} }


if(!bytes) if(!bytes)
@@ -699,12 +699,12 @@ static ssize_t import_ansi(cucul_canvas_t *cv, void const *data,
ch = buffer[i]; ch = buffer[i];
bytes = 1; bytes = 1;
} }
wch = cucul_utf32_is_fullwidth(ch) ? 2 : 1;
wch = caca_utf32_is_fullwidth(ch) ? 2 : 1;
skip += bytes - 1; skip += bytes - 1;
} }
else else
{ {
ch = cucul_cp437_to_utf32(buffer[i]);
ch = caca_cp437_to_utf32(buffer[i]);
wch = 1; wch = 1;
} }


@@ -713,10 +713,10 @@ static ssize_t import_ansi(cucul_canvas_t *cv, void const *data,
{ {
if(growx) if(growx)
{ {
savedattr = cucul_get_attr(cv, -1, -1);
cucul_set_attr(cv, im.clearattr);
cucul_set_canvas_size(cv, width = x + wch, height);
cucul_set_attr(cv, savedattr);
savedattr = caca_get_attr(cv, -1, -1);
caca_set_attr(cv, im.clearattr);
caca_set_canvas_size(cv, width = x + wch, height);
caca_set_attr(cv, savedattr);
} }
else else
{ {
@@ -728,11 +728,11 @@ static ssize_t import_ansi(cucul_canvas_t *cv, void const *data,
/* Scroll or grow vertically */ /* Scroll or grow vertically */
if((unsigned int)y >= height) if((unsigned int)y >= height)
{ {
savedattr = cucul_get_attr(cv, -1, -1);
cucul_set_attr(cv, im.clearattr);
savedattr = caca_get_attr(cv, -1, -1);
caca_set_attr(cv, im.clearattr);
if(growy) if(growy)
{ {
cucul_set_canvas_size(cv, width, height = y + 1);
caca_set_canvas_size(cv, width, height = y + 1);
} }
else else
{ {
@@ -745,63 +745,63 @@ static ssize_t import_ansi(cucul_canvas_t *cv, void const *data,
memcpy(cv->chars + j * cv->width, memcpy(cv->chars + j * cv->width,
cv->chars + (j + lines) * cv->width, cv->width * 4); cv->chars + (j + lines) * cv->width, cv->width * 4);
} }
cucul_fill_box(cv, 0, height - lines,
caca_fill_box(cv, 0, height - lines,
cv->width - 1, height - 1, ' '); cv->width - 1, height - 1, ' ');
y -= lines; y -= lines;
} }
cucul_set_attr(cv, savedattr);
caca_set_attr(cv, savedattr);
} }


/* Now paste our character, if any */ /* Now paste our character, if any */
if(wch) if(wch)
{ {
cucul_put_char(cv, x, y, ch);
caca_put_char(cv, x, y, ch);
x += wch; x += wch;
} }
} }


if(growy && (unsigned int)y > height) if(growy && (unsigned int)y > height)
{ {
savedattr = cucul_get_attr(cv, -1, -1);
cucul_set_attr(cv, im.clearattr);
cucul_set_canvas_size(cv, width, height = y);
cucul_set_attr(cv, savedattr);
savedattr = caca_get_attr(cv, -1, -1);
caca_set_attr(cv, im.clearattr);
caca_set_canvas_size(cv, width, height = y);
caca_set_attr(cv, savedattr);
} }


cv->frames[cv->frame].x = x; cv->frames[cv->frame].x = x;
cv->frames[cv->frame].y = y; cv->frames[cv->frame].y = y;


// if(utf8) // if(utf8)
// cucul_set_attr(cv, savedattr);
// caca_set_attr(cv, savedattr);


return i; return i;
} }


/* XXX : ANSI loader helper */ /* XXX : ANSI loader helper */


static void ansi_parse_grcm(cucul_canvas_t *cv, struct import *im,
static void ansi_parse_grcm(caca_canvas_t *cv, struct import *im,
unsigned int argc, unsigned int const *argv) unsigned int argc, unsigned int const *argv)
{ {
static uint8_t const ansi2cucul[] =
static uint8_t const ansi2caca[] =
{ {
CUCUL_BLACK, CUCUL_RED, CUCUL_GREEN, CUCUL_BROWN,
CUCUL_BLUE, CUCUL_MAGENTA, CUCUL_CYAN, CUCUL_LIGHTGRAY
CACA_BLACK, CACA_RED, CACA_GREEN, CACA_BROWN,
CACA_BLUE, CACA_MAGENTA, CACA_CYAN, CACA_LIGHTGRAY
}; };


unsigned int j; unsigned int j;
uint8_t efg, ebg; /* Effective (libcucul) fg/bg */
uint8_t efg, ebg; /* Effective (libcaca) fg/bg */


for(j = 0; j < argc; j++) for(j = 0; j < argc; j++)
{ {
/* Defined in ECMA-48 8.3.117: SGR - SELECT GRAPHIC RENDITION */ /* Defined in ECMA-48 8.3.117: SGR - SELECT GRAPHIC RENDITION */
if(argv[j] >= 30 && argv[j] <= 37) if(argv[j] >= 30 && argv[j] <= 37)
im->fg = ansi2cucul[argv[j] - 30];
im->fg = ansi2caca[argv[j] - 30];
else if(argv[j] >= 40 && argv[j] <= 47) else if(argv[j] >= 40 && argv[j] <= 47)
im->bg = ansi2cucul[argv[j] - 40];
im->bg = ansi2caca[argv[j] - 40];
else if(argv[j] >= 90 && argv[j] <= 97) else if(argv[j] >= 90 && argv[j] <= 97)
im->fg = ansi2cucul[argv[j] - 90] + 8;
im->fg = ansi2caca[argv[j] - 90] + 8;
else if(argv[j] >= 100 && argv[j] <= 107) else if(argv[j] >= 100 && argv[j] <= 107)
im->bg = ansi2cucul[argv[j] - 100] + 8;
im->bg = ansi2caca[argv[j] - 100] + 8;
else switch(argv[j]) else switch(argv[j])
{ {
case 0: /* default rendition */ case 0: /* default rendition */
@@ -892,7 +892,7 @@ static void ansi_parse_grcm(cucul_canvas_t *cv, struct import *im,


if(im->concealed) if(im->concealed)
{ {
efg = ebg = CUCUL_TRANSPARENT;
efg = ebg = CACA_TRANSPARENT;
} }
else else
{ {
@@ -903,11 +903,11 @@ static void ansi_parse_grcm(cucul_canvas_t *cv, struct import *im,
{ {
if(efg < 8) if(efg < 8)
efg += 8; efg += 8;
else if(efg == CUCUL_DEFAULT)
efg = CUCUL_WHITE;
else if(efg == CACA_DEFAULT)
efg = CACA_WHITE;
} }
} }


cucul_set_color_ansi(cv, efg, ebg);
caca_set_color_ansi(cv, efg, ebg);
} }



cucul/legacy.c → caca/legacy.c View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Canvas for ultrafast compositing of Unicode letters
* libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -25,8 +25,15 @@
# include <string.h> # include <string.h>
#endif #endif


#include "cucul.h"
#include "cucul_internals.h"
#include "caca.h"
#include "caca_internals.h"

struct cucul_buffer
{
size_t size;
char *data;
int user_data;
};


/* /*
* Functions from canvas.c * Functions from canvas.c
@@ -34,17 +41,17 @@


int cucul_putchar(cucul_canvas_t *cv, int x, int y, unsigned long int ch) int cucul_putchar(cucul_canvas_t *cv, int x, int y, unsigned long int ch)
{ {
return cucul_put_char(cv, x, y, ch);
return caca_put_char(cv, x, y, ch);
} }


unsigned long int cucul_getchar(cucul_canvas_t *cv, int x, int y) unsigned long int cucul_getchar(cucul_canvas_t *cv, int x, int y)
{ {
return cucul_get_char(cv, x, y);
return caca_get_char(cv, x, y);
} }


int cucul_putstr(cucul_canvas_t *cv, int x, int y, char const *s) int cucul_putstr(cucul_canvas_t *cv, int x, int y, char const *s)
{ {
return cucul_put_str(cv, x, y, s);
return caca_put_str(cv, x, y, s);
} }


/* /*
@@ -53,12 +60,12 @@ int cucul_putstr(cucul_canvas_t *cv, int x, int y, char const *s)


int cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg) int cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg)
{ {
return cucul_set_color_ansi(cv, fg, bg);
return caca_set_color_ansi(cv, fg, bg);
} }


int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg) int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg)
{ {
return cucul_set_color_argb(cv, fg, bg);
return caca_set_color_argb(cv, fg, bg);
} }


/* /*
@@ -66,22 +73,22 @@ int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg)
*/ */
int cucul_set_dither_invert(cucul_dither_t *d, int value) int cucul_set_dither_invert(cucul_dither_t *d, int value)
{ {
float gamma = cucul_get_dither_gamma(d);
float gamma = caca_get_dither_gamma(d);


if(gamma * (value ? -1 : 1) < 0) if(gamma * (value ? -1 : 1) < 0)
cucul_set_dither_gamma(d, -gamma);
caca_set_dither_gamma(d, -gamma);


return 0; return 0;
} }


int cucul_set_dither_mode(cucul_dither_t *d, char const *s) int cucul_set_dither_mode(cucul_dither_t *d, char const *s)
{ {
return cucul_set_dither_algorithm(d, s);
return caca_set_dither_algorithm(d, s);
} }


char const * const * cucul_get_dither_mode_list(cucul_dither_t const *d) char const * const * cucul_get_dither_mode_list(cucul_dither_t const *d)
{ {
return cucul_get_dither_algorithm_list(d);
return caca_get_dither_algorithm_list(d);
} }


/* /*
@@ -90,12 +97,12 @@ char const * const * cucul_get_dither_mode_list(cucul_dither_t const *d)


cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *buf, char const *format) cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *buf, char const *format)
{ {
cucul_canvas_t *cv = cucul_create_canvas(0, 0);
int ret = cucul_import_memory(cv, (unsigned char const *)buf->data,
caca_canvas_t *cv = caca_create_canvas(0, 0);
int ret = caca_import_memory(cv, (unsigned char const *)buf->data,
buf->size, format); buf->size, format);
if(ret < 0) if(ret < 0)
{ {
cucul_free_canvas(cv);
caca_free_canvas(cv);
return NULL; return NULL;
} }


@@ -117,7 +124,7 @@ cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *cv, char const *format)
return NULL; return NULL;
} }


ex->data = cucul_export_memory(cv, format, &ex->size);
ex->data = caca_export_memory(cv, format, &ex->size);
if(!ex->data) if(!ex->data)
{ {
free(ex); free(ex);
@@ -135,22 +142,22 @@ cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *cv, char const *format)


unsigned int cucul_get_canvas_frame_count(cucul_canvas_t *cv) unsigned int cucul_get_canvas_frame_count(cucul_canvas_t *cv)
{ {
return cucul_get_frame_count(cv);
return caca_get_frame_count(cv);
} }


int cucul_set_canvas_frame(cucul_canvas_t *cv, unsigned int id) int cucul_set_canvas_frame(cucul_canvas_t *cv, unsigned int id)
{ {
return cucul_set_frame(cv, id);
return caca_set_frame(cv, id);
} }


int cucul_create_canvas_frame(cucul_canvas_t *cv, unsigned int id) int cucul_create_canvas_frame(cucul_canvas_t *cv, unsigned int id)
{ {
return cucul_create_frame(cv, id);
return caca_create_frame(cv, id);
} }


int cucul_free_canvas_frame(cucul_canvas_t *cv, unsigned int id) int cucul_free_canvas_frame(cucul_canvas_t *cv, unsigned int id)
{ {
return cucul_free_frame(cv, id);
return caca_free_frame(cv, id);
} }


/* /*
@@ -175,40 +182,40 @@ cucul_buffer_t *cucul_load_memory(void *data, unsigned long int size)
cucul_buffer_t *cucul_load_file(char const *file) cucul_buffer_t *cucul_load_file(char const *file)
{ {
cucul_buffer_t *buf; cucul_buffer_t *buf;
cucul_file_t *f;
caca_file_t *f;
int ret; int ret;


f = cucul_file_open(file, "rb");
f = caca_file_open(file, "rb");
if(!f) if(!f)
return NULL; return NULL;


buf = malloc(sizeof(cucul_buffer_t)); buf = malloc(sizeof(cucul_buffer_t));
if(!buf) if(!buf)
{ {
cucul_file_close(f);
caca_file_close(f);
return NULL; return NULL;
} }


buf->data = NULL; buf->data = NULL;
buf->size = 0; buf->size = 0;


while(!cucul_file_eof(f))
while(!caca_file_eof(f))
{ {
buf->data = realloc(buf->data, buf->size + 1024); buf->data = realloc(buf->data, buf->size + 1024);
if(!buf->data) if(!buf->data)
{ {
int saved_errno = geterrno(); int saved_errno = geterrno();
free(buf); free(buf);
cucul_file_close(f);
caca_file_close(f);
seterrno(saved_errno); seterrno(saved_errno);
return NULL; return NULL;
} }


ret = cucul_file_read(f, buf->data + buf->size, 1024);
ret = caca_file_read(f, buf->data + buf->size, 1024);
if(ret >= 0) if(ret >= 0)
buf->size += ret; buf->size += ret;
} }
cucul_file_close(f);
caca_file_close(f);


return buf; return buf;
} }
@@ -239,6 +246,6 @@ int cucul_free_buffer(cucul_buffer_t *buf)


int cucul_rotate(cucul_canvas_t *cv) int cucul_rotate(cucul_canvas_t *cv)
{ {
return cucul_rotate_180(cv);
return caca_rotate_180(cv);
} }



cucul/line.c → caca/line.c View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Canvas for ultrafast compositing of Unicode letters
* libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -23,8 +23,8 @@
# include <stdlib.h> # include <stdlib.h>
#endif #endif


#include "cucul.h"
#include "cucul_internals.h"
#include "caca.h"
#include "caca_internals.h"


#if !defined(_DOXYGEN_SKIP_ME) #if !defined(_DOXYGEN_SKIP_ME)
struct line struct line
@@ -32,20 +32,20 @@ struct line
int x1, y1; int x1, y1;
int x2, y2; int x2, y2;
uint32_t ch; uint32_t ch;
void (*draw) (cucul_canvas_t *, struct line*);
void (*draw) (caca_canvas_t *, struct line*);
}; };
#endif #endif


static void clip_line(cucul_canvas_t*, struct line*);
static uint8_t clip_bits(cucul_canvas_t*, int, int);
static void draw_solid_line(cucul_canvas_t*, struct line*);
static void draw_thin_line(cucul_canvas_t*, struct line*);
static void clip_line(caca_canvas_t*, struct line*);
static uint8_t clip_bits(caca_canvas_t*, int, int);
static void draw_solid_line(caca_canvas_t*, struct line*);
static void draw_thin_line(caca_canvas_t*, struct line*);


/** \brief Draw a line on the canvas using the given character. /** \brief Draw a line on the canvas using the given character.
* *
* This function never fails. * This function never fails.
* *
* \param cv The handle to the libcucul canvas.
* \param cv The handle to the libcaca canvas.
* \param x1 X coordinate of the first point. * \param x1 X coordinate of the first point.
* \param y1 Y coordinate of the first point. * \param y1 Y coordinate of the first point.
* \param x2 X coordinate of the second point. * \param x2 X coordinate of the second point.
@@ -53,7 +53,7 @@ static void draw_thin_line(cucul_canvas_t*, struct line*);
* \param ch UTF-32 character to be used to draw the line. * \param ch UTF-32 character to be used to draw the line.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_draw_line(cucul_canvas_t *cv, int x1, int y1, int x2, int y2,
int caca_draw_line(caca_canvas_t *cv, int x1, int y1, int x2, int y2,
uint32_t ch) uint32_t ch)
{ {
struct line s; struct line s;
@@ -77,14 +77,14 @@ int cucul_draw_line(cucul_canvas_t *cv, int x1, int y1, int x2, int y2,
* *
* This function never fails. * This function never fails.
* *
* \param cv The handle to the libcucul canvas.
* \param cv The handle to the libcaca canvas.
* \param x Array of X coordinates. Must have \p n + 1 elements. * \param x Array of X coordinates. Must have \p n + 1 elements.
* \param y Array of Y coordinates. Must have \p n + 1 elements. * \param y Array of Y coordinates. Must have \p n + 1 elements.
* \param n Number of lines to draw. * \param n Number of lines to draw.
* \param ch UTF-32 character to be used to draw the lines. * \param ch UTF-32 character to be used to draw the lines.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_draw_polyline(cucul_canvas_t *cv, int const x[], int const y[],
int caca_draw_polyline(caca_canvas_t *cv, int const x[], int const y[],
int n, uint32_t ch) int n, uint32_t ch)
{ {
int i; int i;
@@ -108,14 +108,14 @@ int cucul_draw_polyline(cucul_canvas_t *cv, int const x[], int const y[],
* *
* This function never fails. * This function never fails.
* *
* \param cv The handle to the libcucul canvas.
* \param cv The handle to the libcaca canvas.
* \param x1 X coordinate of the first point. * \param x1 X coordinate of the first point.
* \param y1 Y coordinate of the first point. * \param y1 Y coordinate of the first point.
* \param x2 X coordinate of the second point. * \param x2 X coordinate of the second point.
* \param y2 Y coordinate of the second point. * \param y2 Y coordinate of the second point.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_draw_thin_line(cucul_canvas_t *cv, int x1, int y1, int x2, int y2)
int caca_draw_thin_line(caca_canvas_t *cv, int x1, int y1, int x2, int y2)
{ {
struct line s; struct line s;
s.x1 = x1; s.x1 = x1;
@@ -137,13 +137,13 @@ int cucul_draw_thin_line(cucul_canvas_t *cv, int x1, int y1, int x2, int y2)
* *
* This function never fails. * This function never fails.
* *
* \param cv The handle to the libcucul canvas.
* \param cv The handle to the libcaca canvas.
* \param x Array of X coordinates. Must have \p n + 1 elements. * \param x Array of X coordinates. Must have \p n + 1 elements.
* \param y Array of Y coordinates. Must have \p n + 1 elements. * \param y Array of Y coordinates. Must have \p n + 1 elements.
* \param n Number of lines to draw. * \param n Number of lines to draw.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_draw_thin_polyline(cucul_canvas_t *cv, int const x[], int const y[],
int caca_draw_thin_polyline(caca_canvas_t *cv, int const x[], int const y[],
int n) int n)
{ {
int i; int i;
@@ -167,7 +167,7 @@ int cucul_draw_thin_polyline(cucul_canvas_t *cv, int const x[], int const y[],
*/ */


/* Generic Cohen-Sutherland line clipping function. */ /* Generic Cohen-Sutherland line clipping function. */
static void clip_line(cucul_canvas_t *cv, struct line* s)
static void clip_line(caca_canvas_t *cv, struct line* s)
{ {
uint8_t bits1, bits2; uint8_t bits1, bits2;


@@ -219,7 +219,7 @@ static void clip_line(cucul_canvas_t *cv, struct line* s)
} }


/* Helper function for clip_line(). */ /* Helper function for clip_line(). */
static uint8_t clip_bits(cucul_canvas_t *cv, int x, int y)
static uint8_t clip_bits(caca_canvas_t *cv, int x, int y)
{ {
uint8_t b = 0; uint8_t b = 0;


@@ -238,7 +238,7 @@ static uint8_t clip_bits(cucul_canvas_t *cv, int x, int y)


/* Solid line drawing function, using Bresenham's mid-point line /* Solid line drawing function, using Bresenham's mid-point line
* scan-conversion algorithm. */ * scan-conversion algorithm. */
static void draw_solid_line(cucul_canvas_t *cv, struct line* s)
static void draw_solid_line(caca_canvas_t *cv, struct line* s)
{ {
int x1, y1, x2, y2; int x1, y1, x2, y2;
int dx, dy; int dx, dy;
@@ -260,7 +260,7 @@ static void draw_solid_line(cucul_canvas_t *cv, struct line* s)


for(; dx>=0; dx--) for(; dx>=0; dx--)
{ {
cucul_put_char(cv, x1, y1, s->ch);
caca_put_char(cv, x1, y1, s->ch);
if(delta > 0) if(delta > 0)
{ {
x1 += xinc; x1 += xinc;
@@ -282,7 +282,7 @@ static void draw_solid_line(cucul_canvas_t *cv, struct line* s)


for(; dy >= 0; dy--) for(; dy >= 0; dy--)
{ {
cucul_put_char(cv, x1, y1, s->ch);
caca_put_char(cv, x1, y1, s->ch);
if(delta > 0) if(delta > 0)
{ {
x1 += xinc; x1 += xinc;
@@ -300,7 +300,7 @@ static void draw_solid_line(cucul_canvas_t *cv, struct line* s)


/* Thin line drawing function, using Bresenham's mid-point line /* Thin line drawing function, using Bresenham's mid-point line
* scan-conversion algorithm and ASCII art graphics. */ * scan-conversion algorithm and ASCII art graphics. */
static void draw_thin_line(cucul_canvas_t *cv, struct line* s)
static void draw_thin_line(caca_canvas_t *cv, struct line* s)
{ {
uint32_t charmapx[2], charmapy[2]; uint32_t charmapx[2], charmapy[2];
int x1, y1, x2, y2; int x1, y1, x2, y2;
@@ -347,7 +347,7 @@ static void draw_thin_line(cucul_canvas_t *cv, struct line* s)
{ {
if(delta > 0) if(delta > 0)
{ {
cucul_put_char(cv, x1, y1, charmapy[1]);
caca_put_char(cv, x1, y1, charmapy[1]);
x1++; x1++;
y1 += yinc; y1 += yinc;
delta += dpru; delta += dpru;
@@ -356,9 +356,9 @@ static void draw_thin_line(cucul_canvas_t *cv, struct line* s)
else else
{ {
if(prev) if(prev)
cucul_put_char(cv, x1, y1, charmapy[0]);
caca_put_char(cv, x1, y1, charmapy[0]);
else else
cucul_put_char(cv, x1, y1, '-');
caca_put_char(cv, x1, y1, '-');
x1++; x1++;
delta += dpr; delta += dpr;
prev = 0; prev = 0;
@@ -375,15 +375,15 @@ static void draw_thin_line(cucul_canvas_t *cv, struct line* s)
{ {
if(delta > 0) if(delta > 0)
{ {
cucul_put_char(cv, x1, y1, charmapx[0]);
cucul_put_char(cv, x1 + 1, y1, charmapx[1]);
caca_put_char(cv, x1, y1, charmapx[0]);
caca_put_char(cv, x1 + 1, y1, charmapx[1]);
x1++; x1++;
y1 += yinc; y1 += yinc;
delta += dpru; delta += dpru;
} }
else else
{ {
cucul_put_char(cv, x1, y1, '|');
caca_put_char(cv, x1, y1, '|');
y1 += yinc; y1 += yinc;
delta += dpr; delta += dpr;
} }

cucul/mono9.data → caca/mono9.data View File

@@ -1,4 +1,4 @@
/* libcucul font file
/* libcaca font file
* "Monospace 9": 96 dpi, 4 bpp, 7x15/14x15 glyphs * "Monospace 9": 96 dpi, 4 bpp, 7x15/14x15 glyphs
* Automatically generated by tools/makefont.c: * Automatically generated by tools/makefont.c:
* tools/makefont mono9 "Monospace 9" 96 4 * tools/makefont mono9 "Monospace 9" 96 4

cucul/monobold12.data → caca/monobold12.data View File

@@ -1,4 +1,4 @@
/* libcucul font file
/* libcaca font file
* "Monospace Bold 12": 96 dpi, 4 bpp, 10x19/20x19 glyphs * "Monospace Bold 12": 96 dpi, 4 bpp, 10x19/20x19 glyphs
* Automatically generated by tools/makefont.c: * Automatically generated by tools/makefont.c:
* tools/makefont monobold12 "Monospace Bold 12" 96 4 * tools/makefont monobold12 "Monospace Bold 12" 96 4

cucul/canvas.c → caca/string.c View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Canvas for ultrafast compositing of Unicode letters
* libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -35,8 +35,8 @@
# endif # endif
#endif #endif


#include "cucul.h"
#include "cucul_internals.h"
#include "caca.h"
#include "caca_internals.h"


/** \brief Set cursor position. /** \brief Set cursor position.
* *
@@ -46,12 +46,12 @@
* *
* This function never fails. * This function never fails.
* *
* \param cv A handle to the libcucul canvas.
* \param cv A handle to the libcaca canvas.
* \param x X cursor coordinate. * \param x X cursor coordinate.
* \param y Y cursor coordinate. * \param y Y cursor coordinate.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_gotoxy(cucul_canvas_t *cv, int x, int y)
int caca_gotoxy(caca_canvas_t *cv, int x, int y)
{ {
cv->frames[cv->frame].x = x; cv->frames[cv->frame].x = x;
cv->frames[cv->frame].y = y; cv->frames[cv->frame].y = y;
@@ -65,10 +65,10 @@ int cucul_gotoxy(cucul_canvas_t *cv, int x, int y)
* *
* This function never fails. * This function never fails.
* *
* \param cv A handle to the libcucul canvas.
* \param cv A handle to the libcaca canvas.
* \return The cursor's X coordinate. * \return The cursor's X coordinate.
*/ */
int cucul_get_cursor_x(cucul_canvas_t const *cv)
int caca_get_cursor_x(caca_canvas_t const *cv)
{ {
return cv->frames[cv->frame].x; return cv->frames[cv->frame].x;
} }
@@ -79,10 +79,10 @@ int cucul_get_cursor_x(cucul_canvas_t const *cv)
* *
* This function never fails. * This function never fails.
* *
* \param cv A handle to the libcucul canvas.
* \param cv A handle to the libcaca canvas.
* \return The cursor's Y coordinate. * \return The cursor's Y coordinate.
*/ */
int cucul_get_cursor_y(cucul_canvas_t const *cv)
int caca_get_cursor_y(caca_canvas_t const *cv)
{ {
return cv->frames[cv->frame].y; return cv->frames[cv->frame].y;
} }
@@ -99,17 +99,17 @@ int cucul_get_cursor_y(cucul_canvas_t const *cv)
* *
* The behaviour when printing non-printable characters or invalid UTF-32 * The behaviour when printing non-printable characters or invalid UTF-32
* characters is undefined. To print a sequence of bytes forming an UTF-8 * characters is undefined. To print a sequence of bytes forming an UTF-8
* character instead of an UTF-32 character, use the cucul_put_str() function.
* character instead of an UTF-32 character, use the caca_put_str() function.
* *
* This function never fails. * This function never fails.
* *
* \param cv A handle to the libcucul canvas.
* \param cv A handle to the libcaca canvas.
* \param x X coordinate. * \param x X coordinate.
* \param y Y coordinate. * \param y Y coordinate.
* \param ch The character to print. * \param ch The character to print.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_put_char(cucul_canvas_t *cv, int x, int y, uint32_t ch)
int caca_put_char(caca_canvas_t *cv, int x, int y, uint32_t ch)
{ {
uint32_t *curchar, *curattr, attr; uint32_t *curchar, *curattr, attr;
int fullwidth; int fullwidth;
@@ -117,10 +117,10 @@ int cucul_put_char(cucul_canvas_t *cv, int x, int y, uint32_t ch)
if(x >= (int)cv->width || y < 0 || y >= (int)cv->height) if(x >= (int)cv->width || y < 0 || y >= (int)cv->height)
return 0; return 0;


if(ch == CUCUL_MAGIC_FULLWIDTH)
if(ch == CACA_MAGIC_FULLWIDTH)
return 0; return 0;


fullwidth = cucul_utf32_is_fullwidth(ch);
fullwidth = caca_utf32_is_fullwidth(ch);


if(x == -1 && fullwidth) if(x == -1 && fullwidth)
{ {
@@ -137,7 +137,7 @@ int cucul_put_char(cucul_canvas_t *cv, int x, int y, uint32_t ch)


/* When overwriting the right part of a fullwidth character, /* When overwriting the right part of a fullwidth character,
* replace its left part with a space. */ * replace its left part with a space. */
if(x && curchar[0] == CUCUL_MAGIC_FULLWIDTH)
if(x && curchar[0] == CACA_MAGIC_FULLWIDTH)
curchar[-1] = ' '; curchar[-1] = ' ';


if(fullwidth) if(fullwidth)
@@ -148,10 +148,10 @@ int cucul_put_char(cucul_canvas_t *cv, int x, int y, uint32_t ch)
{ {
/* When overwriting the left part of a fullwidth character, /* When overwriting the left part of a fullwidth character,
* replace its right part with a space. */ * replace its right part with a space. */
if(x + 2 < (int)cv->width && curchar[2] == CUCUL_MAGIC_FULLWIDTH)
if(x + 2 < (int)cv->width && curchar[2] == CACA_MAGIC_FULLWIDTH)
curchar[2] = ' '; curchar[2] = ' ';


curchar[1] = CUCUL_MAGIC_FULLWIDTH;
curchar[1] = CACA_MAGIC_FULLWIDTH;
curattr[1] = attr; curattr[1] = attr;
} }
} }
@@ -159,7 +159,7 @@ int cucul_put_char(cucul_canvas_t *cv, int x, int y, uint32_t ch)
{ {
/* When overwriting the left part of a fullwidth character, /* When overwriting the left part of a fullwidth character,
* replace its right part with a space. */ * replace its right part with a space. */
if(x + 1 != (int)cv->width && curchar[1] == CUCUL_MAGIC_FULLWIDTH)
if(x + 1 != (int)cv->width && curchar[1] == CACA_MAGIC_FULLWIDTH)
curchar[1] = ' '; curchar[1] = ' ';
} }


@@ -179,19 +179,19 @@ int cucul_put_char(cucul_canvas_t *cv, int x, int y, uint32_t ch)
* If the coordinates are outside the canvas boundaries, a space (0x20) * If the coordinates are outside the canvas boundaries, a space (0x20)
* is returned. * is returned.
* *
* A special exception is when CUCUL_MAGIC_FULLWIDTH is returned. This
* A special exception is when CACA_MAGIC_FULLWIDTH is returned. This
* value is guaranteed not to be a valid Unicode character, and indicates * value is guaranteed not to be a valid Unicode character, and indicates
* that the character at the left of the requested one is a fullwidth * that the character at the left of the requested one is a fullwidth
* character. * character.
* *
* This function never fails. * This function never fails.
* *
* \param cv A handle to the libcucul canvas.
* \param cv A handle to the libcaca canvas.
* \param x X coordinate. * \param x X coordinate.
* \param y Y coordinate. * \param y Y coordinate.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
uint32_t cucul_get_char(cucul_canvas_t const *cv, int x, int y)
uint32_t caca_get_char(caca_canvas_t const *cv, int x, int y)
{ {
if(x < 0 || x >= (int)cv->width || y < 0 || y >= (int)cv->height) if(x < 0 || x >= (int)cv->width || y < 0 || y >= (int)cv->height)
return ' '; return ' ';
@@ -206,18 +206,18 @@ uint32_t cucul_get_char(cucul_canvas_t const *cv, int x, int y)
* canvas boundaries (eg. a negative Y coordinate) and the string will * canvas boundaries (eg. a negative Y coordinate) and the string will
* be cropped accordingly if it is too long. * be cropped accordingly if it is too long.
* *
* See cucul_put_char() for more information on how fullwidth characters
* See caca_put_char() for more information on how fullwidth characters
* are handled when overwriting each other or at the canvas' boundaries. * are handled when overwriting each other or at the canvas' boundaries.
* *
* This function never fails. * This function never fails.
* *
* \param cv A handle to the libcucul canvas.
* \param cv A handle to the libcaca canvas.
* \param x X coordinate. * \param x X coordinate.
* \param y Y coordinate. * \param y Y coordinate.
* \param s The string to print. * \param s The string to print.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_put_str(cucul_canvas_t *cv, int x, int y, char const *s)
int caca_put_str(caca_canvas_t *cv, int x, int y, char const *s)
{ {
size_t rd; size_t rd;


@@ -226,15 +226,15 @@ int cucul_put_str(cucul_canvas_t *cv, int x, int y, char const *s)


while(*s && x < -1) while(*s && x < -1)
{ {
x += cucul_utf32_is_fullwidth(cucul_utf8_to_utf32(s, &rd)) ? 2 : 1;
x += caca_utf32_is_fullwidth(caca_utf8_to_utf32(s, &rd)) ? 2 : 1;
s += rd; s += rd;
} }


while(*s && x < (int)cv->width) while(*s && x < (int)cv->width)
{ {
uint32_t ch = cucul_utf8_to_utf32(s, &rd);
cucul_put_char(cv, x, y, ch);
x += cucul_utf32_is_fullwidth(ch) ? 2 : 1;
uint32_t ch = caca_utf8_to_utf32(s, &rd);
caca_put_char(cv, x, y, ch);
x += caca_utf32_is_fullwidth(ch) ? 2 : 1;
s += rd; s += rd;
} }


@@ -251,14 +251,14 @@ int cucul_put_str(cucul_canvas_t *cv, int x, int y, char const *s)
* *
* This function never fails. * This function never fails.
* *
* \param cv A handle to the libcucul canvas.
* \param cv A handle to the libcaca canvas.
* \param x X coordinate. * \param x X coordinate.
* \param y Y coordinate. * \param y Y coordinate.
* \param format The format string to print. * \param format The format string to print.
* \param ... Arguments to the format string. * \param ... Arguments to the format string.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_printf(cucul_canvas_t *cv, int x, int y, char const *format, ...)
int caca_printf(caca_canvas_t *cv, int x, int y, char const *format, ...)
{ {
char tmp[BUFSIZ]; char tmp[BUFSIZ];
char *buf = tmp; char *buf = tmp;
@@ -279,7 +279,7 @@ int cucul_printf(cucul_canvas_t *cv, int x, int y, char const *format, ...)
buf[cv->width - x] = '\0'; buf[cv->width - x] = '\0';
va_end(args); va_end(args);


cucul_put_str(cv, x, y, buf);
caca_put_str(cv, x, y, buf);


if(buf != tmp) if(buf != tmp)
free(buf); free(buf);
@@ -296,7 +296,7 @@ int cucul_printf(cucul_canvas_t *cv, int x, int y, char const *format, ...)
* \param cv The canvas to clear. * \param cv The canvas to clear.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_clear_canvas(cucul_canvas_t *cv)
int caca_clear_canvas(caca_canvas_t *cv)
{ {
uint32_t attr = cv->curattr; uint32_t attr = cv->curattr;
int n; int n;
@@ -317,12 +317,12 @@ int cucul_clear_canvas(cucul_canvas_t *cv)
* *
* This function never fails. * This function never fails.
* *
* \param cv A handle to the libcucul canvas.
* \param cv A handle to the libcaca canvas.
* \param x X handle coordinate. * \param x X handle coordinate.
* \param y Y handle coordinate. * \param y Y handle coordinate.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_set_canvas_handle(cucul_canvas_t *cv, int x, int y)
int caca_set_canvas_handle(caca_canvas_t *cv, int x, int y)
{ {
cv->frames[cv->frame].handlex = x; cv->frames[cv->frame].handlex = x;
cv->frames[cv->frame].handley = y; cv->frames[cv->frame].handley = y;
@@ -336,10 +336,10 @@ int cucul_set_canvas_handle(cucul_canvas_t *cv, int x, int y)
* *
* This function never fails. * This function never fails.
* *
* \param cv A handle to the libcucul canvas.
* \param cv A handle to the libcaca canvas.
* \return The canvas' handle's X coordinate. * \return The canvas' handle's X coordinate.
*/ */
int cucul_get_canvas_handle_x(cucul_canvas_t const *cv)
int caca_get_canvas_handle_x(caca_canvas_t const *cv)
{ {
return cv->frames[cv->frame].handlex; return cv->frames[cv->frame].handlex;
} }
@@ -350,10 +350,10 @@ int cucul_get_canvas_handle_x(cucul_canvas_t const *cv)
* *
* This function never fails. * This function never fails.
* *
* \param cv A handle to the libcucul canvas.
* \param cv A handle to the libcaca canvas.
* \return The canvas' handle's Y coordinate. * \return The canvas' handle's Y coordinate.
*/ */
int cucul_get_canvas_handle_y(cucul_canvas_t const *cv)
int caca_get_canvas_handle_y(caca_canvas_t const *cv)
{ {
return cv->frames[cv->frame].handley; return cv->frames[cv->frame].handley;
} }
@@ -374,8 +374,8 @@ int cucul_get_canvas_handle_y(cucul_canvas_t const *cv)
* \param mask The mask canvas. * \param mask The mask canvas.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_blit(cucul_canvas_t *dst, int x, int y,
cucul_canvas_t const *src, cucul_canvas_t const *mask)
int caca_blit(caca_canvas_t *dst, int x, int y,
caca_canvas_t const *src, caca_canvas_t const *mask)
{ {
int i, j, starti, startj, endi, endj; int i, j, starti, startj, endi, endj;


@@ -404,11 +404,11 @@ int cucul_blit(cucul_canvas_t *dst, int x, int y,
int stride = endi - starti; int stride = endi - starti;


/* FIXME: we are ignoring the mask here */ /* FIXME: we are ignoring the mask here */
if((starti + x) && dst->chars[dstix] == CUCUL_MAGIC_FULLWIDTH)
if((starti + x) && dst->chars[dstix] == CACA_MAGIC_FULLWIDTH)
dst->chars[dstix - 1] = ' '; dst->chars[dstix - 1] = ' ';


if(endi + x < dst->width if(endi + x < dst->width
&& dst->chars[dstix + stride] == CUCUL_MAGIC_FULLWIDTH)
&& dst->chars[dstix + stride] == CACA_MAGIC_FULLWIDTH)
dst->chars[dstix + stride] = ' '; dst->chars[dstix + stride] = ' ';


if(mask) if(mask)
@@ -429,10 +429,10 @@ int cucul_blit(cucul_canvas_t *dst, int x, int y,
} }


/* Fix split fullwidth chars */ /* Fix split fullwidth chars */
if(src->chars[srcix] == CUCUL_MAGIC_FULLWIDTH)
if(src->chars[srcix] == CACA_MAGIC_FULLWIDTH)
dst->chars[dstix] = ' '; dst->chars[dstix] = ' ';


if(endi < src->width && src->chars[endi] == CUCUL_MAGIC_FULLWIDTH)
if(endi < src->width && src->chars[endi] == CACA_MAGIC_FULLWIDTH)
dst->chars[dstix + stride - 1] = ' '; dst->chars[dstix + stride - 1] = ' ';
} }


@@ -458,9 +458,9 @@ int cucul_blit(cucul_canvas_t *dst, int x, int y,
* \param h The height of the cropped area. * \param h The height of the cropped area.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_set_canvas_boundaries(cucul_canvas_t *cv, int x, int y, int w, int h)
int caca_set_canvas_boundaries(caca_canvas_t *cv, int x, int y, int w, int h)
{ {
cucul_canvas_t *new;
caca_canvas_t *new;
int f, saved_f, framecount; int f, saved_f, framecount;


if(cv->refcount) if(cv->refcount)
@@ -475,19 +475,19 @@ int cucul_set_canvas_boundaries(cucul_canvas_t *cv, int x, int y, int w, int h)
return -1; return -1;
} }


new = cucul_create_canvas(w, h);
new = caca_create_canvas(w, h);


framecount = cucul_get_frame_count(cv);
framecount = caca_get_frame_count(cv);
saved_f = cv->frame; saved_f = cv->frame;


for(f = 0; f < framecount; f++) for(f = 0; f < framecount; f++)
{ {
if(f) if(f)
cucul_create_frame(new, framecount);
caca_create_frame(new, framecount);


cucul_set_frame(cv, f);
cucul_set_frame(new, f);
cucul_blit(new, -x, -y, cv, NULL);
caca_set_frame(cv, f);
caca_set_frame(new, f);
caca_blit(new, -x, -y, cv, NULL);
free(cv->frames[f].chars); free(cv->frames[f].chars);
free(cv->frames[f].attrs); free(cv->frames[f].attrs);
} }
@@ -496,9 +496,9 @@ int cucul_set_canvas_boundaries(cucul_canvas_t *cv, int x, int y, int w, int h)
cv->frames = new->frames; cv->frames = new->frames;
free(new); free(new);


cucul_set_frame(cv, saved_f);
_cucul_load_frame_info(cv);
caca_set_frame(cv, saved_f);
_caca_load_frame_info(cv);
return 0; return 0;
} }



cucul/transform.c → caca/transform.c View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Canvas for ultrafast compositing of Unicode letters
* libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -22,8 +22,8 @@
# include <stdlib.h> # include <stdlib.h>
#endif #endif


#include "cucul.h"
#include "cucul_internals.h"
#include "caca.h"
#include "caca_internals.h"


static uint32_t flipchar(uint32_t ch); static uint32_t flipchar(uint32_t ch);
static uint32_t flopchar(uint32_t ch); static uint32_t flopchar(uint32_t ch);
@@ -43,7 +43,7 @@ static void rightpair(uint32_t pair[2]);
* \param cv The canvas to invert. * \param cv The canvas to invert.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_invert(cucul_canvas_t *cv)
int caca_invert(caca_canvas_t *cv)
{ {
uint32_t *attrs = cv->attrs; uint32_t *attrs = cv->attrs;
int i; int i;
@@ -69,7 +69,7 @@ int cucul_invert(cucul_canvas_t *cv)
* \param cv The canvas to flip. * \param cv The canvas to flip.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_flip(cucul_canvas_t *cv)
int caca_flip(caca_canvas_t *cv)
{ {
int y; int y;


@@ -104,10 +104,10 @@ int cucul_flip(cucul_canvas_t *cv)
cright = cleft + cv->width - 1; cright = cleft + cv->width - 1;
for( ; cleft < cright; cleft++) for( ; cleft < cright; cleft++)
{ {
if(cleft[0] == CUCUL_MAGIC_FULLWIDTH)
if(cleft[0] == CACA_MAGIC_FULLWIDTH)
{ {
cleft[0] = cleft[1]; cleft[0] = cleft[1];
cleft[1] = CUCUL_MAGIC_FULLWIDTH;
cleft[1] = CACA_MAGIC_FULLWIDTH;
cleft++; cleft++;
} }
} }
@@ -128,7 +128,7 @@ int cucul_flip(cucul_canvas_t *cv)
* \param cv The canvas to flop. * \param cv The canvas to flop.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_flop(cucul_canvas_t *cv)
int caca_flop(caca_canvas_t *cv)
{ {
int x; int x;


@@ -174,7 +174,7 @@ int cucul_flop(cucul_canvas_t *cv)
* \param cv The canvas to rotate. * \param cv The canvas to rotate.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_rotate_180(cucul_canvas_t *cv)
int caca_rotate_180(caca_canvas_t *cv)
{ {
uint32_t *cbegin = cv->chars; uint32_t *cbegin = cv->chars;
uint32_t *cend = cbegin + cv->width * cv->height - 1; uint32_t *cend = cbegin + cv->width * cv->height - 1;
@@ -206,10 +206,10 @@ int cucul_rotate_180(cucul_canvas_t *cv)
cend = cbegin + cv->width - 1; cend = cbegin + cv->width - 1;
for( ; cbegin < cend; cbegin++) for( ; cbegin < cend; cbegin++)
{ {
if(cbegin[0] == CUCUL_MAGIC_FULLWIDTH)
if(cbegin[0] == CACA_MAGIC_FULLWIDTH)
{ {
cbegin[0] = cbegin[1]; cbegin[0] = cbegin[1];
cbegin[1] = CUCUL_MAGIC_FULLWIDTH;
cbegin[1] = CACA_MAGIC_FULLWIDTH;
cbegin++; cbegin++;
} }
} }
@@ -239,7 +239,7 @@ int cucul_rotate_180(cucul_canvas_t *cv)
* \param cv The canvas to rotate left. * \param cv The canvas to rotate left.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_rotate_left(cucul_canvas_t *cv)
int caca_rotate_left(caca_canvas_t *cv)
{ {
uint32_t *newchars, *newattrs; uint32_t *newchars, *newattrs;
int x, y, w2, h2; int x, y, w2, h2;
@@ -251,7 +251,7 @@ int cucul_rotate_left(cucul_canvas_t *cv)
} }


/* Save the current frame shortcuts */ /* Save the current frame shortcuts */
_cucul_save_frame_info(cv);
_caca_save_frame_info(cv);


w2 = (cv->width + 1) / 2; w2 = (cv->width + 1) / 2;
h2 = cv->height; h2 = cv->height;
@@ -330,7 +330,7 @@ int cucul_rotate_left(cucul_canvas_t *cv)
cv->frames[cv->frame].attrs = newattrs; cv->frames[cv->frame].attrs = newattrs;


/* Reset the current frame shortcuts */ /* Reset the current frame shortcuts */
_cucul_load_frame_info(cv);
_caca_load_frame_info(cv);


return 0; return 0;
} }
@@ -356,7 +356,7 @@ int cucul_rotate_left(cucul_canvas_t *cv)
* \param cv The canvas to rotate right. * \param cv The canvas to rotate right.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_rotate_right(cucul_canvas_t *cv)
int caca_rotate_right(caca_canvas_t *cv)
{ {
uint32_t *newchars, *newattrs; uint32_t *newchars, *newattrs;
int x, y, w2, h2; int x, y, w2, h2;
@@ -368,7 +368,7 @@ int cucul_rotate_right(cucul_canvas_t *cv)
} }


/* Save the current frame shortcuts */ /* Save the current frame shortcuts */
_cucul_save_frame_info(cv);
_caca_save_frame_info(cv);


w2 = (cv->width + 1) / 2; w2 = (cv->width + 1) / 2;
h2 = cv->height; h2 = cv->height;
@@ -447,7 +447,7 @@ int cucul_rotate_right(cucul_canvas_t *cv)
cv->frames[cv->frame].attrs = newattrs; cv->frames[cv->frame].attrs = newattrs;


/* Reset the current frame shortcuts */ /* Reset the current frame shortcuts */
_cucul_load_frame_info(cv);
_caca_load_frame_info(cv);


return 0; return 0;
} }
@@ -471,7 +471,7 @@ int cucul_rotate_right(cucul_canvas_t *cv)
* \param cv The canvas to rotate left. * \param cv The canvas to rotate left.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_stretch_left(cucul_canvas_t *cv)
int caca_stretch_left(caca_canvas_t *cv)
{ {
uint32_t *newchars, *newattrs; uint32_t *newchars, *newattrs;
int x, y; int x, y;
@@ -483,7 +483,7 @@ int cucul_stretch_left(cucul_canvas_t *cv)
} }


/* Save the current frame shortcuts */ /* Save the current frame shortcuts */
_cucul_save_frame_info(cv);
_caca_save_frame_info(cv);


newchars = malloc(cv->width * cv->height * sizeof(uint32_t)); newchars = malloc(cv->width * cv->height * sizeof(uint32_t));
if(!newchars) if(!newchars)
@@ -538,7 +538,7 @@ int cucul_stretch_left(cucul_canvas_t *cv)
cv->frames[cv->frame].attrs = newattrs; cv->frames[cv->frame].attrs = newattrs;


/* Reset the current frame shortcuts */ /* Reset the current frame shortcuts */
_cucul_load_frame_info(cv);
_caca_load_frame_info(cv);


return 0; return 0;
} }
@@ -562,7 +562,7 @@ int cucul_stretch_left(cucul_canvas_t *cv)
* \param cv The canvas to rotate right. * \param cv The canvas to rotate right.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int cucul_stretch_right(cucul_canvas_t *cv)
int caca_stretch_right(caca_canvas_t *cv)
{ {
uint32_t *newchars, *newattrs; uint32_t *newchars, *newattrs;
int x, y; int x, y;
@@ -574,7 +574,7 @@ int cucul_stretch_right(cucul_canvas_t *cv)
} }


/* Save the current frame shortcuts */ /* Save the current frame shortcuts */
_cucul_save_frame_info(cv);
_caca_save_frame_info(cv);


newchars = malloc(cv->width * cv->height * sizeof(uint32_t)); newchars = malloc(cv->width * cv->height * sizeof(uint32_t));
if(!newchars) if(!newchars)
@@ -629,7 +629,7 @@ int cucul_stretch_right(cucul_canvas_t *cv)
cv->frames[cv->frame].attrs = newattrs; cv->frames[cv->frame].attrs = newattrs;


/* Reset the current frame shortcuts */ /* Reset the current frame shortcuts */
_cucul_load_frame_info(cv);
_caca_load_frame_info(cv);


return 0; return 0;
} }
@@ -999,8 +999,8 @@ static uint32_t rightchar(uint32_t ch)
static uint32_t const leftright2x2[] = static uint32_t const leftright2x2[] =
{ {
/* ASCII / Unicode */ /* ASCII / Unicode */
'-', '-', 0x4e28, CUCUL_MAGIC_FULLWIDTH, /* -- 丨 */
'|', '|', 0x2f06, CUCUL_MAGIC_FULLWIDTH, /* || ⼆ */
'-', '-', 0x4e28, CACA_MAGIC_FULLWIDTH, /* -- 丨 */
'|', '|', 0x2f06, CACA_MAGIC_FULLWIDTH, /* || ⼆ */
/* Unicode */ /* Unicode */
0x2584, 0x2580, 0x2580, 0x2584, /* ▄▀ ▀▄ */ 0x2584, 0x2580, 0x2580, 0x2584, /* ▄▀ ▀▄ */
0, 0, 0, 0 0, 0, 0, 0
@@ -1030,22 +1030,22 @@ static uint32_t const leftright2x4[] =
'.', '_', '.', 0x2575, 0x203e, '\'', 0x2577, '\'', /* ._ .╵ ‾' ╷' */ '.', '_', '.', 0x2575, 0x203e, '\'', 0x2577, '\'', /* ._ .╵ ‾' ╷' */
'(', '_', 0x203f, '|', 0x203e, ')', '|', 0x2040, /* (_ ‿| ‾) |⁀ */ '(', '_', 0x203f, '|', 0x203e, ')', '|', 0x2040, /* (_ ‿| ‾) |⁀ */
'(', 0x203e, '|', 0x203f, '_', ')', 0x2040, '|', /* (‾ |‿ _) ⁀| */ '(', 0x203e, '|', 0x203f, '_', ')', 0x2040, '|', /* (‾ |‿ _) ⁀| */
'\\', '/', 0xff1e, CUCUL_MAGIC_FULLWIDTH,
'/', '\\', 0xff1c, CUCUL_MAGIC_FULLWIDTH, /* \/ > /\ < */
')', ' ', 0xfe35, CUCUL_MAGIC_FULLWIDTH,
' ', '(', 0xfe36, CUCUL_MAGIC_FULLWIDTH, /* ) ︵ ( ︶ */
'}', ' ', 0xfe37, CUCUL_MAGIC_FULLWIDTH,
' ', '{', 0xfe38, CUCUL_MAGIC_FULLWIDTH, /* } ︷ { ︸ */
'\\', '/', 0xff1e, CACA_MAGIC_FULLWIDTH,
'/', '\\', 0xff1c, CACA_MAGIC_FULLWIDTH, /* \/ > /\ < */
')', ' ', 0xfe35, CACA_MAGIC_FULLWIDTH,
' ', '(', 0xfe36, CACA_MAGIC_FULLWIDTH, /* ) ︵ ( ︶ */
'}', ' ', 0xfe37, CACA_MAGIC_FULLWIDTH,
' ', '{', 0xfe38, CACA_MAGIC_FULLWIDTH, /* } ︷ { ︸ */
/* Not perfect, but better than nothing */ /* Not perfect, but better than nothing */
'(', ' ', 0x02ce, ',', ' ', ')', 0x00b4, '`', /* ( ˎ, ) ´` */ '(', ' ', 0x02ce, ',', ' ', ')', 0x00b4, '`', /* ( ˎ, ) ´` */
' ', 'v', '>', ' ', 0x028c, ' ', ' ', '<', /* v > ʌ < */ ' ', 'v', '>', ' ', 0x028c, ' ', ' ', '<', /* v > ʌ < */
' ', 'V', '>', ' ', 0x039b, ' ', ' ', '<', /* V > Λ < */ ' ', 'V', '>', ' ', 0x039b, ' ', ' ', '<', /* V > Λ < */
'v', ' ', '>', ' ', ' ', 0x028c, ' ', '<', /* v > ʌ < */ 'v', ' ', '>', ' ', ' ', 0x028c, ' ', '<', /* v > ʌ < */
'V', ' ', '>', ' ', ' ', 0x039b, ' ', '<', /* V > Λ < */ 'V', ' ', '>', ' ', ' ', 0x039b, ' ', '<', /* V > Λ < */
'\\', '|', 0xff1e, CUCUL_MAGIC_FULLWIDTH,
'|', '\\', 0xff1c, CUCUL_MAGIC_FULLWIDTH, /* \| > |\ < */
'|', '/', 0xff1e, CUCUL_MAGIC_FULLWIDTH,
'/', '|', 0xff1c, CUCUL_MAGIC_FULLWIDTH, /* |/ > /| < */
'\\', '|', 0xff1e, CACA_MAGIC_FULLWIDTH,
'|', '\\', 0xff1c, CACA_MAGIC_FULLWIDTH, /* \| > |\ < */
'|', '/', 0xff1e, CACA_MAGIC_FULLWIDTH,
'/', '|', 0xff1c, CACA_MAGIC_FULLWIDTH, /* |/ > /| < */
/* Unicode */ /* Unicode */
0x2584, ' ', ' ', 0x2584, ' ', 0x2580, 0x2580, ' ', /* ▄ ▄ ▀ ▀ */ 0x2584, ' ', ' ', 0x2584, ' ', 0x2580, 0x2580, ' ', /* ▄ ▄ ▀ ▀ */
0x2588, ' ', 0x2584, 0x2584, ' ', 0x2588, 0x2580, 0x2580, /* █ ▄▄ █ ▀▀ */ 0x2588, ' ', 0x2584, 0x2584, ' ', 0x2588, 0x2580, 0x2580, /* █ ▄▄ █ ▀▀ */

cucul/triangle.c → caca/triangle.c View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Canvas for ultrafast compositing of Unicode letters
* libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -22,14 +22,14 @@
# include <stdlib.h> # include <stdlib.h>
#endif #endif


#include "cucul.h"
#include "cucul_internals.h"
#include "caca.h"
#include "caca_internals.h"


/** \brief Draw a triangle on the canvas using the given character. /** \brief Draw a triangle on the canvas using the given character.
* *
* This function never fails. * This function never fails.
* *
* \param cv The handle to the libcucul canvas.
* \param cv The handle to the libcaca canvas.
* \param x1 X coordinate of the first point. * \param x1 X coordinate of the first point.
* \param y1 Y coordinate of the first point. * \param y1 Y coordinate of the first point.
* \param x2 X coordinate of the second point. * \param x2 X coordinate of the second point.
@@ -39,12 +39,12 @@
* \param ch UTF-32 character to be used to draw the triangle outline. * \param ch UTF-32 character to be used to draw the triangle outline.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_draw_triangle(cucul_canvas_t *cv, int x1, int y1, int x2, int y2,
int caca_draw_triangle(caca_canvas_t *cv, int x1, int y1, int x2, int y2,
int x3, int y3, uint32_t ch) int x3, int y3, uint32_t ch)
{ {
cucul_draw_line(cv, x1, y1, x2, y2, ch);
cucul_draw_line(cv, x2, y2, x3, y3, ch);
cucul_draw_line(cv, x3, y3, x1, y1, ch);
caca_draw_line(cv, x1, y1, x2, y2, ch);
caca_draw_line(cv, x2, y2, x3, y3, ch);
caca_draw_line(cv, x3, y3, x1, y1, ch);


return 0; return 0;
} }
@@ -53,7 +53,7 @@ int cucul_draw_triangle(cucul_canvas_t *cv, int x1, int y1, int x2, int y2,
* *
* This function never fails. * This function never fails.
* *
* \param cv The handle to the libcucul canvas.
* \param cv The handle to the libcaca canvas.
* \param x1 X coordinate of the first point. * \param x1 X coordinate of the first point.
* \param y1 Y coordinate of the first point. * \param y1 Y coordinate of the first point.
* \param x2 X coordinate of the second point. * \param x2 X coordinate of the second point.
@@ -62,12 +62,12 @@ int cucul_draw_triangle(cucul_canvas_t *cv, int x1, int y1, int x2, int y2,
* \param y3 Y coordinate of the third point. * \param y3 Y coordinate of the third point.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_draw_thin_triangle(cucul_canvas_t *cv, int x1, int y1,
int caca_draw_thin_triangle(caca_canvas_t *cv, int x1, int y1,
int x2, int y2, int x3, int y3) int x2, int y2, int x3, int y3)
{ {
cucul_draw_thin_line(cv, x1, y1, x2, y2);
cucul_draw_thin_line(cv, x2, y2, x3, y3);
cucul_draw_thin_line(cv, x3, y3, x1, y1);
caca_draw_thin_line(cv, x1, y1, x2, y2);
caca_draw_thin_line(cv, x2, y2, x3, y3);
caca_draw_thin_line(cv, x3, y3, x1, y1);


return 0; return 0;
} }
@@ -76,7 +76,7 @@ int cucul_draw_thin_triangle(cucul_canvas_t *cv, int x1, int y1,
* *
* This function never fails. * This function never fails.
* *
* \param cv The handle to the libcucul canvas.
* \param cv The handle to the libcaca canvas.
* \param x1 X coordinate of the first point. * \param x1 X coordinate of the first point.
* \param y1 Y coordinate of the first point. * \param y1 Y coordinate of the first point.
* \param x2 X coordinate of the second point. * \param x2 X coordinate of the second point.
@@ -86,7 +86,7 @@ int cucul_draw_thin_triangle(cucul_canvas_t *cv, int x1, int y1,
* \param ch UTF-32 character to be used to fill the triangle. * \param ch UTF-32 character to be used to fill the triangle.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int cucul_fill_triangle(cucul_canvas_t *cv, int x1, int y1, int x2, int y2,
int caca_fill_triangle(caca_canvas_t *cv, int x1, int y1, int x2, int y2,
int x3, int y3, uint32_t ch) int x3, int y3, uint32_t ch)
{ {
int x, y, xmin, xmax, ymin, ymax; int x, y, xmin, xmax, ymin, ymax;
@@ -94,10 +94,10 @@ int cucul_fill_triangle(cucul_canvas_t *cv, int x1, int y1, int x2, int y2,


/* Bubble-sort y1 <= y2 <= y3 */ /* Bubble-sort y1 <= y2 <= y3 */
if(y1 > y2) if(y1 > y2)
return cucul_fill_triangle(cv, x2, y2, x1, y1, x3, y3, ch);
return caca_fill_triangle(cv, x2, y2, x1, y1, x3, y3, ch);


if(y2 > y3) if(y2 > y3)
return cucul_fill_triangle(cv, x1, y1, x3, y3, x2, y2, ch);
return caca_fill_triangle(cv, x1, y1, x3, y3, x2, y2, ch);


/* Compute slopes and promote precision */ /* Compute slopes and promote precision */
sl21 = (y2 == y1) ? 0 : (x2 - x1) * 0x10000 / (y2 - y1); sl21 = (y2 == y1) ? 0 : (x2 - x1) * 0x10000 / (y2 - y1);
@@ -146,7 +146,7 @@ int cucul_fill_triangle(cucul_canvas_t *cv, int x1, int y1, int x2, int y2,
xmax = xx2 + 1 < cv->width ? xx2 + 1 : cv->width; xmax = xx2 + 1 < cv->width ? xx2 + 1 : cv->width;


for(x = xmin; x < xmax; x++) for(x = xmin; x < xmax; x++)
cucul_put_char(cv, x, y, ch);
caca_put_char(cv, x, y, ch);


xa += y < y2 ? sl21 : sl32; xa += y < y2 ? sl21 : sl32;
xb += sl31; xb += sl31;

+ 9
- 13
configure.ac View File

@@ -331,20 +331,20 @@ AC_SUBST(X11_LIBS)
AC_SUBST(GL_CFLAGS) AC_SUBST(GL_CFLAGS)
AC_SUBST(GL_LIBS) AC_SUBST(GL_LIBS)


# How to get the C99 types. See cucul/cucul_types.h.in for details about
# the CUCUL_TYPES variable
# How to get the C99 types. See caca/caca_types.h.in for details about
# the CACA_TYPES variable
if test "${ac_cv_my_have_vga}" = "yes"; then if test "${ac_cv_my_have_vga}" = "yes"; then
CUCUL_TYPES=0
CACA_TYPES=0
else else
AC_CHECK_HEADERS(stdint.h, AC_CHECK_HEADERS(stdint.h,
[CUCUL_TYPES=1],
[CACA_TYPES=1],
[AC_CHECK_HEADERS(inttypes.h, [AC_CHECK_HEADERS(inttypes.h,
[CUCUL_TYPES=2],
[CACA_TYPES=2],
[AC_CHECK_HEADERS(windows.h, [AC_CHECK_HEADERS(windows.h,
[CUCUL_TYPES=3],
[CUCUL_TYPES=0])])])
[CACA_TYPES=3],
[CACA_TYPES=0])])])
fi fi
AC_SUBST(CUCUL_TYPES)
AC_SUBST(CACA_TYPES)


# Optimizations # Optimizations
CFLAGS="${CFLAGS} -g -O2 -fno-strength-reduce -fomit-frame-pointer" CFLAGS="${CFLAGS} -g -O2 -fno-strength-reduce -fomit-frame-pointer"
@@ -473,7 +473,6 @@ AM_CONDITIONAL(USE_ZZUF, test "${ZZUF}" != "no")
AC_CONFIG_FILES([ AC_CONFIG_FILES([
Makefile Makefile
kernel/Makefile kernel/Makefile
cucul/Makefile
caca/Makefile caca/Makefile
src/Makefile src/Makefile
examples/Makefile examples/Makefile
@@ -487,12 +486,9 @@ AC_CONFIG_FILES([
msvc/Makefile msvc/Makefile
]) ])
AC_CONFIG_FILES([ AC_CONFIG_FILES([
cucul/cucul_types.h
cucul/cucul.pc
caca/caca_types.h
caca/caca.pc caca/caca.pc
csharp/cucul-sharp.dll.config
csharp/caca-sharp.dll.config csharp/caca-sharp.dll.config
cxx/cucul++.pc
cxx/caca++.pc cxx/caca++.pc
doc/doxygen.cfg doc/doxygen.cfg
]) ])


+ 6
- 14
csharp/Makefile.am View File

@@ -1,32 +1,24 @@
# $Id: $ # $Id: $


cuculdir = $(libdir)/cucul-sharp
cacadir = $(libdir)/caca-sharp cacadir = $(libdir)/caca-sharp


cucul_sources = $(srcdir)/AssemblyInfo.cs $(srcdir)/Cucul.cs
caca_sources = $(srcdir)/AssemblyInfo.cs $(srcdir)/Caca.cs
caca_sources = $(srcdir)/AssemblyInfo.cs $(srcdir)/Cucul.cs $(srcdir)/Caca.cs


if USE_CSHARP if USE_CSHARP
cucul_DATA = cucul-sharp.dll cucul-sharp.dll.config
caca_DATA = caca-sharp.dll caca-sharp.dll.config caca_DATA = caca-sharp.dll caca-sharp.dll.config
noinst_DATA = test.exe noinst_DATA = test.exe
endif endif


EXTRA_DIST = $(cucul_sources) cucul-sharp.dll.config.in \
$(caca_sources) caca-sharp.dll.config.in \
EXTRA_DIST = $(caca_sources) caca-sharp.dll.config.in \
$(srcdir)/test.cs $(srcdir)/test.cs


cucul-sharp.dll: $(cucul_sources)
gmcs -unsafe $(cucul_sources) -out:$@ -target:library \
caca-sharp.dll: $(caca_sources)
gmcs -unsafe $(caca_sources) -out:$@ -target:library \
-r:System.Drawing.dll -r:System.Drawing.dll


caca-sharp.dll: $(caca_sources) cucul-sharp.dll
gmcs -unsafe $(caca_sources) -out:$@ -target:library -lib:./ \
-r:System.Drawing.dll -r:./cucul-sharp.dll

test.exe: $(srcdir)/test.cs caca-sharp.dll cucul-sharp.dll
test.exe: $(srcdir)/test.cs caca-sharp.dll
gmcs $(srcdir)/test.cs -out:$@ -lib:./ \ gmcs $(srcdir)/test.cs -out:$@ -lib:./ \
-r:System.Drawing.dll -r:./cucul-sharp.dll -r:./caca-sharp.dll
-r:System.Drawing.dll -r:./caca-sharp.dll


clean-local: clean-local:
rm -f *.exe *.dll rm -f *.exe *.dll


+ 0
- 1
cucul/.gitignore View File

@@ -1 +0,0 @@
cucul_types.h

+ 0
- 42
cucul/Makefile.am View File

@@ -1,42 +0,0 @@
# $Id$

EXTRA_DIST = cucul_types.h.in cucul.pc.in mono9.data monobold12.data
DISTCLEANFILES = cucul_types.h cucul.pc

pkgconfig_DATA = cucul.pc
pkgconfigdir = $(libdir)/pkgconfig

include_HEADERS = cucul.h cucul_types.h

lib_LTLIBRARIES = libcucul.la

libcucul_la_SOURCES = \
cucul.c \
cucul.h \
cucul_types.h \
cucul_internals.h \
legacy.c \
canvas.c \
transform.c \
charset.c \
attr.c \
line.c \
box.c \
conic.c \
triangle.c \
frame.c \
dither.c \
font.c \
import.c \
export.c \
file.c \
figfont.c \
$(NULL)
libcucul_la_DEPENDENCIES = \
mono9.data \
monobold12.data \
$(NULL)
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/cucul -I../cucul
libcucul_la_LDFLAGS = -no-undefined -version-number @LT_VERSION@
libcucul_la_LIBADD = $(ZLIB_LIBS)


+ 0
- 383
cucul/cucul.h View File

@@ -1,383 +0,0 @@
/*
* 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. It comes without any warranty, to
* the extent permitted by applicable law. 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.
*/

/** \file cucul.h
* \version \$Id$
* \author Sam Hocevar <sam@zoy.org>
* \brief The \e libcucul public header.
*
* This header contains the public types and functions that applications
* using \e libcucul may use.
*/

#ifndef __CUCUL_H__
#define __CUCUL_H__

#include <cucul_types.h>

#undef __extern
#if defined(_DOXYGEN_SKIP_ME)
#elif defined(_WIN32) && defined(__LIBCUCUL__)
# define __extern extern __declspec(dllexport)
#else
# define __extern extern
#endif

/** libcucul API version */
#define CUCUL_API_VERSION_1

#ifdef __cplusplus
extern "C"
{
#endif

/** \e libcucul canvas */
typedef struct cucul_canvas cucul_canvas_t;
/** dither structure */
typedef struct cucul_dither cucul_dither_t;
/** font structure */
typedef struct cucul_font cucul_font_t;
/** file handle structure */
typedef struct cucul_file cucul_file_t;

/** \defgroup cucul_attr libcucul attribute definitions
*
* Colours and styles that can be used with cucul_set_attr().
*
* @{ */
#define CUCUL_BLACK 0x00 /**< The colour index for black. */
#define CUCUL_BLUE 0x01 /**< The colour index for blue. */
#define CUCUL_GREEN 0x02 /**< The colour index for green. */
#define CUCUL_CYAN 0x03 /**< The colour index for cyan. */
#define CUCUL_RED 0x04 /**< The colour index for red. */
#define CUCUL_MAGENTA 0x05 /**< The colour index for magenta. */
#define CUCUL_BROWN 0x06 /**< The colour index for brown. */
#define CUCUL_LIGHTGRAY 0x07 /**< The colour index for light gray. */
#define CUCUL_DARKGRAY 0x08 /**< The colour index for dark gray. */
#define CUCUL_LIGHTBLUE 0x09 /**< The colour index for blue. */
#define CUCUL_LIGHTGREEN 0x0a /**< The colour index for light green. */
#define CUCUL_LIGHTCYAN 0x0b /**< The colour index for light cyan. */
#define CUCUL_LIGHTRED 0x0c /**< The colour index for light red. */
#define CUCUL_LIGHTMAGENTA 0x0d /**< The colour index for light magenta. */
#define CUCUL_YELLOW 0x0e /**< The colour index for yellow. */
#define CUCUL_WHITE 0x0f /**< The colour index for white. */
#define CUCUL_DEFAULT 0x10 /**< The output driver's default colour. */
#define CUCUL_TRANSPARENT 0x20 /**< The transparent colour. */

#define CUCUL_BOLD 0x01 /**< The style mask for bold. */
#define CUCUL_ITALICS 0x02 /**< The style mask for italics. */
#define CUCUL_UNDERLINE 0x04 /**< The style mask for underline. */
#define CUCUL_BLINK 0x08 /**< The style mask for blink. */
/* @} */

/** \defgroup libcucul libcucul basic functions
*
* These functions provide the basic \e libcaca routines for library
* initialisation, system information retrieval and configuration.
*
* @{ */
__extern cucul_canvas_t * cucul_create_canvas(int, int);
__extern int cucul_manage_canvas(cucul_canvas_t *, int (*)(void *), void *);
__extern int cucul_unmanage_canvas(cucul_canvas_t *, int (*)(void *), void *);
__extern int cucul_set_canvas_size(cucul_canvas_t *, int, int);
__extern int cucul_get_canvas_width(cucul_canvas_t const *);
__extern int cucul_get_canvas_height(cucul_canvas_t const *);
__extern uint8_t const * cucul_get_canvas_chars(cucul_canvas_t const *);
__extern uint8_t const * cucul_get_canvas_attrs(cucul_canvas_t const *);
__extern int cucul_free_canvas(cucul_canvas_t *);
__extern int cucul_rand(int, int);
__extern char const * cucul_get_version(void);
/* @} */

/** \defgroup cucul_canvas libcucul canvas drawing
*
* These functions provide low-level character printing routines and
* higher level graphics functions.
*
* @{ */
#define CUCUL_MAGIC_FULLWIDTH 0x000ffffe /**< Used to indicate that the previous character was a fullwidth glyph. */
__extern int cucul_gotoxy(cucul_canvas_t *, int, int);
__extern int cucul_get_cursor_x(cucul_canvas_t const *);
__extern int cucul_get_cursor_y(cucul_canvas_t const *);
__extern int cucul_put_char(cucul_canvas_t *, int, int, uint32_t);
__extern uint32_t cucul_get_char(cucul_canvas_t const *, int, int);
__extern int cucul_put_str(cucul_canvas_t *, int, int, char const *);
__extern uint32_t cucul_get_attr(cucul_canvas_t const *, int, int);
__extern int cucul_set_attr(cucul_canvas_t *, uint32_t);
__extern int cucul_put_attr(cucul_canvas_t *, int, int, uint32_t);
__extern int cucul_set_color_ansi(cucul_canvas_t *, uint8_t, uint8_t);
__extern int cucul_set_color_argb(cucul_canvas_t *, uint16_t, uint16_t);
__extern int cucul_printf(cucul_canvas_t *, int, int, char const *, ...);
__extern int cucul_clear_canvas(cucul_canvas_t *);
__extern int cucul_set_canvas_handle(cucul_canvas_t *, int, int);
__extern int cucul_get_canvas_handle_x(cucul_canvas_t const *);
__extern int cucul_get_canvas_handle_y(cucul_canvas_t const *);
__extern int cucul_blit(cucul_canvas_t *, int, int, cucul_canvas_t const *,
cucul_canvas_t const *);
__extern int cucul_set_canvas_boundaries(cucul_canvas_t *, int, int, int, int);
/* @} */

/** \defgroup cucul_transform libcucul canvas transformation
*
* These functions perform horizontal and vertical canvas flipping.
*
* @{ */
__extern int cucul_invert(cucul_canvas_t *);
__extern int cucul_flip(cucul_canvas_t *);
__extern int cucul_flop(cucul_canvas_t *);
__extern int cucul_rotate_180(cucul_canvas_t *);
__extern int cucul_rotate_left(cucul_canvas_t *);
__extern int cucul_rotate_right(cucul_canvas_t *);
__extern int cucul_stretch_left(cucul_canvas_t *);
__extern int cucul_stretch_right(cucul_canvas_t *);
/* @} */

/** \defgroup cucul_attributes libcucul attribute conversions
*
* These functions perform conversions between attribute values.
*
* @{ */
__extern uint8_t cucul_attr_to_ansi(uint32_t);
__extern uint8_t cucul_attr_to_ansi_fg(uint32_t);
__extern uint8_t cucul_attr_to_ansi_bg(uint32_t);
__extern uint16_t cucul_attr_to_rgb12_fg(uint32_t);
__extern uint16_t cucul_attr_to_rgb12_bg(uint32_t);
__extern void cucul_attr_to_argb64(uint32_t, uint8_t[8]);
/* @} */

/** \defgroup cucul_charset libcucul character set conversions
*
* These functions perform conversions between usual character sets.
*
* @{ */
__extern uint32_t cucul_utf8_to_utf32(char const *, size_t *);
__extern size_t cucul_utf32_to_utf8(char *, uint32_t);
__extern uint8_t cucul_utf32_to_cp437(uint32_t);
__extern uint32_t cucul_cp437_to_utf32(uint8_t);
__extern char cucul_utf32_to_ascii(uint32_t);
__extern int cucul_utf32_is_fullwidth(uint32_t);
/* @} */

/** \defgroup cucul_primitives libcucul primitives drawing
*
* These functions provide routines for primitive drawing, such as lines,
* boxes, triangles and ellipses.
*
* @{ */
__extern int cucul_draw_line(cucul_canvas_t *, int, int, int, int, uint32_t);
__extern int cucul_draw_polyline(cucul_canvas_t *, int const x[],
int const y[], int, uint32_t);
__extern int cucul_draw_thin_line(cucul_canvas_t *, int, int, int, int);
__extern int cucul_draw_thin_polyline(cucul_canvas_t *, int const x[],
int const y[], int);

__extern int cucul_draw_circle(cucul_canvas_t *, int, int, int, uint32_t);
__extern int cucul_draw_ellipse(cucul_canvas_t *, int, int, int, int, uint32_t);
__extern int cucul_draw_thin_ellipse(cucul_canvas_t *, int, int, int, int);
__extern int cucul_fill_ellipse(cucul_canvas_t *, int, int, int, int, uint32_t);

__extern int cucul_draw_box(cucul_canvas_t *, int, int, int, int, uint32_t);
__extern int cucul_draw_thin_box(cucul_canvas_t *, int, int, int, int);
__extern int cucul_draw_cp437_box(cucul_canvas_t *, int, int, int, int);
__extern int cucul_fill_box(cucul_canvas_t *, int, int, int, int, uint32_t);

__extern int cucul_draw_triangle(cucul_canvas_t *, int, int, int, int, int,
int, uint32_t);
__extern int cucul_draw_thin_triangle(cucul_canvas_t *, int, int, int, int,
int, int);
__extern int cucul_fill_triangle(cucul_canvas_t *, int, int, int, int, int,
int, uint32_t);
/* @} */

/** \defgroup cucul_frame libcucul canvas frame handling
*
* These functions provide high level routines for canvas frame insertion,
* removal, copying etc.
*
* @{ */
__extern int cucul_get_frame_count(cucul_canvas_t const *);
__extern int cucul_set_frame(cucul_canvas_t *, int);
__extern char const *cucul_get_frame_name(cucul_canvas_t const *);
__extern int cucul_set_frame_name(cucul_canvas_t *, char const *);
__extern int cucul_create_frame(cucul_canvas_t *, int);
__extern int cucul_free_frame(cucul_canvas_t *, int);
/* @} */

/** \defgroup cucul_dither libcucul bitmap dithering
*
* These functions provide high level routines for dither allocation and
* rendering.
*
* @{ */
__extern cucul_dither_t *cucul_create_dither(int, int, int, int,
uint32_t, uint32_t,
uint32_t, uint32_t);
__extern int cucul_set_dither_palette(cucul_dither_t *,
uint32_t r[], uint32_t g[],
uint32_t b[], uint32_t a[]);
__extern int cucul_set_dither_brightness(cucul_dither_t *, float);
__extern float cucul_get_dither_brightness(cucul_dither_t const *);
__extern int cucul_set_dither_gamma(cucul_dither_t *, float);
__extern float cucul_get_dither_gamma(cucul_dither_t const *);
__extern int cucul_set_dither_contrast(cucul_dither_t *, float);
__extern float cucul_get_dither_contrast(cucul_dither_t const *);
__extern int cucul_set_dither_antialias(cucul_dither_t *, char const *);
__extern char const * const * cucul_get_dither_antialias_list(cucul_dither_t
const *);
__extern char const * cucul_get_dither_antialias(cucul_dither_t const *);
__extern int cucul_set_dither_color(cucul_dither_t *, char const *);
__extern char const * const * cucul_get_dither_color_list(cucul_dither_t
const *);
__extern char const * cucul_get_dither_color(cucul_dither_t const *);
__extern int cucul_set_dither_charset(cucul_dither_t *, char const *);
__extern char const * const * cucul_get_dither_charset_list(cucul_dither_t
const *);
__extern char const * cucul_get_dither_charset(cucul_dither_t const *);
__extern int cucul_set_dither_algorithm(cucul_dither_t *, char const *);
__extern char const * const * cucul_get_dither_algorithm_list(cucul_dither_t
const *);
__extern char const * cucul_get_dither_algorithm(cucul_dither_t const *);
__extern int cucul_dither_bitmap(cucul_canvas_t *, int, int, int, int,
cucul_dither_t const *, void *);
__extern int cucul_free_dither(cucul_dither_t *);
/* @} */

/** \defgroup cucul_font libcucul font handling
*
* These functions provide font handling routines and high quality
* canvas to bitmap rendering.
*
* @{ */
__extern cucul_font_t *cucul_load_font(void const *, size_t);
__extern char const * const * cucul_get_font_list(void);
__extern int cucul_get_font_width(cucul_font_t const *);
__extern int cucul_get_font_height(cucul_font_t const *);
__extern uint32_t const *cucul_get_font_blocks(cucul_font_t const *);
__extern int cucul_render_canvas(cucul_canvas_t const *, cucul_font_t const *,
void *, int, int, int);
__extern int cucul_free_font(cucul_font_t *);
/* @} */

/** \defgroup cucul_figfont libcucul FIGfont handling
*
* These functions provide FIGlet and TOIlet font handling routines.
*
* @{ */
__extern int cucul_canvas_set_figfont(cucul_canvas_t *, char const *);
__extern int cucul_put_figchar(cucul_canvas_t *, uint32_t);
__extern int cucul_flush_figlet(cucul_canvas_t *);
/* @} */

/** \defgroup cucul_file libcucul file IO
*
* These functions allow to read and write files in a platform-independent
* way.
* @{ */
__extern cucul_file_t *cucul_file_open(char const *, const char *);
__extern int cucul_file_close(cucul_file_t *);
__extern uint64_t cucul_file_tell(cucul_file_t *);
__extern size_t cucul_file_read(cucul_file_t *, void *, size_t);
__extern size_t cucul_file_write(cucul_file_t *, const void *, size_t);
__extern char * cucul_file_gets(cucul_file_t *, char *, int);
__extern int cucul_file_eof(cucul_file_t *);
/* @} */

/** \defgroup cucul_importexport libcucul importers/exporters from/to various
* formats
*
* These functions import various file formats into a new canvas, or export
* the current canvas to various text formats.
*
* @{ */
__extern ssize_t cucul_import_memory(cucul_canvas_t *, void const *,
size_t, char const *);
__extern ssize_t cucul_import_file(cucul_canvas_t *, char const *,
char const *);
__extern char const * const * cucul_get_import_list(void);
__extern void *cucul_export_memory(cucul_canvas_t const *, char const *,
size_t *);
__extern char const * const * cucul_get_export_list(void);
/* @} */

#if !defined(_DOXYGEN_SKIP_ME)
/* Legacy stuff from beta versions, will probably disappear in 1.0 */
typedef struct cucul_buffer cucul_buffer_t;
# if defined __GNUC__ && __GNUC__ >= 3
# define CUCUL_DEPRECATED __attribute__ ((__deprecated__))
# else
# define CUCUL_DEPRECATED
# endif
__extern int cucul_putchar(cucul_canvas_t *, int, int,
unsigned long int) CUCUL_DEPRECATED;
__extern unsigned long int cucul_getchar(cucul_canvas_t *,
int, int) CUCUL_DEPRECATED;
__extern int cucul_putstr(cucul_canvas_t *, int, int,
char const *) CUCUL_DEPRECATED;
__extern int cucul_set_color(cucul_canvas_t *, unsigned char,
unsigned char) CUCUL_DEPRECATED;
__extern int cucul_set_truecolor(cucul_canvas_t *, unsigned int,
unsigned int) CUCUL_DEPRECATED;
__extern unsigned int cucul_get_canvas_frame_count(cucul_canvas_t *)
CUCUL_DEPRECATED;
__extern int cucul_set_canvas_frame(cucul_canvas_t *,
unsigned int) CUCUL_DEPRECATED;
__extern int cucul_create_canvas_frame(cucul_canvas_t *,
unsigned int) CUCUL_DEPRECATED;
__extern int cucul_free_canvas_frame(cucul_canvas_t *,
unsigned int) CUCUL_DEPRECATED;
__extern cucul_buffer_t *cucul_load_memory(void *,
unsigned long int) CUCUL_DEPRECATED;
__extern cucul_buffer_t *cucul_load_file(char const *) CUCUL_DEPRECATED;
__extern unsigned long int cucul_get_buffer_size(cucul_buffer_t *)
CUCUL_DEPRECATED;
__extern void * cucul_get_buffer_data(cucul_buffer_t *) CUCUL_DEPRECATED;
__extern int cucul_free_buffer(cucul_buffer_t *) CUCUL_DEPRECATED;
__extern cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *,
char const *) CUCUL_DEPRECATED;
__extern cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *,
char const *) CUCUL_DEPRECATED;
__extern int cucul_rotate(cucul_canvas_t *) CUCUL_DEPRECATED;
__extern int cucul_set_dither_invert(cucul_dither_t *, int) CUCUL_DEPRECATED;
__extern int cucul_set_dither_mode(cucul_dither_t *,
char const *) CUCUL_DEPRECATED;
__extern char const * const * cucul_get_dither_mode_list(cucul_dither_t
const *)
CUCUL_DEPRECATED;
# define CUCUL_COLOR_BLACK CUCUL_BLACK
# define CUCUL_COLOR_BLUE CUCUL_BLUE
# define CUCUL_COLOR_GREEN CUCUL_GREEN
# define CUCUL_COLOR_CYAN CUCUL_CYAN
# define CUCUL_COLOR_RED CUCUL_RED
# define CUCUL_COLOR_MAGENTA CUCUL_MAGENTA
# define CUCUL_COLOR_BROWN CUCUL_BROWN
# define CUCUL_COLOR_LIGHTGRAY CUCUL_LIGHTGRAY
# define CUCUL_COLOR_DARKGRAY CUCUL_DARKGRAY
# define CUCUL_COLOR_LIGHTBLUE CUCUL_LIGHTBLUE
# define CUCUL_COLOR_LIGHTGREEN CUCUL_LIGHTGREEN
# define CUCUL_COLOR_LIGHTCYAN CUCUL_LIGHTCYAN
# define CUCUL_COLOR_LIGHTRED CUCUL_LIGHTRED
# define CUCUL_COLOR_LIGHTMAGENTA CUCUL_LIGHTMAGENTA
# define CUCUL_COLOR_YELLOW CUCUL_YELLOW
# define CUCUL_COLOR_WHITE CUCUL_YELLOW
# define CUCUL_COLOR_DEFAULT CUCUL_DEFAULT
# define CUCUL_COLOR_TRANSPARENT CUCUL_TRANSPARENT
#endif

#ifdef __cplusplus
}
#endif

#undef __extern

#endif /* __CUCUL_H__ */

+ 0
- 12
cucul/cucul.pc.in View File

@@ -1,12 +0,0 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@

Name: cucul
Description: Canvas for ultrafast compositing of Unicode letters
Version: @VERSION@
Requires:
Conflicts:
Libs: -L${libdir} -lcucul
Cflags: -I${includedir}

+ 0
- 80
cucul/cucul_internals.h View File

@@ -1,80 +0,0 @@
/*
* 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. It comes without any warranty, to
* the extent permitted by applicable law. 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.
*/

#ifndef __CUCUL_INTERNALS_H__
#define __CUCUL_INTERNALS_H__

#include "stubs.h"

typedef struct cucul_figfont cucul_figfont_t;

struct cucul_frame
{
/* Frame size */
int width, height;

/* Cell information */
uint32_t *chars;
uint32_t *attrs;

/* Painting context */
int x, y;
int handlex, handley;
uint32_t curattr;

/* Frame name */
char *name;
};

struct cucul_canvas
{
/* XXX: look at cucul_set_canvas_boundaries() before adding anything
* to this structure. The function is quite hacky. */

/* Frame information */
int frame, framecount;
struct cucul_frame *frames;

/* Canvas management */
int refcount;
int autoinc;
int (*resize_callback)(void *);
void *resize_data;

/* Shortcut to the active frame information */
int width, height;
uint32_t *chars;
uint32_t *attrs;
uint32_t curattr;

/* FIGfont management */
cucul_figfont_t *ff;
};

struct cucul_buffer
{
size_t size;
char *data;
int user_data;
};

/* Colour functions */
extern uint32_t _cucul_attr_to_rgb24fg(uint32_t);
extern uint32_t _cucul_attr_to_rgb24bg(uint32_t);

/* Frames functions */
extern void _cucul_save_frame_info(cucul_canvas_t *);
extern void _cucul_load_frame_info(cucul_canvas_t *);

#endif /* __CUCUL_INTERNALS_H__ */

+ 7
- 12
cxx/Makefile.am View File

@@ -1,28 +1,23 @@
# $Id: Makefile.am 552 2006-04-13 16:10:16Z jylam $ # $Id: Makefile.am 552 2006-04-13 16:10:16Z jylam $


AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/cucul -I../cucul \
-I$(top_srcdir)/caca
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/caca -I../caca


if USE_CXX if USE_CXX
pkgconfig_DATA = cucul++.pc caca++.pc
pkgconfig_DATA = caca++.pc
pkgconfigdir = $(libdir)/pkgconfig pkgconfigdir = $(libdir)/pkgconfig


include_HEADERS = cucul++.h caca++.h
lib_LTLIBRARIES = libcucul++.la libcaca++.la
include_HEADERS = caca++.h
lib_LTLIBRARIES = libcaca++.la
endif endif


libcucul___la_SOURCES = cucul++.cpp cucul++.h
libcucul___la_LDFLAGS = -no-undefined -version-number @LT_VERSION@
libcucul___la_LIBADD = ../cucul/libcucul.la

libcaca___la_SOURCES = caca++.cpp caca++.h
libcaca___la_SOURCES = caca++.cpp cucul++.cpp caca++.h
libcaca___la_LDFLAGS = -no-undefined -version-number @LT_VERSION@ libcaca___la_LDFLAGS = -no-undefined -version-number @LT_VERSION@
libcaca___la_LIBADD = libcucul++.la ../caca/libcaca.la
libcaca___la_LIBADD = ../caca/libcaca.la


if USE_CXX if USE_CXX
noinst_PROGRAMS = cxxtest noinst_PROGRAMS = cxxtest
endif endif


cxxtest_SOURCES = cxxtest.cpp cxxtest_SOURCES = cxxtest.cpp
cxxtest_LDADD = libcaca++.la libcucul++.la ../caca/libcaca.la ../cucul/libcucul.la
cxxtest_LDADD = libcaca++.la ../caca/libcaca.la



+ 4
- 4
cxx/caca++.cpp View File

@@ -24,9 +24,9 @@


#include "caca++.h" #include "caca++.h"


Caca::Caca(Cucul *cv)
Caca::Caca(Canvas *cv)
{ {
dp = caca_create_display(cv->get_cucul_canvas_t());
dp = caca_create_display(cv->get_caca_canvas_t());
if(!dp) if(!dp)
throw -1; throw -1;
} }
@@ -36,9 +36,9 @@ Caca::~Caca()
caca_free_display(dp); caca_free_display(dp);
} }


void Caca::Attach(Cucul *cv)
void Caca::Attach(Canvas *cv)
{ {
dp = caca_create_display(cv->get_cucul_canvas_t());
dp = caca_create_display(cv->get_caca_canvas_t());
if(!dp) if(!dp)
throw -1; throw -1;
} }


+ 3
- 4
cxx/caca++.h View File

@@ -23,9 +23,8 @@
#ifndef _CACA_PP_H #ifndef _CACA_PP_H
#define _CACA_PP_H #define _CACA_PP_H


#include <cucul.h>
#include <caca.h> #include <caca.h>
#include <caca++.h>
#include <cucul++.h> #include <cucul++.h>


#undef __class #undef __class
@@ -61,10 +60,10 @@ __class Caca
{ {
public: public:
Caca(); Caca();
Caca(Cucul *cv);
Caca(Canvas *cv);
~Caca(); ~Caca();


void Attach(Cucul *cv);
void Attach(Canvas *cv);
void Detach(); void Detach();
void setDisplayTime(unsigned int); void setDisplayTime(unsigned int);




+ 130
- 130
cxx/cucul++.cpp View File

@@ -1,5 +1,5 @@
/* /*
* libcucul++ C++ bindings for libcucul
* libcaca++ C++ bindings for libcaca
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org> * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -13,7 +13,7 @@
*/ */


/* /*
* This file contains the main functions used by \e libcucul++ applications
* This file contains the main functions used by \e libcaca++ applications
* to initialise a drawing context. * to initialise a drawing context.
*/ */


@@ -22,92 +22,92 @@
#include <stdio.h> // BUFSIZ #include <stdio.h> // BUFSIZ
#include <stdarg.h> // va_* #include <stdarg.h> // va_*


#include "cucul++.h"
#include "caca++.h"




uint32_t Charset::utf8ToUtf32(char const *s, size_t *read) uint32_t Charset::utf8ToUtf32(char const *s, size_t *read)
{ {
return cucul_utf8_to_utf32(s, read);
return caca_utf8_to_utf32(s, read);
} }
size_t Charset::utf32ToUtf8(char *buf, uint32_t ch) size_t Charset::utf32ToUtf8(char *buf, uint32_t ch)
{ {
return cucul_utf32_to_utf8(buf, ch);
return caca_utf32_to_utf8(buf, ch);
} }
uint8_t Charset::utf32ToCp437(uint32_t ch) uint8_t Charset::utf32ToCp437(uint32_t ch)
{ {
return cucul_utf32_to_cp437(ch);
return caca_utf32_to_cp437(ch);
} }
uint32_t Charset::cp437ToUtf32(uint8_t ch) uint32_t Charset::cp437ToUtf32(uint8_t ch)
{ {
return cucul_cp437_to_utf32(ch);
return caca_cp437_to_utf32(ch);
} }




Cucul::Cucul()
Canvas::Canvas()
{ {
cv = cucul_create_canvas(0, 0);
cv = caca_create_canvas(0, 0);
if(!cv) if(!cv)
throw -1; throw -1;
} }


Cucul::Cucul(int width, int height)
Canvas::Canvas(int width, int height)
{ {
cv = cucul_create_canvas(width, height);
cv = caca_create_canvas(width, height);
if(!cv) throw -1; if(!cv) throw -1;
} }


Cucul::~Cucul()
Canvas::~Canvas()
{ {
if(cv) if(cv)
cucul_free_canvas(cv);
caca_free_canvas(cv);
} }


cucul_canvas_t *Cucul::get_cucul_canvas_t()
caca_canvas_t *Canvas::get_caca_canvas_t()
{ {
return cv; return cv;
} }


void Cucul::setSize(unsigned int width, unsigned int height)
void Canvas::setSize(unsigned int width, unsigned int height)
{ {
cucul_set_canvas_size(cv, width, height);
caca_set_canvas_size(cv, width, height);
} }


unsigned int Cucul::getWidth(void)
unsigned int Canvas::getWidth(void)
{ {
return cucul_get_canvas_width(cv);
return caca_get_canvas_width(cv);
} }


unsigned int Cucul::getHeight(void)
unsigned int Canvas::getHeight(void)
{ {
return cucul_get_canvas_height(cv);
return caca_get_canvas_height(cv);
} }


int Cucul::setColorANSI(uint8_t f, uint8_t b)
int Canvas::setColorANSI(uint8_t f, uint8_t b)
{ {
return cucul_set_color_ansi(cv, f, b);
return caca_set_color_ansi(cv, f, b);
} }


int Cucul::setColorARGB(unsigned int f, unsigned int b)
int Canvas::setColorARGB(unsigned int f, unsigned int b)
{ {
return cucul_set_color_argb(cv, f, b);
return caca_set_color_argb(cv, f, b);
} }


void Cucul::putChar(int x, int y, uint32_t ch)
void Canvas::putChar(int x, int y, uint32_t ch)
{ {
cucul_put_char(cv, x, y, ch);
caca_put_char(cv, x, y, ch);
} }


uint32_t Cucul::getChar(int x, int y)
uint32_t Canvas::getChar(int x, int y)
{ {
return cucul_get_char(cv, x, y);
return caca_get_char(cv, x, y);
} }


void Cucul::putStr(int x, int y, char *str)
void Canvas::putStr(int x, int y, char *str)
{ {
cucul_put_str(cv, x, y, str);
caca_put_str(cv, x, y, str);
} }


void Cucul::Printf(int x, int y, char const * format, ...)
void Canvas::Printf(int x, int y, char const * format, ...)
{ {
char tmp[BUFSIZ]; char tmp[BUFSIZ];
char *buf = tmp; char *buf = tmp;
@@ -125,297 +125,297 @@ void Cucul::Printf(int x, int y, char const * format, ...)
putStr(x, y, buf); putStr(x, y, buf);
} }


void Cucul::Clear(void)
void Canvas::Clear(void)
{ {
cucul_clear_canvas(cv);
caca_clear_canvas(cv);
} }


void Cucul::Blit(int x, int y, Cucul* c1, Cucul* c2)
void Canvas::Blit(int x, int y, Canvas* c1, Canvas* c2)
{ {
cucul_blit(cv, x, y, c1->get_cucul_canvas_t(),
c2 ? c2->get_cucul_canvas_t() : NULL);
caca_blit(cv, x, y, c1->get_caca_canvas_t(),
c2 ? c2->get_caca_canvas_t() : NULL);
} }


void Cucul::Invert()
void Canvas::Invert()
{ {
cucul_invert(cv);
caca_invert(cv);
} }


void Cucul::Flip()
void Canvas::Flip()
{ {
cucul_flip(cv);
caca_flip(cv);
} }


void Cucul::Flop()
void Canvas::Flop()
{ {
cucul_flop(cv);
caca_flop(cv);
} }


void Cucul::Rotate180()
void Canvas::Rotate180()
{ {
cucul_rotate_180(cv);
caca_rotate_180(cv);
} }


void Cucul::RotateLeft()
void Canvas::RotateLeft()
{ {
cucul_rotate_left(cv);
caca_rotate_left(cv);
} }


void Cucul::RotateRight()
void Canvas::RotateRight()
{ {
cucul_rotate_right(cv);
caca_rotate_right(cv);
} }


void Cucul::drawLine(int x1, int y1, int x2, int y2, uint32_t ch)
void Canvas::drawLine(int x1, int y1, int x2, int y2, uint32_t ch)
{ {
cucul_draw_line(cv, x1, y1, x2, y2, ch);
caca_draw_line(cv, x1, y1, x2, y2, ch);
} }


void Cucul::drawPolyline(int const x[], int const y[], int f, uint32_t ch)
void Canvas::drawPolyline(int const x[], int const y[], int f, uint32_t ch)
{ {
cucul_draw_polyline(cv, x, y, f, ch);
caca_draw_polyline(cv, x, y, f, ch);
} }


void Cucul::drawThinLine(int x1, int y1, int x2, int y2)
void Canvas::drawThinLine(int x1, int y1, int x2, int y2)
{ {
cucul_draw_thin_line(cv, x1, y1, x2, y2);
caca_draw_thin_line(cv, x1, y1, x2, y2);
} }


void Cucul::drawThinPolyline(int const x[], int const y[], int f)
void Canvas::drawThinPolyline(int const x[], int const y[], int f)
{ {
cucul_draw_thin_polyline(cv, x, y, f);
caca_draw_thin_polyline(cv, x, y, f);
} }


void Cucul::drawCircle(int x, int y, int d, uint32_t ch)
void Canvas::drawCircle(int x, int y, int d, uint32_t ch)
{ {
cucul_draw_circle(cv, x, y, d, ch);
caca_draw_circle(cv, x, y, d, ch);
} }


void Cucul::drawEllipse(int x, int y, int d1, int d2, uint32_t ch)
void Canvas::drawEllipse(int x, int y, int d1, int d2, uint32_t ch)
{ {
cucul_draw_ellipse(cv, x, y, d1, d2, ch);
caca_draw_ellipse(cv, x, y, d1, d2, ch);
} }


void Cucul::drawThinEllipse(int x, int y, int d1, int d2)
void Canvas::drawThinEllipse(int x, int y, int d1, int d2)
{ {
cucul_draw_thin_ellipse(cv, x, y, d1, d2);
caca_draw_thin_ellipse(cv, x, y, d1, d2);
} }


void Cucul::fillEllipse(int x, int y, int d1, int d2, uint32_t ch)
void Canvas::fillEllipse(int x, int y, int d1, int d2, uint32_t ch)
{ {
cucul_fill_ellipse(cv, x, y, d1, d2, ch);
caca_fill_ellipse(cv, x, y, d1, d2, ch);
} }


void Cucul::drawBox(int x, int y, int w, int h, uint32_t ch)
void Canvas::drawBox(int x, int y, int w, int h, uint32_t ch)
{ {
cucul_draw_box(cv, x, y, w, h, ch);
caca_draw_box(cv, x, y, w, h, ch);
} }


void Cucul::drawThinBox(int x, int y, int w, int h)
void Canvas::drawThinBox(int x, int y, int w, int h)
{ {
cucul_draw_thin_box(cv, x, y, w, h);
caca_draw_thin_box(cv, x, y, w, h);
} }


void Cucul::drawCP437Box(int x, int y, int w, int h)
void Canvas::drawCP437Box(int x, int y, int w, int h)
{ {
cucul_draw_cp437_box(cv, x, y, w, h);
caca_draw_cp437_box(cv, x, y, w, h);
} }


void Cucul::fillBox(int x, int y, int w, int h, uint32_t ch)
void Canvas::fillBox(int x, int y, int w, int h, uint32_t ch)
{ {
cucul_fill_box(cv, x, y, w, h, ch);
caca_fill_box(cv, x, y, w, h, ch);
} }


void Cucul::drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, uint32_t ch)
void Canvas::drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, uint32_t ch)
{ {
cucul_draw_triangle(cv, x1, y1, x2, y2, x3, y3, ch);
caca_draw_triangle(cv, x1, y1, x2, y2, x3, y3, ch);
} }


void Cucul::drawThinTriangle(int x1, int y1, int x2, int y2, int x3, int y3)
void Canvas::drawThinTriangle(int x1, int y1, int x2, int y2, int x3, int y3)
{ {
cucul_draw_thin_triangle(cv, x1, y1, x2, y2, x3, y3);
caca_draw_thin_triangle(cv, x1, y1, x2, y2, x3, y3);
} }


void Cucul::fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, uint32_t ch)
void Canvas::fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, uint32_t ch)
{ {
cucul_fill_triangle(cv, x1, y1, x2, y2, x3, y3, ch);
caca_fill_triangle(cv, x1, y1, x2, y2, x3, y3, ch);
} }


int Cucul::Rand(int min, int max)
int Canvas::Rand(int min, int max)
{ {
return cucul_rand(min, max);
return caca_rand(min, max);
} }


const char * Cucul::getVersion()
const char * Canvas::getVersion()
{ {
return cucul_get_version();
return caca_get_version();
} }


int Cucul::setAttr(uint32_t attr)
int Canvas::setAttr(uint32_t attr)
{ {
return cucul_set_attr(cv, attr);
return caca_set_attr(cv, attr);
} }


uint32_t Cucul::getAttr(int x, int y)
uint32_t Canvas::getAttr(int x, int y)
{ {
return cucul_get_attr(cv, x, y);
return caca_get_attr(cv, x, y);
} }


int Cucul::setBoundaries(cucul_canvas_t *, int x, int y,
int Canvas::setBoundaries(caca_canvas_t *, int x, int y,
unsigned int w, unsigned int h) unsigned int w, unsigned int h)
{ {
return cucul_set_canvas_boundaries(cv, x, y, h, w);
return caca_set_canvas_boundaries(cv, x, y, h, w);
} }


unsigned int Cucul::getFrameCount()
unsigned int Canvas::getFrameCount()
{ {
return cucul_get_frame_count(cv);
return caca_get_frame_count(cv);
} }
int Cucul::setFrame(unsigned int f)
int Canvas::setFrame(unsigned int f)
{ {
return cucul_set_frame(cv, f);
return caca_set_frame(cv, f);
} }
int Cucul::createFrame(unsigned int f)
int Canvas::createFrame(unsigned int f)
{ {
return cucul_create_frame(cv, f);
return caca_create_frame(cv, f);
} }
int Cucul::freeFrame(unsigned int f)
int Canvas::freeFrame(unsigned int f)
{ {
return cucul_create_frame(cv, f);
return caca_create_frame(cv, f);
} }


char const *const * Cucul::getImportList(void)
char const *const * Canvas::getImportList(void)
{ {
return cucul_get_import_list();
return caca_get_import_list();
} }


long int Cucul::importMemory(void const *buf, size_t len, char const *fmt)
long int Canvas::importMemory(void const *buf, size_t len, char const *fmt)
{ {
return cucul_import_memory(cv, buf, len, fmt);
return caca_import_memory(cv, buf, len, fmt);
} }


long int Cucul::importFile(char const *file, char const *fmt)
long int Canvas::importFile(char const *file, char const *fmt)
{ {
return cucul_import_file(cv, file, fmt);
return caca_import_file(cv, file, fmt);
} }


char const *const * Cucul::getExportList(void)
char const *const * Canvas::getExportList(void)
{ {
return cucul_get_export_list();
return caca_get_export_list();
} }


void *Cucul::exportMemory(char const *fmt, size_t *len)
void *Canvas::exportMemory(char const *fmt, size_t *len)
{ {
return cucul_export_memory(cv, fmt, len);
return caca_export_memory(cv, fmt, len);
} }


Dither::Dither(unsigned int v1, unsigned int v2, unsigned int v3, unsigned int v4, unsigned int v5, unsigned int v6, unsigned int v7, unsigned int v8) Dither::Dither(unsigned int v1, unsigned int v2, unsigned int v3, unsigned int v4, unsigned int v5, unsigned int v6, unsigned int v7, unsigned int v8)
{ {
dither = cucul_create_dither(v1, v2, v3, v4, v5, v6, v7, v8);
dither = caca_create_dither(v1, v2, v3, v4, v5, v6, v7, v8);
} }
Dither::~Dither() Dither::~Dither()
{ {
cucul_free_dither(dither);
caca_free_dither(dither);
} }


void Dither::setPalette(uint32_t r[], uint32_t g[], uint32_t b[], uint32_t a[]) void Dither::setPalette(uint32_t r[], uint32_t g[], uint32_t b[], uint32_t a[])
{ {
cucul_set_dither_palette(dither, r, g, b, a);
caca_set_dither_palette(dither, r, g, b, a);
} }


void Dither::setBrightness(float f) void Dither::setBrightness(float f)
{ {
cucul_set_dither_brightness(dither, f);
caca_set_dither_brightness(dither, f);
} }


void Dither::setGamma(float f) void Dither::setGamma(float f)
{ {
cucul_set_dither_gamma(dither, f);
caca_set_dither_gamma(dither, f);
} }


void Dither::setContrast(float f) void Dither::setContrast(float f)
{ {
cucul_set_dither_contrast(dither, f);
caca_set_dither_contrast(dither, f);
} }


void Dither::setAntialias(char const *cv) void Dither::setAntialias(char const *cv)
{ {
cucul_set_dither_antialias(dither, cv);
caca_set_dither_antialias(dither, cv);
} }


char const *const * Dither::getAntialiasList() char const *const * Dither::getAntialiasList()
{ {
return cucul_get_dither_antialias_list(dither);
return caca_get_dither_antialias_list(dither);
} }


void Dither::setColor(char const *cv) void Dither::setColor(char const *cv)
{ {
cucul_set_dither_color(dither, cv);
caca_set_dither_color(dither, cv);
} }


char const *const * Dither::getColorList() char const *const * Dither::getColorList()
{ {
return cucul_get_dither_color_list(dither);
return caca_get_dither_color_list(dither);
} }


void Dither::setCharset(char const *cv) void Dither::setCharset(char const *cv)
{ {
cucul_set_dither_charset(dither, cv);
caca_set_dither_charset(dither, cv);
} }


char const *const * Dither::getCharsetList() char const *const * Dither::getCharsetList()
{ {
return cucul_get_dither_charset_list(dither);
return caca_get_dither_charset_list(dither);
} }


void Dither::setMode(char const *cv) void Dither::setMode(char const *cv)
{ {
cucul_set_dither_algorithm(dither, cv);
caca_set_dither_algorithm(dither, cv);
} }


char const *const * Dither::getModeList(void) char const *const * Dither::getModeList(void)
{ {
return cucul_get_dither_algorithm_list(dither);
return caca_get_dither_algorithm_list(dither);
} }


void Dither::Bitmap(Cucul *cv, int x, int y, int w, int h, void *v)
void Dither::Bitmap(Canvas *cv, int x, int y, int w, int h, void *v)
{ {
cucul_dither_bitmap(cv->get_cucul_canvas_t(), x, y, w, h, dither, v);
caca_dither_bitmap(cv->get_caca_canvas_t(), x, y, w, h, dither, v);
} }


Font::Font(void const *s, unsigned int v) Font::Font(void const *s, unsigned int v)
{ {
font = cucul_load_font(s, v);
font = caca_load_font(s, v);
if(!font) throw -1; if(!font) throw -1;
} }


char const *const * Font::getList(void) char const *const * Font::getList(void)
{ {
return cucul_get_font_list();
return caca_get_font_list();
} }


unsigned int Font::getWidth() unsigned int Font::getWidth()
{ {
return cucul_get_font_width(font);
return caca_get_font_width(font);
} }


unsigned int Font::getHeight() unsigned int Font::getHeight()
{ {
return cucul_get_font_height(font);
return caca_get_font_height(font);
} }


void Font::renderCanvas(Cucul *cv, uint8_t *buf, unsigned int x, unsigned int y, unsigned int w)
void Font::renderCanvas(Canvas *cv, uint8_t *buf, unsigned int x, unsigned int y, unsigned int w)
{ {
cucul_render_canvas(cv->get_cucul_canvas_t(), font, buf, x, y, w);
caca_render_canvas(cv->get_caca_canvas_t(), font, buf, x, y, w);
} }


uint32_t const *Font::getBlocks() uint32_t const *Font::getBlocks()
{ {
return cucul_get_font_blocks(font);
return caca_get_font_blocks(font);
} }


Font::~Font() Font::~Font()
{ {
cucul_free_font(font);
caca_free_font(font);
} }



+ 19
- 19
cxx/cucul++.h View File

@@ -1,5 +1,5 @@
/* /*
* libcucul++ C++ bindings for libcucul
* libcaca++ C++ bindings for libcaca
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org> * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -12,28 +12,28 @@
* http://sam.zoy.org/wtfpl/COPYING for more details. * http://sam.zoy.org/wtfpl/COPYING for more details.
*/ */


/** \file cucul++.h
/** \file caca++.h
* \version \$Id$ * \version \$Id$
* \author Jean-Yves Lamoureux <jylam@lnxscene.org> * \author Jean-Yves Lamoureux <jylam@lnxscene.org>
* \brief The \e libcucul++ public header.
* \brief The \e libcaca++ public header.
* *
* This header contains the public types and functions that applications * This header contains the public types and functions that applications
* using \e libcucul++ may use.
* using \e libcaca++ may use.
*/ */


#ifndef _CUCUL_PP_H #ifndef _CUCUL_PP_H
#define _CUCUL_PP_H #define _CUCUL_PP_H


#include <cucul.h>
#include <caca.h>


#undef __class #undef __class
#if defined(_WIN32) && defined(__LIBCUCUL_PP__)
#if defined(_WIN32) && defined(__LIBCACA_PP__)
# define __class class __declspec(dllexport) # define __class class __declspec(dllexport)
#else #else
# define __class class # define __class class
#endif #endif


class Cucul;
class Canvas;


__class Charset __class Charset
{ {
@@ -53,12 +53,12 @@ __class Font
char const *const * getList(void); char const *const * getList(void);
unsigned int getWidth(); unsigned int getWidth();
unsigned int getHeight(); unsigned int getHeight();
void renderCanvas(Cucul *, uint8_t *, unsigned int,
void renderCanvas(Canvas *, uint8_t *, unsigned int,
unsigned int, unsigned int); unsigned int, unsigned int);
uint32_t const *getBlocks(); uint32_t const *getBlocks();


private: private:
cucul_font *font;
caca_font *font;
}; };


__class Dither __class Dither
@@ -81,21 +81,21 @@ __class Dither
char const *const * getCharsetList(); char const *const * getCharsetList();
void setMode(char const *); void setMode(char const *);
char const *const * getModeList(); char const *const * getModeList();
void Bitmap(Cucul *, int, int, int, int, void *);
void Bitmap(Canvas *, int, int, int, int, void *);


private: private:
cucul_dither *dither;
caca_dither *dither;
}; };


__class Cucul
__class Canvas
{ {
friend class Caca; friend class Caca;
friend class Dither; friend class Dither;
friend class Font; friend class Font;
public: public:
Cucul();
Cucul(int width, int height);
~Cucul();
Canvas();
Canvas(int width, int height);
~Canvas();


void setSize(unsigned int w, unsigned int h); void setSize(unsigned int w, unsigned int h);
unsigned int getWidth(void); unsigned int getWidth(void);
@@ -109,7 +109,7 @@ __class Cucul
uint32_t getChar(int, int); uint32_t getChar(int, int);
void putStr(int x, int y, char *str); void putStr(int x, int y, char *str);
void Clear(void); void Clear(void);
void Blit(int, int, Cucul* c1, Cucul* c2);
void Blit(int, int, Canvas* c1, Canvas* c2);
void Invert(); void Invert();
void Flip(); void Flip();
void Flop(); void Flop();
@@ -131,7 +131,7 @@ __class Cucul
void drawTriangle(int, int, int, int, int, int, uint32_t); void drawTriangle(int, int, int, int, int, int, uint32_t);
void drawThinTriangle(int, int, int, int, int, int); void drawThinTriangle(int, int, int, int, int, int);
void fillTriangle(int, int, int, int, int, int, uint32_t); void fillTriangle(int, int, int, int, int, int, uint32_t);
int setBoundaries(cucul_canvas_t *, int, int, unsigned int, unsigned int);
int setBoundaries(caca_canvas_t *, int, int, unsigned int, unsigned int);
unsigned int getFrameCount(); unsigned int getFrameCount();
int setFrame(unsigned int); int setFrame(unsigned int);
int createFrame(unsigned int); int createFrame(unsigned int);
@@ -147,10 +147,10 @@ __class Cucul
static char const * getVersion(); static char const * getVersion();


protected: protected:
cucul_canvas_t *get_cucul_canvas_t();
caca_canvas_t *get_caca_canvas_t();


private: private:
cucul_canvas_t *cv;
caca_canvas_t *cv;
}; };


#endif /* _CUCUL_PP_H */ #endif /* _CUCUL_PP_H */

+ 5
- 5
cxx/cxxtest.cpp View File

@@ -40,13 +40,13 @@ static char const pigstring[] =


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
Cucul *cv, *pig;
Canvas *cv, *pig;
Caca *dp; Caca *dp;


int x = 0, y = 0, ix = 1, iy = 1; int x = 0, y = 0, ix = 1, iy = 1;


try { try {
cv = new Cucul();
cv = new Canvas();
} }
catch (int e) { catch (int e) {
cerr << "Error while initializing cucul (" << e << ")" << endl; cerr << "Error while initializing cucul (" << e << ")" << endl;
@@ -63,8 +63,8 @@ int main(int argc, char *argv[])


try { try {
// Import buffer into a canvas // Import buffer into a canvas
pig = new Cucul();
pig->setColorANSI(CUCUL_LIGHTMAGENTA, CUCUL_TRANSPARENT);
pig = new Canvas();
pig->setColorANSI(CACA_LIGHTMAGENTA, CACA_TRANSPARENT);
pig->importMemory(pigstring, strlen(pigstring), "text"); pig->importMemory(pigstring, strlen(pigstring), "text");
} }
catch(int e) { catch(int e) {
@@ -89,7 +89,7 @@ int main(int argc, char *argv[])
cv->Blit(x, y, pig, NULL); cv->Blit(x, y, pig, NULL);


/* printf works */ /* printf works */
cv->setColorANSI(CUCUL_LIGHTBLUE, CUCUL_BLACK);
cv->setColorANSI(CACA_LIGHTBLUE, CACA_BLACK);
cv->Printf(cv->getWidth() / 2 - 10, cv->getHeight() / 2, cv->Printf(cv->getWidth() / 2 - 10, cv->getHeight() / 2,
"Powered by libcaca %s", dp->getVersion()); "Powered by libcaca %s", dp->getVersion());




+ 4
- 4
doc/Makefile.am View File

@@ -8,10 +8,10 @@ man_MANS = caca-config.1 cacafire.1 cacaview.1 cacaserver.1 img2txt.1 cacaplay.1


if BUILD_DOCUMENTATION if BUILD_DOCUMENTATION
htmldoc_DATA = html/doxygen.css htmldoc_DATA = html/doxygen.css
htmldocdir = $(datadir)/doc/libcucul-dev/html
htmldocdir = $(datadir)/doc/libcaca-dev/html
if USE_LATEX if USE_LATEX
pdfdoc_DATA = latex/libcaca.pdf pdfdoc_DATA = latex/libcaca.pdf
pdfdocdir = $(datadir)/doc/libcucul-dev/pdf
pdfdocdir = $(datadir)/doc/libcaca-dev/pdf
endif endif
endif endif


@@ -43,9 +43,9 @@ clean-local:


install-data-local: install-data-local:
if BUILD_DOCUMENTATION if BUILD_DOCUMENTATION
$(mkinstalldirs) $(DESTDIR)$(datadir)/doc/libcucul-dev/html
$(mkinstalldirs) $(DESTDIR)$(datadir)/doc/libcaca-dev/html
cp `find html -name '*.html' -o -name '*.gif' -o -name '*.png'` \ cp `find html -name '*.html' -o -name '*.gif' -o -name '*.png'` \
$(DESTDIR)$(datadir)/doc/libcucul-dev/html
$(DESTDIR)$(datadir)/doc/libcaca-dev/html
$(mkinstalldirs) $(DESTDIR)$(mandir)/man3 $(mkinstalldirs) $(DESTDIR)$(mandir)/man3
for man in $$(find man -name '*.3caca'); do \ for man in $$(find man -name '*.3caca'); do \
sed -e 's/man3caca/man3/g' -e "s/fC'\([a-zA-Z0-9]*\)'/fC\"\1\"/g" \ sed -e 's/man3caca/man3/g' -e "s/fC'\([a-zA-Z0-9]*\)'/fC\"\1\"/g" \


+ 28
- 29
examples/Makefile.am View File

@@ -1,82 +1,81 @@
# $Id$ # $Id$


AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/cucul -I../cucul \
-I$(top_srcdir)/caca -DDATADIR=\"$(pkgdatadir)\"
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/caca -DDATADIR=\"$(pkgdatadir)\"


noinst_PROGRAMS = blit colors cucul demo demo0 dithering driver event export figfont font font2tga frames fullwidth gamma hsv input spritedit swallow text transform truecolor unicode import
noinst_PROGRAMS = blit canvas colors demo demo0 dithering driver event export figfont font font2tga frames fullwidth gamma hsv input spritedit swallow text transform truecolor unicode import


blit_SOURCES = blit.c blit_SOURCES = blit.c
blit_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
blit_LDADD = ../caca/libcaca.la


colors_SOURCES = colors.c
colors_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
canvas_SOURCES = canvas.c
canvas_LDADD = ../caca/libcaca.la


cucul_SOURCES = cucul.c
cucul_LDADD = ../cucul/libcucul.la
colors_SOURCES = colors.c
colors_LDADD = ../caca/libcaca.la


demo_SOURCES = demo.c demo_SOURCES = demo.c
demo_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
demo_LDADD = ../caca/libcaca.la
demo_LDFLAGS = @MATH_LIBS@ demo_LDFLAGS = @MATH_LIBS@


demo0_SOURCES = demo0.c demo0_SOURCES = demo0.c
demo0_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
demo0_LDADD = ../caca/libcaca.la
demo0_LDFLAGS = @MATH_LIBS@ demo0_LDFLAGS = @MATH_LIBS@


dithering_SOURCES = dithering.c dithering_SOURCES = dithering.c
dithering_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
dithering_LDADD = ../caca/libcaca.la


driver_SOURCES = driver.c driver_SOURCES = driver.c
driver_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
driver_LDADD = ../caca/libcaca.la


event_SOURCES = event.c event_SOURCES = event.c
event_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
event_LDADD = ../caca/libcaca.la


export_SOURCES = export.c export_SOURCES = export.c
export_LDADD = ../cucul/libcucul.la
export_LDADD = ../caca/libcaca.la


figfont_SOURCES = figfont.c figfont_SOURCES = figfont.c
figfont_LDADD = ../cucul/libcucul.la
figfont_LDADD = ../caca/libcaca.la


font_SOURCES = font.c font_SOURCES = font.c
font_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
font_LDADD = ../caca/libcaca.la


font2tga_SOURCES = font2tga.c font2tga_SOURCES = font2tga.c
font2tga_LDADD = ../cucul/libcucul.la
font2tga_LDADD = ../caca/libcaca.la


frames_SOURCES = frames.c frames_SOURCES = frames.c
frames_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
frames_LDADD = ../caca/libcaca.la


fullwidth_SOURCES = fullwidth.c fullwidth_SOURCES = fullwidth.c
fullwidth_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
fullwidth_LDADD = ../caca/libcaca.la


gamma_SOURCES = gamma.c gamma_SOURCES = gamma.c
gamma_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
gamma_LDADD = ../caca/libcaca.la
gamma_LDFLAGS = @MATH_LIBS@ gamma_LDFLAGS = @MATH_LIBS@


hsv_SOURCES = hsv.c hsv_SOURCES = hsv.c
hsv_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
hsv_LDADD = ../caca/libcaca.la


input_SOURCES = input.c input_SOURCES = input.c
input_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
input_LDADD = ../caca/libcaca.la


spritedit_SOURCES = spritedit.c spritedit_SOURCES = spritedit.c
spritedit_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
spritedit_LDADD = ../caca/libcaca.la


swallow_SOURCES = swallow.c swallow_SOURCES = swallow.c
swallow_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
swallow_LDADD = ../caca/libcaca.la


text_SOURCES = text.c text_SOURCES = text.c
text_LDADD = ../cucul/libcucul.la
text_LDADD = ../caca/libcaca.la


transform_SOURCES = transform.c transform_SOURCES = transform.c
transform_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
transform_LDADD = ../caca/libcaca.la


truecolor_SOURCES = truecolor.c truecolor_SOURCES = truecolor.c
truecolor_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
truecolor_LDADD = ../caca/libcaca.la


unicode_SOURCES = unicode.c unicode_SOURCES = unicode.c
unicode_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
unicode_LDADD = ../caca/libcaca.la


import_SOURCES = import.c import_SOURCES = import.c
import_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
import_LDADD = ../caca/libcaca.la



+ 13
- 14
examples/blit.c View File

@@ -19,7 +19,6 @@
# include <string.h> # include <string.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"


static char const pig[] = static char const pig[] =
@@ -40,10 +39,10 @@ static char const pig[] =


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
cucul_canvas_t *cv, *sprite;
caca_canvas_t *cv, *sprite;
caca_display_t *dp; caca_display_t *dp;


cv = cucul_create_canvas(80, 24);
cv = caca_create_canvas(80, 24);
if(cv == NULL) if(cv == NULL)
{ {
printf("Failed to create canvas\n"); printf("Failed to create canvas\n");
@@ -57,25 +56,25 @@ int main(int argc, char *argv[])
return 1; return 1;
} }


sprite = cucul_create_canvas(0, 0);
cucul_set_color_ansi(sprite, CUCUL_LIGHTRED, CUCUL_BLACK);
cucul_import_memory(sprite, pig, strlen(pig), "text");
cucul_set_canvas_handle(sprite, cucul_get_canvas_width(sprite) / 2,
cucul_get_canvas_height(sprite) / 2);
sprite = caca_create_canvas(0, 0);
caca_set_color_ansi(sprite, CACA_LIGHTRED, CACA_BLACK);
caca_import_memory(sprite, pig, strlen(pig), "text");
caca_set_canvas_handle(sprite, caca_get_canvas_width(sprite) / 2,
caca_get_canvas_height(sprite) / 2);


cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
cucul_put_str(cv, 0, 0, "Centered sprite");
caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
caca_put_str(cv, 0, 0, "Centered sprite");


cucul_blit(cv, cucul_get_canvas_width(cv) / 2,
cucul_get_canvas_height(cv) / 2, sprite, NULL);
caca_blit(cv, caca_get_canvas_width(cv) / 2,
caca_get_canvas_height(cv) / 2, sprite, NULL);


caca_refresh_display(dp); caca_refresh_display(dp);


caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);


caca_free_display(dp); caca_free_display(dp);
cucul_free_canvas(sprite);
cucul_free_canvas(cv);
caca_free_canvas(sprite);
caca_free_canvas(cv);


return 0; return 0;
} }


examples/cucul.c → examples/canvas.c View File

@@ -19,30 +19,29 @@
# include <string.h> # include <string.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"


#define ITER 128 #define ITER 128


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
cucul_canvas_t *cv;
caca_canvas_t *cv;
unsigned int i, j, w, h; unsigned int i, j, w, h;


fprintf(stderr, "testing cucul_create_canvas()\n");
fprintf(stderr, "testing caca_create_canvas()\n");
for(i = 0; i < ITER; i++) for(i = 0; i < ITER; i++)
{ {
w = cucul_rand(1, 1000);
h = cucul_rand(1, 1000);
cv = cucul_create_canvas(w, h);
cucul_put_char(cv, w - 1, h - 1, 'x');
if(cucul_get_char(cv, w - 1, h - 1) != 'x')
w = caca_rand(1, 1000);
h = caca_rand(1, 1000);
cv = caca_create_canvas(w, h);
caca_put_char(cv, w - 1, h - 1, 'x');
if(caca_get_char(cv, w - 1, h - 1) != 'x')
fprintf(stderr, " failed (%ux%u)\n", w, h); fprintf(stderr, " failed (%ux%u)\n", w, h);
cucul_free_canvas(cv);
caca_free_canvas(cv);
} }


fprintf(stderr, "testing cucul_set_frame_name()\n");
cv = cucul_create_canvas(1, 1);
fprintf(stderr, "testing caca_set_frame_name()\n");
cv = caca_create_canvas(1, 1);
if(cv == NULL) if(cv == NULL)
{ {
printf("Failed to create canvas\n"); printf("Failed to create canvas\n");
@@ -51,17 +50,17 @@ int main(int argc, char *argv[])


for(i = 0; i < ITER; i++) for(i = 0; i < ITER; i++)
{ {
cucul_create_frame(cv, 0);
caca_create_frame(cv, 0);
for(j = 0; j < ITER; j++) for(j = 0; j < ITER; j++)
{ {
char buf[BUFSIZ]; char buf[BUFSIZ];
w = cucul_rand(1, 1000);
w = caca_rand(1, 1000);
memset(buf, 'x', w); memset(buf, 'x', w);
buf[w] = '\0'; buf[w] = '\0';
cucul_set_frame_name(cv, buf);
caca_set_frame_name(cv, buf);
} }
} }
cucul_free_canvas(cv);
caca_free_canvas(cv);


fprintf(stderr, "all tests passed\n"); fprintf(stderr, "all tests passed\n");
return 0; return 0;

+ 19
- 20
examples/colors.c View File

@@ -18,16 +18,15 @@
# include <stdio.h> # include <stdio.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"


int main(int argc, char **argv) int main(int argc, char **argv)
{ {
cucul_canvas_t *cv;
caca_canvas_t *cv;
caca_display_t *dp; caca_display_t *dp;
int i, j; int i, j;


cv = cucul_create_canvas(80, 24);
cv = caca_create_canvas(80, 24);
if(cv == NULL) if(cv == NULL)
{ {
printf("Failed to create canvas\n"); printf("Failed to create canvas\n");
@@ -41,36 +40,36 @@ int main(int argc, char **argv)
return 1; return 1;
} }


cucul_set_color_ansi(cv, CUCUL_LIGHTGRAY, CUCUL_BLACK);
cucul_clear_canvas(cv);
caca_set_color_ansi(cv, CACA_LIGHTGRAY, CACA_BLACK);
caca_clear_canvas(cv);
for(i = 0; i < 16; i++) for(i = 0; i < 16; i++)
{ {
cucul_set_color_ansi(cv, CUCUL_LIGHTGRAY, CUCUL_BLACK);
cucul_printf(cv, 3, i + (i >= 8 ? 3 : 2), "ANSI %i", i);
caca_set_color_ansi(cv, CACA_LIGHTGRAY, CACA_BLACK);
caca_printf(cv, 3, i + (i >= 8 ? 3 : 2), "ANSI %i", i);
for(j = 0; j < 16; j++) for(j = 0; j < 16; j++)
{ {
cucul_set_color_ansi(cv, i, j);
cucul_put_str(cv, (j >= 8 ? 13 : 12) + j * 4, i + (i >= 8 ? 3 : 2),
caca_set_color_ansi(cv, i, j);
caca_put_str(cv, (j >= 8 ? 13 : 12) + j * 4, i + (i >= 8 ? 3 : 2),
"Aaホ"); "Aaホ");
} }
} }


cucul_set_color_ansi(cv, CUCUL_LIGHTGRAY, CUCUL_BLACK);
cucul_put_str(cv, 3, 20, "This is bold This is blink This is italics This is underline");
cucul_set_attr(cv, CUCUL_BOLD);
cucul_put_str(cv, 3 + 8, 20, "bold");
cucul_set_attr(cv, CUCUL_BLINK);
cucul_put_str(cv, 3 + 24, 20, "blink");
cucul_set_attr(cv, CUCUL_ITALICS);
cucul_put_str(cv, 3 + 41, 20, "italics");
cucul_set_attr(cv, CUCUL_UNDERLINE);
cucul_put_str(cv, 3 + 60, 20, "underline");
caca_set_color_ansi(cv, CACA_LIGHTGRAY, CACA_BLACK);
caca_put_str(cv, 3, 20, "This is bold This is blink This is italics This is underline");
caca_set_attr(cv, CACA_BOLD);
caca_put_str(cv, 3 + 8, 20, "bold");
caca_set_attr(cv, CACA_BLINK);
caca_put_str(cv, 3 + 24, 20, "blink");
caca_set_attr(cv, CACA_ITALICS);
caca_put_str(cv, 3 + 41, 20, "italics");
caca_set_attr(cv, CACA_UNDERLINE);
caca_put_str(cv, 3 + 60, 20, "underline");


caca_refresh_display(dp); caca_refresh_display(dp);
caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);


caca_free_display(dp); caca_free_display(dp);
cucul_free_canvas(cv);
caca_free_canvas(cv);


return 0; return 0;
} }


+ 155
- 156
examples/demo.c View File

@@ -20,7 +20,6 @@
# include <stdio.h> # include <stdio.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"


static void display_menu(void); static void display_menu(void);
@@ -39,10 +38,10 @@ int bounds = 0;
int outline = 0; int outline = 0;
int dithering = 0; int dithering = 0;
#if 0 #if 0
cucul_sprite_t *sprite = NULL;
caca_sprite_t *sprite = NULL;
#endif #endif


cucul_canvas_t *cv;
caca_canvas_t *cv;
caca_display_t *dp; caca_display_t *dp;


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


cv = cucul_create_canvas(80, 24);
cv = caca_create_canvas(80, 24);
if(cv == NULL) if(cv == NULL)
{ {
printf("Failed to create canvas\n"); printf("Failed to create canvas\n");
@@ -68,11 +67,11 @@ int main(int argc, char **argv)


/* Initialize data */ /* Initialize data */
#if 0 #if 0
sprite = cucul_load_sprite(DATADIR "/caca.txt");
sprite = caca_load_sprite(DATADIR "/caca.txt");
if(!sprite) if(!sprite)
sprite = cucul_load_sprite("caca.txt");
sprite = caca_load_sprite("caca.txt");
if(!sprite) if(!sprite)
sprite = cucul_load_sprite("examples/caca.txt");
sprite = caca_load_sprite("examples/caca.txt");
#endif #endif


/* Disable cursor */ /* Disable cursor */
@@ -119,7 +118,7 @@ int main(int argc, char **argv)
case 'd': case 'd':
case 'D': case 'D':
dithering = (dithering + 1) % 5; dithering = (dithering + 1) % 5;
cucul_set_feature(cv, dithering);
caca_set_feature(cv, dithering);
display_menu(); display_menu();
break; break;
#endif #endif
@@ -157,8 +156,8 @@ int main(int argc, char **argv)


if(demo) if(demo)
{ {
cucul_set_color_ansi(cv, CUCUL_LIGHTGRAY, CUCUL_BLACK);
cucul_clear_canvas(cv);
caca_set_color_ansi(cv, CACA_LIGHTGRAY, CACA_BLACK);
caca_clear_canvas(cv);
} }
} }
else if(caca_get_event_type(&ev) & CACA_EVENT_MOUSE_MOTION) else if(caca_get_event_type(&ev) & CACA_EVENT_MOUSE_MOTION)
@@ -178,9 +177,9 @@ int main(int argc, char **argv)
display_menu(); display_menu();
if(mouse && !demo) if(mouse && !demo)
{ {
cucul_set_color_ansi(cv, CUCUL_RED, CUCUL_BLACK);
cucul_put_str(cv, xmouse, ymouse, ".");
cucul_put_str(cv, xmouse, ymouse + 1, "|\\");
caca_set_color_ansi(cv, CACA_RED, CACA_BLACK);
caca_put_str(cv, xmouse, ymouse, ".");
caca_put_str(cv, xmouse, ymouse + 1, "|\\");
} }
caca_refresh_display(dp); caca_refresh_display(dp);
mouse = menu = 0; mouse = menu = 0;
@@ -190,10 +189,10 @@ int main(int argc, char **argv)
{ {
demo(); demo();


cucul_set_color_ansi(cv, CUCUL_LIGHTGRAY, CUCUL_BLACK);
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]----",
caca_set_color_ansi(cv, CACA_LIGHTGRAY, CACA_BLACK);
caca_draw_thin_box(cv, 1, 1, caca_get_canvas_width(cv) - 2,
caca_get_canvas_height(cv) - 2);
caca_printf(cv, 4, 1, "[%i.%i fps]----",
1000000 / caca_get_display_time(dp), 1000000 / caca_get_display_time(dp),
(10000000 / caca_get_display_time(dp)) % 10); (10000000 / caca_get_display_time(dp)) % 10);
caca_refresh_display(dp); caca_refresh_display(dp);
@@ -202,49 +201,49 @@ int main(int argc, char **argv)


/* Clean up */ /* Clean up */
#if 0 #if 0
cucul_free_sprite(sprite);
caca_free_sprite(sprite);
#endif #endif
caca_free_display(dp); caca_free_display(dp);
cucul_free_canvas(cv);
caca_free_canvas(cv);


return 0; return 0;
} }


static void display_menu(void) static void display_menu(void)
{ {
int xo = cucul_get_canvas_width(cv) - 2;
int yo = cucul_get_canvas_height(cv) - 2;
cucul_set_color_ansi(cv, CUCUL_LIGHTGRAY, CUCUL_BLACK);
cucul_clear_canvas(cv);
cucul_draw_thin_box(cv, 1, 1, xo, yo);
cucul_put_str(cv, (xo - strlen("libcaca demo")) / 2, 3, "libcaca demo");
cucul_put_str(cv, (xo - strlen("==============")) / 2, 4, "==============");
cucul_put_str(cv, 4, 6, "demos:");
cucul_put_str(cv, 4, 7, "'f': full");
cucul_put_str(cv, 4, 8, "'1': dots");
cucul_put_str(cv, 4, 9, "'2': lines");
cucul_put_str(cv, 4, 10, "'3': boxes");
cucul_put_str(cv, 4, 11, "'4': triangles");
cucul_put_str(cv, 4, 12, "'5': ellipses");
cucul_put_str(cv, 4, 13, "'c': colour");
cucul_put_str(cv, 4, 14, "'r': render");
int xo = caca_get_canvas_width(cv) - 2;
int yo = caca_get_canvas_height(cv) - 2;
caca_set_color_ansi(cv, CACA_LIGHTGRAY, CACA_BLACK);
caca_clear_canvas(cv);
caca_draw_thin_box(cv, 1, 1, xo, yo);
caca_put_str(cv, (xo - strlen("libcaca demo")) / 2, 3, "libcaca demo");
caca_put_str(cv, (xo - strlen("==============")) / 2, 4, "==============");
caca_put_str(cv, 4, 6, "demos:");
caca_put_str(cv, 4, 7, "'f': full");
caca_put_str(cv, 4, 8, "'1': dots");
caca_put_str(cv, 4, 9, "'2': lines");
caca_put_str(cv, 4, 10, "'3': boxes");
caca_put_str(cv, 4, 11, "'4': triangles");
caca_put_str(cv, 4, 12, "'5': ellipses");
caca_put_str(cv, 4, 13, "'c': colour");
caca_put_str(cv, 4, 14, "'r': render");
#if 0 #if 0
if(sprite) if(sprite)
cucul_put_str(cv, 4, 15, "'s': sprites");
caca_put_str(cv, 4, 15, "'s': sprites");
#endif #endif


cucul_put_str(cv, 4, 16, "settings:");
cucul_printf(cv, 4, 17, "'o': outline: %s",
caca_put_str(cv, 4, 16, "settings:");
caca_printf(cv, 4, 17, "'o': outline: %s",
outline == 0 ? "none" : outline == 1 ? "solid" : "thin"); outline == 0 ? "none" : outline == 1 ? "solid" : "thin");
cucul_printf(cv, 4, 18, "'b': drawing boundaries: %s",
caca_printf(cv, 4, 18, "'b': drawing boundaries: %s",
bounds == 0 ? "screen" : "infinite"); bounds == 0 ? "screen" : "infinite");
//cucul_printf(cv, 4, 19, "'d': dithering (%s)",
// cucul_get_feature_name(dithering));
//caca_printf(cv, 4, 19, "'d': dithering (%s)",
// caca_get_feature_name(dithering));


cucul_put_str(cv, 4, yo - 2, "'q': quit");
caca_put_str(cv, 4, yo - 2, "'q': quit");


caca_refresh_display(dp); caca_refresh_display(dp);
} }
@@ -257,104 +256,104 @@ static void demo_all(void)


i++; i++;


cucul_set_color_ansi(cv, CUCUL_LIGHTGRAY, CUCUL_BLACK);
cucul_clear_canvas(cv);
caca_set_color_ansi(cv, CACA_LIGHTGRAY, CACA_BLACK);
caca_clear_canvas(cv);


/* Draw the sun */ /* Draw the sun */
cucul_set_color_ansi(cv, CUCUL_YELLOW, CUCUL_BLACK);
xo = cucul_get_canvas_width(cv) / 4;
yo = cucul_get_canvas_height(cv) / 4 + 5 * sin(0.03*i);
caca_set_color_ansi(cv, CACA_YELLOW, CACA_BLACK);
xo = caca_get_canvas_width(cv) / 4;
yo = caca_get_canvas_height(cv) / 4 + 5 * sin(0.03*i);


for(j = 0; j < 16; j++) for(j = 0; j < 16; j++)
{ {
xa = xo - (30 + sin(0.03*i) * 8) * sin(0.03*i + M_PI*j/8); xa = xo - (30 + sin(0.03*i) * 8) * sin(0.03*i + M_PI*j/8);
ya = yo + (15 + sin(0.03*i) * 4) * cos(0.03*i + M_PI*j/8); ya = yo + (15 + sin(0.03*i) * 4) * cos(0.03*i + M_PI*j/8);
cucul_draw_thin_line(cv, xo, yo, xa, ya);
caca_draw_thin_line(cv, xo, yo, xa, ya);
} }


j = 15 + sin(0.03*i) * 8; j = 15 + sin(0.03*i) * 8;
cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLACK);
cucul_fill_ellipse(cv, xo, yo, j, j / 2, '#');
cucul_set_color_ansi(cv, CUCUL_YELLOW, CUCUL_BLACK);
cucul_draw_ellipse(cv, xo, yo, j, j / 2, '#');
caca_set_color_ansi(cv, CACA_WHITE, CACA_BLACK);
caca_fill_ellipse(cv, xo, yo, j, j / 2, '#');
caca_set_color_ansi(cv, CACA_YELLOW, CACA_BLACK);
caca_draw_ellipse(cv, xo, yo, j, j / 2, '#');


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


xa = cucul_get_canvas_width(cv) / 8 + sin(0.03*i) * 5;
ya = cucul_get_canvas_height(cv) / 2 + cos(0.03*i) * 5;
xa = caca_get_canvas_width(cv) / 8 + sin(0.03*i) * 5;
ya = caca_get_canvas_height(cv) / 2 + cos(0.03*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;
xb = caca_get_canvas_width(cv) - 10 - cos(0.02*i) * 10;
yb = caca_get_canvas_height(cv) * 3 / 4 - 5 + sin(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;
xc = caca_get_canvas_width(cv) / 4 - sin(0.02*i) * 5;
yc = caca_get_canvas_height(cv) * 3 / 4 + cos(0.02*i) * 5;


cucul_set_color_ansi(cv, CUCUL_GREEN, CUCUL_BLACK);
cucul_fill_triangle(cv, xo, yo, xb, yb, xa, ya, '%');
cucul_set_color_ansi(cv, CUCUL_YELLOW, CUCUL_BLACK);
cucul_draw_thin_triangle(cv, xo, yo, xb, yb, xa, ya);
caca_set_color_ansi(cv, CACA_GREEN, CACA_BLACK);
caca_fill_triangle(cv, xo, yo, xb, yb, xa, ya, '%');
caca_set_color_ansi(cv, CACA_YELLOW, CACA_BLACK);
caca_draw_thin_triangle(cv, xo, yo, xb, yb, xa, ya);


cucul_set_color_ansi(cv, CUCUL_RED, CUCUL_BLACK);
cucul_fill_triangle(cv, xa, ya, xb, yb, xc, yc, '#');
cucul_set_color_ansi(cv, CUCUL_YELLOW, CUCUL_BLACK);
cucul_draw_thin_triangle(cv, xa, ya, xb, yb, xc, yc);
caca_set_color_ansi(cv, CACA_RED, CACA_BLACK);
caca_fill_triangle(cv, xa, ya, xb, yb, xc, yc, '#');
caca_set_color_ansi(cv, CACA_YELLOW, CACA_BLACK);
caca_draw_thin_triangle(cv, xa, ya, xb, yb, xc, yc);


cucul_set_color_ansi(cv, CUCUL_BLUE, CUCUL_BLACK);
cucul_fill_triangle(cv, xo, yo, xb, yb, xc, yc, '%');
cucul_set_color_ansi(cv, CUCUL_YELLOW, CUCUL_BLACK);
cucul_draw_thin_triangle(cv, xo, yo, xb, yb, xc, yc);
caca_set_color_ansi(cv, CACA_BLUE, CACA_BLACK);
caca_fill_triangle(cv, xo, yo, xb, yb, xc, yc, '%');
caca_set_color_ansi(cv, CACA_YELLOW, CACA_BLACK);
caca_draw_thin_triangle(cv, xo, yo, xb, yb, xc, yc);


/* Draw a background triangle */ /* Draw a background triangle */
xa = 2; xa = 2;
ya = 2; ya = 2;


xb = cucul_get_canvas_width(cv) - 3;
yb = cucul_get_canvas_height(cv) / 2;
xb = caca_get_canvas_width(cv) - 3;
yb = caca_get_canvas_height(cv) / 2;


xc = cucul_get_canvas_width(cv) / 3;
yc = cucul_get_canvas_height(cv) - 3;
xc = caca_get_canvas_width(cv) / 3;
yc = caca_get_canvas_height(cv) - 3;


cucul_set_color_ansi(cv, CUCUL_CYAN, CUCUL_BLACK);
cucul_draw_thin_triangle(cv, xa, ya, xb, yb, xc, yc);
caca_set_color_ansi(cv, CACA_CYAN, CACA_BLACK);
caca_draw_thin_triangle(cv, xa, ya, xb, yb, xc, yc);


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;
xo = caca_get_canvas_width(cv) / 2 + cos(0.027*i) * caca_get_canvas_width(cv) / 3;
yo = caca_get_canvas_height(cv) / 2 - sin(0.027*i) * caca_get_canvas_height(cv) / 2;


cucul_draw_thin_line(cv, xa, ya, xo, yo);
cucul_draw_thin_line(cv, xb, yb, xo, yo);
cucul_draw_thin_line(cv, xc, yc, xo, yo);
caca_draw_thin_line(cv, xa, ya, xo, yo);
caca_draw_thin_line(cv, xb, yb, xo, yo);
caca_draw_thin_line(cv, xc, yc, xo, yo);


/* Draw a sprite on the pyramid */ /* Draw a sprite on the pyramid */
#if 0 #if 0
cucul_draw_sprite(cv, xo, yo, sprite, 0);
caca_draw_sprite(cv, xo, yo, sprite, 0);
#endif #endif


/* Draw a trail behind the foreground sprite */ /* Draw a trail behind the foreground sprite */
for(j = i - 60; j < i; j++) for(j = i - 60; j < i; j++)
{ {
int delta = cucul_rand(-5, 6);
cucul_set_color_ansi(cv, cucul_rand(0, 16), cucul_rand(0, 16));
cucul_put_char(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),
int delta = caca_rand(-5, 6);
caca_set_color_ansi(cv, caca_rand(0, 16), caca_rand(0, 16));
caca_put_char(cv, caca_get_canvas_width(cv) / 2
+ cos(0.02*j) * (delta + caca_get_canvas_width(cv) / 4),
caca_get_canvas_height(cv) / 2
+ sin(0.02*j) * (delta + caca_get_canvas_height(cv) / 3),
'#'); '#');
} }


/* Draw foreground sprite */ /* Draw foreground sprite */
#if 0 #if 0
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,
caca_draw_sprite(cv, caca_get_canvas_width(cv) / 2 + cos(0.02*i) * caca_get_canvas_width(cv) / 4,
caca_get_canvas_height(cv) / 2 + sin(0.02*i) * caca_get_canvas_height(cv) / 3,
sprite, 0); sprite, 0);
#endif #endif
} }


static void demo_dots(void) static void demo_dots(void)
{ {
int xmax = cucul_get_canvas_width(cv);
int ymax = cucul_get_canvas_height(cv);
int xmax = caca_get_canvas_width(cv);
int ymax = caca_get_canvas_height(cv);
int i; int i;
static char chars[10] = static char chars[10] =
{ {
@@ -364,136 +363,136 @@ static void demo_dots(void)
for(i = 1000; i--;) for(i = 1000; i--;)
{ {
/* Putpixel */ /* Putpixel */
cucul_set_color_ansi(cv, cucul_rand(0, 16), cucul_rand(0, 16));
cucul_put_char(cv, cucul_rand(0, xmax), cucul_rand(0, ymax),
chars[cucul_rand(0, 9)]);
caca_set_color_ansi(cv, caca_rand(0, 16), caca_rand(0, 16));
caca_put_char(cv, caca_rand(0, xmax), caca_rand(0, ymax),
chars[caca_rand(0, 9)]);
} }
} }


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


if(bounds) if(bounds)
{ {
xa = cucul_rand(- w, 2 * w); ya = cucul_rand(- h, 2 * h);
xb = cucul_rand(- w, 2 * w); yb = cucul_rand(- h, 2 * h);
xa = caca_rand(- w, 2 * w); ya = caca_rand(- h, 2 * h);
xb = caca_rand(- w, 2 * w); yb = caca_rand(- h, 2 * h);
} }
else else
{ {
xa = cucul_rand(0, w); ya = cucul_rand(0, h);
xb = cucul_rand(0, w); yb = cucul_rand(0, h);
xa = caca_rand(0, w); ya = caca_rand(0, h);
xb = caca_rand(0, w); yb = caca_rand(0, h);
} }


cucul_set_color_ansi(cv, cucul_rand(0, 16), CUCUL_BLACK);
caca_set_color_ansi(cv, caca_rand(0, 16), CACA_BLACK);
if(outline > 1) if(outline > 1)
cucul_draw_thin_line(cv, xa, ya, xb, yb);
caca_draw_thin_line(cv, xa, ya, xb, yb);
else else
cucul_draw_line(cv, xa, ya, xb, yb, '#');
caca_draw_line(cv, xa, ya, xb, yb, '#');
} }


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


if(bounds) if(bounds)
{ {
xa = cucul_rand(- w, 2 * w); ya = cucul_rand(- h, 2 * h);
xb = cucul_rand(- w, 2 * w); yb = cucul_rand(- h, 2 * h);
xa = caca_rand(- w, 2 * w); ya = caca_rand(- h, 2 * h);
xb = caca_rand(- w, 2 * w); yb = caca_rand(- h, 2 * h);
} }
else else
{ {
xa = cucul_rand(0, w); ya = cucul_rand(0, h);
xb = cucul_rand(0, w); yb = cucul_rand(0, h);
xa = caca_rand(0, w); ya = caca_rand(0, h);
xb = caca_rand(0, w); yb = caca_rand(0, h);
} }


cucul_set_color_ansi(cv, cucul_rand(0, 16), cucul_rand(0, 16));
cucul_fill_box(cv, xa, ya, xb, yb, '#');
caca_set_color_ansi(cv, caca_rand(0, 16), caca_rand(0, 16));
caca_fill_box(cv, xa, ya, xb, yb, '#');


cucul_set_color_ansi(cv, cucul_rand(0, 16), CUCUL_BLACK);
caca_set_color_ansi(cv, caca_rand(0, 16), CACA_BLACK);
if(outline == 2) if(outline == 2)
cucul_draw_thin_box(cv, xa, ya, xb, yb);
caca_draw_thin_box(cv, xa, ya, xb, yb);
else if(outline == 1) else if(outline == 1)
cucul_draw_box(cv, xa, ya, xb, yb, '#');
caca_draw_box(cv, xa, ya, xb, yb, '#');
} }


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


if(bounds) if(bounds)
{ {
x = cucul_rand(- w, 2 * w); y = cucul_rand(- h, 2 * h);
a = cucul_rand(0, w); b = cucul_rand(0, h);
x = caca_rand(- w, 2 * w); y = caca_rand(- h, 2 * h);
a = caca_rand(0, w); b = caca_rand(0, h);
} }
else else
{ {
do do
{ {
x = cucul_rand(0, w); y = cucul_rand(0, h);
a = cucul_rand(0, w); b = cucul_rand(0, h);
x = caca_rand(0, w); y = caca_rand(0, h);
a = caca_rand(0, w); b = caca_rand(0, h);


} while(x - a < 0 || x + a >= w || y - b < 0 || y + b >= h); } while(x - a < 0 || x + a >= w || y - b < 0 || y + b >= h);
} }


cucul_set_color_ansi(cv, cucul_rand(0, 16), cucul_rand(0, 16));
cucul_fill_ellipse(cv, x, y, a, b, '#');
caca_set_color_ansi(cv, caca_rand(0, 16), caca_rand(0, 16));
caca_fill_ellipse(cv, x, y, a, b, '#');


cucul_set_color_ansi(cv, cucul_rand(0, 16), CUCUL_BLACK);
caca_set_color_ansi(cv, caca_rand(0, 16), CACA_BLACK);
if(outline == 2) if(outline == 2)
cucul_draw_thin_ellipse(cv, x, y, a, b);
caca_draw_thin_ellipse(cv, x, y, a, b);
else if(outline == 1) else if(outline == 1)
cucul_draw_ellipse(cv, x, y, a, b, '#');
caca_draw_ellipse(cv, x, y, a, b, '#');
} }


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


if(bounds) if(bounds)
{ {
xa = cucul_rand(- w, 2 * w); ya = cucul_rand(- h, 2 * h);
xb = cucul_rand(- w, 2 * w); yb = cucul_rand(- h, 2 * h);
xc = cucul_rand(- w, 2 * w); yc = cucul_rand(- h, 2 * h);
xa = caca_rand(- w, 2 * w); ya = caca_rand(- h, 2 * h);
xb = caca_rand(- w, 2 * w); yb = caca_rand(- h, 2 * h);
xc = caca_rand(- w, 2 * w); yc = caca_rand(- h, 2 * h);
} }
else else
{ {


xa = cucul_rand(0, w); ya = cucul_rand(0, h);
xb = cucul_rand(0, w); yb = cucul_rand(0, h);
xc = cucul_rand(0, w); yc = cucul_rand(0, h);
xa = caca_rand(0, w); ya = caca_rand(0, h);
xb = caca_rand(0, w); yb = caca_rand(0, h);
xc = caca_rand(0, w); yc = caca_rand(0, h);
} }


cucul_set_color_ansi(cv, cucul_rand(0, 16), cucul_rand(0, 16));
cucul_fill_triangle(cv, xa, ya, xb, yb, xc, yc, '#');
caca_set_color_ansi(cv, caca_rand(0, 16), caca_rand(0, 16));
caca_fill_triangle(cv, xa, ya, xb, yb, xc, yc, '#');


cucul_set_color_ansi(cv, cucul_rand(0, 16), CUCUL_BLACK);
caca_set_color_ansi(cv, caca_rand(0, 16), CACA_BLACK);
if(outline == 2) if(outline == 2)
cucul_draw_thin_triangle(cv, xa, ya, xb, yb, xc, yc);
caca_draw_thin_triangle(cv, xa, ya, xb, yb, xc, yc);
else if(outline == 1) else if(outline == 1)
cucul_draw_triangle(cv, xa, ya, xb, yb, xc, yc, '#');
caca_draw_triangle(cv, xa, ya, xb, yb, xc, yc, '#');
} }
#if 0 #if 0
static void demo_sprites(void) static void demo_sprites(void)
{ {


cucul_draw_sprite(cv, cucul_rand(0, cucul_get_canvas_width(cv)),
cucul_rand(0, cucul_get_canvas_height(cv)), sprite, 0);
caca_draw_sprite(cv, caca_rand(0, caca_get_canvas_width(cv)),
caca_rand(0, caca_get_canvas_height(cv)), sprite, 0);


} }
#endif #endif
#if 0 #if 0
static void demo_render(void) static void demo_render(void)
{ {
cucul_dither_t *dither;
caca_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];
@@ -510,12 +509,12 @@ static void demo_render(void)
//*dest++ = ((x >> 3) << 11) | ((y >> 2) << 5) | ((z >> 3)); //*dest++ = ((x >> 3) << 11) | ((y >> 2) << 5) | ((z >> 3));
*dest++ = (x << 16) | (y << 8) | (z); *dest++ = (x << 16) | (y << 8) | (z);
} }
cucul_set_dither_invert(dither, 1);
//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);
cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv), cucul_get_canvas_height(cv),
caca_set_dither_invert(dither, 1);
//dither = caca_create_dither(16, 256, 256, 2 * 256, 0xf800, 0x07e0, 0x001f, 0x0000);
dither = caca_create_dither(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
caca_dither_bitmap(cv, 0, 0, caca_get_canvas_width(cv), caca_get_canvas_height(cv),
dither, buffer); dither, buffer);
cucul_free_dither(dither);
caca_free_dither(dither);
} }
#endif #endif


@@ -523,7 +522,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)
{ {
cucul_dither_t *dither;
caca_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;
@@ -556,10 +555,10 @@ static void demo_render(void)
for(z = 0; z < 240; z++) for(z = 0; z < 240; z++)
draw_circle(buffer, xo, yo, z, 0x000000ff, 200); draw_circle(buffer, xo, yo, z, 0x000000ff, 200);


dither = cucul_create_dither(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
cucul_set_dither_gamma(dither, -1.0);
cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv), cucul_get_canvas_height(cv), dither, (char *)buffer);
cucul_free_dither(dither);
dither = caca_create_dither(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
caca_set_dither_gamma(dither, -1.0);
caca_dither_bitmap(cv, 0, 0, caca_get_canvas_width(cv), caca_get_canvas_height(cv), dither, (char *)buffer);
caca_free_dither(dither);
} }


static void draw_circle(int *buffer, int x, int y, int r, int mask, int val) static void draw_circle(int *buffer, int x, int y, int r, int mask, int val)


+ 17
- 18
examples/dithering.c View File

@@ -18,7 +18,6 @@
# include <stdio.h> # include <stdio.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"


#define XRATIO 100*100 #define XRATIO 100*100
@@ -27,20 +26,20 @@


unsigned int points[] = unsigned int points[] =
{ {
CUCUL_BLACK, CUCUL_DARKGRAY, CUCUL_LIGHTGRAY,
CUCUL_WHITE, CUCUL_RED, CUCUL_LIGHTRED
CACA_BLACK, CACA_DARKGRAY, CACA_LIGHTGRAY,
CACA_WHITE, CACA_RED, CACA_LIGHTRED
}; };


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


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
cucul_canvas_t *cv;
caca_canvas_t *cv;
caca_display_t *dp; caca_display_t *dp;
int neara, dista, nearb, distb, dist; int neara, dista, nearb, distb, dist;
int x, y; int x, y;


cv = cucul_create_canvas(80, 24);
cv = caca_create_canvas(80, 24);
if(cv == NULL) if(cv == NULL)
{ {
printf("Failed to create canvas\n"); printf("Failed to create canvas\n");
@@ -67,7 +66,7 @@ int main(int argc, char *argv[])


/* distance to 40% */ /* distance to 40% */
dist = XRATIO * (x - 40) * (x - 40) + YRATIO * y * y; dist = XRATIO * (x - 40) * (x - 40) + YRATIO * y * y;
if(cucul_rand(-FUZZY, FUZZY+1) + dist < dista)
if(caca_rand(-FUZZY, FUZZY+1) + dist < dista)
{ {
nearb = neara; distb = dista; neara = 1; dista = dist; nearb = neara; distb = dista; neara = 1; dista = dist;
} }
@@ -78,22 +77,22 @@ int main(int argc, char *argv[])


/* check dist to 70% */ /* check dist to 70% */
dist = XRATIO * (x - 70) * (x - 70) + YRATIO * y * y; dist = XRATIO * (x - 70) * (x - 70) + YRATIO * y * y;
if(cucul_rand(-FUZZY, FUZZY+1) + dist < dista)
if(caca_rand(-FUZZY, FUZZY+1) + dist < dista)
{ {
nearb = neara; distb = dista; neara = 2; dista = dist; nearb = neara; distb = dista; neara = 2; dista = dist;
} }
else if(cucul_rand(-FUZZY, FUZZY+1) + dist < distb)
else if(caca_rand(-FUZZY, FUZZY+1) + dist < distb)
{ {
nearb = 2; distb = dist; nearb = 2; distb = dist;
} }


/* check dist to white */ /* check dist to white */
dist = XRATIO * (x - 100) * (x - 100) + YRATIO * y * y; dist = XRATIO * (x - 100) * (x - 100) + YRATIO * y * y;
if(cucul_rand(-FUZZY, FUZZY+1) + dist < dista)
if(caca_rand(-FUZZY, FUZZY+1) + dist < dista)
{ {
nearb = neara; distb = dista; neara = 3; dista = dist; nearb = neara; distb = dista; neara = 3; dista = dist;
} }
else if(cucul_rand(-FUZZY, FUZZY+1) + dist < distb)
else if(caca_rand(-FUZZY, FUZZY+1) + dist < distb)
{ {
nearb = 3; distb = dist; nearb = 3; distb = dist;
} }
@@ -102,11 +101,11 @@ int main(int argc, char *argv[])
/* check dist to dark */ /* check dist to dark */
dist = XRATIO * (x - 40) * (x - 40) + YRATIO * (y - 100) * (y - 100); dist = XRATIO * (x - 40) * (x - 40) + YRATIO * (y - 100) * (y - 100);
dist = dist * 12 / 16; dist = dist * 12 / 16;
if(cucul_rand(-FUZZY, FUZZY+1) + dist < dista)
if(caca_rand(-FUZZY, FUZZY+1) + dist < dista)
{ {
nearb = neara; distb = dista; neara = 4; dista = dist; nearb = neara; distb = dista; neara = 4; dista = dist;
} }
else if(cucul_rand(-FUZZY, FUZZY+1) + dist < distb)
else if(caca_rand(-FUZZY, FUZZY+1) + dist < distb)
{ {
nearb = 4; distb = dist; nearb = 4; distb = dist;
} }
@@ -114,11 +113,11 @@ int main(int argc, char *argv[])
/* check dist to light */ /* check dist to light */
dist = XRATIO * (x - 100) * (x - 100) + YRATIO * (y - 100) * (y - 100); dist = XRATIO * (x - 100) * (x - 100) + YRATIO * (y - 100) * (y - 100);
dist = dist * 8 / 16; dist = dist * 8 / 16;
if(cucul_rand(-FUZZY, FUZZY+1) + dist < dista)
if(caca_rand(-FUZZY, FUZZY+1) + dist < dista)
{ {
nearb = neara; distb = dista; neara = 5; dista = dist; nearb = neara; distb = dista; neara = 5; dista = dist;
} }
else if(cucul_rand(-FUZZY, FUZZY+1) + dist < distb)
else if(caca_rand(-FUZZY, FUZZY+1) + dist < distb)
{ {
nearb = 5; distb = dist; nearb = 5; distb = dist;
} }
@@ -129,10 +128,10 @@ int main(int argc, char *argv[])
ch = density[distb * 2 * 13 / (dista + distb)]; ch = density[distb * 2 * 13 / (dista + distb)];
else else
ch = density[dista * 2 * 13 / (dista + distb)]; ch = density[dista * 2 * 13 / (dista + distb)];
cucul_set_color_ansi(cv, points[nearb], points[neara]);
caca_set_color_ansi(cv, points[nearb], points[neara]);


cucul_put_char(cv, x * cucul_get_canvas_width(cv) / 100,
(100 - y) * cucul_get_canvas_height(cv) / 100, ch);
caca_put_char(cv, x * caca_get_canvas_width(cv) / 100,
(100 - y) * caca_get_canvas_height(cv) / 100, ch);
} }


caca_refresh_display(dp); caca_refresh_display(dp);
@@ -140,7 +139,7 @@ int main(int argc, char *argv[])
caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);


caca_free_display(dp); caca_free_display(dp);
cucul_free_canvas(cv);
caca_free_canvas(cv);


return 0; return 0;
} }


+ 6
- 7
examples/driver.c View File

@@ -19,14 +19,13 @@
# include <stdio.h> # include <stdio.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char const * const *list; char const * const *list;
caca_display_t *dp; caca_display_t *dp;
cucul_canvas_t *cv;
caca_canvas_t *cv;


list = caca_get_display_driver_list(); list = caca_get_display_driver_list();


@@ -38,14 +37,14 @@ int main(int argc, char *argv[])
} }


cv = caca_get_canvas(dp); cv = caca_get_canvas(dp);
cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLACK);
caca_set_color_ansi(cv, CACA_WHITE, CACA_BLACK);


while(1) while(1)
{ {
char const *driver; char const *driver;
int i, cur = 0; int i, cur = 0;


cucul_put_str(cv, 1, 0, "Available drivers:");
caca_put_str(cv, 1, 0, "Available drivers:");


driver = caca_get_display_driver(dp); driver = caca_get_display_driver(dp);


@@ -55,12 +54,12 @@ int main(int argc, char *argv[])


if(match) if(match)
cur = i; cur = i;
cucul_draw_line(cv, 0, i + 2, 9999, i + 2, ' ');
cucul_printf(cv, 2, i + 2, "%c %s (%s)",
caca_draw_line(cv, 0, i + 2, 9999, i + 2, ' ');
caca_printf(cv, 2, i + 2, "%c %s (%s)",
match ? '*' : ' ', list[i], list[i + 1]); match ? '*' : ' ', list[i], list[i + 1]);
} }


cucul_put_str(cv, 1, i + 2, "Switching driver in 5 seconds");
caca_put_str(cv, 1, i + 2, "Switching driver in 5 seconds");


caca_refresh_display(dp); caca_refresh_display(dp);




+ 24
- 25
examples/event.c View File

@@ -20,10 +20,9 @@
# include <stdlib.h> # include <stdlib.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"


static cucul_canvas_t *cv;
static caca_canvas_t *cv;
static caca_display_t *dp; static caca_display_t *dp;


static void print_event(int, int, caca_event_t *); static void print_event(int, int, caca_event_t *);
@@ -33,7 +32,7 @@ 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_canvas(80, 24);
cv = caca_create_canvas(80, 24);
if(cv == NULL) if(cv == NULL)
{ {
printf("Failed to create canvas\n"); printf("Failed to create canvas\n");
@@ -47,13 +46,13 @@ int main(int argc, char **argv)
return 1; return 1;
} }


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


cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
cucul_draw_line(cv, 0, 0, cucul_get_canvas_width(cv) - 1, 0, ' ');
caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
caca_draw_line(cv, 0, 0, caca_get_canvas_width(cv) - 1, 0, ' ');


cucul_draw_line(cv, 0, h, cucul_get_canvas_width(cv) - 1, h, ' ');
cucul_put_str(cv, 0, h, "type \"quit\" to exit");
caca_draw_line(cv, 0, h, caca_get_canvas_width(cv) - 1, h, ' ');
caca_put_str(cv, 0, h, "type \"quit\" to exit");


caca_refresh_display(dp); caca_refresh_display(dp);


@@ -91,19 +90,19 @@ int main(int argc, char **argv)
} }
while(ret); while(ret);


cucul_set_color_ansi(cv, CUCUL_LIGHTGRAY, CUCUL_BLACK);
cucul_clear_canvas(cv);
caca_set_color_ansi(cv, CACA_LIGHTGRAY, CACA_BLACK);
caca_clear_canvas(cv);


/* Print current event */ /* Print current event */
cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
cucul_draw_line(cv, 0, 0, cucul_get_canvas_width(cv) - 1, 0, ' ');
caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
caca_draw_line(cv, 0, 0, caca_get_canvas_width(cv) - 1, 0, ' ');
print_event(0, 0, events); print_event(0, 0, events);


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]);
caca_draw_line(cv, 0, h, caca_get_canvas_width(cv) - 1, h, ' ');
caca_printf(cv, 0, h, "type \"quit\" to exit: %s", quit_string[quit]);


/* Print previous events */ /* Print previous events */
cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLACK);
caca_set_color_ansi(cv, CACA_WHITE, CACA_BLACK);
for(i = 1; i < h && caca_get_event_type(&events[i]); i++) for(i = 1; i < h && caca_get_event_type(&events[i]); i++)
print_event(0, i, events + i); print_event(0, i, events + i);


@@ -113,7 +112,7 @@ int main(int argc, char **argv)
/* Clean up */ /* Clean up */
free(events); free(events);
caca_free_display(dp); caca_free_display(dp);
cucul_free_canvas(cv);
caca_free_canvas(cv);


return 0; return 0;
} }
@@ -125,40 +124,40 @@ static void print_event(int x, int y, caca_event_t *ev)
switch(caca_get_event_type(ev)) switch(caca_get_event_type(ev))
{ {
case CACA_EVENT_NONE: case CACA_EVENT_NONE:
cucul_printf(cv, x, y, "CACA_EVENT_NONE");
caca_printf(cv, x, y, "CACA_EVENT_NONE");
break; break;
case CACA_EVENT_KEY_PRESS: case CACA_EVENT_KEY_PRESS:
character = caca_get_event_key_ch(ev); character = caca_get_event_key_ch(ev);
cucul_printf(cv, x, y, "CACA_EVENT_KEY_PRESS 0x%02x (%c)", character,
caca_printf(cv, x, y, "CACA_EVENT_KEY_PRESS 0x%02x (%c)", character,
(character > 0x1f && character < 0x80) ? character : '?'); (character > 0x1f && character < 0x80) ? character : '?');
break; break;
case CACA_EVENT_KEY_RELEASE: case CACA_EVENT_KEY_RELEASE:
character = caca_get_event_key_ch(ev); character = caca_get_event_key_ch(ev);
cucul_printf(cv, x, y, "CACA_EVENT_KEY_RELEASE 0x%02x (%c)", character,
caca_printf(cv, x, y, "CACA_EVENT_KEY_RELEASE 0x%02x (%c)", character,
(character > 0x1f && character < 0x80) ? character : '?'); (character > 0x1f && character < 0x80) ? character : '?');
break; break;
case CACA_EVENT_MOUSE_MOTION: case CACA_EVENT_MOUSE_MOTION:
cucul_printf(cv, x, y, "CACA_EVENT_MOUSE_MOTION %u %u",
caca_printf(cv, x, y, "CACA_EVENT_MOUSE_MOTION %u %u",
caca_get_event_mouse_x(ev), caca_get_event_mouse_y(ev)); caca_get_event_mouse_x(ev), caca_get_event_mouse_y(ev));
break; break;
case CACA_EVENT_MOUSE_PRESS: case CACA_EVENT_MOUSE_PRESS:
cucul_printf(cv, x, y, "CACA_EVENT_MOUSE_PRESS %u",
caca_printf(cv, x, y, "CACA_EVENT_MOUSE_PRESS %u",
caca_get_event_mouse_button(ev)); caca_get_event_mouse_button(ev));
break; break;
case CACA_EVENT_MOUSE_RELEASE: case CACA_EVENT_MOUSE_RELEASE:
cucul_printf(cv, x, y, "CACA_EVENT_MOUSE_RELEASE %u",
caca_printf(cv, x, y, "CACA_EVENT_MOUSE_RELEASE %u",
caca_get_event_mouse_button(ev)); caca_get_event_mouse_button(ev));
break; break;
case CACA_EVENT_RESIZE: case CACA_EVENT_RESIZE:
cucul_printf(cv, x, y, "CACA_EVENT_RESIZE %u %u",
caca_printf(cv, x, y, "CACA_EVENT_RESIZE %u %u",
caca_get_event_resize_width(ev), caca_get_event_resize_width(ev),
caca_get_event_resize_height(ev)); caca_get_event_resize_height(ev));
break; break;
case CACA_EVENT_QUIT: case CACA_EVENT_QUIT:
cucul_printf(cv, x, y, "CACA_EVENT_QUIT");
caca_printf(cv, x, y, "CACA_EVENT_QUIT");
break; break;
default: default:
cucul_printf(cv, x, y, "CACA_EVENT_UNKNOWN");
caca_printf(cv, x, y, "CACA_EVENT_UNKNOWN");
} }
} }



+ 45
- 45
examples/export.c View File

@@ -1,5 +1,5 @@
/* /*
* export libcucul export test program
* export libcaca export test program
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org> * Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -20,7 +20,7 @@
# include <string.h> # include <string.h>
#endif #endif


#include "cucul.h"
#include "caca.h"


#define WIDTH 80 #define WIDTH 80
#define HEIGHT 32 #define HEIGHT 32
@@ -29,15 +29,15 @@ uint32_t pixels[256*256];


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
cucul_canvas_t *cv;
cucul_dither_t *dither;
caca_canvas_t *cv;
caca_dither_t *dither;
void *buffer; void *buffer;
char *file, *format; char *file, *format;
char const * const * exports, * const * p; char const * const * exports, * const * p;
size_t len; size_t len;
int x, y; int x, y;


exports = cucul_get_export_list();
exports = caca_get_export_list();


if(argc < 2 || argc > 3) if(argc < 2 || argc > 3)
{ {
@@ -75,8 +75,8 @@ int main(int argc, char *argv[])


if(file) if(file)
{ {
cv = cucul_create_canvas(0, 0);
if(cucul_import_file(cv, file, "") < 0)
cv = caca_create_canvas(0, 0);
if(caca_import_file(cv, file, "") < 0)
{ {
fprintf(stderr, "%s: `%s' has unknown format\n", argv[0], file); fprintf(stderr, "%s: `%s' has unknown format\n", argv[0], file);
exit(-1); exit(-1);
@@ -84,7 +84,7 @@ int main(int argc, char *argv[])
} }
else else
{ {
cv = cucul_create_canvas(WIDTH, HEIGHT);
cv = caca_create_canvas(WIDTH, HEIGHT);


for(y = 0; y < 256; y++) for(y = 0; y < 256; y++)
{ {
@@ -97,62 +97,62 @@ int main(int argc, char *argv[])
} }
} }


dither = cucul_create_dither(32, 256, 256, 4 * 256,
dither = caca_create_dither(32, 256, 256, 4 * 256,
0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
if(!strcmp(format, "ansi") || !strcmp(format, "utf8")) if(!strcmp(format, "ansi") || !strcmp(format, "utf8"))
cucul_set_dither_charset(dither, "shades");
cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv),
cucul_get_canvas_height(cv), dither, pixels);
cucul_free_dither(dither);
caca_set_dither_charset(dither, "shades");
caca_dither_bitmap(cv, 0, 0, caca_get_canvas_width(cv),
caca_get_canvas_height(cv), dither, pixels);
caca_free_dither(dither);


cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLACK);
cucul_draw_thin_box(cv, 0, 0, WIDTH - 1, HEIGHT - 1);
caca_set_color_ansi(cv, CACA_WHITE, CACA_BLACK);
caca_draw_thin_box(cv, 0, 0, WIDTH - 1, HEIGHT - 1);


cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
cucul_fill_ellipse(cv, WIDTH / 2, HEIGHT / 2,
caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE);
caca_fill_ellipse(cv, WIDTH / 2, HEIGHT / 2,
WIDTH / 4, HEIGHT / 4, ' '); WIDTH / 4, HEIGHT / 4, ' ');


cucul_set_color_ansi(cv, CUCUL_LIGHTGRAY, CUCUL_BLACK);
cucul_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 6,
caca_set_color_ansi(cv, CACA_LIGHTGRAY, CACA_BLACK);
caca_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 6,
" lightgray on black "); " lightgray on black ");
cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_TRANSPARENT);
cucul_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 5,
caca_set_color_ansi(cv, CACA_DEFAULT, CACA_TRANSPARENT);
caca_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 5,
" default on transparent "); " default on transparent ");
cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
cucul_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 4,
caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE);
caca_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 4,
" black on white "); " black on white ");


cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
cucul_put_str(cv, WIDTH / 2 - 8, HEIGHT / 2 - 3, "[<><><><> <>--<>]");
cucul_put_str(cv, WIDTH / 2 - 8, HEIGHT / 2 - 2, "[ドラゴン ボーレ]");
cucul_put_str(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
cucul_put_str(cv, WIDTH / 2 - 5, HEIGHT / 2 + 4, "(\") \\o/ <&>");
cucul_set_attr(cv, CUCUL_BOLD);
cucul_put_str(cv, WIDTH / 2 - 16, HEIGHT / 2 + 3, "Bold");
cucul_set_attr(cv, CUCUL_BLINK);
cucul_put_str(cv, WIDTH / 2 - 9, HEIGHT / 2 + 3, "Blink");
cucul_set_attr(cv, CUCUL_ITALICS);
cucul_put_str(cv, WIDTH / 2 - 1, HEIGHT / 2 + 3, "Italics");
cucul_set_attr(cv, CUCUL_UNDERLINE);
cucul_put_str(cv, WIDTH / 2 + 8, HEIGHT / 2 + 3, "Underline");
cucul_set_attr(cv, 0);
cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_LIGHTBLUE);
cucul_put_str(cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");
caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE);
caca_put_str(cv, WIDTH / 2 - 8, HEIGHT / 2 - 3, "[<><><><> <>--<>]");
caca_put_str(cv, WIDTH / 2 - 8, HEIGHT / 2 - 2, "[ドラゴン ボーレ]");
caca_put_str(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
caca_put_str(cv, WIDTH / 2 - 5, HEIGHT / 2 + 4, "(\") \\o/ <&>");
caca_set_attr(cv, CACA_BOLD);
caca_put_str(cv, WIDTH / 2 - 16, HEIGHT / 2 + 3, "Bold");
caca_set_attr(cv, CACA_BLINK);
caca_put_str(cv, WIDTH / 2 - 9, HEIGHT / 2 + 3, "Blink");
caca_set_attr(cv, CACA_ITALICS);
caca_put_str(cv, WIDTH / 2 - 1, HEIGHT / 2 + 3, "Italics");
caca_set_attr(cv, CACA_UNDERLINE);
caca_put_str(cv, WIDTH / 2 + 8, HEIGHT / 2 + 3, "Underline");
caca_set_attr(cv, 0);
caca_set_color_ansi(cv, CACA_WHITE, CACA_LIGHTBLUE);
caca_put_str(cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");


for(x = 0; x < 16; x++) for(x = 0; x < 16; x++)
{ {
cucul_set_color_argb(cv, 0xff00 | x, 0xf00f | (x << 4));
cucul_put_char(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 6, '#');
caca_set_color_argb(cv, 0xff00 | x, 0xf00f | (x << 4));
caca_put_char(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 6, '#');
} }
} }


buffer = cucul_export_memory(cv, format, &len);
buffer = caca_export_memory(cv, format, &len);
fwrite(buffer, len, 1, stdout); fwrite(buffer, len, 1, stdout);
free(buffer); free(buffer);


cucul_free_canvas(cv);
caca_free_canvas(cv);


return 0; return 0;
} }


+ 9
- 9
examples/figfont.c View File

@@ -1,5 +1,5 @@
/* /*
* figfont libcucul FIGfont test program
* figfont libcaca FIGfont test program
* Copyright (c) 2007 Sam Hocevar <sam@zoy.org> * Copyright (c) 2007 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -19,11 +19,11 @@
# include <stdlib.h> # include <stdlib.h>
#endif #endif


#include "cucul.h"
#include "caca.h"


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
cucul_canvas_t *cv;
caca_canvas_t *cv;
void *buffer; void *buffer;
size_t len; size_t len;
uint8_t color = 0; uint8_t color = 0;
@@ -34,8 +34,8 @@ int main(int argc, char *argv[])
return -1; return -1;
} }


cv = cucul_create_canvas(0, 0);
if(cucul_canvas_set_figfont(cv, argv[1]))
cv = caca_create_canvas(0, 0);
if(caca_canvas_set_figfont(cv, argv[1]))
{ {
fprintf(stderr, "Could not open font\n"); fprintf(stderr, "Could not open font\n");
return -1; return -1;
@@ -43,15 +43,15 @@ int main(int argc, char *argv[])


while(argv[2][0]) while(argv[2][0])
{ {
cucul_set_color_ansi(cv, 1 + ((color += 4) % 15), CUCUL_TRANSPARENT);
cucul_put_figchar(cv, argv[2]++[0]);
caca_set_color_ansi(cv, 1 + ((color += 4) % 15), CACA_TRANSPARENT);
caca_put_figchar(cv, argv[2]++[0]);
} }


buffer = cucul_export_memory(cv, "utf8", &len);
buffer = caca_export_memory(cv, "utf8", &len);
fwrite(buffer, len, 1, stdout); fwrite(buffer, len, 1, stdout);
free(buffer); free(buffer);


cucul_free_canvas(cv);
caca_free_canvas(cv);


return 0; return 0;
} }


+ 27
- 28
examples/font.c View File

@@ -1,5 +1,5 @@
/* /*
* font libcucul font test program
* font libcaca font test program
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org> * Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -24,21 +24,20 @@
# include <string.h> # include <string.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
cucul_canvas_t *cv;
caca_canvas_t *cv;
caca_display_t *dp; caca_display_t *dp;
cucul_font_t *f;
cucul_dither_t *d;
caca_font_t *f;
caca_dither_t *d;
uint8_t *buf; uint8_t *buf;
unsigned int w, h; unsigned int w, h;
char const * const * fonts; char const * const * fonts;


/* Create a canvas */ /* Create a canvas */
cv = cucul_create_canvas(8, 2);
cv = caca_create_canvas(8, 2);
if(cv == NULL) if(cv == NULL)
{ {
printf("Can't create canvas\n"); printf("Can't create canvas\n");
@@ -47,21 +46,21 @@ int main(int argc, char *argv[])




/* Draw stuff on our canvas */ /* Draw stuff on our canvas */
cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLACK);
cucul_put_str(cv, 0, 0, "ABcde");
cucul_set_color_ansi(cv, CUCUL_LIGHTRED, CUCUL_BLACK);
cucul_put_str(cv, 5, 0, "\\o/");
cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
cucul_put_str(cv, 0, 1, "&$âøÿØ?!");
/* Load a libcucul internal font */
fonts = cucul_get_font_list();
caca_set_color_ansi(cv, CACA_WHITE, CACA_BLACK);
caca_put_str(cv, 0, 0, "ABcde");
caca_set_color_ansi(cv, CACA_LIGHTRED, CACA_BLACK);
caca_put_str(cv, 5, 0, "\\o/");
caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
caca_put_str(cv, 0, 1, "&$âøÿØ?!");
/* Load a libcaca internal font */
fonts = caca_get_font_list();
if(fonts[0] == NULL) if(fonts[0] == NULL)
{ {
fprintf(stderr, "error: libcucul was compiled without any fonts\n");
fprintf(stderr, "error: libcaca was compiled without any fonts\n");
return -1; return -1;
} }
f = cucul_load_font(fonts[0], 0);
f = caca_load_font(fonts[0], 0);
if(f == NULL) if(f == NULL)
{ {
fprintf(stderr, "error: could not load font \"%s\"\n", fonts[0]); fprintf(stderr, "error: could not load font \"%s\"\n", fonts[0]);
@@ -69,15 +68,15 @@ int main(int argc, char *argv[])
} }


/* Create our bitmap buffer (32-bit ARGB) */ /* Create our bitmap buffer (32-bit ARGB) */
w = cucul_get_canvas_width(cv) * cucul_get_font_width(f);
h = cucul_get_canvas_height(cv) * cucul_get_font_height(f);
w = caca_get_canvas_width(cv) * caca_get_font_width(f);
h = caca_get_canvas_height(cv) * caca_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);
caca_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_canvas_size(cv, 80, 32);
caca_set_canvas_size(cv, 80, 32);
dp = caca_create_display(cv); dp = caca_create_display(cv);


{ {
@@ -88,15 +87,15 @@ int main(int argc, char *argv[])
uint32_t const tmp = 0x12345678; uint32_t const tmp = 0x12345678;
if(*(uint8_t const *)&tmp == 0x12) if(*(uint8_t const *)&tmp == 0x12)
#endif #endif
d = cucul_create_dither(32, w, h, 4 * w,
d = caca_create_dither(32, w, h, 4 * w,
0xff0000, 0xff00, 0xff, 0xff000000); 0xff0000, 0xff00, 0xff, 0xff000000);
else else
d = cucul_create_dither(32, w, h, 4 * w,
d = caca_create_dither(32, w, h, 4 * w,
0xff00, 0xff0000, 0xff000000, 0xff); 0xff00, 0xff0000, 0xff000000, 0xff);
} }


cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv),
cucul_get_canvas_height(cv), d, buf);
caca_dither_bitmap(cv, 0, 0, caca_get_canvas_width(cv),
caca_get_canvas_height(cv), d, buf);
caca_refresh_display(dp); caca_refresh_display(dp);


caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);
@@ -104,9 +103,9 @@ int main(int argc, char *argv[])
/* Free everything */ /* Free everything */
caca_free_display(dp); caca_free_display(dp);
free(buf); free(buf);
cucul_free_dither(d);
cucul_free_font(f);
cucul_free_canvas(cv);
caca_free_dither(d);
caca_free_font(f);
caca_free_canvas(cv);


return 0; return 0;
} }


+ 17
- 17
examples/font2tga.c View File

@@ -1,5 +1,5 @@
/* /*
* font2tga libcucul font test program
* font2tga libcaca font test program
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org> * Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -19,27 +19,27 @@
# include <stdlib.h> # include <stdlib.h>
#endif #endif


#include "cucul.h"
#include "caca.h"


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
uint32_t const *blocks; uint32_t const *blocks;
cucul_font_t *f;
caca_font_t *f;
char const * const * fonts; char const * const * fonts;
cucul_canvas_t *cv;
caca_canvas_t *cv;
void *buffer; void *buffer;
size_t len; size_t len;
unsigned int i, j, x, y, cells, width; unsigned int i, j, x, y, cells, width;


fonts = cucul_get_font_list();
f = cucul_load_font(fonts[0], 0);
blocks = cucul_get_font_blocks(f);
fonts = caca_get_font_list();
f = caca_load_font(fonts[0], 0);
blocks = caca_get_font_blocks(f);


for(i = 0, cells = 0; blocks[i + 1]; i += 2) for(i = 0, cells = 0; blocks[i + 1]; i += 2)
{ {
cells += blocks[i + 1] - blocks[i]; cells += blocks[i + 1] - blocks[i];
for(j = blocks[i]; j < blocks[i + 1]; j++) for(j = blocks[i]; j < blocks[i + 1]; j++)
if(cucul_utf32_is_fullwidth(j))
if(caca_utf32_is_fullwidth(j))
cells++; cells++;
} }


@@ -47,10 +47,10 @@ int main(int argc, char *argv[])
; ;


/* Create a canvas */ /* Create a canvas */
cv = cucul_create_canvas(width, (cells + width - 1) / (width - 1));
cucul_set_color_ansi(cv, CUCUL_RED, CUCUL_RED);
cucul_clear_canvas(cv);
cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
cv = caca_create_canvas(width, (cells + width - 1) / (width - 1));
caca_set_color_ansi(cv, CACA_RED, CACA_RED);
caca_clear_canvas(cv);
caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE);


/* Put all glyphs on the canvas */ /* Put all glyphs on the canvas */
x = y = 0; x = y = 0;
@@ -59,9 +59,9 @@ int main(int argc, char *argv[])
{ {
for(j = blocks[i]; j < blocks[i + 1]; j++) for(j = blocks[i]; j < blocks[i + 1]; j++)
{ {
cucul_put_char(cv, x, y, j);
caca_put_char(cv, x, y, j);


if(cucul_utf32_is_fullwidth(j))
if(caca_utf32_is_fullwidth(j))
++x; ++x;


if(++x >= width - 1) if(++x >= width - 1)
@@ -72,14 +72,14 @@ int main(int argc, char *argv[])
} }
} }


cucul_free_font(f);
caca_free_font(f);


buffer = cucul_export_memory(cv, "tga", &len);
buffer = caca_export_memory(cv, "tga", &len);
fwrite(buffer, len, 1, stdout); fwrite(buffer, len, 1, stdout);
free(buffer); free(buffer);


/* Free everything */ /* Free everything */
cucul_free_canvas(cv);
caca_free_canvas(cv);


return 0; return 0;
} }


+ 17
- 18
examples/frames.c View File

@@ -18,18 +18,17 @@
# include <stdio.h> # include <stdio.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
cucul_canvas_t *cv;
caca_canvas_t *cv;
caca_display_t *dp; caca_display_t *dp;


int n, frame; int n, frame;


/* Create a canvas with 200 frames */ /* Create a canvas with 200 frames */
cv = cucul_create_canvas(0, 0);
cv = caca_create_canvas(0, 0);
if(cv == NULL) if(cv == NULL)
{ {
printf("Can't create canvas\n"); printf("Can't create canvas\n");
@@ -37,44 +36,44 @@ int main(int argc, char *argv[])
} }


for(frame = 1; frame < 200; frame++) for(frame = 1; frame < 200; frame++)
cucul_create_frame(cv, frame);
caca_create_frame(cv, frame);


fprintf(stderr, "canvas created, size is %ix%i\n", fprintf(stderr, "canvas created, size is %ix%i\n",
cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
caca_get_canvas_width(cv), caca_get_canvas_height(cv));


/* Resize it to 150 x 80 (around 19MB) */ /* Resize it to 150 x 80 (around 19MB) */
cucul_set_canvas_size(cv, 150, 80);
caca_set_canvas_size(cv, 150, 80);


fprintf(stderr, "canvas expanded, size is %ix%i\n", fprintf(stderr, "canvas expanded, size is %ix%i\n",
cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
caca_get_canvas_width(cv), caca_get_canvas_height(cv));


/* Fill the first 16 frames with a different colour */ /* Fill the first 16 frames with a different colour */
for(frame = 0; frame < 16; frame++) for(frame = 0; frame < 16; frame++)
{ {
cucul_set_frame(cv, frame);
cucul_set_color_ansi(cv, CUCUL_WHITE, frame);
cucul_fill_box(cv, 0, 0, 40, 15, ':');
cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
cucul_put_str(cv, frame * 5 / 2, frame, "カカ");
cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_TRANSPARENT);
caca_set_frame(cv, frame);
caca_set_color_ansi(cv, CACA_WHITE, frame);
caca_fill_box(cv, 0, 0, 40, 15, ':');
caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
caca_put_str(cv, frame * 5 / 2, frame, "カカ");
caca_set_color_ansi(cv, CACA_DEFAULT, CACA_TRANSPARENT);
} }


/* Resize it to a more decent size */ /* Resize it to a more decent size */
cucul_set_canvas_size(cv, 41, 16);
caca_set_canvas_size(cv, 41, 16);


fprintf(stderr, "canvas shrinked, size is %ix%i\n", fprintf(stderr, "canvas shrinked, size is %ix%i\n",
cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
caca_get_canvas_width(cv), caca_get_canvas_height(cv));


dp = caca_create_display(cv); dp = caca_create_display(cv);
caca_set_display_time(dp, 50000); caca_set_display_time(dp, 50000);


fprintf(stderr, "display attached, size is %ix%i\n", fprintf(stderr, "display attached, size is %ix%i\n",
cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
caca_get_canvas_width(cv), caca_get_canvas_height(cv));


n = 0; n = 0;
while(!caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, 0)) while(!caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, 0))
{ {
cucul_set_frame(cv, n % 16);
caca_set_frame(cv, n % 16);
caca_refresh_display(dp); caca_refresh_display(dp);
n++; n++;
} }
@@ -83,7 +82,7 @@ int main(int argc, char *argv[])


/* It is possible, though not necessary, to free all additional frames /* It is possible, though not necessary, to free all additional frames
* separately. */ * separately. */
cucul_free_canvas(cv);
caca_free_canvas(cv);


return 0; return 0;
} }


+ 23
- 24
examples/fullwidth.c View File

@@ -18,19 +18,18 @@
# include <stdio.h> # include <stdio.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"


#define CACA "쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊" #define CACA "쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊"


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
cucul_canvas_t *cv, *caca, *line;
caca_canvas_t *cv, *caca, *line;
caca_display_t *dp; caca_display_t *dp;


unsigned int i; unsigned int i;


cv = cucul_create_canvas(0, 0);
cv = caca_create_canvas(0, 0);
if(cv == NULL) if(cv == NULL)
{ {
printf("Can't created canvas\n"); printf("Can't created canvas\n");
@@ -43,42 +42,42 @@ int main(int argc, char *argv[])
return -1; return -1;
} }


caca = cucul_create_canvas(6, 10);
line = cucul_create_canvas(2, 1);
caca = caca_create_canvas(6, 10);
line = caca_create_canvas(2, 1);


/* Line of x's */ /* Line of x's */
for(i = 0; i < 10; i++) for(i = 0; i < 10; i++)
{ {
cucul_set_color_ansi(caca, CUCUL_WHITE, CUCUL_BLUE);
cucul_put_str(caca, 0, i, CACA);
cucul_set_color_ansi(caca, CUCUL_WHITE, CUCUL_RED);
cucul_put_char(caca, i - 2, i, 'x');
caca_set_color_ansi(caca, CACA_WHITE, CACA_BLUE);
caca_put_str(caca, 0, i, CACA);
caca_set_color_ansi(caca, CACA_WHITE, CACA_RED);
caca_put_char(caca, i - 2, i, 'x');
} }


cucul_blit(cv, 1, 1, caca, NULL);
caca_blit(cv, 1, 1, caca, NULL);


/* Line of ホ's */ /* Line of ホ's */
for(i = 0; i < 10; i++) for(i = 0; i < 10; i++)
{ {
cucul_set_color_ansi(caca, CUCUL_WHITE, CUCUL_BLUE);
cucul_put_str(caca, 0, i, CACA);
cucul_set_color_ansi(caca, CUCUL_WHITE, CUCUL_GREEN);
cucul_put_str(caca, i - 2, i, "ホ");
caca_set_color_ansi(caca, CACA_WHITE, CACA_BLUE);
caca_put_str(caca, 0, i, CACA);
caca_set_color_ansi(caca, CACA_WHITE, CACA_GREEN);
caca_put_str(caca, i - 2, i, "ホ");
} }


cucul_blit(cv, 15, 1, caca, NULL);
caca_blit(cv, 15, 1, caca, NULL);


/* Line of canvas */ /* Line of canvas */
cucul_set_color_ansi(line, CUCUL_WHITE, CUCUL_MAGENTA);
cucul_put_str(line, 0, 0, "ほ");
caca_set_color_ansi(line, CACA_WHITE, CACA_MAGENTA);
caca_put_str(line, 0, 0, "ほ");
for(i = 0; i < 10; i++) for(i = 0; i < 10; i++)
{ {
cucul_set_color_ansi(caca, CUCUL_WHITE, CUCUL_BLUE);
cucul_put_str(caca, 0, i, CACA);
cucul_blit(caca, i - 2, i, line, NULL);
caca_set_color_ansi(caca, CACA_WHITE, CACA_BLUE);
caca_put_str(caca, 0, i, CACA);
caca_blit(caca, i - 2, i, line, NULL);
} }


cucul_blit(cv, 29, 1, caca, NULL);
caca_blit(cv, 29, 1, caca, NULL);


caca_refresh_display(dp); caca_refresh_display(dp);


@@ -86,9 +85,9 @@ int main(int argc, char *argv[])


caca_free_display(dp); caca_free_display(dp);


cucul_free_canvas(line);
cucul_free_canvas(caca);
cucul_free_canvas(cv);
caca_free_canvas(line);
caca_free_canvas(caca);
caca_free_canvas(cv);


return 0; return 0;
} }


+ 32
- 33
examples/gamma.c View File

@@ -1,5 +1,5 @@
/* /*
* gamma libcucul gamma test program
* gamma libcaca gamma test program
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org> * Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -19,7 +19,6 @@
# include <math.h> # include <math.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"


uint32_t buffer[256 * 4]; uint32_t buffer[256 * 4];
@@ -27,13 +26,13 @@ uint32_t buffer[256 * 4];
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
caca_event_t ev; caca_event_t ev;
cucul_canvas_t *cv, *cw, *mask;
caca_canvas_t *cv, *cw, *mask;
caca_display_t *dp; caca_display_t *dp;
cucul_dither_t *left, *right;
caca_dither_t *left, *right;
float gam; float gam;
int x; int x;


cv = cucul_create_canvas(0, 0);
cv = caca_create_canvas(0, 0);
if(cv == NULL) if(cv == NULL)
{ {
printf("Can't created canvas\n"); printf("Can't created canvas\n");
@@ -46,8 +45,8 @@ int main(int argc, char *argv[])
return -1; return -1;
} }


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));
cw = caca_create_canvas(caca_get_canvas_width(cv), caca_get_canvas_height(cv));
mask = caca_create_canvas(caca_get_canvas_width(cv), caca_get_canvas_height(cv));


for(x = 0; x < 256; x++) for(x = 0; x < 256; x++)
{ {
@@ -57,11 +56,11 @@ int main(int argc, char *argv[])
buffer[x + 768] = (x << 16) | (0x00 << 8) | (0xff << 0); buffer[x + 768] = (x << 16) | (0x00 << 8) | (0xff << 0);
} }


left = cucul_create_dither(32, 256, 4, 4 * 256,
left = caca_create_dither(32, 256, 4, 4 * 256,
0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
right = cucul_create_dither(32, 256, 4, 4 * 256,
right = caca_create_dither(32, 256, 4, 4 * 256,
0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
gam = cucul_get_dither_gamma(right);
gam = caca_get_dither_gamma(right);
caca_set_display_time(dp, 20000); caca_set_display_time(dp, 20000);


for(x = 0; ; x++) for(x = 0; ; x++)
@@ -81,46 +80,46 @@ int main(int argc, char *argv[])
} }


/* Resize the spare canvas, just in case the main one changed */ /* Resize the spare canvas, just in case the main one changed */
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));
caca_set_canvas_size(cw, caca_get_canvas_width(cv), caca_get_canvas_height(cv));
caca_set_canvas_size(mask, caca_get_canvas_width(cv), caca_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_canvas_width(cv),
cucul_get_canvas_height(cv), left, buffer);
caca_dither_bitmap(cv, 0, 0, caca_get_canvas_width(cv),
caca_get_canvas_height(cv), 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_dither_bitmap(cw, 0, 0, cucul_get_canvas_width(cw),
cucul_get_canvas_height(cw), right, buffer);
caca_set_dither_gamma(right, gam);
caca_dither_bitmap(cw, 0, 0, caca_get_canvas_width(cw),
caca_get_canvas_height(cw), right, buffer);


/* Draw something on the mask */ /* Draw something on the mask */
cucul_set_color_ansi(mask, CUCUL_LIGHTGRAY, CUCUL_BLACK);
cucul_clear_canvas(mask);
cucul_set_color_ansi(mask, CUCUL_WHITE, CUCUL_WHITE);
cucul_fill_ellipse(mask, (1.0 + sin(0.05 * (float)x))
* 0.5 * cucul_get_canvas_width(mask),
caca_set_color_ansi(mask, CACA_LIGHTGRAY, CACA_BLACK);
caca_clear_canvas(mask);
caca_set_color_ansi(mask, CACA_WHITE, CACA_WHITE);
caca_fill_ellipse(mask, (1.0 + sin(0.05 * (float)x))
* 0.5 * caca_get_canvas_width(mask),
(1.0 + cos(0.05 * (float)x)) (1.0 + cos(0.05 * (float)x))
* 0.5 * cucul_get_canvas_height(mask),
cucul_get_canvas_width(mask) / 2,
cucul_get_canvas_height(mask) / 2, '#');
* 0.5 * caca_get_canvas_height(mask),
caca_get_canvas_width(mask) / 2,
caca_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);
caca_blit(cv, 0, 0, cw, mask);


cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
cucul_printf(cv, 2, 1,
caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
caca_printf(cv, 2, 1,
"gamma=%g - use arrows to change, Esc to quit", gam); "gamma=%g - use arrows to change, Esc to quit", gam);


caca_refresh_display(dp); caca_refresh_display(dp);
} }


cucul_free_dither(left);
cucul_free_dither(right);
caca_free_dither(left);
caca_free_dither(right);


caca_free_display(dp); caca_free_display(dp);
cucul_free_canvas(mask);
cucul_free_canvas(cw);
cucul_free_canvas(cv);
caca_free_canvas(mask);
caca_free_canvas(cw);
caca_free_canvas(cv);


return 0; return 0;
} }


+ 6
- 7
examples/hsv.c View File

@@ -18,7 +18,6 @@
# include <stdio.h> # include <stdio.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"


uint32_t buffer[256*256]; uint32_t buffer[256*256];
@@ -26,9 +25,9 @@ uint32_t buffer[256*256];
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
caca_display_t *dp; caca_display_t *dp;
cucul_canvas_t *cv;
caca_canvas_t *cv;


cucul_dither_t *dither;
caca_dither_t *dither;
int x, y; int x, y;


dp = caca_create_display(NULL); dp = caca_create_display(NULL);
@@ -46,11 +45,11 @@ int main(int argc, char *argv[])
buffer[y * 256 + x] = ((y * x / 256) << 16) | ((y * x / 256) << 8) | (x<< 0); buffer[y * 256 + x] = ((y * x / 256) << 16) | ((y * x / 256) << 8) | (x<< 0);
} }


dither = cucul_create_dither(32, 256, 256, 4 * 256,
dither = caca_create_dither(32, 256, 256, 4 * 256,
0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
cucul_dither_bitmap(caca_get_canvas(dp), 0, 0, cucul_get_canvas_width(cv),
cucul_get_canvas_height(cv), dither, buffer);
cucul_free_dither(dither);
caca_dither_bitmap(caca_get_canvas(dp), 0, 0, caca_get_canvas_width(cv),
caca_get_canvas_height(cv), dither, buffer);
caca_free_dither(dither);


caca_refresh_display(dp); caca_refresh_display(dp);




+ 5
- 6
examples/import.c View File

@@ -19,12 +19,11 @@
# include <stdlib.h> # include <stdlib.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
cucul_canvas_t *cv;
caca_canvas_t *cv;
caca_display_t *dp; caca_display_t *dp;


if(argc < 2) if(argc < 2)
@@ -34,17 +33,17 @@ int main(int argc, char *argv[])
return 1; return 1;
} }


cv = cucul_create_canvas(0, 0);
cv = caca_create_canvas(0, 0);
if(cv == NULL) if(cv == NULL)
{ {
printf("Can't create canvas\n"); printf("Can't create canvas\n");
return -1; return -1;
} }


if(cucul_import_file(cv, argv[1], argc >= 3 ? argv[2] : "") < 0)
if(caca_import_file(cv, argv[1], argc >= 3 ? argv[2] : "") < 0)
{ {
fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]); fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]);
cucul_free_canvas(cv);
caca_free_canvas(cv);
return 1; return 1;
} }


@@ -60,7 +59,7 @@ int main(int argc, char *argv[])
caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);


caca_free_display(dp); caca_free_display(dp);
cucul_free_canvas(cv);
caca_free_canvas(cv);


return 0; return 0;
} }


+ 9
- 10
examples/input.c View File

@@ -19,7 +19,6 @@
# include <stdio.h> # include <stdio.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"


#define BUFFER_SIZE 75 #define BUFFER_SIZE 75
@@ -34,11 +33,11 @@ typedef struct textentry
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
textentry entries[TEXT_ENTRIES]; textentry entries[TEXT_ENTRIES];
cucul_canvas_t *cv;
caca_canvas_t *cv;
caca_display_t *dp; caca_display_t *dp;
unsigned int i, e = 0, running = 1; unsigned int i, e = 0, running = 1;


cv = cucul_create_canvas(0, 0);
cv = caca_create_canvas(0, 0);
if(cv == NULL) if(cv == NULL)
{ {
printf("Can't create canvas\n"); printf("Can't create canvas\n");
@@ -52,8 +51,8 @@ int main(int argc, char *argv[])
} }
caca_set_cursor(dp, 1); caca_set_cursor(dp, 1);


cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
cucul_put_str(cv, 1, 1, "Text entries - press tab to cycle");
caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
caca_put_str(cv, 1, 1, "Text entries - press tab to cycle");


for(i = 0; i < TEXT_ENTRIES; i++) for(i = 0; i < TEXT_ENTRIES; i++)
{ {
@@ -70,21 +69,21 @@ int main(int argc, char *argv[])
{ {
unsigned int j, start, size; unsigned int j, start, size;


cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_LIGHTGRAY);
cucul_fill_box(cv, 2, 3 * i + 4, 2 + BUFFER_SIZE, 3 * i + 4, ' ');
caca_set_color_ansi(cv, CACA_BLACK, CACA_LIGHTGRAY);
caca_fill_box(cv, 2, 3 * i + 4, 2 + BUFFER_SIZE, 3 * i + 4, ' ');


start = 0; start = 0;
size = entries[i].size; size = entries[i].size;


for(j = 0; j < size; j++) for(j = 0; j < size; j++)
{ {
cucul_put_char(cv, 2 + j, 3 * i + 4,
caca_put_char(cv, 2 + j, 3 * i + 4,
entries[i].buffer[start + j]); entries[i].buffer[start + j]);
} }
} }


/* Put the cursor on the active textentry */ /* Put the cursor on the active textentry */
cucul_gotoxy(cv, 2 + entries[e].cursor, 3 * e + 4);
caca_gotoxy(cv, 2 + entries[e].cursor, 3 * e + 4);


caca_refresh_display(dp); caca_refresh_display(dp);


@@ -149,7 +148,7 @@ int main(int argc, char *argv[])
} }


caca_free_display(dp); caca_free_display(dp);
cucul_free_canvas(cv);
caca_free_canvas(cv);


return 0; return 0;
} }


+ 12
- 13
examples/spritedit.c View File

@@ -20,7 +20,6 @@
# include <stdlib.h> # include <stdlib.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"


/* Courtesy of Zashi */ /* Courtesy of Zashi */
@@ -48,46 +47,46 @@ char *guy[] = {


int main(int argc, char **argv) int main(int argc, char **argv)
{ {
cucul_canvas_t *sprite;
caca_canvas_t *sprite;
size_t len; size_t len;
void *buffer; void *buffer;
int i; int i;


/* Create a canvas with 4 frames */ /* Create a canvas with 4 frames */
sprite = cucul_create_canvas(0, 0);
sprite = caca_create_canvas(0, 0);
for(i = 0; i < 3; i++) for(i = 0; i < 3; i++)
cucul_create_frame(sprite, 0);
caca_create_frame(sprite, 0);


/* Load stuff in all 4 frames */ /* Load stuff in all 4 frames */
for(i = 0; i < 4; i++) for(i = 0; i < 4; i++)
{ {
cucul_set_frame(sprite, i);
cucul_import_memory(sprite, guy[i], strlen(guy[i]), "utf8");
caca_set_frame(sprite, i);
caca_import_memory(sprite, guy[i], strlen(guy[i]), "utf8");
} }


/* Export our sprite in a memory buffer. We could save this to /* Export our sprite in a memory buffer. We could save this to
* disk afterwards. */ * disk afterwards. */
buffer = cucul_export_memory(sprite, "caca", &len);
buffer = caca_export_memory(sprite, "caca", &len);


/* Free our sprite and reload it from the memory buffer. We could /* Free our sprite and reload it from the memory buffer. We could
* load this from disk, too. */ * load this from disk, too. */
cucul_free_canvas(sprite);
sprite = cucul_create_canvas(0, 0);
cucul_import_memory(sprite, buffer, len, "caca");
caca_free_canvas(sprite);
sprite = caca_create_canvas(0, 0);
caca_import_memory(sprite, buffer, len, "caca");
free(buffer); free(buffer);


/* Print each sprite frame to stdout */ /* Print each sprite frame to stdout */
for(i = 0; i < 4; i++) for(i = 0; i < 4; i++)
{ {
cucul_set_frame(sprite, i);
caca_set_frame(sprite, i);
printf("Frame #%i\n", i); printf("Frame #%i\n", i);
buffer = cucul_export_memory(sprite, "utf8", &len);
buffer = caca_export_memory(sprite, "utf8", &len);
fwrite(buffer, len, 1, stdout); fwrite(buffer, len, 1, stdout);
free(buffer); free(buffer);
} }


/* Free our sprite */ /* Free our sprite */
cucul_free_canvas(sprite);
caca_free_canvas(sprite);


return 0; return 0;
} }


+ 13
- 14
examples/swallow.c View File

@@ -20,13 +20,12 @@
# include <stdlib.h> # include <stdlib.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"


int main(int argc, char **argv) int main(int argc, char **argv)
{ {
char cmd[BUFSIZ]; char cmd[BUFSIZ];
static cucul_canvas_t *cv, *app;
static caca_canvas_t *cv, *app;
static caca_display_t *dp; static caca_display_t *dp;
uint8_t *buf[4]; uint8_t *buf[4];
long int bytes[4], total[4]; long int bytes[4], total[4];
@@ -39,8 +38,8 @@ int main(int argc, char **argv)
return 1; return 1;
} }


cv = cucul_create_canvas(0, 0);
app = cucul_create_canvas(0, 0);
cv = caca_create_canvas(0, 0);
app = caca_create_canvas(0, 0);
dp = caca_create_display(cv); dp = caca_create_display(cv);


if(cv == NULL || app == NULL ) if(cv == NULL || app == NULL )
@@ -54,15 +53,15 @@ int main(int argc, char **argv)
return -1; return -1;
} }


w = (cucul_get_canvas_width(cv) - 4) / 2;
h = (cucul_get_canvas_height(cv) - 6) / 2;
w = (caca_get_canvas_width(cv) - 4) / 2;
h = (caca_get_canvas_height(cv) - 6) / 2;


if(w < 0 || h < 0) if(w < 0 || h < 0)
return 1; return 1;


cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
cucul_draw_line(cv, 0, 0, cucul_get_canvas_width(cv) - 1, 0, ' ');
cucul_printf(cv, cucul_get_canvas_width(cv) / 2 - 10, 0,
caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
caca_draw_line(cv, 0, 0, caca_get_canvas_width(cv) - 1, 0, ' ');
caca_printf(cv, caca_get_canvas_width(cv) / 2 - 10, 0,
"libcaca multiplexer"); "libcaca multiplexer");


for(i = 0; i < 4; i++) for(i = 0; i < 4; i++)
@@ -74,7 +73,7 @@ int main(int argc, char **argv)
f[i] = popen(cmd, "r"); f[i] = popen(cmd, "r");
if(!f[i]) if(!f[i])
return 1; return 1;
cucul_printf(cv, (w + 2) * (i / 2) + 1,
caca_printf(cv, (w + 2) * (i / 2) + 1,
(h + 2) * ((i % 2) + 1), "%s", argv[i + 1]); (h + 2) * ((i % 2) + 1), "%s", argv[i + 1]);
} }


@@ -88,14 +87,14 @@ int main(int argc, char **argv)


for(i = 0; i < 4; i++) for(i = 0; i < 4; i++)
{ {
bytes[i] = cucul_import_memory(app, buf[i], total[i], "caca");
bytes[i] = caca_import_memory(app, buf[i], total[i], "caca");


if(bytes[i] > 0) if(bytes[i] > 0)
{ {
total[i] -= bytes[i]; total[i] -= bytes[i];
memmove(buf[i], buf[i] + bytes[i], total[i]); memmove(buf[i], buf[i] + bytes[i], total[i]);


cucul_blit(cv, (w + 2) * (i / 2) + 1,
caca_blit(cv, (w + 2) * (i / 2) + 1,
(h + 2) * (i % 2) + 2, app, NULL); (h + 2) * (i % 2) + 2, app, NULL);
caca_refresh_display(dp); caca_refresh_display(dp);
} }
@@ -115,8 +114,8 @@ int main(int argc, char **argv)


/* Clean up */ /* Clean up */
caca_free_display(dp); caca_free_display(dp);
cucul_free_canvas(cv);
cucul_free_canvas(app);
caca_free_canvas(cv);
caca_free_canvas(app);


return 0; return 0;
} }


+ 28
- 28
examples/text.c View File

@@ -20,7 +20,7 @@
# include <stdlib.h> # include <stdlib.h>
#endif #endif


#include "cucul.h"
#include "caca.h"


#define STRING \ #define STRING \
" |_| \n" \ " |_| \n" \
@@ -35,16 +35,16 @@


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
cucul_canvas_t *cv, *pig;
caca_canvas_t *cv, *pig;
void *buffer; void *buffer;
size_t len; size_t len;
int i, j; int i, j;


pig = cucul_create_canvas(0, 0);
cucul_import_memory(pig, STRING, strlen(STRING), "text");
pig = caca_create_canvas(0, 0);
caca_import_memory(pig, STRING, strlen(STRING), "text");


cv = cucul_create_canvas(cucul_get_canvas_width(pig) * 2,
cucul_get_canvas_height(pig) * 2);
cv = caca_create_canvas(caca_get_canvas_width(pig) * 2,
caca_get_canvas_height(pig) * 2);


if(cv == NULL || pig == NULL) if(cv == NULL || pig == NULL)
{ {
@@ -52,41 +52,41 @@ int main(int argc, char *argv[])
return -1; return -1;
} }


cucul_blit(cv, 0, 0, pig, NULL);
cucul_flip(pig);
cucul_blit(cv, cucul_get_canvas_width(pig), 0, pig, NULL);
cucul_flip(pig);
cucul_flop(pig);
cucul_blit(cv, 0, cucul_get_canvas_height(pig), pig, NULL);
cucul_flop(pig);
cucul_rotate_180(pig);
cucul_blit(cv, cucul_get_canvas_width(pig),
cucul_get_canvas_height(pig), pig, NULL);
caca_blit(cv, 0, 0, pig, NULL);
caca_flip(pig);
caca_blit(cv, caca_get_canvas_width(pig), 0, pig, NULL);
caca_flip(pig);
caca_flop(pig);
caca_blit(cv, 0, caca_get_canvas_height(pig), pig, NULL);
caca_flop(pig);
caca_rotate_180(pig);
caca_blit(cv, caca_get_canvas_width(pig),
caca_get_canvas_height(pig), pig, NULL);


for(j = 0; j < cucul_get_canvas_height(cv); j++)
for(j = 0; j < caca_get_canvas_height(cv); j++)
{ {
for(i = 0; i < cucul_get_canvas_width(cv); i += 2)
for(i = 0; i < caca_get_canvas_width(cv); i += 2)
{ {
unsigned long int a; unsigned long int a;
cucul_set_color_ansi(cv, CUCUL_LIGHTBLUE + (i + j) % 6,
CUCUL_DEFAULT);
a = cucul_get_attr(cv, -1, -1);
cucul_put_attr(cv, i, j, a);
cucul_put_attr(cv, i + 1, j, a);
caca_set_color_ansi(cv, CACA_LIGHTBLUE + (i + j) % 6,
CACA_DEFAULT);
a = caca_get_attr(cv, -1, -1);
caca_put_attr(cv, i, j, a);
caca_put_attr(cv, i + 1, j, a);
} }
} }


buffer = cucul_export_memory(cv, "utf8", &len);
buffer = caca_export_memory(cv, "utf8", &len);
fwrite(buffer, len, 1, stdout); fwrite(buffer, len, 1, stdout);
free(buffer); free(buffer);


cucul_rotate_left(cv);
buffer = cucul_export_memory(cv, "utf8", &len);
caca_rotate_left(cv);
buffer = caca_export_memory(cv, "utf8", &len);
fwrite(buffer, len, 1, stdout); fwrite(buffer, len, 1, stdout);
free(buffer); free(buffer);


cucul_free_canvas(pig);
cucul_free_canvas(cv);
caca_free_canvas(pig);
caca_free_canvas(cv);


return 0; return 0;
} }


+ 44
- 45
examples/transform.c View File

@@ -19,7 +19,6 @@
# include <string.h> # include <string.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"


static char const pig[] = static char const pig[] =
@@ -39,10 +38,10 @@ static char const duck[] =


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
cucul_canvas_t *cv, *image, *tmp, *sprite;
caca_canvas_t *cv, *image, *tmp, *sprite;
caca_display_t *dp; caca_display_t *dp;


cv = cucul_create_canvas(0, 0);
cv = caca_create_canvas(0, 0);
if(cv == NULL) if(cv == NULL)
{ {
printf("Can't created canvas\n"); printf("Can't created canvas\n");
@@ -55,64 +54,64 @@ int main(int argc, char *argv[])
return -1; return -1;
} }


image = cucul_create_canvas(70, 6);
tmp = cucul_create_canvas(70, 6);
sprite = cucul_create_canvas(0, 0);
image = caca_create_canvas(70, 6);
tmp = caca_create_canvas(70, 6);
sprite = caca_create_canvas(0, 0);


cucul_set_color_ansi(sprite, CUCUL_LIGHTMAGENTA, CUCUL_BLACK);
cucul_import_memory(sprite, pig, strlen(pig), "text");
cucul_blit(image, 55, 0, sprite, NULL);
caca_set_color_ansi(sprite, CACA_LIGHTMAGENTA, CACA_BLACK);
caca_import_memory(sprite, pig, strlen(pig), "text");
caca_blit(image, 55, 0, sprite, NULL);


cucul_set_color_ansi(sprite, CUCUL_LIGHTGREEN, CUCUL_BLACK);
cucul_import_memory(sprite, duck, strlen(duck), "text");
cucul_blit(image, 30, 1, sprite, NULL);
caca_set_color_ansi(sprite, CACA_LIGHTGREEN, CACA_BLACK);
caca_import_memory(sprite, duck, strlen(duck), "text");
caca_blit(image, 30, 1, sprite, NULL);


cucul_set_color_ansi(image, CUCUL_LIGHTCYAN, CUCUL_BLACK);
cucul_put_str(image, 1, 1, "hahaha mais vieux porc immonde !! [⽼ ⾗]");
cucul_set_color_ansi(image, CUCUL_LIGHTRED, CUCUL_BLACK);
cucul_put_char(image, 38, 1, '|');
caca_set_color_ansi(image, CACA_LIGHTCYAN, CACA_BLACK);
caca_put_str(image, 1, 1, "hahaha mais vieux porc immonde !! [⽼ ⾗]");
caca_set_color_ansi(image, CACA_LIGHTRED, CACA_BLACK);
caca_put_char(image, 38, 1, '|');


cucul_set_color_ansi(image, CUCUL_YELLOW, CUCUL_BLACK);
cucul_put_str(image, 4, 2, "\\o\\ \\o| _o/ \\o_ |o/ /o/");
caca_set_color_ansi(image, CACA_YELLOW, CACA_BLACK);
caca_put_str(image, 4, 2, "\\o\\ \\o| _o/ \\o_ |o/ /o/");


cucul_set_color_ansi(image, CUCUL_WHITE, CUCUL_LIGHTRED);
cucul_put_str(image, 7, 3, "▙▘▌▙▘▞▖▞▖▌ ▞▖▌ ▌▌");
cucul_put_str(image, 7, 4, "▛▖▌▛▖▚▘▚▘▚▖▚▘▚▖▖▖");
cucul_set_color_ansi(image, CUCUL_BLACK, CUCUL_LIGHTRED);
cucul_put_str(image, 4, 3, "▓▒░");
cucul_put_str(image, 4, 4, "▓▒░");
cucul_put_str(image, 24, 3, "░▒▓");
cucul_put_str(image, 24, 4, "░▒▓");
caca_set_color_ansi(image, CACA_WHITE, CACA_LIGHTRED);
caca_put_str(image, 7, 3, "▙▘▌▙▘▞▖▞▖▌ ▞▖▌ ▌▌");
caca_put_str(image, 7, 4, "▛▖▌▛▖▚▘▚▘▚▖▚▘▚▖▖▖");
caca_set_color_ansi(image, CACA_BLACK, CACA_LIGHTRED);
caca_put_str(image, 4, 3, "▓▒░");
caca_put_str(image, 4, 4, "▓▒░");
caca_put_str(image, 24, 3, "░▒▓");
caca_put_str(image, 24, 4, "░▒▓");


/* Blit the transformed canvas onto the main canvas */ /* Blit the transformed canvas onto the main canvas */
cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
cucul_put_str(cv, 0, 0, "normal");
cucul_blit(cv, 10, 0, image, NULL);
caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
caca_put_str(cv, 0, 0, "normal");
caca_blit(cv, 10, 0, image, NULL);


cucul_put_str(cv, 0, 6, "flip");
cucul_blit(tmp, 0, 0, image, NULL);
cucul_flip(tmp);
cucul_blit(cv, 10, 6, tmp, NULL);
caca_put_str(cv, 0, 6, "flip");
caca_blit(tmp, 0, 0, image, NULL);
caca_flip(tmp);
caca_blit(cv, 10, 6, tmp, NULL);


cucul_put_str(cv, 0, 12, "flop");
cucul_blit(tmp, 0, 0, image, NULL);
cucul_flop(tmp);
cucul_blit(cv, 10, 12, tmp, NULL);
caca_put_str(cv, 0, 12, "flop");
caca_blit(tmp, 0, 0, image, NULL);
caca_flop(tmp);
caca_blit(cv, 10, 12, tmp, NULL);


cucul_put_str(cv, 0, 18, "rotate");
cucul_blit(tmp, 0, 0, image, NULL);
cucul_rotate_180(tmp);
cucul_blit(cv, 10, 18, tmp, NULL);
caca_put_str(cv, 0, 18, "rotate");
caca_blit(tmp, 0, 0, image, NULL);
caca_rotate_180(tmp);
caca_blit(cv, 10, 18, tmp, NULL);


caca_refresh_display(dp); caca_refresh_display(dp);


caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);


caca_free_display(dp); caca_free_display(dp);
cucul_free_canvas(tmp);
cucul_free_canvas(sprite);
cucul_free_canvas(image);
cucul_free_canvas(cv);
caca_free_canvas(tmp);
caca_free_canvas(sprite);
caca_free_canvas(image);
caca_free_canvas(cv);


return 0; return 0;
} }


+ 7
- 8
examples/truecolor.c View File

@@ -18,17 +18,16 @@
# include <stdio.h> # include <stdio.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
cucul_canvas_t *cv;
caca_canvas_t *cv;
caca_display_t *dp; caca_display_t *dp;


int x, y; int x, y;


cv = cucul_create_canvas(32, 16);
cv = caca_create_canvas(32, 16);
if(cv == NULL) if(cv == NULL)
{ {
printf("Failed to create canvas\n"); printf("Failed to create canvas\n");
@@ -48,19 +47,19 @@ int main(int argc, char *argv[])
uint16_t bgcolor = 0xff00 | (y << 4) | x; uint16_t bgcolor = 0xff00 | (y << 4) | x;
uint16_t fgcolor = 0xf000 | ((15 - y) << 4) | ((15 - x) << 8); uint16_t fgcolor = 0xf000 | ((15 - y) << 4) | ((15 - x) << 8);


cucul_set_color_argb(cv, fgcolor, bgcolor);
cucul_put_str(cv, x * 2, y, "CA");
caca_set_color_argb(cv, fgcolor, bgcolor);
caca_put_str(cv, x * 2, y, "CA");
} }


cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_LIGHTBLUE);
cucul_put_str(cv, 2, 1, " truecolor libcaca ");
caca_set_color_ansi(cv, CACA_WHITE, CACA_LIGHTBLUE);
caca_put_str(cv, 2, 1, " truecolor libcaca ");


caca_refresh_display(dp); caca_refresh_display(dp);


caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);


caca_free_display(dp); caca_free_display(dp);
cucul_free_canvas(cv);
caca_free_canvas(cv);


return 0; return 0;
} }


+ 56
- 57
examples/unicode.c View File

@@ -18,15 +18,14 @@
# include <stdio.h> # include <stdio.h>
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
cucul_canvas_t *cv;
caca_canvas_t *cv;
caca_display_t *dp; caca_display_t *dp;


cv = cucul_create_canvas(0, 0);
cv = caca_create_canvas(0, 0);
if(cv == NULL) if(cv == NULL)
{ {
printf("Can't created canvas\n"); printf("Can't created canvas\n");
@@ -38,66 +37,66 @@ int main(int argc, char *argv[])
printf("Can't create display\n"); printf("Can't create display\n");
return -1; return -1;
} }
cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
cucul_put_str(cv, 1, 1, "Basic Unicode support");
cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_TRANSPARENT);
cucul_put_str(cv, 1, 2, "This is ASCII: | abc DEF 123 !@# |");
cucul_put_str(cv, 1, 3, "This is Unicode: | äßç δεφ ☺♥♀ ╞╬╗ |");
cucul_put_str(cv, 1, 4, "And this is, too: | ἀβϛ ΔЗҒ ᚴᛒᛯ ♩♔✈ |");
cucul_put_str(cv, 1, 5, "If the three lines do not have the same length, there is a bug somewhere.");
cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
cucul_put_str(cv, 1, 7, "Gradient glyphs");
cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_TRANSPARENT);
cucul_put_str(cv, 31, 8, " 0%");
cucul_put_str(cv, 31, 9, " 25%");
cucul_put_str(cv, 31, 10, " 50%");
cucul_put_str(cv, 31, 11, " 75%");
cucul_put_str(cv, 31, 12, "100%");
cucul_set_color_ansi(cv, CUCUL_LIGHTRED, CUCUL_LIGHTGREEN);
cucul_put_str(cv, 1, 8, " ");
cucul_put_str(cv, 1, 9, "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
cucul_put_str(cv, 1, 10, "▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒");
cucul_put_str(cv, 1, 11, "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
cucul_put_str(cv, 1, 12, "█████████████████████████████");
cucul_set_color_ansi(cv, CUCUL_LIGHTGREEN, CUCUL_LIGHTRED);
cucul_put_str(cv, 36, 8, "█████████████████████████████");
cucul_put_str(cv, 36, 9, "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
cucul_put_str(cv, 36, 10, "▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒");
cucul_put_str(cv, 36, 11, "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
cucul_put_str(cv, 36, 12, " ");
cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
cucul_put_str(cv, 1, 14, "Double width characters");
cucul_set_color_ansi(cv, CUCUL_LIGHTRED, CUCUL_TRANSPARENT);
cucul_put_str(cv, 1, 15, "| ドラゴン ボーレ |");
cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_TRANSPARENT);
cucul_put_str(cv, 1, 16, "| ()()()() ()()() |");
cucul_set_color_ansi(cv, CUCUL_YELLOW, CUCUL_TRANSPARENT);
cucul_put_str(cv, 1, 17, "| ドラゴン");
cucul_put_str(cv, 12, 17, "ボーレ |");
cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_TRANSPARENT);
cucul_put_str(cv, 1, 18, "If the three lines do not have the same length, there is a bug somewhere.");
cucul_put_str(cv, 1, 20, "CP437 glyphs: ☺ ☻ ♥ ♦ ♣ ♠ • ◘ ○ ◙ ♂ ♀ ♪ ♫ ☼ ► ◄ ↕ ‼ ¶ § ▬ ↨ ↑ ↓ → ← ∟ ↔ ▲ ▼");
cucul_put_str(cv, 1, 21, "more CP437: α ß Γ π Σ σ µ τ Φ Θ Ω δ ∞ φ ε ∩ ≡ ± ≥ ≤ ⌠ ⌡ ÷ ≈ ° ∙ · √ ⁿ ² ■");
cucul_put_str(cv, 1, 22, "drawing blocks: ███ ▓▓▓ ▒▒▒ ░░░ ▀ ▄ ▌ ▐ █ ▖ ▗ ▘ ▝ ▚ ▞ ▙ ▛ ▜ ▟ ─ │ ┌ ┐ └ ┘ ├ ┤");
cucul_put_str(cv, 1, 23, "more drawing: ┬ ┴ ┼ ═ ║ ╒ ╓ ╔ ╕ ╖ ╗ ╘ ╙ ╚ ╛ ╜ ╝ ╞ ╟ ╠ ╡ ╢ ╣ ╤ ╥ ╦ ╧ ╨ ╩ ╪ ╫ ╬");
cucul_put_str(cv, 1, 24, "misc Unicode: ● ☭ ☮ ☯ ♔ ♛ ♙ ♞ ⚒ ⚓ ⚠");
caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
caca_put_str(cv, 1, 1, "Basic Unicode support");
caca_set_color_ansi(cv, CACA_DEFAULT, CACA_TRANSPARENT);
caca_put_str(cv, 1, 2, "This is ASCII: | abc DEF 123 !@# |");
caca_put_str(cv, 1, 3, "This is Unicode: | äßç δεφ ☺♥♀ ╞╬╗ |");
caca_put_str(cv, 1, 4, "And this is, too: | ἀβϛ ΔЗҒ ᚴᛒᛯ ♩♔✈ |");
caca_put_str(cv, 1, 5, "If the three lines do not have the same length, there is a bug somewhere.");
caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
caca_put_str(cv, 1, 7, "Gradient glyphs");
caca_set_color_ansi(cv, CACA_DEFAULT, CACA_TRANSPARENT);
caca_put_str(cv, 31, 8, " 0%");
caca_put_str(cv, 31, 9, " 25%");
caca_put_str(cv, 31, 10, " 50%");
caca_put_str(cv, 31, 11, " 75%");
caca_put_str(cv, 31, 12, "100%");
caca_set_color_ansi(cv, CACA_LIGHTRED, CACA_LIGHTGREEN);
caca_put_str(cv, 1, 8, " ");
caca_put_str(cv, 1, 9, "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
caca_put_str(cv, 1, 10, "▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒");
caca_put_str(cv, 1, 11, "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
caca_put_str(cv, 1, 12, "█████████████████████████████");
caca_set_color_ansi(cv, CACA_LIGHTGREEN, CACA_LIGHTRED);
caca_put_str(cv, 36, 8, "█████████████████████████████");
caca_put_str(cv, 36, 9, "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
caca_put_str(cv, 36, 10, "▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒");
caca_put_str(cv, 36, 11, "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
caca_put_str(cv, 36, 12, " ");
caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
caca_put_str(cv, 1, 14, "Double width characters");
caca_set_color_ansi(cv, CACA_LIGHTRED, CACA_TRANSPARENT);
caca_put_str(cv, 1, 15, "| ドラゴン ボーレ |");
caca_set_color_ansi(cv, CACA_DEFAULT, CACA_TRANSPARENT);
caca_put_str(cv, 1, 16, "| ()()()() ()()() |");
caca_set_color_ansi(cv, CACA_YELLOW, CACA_TRANSPARENT);
caca_put_str(cv, 1, 17, "| ドラゴン");
caca_put_str(cv, 12, 17, "ボーレ |");
caca_set_color_ansi(cv, CACA_DEFAULT, CACA_TRANSPARENT);
caca_put_str(cv, 1, 18, "If the three lines do not have the same length, there is a bug somewhere.");
caca_put_str(cv, 1, 20, "CP437 glyphs: ☺ ☻ ♥ ♦ ♣ ♠ • ◘ ○ ◙ ♂ ♀ ♪ ♫ ☼ ► ◄ ↕ ‼ ¶ § ▬ ↨ ↑ ↓ → ← ∟ ↔ ▲ ▼");
caca_put_str(cv, 1, 21, "more CP437: α ß Γ π Σ σ µ τ Φ Θ Ω δ ∞ φ ε ∩ ≡ ± ≥ ≤ ⌠ ⌡ ÷ ≈ ° ∙ · √ ⁿ ² ■");
caca_put_str(cv, 1, 22, "drawing blocks: ███ ▓▓▓ ▒▒▒ ░░░ ▀ ▄ ▌ ▐ █ ▖ ▗ ▘ ▝ ▚ ▞ ▙ ▛ ▜ ▟ ─ │ ┌ ┐ └ ┘ ├ ┤");
caca_put_str(cv, 1, 23, "more drawing: ┬ ┴ ┼ ═ ║ ╒ ╓ ╔ ╕ ╖ ╗ ╘ ╙ ╚ ╛ ╜ ╝ ╞ ╟ ╠ ╡ ╢ ╣ ╤ ╥ ╦ ╧ ╨ ╩ ╪ ╫ ╬");
caca_put_str(cv, 1, 24, "misc Unicode: ● ☭ ☮ ☯ ♔ ♛ ♙ ♞ ⚒ ⚓ ⚠");


caca_refresh_display(dp); caca_refresh_display(dp);


caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);


caca_free_display(dp); caca_free_display(dp);
cucul_free_canvas(cv);
caca_free_canvas(cv);


return 0; return 0;
} }


+ 3
- 3
kernel/kernel.c View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Canvas for ultrafast compositing of Unicode letters
* libcaca Canvas for ultrafast compositing of Unicode letters
* libcaca Colour ASCII-Art library * libcaca Colour ASCII-Art library
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org> * Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
* 2006 Jean-Yves Lamoureux <jylam@lnxscene.org> * 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
@@ -16,12 +16,12 @@


/* /*
* This file contains replacement functions for the standard C library * This file contains replacement functions for the standard C library
* that must be used when building libcucul and libcaca into a kernel.
* that must be used when building libcaca and libcaca into a kernel.
*/ */


#include "config.h" #include "config.h"


#include "cucul_types.h"
#include "caca_types.h"


#ifdef __KERNEL__ #ifdef __KERNEL__




+ 2
- 2
kernel/kernel.h View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Canvas for ultrafast compositing of Unicode letters
* libcaca Canvas for ultrafast compositing of Unicode letters
* libcaca Colour ASCII-Art library * libcaca Colour ASCII-Art library
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org> * Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
@@ -15,7 +15,7 @@


/* /*
* This file contains replacement functions for the standard C library * This file contains replacement functions for the standard C library
* that must be used when building libcucul and libcaca into a kernel.
* that must be used when building libcaca and libcaca into a kernel.
*/ */


/* Various defines */ /* Various defines */


+ 3
- 3
msvc/Makefile.am View File

@@ -4,12 +4,12 @@ NULL =


EXTRA_DIST = libcaca.sln \ EXTRA_DIST = libcaca.sln \
config.h \ config.h \
cucul_types.h \
libcucul.vcproj \
caca_types.h \
libcaca.vcproj \
libcaca.vcproj \ libcaca.vcproj \
cacafire.vcproj \ cacafire.vcproj \
cacademo.vcproj \ cacademo.vcproj \
cucul-sharp.csproj \
caca-sharp.csproj \
caca-sharp.csproj \ caca-sharp.csproj \
test-csharp.csproj \ test-csharp.csproj \
$(NULL) $(NULL)


+ 2
- 2
msvc/cucul_types.h View File

@@ -1,2 +1,2 @@
#define CUCUL_TYPES 3
#include "../cucul/cucul_types.h.in"
#define CACA_TYPES 3
#include "../caca/caca_types.h.in"

+ 8
- 16
ruby/Makefile.am View File

@@ -4,30 +4,22 @@ rubylibdir = $(RUBY_SITEARCHDIR)
rubysitedir = $(RUBY_SITELIBDIR) rubysitedir = $(RUBY_SITELIBDIR)


if USE_RUBY if USE_RUBY
rubylib_LTLIBRARIES = caca.la cucul.la
rubylib_LTLIBRARIES = caca.la
rubysite_DATA = lib/caca.rb rubysite_DATA = lib/caca.rb
TESTS = test TESTS = test
endif endif


CFLAGS += -Wno-strict-prototypes -Wno-missing-prototypes CFLAGS += -Wno-strict-prototypes -Wno-missing-prototypes


cucul_la_CPPFLAGS = -I$(top_srcdir)/cucul -I../cucul $(RUBY_CFLAGS)
cucul_la_SOURCES = cucul.c \
common.h \
cucul-canvas.c \
cucul-canvas.h \
cucul-dither.c \
cucul-dither.h \
cucul-font.c \
cucul-font.h \
$(NULL)
cucul_la_LDFLAGS = -module -avoid-version -shared $(RUBY_LIBS)
cucul_la_LIBADD = ../cucul/libcucul.la

caca_la_CPPFLAGS = -I$(top_srcdir)/caca -I$(top_srcdir)/cucul -I../cucul \
$(RUBY_CFLAGS)
caca_la_CPPFLAGS = -I$(top_srcdir)/caca -I../caca $(RUBY_CFLAGS)
caca_la_SOURCES = caca.c \ caca_la_SOURCES = caca.c \
common.h \ common.h \
caca-canvas.c \
caca-canvas.h \
caca-dither.c \
caca-dither.h \
caca-font.c \
caca-font.h \
caca-display.c \ caca-display.c \
caca-display.h \ caca-display.h \
caca-event.c \ caca-event.c \


ruby/cucul-canvas.c → ruby/caca-canvas.c View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Ruby bindings
* libcaca Ruby bindings
* Copyright (c) 2007 Pascal Terjan <pterjan@linuxfr.org> * Copyright (c) 2007 Pascal Terjan <pterjan@linuxfr.org>
* *
* This library is free software. It comes without any warranty, to * This library is free software. It comes without any warranty, to
@@ -10,10 +10,10 @@
*/ */


#include <ruby.h> #include <ruby.h>
#include <cucul.h>
#include <caca.h>
#include <errno.h> #include <errno.h>
#include "cucul-dither.h"
#include "cucul-font.h"
#include "caca-dither.h"
#include "caca-font.h"
#include "common.h" #include "common.h"


VALUE cCanvas; VALUE cCanvas;
@@ -21,7 +21,7 @@ VALUE cCanvas;
#define simple_func(x) \ #define simple_func(x) \
static VALUE x (VALUE self) \ static VALUE x (VALUE self) \
{ \ { \
if( cucul_##x (_SELF) <0) \
if( caca_##x (_SELF) <0) \
rb_raise(rb_eRuntimeError, strerror(errno)); \ rb_raise(rb_eRuntimeError, strerror(errno)); \
\ \
return self; \ return self; \
@@ -30,12 +30,12 @@ static VALUE x (VALUE self) \
#define get_int(x) \ #define get_int(x) \
static VALUE get_##x (VALUE self) \ static VALUE get_##x (VALUE self) \
{ \ { \
return INT2NUM(cucul_get_##x (_SELF)); \
return INT2NUM(caca_get_##x (_SELF)); \
} }


static void canvas_free(void * p) static void canvas_free(void * p)
{ {
cucul_free_canvas((cucul_canvas_t *)p);
caca_free_canvas((caca_canvas_t *)p);
} }


static VALUE canvas_alloc(VALUE klass) static VALUE canvas_alloc(VALUE klass)
@@ -45,16 +45,16 @@ static VALUE canvas_alloc(VALUE klass)
return obj; return obj;
} }


VALUE canvas_create(cucul_canvas_t *canvas)
VALUE canvas_create(caca_canvas_t *canvas)
{ {
return Data_Wrap_Struct(cCanvas, NULL, NULL, canvas); return Data_Wrap_Struct(cCanvas, NULL, NULL, canvas);
} }


static VALUE canvas_initialize(VALUE self, VALUE width, VALUE height) static VALUE canvas_initialize(VALUE self, VALUE width, VALUE height)
{ {
cucul_canvas_t *canvas;
caca_canvas_t *canvas;


canvas = cucul_create_canvas(NUM2INT(width), NUM2INT(height));
canvas = caca_create_canvas(NUM2INT(width), NUM2INT(height));


if(canvas == NULL) if(canvas == NULL)
{ {
@@ -71,7 +71,7 @@ get_int(canvas_width)


static VALUE set_canvas_width(VALUE self, VALUE width) static VALUE set_canvas_width(VALUE self, VALUE width)
{ {
cucul_set_canvas_size(_SELF, NUM2INT(width), cucul_get_canvas_height(_SELF));
caca_set_canvas_size(_SELF, NUM2INT(width), caca_get_canvas_height(_SELF));
return width; return width;
} }


@@ -83,7 +83,7 @@ static VALUE set_canvas_width2(VALUE self, VALUE width)


static VALUE set_canvas_height(VALUE self, VALUE height) static VALUE set_canvas_height(VALUE self, VALUE height)
{ {
cucul_set_canvas_size(_SELF, cucul_get_canvas_width(_SELF), NUM2INT(height));
caca_set_canvas_size(_SELF, caca_get_canvas_width(_SELF), NUM2INT(height));
return height; return height;
} }


@@ -95,7 +95,7 @@ static VALUE set_canvas_height2(VALUE self, VALUE height)


static VALUE set_canvas_size(VALUE self, VALUE height, VALUE width) static VALUE set_canvas_size(VALUE self, VALUE height, VALUE width)
{ {
cucul_set_canvas_size(_SELF, NUM2INT(width), NUM2INT(height));
caca_set_canvas_size(_SELF, NUM2INT(width), NUM2INT(height));
return self; return self;
} }


@@ -103,7 +103,7 @@ static VALUE set_canvas_size(VALUE self, VALUE height, VALUE width)


static VALUE gotoxy(VALUE self, VALUE x, VALUE y) static VALUE gotoxy(VALUE self, VALUE x, VALUE y)
{ {
if( cucul_gotoxy(_SELF, NUM2INT(x), NUM2INT(y)) <0) {
if( caca_gotoxy(_SELF, NUM2INT(x), NUM2INT(y)) <0) {
rb_raise(rb_eRuntimeError, strerror(errno)); rb_raise(rb_eRuntimeError, strerror(errno));
} }
return self; return self;
@@ -116,33 +116,33 @@ simple_func(clear_canvas)


static VALUE put_char(VALUE self, VALUE x, VALUE y, VALUE ch) static VALUE put_char(VALUE self, VALUE x, VALUE y, VALUE ch)
{ {
cucul_put_char(_SELF, NUM2INT(x), NUM2INT(y), NUM2ULONG(ch));
caca_put_char(_SELF, NUM2INT(x), NUM2INT(y), NUM2ULONG(ch));
return self; return self;
} }


static VALUE get_char(VALUE self, VALUE x, VALUE y) static VALUE get_char(VALUE self, VALUE x, VALUE y)
{ {
unsigned long int ch; unsigned long int ch;
ch = cucul_get_char(_SELF, NUM2INT(x), NUM2INT(y));
ch = caca_get_char(_SELF, NUM2INT(x), NUM2INT(y));
return INT2NUM(ch); return INT2NUM(ch);
} }


static VALUE put_str(VALUE self, VALUE x, VALUE y, VALUE str) static VALUE put_str(VALUE self, VALUE x, VALUE y, VALUE str)
{ {
cucul_put_str(_SELF, NUM2INT(x), NUM2INT(y), StringValuePtr(str));
caca_put_str(_SELF, NUM2INT(x), NUM2INT(y), StringValuePtr(str));
return self; return self;
} }


static VALUE get_attr(VALUE self, VALUE x, VALUE y) static VALUE get_attr(VALUE self, VALUE x, VALUE y)
{ {
unsigned long int ch; unsigned long int ch;
ch = cucul_get_attr(_SELF, NUM2INT(x), NUM2INT(y));
ch = caca_get_attr(_SELF, NUM2INT(x), NUM2INT(y));
return INT2NUM(ch); return INT2NUM(ch);
} }


static VALUE set_attr(VALUE self, VALUE attr) static VALUE set_attr(VALUE self, VALUE attr)
{ {
if(cucul_set_attr(_SELF, NUM2ULONG(attr)) <0)
if(caca_set_attr(_SELF, NUM2ULONG(attr)) <0)
rb_raise(rb_eRuntimeError, strerror(errno)); rb_raise(rb_eRuntimeError, strerror(errno));


return self; return self;
@@ -156,7 +156,7 @@ static VALUE set_attr2(VALUE self, VALUE attr)


static VALUE put_attr(VALUE self, VALUE x, VALUE y, VALUE attr) static VALUE put_attr(VALUE self, VALUE x, VALUE y, VALUE attr)
{ {
if(cucul_put_attr(_SELF, NUM2INT(x), NUM2INT(y), NUM2ULONG(attr)) <0)
if(caca_put_attr(_SELF, NUM2INT(x), NUM2INT(y), NUM2ULONG(attr)) <0)
rb_raise(rb_eRuntimeError, strerror(errno)); rb_raise(rb_eRuntimeError, strerror(errno));


return self; return self;
@@ -164,7 +164,7 @@ static VALUE put_attr(VALUE self, VALUE x, VALUE y, VALUE attr)


static VALUE set_color_ansi(VALUE self, VALUE fg, VALUE bg) static VALUE set_color_ansi(VALUE self, VALUE fg, VALUE bg)
{ {
if(cucul_set_color_ansi(_SELF, NUM2INT(fg), NUM2INT(bg)) <0)
if(caca_set_color_ansi(_SELF, NUM2INT(fg), NUM2INT(bg)) <0)
rb_raise(rb_eRuntimeError, strerror(errno)); rb_raise(rb_eRuntimeError, strerror(errno));


return self; return self;
@@ -172,7 +172,7 @@ static VALUE set_color_ansi(VALUE self, VALUE fg, VALUE bg)


static VALUE set_color_argb(VALUE self, VALUE fg, VALUE bg) static VALUE set_color_argb(VALUE self, VALUE fg, VALUE bg)
{ {
if(cucul_set_color_argb(_SELF, NUM2UINT(fg), NUM2UINT(bg)) <0) {
if(caca_set_color_argb(_SELF, NUM2UINT(fg), NUM2UINT(bg)) <0) {
rb_raise(rb_eRuntimeError, strerror(errno)); rb_raise(rb_eRuntimeError, strerror(errno));
} }
return self; return self;
@@ -186,7 +186,7 @@ static VALUE cprintf(int argc, VALUE* argv, VALUE self)
x = NUM2INT(rx); x = NUM2INT(rx);
y = NUM2INT(ry); y = NUM2INT(ry);
string = rb_funcall2(rb_mKernel, rb_intern("sprintf"), argc-2, argv+2); string = rb_funcall2(rb_mKernel, rb_intern("sprintf"), argc-2, argv+2);
cucul_put_str(_SELF, x, y, StringValuePtr(string));
caca_put_str(_SELF, x, y, StringValuePtr(string));
return self; return self;
} }


@@ -196,13 +196,13 @@ get_int(canvas_handle_y)


static VALUE set_canvas_handle(VALUE self, VALUE x, VALUE y) static VALUE set_canvas_handle(VALUE self, VALUE x, VALUE y)
{ {
cucul_set_canvas_handle(_SELF, NUM2INT(x), NUM2INT(y));
caca_set_canvas_handle(_SELF, NUM2INT(x), NUM2INT(y));
return self; return self;
} }


static VALUE blit(int argc, VALUE* argv, VALUE self) { static VALUE blit(int argc, VALUE* argv, VALUE self) {
VALUE x, y, src, mask; VALUE x, y, src, mask;
cucul_canvas_t *csrc, *cmask;
caca_canvas_t *csrc, *cmask;


rb_scan_args(argc, argv, "31", &x, &y, &src, &mask); rb_scan_args(argc, argv, "31", &x, &y, &src, &mask);


@@ -213,7 +213,7 @@ static VALUE blit(int argc, VALUE* argv, VALUE self) {
{ {
rb_raise(rb_eArgError, "src is not a Cucul::Canvas"); rb_raise(rb_eArgError, "src is not a Cucul::Canvas");
} }
Data_Get_Struct(src, cucul_canvas_t, csrc);
Data_Get_Struct(src, caca_canvas_t, csrc);


if(!NIL_P(mask)) if(!NIL_P(mask))
{ {
@@ -221,12 +221,12 @@ static VALUE blit(int argc, VALUE* argv, VALUE self) {
{ {
rb_raise(rb_eArgError, "mask is not a Cucul::Canvas"); rb_raise(rb_eArgError, "mask is not a Cucul::Canvas");
} }
Data_Get_Struct(mask, cucul_canvas_t, cmask);
Data_Get_Struct(mask, caca_canvas_t, cmask);
} }
else else
cmask = NULL; cmask = NULL;
if(cucul_blit(_SELF, NUM2INT(x), NUM2INT(y), csrc, cmask)<0)
if(caca_blit(_SELF, NUM2INT(x), NUM2INT(y), csrc, cmask)<0)
rb_raise(rb_eRuntimeError, strerror(errno)); rb_raise(rb_eRuntimeError, strerror(errno));


return self; return self;
@@ -234,7 +234,7 @@ static VALUE blit(int argc, VALUE* argv, VALUE self) {


static VALUE set_canvas_boundaries(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h) static VALUE set_canvas_boundaries(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h)
{ {
if(cucul_set_canvas_boundaries(_SELF, NUM2INT(x), NUM2INT(y), NUM2UINT(w), NUM2UINT(h))<0)
if(caca_set_canvas_boundaries(_SELF, NUM2INT(x), NUM2INT(y), NUM2UINT(w), NUM2UINT(h))<0)
{ {
rb_raise(rb_eRuntimeError, strerror(errno)); rb_raise(rb_eRuntimeError, strerror(errno));
} }
@@ -256,7 +256,7 @@ simple_func(stretch_right)


static VALUE draw_line(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE ch) static VALUE draw_line(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE ch)
{ {
cucul_draw_line(_SELF, NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2),NUM2ULONG(ch));
caca_draw_line(_SELF, NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2),NUM2ULONG(ch));
return self; return self;
} }


@@ -308,7 +308,7 @@ static VALUE draw_polyline(VALUE self, VALUE points, VALUE ch)


n--; n--;


cucul_draw_polyline(_SELF, ax, ay, n, NUM2ULONG(ch));
caca_draw_polyline(_SELF, ax, ay, n, NUM2ULONG(ch));


free(ax); free(ax);
free(ay); free(ay);
@@ -318,7 +318,7 @@ static VALUE draw_polyline(VALUE self, VALUE points, VALUE ch)


static VALUE draw_thin_line(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2) static VALUE draw_thin_line(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2)
{ {
cucul_draw_thin_line(_SELF, NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2));
caca_draw_thin_line(_SELF, NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2));
return self; return self;
} }


@@ -370,7 +370,7 @@ static VALUE draw_thin_polyline(VALUE self, VALUE points)


n--; n--;


cucul_draw_thin_polyline(_SELF, ax, ay, n);
caca_draw_thin_polyline(_SELF, ax, ay, n);


free(ax); free(ax);
free(ay); free(ay);
@@ -380,67 +380,67 @@ static VALUE draw_thin_polyline(VALUE self, VALUE points)


static VALUE draw_circle(VALUE self, VALUE x, VALUE y, VALUE r, VALUE ch) static VALUE draw_circle(VALUE self, VALUE x, VALUE y, VALUE r, VALUE ch)
{ {
cucul_draw_circle(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(r), NUM2ULONG(ch));
caca_draw_circle(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(r), NUM2ULONG(ch));
return self; return self;
} }


static VALUE draw_ellipse(VALUE self, VALUE x, VALUE y, VALUE a, VALUE b, VALUE ch) static VALUE draw_ellipse(VALUE self, VALUE x, VALUE y, VALUE a, VALUE b, VALUE ch)
{ {
cucul_draw_ellipse(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(a), NUM2INT(b), NUM2ULONG(ch));
caca_draw_ellipse(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(a), NUM2INT(b), NUM2ULONG(ch));
return self; return self;
} }


static VALUE draw_thin_ellipse(VALUE self, VALUE x, VALUE y, VALUE a, VALUE b) static VALUE draw_thin_ellipse(VALUE self, VALUE x, VALUE y, VALUE a, VALUE b)
{ {
cucul_draw_thin_ellipse(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(a), NUM2INT(b));
caca_draw_thin_ellipse(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(a), NUM2INT(b));
return self; return self;
} }


static VALUE fill_ellipse(VALUE self, VALUE x, VALUE y, VALUE a, VALUE b, VALUE ch) static VALUE fill_ellipse(VALUE self, VALUE x, VALUE y, VALUE a, VALUE b, VALUE ch)
{ {
cucul_fill_ellipse(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(a), NUM2INT(b), NUM2ULONG(ch));
caca_fill_ellipse(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(a), NUM2INT(b), NUM2ULONG(ch));
return self; return self;
} }


static VALUE draw_box(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h, VALUE ch) static VALUE draw_box(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h, VALUE ch)
{ {
cucul_draw_box(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h), NUM2ULONG(ch));
caca_draw_box(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h), NUM2ULONG(ch));
return self; return self;
} }


static VALUE draw_thin_box(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h) static VALUE draw_thin_box(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h)
{ {
cucul_draw_thin_box(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h));
caca_draw_thin_box(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h));
return self; return self;
} }


static VALUE draw_cp437_box(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h) static VALUE draw_cp437_box(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h)
{ {
cucul_draw_cp437_box(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h));
caca_draw_cp437_box(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h));
return self; return self;
} }


static VALUE fill_box(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h, VALUE ch) static VALUE fill_box(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h, VALUE ch)
{ {
cucul_fill_box(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h), NUM2ULONG(ch));
caca_fill_box(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h), NUM2ULONG(ch));
return self; return self;
} }


static VALUE draw_triangle(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE x3, VALUE y3, VALUE ch) static VALUE draw_triangle(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE x3, VALUE y3, VALUE ch)
{ {
cucul_draw_triangle(_SELF, NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2), NUM2INT(x3), NUM2INT(y3), NUM2ULONG(ch));
caca_draw_triangle(_SELF, NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2), NUM2INT(x3), NUM2INT(y3), NUM2ULONG(ch));
return self; return self;
} }


static VALUE draw_thin_triangle(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE x3, VALUE y3) static VALUE draw_thin_triangle(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE x3, VALUE y3)
{ {
cucul_draw_thin_triangle(_SELF, NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2), NUM2INT(x3), NUM2INT(y3));
caca_draw_thin_triangle(_SELF, NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2), NUM2INT(x3), NUM2INT(y3));
return self; return self;
} }


static VALUE fill_triangle(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE x3, VALUE y3, VALUE ch) static VALUE fill_triangle(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE x3, VALUE y3, VALUE ch)
{ {
cucul_fill_triangle(_SELF, NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2), NUM2INT(x3), NUM2INT(y3), NUM2ULONG(ch));
caca_fill_triangle(_SELF, NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2), NUM2INT(x3), NUM2INT(y3), NUM2ULONG(ch));
return self; return self;
} }


@@ -450,7 +450,7 @@ static VALUE dither_bitmap(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h, VALUE
rb_raise(rb_eArgError, "d is not a Cucul::Dither"); rb_raise(rb_eArgError, "d is not a Cucul::Dither");
Check_Type(pixels, T_STRING); Check_Type(pixels, T_STRING);


cucul_dither_bitmap(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h), DATA_PTR(d), StringValuePtr(pixels));
caca_dither_bitmap(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h), DATA_PTR(d), StringValuePtr(pixels));
return self; return self;
} }


@@ -460,7 +460,7 @@ get_int(frame_count)


static VALUE set_frame(VALUE self, VALUE id) static VALUE set_frame(VALUE self, VALUE id)
{ {
if(cucul_set_frame(_SELF, NUM2INT(id))<0)
if(caca_set_frame(_SELF, NUM2INT(id))<0)
rb_raise(rb_eArgError, strerror(errno)); rb_raise(rb_eArgError, strerror(errno));


return self; return self;
@@ -474,12 +474,12 @@ static VALUE set_frame2(VALUE self, VALUE id)


static VALUE get_frame_name(VALUE self) static VALUE get_frame_name(VALUE self)
{ {
return rb_str_new2(cucul_get_frame_name(_SELF));
return rb_str_new2(caca_get_frame_name(_SELF));
} }


static VALUE set_frame_name(VALUE self, VALUE name) static VALUE set_frame_name(VALUE self, VALUE name)
{ {
if(cucul_set_frame_name(_SELF, StringValuePtr(name))<0)
if(caca_set_frame_name(_SELF, StringValuePtr(name))<0)
rb_raise(rb_eRuntimeError, strerror(errno)); rb_raise(rb_eRuntimeError, strerror(errno));


return self; return self;
@@ -493,7 +493,7 @@ static VALUE set_frame_name2(VALUE self, VALUE name)


static VALUE create_frame(VALUE self, VALUE id) static VALUE create_frame(VALUE self, VALUE id)
{ {
if(cucul_create_frame(_SELF, NUM2INT(id))<0) {
if(caca_create_frame(_SELF, NUM2INT(id))<0) {
rb_raise(rb_eRuntimeError, strerror(errno)); rb_raise(rb_eRuntimeError, strerror(errno));
} }
return self; return self;
@@ -501,7 +501,7 @@ static VALUE create_frame(VALUE self, VALUE id)


static VALUE free_frame(VALUE self, VALUE id) static VALUE free_frame(VALUE self, VALUE id)
{ {
if(cucul_free_frame(_SELF, NUM2INT(id))<0) {
if(caca_free_frame(_SELF, NUM2INT(id))<0) {
rb_raise(rb_eArgError, strerror(errno)); rb_raise(rb_eArgError, strerror(errno));
} }
return self; return self;
@@ -512,7 +512,7 @@ static VALUE free_frame(VALUE self, VALUE id)
static VALUE render_canvas(VALUE self, VALUE font, VALUE width, VALUE height, VALUE pitch) static VALUE render_canvas(VALUE self, VALUE font, VALUE width, VALUE height, VALUE pitch)
{ {
void *buf; void *buf;
cucul_font_t *f;
caca_font_t *f;
VALUE b; VALUE b;


if(CLASS_OF(font) != cFont) if(CLASS_OF(font) != cFont)
@@ -527,7 +527,7 @@ static VALUE render_canvas(VALUE self, VALUE font, VALUE width, VALUE height, VA
} }


f = DATA_PTR(font); f = DATA_PTR(font);
cucul_render_canvas(_SELF, f, buf, NUM2UINT(width), NUM2UINT(height), NUM2UINT(pitch));
caca_render_canvas(_SELF, f, buf, NUM2UINT(width), NUM2UINT(height), NUM2UINT(pitch));


b = rb_str_new(buf, width*height*4); b = rb_str_new(buf, width*height*4);
free(buf); free(buf);
@@ -537,7 +537,7 @@ static VALUE render_canvas(VALUE self, VALUE font, VALUE width, VALUE height, VA
static VALUE import_memory(VALUE self, VALUE data, VALUE format) static VALUE import_memory(VALUE self, VALUE data, VALUE format)
{ {
long int bytes; long int bytes;
bytes = cucul_import_memory (_SELF, StringValuePtr(data), RSTRING(StringValue(data))->len, StringValuePtr(format));
bytes = caca_import_memory (_SELF, StringValuePtr(data), RSTRING(StringValue(data))->len, StringValuePtr(format));
if(bytes <= 0) if(bytes <= 0)
rb_raise(rb_eRuntimeError, strerror(errno)); rb_raise(rb_eRuntimeError, strerror(errno));


@@ -547,7 +547,7 @@ static VALUE import_memory(VALUE self, VALUE data, VALUE format)
static VALUE import_file(VALUE self, VALUE filename, VALUE format) static VALUE import_file(VALUE self, VALUE filename, VALUE format)
{ {
long int bytes; long int bytes;
bytes = cucul_import_file (_SELF, StringValuePtr(filename), StringValuePtr(format));
bytes = caca_import_file (_SELF, StringValuePtr(filename), StringValuePtr(format));
if(bytes <= 0) if(bytes <= 0)
rb_raise(rb_eRuntimeError, strerror(errno)); rb_raise(rb_eRuntimeError, strerror(errno));


@@ -559,7 +559,7 @@ static VALUE export_memory(VALUE self, VALUE format)
unsigned long int bytes; unsigned long int bytes;
void *result; void *result;
VALUE ret; VALUE ret;
result = cucul_export_memory (_SELF, StringValuePtr(format), &bytes);
result = caca_export_memory (_SELF, StringValuePtr(format), &bytes);
ret = rb_str_new(result, bytes); ret = rb_str_new(result, bytes);
free(result); free(result);
return ret; return ret;
@@ -570,7 +570,7 @@ get_singleton_double_list(import)


/****/ /****/


void Init_cucul_canvas(VALUE mCucul)
void Init_caca_canvas(VALUE mCucul)
{ {
cCanvas = rb_define_class_under(mCucul, "Canvas", rb_cObject); cCanvas = rb_define_class_under(mCucul, "Canvas", rb_cObject);
rb_define_alloc_func(cCanvas, canvas_alloc); rb_define_alloc_func(cCanvas, canvas_alloc);

+ 10
- 0
ruby/caca-canvas.h View File

@@ -0,0 +1,10 @@
#ifndef __CACA_CANVAS_H__
#define __CACA_CANVAS_H__

#include <ruby.h>

extern VALUE cCanvas;
extern void Init_caca_canvas(VALUE);
extern VALUE canvas_create(caca_canvas_t *canvas);

#endif

+ 2
- 2
ruby/caca-display.c View File

@@ -13,7 +13,7 @@
#include <caca.h> #include <caca.h>
#include <errno.h> #include <errno.h>
#include "caca-event.h" #include "caca-event.h"
#include "cucul-canvas.h"
#include "caca-canvas.h"
#include "common.h" #include "common.h"


VALUE cDisplay; VALUE cDisplay;
@@ -33,7 +33,7 @@ static VALUE display_alloc(VALUE klass)
static VALUE display_initialize(int argc, VALUE* argv, VALUE self) static VALUE display_initialize(int argc, VALUE* argv, VALUE self)
{ {
caca_display_t *display; caca_display_t *display;
cucul_canvas_t *canvas = NULL;
caca_canvas_t *canvas = NULL;
const char *driver = NULL; const char *driver = NULL;
VALUE cv = Qnil; VALUE cv = Qnil;
VALUE arg1, arg2; VALUE arg1, arg2;


ruby/cucul-dither.c → ruby/caca-dither.c View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Ruby bindings
* libcaca Ruby bindings
* Copyright (c) 2007 Pascal Terjan <pterjan@linuxfr.org> * Copyright (c) 2007 Pascal Terjan <pterjan@linuxfr.org>
* *
* This library is free software. It comes without any warranty, to * This library is free software. It comes without any warranty, to
@@ -10,7 +10,7 @@
*/ */


#include <ruby.h> #include <ruby.h>
#include <cucul.h>
#include <caca.h>
#include <errno.h> #include <errno.h>
#include "common.h" #include "common.h"


@@ -18,7 +18,7 @@ VALUE cDither;


void dither_free(void *dither) void dither_free(void *dither)
{ {
cucul_free_dither((cucul_dither_t *)dither);
caca_free_dither((caca_dither_t *)dither);
} }


static VALUE dither_alloc(VALUE klass) static VALUE dither_alloc(VALUE klass)
@@ -30,9 +30,9 @@ static VALUE dither_alloc(VALUE klass)


static VALUE dither_initialize(VALUE self, VALUE bpp, VALUE w, VALUE h, VALUE pitch, VALUE rmask, VALUE gmask, VALUE bmask, VALUE amask) static VALUE dither_initialize(VALUE self, VALUE bpp, VALUE w, VALUE h, VALUE pitch, VALUE rmask, VALUE gmask, VALUE bmask, VALUE amask)
{ {
cucul_dither_t *dither;
caca_dither_t *dither;


dither = cucul_create_dither(NUM2UINT(bpp), NUM2UINT(w), NUM2UINT(h), NUM2UINT(pitch), NUM2ULONG(rmask), NUM2ULONG(gmask), NUM2ULONG(bmask), NUM2ULONG(amask));
dither = caca_create_dither(NUM2UINT(bpp), NUM2UINT(w), NUM2UINT(h), NUM2UINT(pitch), NUM2ULONG(rmask), NUM2ULONG(gmask), NUM2ULONG(bmask), NUM2ULONG(amask));
if(dither == NULL) if(dither == NULL)
{ {
rb_raise(rb_eRuntimeError, strerror(errno)); rb_raise(rb_eRuntimeError, strerror(errno));
@@ -115,7 +115,7 @@ static VALUE set_dither_palette(VALUE self, VALUE palette)
rb_raise(rb_eArgError, "Invalid palette"); rb_raise(rb_eArgError, "Invalid palette");
} }


if(cucul_set_dither_palette(_SELF, red, green, blue, alpha)<0)
if(caca_set_dither_palette(_SELF, red, green, blue, alpha)<0)
{ {
free(red); free(red);
free(green); free(green);
@@ -141,7 +141,7 @@ static VALUE set_dither_palette2(VALUE self, VALUE palette)
#define set_float(x) \ #define set_float(x) \
static VALUE set_##x(VALUE self, VALUE x) \ static VALUE set_##x(VALUE self, VALUE x) \
{ \ { \
if(cucul_set_dither_##x(_SELF, (float)NUM2DBL(x))<0)\
if(caca_set_dither_##x(_SELF, (float)NUM2DBL(x))<0)\
rb_raise(rb_eRuntimeError, strerror(errno)); \ rb_raise(rb_eRuntimeError, strerror(errno)); \
\ \
return x; \ return x; \
@@ -161,7 +161,7 @@ set_float(contrast)
get_double_list(dither_##x) \ get_double_list(dither_##x) \
static VALUE set_dither_##x(VALUE self, VALUE x) \ static VALUE set_dither_##x(VALUE self, VALUE x) \
{ \ { \
if(cucul_set_dither_##x(_SELF, StringValuePtr(x))<0) \
if(caca_set_dither_##x(_SELF, StringValuePtr(x))<0) \
{ \ { \
rb_raise(rb_eRuntimeError, strerror(errno)); \ rb_raise(rb_eRuntimeError, strerror(errno)); \
} \ } \
@@ -179,7 +179,7 @@ get_set_str_from_list(color)
get_set_str_from_list(charset) get_set_str_from_list(charset)
get_set_str_from_list(algorithm) get_set_str_from_list(algorithm)


void Init_cucul_dither(VALUE mCucul)
void Init_caca_dither(VALUE mCucul)
{ {
cDither = rb_define_class_under(mCucul, "Dither", rb_cObject); cDither = rb_define_class_under(mCucul, "Dither", rb_cObject);
rb_define_alloc_func(cDither, dither_alloc); rb_define_alloc_func(cDither, dither_alloc);

+ 9
- 0
ruby/caca-dither.h View File

@@ -0,0 +1,9 @@
#ifndef __CACA_DITHER_H__
#define __CACA_DITHER_H__

#include <ruby.h>

extern VALUE cDither;
extern void Init_caca_dither(VALUE);

#endif

ruby/cucul-font.c → ruby/caca-font.c View File

@@ -1,5 +1,5 @@
/* /*
* libcucul Ruby bindings
* libcaca Ruby bindings
* Copyright (c) 2007 Pascal Terjan <pterjan@linuxfr.org> * Copyright (c) 2007 Pascal Terjan <pterjan@linuxfr.org>
* *
* This library is free software. It comes without any warranty, to * This library is free software. It comes without any warranty, to
@@ -10,7 +10,7 @@
*/ */


#include <ruby.h> #include <ruby.h>
#include <cucul.h>
#include <caca.h>
#include <errno.h> #include <errno.h>
#include "common.h" #include "common.h"


@@ -18,7 +18,7 @@ VALUE cFont;


void font_free(void *font) void font_free(void *font)
{ {
cucul_free_font((cucul_font_t *)font);
caca_free_font((caca_font_t *)font);
} }


static VALUE font_alloc(VALUE klass) static VALUE font_alloc(VALUE klass)
@@ -30,9 +30,9 @@ static VALUE font_alloc(VALUE klass)


static VALUE font_initialize(VALUE self, VALUE name) static VALUE font_initialize(VALUE self, VALUE name)
{ {
cucul_font_t *font;
caca_font_t *font;


font = cucul_load_font(StringValuePtr(name), 0);
font = caca_load_font(StringValuePtr(name), 0);
if(font == NULL) if(font == NULL)
{ {
rb_raise(rb_eRuntimeError, strerror(errno)); rb_raise(rb_eRuntimeError, strerror(errno));
@@ -46,7 +46,7 @@ static VALUE font_list(void)
VALUE ary; VALUE ary;
char const* const* list; char const* const* list;
list = cucul_get_font_list();
list = caca_get_font_list();
ary = rb_ary_new(); ary = rb_ary_new();
while (*list != NULL) while (*list != NULL)
@@ -60,12 +60,12 @@ static VALUE font_list(void)


static VALUE get_font_width(VALUE self) static VALUE get_font_width(VALUE self)
{ {
return UINT2NUM(cucul_get_font_width(_SELF));
return UINT2NUM(caca_get_font_width(_SELF));
} }


static VALUE get_font_height(VALUE self) static VALUE get_font_height(VALUE self)
{ {
return UINT2NUM(cucul_get_font_height(_SELF));
return UINT2NUM(caca_get_font_height(_SELF));
} }


static VALUE get_font_blocks(VALUE self) static VALUE get_font_blocks(VALUE self)
@@ -73,7 +73,7 @@ static VALUE get_font_blocks(VALUE self)
VALUE ary; VALUE ary;
uint32_t const *list; uint32_t const *list;
list = cucul_get_font_blocks(_SELF);
list = caca_get_font_blocks(_SELF);
ary = rb_ary_new(); ary = rb_ary_new();
while (*list != 0L) while (*list != 0L)
@@ -85,7 +85,7 @@ static VALUE get_font_blocks(VALUE self)
return ary; return ary;
} }


void Init_cucul_font(VALUE mCucul)
void Init_caca_font(VALUE mCucul)
{ {
cFont = rb_define_class_under(mCucul, "Font", rb_cObject); cFont = rb_define_class_under(mCucul, "Font", rb_cObject);
rb_define_alloc_func(cFont, font_alloc); rb_define_alloc_func(cFont, font_alloc);

+ 9
- 0
ruby/caca-font.h View File

@@ -0,0 +1,9 @@
#ifndef __CACA_FONT_H__
#define __CACA_FONT_H__

#include <ruby.h>

extern VALUE cFont;
extern void Init_caca_font(VALUE);

#endif

+ 30
- 0
ruby/caca.c View File

@@ -12,6 +12,9 @@
#include <ruby.h> #include <ruby.h>
#include <caca.h> #include <caca.h>


#include "caca-canvas.h"
#include "caca-dither.h"
#include "caca-font.h"
#include "caca-display.h" #include "caca-display.h"
#include "caca-event.h" #include "caca-event.h"


@@ -26,6 +29,33 @@ void Init_caca()


rb_define_singleton_method(mCaca, "version", get_version, 0); rb_define_singleton_method(mCaca, "version", get_version, 0);


rb_define_const(mCaca, "BLACK", INT2FIX(CACA_BLACK));
rb_define_const(mCaca, "BLUE", INT2FIX(CACA_BLUE));
rb_define_const(mCaca, "GREEN", INT2FIX(CACA_GREEN));
rb_define_const(mCaca, "CYAN", INT2FIX(CACA_CYAN));
rb_define_const(mCaca, "RED", INT2FIX(CACA_RED));
rb_define_const(mCaca, "MAGENTA", INT2FIX(CACA_MAGENTA));
rb_define_const(mCaca, "BROWN", INT2FIX(CACA_BROWN));
rb_define_const(mCaca, "LIGHTGRAY", INT2FIX(CACA_LIGHTGRAY));
rb_define_const(mCaca, "DARKGRAY", INT2FIX(CACA_DARKGRAY));
rb_define_const(mCaca, "LIGHTBLUE", INT2FIX(CACA_LIGHTBLUE));
rb_define_const(mCaca, "LIGHTGREEN", INT2FIX(CACA_LIGHTGREEN));
rb_define_const(mCaca, "LIGHTCYAN", INT2FIX(CACA_LIGHTCYAN));
rb_define_const(mCaca, "LIGHTRED", INT2FIX(CACA_LIGHTRED));
rb_define_const(mCaca, "LIGHTMAGENTA", INT2FIX(CACA_LIGHTMAGENTA));
rb_define_const(mCaca, "YELLOW", INT2FIX(CACA_YELLOW));
rb_define_const(mCaca, "WHITE", INT2FIX(CACA_WHITE));
rb_define_const(mCaca, "DEFAULT", INT2FIX(CACA_DEFAULT));
rb_define_const(mCaca, "TRANSPARENT", INT2FIX(CACA_TRANSPARENT));

rb_define_const(mCaca, "BOLD", INT2FIX(CACA_BOLD));
rb_define_const(mCaca, "ITALICS", INT2FIX(CACA_ITALICS));
rb_define_const(mCaca, "UNDERLINE", INT2FIX(CACA_UNDERLINE));
rb_define_const(mCaca, "BLINK", INT2FIX(CACA_BLINK));

Init_caca_canvas(mCaca);
Init_caca_dither(mCaca);
Init_caca_font(mCaca);
Init_caca_display(mCaca); Init_caca_display(mCaca);
Init_caca_event(mCaca); Init_caca_event(mCaca);
} }

+ 2
- 2
ruby/common.h View File

@@ -9,7 +9,7 @@ static VALUE x##_list(void) \
VALUE ary, ary2; \ VALUE ary, ary2; \
char const* const* list; \ char const* const* list; \
\ \
list = cucul_get_##x##_list(); \
list = caca_get_##x##_list(); \
ary = rb_ary_new(); \ ary = rb_ary_new(); \
while (*list != NULL) \ while (*list != NULL) \
{ \ { \
@@ -30,7 +30,7 @@ static VALUE x##_list(VALUE self) \
VALUE ary, ary2; \ VALUE ary, ary2; \
char const* const* list; \ char const* const* list; \
\ \
list = cucul_get_##x##_list(_SELF); \
list = caca_get_##x##_list(_SELF); \
ary = rb_ary_new(); \ ary = rb_ary_new(); \
while (*list != NULL) \ while (*list != NULL) \
{ \ { \


+ 0
- 10
ruby/cucul-canvas.h View File

@@ -1,10 +0,0 @@
#ifndef __CUCUL_CANVAS_H__
#define __CUCUL_CANVAS_H__

#include <ruby.h>

extern VALUE cCanvas;
extern void Init_cucul_canvas(VALUE);
extern VALUE canvas_create(cucul_canvas_t *canvas);

#endif

+ 0
- 9
ruby/cucul-dither.h View File

@@ -1,9 +0,0 @@
#ifndef __CUCUL_DITHER_H__
#define __CUCUL_DITHER_H__

#include <ruby.h>

extern VALUE cDither;
extern void Init_cucul_dither(VALUE);

#endif

+ 0
- 9
ruby/cucul-font.h View File

@@ -1,9 +0,0 @@
#ifndef __CUCUL_FONT_H__
#define __CUCUL_FONT_H__

#include <ruby.h>

extern VALUE cFont;
extern void Init_cucul_font(VALUE);

#endif

+ 0
- 57
ruby/cucul.c View File

@@ -1,57 +0,0 @@
/*
* libcucul Ruby bindings
* Copyright (c) 2007 Pascal Terjan <pterjan@linuxfr.org>
*
* This library is free software. It comes without any warranty, to
* the extent permitted by applicable law. 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.
*/

#include <ruby.h>
#include <cucul.h>

#include "cucul-canvas.h"
#include "cucul-dither.h"
#include "cucul-font.h"

static VALUE get_version(VALUE self)
{
return rb_str_new2(cucul_get_version());
}

void Init_cucul()
{
VALUE mCucul = rb_define_module("Cucul");

rb_define_singleton_method(mCucul, "version", get_version, 0);

rb_define_const(mCucul, "BLACK", INT2FIX(CUCUL_BLACK));
rb_define_const(mCucul, "BLUE", INT2FIX(CUCUL_BLUE));
rb_define_const(mCucul, "GREEN", INT2FIX(CUCUL_GREEN));
rb_define_const(mCucul, "CYAN", INT2FIX(CUCUL_CYAN));
rb_define_const(mCucul, "RED", INT2FIX(CUCUL_RED));
rb_define_const(mCucul, "MAGENTA", INT2FIX(CUCUL_MAGENTA));
rb_define_const(mCucul, "BROWN", INT2FIX(CUCUL_BROWN));
rb_define_const(mCucul, "LIGHTGRAY", INT2FIX(CUCUL_LIGHTGRAY));
rb_define_const(mCucul, "DARKGRAY", INT2FIX(CUCUL_DARKGRAY));
rb_define_const(mCucul, "LIGHTBLUE", INT2FIX(CUCUL_LIGHTBLUE));
rb_define_const(mCucul, "LIGHTGREEN", INT2FIX(CUCUL_LIGHTGREEN));
rb_define_const(mCucul, "LIGHTCYAN", INT2FIX(CUCUL_LIGHTCYAN));
rb_define_const(mCucul, "LIGHTRED", INT2FIX(CUCUL_LIGHTRED));
rb_define_const(mCucul, "LIGHTMAGENTA", INT2FIX(CUCUL_LIGHTMAGENTA));
rb_define_const(mCucul, "YELLOW", INT2FIX(CUCUL_YELLOW));
rb_define_const(mCucul, "WHITE", INT2FIX(CUCUL_WHITE));
rb_define_const(mCucul, "DEFAULT", INT2FIX(CUCUL_DEFAULT));
rb_define_const(mCucul, "TRANSPARENT", INT2FIX(CUCUL_TRANSPARENT));

rb_define_const(mCucul, "BOLD", INT2FIX(CUCUL_BOLD));
rb_define_const(mCucul, "ITALICS", INT2FIX(CUCUL_ITALICS));
rb_define_const(mCucul, "UNDERLINE", INT2FIX(CUCUL_UNDERLINE));
rb_define_const(mCucul, "BLINK", INT2FIX(CUCUL_BLINK));

Init_cucul_canvas(mCucul);
Init_cucul_dither(mCucul);
Init_cucul_font(mCucul);
}

+ 8
- 8
src/Makefile.am View File

@@ -3,35 +3,35 @@
pkgdata_DATA = caca.txt pkgdata_DATA = caca.txt


EXTRA_DIST = caca.txt EXTRA_DIST = caca.txt
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/cucul -I../cucul \
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/caca -I../caca \
-I$(top_srcdir)/caca -DLIBCACA=1 -DX_DISPLAY_MISSING=1 -I$(top_srcdir)/caca -DLIBCACA=1 -DX_DISPLAY_MISSING=1


bin_PROGRAMS = cacademo cacafire cacaplay cacaview img2txt $(fcntl_programs) bin_PROGRAMS = cacademo cacafire cacaplay cacaview img2txt $(fcntl_programs)
noinst_PROGRAMS = cacadraw noinst_PROGRAMS = cacadraw


cacademo_SOURCES = cacademo.c texture.h cacademo_SOURCES = cacademo.c texture.h
cacademo_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
cacademo_LDADD = ../caca/libcaca.la ../caca/libcaca.la
cacademo_LDFLAGS = @MATH_LIBS@ cacademo_LDFLAGS = @MATH_LIBS@


cacafire_SOURCES = aafire.c cacafire_SOURCES = aafire.c
cacafire_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
cacafire_LDADD = ../caca/libcaca.la ../caca/libcaca.la


cacaview_SOURCES = cacaview.c common-image.c common-image.h cacaview_SOURCES = cacaview.c common-image.c common-image.h
cacaview_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
cacaview_LDADD = ../caca/libcaca.la ../caca/libcaca.la
cacaview_CFLAGS = $(IMLIB2_CFLAGS) cacaview_CFLAGS = $(IMLIB2_CFLAGS)
cacaview_LDFLAGS = $(IMLIB2_LIBS) cacaview_LDFLAGS = $(IMLIB2_LIBS)


cacadraw_SOURCES = cacadraw.c cacadraw_SOURCES = cacadraw.c
cacadraw_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
cacadraw_LDADD = ../caca/libcaca.la ../caca/libcaca.la


cacaplay_SOURCES = cacaplay.c cacaplay_SOURCES = cacaplay.c
cacaplay_LDADD = ../caca/libcaca.la ../cucul/libcucul.la
cacaplay_LDADD = ../caca/libcaca.la ../caca/libcaca.la


cacaserver_SOURCES = cacaserver.c cacaserver_SOURCES = cacaserver.c
cacaserver_LDADD = ../cucul/libcucul.la
cacaserver_LDADD = ../caca/libcaca.la


img2txt_SOURCES = img2txt.c $(GETOPT) common-image.c common-image.h img2txt_SOURCES = img2txt.c $(GETOPT) common-image.c common-image.h
img2txt_LDADD = ../cucul/libcucul.la
img2txt_LDADD = ../caca/libcaca.la
img2txt_CFLAGS = $(IMLIB2_CFLAGS) img2txt_CFLAGS = $(IMLIB2_CFLAGS)
img2txt_LDFLAGS = $(IMLIB2_LIBS) $(GETOPT_LIBS) img2txt_LDFLAGS = $(IMLIB2_LIBS) $(GETOPT_LIBS)




+ 18
- 19
src/aafire.c View File

@@ -29,7 +29,6 @@
# include <stdlib.h> # include <stdlib.h>
# include <string.h> # include <string.h>
#endif #endif
#include "cucul.h"
#include "caca.h" #include "caca.h"
#else #else
#include <stdio.h> #include <stdio.h>
@@ -40,10 +39,10 @@
#endif #endif
#define MAXTABLE (256*5) #define MAXTABLE (256*5)
#ifdef LIBCACA #ifdef LIBCACA
static cucul_canvas_t *cv;
static caca_canvas_t *cv;
static caca_display_t *dp; static caca_display_t *dp;
static int XSIZ, YSIZ; static int XSIZ, YSIZ;
static cucul_dither_t *cucul_dither;
static caca_dither_t *caca_dither;
static char *bitmap; static char *bitmap;
static int paused = 0; static int paused = 0;
#else #else
@@ -101,10 +100,10 @@ initialize (void)
#endif #endif


#ifdef LIBCACA #ifdef LIBCACA
cv = cucul_create_canvas(80, 32);
cv = caca_create_canvas(80, 32);
if (!cv) if (!cv)
{ {
printf ("Failed to initialize libcucul\n");
printf ("Failed to initialize libcaca\n");
exit (1); exit (1);
} }
dp = caca_create_display(cv); dp = caca_create_display(cv);
@@ -114,8 +113,8 @@ initialize (void)
exit (1); exit (1);
} }
caca_set_display_time(dp, 10000); caca_set_display_time(dp, 10000);
XSIZ = cucul_get_canvas_width(cv) * 2;
YSIZ = cucul_get_canvas_height(cv) * 2 - 4;
XSIZ = caca_get_canvas_width(cv) * 2;
YSIZ = caca_get_canvas_height(cv) * 2 - 4;
#else #else
context = aa_autoinit (&aa_defparams); context = aa_autoinit (&aa_defparams);
if (context == NULL) if (context == NULL)
@@ -141,12 +140,12 @@ initialize (void)
#endif #endif


#ifdef LIBCACA #ifdef LIBCACA
cucul_dither = cucul_create_dither(8, XSIZ, YSIZ - 2, XSIZ, 0, 0, 0, 0);
cucul_set_dither_palette(cucul_dither, r, g, b, a);
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));
caca_dither = caca_create_dither(8, XSIZ, YSIZ - 2, XSIZ, 0, 0, 0, 0);
caca_set_dither_palette(caca_dither, r, g, b, a);
bitmap = malloc(4 * caca_get_canvas_width(cv)
* caca_get_canvas_height(cv));
memset(bitmap, 0, 4 * caca_get_canvas_width(cv)
* caca_get_canvas_height(cv));
#else #else
aa_hidecursor (context); aa_hidecursor (context);
#endif #endif
@@ -156,7 +155,7 @@ uninitialize (void)
{ {
#ifdef LIBCACA #ifdef LIBCACA
caca_free_display(dp); caca_free_display(dp);
cucul_free_canvas(cv);
caca_free_canvas(cv);
#else #else
aa_close (context); aa_close (context);
#endif #endif
@@ -238,12 +237,12 @@ drawfire (void)
firemain (); firemain ();
#ifdef LIBCACA #ifdef LIBCACA
_paused: _paused:
cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv),
cucul_get_canvas_height(cv), cucul_dither, bitmap);
cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
caca_dither_bitmap(cv, 0, 0, caca_get_canvas_width(cv),
caca_get_canvas_height(cv), caca_dither, bitmap);
caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
if (sloop < 100) if (sloop < 100)
cucul_put_str(cv, cucul_get_canvas_width(cv) - 30,
cucul_get_canvas_height(cv) - 2,
caca_put_str(cv, caca_get_canvas_width(cv) - 30,
caca_get_canvas_height(cv) - 2,
" -=[ Powered by libcaca ]=- "); " -=[ Powered by libcaca ]=- ");
caca_refresh_display(dp); caca_refresh_display(dp);


+ 117
- 118
src/cacademo.c View File

@@ -26,20 +26,19 @@
# endif # endif
#endif #endif


#include "cucul.h"
#include "caca.h" #include "caca.h"


enum action { PREPARE, INIT, UPDATE, RENDER, FREE }; enum action { PREPARE, INIT, UPDATE, RENDER, FREE };


void transition(cucul_canvas_t *, int, int);
void plasma(enum action, cucul_canvas_t *);
void metaballs(enum action, cucul_canvas_t *);
void moire(enum action, cucul_canvas_t *);
void langton(enum action, cucul_canvas_t *);
void matrix(enum action, cucul_canvas_t *);
void rotozoom(enum action, cucul_canvas_t *);
void transition(caca_canvas_t *, int, int);
void plasma(enum action, caca_canvas_t *);
void metaballs(enum action, caca_canvas_t *);
void moire(enum action, caca_canvas_t *);
void langton(enum action, caca_canvas_t *);
void matrix(enum action, caca_canvas_t *);
void rotozoom(enum action, caca_canvas_t *);


void (*fn[])(enum action, cucul_canvas_t *) =
void (*fn[])(enum action, caca_canvas_t *) =
{ {
plasma, plasma,
metaballs, metaballs,
@@ -50,7 +49,7 @@ void (*fn[])(enum action, cucul_canvas_t *) =
}; };
#define DEMOS (sizeof(fn)/sizeof(*fn)) #define DEMOS (sizeof(fn)/sizeof(*fn))


#define DEMO_FRAMES cucul_rand(500, 1000)
#define DEMO_FRAMES caca_rand(500, 1000)
#define TRANSITION_FRAMES 40 #define TRANSITION_FRAMES 40


#define TRANSITION_COUNT 5 #define TRANSITION_COUNT 5
@@ -70,25 +69,25 @@ static int frame = 0;
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
static caca_display_t *dp; static caca_display_t *dp;
static cucul_canvas_t *frontcv, *backcv, *mask;
static caca_canvas_t *frontcv, *backcv, *mask;


int demo, next = -1, paused = 0, next_transition = DEMO_FRAMES; int demo, next = -1, paused = 0, next_transition = DEMO_FRAMES;
unsigned int i; unsigned int i;
int tmode = cucul_rand(0, TRANSITION_COUNT);
int tmode = caca_rand(0, TRANSITION_COUNT);


/* Set up two canvases, a mask, and attach a display to the front one */ /* Set up two canvases, a mask, and attach a display to the front one */
frontcv = cucul_create_canvas(0, 0);
backcv = cucul_create_canvas(0, 0);
mask = cucul_create_canvas(0, 0);
frontcv = caca_create_canvas(0, 0);
backcv = caca_create_canvas(0, 0);
mask = caca_create_canvas(0, 0);


dp = caca_create_display(frontcv); dp = caca_create_display(frontcv);
if(!dp) if(!dp)
return 1; return 1;


cucul_set_canvas_size(backcv, cucul_get_canvas_width(frontcv),
cucul_get_canvas_height(frontcv));
cucul_set_canvas_size(mask, cucul_get_canvas_width(frontcv),
cucul_get_canvas_height(frontcv));
caca_set_canvas_size(backcv, caca_get_canvas_width(frontcv),
caca_get_canvas_height(frontcv));
caca_set_canvas_size(mask, caca_get_canvas_width(frontcv),
caca_get_canvas_height(frontcv));


caca_set_display_time(dp, 20000); caca_set_display_time(dp, 20000);


@@ -97,7 +96,7 @@ int main(int argc, char **argv)
fn[i](PREPARE, frontcv); fn[i](PREPARE, frontcv);


/* Choose a demo at random */ /* Choose a demo at random */
demo = cucul_rand(0, DEMOS);
demo = caca_rand(0, DEMOS);
fn[demo](INIT, frontcv); fn[demo](INIT, frontcv);


for(;;) for(;;)
@@ -127,10 +126,10 @@ int main(int argc, char **argv)
} }


/* Resize the spare canvas, just in case the main one changed */ /* Resize the spare canvas, just in case the main one changed */
cucul_set_canvas_size(backcv, cucul_get_canvas_width(frontcv),
cucul_get_canvas_height(frontcv));
cucul_set_canvas_size(mask, cucul_get_canvas_width(frontcv),
cucul_get_canvas_height(frontcv));
caca_set_canvas_size(backcv, caca_get_canvas_width(frontcv),
caca_get_canvas_height(frontcv));
caca_set_canvas_size(mask, caca_get_canvas_width(frontcv),
caca_get_canvas_height(frontcv));


if(paused) if(paused)
goto _paused; goto _paused;
@@ -141,7 +140,7 @@ int main(int argc, char **argv)
/* Handle transitions */ /* Handle transitions */
if(frame == next_transition) if(frame == next_transition)
{ {
next = cucul_rand(0, DEMOS);
next = caca_rand(0, DEMOS);
if(next == demo) if(next == demo)
next = (next + 1) % DEMOS; next = (next + 1) % DEMOS;
fn[next](INIT, backcv); fn[next](INIT, backcv);
@@ -152,7 +151,7 @@ int main(int argc, char **argv)
demo = next; demo = next;
next = -1; next = -1;
next_transition = frame + DEMO_FRAMES; next_transition = frame + DEMO_FRAMES;
tmode = cucul_rand(0, TRANSITION_COUNT);
tmode = caca_rand(0, TRANSITION_COUNT);
} }


if(next != -1) if(next != -1)
@@ -167,18 +166,18 @@ _paused:
if(next != -1) if(next != -1)
{ {
fn[next](RENDER, backcv); fn[next](RENDER, backcv);
cucul_set_color_ansi(mask, CUCUL_LIGHTGRAY, CUCUL_BLACK);
cucul_clear_canvas(mask);
cucul_set_color_ansi(mask, CUCUL_WHITE, CUCUL_WHITE);
caca_set_color_ansi(mask, CACA_LIGHTGRAY, CACA_BLACK);
caca_clear_canvas(mask);
caca_set_color_ansi(mask, CACA_WHITE, CACA_WHITE);
transition(mask, tmode, transition(mask, tmode,
100 * (frame - next_transition) / TRANSITION_FRAMES); 100 * (frame - next_transition) / TRANSITION_FRAMES);
cucul_blit(frontcv, 0, 0, backcv, mask);
caca_blit(frontcv, 0, 0, backcv, mask);
} }


cucul_set_color_ansi(frontcv, CUCUL_WHITE, CUCUL_BLUE);
caca_set_color_ansi(frontcv, CACA_WHITE, CACA_BLUE);
if(frame < 100) if(frame < 100)
cucul_put_str(frontcv, cucul_get_canvas_width(frontcv) - 30,
cucul_get_canvas_height(frontcv) - 2,
caca_put_str(frontcv, caca_get_canvas_width(frontcv) - 30,
caca_get_canvas_height(frontcv) - 2,
" -=[ Powered by libcaca ]=- "); " -=[ Powered by libcaca ]=- ");
caca_refresh_display(dp); caca_refresh_display(dp);
} }
@@ -188,15 +187,15 @@ end:
fn[demo](FREE, frontcv); fn[demo](FREE, frontcv);


caca_free_display(dp); caca_free_display(dp);
cucul_free_canvas(mask);
cucul_free_canvas(backcv);
cucul_free_canvas(frontcv);
caca_free_canvas(mask);
caca_free_canvas(backcv);
caca_free_canvas(frontcv);


return 0; return 0;
} }


/* Transitions */ /* Transitions */
void transition(cucul_canvas_t *mask, int tmode, int completed)
void transition(caca_canvas_t *mask, int tmode, int completed)
{ {
static float const star[] = static float const star[] =
{ {
@@ -223,14 +222,14 @@ void transition(cucul_canvas_t *mask, int tmode, int completed)
}; };
static float square_rot[sizeof(square)/sizeof(*square)]; static float square_rot[sizeof(square)/sizeof(*square)];


float mulx = 0.0075f * completed * cucul_get_canvas_width(mask);
float muly = 0.0075f * completed * cucul_get_canvas_height(mask);
int w2 = cucul_get_canvas_width(mask) / 2;
int h2 = cucul_get_canvas_height(mask) / 2;
float mulx = 0.0075f * completed * caca_get_canvas_width(mask);
float muly = 0.0075f * completed * caca_get_canvas_height(mask);
int w2 = caca_get_canvas_width(mask) / 2;
int h2 = caca_get_canvas_height(mask) / 2;
float angle = (0.0075f * completed * 360) * 3.14 / 180, x, y; float angle = (0.0075f * completed * 360) * 3.14 / 180, x, y;
unsigned int i; unsigned int i;
int w = cucul_get_canvas_width(mask);
int h = cucul_get_canvas_height(mask);
int w = caca_get_canvas_width(mask);
int h = caca_get_canvas_height(mask);


switch(tmode) switch(tmode)
{ {
@@ -247,11 +246,11 @@ void transition(cucul_canvas_t *mask, int tmode, int completed)


mulx *= 1.8; mulx *= 1.8;
muly *= 1.8; muly *= 1.8;
cucul_fill_triangle(mask,
caca_fill_triangle(mask,
square_rot[0*2] * mulx + w2, square_rot[0*2+1] * muly + h2, \ square_rot[0*2] * mulx + w2, square_rot[0*2+1] * muly + h2, \
square_rot[1*2] * mulx + w2, square_rot[1*2+1] * muly + h2, \ square_rot[1*2] * mulx + w2, square_rot[1*2+1] * muly + h2, \
square_rot[2*2] * mulx + w2, square_rot[2*2+1] * muly + h2, '#'); square_rot[2*2] * mulx + w2, square_rot[2*2+1] * muly + h2, '#');
cucul_fill_triangle(mask,
caca_fill_triangle(mask,
square_rot[0*2] * mulx + w2, square_rot[0*2+1] * muly + h2, \ square_rot[0*2] * mulx + w2, square_rot[0*2+1] * muly + h2, \
square_rot[2*2] * mulx + w2, square_rot[2*2+1] * muly + h2, \ square_rot[2*2] * mulx + w2, square_rot[2*2+1] * muly + h2, \
square_rot[3*2] * mulx + w2, square_rot[3*2+1] * muly + h2, '#'); square_rot[3*2] * mulx + w2, square_rot[3*2+1] * muly + h2, '#');
@@ -273,7 +272,7 @@ void transition(cucul_canvas_t *mask, int tmode, int completed)
muly *= 1.8; muly *= 1.8;


#define DO_TRI(a, b, c) \ #define DO_TRI(a, b, c) \
cucul_fill_triangle(mask, \
caca_fill_triangle(mask, \
star_rot[(a)*2] * mulx + w2, star_rot[(a)*2+1] * muly + h2, \ star_rot[(a)*2] * mulx + w2, star_rot[(a)*2+1] * muly + h2, \
star_rot[(b)*2] * mulx + w2, star_rot[(b)*2+1] * muly + h2, \ star_rot[(b)*2] * mulx + w2, star_rot[(b)*2+1] * muly + h2, \
star_rot[(c)*2] * mulx + w2, star_rot[(c)*2+1] * muly + h2, '#') star_rot[(c)*2] * mulx + w2, star_rot[(c)*2+1] * muly + h2, '#')
@@ -288,14 +287,14 @@ void transition(cucul_canvas_t *mask, int tmode, int completed)
break; break;


case TRANSITION_CIRCLE: case TRANSITION_CIRCLE:
cucul_fill_ellipse(mask, w2, h2, mulx, muly, '#');
caca_fill_ellipse(mask, w2, h2, mulx, muly, '#');
break; break;


case TRANSITION_VLINES: case TRANSITION_VLINES:
for(i = 0; i < 8; i++) for(i = 0; i < 8; i++)
{ {
int z = ((i & 1) ? w : (-w)/2) * (100 - completed) / 100; int z = ((i & 1) ? w : (-w)/2) * (100 - completed) / 100;
cucul_fill_box(mask, i * w / 8, z , (w / 8) + 1, z + h, '#');
caca_fill_box(mask, i * w / 8, z , (w / 8) + 1, z + h, '#');
} }
break; break;


@@ -304,7 +303,7 @@ void transition(cucul_canvas_t *mask, int tmode, int completed)
for(i = 0; i < 6; i++) for(i = 0; i < 6; i++)
{ {
int z = ((i & 1) ? w : (-w)/2) * (100 - completed) / 100; int z = ((i & 1) ? w : (-w)/2) * (100 - completed) / 100;
cucul_fill_box(mask, z, i * h / 6, z + w, (h / 6) + 1, '#');
caca_fill_box(mask, z, i * h / 6, z + w, (h / 6) + 1, '#');
} }
break; break;
} }
@@ -318,9 +317,9 @@ static uint8_t table[TABLEX * TABLEY];
static void do_plasma(uint8_t *, static void do_plasma(uint8_t *,
double, double, double, double, double, double); double, double, double, double, double, double);


void plasma(enum action action, cucul_canvas_t *cv)
void plasma(enum action action, caca_canvas_t *cv)
{ {
static cucul_dither_t *dither;
static caca_dither_t *dither;
static uint8_t *screen; static uint8_t *screen;
static uint32_t red[256], green[256], blue[256], alpha[256]; static uint32_t red[256], green[256], blue[256], alpha[256];
static double r[3], R[6]; static double r[3], R[6];
@@ -335,10 +334,10 @@ void plasma(enum action action, cucul_canvas_t *cv)
red[i] = green[i] = blue[i] = alpha[i] = 0; red[i] = green[i] = blue[i] = alpha[i] = 0;


for(i = 0; i < 3; i++) for(i = 0; i < 3; i++)
r[i] = (double)(cucul_rand(1, 1000)) / 60000 * M_PI;
r[i] = (double)(caca_rand(1, 1000)) / 60000 * M_PI;


for(i = 0; i < 6; i++) for(i = 0; i < 6; i++)
R[i] = (double)(cucul_rand(1, 1000)) / 10000;
R[i] = (double)(caca_rand(1, 1000)) / 10000;


for(y = 0 ; y < TABLEY ; y++) for(y = 0 ; y < TABLEY ; y++)
for(x = 0 ; x < TABLEX ; x++) for(x = 0 ; x < TABLEX ; x++)
@@ -353,7 +352,7 @@ void plasma(enum action action, cucul_canvas_t *cv)


case INIT: case INIT:
screen = malloc(XSIZ * YSIZ * sizeof(uint8_t)); screen = malloc(XSIZ * YSIZ * sizeof(uint8_t));
dither = cucul_create_dither(8, XSIZ, YSIZ, XSIZ, 0, 0, 0, 0);
dither = caca_create_dither(8, XSIZ, YSIZ, XSIZ, 0, 0, 0, 0);
break; break;


case UPDATE: case UPDATE:
@@ -367,7 +366,7 @@ void plasma(enum action action, cucul_canvas_t *cv)
} }


/* Set the palette */ /* Set the palette */
cucul_set_dither_palette(dither, red, green, blue, alpha);
caca_set_dither_palette(dither, red, green, blue, alpha);


do_plasma(screen, do_plasma(screen,
(1.0 + sin(((double)frame) * R[0])) / 2, (1.0 + sin(((double)frame) * R[0])) / 2,
@@ -379,15 +378,15 @@ void plasma(enum action action, cucul_canvas_t *cv)
break; break;


case RENDER: case RENDER:
cucul_dither_bitmap(cv, 0, 0,
cucul_get_canvas_width(cv),
cucul_get_canvas_height(cv),
caca_dither_bitmap(cv, 0, 0,
caca_get_canvas_width(cv),
caca_get_canvas_height(cv),
dither, screen); dither, screen);
break; break;


case FREE: case FREE:
free(screen); free(screen);
cucul_free_dither(dither);
caca_free_dither(dither);
break; break;
} }
} }
@@ -425,9 +424,9 @@ static uint8_t metaball[METASIZE * METASIZE];
static void create_ball(void); static void create_ball(void);
static void draw_ball(uint8_t *, unsigned int, unsigned int); static void draw_ball(uint8_t *, unsigned int, unsigned int);


void metaballs(enum action action, cucul_canvas_t *cv)
void metaballs(enum action action, caca_canvas_t *cv)
{ {
static cucul_dither_t *cucul_dither;
static caca_dither_t *caca_dither;
static uint8_t *screen; static uint8_t *screen;
static uint32_t r[256], g[256], b[256], a[256]; static uint32_t r[256], g[256], b[256], a[256];
static float dd[METABALLS], di[METABALLS], dj[METABALLS], dk[METABALLS]; static float dd[METABALLS], di[METABALLS], dj[METABALLS], dk[METABALLS];
@@ -451,13 +450,13 @@ void metaballs(enum action action, cucul_canvas_t *cv)


for(n = 0; n < METABALLS; n++) for(n = 0; n < METABALLS; n++)
{ {
dd[n] = cucul_rand(0, 100);
di[n] = (float)cucul_rand(500, 4000) / 6000.0;
dj[n] = (float)cucul_rand(500, 4000) / 6000.0;
dk[n] = (float)cucul_rand(500, 4000) / 6000.0;
dd[n] = caca_rand(0, 100);
di[n] = (float)caca_rand(500, 4000) / 6000.0;
dj[n] = (float)caca_rand(500, 4000) / 6000.0;
dk[n] = (float)caca_rand(500, 4000) / 6000.0;
} }


angleoff = cucul_rand(0, 360);
angleoff = caca_rand(0, 360);


for(n = 0; n < 360 + 80; n++) for(n = 0; n < 360 + 80; n++)
offset[n] = 1.0 + sin((double)(n * M_PI / 60)); offset[n] = 1.0 + sin((double)(n * M_PI / 60));
@@ -465,9 +464,9 @@ void metaballs(enum action action, cucul_canvas_t *cv)


case INIT: case INIT:
screen = malloc(XSIZ * YSIZ * sizeof(uint8_t)); screen = malloc(XSIZ * YSIZ * sizeof(uint8_t));
/* Create a libcucul dither smaller than our pixel buffer, so that we
/* Create a libcaca dither smaller than our pixel buffer, so that we
* display only the interesting part of it */ * display only the interesting part of it */
cucul_dither = cucul_create_dither(8, XSIZ - METASIZE, YSIZ - METASIZE,
caca_dither = caca_create_dither(8, XSIZ - METASIZE, YSIZ - METASIZE,
XSIZ, 0, 0, 0, 0); XSIZ, 0, 0, 0, 0);
break; break;


@@ -492,7 +491,7 @@ void metaballs(enum action action, cucul_canvas_t *cv)
} }


/* Set the palette */ /* Set the palette */
cucul_set_dither_palette(cucul_dither, r, g, b, a);
caca_set_dither_palette(caca_dither, r, g, b, a);


/* Silly paths for our balls */ /* Silly paths for our balls */
for(n = 0; n < METABALLS; n++) for(n = 0; n < METABALLS; n++)
@@ -516,15 +515,15 @@ void metaballs(enum action action, cucul_canvas_t *cv)
break; break;


case RENDER: case RENDER:
cucul_dither_bitmap(cv, 0, 0,
cucul_get_canvas_width(cv),
cucul_get_canvas_height(cv),
cucul_dither, screen + (METASIZE / 2) * (1 + XSIZ));
caca_dither_bitmap(cv, 0, 0,
caca_get_canvas_width(cv),
caca_get_canvas_height(cv),
caca_dither, screen + (METASIZE / 2) * (1 + XSIZ));
break; break;


case FREE: case FREE:
free(screen); free(screen);
cucul_free_dither(cucul_dither);
caca_free_dither(caca_dither);
break; break;
} }
} }
@@ -576,9 +575,9 @@ static uint8_t disc[DISCSIZ * DISCSIZ];
static void put_disc(uint8_t *, int, int); static void put_disc(uint8_t *, int, int);
static void draw_line(int, int, char); static void draw_line(int, int, char);


void moire(enum action action, cucul_canvas_t *cv)
void moire(enum action action, caca_canvas_t *cv)
{ {
static cucul_dither_t *dither;
static caca_dither_t *dither;
static uint8_t *screen; static uint8_t *screen;
static float d[6]; static float d[6];
static uint32_t red[256], green[256], blue[256], alpha[256]; static uint32_t red[256], green[256], blue[256], alpha[256];
@@ -593,7 +592,7 @@ void moire(enum action action, cucul_canvas_t *cv)
red[i] = green[i] = blue[i] = alpha[i] = 0; red[i] = green[i] = blue[i] = alpha[i] = 0;


for(i = 0; i < 6; i++) for(i = 0; i < 6; i++)
d[i] = ((float)cucul_rand(50, 70)) / 1000.0;
d[i] = ((float)caca_rand(50, 70)) / 1000.0;


red[0] = green[0] = blue[0] = 0x777; red[0] = green[0] = blue[0] = 0x777;
red[1] = green[1] = blue[1] = 0xfff; red[1] = green[1] = blue[1] = 0xfff;
@@ -616,7 +615,7 @@ void moire(enum action action, cucul_canvas_t *cv)


case INIT: case INIT:
screen = malloc(XSIZ * YSIZ * sizeof(uint8_t)); screen = malloc(XSIZ * YSIZ * sizeof(uint8_t));
dither = cucul_create_dither(8, XSIZ, YSIZ, XSIZ, 0, 0, 0, 0);
dither = caca_create_dither(8, XSIZ, YSIZ, XSIZ, 0, 0, 0, 0);
break; break;


case UPDATE: case UPDATE:
@@ -631,7 +630,7 @@ void moire(enum action action, cucul_canvas_t *cv)
green[1] = 0.5 * (1 + cos(d[4] * frame + 5.0)) * 0xfff; green[1] = 0.5 * (1 + cos(d[4] * frame + 5.0)) * 0xfff;
blue[1] = 0.5 * (1 + cos(d[5] * (frame + 4000))) * 0xfff; blue[1] = 0.5 * (1 + cos(d[5] * (frame + 4000))) * 0xfff;


cucul_set_dither_palette(dither, red, green, blue, alpha);
caca_set_dither_palette(dither, red, green, blue, alpha);


/* Draw circles */ /* Draw circles */
x = cos(d[0] * (frame + 1000)) * 128.0 + (XSIZ / 2); x = cos(d[0] * (frame + 1000)) * 128.0 + (XSIZ / 2);
@@ -644,15 +643,15 @@ void moire(enum action action, cucul_canvas_t *cv)
break; break;


case RENDER: case RENDER:
cucul_dither_bitmap(cv, 0, 0,
cucul_get_canvas_width(cv),
cucul_get_canvas_height(cv),
caca_dither_bitmap(cv, 0, 0,
caca_get_canvas_width(cv),
caca_get_canvas_height(cv),
dither, screen); dither, screen);
break; break;


case FREE: case FREE:
free(screen); free(screen);
cucul_free_dither(dither);
caca_free_dither(dither);
break; break;
} }
} }
@@ -687,7 +686,7 @@ static void draw_line(int x, int y, char color)
#define ANTS 15 #define ANTS 15
#define ITER 2 #define ITER 2


void langton(enum action action, cucul_canvas_t *cv)
void langton(enum action action, caca_canvas_t *cv)
{ {
static char gradient[] = static char gradient[] =
{ {
@@ -704,13 +703,13 @@ void langton(enum action action, cucul_canvas_t *cv)
switch(action) switch(action)
{ {
case PREPARE: case PREPARE:
width = cucul_get_canvas_width(cv);
height = cucul_get_canvas_height(cv);
width = caca_get_canvas_width(cv);
height = caca_get_canvas_height(cv);
for(i = 0; i < ANTS; i++) for(i = 0; i < ANTS; i++)
{ {
ax[i] = cucul_rand(0, width);
ay[i] = cucul_rand(0, height);
dir[i] = cucul_rand(0, 4);
ax[i] = caca_rand(0, width);
ay[i] = caca_rand(0, height);
dir[i] = caca_rand(0, 4);
} }
break; break;


@@ -757,10 +756,10 @@ void langton(enum action action, cucul_canvas_t *cv)
uint8_t p = screen[x + width * y]; uint8_t p = screen[x + width * y];


if(p & 0x0f) if(p & 0x0f)
cucul_set_color_ansi(cv, CUCUL_WHITE, p >> 4);
caca_set_color_ansi(cv, CACA_WHITE, p >> 4);
else else
cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_BLACK);
cucul_put_char(cv, x, y, gradient[p & 0x0f]);
caca_set_color_ansi(cv, CACA_BLACK, CACA_BLACK);
caca_put_char(cv, x, y, gradient[p & 0x0f]);
} }
} }
break; break;
@@ -776,7 +775,7 @@ void langton(enum action action, cucul_canvas_t *cv)
#define MINLEN 15 #define MINLEN 15
#define MAXLEN 30 #define MAXLEN 30


void matrix(enum action action, cucul_canvas_t *cv)
void matrix(enum action action, caca_canvas_t *cv)
{ {
static struct drop static struct drop
{ {
@@ -792,12 +791,12 @@ void matrix(enum action action, cucul_canvas_t *cv)
case PREPARE: case PREPARE:
for(i = 0; i < MAXDROPS; i++) for(i = 0; i < MAXDROPS; i++)
{ {
drop[i].x = cucul_rand(0, 1000);
drop[i].y = cucul_rand(0, 1000);
drop[i].speed = 5 + cucul_rand(0, 30);
drop[i].len = MINLEN + cucul_rand(0, (MAXLEN - MINLEN));
drop[i].x = caca_rand(0, 1000);
drop[i].y = caca_rand(0, 1000);
drop[i].speed = 5 + caca_rand(0, 30);
drop[i].len = MINLEN + caca_rand(0, (MAXLEN - MINLEN));
for(j = 0; j < MAXLEN; j++) for(j = 0; j < MAXLEN; j++)
drop[i].str[j] = cucul_rand('0', 'z');
drop[i].str[j] = caca_rand('0', 'z');
} }
break; break;


@@ -805,8 +804,8 @@ void matrix(enum action action, cucul_canvas_t *cv)
break; break;


case UPDATE: case UPDATE:
w = cucul_get_canvas_width(cv);
h = cucul_get_canvas_height(cv);
w = caca_get_canvas_width(cv);
h = caca_get_canvas_height(cv);


for(i = 0; i < MAXDROPS && i < (w * h / 32); i++) for(i = 0; i < MAXDROPS && i < (w * h / 32); i++)
{ {
@@ -814,17 +813,17 @@ void matrix(enum action action, cucul_canvas_t *cv)
if(drop[i].y > 1000) if(drop[i].y > 1000)
{ {
drop[i].y -= 1000; drop[i].y -= 1000;
drop[i].x = cucul_rand(0, 1000);
drop[i].x = caca_rand(0, 1000);
} }
} }
break; break;


case RENDER: case RENDER:
w = cucul_get_canvas_width(cv);
h = cucul_get_canvas_height(cv);
w = caca_get_canvas_width(cv);
h = caca_get_canvas_height(cv);


cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_BLACK);
cucul_clear_canvas(cv);
caca_set_color_ansi(cv, CACA_BLACK, CACA_BLACK);
caca_clear_canvas(cv);


for(i = 0; i < MAXDROPS && i < (w * h / 32); i++) for(i = 0; i < MAXDROPS && i < (w * h / 32); i++)
{ {
@@ -838,16 +837,16 @@ void matrix(enum action action, cucul_canvas_t *cv)
unsigned int fg; unsigned int fg;


if(j < 2) if(j < 2)
fg = CUCUL_WHITE;
fg = CACA_WHITE;
else if(j < drop[i].len / 4) else if(j < drop[i].len / 4)
fg = CUCUL_LIGHTGREEN;
fg = CACA_LIGHTGREEN;
else if(j < drop[i].len * 4 / 5) else if(j < drop[i].len * 4 / 5)
fg = CUCUL_GREEN;
fg = CACA_GREEN;
else else
fg = CUCUL_DARKGRAY;
cucul_set_color_ansi(cv, fg, CUCUL_BLACK);
fg = CACA_DARKGRAY;
caca_set_color_ansi(cv, fg, CACA_BLACK);


cucul_put_char(cv, x, y - j,
caca_put_char(cv, x, y - j,
drop[i].str[(y - j) % drop[i].len]); drop[i].str[(y - j) % drop[i].len]);
} }
} }
@@ -871,13 +870,13 @@ void matrix(enum action action, cucul_canvas_t *cv)


#include "texture.h" #include "texture.h"


void rotozoom(enum action action, cucul_canvas_t *canvas)
void rotozoom(enum action action, caca_canvas_t *canvas)
{ {
static uint32_t screen[XSIZ * YSIZ]; static uint32_t screen[XSIZ * YSIZ];
static int cos_tab[TABLE_SIZE], sin_tab[TABLE_SIZE]; static int cos_tab[TABLE_SIZE], sin_tab[TABLE_SIZE];
static int y_tab[TEXTURE_SIZE]; static int y_tab[TEXTURE_SIZE];


static cucul_dither_t *dither;
static caca_dither_t *dither;
static uint32_t *texture; static uint32_t *texture;
uint32_t *p; uint32_t *p;
static int alphaF, tF; static int alphaF, tF;
@@ -903,7 +902,7 @@ void rotozoom(enum action action, cucul_canvas_t *canvas)
break; break;


case INIT: case INIT:
dither = cucul_create_dither(32, XSIZ, YSIZ, XSIZ * 4,
dither = caca_create_dither(32, XSIZ, YSIZ, XSIZ * 4,
0x00FF0000, 0x00FF0000,
0x0000FF00, 0x0000FF00,
0x000000FF, 0x000000FF,
@@ -941,14 +940,14 @@ void rotozoom(enum action action, cucul_canvas_t *canvas)
break; break;


case RENDER: case RENDER:
cucul_dither_bitmap(canvas, 0, 0,
cucul_get_canvas_width(canvas),
cucul_get_canvas_height(canvas),
caca_dither_bitmap(canvas, 0, 0,
caca_get_canvas_width(canvas),
caca_get_canvas_height(canvas),
dither, screen); dither, screen);
break; break;


case FREE: case FREE:
cucul_free_dither(dither);
caca_free_dither(dither);
break; break;
} }
} }


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save