Bläddra i källkod

Port toilet to the unified libcaca 0.99.beta15 API.

pull/1/head
Sam Hocevar sam 16 år sedan
förälder
incheckning
0b8e189863
12 ändrade filer med 104 tillägg och 104 borttagningar
  1. +2
    -2
      configure.ac
  2. +1
    -1
      doc/toilet.1.in
  3. +2
    -2
      src/Makefile.am
  4. +3
    -3
      src/export.c
  5. +6
    -6
      src/figlet.c
  6. +24
    -24
      src/filter.c
  7. +1
    -1
      src/main.c
  8. +22
    -22
      src/render.c
  9. +6
    -6
      src/term.c
  10. +3
    -3
      src/toilet.h
  11. +2
    -2
      tools/Makefile.am
  12. +32
    -32
      tools/caca2tlf.c

+ 2
- 2
configure.ac Visa fil

@@ -51,10 +51,10 @@ if test "${ac_cv_have_tiocgwinsz}" = "yes"; then
fi

CUCUL="no"
PKG_CHECK_MODULES(CUCUL, cucul >= 0.99.beta14,
PKG_CHECK_MODULES(CACA, caca >= 0.99.beta15,
[CUCUL="yes"],
[AC_MSG_RESULT(no)
AC_MSG_ERROR([you need libcucul version 0.99.beta14 or later])])
AC_MSG_ERROR([you need libcaca version 0.99.beta15 or later])])

AC_MSG_CHECKING([for release date])
stamp="$(sed -ne 's/# \$Id: .*\(....-..-..\).*/\1/p;q' configure.ac)"


+ 1
- 1
doc/toilet.1.in Visa fil

@@ -122,7 +122,7 @@ Specify the output format. By default,
will output UTF-8 text using ANSI colour codes suitable for most terminals
such as XTerm or rxvt.
.I <format>
is the name of the export format as recognised by libcucul. The special
is the name of the export format as recognised by libcaca. The special
argument
.I list
outputs a list of available export formats.


+ 2
- 2
src/Makefile.am Visa fil

@@ -7,6 +7,6 @@ toilet_SOURCES = main.c toilet.h \
export.c export.h \
term.c figlet.c
toilet_CPPFLAGS = -DFONTDIR=\"$(datadir)/figlet\"
toilet_CFLAGS = @CUCUL_CFLAGS@
toilet_LDADD = @CUCUL_LIBS@ @GETOPT_LIBS@ @ZLIB_LIBS@
toilet_CFLAGS = @CACA_CFLAGS@
toilet_LDADD = @CACA_LIBS@ @GETOPT_LIBS@ @ZLIB_LIBS@


+ 3
- 3
src/export.c Visa fil

@@ -24,7 +24,7 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <cucul.h>
#include <caca.h>

#include "toilet.h"
#include "export.h"
@@ -35,7 +35,7 @@ int export_list(void)

printf("Available export formats:\n");

exports = cucul_get_export_list();
exports = caca_get_export_list();
for(p = exports; *p; p += 2)
printf("\"%s\": %s\n", *p, *(p + 1));

@@ -48,7 +48,7 @@ int export_set(context_t *cx, char const *format)

cx->export = format;

exports = cucul_get_export_list();
exports = caca_get_export_list();
for(p = exports; *p; p += 2)
if(!strcmp(*p, format))
return 0;


+ 6
- 6
src/figlet.c Visa fil

@@ -24,7 +24,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cucul.h>
#include <caca.h>

#include "toilet.h"
#include "render.h"
@@ -41,7 +41,7 @@ int init_figlet(context_t *cx)
char path[2048];

snprintf(path, 2047, "%s/%s", cx->dir, cx->font);
if(cucul_canvas_set_figfont(cx->cv, path))
if(caca_canvas_set_figfont(cx->cv, path))
return -1;

cx->feed = feed_figlet;
@@ -53,19 +53,19 @@ int init_figlet(context_t *cx)

static int feed_figlet(context_t *cx, uint32_t ch, uint32_t attr)
{
return cucul_put_figchar(cx->cv, ch);
return caca_put_figchar(cx->cv, ch);
}

static int flush_figlet(context_t *cx)
{
int ret = cucul_flush_figlet(cx->cv);
int ret = caca_flush_figlet(cx->cv);
cx->torender = cx->cv;
cx->cv = cucul_create_canvas(0, 0);
cx->cv = caca_create_canvas(0, 0);
return ret;
}

static int end_figlet(context_t *cx)
{
return cucul_canvas_set_figfont(cx->cv, NULL);
return caca_canvas_set_figfont(cx->cv, NULL);
}


+ 24
- 24
src/filter.c Visa fil

@@ -24,7 +24,7 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <cucul.h>
#include <caca.h>

#include "toilet.h"
#include "filter.h"
@@ -129,15 +129,15 @@ static void filter_crop(context_t *cx)
unsigned int x, y, w, h;
unsigned int xmin, xmax, ymin, ymax;

xmin = w = cucul_get_canvas_width(cx->torender);
xmin = w = caca_get_canvas_width(cx->torender);
xmax = 0;
ymin = h = cucul_get_canvas_height(cx->torender);
ymin = h = caca_get_canvas_height(cx->torender);
ymax = 0;

for(y = 0; y < h; y++)
for(x = 0; x < w; x++)
{
unsigned long int ch = cucul_get_char(cx->torender, x, y);
unsigned long int ch = caca_get_char(cx->torender, x, y);
if(ch != (unsigned char)' ')
{
if(x < xmin)
@@ -154,7 +154,7 @@ static void filter_crop(context_t *cx)
if(xmax < xmin || ymax < ymin)
return;

cucul_set_canvas_boundaries(cx->torender, xmin, ymin,
caca_set_canvas_boundaries(cx->torender, xmin, ymin,
xmax - xmin + 1, ymax - ymin + 1);
}

@@ -162,26 +162,26 @@ static void filter_metal(context_t *cx)
{
static unsigned char const palette[] =
{
CUCUL_LIGHTBLUE, CUCUL_BLUE, CUCUL_LIGHTGRAY, CUCUL_DARKGRAY,
CACA_LIGHTBLUE, CACA_BLUE, CACA_LIGHTGRAY, CACA_DARKGRAY,
};

unsigned int x, y, w, h;

w = cucul_get_canvas_width(cx->torender);
h = cucul_get_canvas_height(cx->torender);
w = caca_get_canvas_width(cx->torender);
h = caca_get_canvas_height(cx->torender);

for(y = 0; y < h; y++)
for(x = 0; x < w; x++)
{
unsigned long int ch = cucul_get_char(cx->torender, x, y);
unsigned long int ch = caca_get_char(cx->torender, x, y);
int i;

if(ch == (unsigned char)' ')
continue;

i = ((cx->lines + y + x / 8) / 2) % 4;
cucul_set_color_ansi(cx->torender, palette[i], CUCUL_TRANSPARENT);
cucul_put_char(cx->torender, x, y, ch);
caca_set_color_ansi(cx->torender, palette[i], CACA_TRANSPARENT);
caca_put_char(cx->torender, x, y, ch);
}
}

@@ -189,50 +189,50 @@ static void filter_gay(context_t *cx)
{
static unsigned char const rainbow[] =
{
CUCUL_LIGHTMAGENTA, CUCUL_LIGHTRED, CUCUL_YELLOW,
CUCUL_LIGHTGREEN, CUCUL_LIGHTCYAN, CUCUL_LIGHTBLUE,
CACA_LIGHTMAGENTA, CACA_LIGHTRED, CACA_YELLOW,
CACA_LIGHTGREEN, CACA_LIGHTCYAN, CACA_LIGHTBLUE,
};
unsigned int x, y, w, h;

w = cucul_get_canvas_width(cx->torender);
h = cucul_get_canvas_height(cx->torender);
w = caca_get_canvas_width(cx->torender);
h = caca_get_canvas_height(cx->torender);

for(y = 0; y < h; y++)
for(x = 0; x < w; x++)
{
unsigned long int ch = cucul_get_char(cx->torender, x, y);
unsigned long int ch = caca_get_char(cx->torender, x, y);
if(ch != (unsigned char)' ')
{
cucul_set_color_ansi(cx->torender,
caca_set_color_ansi(cx->torender,
rainbow[(x / 2 + y + cx->lines) % 6],
CUCUL_TRANSPARENT);
cucul_put_char(cx->torender, x, y, ch);
CACA_TRANSPARENT);
caca_put_char(cx->torender, x, y, ch);
}
}
}

static void filter_flip(context_t *cx)
{
cucul_flip(cx->torender);
caca_flip(cx->torender);
}

static void filter_flop(context_t *cx)
{
cucul_flop(cx->torender);
caca_flop(cx->torender);
}

static void filter_180(context_t *cx)
{
cucul_rotate_180(cx->torender);
caca_rotate_180(cx->torender);
}

static void filter_left(context_t *cx)
{
cucul_rotate_left(cx->torender);
caca_rotate_left(cx->torender);
}

static void filter_right(context_t *cx)
{
cucul_rotate_right(cx->torender);
caca_rotate_right(cx->torender);
}


+ 1
- 1
src/main.c Visa fil

@@ -30,7 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cucul.h>
#include <caca.h>

#include "toilet.h"
#include "render.h"


+ 22
- 22
src/render.c Visa fil

@@ -24,7 +24,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <cucul.h>
#include <caca.h>

#include "toilet.h"
#include "render.h"
@@ -37,7 +37,7 @@ int render_init(context_t *cx)
cx->x = cx->y = 0;
cx->w = cx->h = 0;
cx->lines = 0;
cx->cv = cucul_create_canvas(0, 0);
cx->cv = caca_create_canvas(0, 0);

if(!strcasecmp(cx->font, "term"))
return init_tiny(cx);
@@ -47,14 +47,14 @@ int render_init(context_t *cx)

int render_stdin(context_t *cx)
{
cucul_canvas_t *cv;
caca_canvas_t *cv;
char *line;
int i, len;

/* FIXME: we can't read longer lines */
len = 1024;
line = malloc(len);
cv = cucul_create_canvas(0, 0);
cv = caca_create_canvas(0, 0);

/* Read from stdin */
while(!feof(stdin))
@@ -62,14 +62,14 @@ int render_stdin(context_t *cx)
if(!fgets(line, len, stdin))
break;

cucul_set_canvas_size(cv, 0, 0);
cucul_import_memory(cv, line, strlen(line), "utf8");
for(i = 0; i < cucul_get_canvas_width(cv); i++)
caca_set_canvas_size(cv, 0, 0);
caca_import_memory(cv, line, strlen(line), "utf8");
for(i = 0; i < caca_get_canvas_width(cv); i++)
{
uint32_t ch = cucul_get_char(cv, i, 0);
uint32_t at = cucul_get_attr(cv, i, 0);
uint32_t ch = caca_get_char(cv, i, 0);
uint32_t at = caca_get_attr(cv, i, 0);
cx->feed(cx, ch, at);
if(cucul_utf32_is_fullwidth(ch)) i++;
if(caca_utf32_is_fullwidth(ch)) i++;
}

render_flush(cx);
@@ -82,11 +82,11 @@ int render_stdin(context_t *cx)

int render_list(context_t *cx, int argc, char *argv[])
{
cucul_canvas_t *cv;
caca_canvas_t *cv;
int i, j, len;
char *parser = NULL;

cv = cucul_create_canvas(0, 0);
cv = caca_create_canvas(0, 0);

for(j = 0; j < argc; )
{
@@ -105,14 +105,14 @@ int render_list(context_t *cx, int argc, char *argv[])
else
len = strlen(parser);

cucul_set_canvas_size(cv, 0, 0);
cucul_import_memory(cv, parser, len, "utf8");
for(i = 0; i < cucul_get_canvas_width(cv); i++)
caca_set_canvas_size(cv, 0, 0);
caca_import_memory(cv, parser, len, "utf8");
for(i = 0; i < caca_get_canvas_width(cv); i++)
{
uint32_t ch = cucul_get_char(cv, i, 0);
uint32_t at = cucul_get_attr(cv, i, 0);
uint32_t ch = caca_get_char(cv, i, 0);
uint32_t at = caca_get_attr(cv, i, 0);
cx->feed(cx, ch, at);
if(cucul_utf32_is_fullwidth(ch)) i++;
if(caca_utf32_is_fullwidth(ch)) i++;
}

if(cr)
@@ -129,7 +129,7 @@ int render_list(context_t *cx, int argc, char *argv[])

render_flush(cx);

cucul_free_canvas(cv);
caca_free_canvas(cv);

return 0;
}
@@ -137,7 +137,7 @@ int render_list(context_t *cx, int argc, char *argv[])
int render_end(context_t *cx)
{
cx->end(cx);
cucul_free_canvas(cx->cv);
caca_free_canvas(cx->cv);

return 0;
}
@@ -156,12 +156,12 @@ static int render_flush(context_t *cx)
filter_do(cx);

/* Output line */
buffer = cucul_export_memory(cx->torender, cx->export, &len);
buffer = caca_export_memory(cx->torender, cx->export, &len);
if(!buffer)
return -1;
fwrite(buffer, len, 1, stdout);
free(buffer);
cucul_free_canvas(cx->torender);
caca_free_canvas(cx->torender);

return 0;
}


+ 6
- 6
src/term.c Visa fil

@@ -22,7 +22,7 @@
# include <inttypes.h>
#endif
#include <stdlib.h>
#include <cucul.h>
#include <caca.h>

#include "toilet.h"
#include "render.h"
@@ -80,10 +80,10 @@ static int feed_tiny(context_t *cx, uint32_t ch, uint32_t attr)
cx->eh = cx->eh + cx->eh / 2;
}

cucul_set_attr(cx->cv, attr);
cucul_set_canvas_size(cx->cv, cx->ew, cx->eh);
caca_set_attr(cx->cv, attr);
caca_set_canvas_size(cx->cv, cx->ew, cx->eh);

cucul_put_char(cx->cv, cx->x, cx->y, ch);
caca_put_char(cx->cv, cx->x, cx->y, ch);
cx->x++;

return 0;
@@ -92,13 +92,13 @@ static int feed_tiny(context_t *cx, uint32_t ch, uint32_t attr)
static int flush_tiny(context_t *cx)
{
cx->torender = cx->cv;
cucul_set_canvas_size(cx->torender, cx->w, cx->h);
caca_set_canvas_size(cx->torender, cx->w, cx->h);

cx->ew = 16;
cx->eh = 2;
cx->x = cx->y = 0;
cx->w = cx->h = 0;
cx->cv = cucul_create_canvas(cx->ew, cx->eh);
cx->cv = caca_create_canvas(cx->ew, cx->eh);

return 0;
}


+ 3
- 3
src/toilet.h Visa fil

@@ -24,8 +24,8 @@ struct toilet_context

unsigned int term_width;

cucul_canvas_t *cv;
cucul_canvas_t *torender;
caca_canvas_t *cv;
caca_canvas_t *torender;
unsigned int w, h, ew, eh, x, y, lines;

/* Render methods */
@@ -41,7 +41,7 @@ struct toilet_context
int old_layout;
unsigned int print_direction, full_layout, codetag_count;
unsigned int glyphs;
cucul_canvas_t *fontcv, *charcv;
caca_canvas_t *fontcv, *charcv;
int *left, *right; /* Unused yet */
unsigned int *lookup;



+ 2
- 2
tools/Makefile.am Visa fil

@@ -3,6 +3,6 @@
noinst_PROGRAMS = caca2tlf

caca2tlf_SOURCES = caca2tlf.c
caca2tlf_CFLAGS = @CUCUL_CFLAGS@
caca2tlf_LDADD = @CUCUL_LIBS@
caca2tlf_CFLAGS = @CACA_CFLAGS@
caca2tlf_LDADD = @CACA_LIBS@


+ 32
- 32
tools/caca2tlf.c Visa fil

@@ -24,15 +24,15 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <cucul.h>
#include <caca.h>

enum mode { GRAY, HALFBLOCKS, QUARTERBLOCKS } mode;

static void list_fonts(void);
static void add_char(unsigned long int);

cucul_font_t *f;
cucul_canvas_t *out, *onechar;
caca_font_t *f;
caca_canvas_t *out, *onechar;
uint32_t const *blocks;
uint8_t * image;
unsigned int w, h, gw, fgw, gh, iw, ih;
@@ -68,7 +68,7 @@ int main(int argc, char *argv[])
fontname = argv[1];
}

f = cucul_load_font(fontname, 0);
f = caca_load_font(fontname, 0);

if(!f)
{
@@ -77,8 +77,8 @@ int main(int argc, char *argv[])
return -2;
}

w = cucul_get_font_width(f);
h = cucul_get_font_height(f);
w = caca_get_font_width(f);
h = caca_get_font_height(f);
iw = w * 2 + 1;
ih = h + 1;
switch(mode)
@@ -100,12 +100,12 @@ int main(int argc, char *argv[])
break;
}

blocks = cucul_get_font_blocks(f);
onechar = cucul_create_canvas(0, 0);
cucul_set_color_ansi(onechar, CUCUL_WHITE, CUCUL_BLACK);
blocks = caca_get_font_blocks(f);
onechar = caca_create_canvas(0, 0);
caca_set_color_ansi(onechar, CACA_WHITE, CACA_BLACK);
image = malloc(4 * iw * ih);

out = cucul_create_canvas(0, 0);
out = caca_create_canvas(0, 0);
printf("tlf2a$ %u %u %u -1 4 0 0 0\n", gh, gh - 1, fgw + 2);

printf("=============================================="
@@ -140,17 +140,17 @@ int main(int argc, char *argv[])
|| ch == 228 || ch == 246 || ch == 252 || ch == 223)
continue;

len = cucul_utf32_to_utf8(buf, ch);
len = caca_utf32_to_utf8(buf, ch);
buf[len] = '\0';
printf("0x%.04lX %s\n", ch, buf);
add_char(ch);
}
}

cucul_free_canvas(out);
cucul_free_canvas(onechar);
caca_free_canvas(out);
caca_free_canvas(onechar);
free(image);
cucul_free_font(f);
caca_free_font(f);

return 0;
}
@@ -162,7 +162,7 @@ static void list_fonts(void)

fprintf(stderr, "Available fonts:\n");

fonts = cucul_get_font_list();
fonts = caca_get_font_list();
for(i = 0; fonts[i]; i++)
fprintf(stderr, " \"%s\"\n", fonts[i]);
}
@@ -172,16 +172,16 @@ static void add_char(unsigned long int ch)
void *buf;
unsigned long int len;
unsigned int x, y, myw, mygw;
int full = cucul_utf32_is_fullwidth(ch);
int full = caca_utf32_is_fullwidth(ch);

cucul_set_canvas_size(onechar, full ? 2 : 1, 1);
cucul_put_char(onechar, 0, 0, ch);
cucul_render_canvas(onechar, f, image, iw, ih, 4 * iw);
caca_set_canvas_size(onechar, full ? 2 : 1, 1);
caca_put_char(onechar, 0, 0, ch);
caca_render_canvas(onechar, f, image, iw, ih, 4 * iw);

myw = full ? 2 * w : w;
mygw = full ? fgw : gw;

cucul_set_canvas_size(out, (full ? fgw : gw) + 2, gh);
caca_set_canvas_size(out, (full ? fgw : gw) + 2, gh);

switch(mode)
{
@@ -192,15 +192,15 @@ static void add_char(unsigned long int ch)
uint8_t c = image[4 * (x + y * iw) + 2];

if(c >= 0xa0)
cucul_put_str(out, x, y, "█");
caca_put_str(out, x, y, "█");
else if(c >= 0x80)
cucul_put_str(out, x, y, "▓");
caca_put_str(out, x, y, "▓");
else if(c >= 0x40)
cucul_put_str(out, x, y, "▒");
caca_put_str(out, x, y, "▒");
else if(c >= 0x20)
cucul_put_str(out, x, y, "░");
caca_put_str(out, x, y, "░");
else
cucul_put_char(out, x, y, ' ');
caca_put_char(out, x, y, ' ');
}
break;
case HALFBLOCKS:
@@ -212,7 +212,7 @@ static void add_char(unsigned long int ch)
uint8_t p1 = image[4 * (x + y * 2 * iw) + 2];
uint8_t p2 = image[4 * (x + (y * 2 + 1) * iw) + 2];

cucul_put_str(out, x, y, str[(p1 > 0x80) + 2 * (p2 > 0x80)]);
caca_put_str(out, x, y, str[(p1 > 0x80) + 2 * (p2 > 0x80)]);
}
break;
case QUARTERBLOCKS:
@@ -230,7 +230,7 @@ static void add_char(unsigned long int ch)
uint8_t p3 = image[4 * (x * 2 + (y * 2 + 1) * iw) + 2];
uint8_t p4 = image[4 * (x * 2 + 1 + (y * 2 + 1) * iw) + 2];

cucul_put_str(out, x, y, str[(p1 > 0x80) + 2 * (p2 > 0x80) +
caca_put_str(out, x, y, str[(p1 > 0x80) + 2 * (p2 > 0x80) +
4 * (p3 > 0x80) + 8 * (p4 > 0x80)]);
}
break;
@@ -238,14 +238,14 @@ static void add_char(unsigned long int ch)

if(ch == ' ' || ch == 0xa0)
{
cucul_draw_line(out, mygw - 1, 0, mygw - 1, gh - 1, '$');
cucul_draw_line(out, mygw / 2, 0, mygw / 2, gh - 1, '$');
caca_draw_line(out, mygw - 1, 0, mygw - 1, gh - 1, '$');
caca_draw_line(out, mygw / 2, 0, mygw / 2, gh - 1, '$');
}

cucul_draw_line(out, mygw, 0, mygw, gh - 1, '@');
cucul_put_char(out, mygw + 1, gh - 1, '@');
caca_draw_line(out, mygw, 0, mygw, gh - 1, '@');
caca_put_char(out, mygw + 1, gh - 1, '@');

buf = cucul_export_memory(out, "utf8", &len);
buf = caca_export_memory(out, "utf8", &len);
fwrite(buf, len, 1, stdout);
free(buf);
}


Laddar…
Avbryt
Spara