Browse Source

* Now that libcaca 0.99.beta10 is out, we can switch to the new API.

pull/1/head
Sam Hocevar sam 18 years ago
parent
commit
981e398b67
7 changed files with 38 additions and 46 deletions
  1. +2
    -2
      configure.ac
  2. +1
    -1
      doc/Makefile.am
  3. +9
    -18
      src/figlet.c
  4. +5
    -5
      src/filter.c
  5. +5
    -5
      src/render.c
  6. +1
    -1
      src/term.c
  7. +15
    -14
      tools/caca2tlf.c

+ 2
- 2
configure.ac View File

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


CUCUL="no" CUCUL="no"
PKG_CHECK_MODULES(cucul, cucul >= 0.99.beta9,
PKG_CHECK_MODULES(cucul, cucul >= 0.99.beta10,
[CUCUL="yes"], [CUCUL="yes"],
[AC_MSG_RESULT(no) [AC_MSG_RESULT(no)
AC_MSG_ERROR([you need libcucul version 0.99.beta9 or later])])
AC_MSG_ERROR([you need libcucul version 0.99.beta10 or later])])


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


+ 1
- 1
doc/Makefile.am View File

@@ -6,5 +6,5 @@ CLEANFILES = toilet.1
man_MANS = toilet.1 man_MANS = toilet.1


toilet.1: toilet.1.in toilet.1: toilet.1.in
sed -e "s,@data""rootdir@,$(datarootdir),g" $(srcdir)/$^ > $@
sed -e "s,[@]datarootdir@,$(datarootdir),g" $(srcdir)/$^ > $@



+ 9
- 18
src/figlet.c View File

@@ -96,8 +96,8 @@ static int feed_figlet(context_t *cx, uint32_t ch)
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 tmp = cucul_getchar(cx->image, x, y + c * cx->height);
cucul_putchar(cx->cv, cx->x + x, cx->y + y, tmp);
uint32_t tmp = cucul_get_char(cx->image, x, y + c * cx->height);
cucul_put_char(cx->cv, cx->x + x, cx->y + y, tmp);
} }


/* Advance cursor */ /* Advance cursor */
@@ -132,7 +132,6 @@ static int open_font(context_t *cx)
char path[2048]; char path[2048];
char buf[2048]; char buf[2048];
char hardblank[10]; char hardblank[10];
cucul_buffer_t *b;
TOIFILE *f; TOIFILE *f;
unsigned int i, j, size, comment_lines; unsigned int i, j, size, comment_lines;


@@ -249,18 +248,10 @@ static int open_font(context_t *cx)
} }


/* Import buffer into canvas */ /* Import buffer into canvas */
b = cucul_load_memory(data, i);
cx->image = cucul_import_canvas(b, "utf8");
cucul_free_buffer(b);
cx->image = cucul_create_canvas(0, 0);
cucul_import_memory(cx->image, data, i, "utf8");
free(data); free(data);


if(!cx->image)
{
free(cx->lookup);
fprintf(stderr, "libcucul could not load data in `%s'\n", path);
return -1;
}

/* Remove EOL characters. For now we ignore hardblanks, don’t do any /* Remove EOL characters. For now we ignore hardblanks, don’t do any
* smushing, nor any kind of error checking. */ * smushing, nor any kind of error checking. */
for(j = 0; j < cx->height * cx->glyphs; j++) for(j = 0; j < cx->height * cx->glyphs; j++)
@@ -269,12 +260,12 @@ static int open_font(context_t *cx)


for(i = cx->max_length; i--;) for(i = cx->max_length; i--;)
{ {
ch = cucul_getchar(cx->image, i, j);
ch = cucul_get_char(cx->image, i, j);


/* TODO: Replace hardblanks with U+00A0 NO-BREAK SPACE */ /* TODO: Replace hardblanks with U+00A0 NO-BREAK SPACE */
if(ch == cx->hardblank) if(ch == cx->hardblank)
cucul_putchar(cx->image, i, j, ch = ' ');
//cucul_putchar(cx->image, i, j, ch = 0xa0);
cucul_put_char(cx->image, i, j, ch = ' ');
//cucul_put_char(cx->image, i, j, ch = 0xa0);


if(oldch && ch != oldch) if(oldch && ch != oldch)
{ {
@@ -282,11 +273,11 @@ static int open_font(context_t *cx)
cx->lookup[j / cx->height * 2 + 1] = i + 1; cx->lookup[j / cx->height * 2 + 1] = i + 1;
} }
else if(oldch && ch == oldch) else if(oldch && ch == oldch)
cucul_putchar(cx->image, i, j, ' ');
cucul_put_char(cx->image, i, j, ' ');
else if(ch != ' ') else if(ch != ' ')
{ {
oldch = ch; oldch = ch;
cucul_putchar(cx->image, i, j, ' ');
cucul_put_char(cx->image, i, j, ' ');
} }
} }
} }


+ 5
- 5
src/filter.c View File

@@ -130,7 +130,7 @@ static void filter_crop(context_t *cx)
for(y = 0; y < h; y++) for(y = 0; y < h; y++)
for(x = 0; x < w; x++) for(x = 0; x < w; x++)
{ {
unsigned long int ch = cucul_getchar(cx->torender, x, y);
unsigned long int ch = cucul_get_char(cx->torender, x, y);
if(ch != (unsigned char)' ') if(ch != (unsigned char)' ')
{ {
if(x < xmin) if(x < xmin)
@@ -166,7 +166,7 @@ static void filter_metal(context_t *cx)
for(y = 0; y < h; y++) for(y = 0; y < h; y++)
for(x = 0; x < w; x++) for(x = 0; x < w; x++)
{ {
unsigned long int ch = cucul_getchar(cx->torender, x, y);
unsigned long int ch = cucul_get_char(cx->torender, x, y);
int i; int i;


if(ch == (unsigned char)' ') if(ch == (unsigned char)' ')
@@ -174,7 +174,7 @@ static void filter_metal(context_t *cx)


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


@@ -193,13 +193,13 @@ static void filter_gay(context_t *cx)
for(y = 0; y < h; y++) for(y = 0; y < h; y++)
for(x = 0; x < w; x++) for(x = 0; x < w; x++)
{ {
unsigned long int ch = cucul_getchar(cx->torender, x, y);
unsigned long int ch = cucul_get_char(cx->torender, x, y);
if(ch != (unsigned char)' ') if(ch != (unsigned char)' ')
{ {
cucul_set_color_ansi(cx->torender, cucul_set_color_ansi(cx->torender,
rainbow[(x / 2 + y + cx->lines) % 6], rainbow[(x / 2 + y + cx->lines) % 6],
CUCUL_TRANSPARENT); CUCUL_TRANSPARENT);
cucul_putchar(cx->torender, x, y, ch);
cucul_put_char(cx->torender, x, y, ch);
} }
} }
} }


+ 5
- 5
src/render.c View File

@@ -107,7 +107,8 @@ int render_end(context_t *cx)


static int render_flush(context_t *cx) static int render_flush(context_t *cx)
{ {
cucul_buffer_t *buffer;
unsigned long int len;
void *buffer;


/* Flush current line */ /* Flush current line */
cx->flush(cx); cx->flush(cx);
@@ -118,12 +119,11 @@ static int render_flush(context_t *cx)
cx->lines += cucul_get_canvas_height(cx->torender); cx->lines += cucul_get_canvas_height(cx->torender);


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


return 0; return 0;


+ 1
- 1
src/term.c View File

@@ -81,7 +81,7 @@ static int feed_tiny(context_t *cx, uint32_t ch)


cucul_set_canvas_size(cx->cv, cx->ew, cx->eh); cucul_set_canvas_size(cx->cv, cx->ew, cx->eh);


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


return 0; return 0;


+ 15
- 14
tools/caca2tlf.c View File

@@ -168,12 +168,13 @@ static void list_fonts(void)


static void add_char(unsigned long int ch) static void add_char(unsigned long int ch)
{ {
cucul_buffer_t *buf;
void *buf;
unsigned long int len;
unsigned int x, y, myw, mygw; unsigned int x, y, myw, mygw;
int full = cucul_utf32_is_fullwidth(ch); int full = cucul_utf32_is_fullwidth(ch);


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


myw = full ? 2 * w : w; myw = full ? 2 * w : w;
@@ -190,15 +191,15 @@ static void add_char(unsigned long int ch)
uint8_t c = image[4 * (x + y * iw) + 2]; uint8_t c = image[4 * (x + y * iw) + 2];


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


cucul_putstr(out, x, y, str[(p1 > 0x80) + 2 * (p2 > 0x80)]);
cucul_put_str(out, x, y, str[(p1 > 0x80) + 2 * (p2 > 0x80)]);
} }
break; break;
case QUARTERBLOCKS: case QUARTERBLOCKS:
@@ -228,17 +229,17 @@ static void add_char(unsigned long int ch)
uint8_t p3 = image[4 * (x * 2 + (y * 2 + 1) * iw) + 2]; 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]; uint8_t p4 = image[4 * (x * 2 + 1 + (y * 2 + 1) * iw) + 2];


cucul_putstr(out, x, y, str[(p1 > 0x80) + 2 * (p2 > 0x80) +
4 * (p3 > 0x80) + 8 * (p4 > 0x80)]);
cucul_put_str(out, x, y, str[(p1 > 0x80) + 2 * (p2 > 0x80) +
4 * (p3 > 0x80) + 8 * (p4 > 0x80)]);
} }
break; break;
} }


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


buf = cucul_export_canvas(out, "utf8");
fwrite(cucul_get_buffer_data(buf), cucul_get_buffer_size(buf), 1, stdout);
cucul_free_buffer(buf);
buf = cucul_export_memory(out, "utf8", &len);
fwrite(buf, len, 1, stdout);
free(buf);
} }



Loading…
Cancel
Save