From d3ef2bbecdeb5043874de3a2a8f1014a5f4754bb Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Thu, 21 May 2009 20:55:21 +0000 Subject: [PATCH] Add caca_export_area_to_memory() to export only a selected part of the current canvas. This is useful to export dirty rectangles. Accordingly, add caca_import_area_from_memory() and caca_import_area_from_file(). --- caca/caca.h | 25 ++++++++++--- caca/caca0.c | 4 +- caca/codec/export.c | 51 +++++++++++++++++++++++-- caca/codec/import.c | 89 +++++++++++++++++++++++++++++++++++++++++--- caca/driver/raw.c | 4 +- caca/figfont.c | 4 +- caca/legacy.c | 9 +++-- cxx/caca++.cpp | 12 +++--- cxx/caca++.h | 6 +-- cxx/cxxtest.cpp | 2 +- examples/blit.c | 4 +- examples/export.c | 6 +-- examples/figfont.c | 4 +- examples/font2tga.c | 4 +- examples/import.c | 2 +- examples/spritedit.c | 10 ++--- examples/swallow.c | 5 ++- examples/text.c | 8 ++-- examples/transform.c | 6 +-- ruby/caca-canvas.c | 25 ++++++------- src/cacadraw.c | 4 +- src/cacaplay.c | 4 +- src/cacaserver.c | 15 ++++---- src/img2txt.c | 6 +-- 24 files changed, 224 insertions(+), 85 deletions(-) diff --git a/caca/caca.h b/caca/caca.h index e7ba1a2..82963f9 100644 --- a/caca/caca.h +++ b/caca/caca.h @@ -425,13 +425,20 @@ __extern int caca_file_eof(caca_file_t *); * 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 ssize_t caca_import_canvas_from_memory(caca_canvas_t *, void const *, + size_t, char const *); +__extern ssize_t caca_import_canvas_from_file(caca_canvas_t *, char const *, + char const *); +__extern ssize_t caca_import_area_from_memory(caca_canvas_t *, int, int, + void const *, size_t, + char const *); +__extern ssize_t caca_import_area_from_file(caca_canvas_t *, int, int, + 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 void *caca_export_canvas_to_memory(caca_canvas_t const *, + char const *, size_t *); +__extern void *caca_export_area_to_memory(caca_canvas_t const *, int, int, + int, int, char const *, size_t *); __extern char const * const * caca_get_export_list(void); /* @} */ @@ -522,6 +529,12 @@ __extern cucul_buffer_t * cucul_export_canvas(caca_canvas_t *, char const *) CACA_DEPRECATED; __extern caca_canvas_t * cucul_import_canvas(cucul_buffer_t *, char const *) CACA_DEPRECATED; +__extern ssize_t caca_import_memory(caca_canvas_t *, void const *, size_t, + char const *) CACA_DEPRECATED; +__extern ssize_t caca_import_file(caca_canvas_t *, char const *, + char const *) CACA_DEPRECATED; +__extern void *caca_export_memory(caca_canvas_t const *, char const *, + size_t *) CACA_DEPRECATED; __extern int cucul_rotate(caca_canvas_t *) CACA_DEPRECATED; __extern int cucul_set_dither_invert(caca_dither_t *, int) CACA_DEPRECATED; __extern int cucul_set_dither_mode(caca_dither_t *, diff --git a/caca/caca0.c b/caca/caca0.c index 083d945..107021d 100644 --- a/caca/caca0.c +++ b/caca/caca0.c @@ -1,6 +1,6 @@ /* * libcaca Colour ASCII-Art library - * Copyright (c) 2002-2006 Sam Hocevar + * Copyright (c) 2002-2009 Sam Hocevar * All Rights Reserved * * $Id$ @@ -215,7 +215,7 @@ caca_canvas_t *__caca0_load_sprite(char const *file) caca_canvas_t *cv; cv = caca_create_canvas(0, 0);; - if(caca_import_file(cv, file, "") < 0) + if(caca_import_canvas_from_file(cv, file, "") < 0) { caca_free_canvas(cv); return NULL; diff --git a/caca/codec/export.c b/caca/codec/export.c index dc1a30e..f789644 100644 --- a/caca/codec/export.c +++ b/caca/codec/export.c @@ -80,8 +80,8 @@ static void *export_tga(caca_canvas_t const *, size_t *); * will be written. * \return A pointer to the exported memory area, or NULL in case of error. */ -void *caca_export_memory(caca_canvas_t const *cv, char const *format, - size_t *bytes) +void *caca_export_canvas_to_memory(caca_canvas_t const *cv, char const *format, + size_t *bytes) { if(!strcasecmp("caca", format)) return export_caca(cv, bytes); @@ -120,6 +120,49 @@ void *caca_export_memory(caca_canvas_t const *cv, char const *format, return NULL; } +/** \brief Export a canvas portion into a foreign format. + * + * This function exports a portion of a \e libcaca canvas into various + * formats. For more information, see caca_export_canvas_to_memory(). + * + * If an error occurs, NULL is returned and \b errno is set accordingly: + * - \c EINVAL Unsupported format requested or invalid coordinates. + * - \c ENOMEM Not enough memory to allocate output buffer. + * + * \param cv A libcaca canvas + * \param x The leftmost coordinate of the area to export. + * \param y The topmost coordinate of the area to export. + * \param w The width of the area to export. + * \param h The height of the area to export. + * \param format A string describing the requested output format. + * \param bytes A pointer to a size_t where the number of allocated bytes + * will be written. + * \return A pointer to the exported memory area, or NULL in case of error. + */ +void *caca_export_area_to_memory(caca_canvas_t const *cv, int x, int y, int w, + int h, char const *format, size_t *bytes) +{ + caca_canvas_t *tmp; + void *ret; + + if(w < 0 || h < 0 || x < 0 || y < 0 + || x + w >= cv->width || y + h >= cv->height) + { + seterrno(EINVAL); + return NULL; + } + + /* TODO: we need to spare the blit here by exporting the area we want. */ + tmp = caca_create_canvas(w, h); + caca_blit(tmp, -x, -y, cv, NULL); + + ret = caca_export_canvas_to_memory(tmp, format, bytes); + + caca_free_canvas(tmp); + + return ret; +} + /** \brief Get available export formats * * Return a list of available export formats. The list is a NULL-terminated @@ -937,7 +980,9 @@ static void *export_tga(caca_canvas_t const *cv, size_t *bytes) */ void *cucul_export_memory(cucul_canvas_t const *, char const *, - size_t *) CACA_ALIAS(caca_export_memory); + size_t *) CACA_ALIAS(caca_export_canvas_to_memory); +void *caca_export_memory(caca_canvas_t const *, char const *, + size_t *) CACA_ALIAS(caca_export_canvas_to_memory); char const * const * cucul_get_export_list(void) CACA_ALIAS(caca_get_export_list); diff --git a/caca/codec/import.c b/caca/codec/import.c index 0133a88..3cb240e 100644 --- a/caca/codec/import.c +++ b/caca/codec/import.c @@ -71,8 +71,8 @@ static ssize_t import_caca(caca_canvas_t *, void const *, size_t); * \return The number of bytes read, or 0 if there was not enough data, * or -1 if an error occurred. */ -ssize_t caca_import_memory(caca_canvas_t *cv, void const *data, - size_t len, char const *format) +ssize_t caca_import_canvas_from_memory(caca_canvas_t *cv, void const *data, + size_t len, char const *format) { if(!strcasecmp("caca", format)) return import_caca(cv, data, len); @@ -136,8 +136,8 @@ ssize_t caca_import_memory(caca_canvas_t *cv, void const *data, * \return The number of bytes read, or 0 if there was not enough data, * or -1 if an error occurred. */ -ssize_t caca_import_file(caca_canvas_t *cv, char const *filename, - char const *format) +ssize_t caca_import_canvas_from_file(caca_canvas_t *cv, char const *filename, + char const *format) { #if defined __KERNEL__ seterrno(ENOSYS); @@ -167,13 +167,88 @@ ssize_t caca_import_file(caca_canvas_t *cv, char const *filename, } caca_file_close(f); - ret = caca_import_memory(cv, data, size, format); + ret = caca_import_canvas_from_memory(cv, data, size, format); free(data); return ret; #endif } +/** \brief Import a memory buffer into a canvas area + * + * Import a memory buffer into the given libcaca canvas's current + * frame, at the specified position. For more information, see + * caca_import_canvas_from_memory(). + * + * If an error occurs, -1 is returned and \b errno is set accordingly: + * - \c EINVAL Unsupported format requested or invalid coordinates. + * - \c ENOMEM Not enough memory to allocate canvas. + * + * \param cv A libcaca canvas in which to import the file. + * \param x The leftmost coordinate of the area to import to. + * \param y The topmost coordinate of the area to import to. + * \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 format A string describing the input format. + * \return The number of bytes read, or 0 if there was not enough data, + * or -1 if an error occurred. + */ +ssize_t caca_import_area_from_memory(caca_canvas_t *cv, int x, int y, + void const *data, size_t len, + char const *format) +{ + caca_canvas_t *tmp; + ssize_t ret; + + tmp = caca_create_canvas(0, 0); + ret = caca_import_canvas_from_memory(tmp, data, len, format); + + if(ret > 0) + caca_blit(cv, x, y, tmp, NULL); + + caca_free_canvas(tmp); + + return ret; +} + +/** \brief Import a file into a canvas area + * + * Import a file into the given libcaca canvas's current frame, at the + * specified position. For more information, see + * caca_import_canvas_from_file(). + * + * If an error occurs, -1 is returned and \b errno is set accordingly: + * - \c ENOSYS File access is not implemented on this system. + * - \c ENOMEM Not enough memory to allocate canvas. + * - \c EINVAL Unsupported format requested or invalid coordinates. + * caca_import_file() may also fail and set \b errno for any of the + * errors specified for the routine fopen(). + * + * \param cv A libcaca canvas in which to import the file. + * \param x The leftmost coordinate of the area to import to. + * \param y The topmost coordinate of the area to import to. + * \param filename The name of the file to load. + * \param format A string describing the input format. + * \return The number of bytes read, or 0 if there was not enough data, + * or -1 if an error occurred. + */ +ssize_t caca_import_area_from_file(caca_canvas_t *cv, int x, int y, + char const *filename, char const *format) +{ + caca_canvas_t *tmp; + ssize_t ret; + + tmp = caca_create_canvas(0, 0); + ret = caca_import_canvas_from_file(tmp, filename, format); + + if(ret > 0) + caca_blit(cv, x, y, tmp, NULL); + + caca_free_canvas(tmp); + + return ret; +} + /** \brief Get available import formats * * Return a list of available import formats. The list is a NULL-terminated @@ -329,6 +404,10 @@ ssize_t cucul_import_memory(cucul_canvas_t *, void const *, size_t, char const *) CACA_ALIAS(caca_import_memory); ssize_t cucul_import_file(cucul_canvas_t *, char const *, char const *) CACA_ALIAS(caca_import_file); +ssize_t caca_import_memory(caca_canvas_t *, void const *, size_t, char const *) + CACA_ALIAS(caca_import_canvas_from_memory); +ssize_t caca_import_file(caca_canvas_t *, char const *, char const *) + CACA_ALIAS(caca_import_canvas_from_file); char const * const * cucul_get_import_list(void) CACA_ALIAS(caca_get_import_list); diff --git a/caca/driver/raw.c b/caca/driver/raw.c index e308ab7..b621682 100644 --- a/caca/driver/raw.c +++ b/caca/driver/raw.c @@ -1,6 +1,6 @@ /* * libcaca Colour ASCII-Art library - * Copyright (c) 2002-2006 Sam Hocevar + * Copyright (c) 2002-2009 Sam Hocevar * All Rights Reserved * * $Id$ @@ -70,7 +70,7 @@ static void raw_display(caca_display_t *dp) void *buffer; size_t len; - buffer = caca_export_memory(dp->cv, "caca", &len); + buffer = caca_export_canvas_to_memory(dp->cv, "caca", &len); if(!buffer) return; fwrite(buffer, len, 1, stdout); diff --git a/caca/figfont.c b/caca/figfont.c index a2c1ada..8e16d6a 100644 --- a/caca/figfont.c +++ b/caca/figfont.c @@ -1,6 +1,6 @@ /* * libcaca Colour ASCII-Art library - * Copyright (c) 2006-2007 Sam Hocevar + * Copyright (c) 2002-2009 Sam Hocevar * All Rights Reserved * * $Id$ @@ -448,7 +448,7 @@ static caca_figfont_t * open_figfont(char const *path) /* Import buffer into canvas */ ff->fontcv = caca_create_canvas(0, 0); - caca_import_memory(ff->fontcv, data, i, "utf8"); + caca_import_canvas_from_memory(ff->fontcv, data, i, "utf8"); free(data); /* Remove EOL characters. For now we ignore hardblanks, don’t do any diff --git a/caca/legacy.c b/caca/legacy.c index 14f3d18..2f463e9 100644 --- a/caca/legacy.c +++ b/caca/legacy.c @@ -1,6 +1,6 @@ /* * libcaca Colour ASCII-Art library - * Copyright (c) 2002-2006 Sam Hocevar + * Copyright (c) 2002-2009 Sam Hocevar * All Rights Reserved * * $Id$ @@ -98,8 +98,9 @@ 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) { caca_canvas_t *cv = caca_create_canvas(0, 0); - int ret = caca_import_memory(cv, (unsigned char const *)buf->data, - buf->size, format); + int ret = caca_import_canvas_from_memory(cv, + (unsigned char const *)buf->data, + buf->size, format); if(ret < 0) { caca_free_canvas(cv); @@ -124,7 +125,7 @@ cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *cv, char const *format) return NULL; } - ex->data = caca_export_memory(cv, format, &ex->size); + ex->data = caca_export_canvas_to_memory(cv, format, &ex->size); if(!ex->data) { free(ex); diff --git a/cxx/caca++.cpp b/cxx/caca++.cpp index 395b5c7..f804ff4 100644 --- a/cxx/caca++.cpp +++ b/cxx/caca++.cpp @@ -291,14 +291,14 @@ char const *const * Canvas::getImportList(void) return caca_get_import_list(); } -long int Canvas::importMemory(void const *buf, size_t len, char const *fmt) +long int Canvas::importFromMemory(void const *buf, size_t len, char const *fmt) { - return caca_import_memory(cv, buf, len, fmt); + return caca_import_canvas_from_memory(cv, buf, len, fmt); } -long int Canvas::importFile(char const *file, char const *fmt) +long int Canvas::importFromFile(char const *file, char const *fmt) { - return caca_import_file(cv, file, fmt); + return caca_import_canvas_from_file(cv, file, fmt); } char const *const * Canvas::getExportList(void) @@ -306,9 +306,9 @@ char const *const * Canvas::getExportList(void) return caca_get_export_list(); } -void *Canvas::exportMemory(char const *fmt, size_t *len) +void *Canvas::exportToMemory(char const *fmt, size_t *len) { - return caca_export_memory(cv, fmt, len); + return caca_export_canvas_to_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) diff --git a/cxx/caca++.h b/cxx/caca++.h index 515fc32..ebfff30 100644 --- a/cxx/caca++.h +++ b/cxx/caca++.h @@ -137,10 +137,10 @@ __class Canvas int freeFrame(unsigned int); char const * const * getImportList(void); - long int importMemory(void const *, size_t, char const *); - long int importFile(char const *, char const *); + long int importFromMemory(void const *, size_t, char const *); + long int importFromFile(char const *, char const *); char const * const * getExportList(void); - void *exportMemory(char const *, size_t *); + void *exportToMemory(char const *, size_t *); static int Rand(int, int); static char const * getVersion(); diff --git a/cxx/cxxtest.cpp b/cxx/cxxtest.cpp index 33f6c39..6e29068 100644 --- a/cxx/cxxtest.cpp +++ b/cxx/cxxtest.cpp @@ -64,7 +64,7 @@ int main(int argc, char *argv[]) // Import buffer into a canvas pig = new Canvas(); pig->setColorANSI(CACA_LIGHTMAGENTA, CACA_TRANSPARENT); - pig->importMemory(pigstring, strlen(pigstring), "text"); + pig->importFromMemory(pigstring, strlen(pigstring), "text"); } catch(int e) { cerr << "Error while importing image (" << e << ")" << endl; diff --git a/examples/blit.c b/examples/blit.c index 5818c3a..b8a4b00 100644 --- a/examples/blit.c +++ b/examples/blit.c @@ -1,6 +1,6 @@ /* * blit libcaca blit test program - * Copyright (c) 2006 Sam Hocevar + * Copyright (c) 2006-2009 Sam Hocevar * All Rights Reserved * * $Id$ @@ -58,7 +58,7 @@ int main(int argc, char *argv[]) sprite = caca_create_canvas(0, 0); caca_set_color_ansi(sprite, CACA_LIGHTRED, CACA_BLACK); - caca_import_memory(sprite, pig, strlen(pig), "text"); + caca_import_canvas_from_memory(sprite, pig, strlen(pig), "text"); caca_set_canvas_handle(sprite, caca_get_canvas_width(sprite) / 2, caca_get_canvas_height(sprite) / 2); diff --git a/examples/export.c b/examples/export.c index 44872fe..be72c76 100644 --- a/examples/export.c +++ b/examples/export.c @@ -1,6 +1,6 @@ /* * export libcaca export test program - * Copyright (c) 2006 Sam Hocevar + * Copyright (c) 2006-2009 Sam Hocevar * All Rights Reserved * * $Id$ @@ -76,7 +76,7 @@ int main(int argc, char *argv[]) if(file) { cv = caca_create_canvas(0, 0); - if(caca_import_file(cv, file, "") < 0) + if(caca_import_canvas_from_file(cv, file, "") < 0) { fprintf(stderr, "%s: `%s' has unknown format\n", argv[0], file); exit(-1); @@ -148,7 +148,7 @@ int main(int argc, char *argv[]) } } - buffer = caca_export_memory(cv, format, &len); + buffer = caca_export_canvas_to_memory(cv, format, &len); fwrite(buffer, len, 1, stdout); free(buffer); diff --git a/examples/figfont.c b/examples/figfont.c index 4b8d5db..2742c7b 100644 --- a/examples/figfont.c +++ b/examples/figfont.c @@ -1,6 +1,6 @@ /* * figfont libcaca FIGfont test program - * Copyright (c) 2007 Sam Hocevar + * Copyright (c) 2007-2009 Sam Hocevar * All Rights Reserved * * $Id$ @@ -47,7 +47,7 @@ int main(int argc, char *argv[]) caca_put_figchar(cv, argv[2]++[0]); } - buffer = caca_export_memory(cv, "utf8", &len); + buffer = caca_export_canvas_to_memory(cv, "utf8", &len); fwrite(buffer, len, 1, stdout); free(buffer); diff --git a/examples/font2tga.c b/examples/font2tga.c index 57d71a7..b55c02c 100644 --- a/examples/font2tga.c +++ b/examples/font2tga.c @@ -1,6 +1,6 @@ /* * font2tga libcaca font test program - * Copyright (c) 2006 Sam Hocevar + * Copyright (c) 2006-2009 Sam Hocevar * All Rights Reserved * * $Id$ @@ -74,7 +74,7 @@ int main(int argc, char *argv[]) caca_free_font(f); - buffer = caca_export_memory(cv, "tga", &len); + buffer = caca_export_canvas_to_memory(cv, "tga", &len); fwrite(buffer, len, 1, stdout); free(buffer); diff --git a/examples/import.c b/examples/import.c index d235f62..b7b23d3 100644 --- a/examples/import.c +++ b/examples/import.c @@ -40,7 +40,7 @@ int main(int argc, char *argv[]) return -1; } - if(caca_import_file(cv, argv[1], argc >= 3 ? argv[2] : "") < 0) + if(caca_import_canvas_from_file(cv, argv[1], argc >= 3 ? argv[2] : "") < 0) { fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]); caca_free_canvas(cv); diff --git a/examples/spritedit.c b/examples/spritedit.c index ccb7c26..3e11d83 100644 --- a/examples/spritedit.c +++ b/examples/spritedit.c @@ -1,6 +1,6 @@ /* * spritedit sprite editor for libcaca - * Copyright (c) 2003 Sam Hocevar + * Copyright (c) 2003-2009 Sam Hocevar * All Rights Reserved * * $Id$ @@ -61,18 +61,18 @@ int main(int argc, char **argv) for(i = 0; i < 4; i++) { caca_set_frame(sprite, i); - caca_import_memory(sprite, guy[i], strlen(guy[i]), "utf8"); + caca_import_canvas_from_memory(sprite, guy[i], strlen(guy[i]), "utf8"); } /* Export our sprite in a memory buffer. We could save this to * disk afterwards. */ - buffer = caca_export_memory(sprite, "caca", &len); + buffer = caca_export_canvas_to_memory(sprite, "caca", &len); /* Free our sprite and reload it from the memory buffer. We could * load this from disk, too. */ caca_free_canvas(sprite); sprite = caca_create_canvas(0, 0); - caca_import_memory(sprite, buffer, len, "caca"); + caca_import_canvas_from_memory(sprite, buffer, len, "caca"); free(buffer); /* Print each sprite frame to stdout */ @@ -80,7 +80,7 @@ int main(int argc, char **argv) { caca_set_frame(sprite, i); printf("Frame #%i\n", i); - buffer = caca_export_memory(sprite, "utf8", &len); + buffer = caca_export_canvas_to_memory(sprite, "utf8", &len); fwrite(buffer, len, 1, stdout); free(buffer); } diff --git a/examples/swallow.c b/examples/swallow.c index 8523406..1fdcfb8 100644 --- a/examples/swallow.c +++ b/examples/swallow.c @@ -1,6 +1,6 @@ /* * swallow swallow another libcaca application - * Copyright (c) 2006 Sam Hocevar + * Copyright (c) 2006-2009 Sam Hocevar * All Rights Reserved * * $Id$ @@ -87,7 +87,8 @@ int main(int argc, char **argv) for(i = 0; i < 4; i++) { - bytes[i] = caca_import_memory(app, buf[i], total[i], "caca"); + bytes[i] = caca_import_canvas_from_memory(app, buf[i], + total[i], "caca"); if(bytes[i] > 0) { diff --git a/examples/text.c b/examples/text.c index de4bd10..51678fc 100644 --- a/examples/text.c +++ b/examples/text.c @@ -1,6 +1,6 @@ /* * text canvas text import/export - * Copyright (c) 2006 Sam Hocevar + * Copyright (c) 2006-2009 Sam Hocevar * All Rights Reserved * * $Id$ @@ -41,7 +41,7 @@ int main(int argc, char *argv[]) int i, j; pig = caca_create_canvas(0, 0); - caca_import_memory(pig, STRING, strlen(STRING), "text"); + caca_import_canvas_from_memory(pig, STRING, strlen(STRING), "text"); cv = caca_create_canvas(caca_get_canvas_width(pig) * 2, caca_get_canvas_height(pig) * 2); @@ -76,12 +76,12 @@ int main(int argc, char *argv[]) } } - buffer = caca_export_memory(cv, "utf8", &len); + buffer = caca_export_canvas_to_memory(cv, "utf8", &len); fwrite(buffer, len, 1, stdout); free(buffer); caca_rotate_left(cv); - buffer = caca_export_memory(cv, "utf8", &len); + buffer = caca_export_canvas_to_memory(cv, "utf8", &len); fwrite(buffer, len, 1, stdout); free(buffer); diff --git a/examples/transform.c b/examples/transform.c index 6c6827a..04f4d74 100644 --- a/examples/transform.c +++ b/examples/transform.c @@ -1,6 +1,6 @@ /* * unicode libcaca Unicode rendering test program - * Copyright (c) 2006 Sam Hocevar + * Copyright (c) 2006-2009 Sam Hocevar * All Rights Reserved * * $Id$ @@ -59,11 +59,11 @@ int main(int argc, char *argv[]) sprite = caca_create_canvas(0, 0); caca_set_color_ansi(sprite, CACA_LIGHTMAGENTA, CACA_BLACK); - caca_import_memory(sprite, pig, strlen(pig), "text"); + caca_import_canvas_from_memory(sprite, pig, strlen(pig), "text"); caca_blit(image, 55, 0, sprite, NULL); caca_set_color_ansi(sprite, CACA_LIGHTGREEN, CACA_BLACK); - caca_import_memory(sprite, duck, strlen(duck), "text"); + caca_import_canvas_from_memory(sprite, duck, strlen(duck), "text"); caca_blit(image, 30, 1, sprite, NULL); caca_set_color_ansi(image, CACA_LIGHTCYAN, CACA_BLACK); diff --git a/ruby/caca-canvas.c b/ruby/caca-canvas.c index 95e6507..84b16b8 100644 --- a/ruby/caca-canvas.c +++ b/ruby/caca-canvas.c @@ -21,7 +21,7 @@ VALUE cCanvas; #define simple_func(x) \ static VALUE x (VALUE self) \ { \ - if( caca_##x (_SELF) <0) \ + if( caca_##x (_SELF) <0) \ rb_raise(rb_eRuntimeError, strerror(errno)); \ \ return self; \ @@ -30,7 +30,7 @@ static VALUE x (VALUE self) \ #define get_int(x) \ static VALUE get_##x (VALUE self) \ { \ - return INT2NUM(caca_get_##x (_SELF)); \ + return INT2NUM(caca_get_##x (_SELF)); \ } static void canvas_free(void * p) @@ -40,7 +40,7 @@ static void canvas_free(void * p) static VALUE canvas_alloc(VALUE klass) { - VALUE obj; + VALUE obj; obj = Data_Wrap_Struct(klass, NULL, canvas_free, NULL); return obj; } @@ -534,32 +534,32 @@ static VALUE render_canvas(VALUE self, VALUE font, VALUE width, VALUE height, VA return b; } -static VALUE import_memory(VALUE self, VALUE data, VALUE format) +static VALUE import_from_memory(VALUE self, VALUE data, VALUE format) { long int bytes; - bytes = caca_import_memory (_SELF, StringValuePtr(data), RSTRING(StringValue(data))->len, StringValuePtr(format)); + bytes = caca_import_canvas_from_memory (_SELF, StringValuePtr(data), RSTRING(StringValue(data))->len, StringValuePtr(format)); if(bytes <= 0) rb_raise(rb_eRuntimeError, strerror(errno)); return self; } -static VALUE import_file(VALUE self, VALUE filename, VALUE format) +static VALUE import_from_file(VALUE self, VALUE filename, VALUE format) { long int bytes; - bytes = caca_import_file (_SELF, StringValuePtr(filename), StringValuePtr(format)); + bytes = caca_import_canvas_from_file (_SELF, StringValuePtr(filename), StringValuePtr(format)); if(bytes <= 0) rb_raise(rb_eRuntimeError, strerror(errno)); return self; } -static VALUE export_memory(VALUE self, VALUE format) +static VALUE export_to_memory(VALUE self, VALUE format) { size_t bytes; void *result; VALUE ret; - result = caca_export_memory (_SELF, StringValuePtr(format), &bytes); + result = caca_export_canvas_to_memory (_SELF, StringValuePtr(format), &bytes); ret = rb_str_new(result, bytes); free(result); return ret; @@ -643,11 +643,10 @@ void Init_caca_canvas(VALUE mCaca) rb_define_method(cCanvas, "free_frame", free_frame, 1); rb_define_method(cCanvas, "render", render_canvas, 4); - rb_define_method(cCanvas, "import_memory", import_memory, 2); - rb_define_method(cCanvas, "import_file", import_file, 2); - rb_define_method(cCanvas, "export_memory", export_memory, 1); + rb_define_method(cCanvas, "import_from_memory", import_from_memory, 2); + rb_define_method(cCanvas, "import_from_file", import_from_file, 2); + rb_define_method(cCanvas, "export_to_memory", export_to_memory, 1); rb_define_singleton_method(cCanvas, "export_list", export_list, 0); rb_define_singleton_method(cCanvas, "import_list", import_list, 0); - } diff --git a/src/cacadraw.c b/src/cacadraw.c index 2f41dd1..1cbb90d 100644 --- a/src/cacadraw.c +++ b/src/cacadraw.c @@ -1,6 +1,6 @@ /* * event event lister for libcaca - * Copyright (c) 2004 Sam Hocevar + * Copyright (c) 2004-2009 Sam Hocevar * All Rights Reserved * * $Id$ @@ -55,7 +55,7 @@ int main(int argc, char **argv) if(!image) { image = caca_create_canvas(0, 0); - if(caca_import_file(image, argv[file], "ansi") < 0) + if(caca_import_canvas_from_file(image, argv[file], "ansi") < 0) { fprintf(stderr, "%s: invalid file `%s'.\n", argv[0], argv[1]); return 1; diff --git a/src/cacaplay.c b/src/cacaplay.c index 7b28e66..3052dbd 100644 --- a/src/cacaplay.c +++ b/src/cacaplay.c @@ -1,6 +1,6 @@ /* * cacaplay caca file player - * Copyright (c) 2006 Sam Hocevar + * Copyright (c) 2006-2009 Sam Hocevar * All Rights Reserved * * $Id$ @@ -89,7 +89,7 @@ int main(int argc, char **argv) total += n; } - bytes = caca_import_memory(app, buf, total, "caca"); + bytes = caca_import_canvas_from_memory(app, buf, total, "caca"); if(bytes > 0) { diff --git a/src/cacaserver.c b/src/cacaserver.c index 0b7b8b5..12142a5 100644 --- a/src/cacaserver.c +++ b/src/cacaserver.c @@ -1,7 +1,7 @@ /* * cacaserver Colour ASCII-Art library * Copyright (c) 2006 Jean-Yves Lamoureux - * 2006 Sam Hocevar + * 2006-2009 Sam Hocevar * All Rights Reserved * * $Id$ @@ -213,8 +213,8 @@ restart: server->read = 12; } - while(caca_import_memory(server->canvas, server->input, - server->read, "caca") < 0) + while(caca_import_canvas_from_memory(server->canvas, server->input, + server->read, "caca") < 0) { memmove(server->input, server->input + 1, server->read - 1); read(0, server->input + server->read - 1, 1); @@ -224,8 +224,9 @@ restart: { ssize_t needed, wanted; - needed = caca_import_memory(server->canvas, server->input, - server->read, "caca"); + needed = caca_import_canvas_from_memory(server->canvas, + server->input, + server->read, "caca"); if(needed < 0) goto restart; @@ -252,8 +253,8 @@ restart: /* Get ANSI representation of the image and skip the end-of buffer * linefeed ("\r\n", 2 byte) */ - server->buffer = caca_export_memory(server->canvas, "utf8cr", - &server->buflen); + server->buffer = caca_export_canvas_to_memory(server->canvas, "utf8cr", + &server->buflen); server->buflen -= 2; for(i = 0; i < server->client_count; i++) diff --git a/src/img2txt.c b/src/img2txt.c index 5c0971b..7645508 100644 --- a/src/img2txt.c +++ b/src/img2txt.c @@ -1,6 +1,6 @@ /* * img2txt image to text converter - * Copyright (c) 2006 Sam Hocevar + * Copyright (c) 2006-2009 Sam Hocevar * 2007 Jean-Yves Lamoureux * All Rights Reserved * @@ -81,7 +81,7 @@ static void version(void) { printf( "img2txt Copyright 2006-2007 Sam Hocevar and Jean-Yves Lamoureux\n" - "Internet: Version: %s, date: %s\n" + "Internet: Version: %s, date: %s\n" "\n" "img2txt, along with its documentation, may be freely copied and distributed.\n" "\n" @@ -224,7 +224,7 @@ int main(int argc, char **argv) unload_image(i); - export = caca_export_memory(cv, format?format:"ansi", &len); + export = caca_export_canvas_to_memory(cv, format?format:"ansi", &len); if(!export) { fprintf(stderr, "%s: Can't export to format '%s'\n", argv[0], format);