ソースを参照

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().
tags/v0.99.beta17
Sam Hocevar sam 15年前
コミット
d3ef2bbecd
24個のファイルの変更224行の追加85行の削除
  1. +19
    -6
      caca/caca.h
  2. +2
    -2
      caca/caca0.c
  3. +48
    -3
      caca/codec/export.c
  4. +84
    -5
      caca/codec/import.c
  5. +2
    -2
      caca/driver/raw.c
  6. +2
    -2
      caca/figfont.c
  7. +5
    -4
      caca/legacy.c
  8. +6
    -6
      cxx/caca++.cpp
  9. +3
    -3
      cxx/caca++.h
  10. +1
    -1
      cxx/cxxtest.cpp
  11. +2
    -2
      examples/blit.c
  12. +3
    -3
      examples/export.c
  13. +2
    -2
      examples/figfont.c
  14. +2
    -2
      examples/font2tga.c
  15. +1
    -1
      examples/import.c
  16. +5
    -5
      examples/spritedit.c
  17. +3
    -2
      examples/swallow.c
  18. +4
    -4
      examples/text.c
  19. +3
    -3
      examples/transform.c
  20. +12
    -13
      ruby/caca-canvas.c
  21. +2
    -2
      src/cacadraw.c
  22. +2
    -2
      src/cacaplay.c
  23. +8
    -7
      src/cacaserver.c
  24. +3
    -3
      src/img2txt.c

+ 19
- 6
caca/caca.h ファイルの表示

@@ -425,13 +425,20 @@ __extern int caca_file_eof(caca_file_t *);
* the current canvas to various text formats. * 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 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); __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; char const *) CACA_DEPRECATED;
__extern caca_canvas_t * cucul_import_canvas(cucul_buffer_t *, __extern caca_canvas_t * cucul_import_canvas(cucul_buffer_t *,
char const *) CACA_DEPRECATED; 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_rotate(caca_canvas_t *) CACA_DEPRECATED;
__extern int cucul_set_dither_invert(caca_dither_t *, int) CACA_DEPRECATED; __extern int cucul_set_dither_invert(caca_dither_t *, int) CACA_DEPRECATED;
__extern int cucul_set_dither_mode(caca_dither_t *, __extern int cucul_set_dither_mode(caca_dither_t *,


+ 2
- 2
caca/caca0.c ファイルの表示

@@ -1,6 +1,6 @@
/* /*
* libcaca Colour ASCII-Art library * libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2002-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -215,7 +215,7 @@ caca_canvas_t *__caca0_load_sprite(char const *file)
caca_canvas_t *cv; caca_canvas_t *cv;


cv = caca_create_canvas(0, 0);; 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); caca_free_canvas(cv);
return NULL; return NULL;


+ 48
- 3
caca/codec/export.c ファイルの表示

@@ -80,8 +80,8 @@ static void *export_tga(caca_canvas_t const *, size_t *);
* 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 *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)) if(!strcasecmp("caca", format))
return export_caca(cv, bytes); return export_caca(cv, bytes);
@@ -120,6 +120,49 @@ void *caca_export_memory(caca_canvas_t const *cv, char const *format,
return NULL; 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 /** \brief Get available export formats
* *
* 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
@@ -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 *, 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) char const * const * cucul_get_export_list(void)
CACA_ALIAS(caca_get_export_list); CACA_ALIAS(caca_get_export_list);



+ 84
- 5
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, * \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 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)) if(!strcasecmp("caca", format))
return import_caca(cv, data, len); 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, * \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 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__ #if defined __KERNEL__
seterrno(ENOSYS); seterrno(ENOSYS);
@@ -167,13 +167,88 @@ ssize_t caca_import_file(caca_canvas_t *cv, char const *filename,
} }
caca_file_close(f); caca_file_close(f);


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


return ret; return ret;
#endif #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 /** \brief Get available import formats
* *
* 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
@@ -329,6 +404,10 @@ ssize_t cucul_import_memory(cucul_canvas_t *, void const *, size_t,
char const *) CACA_ALIAS(caca_import_memory); char const *) CACA_ALIAS(caca_import_memory);
ssize_t cucul_import_file(cucul_canvas_t *, char const *, ssize_t cucul_import_file(cucul_canvas_t *, char const *,
char const *) CACA_ALIAS(caca_import_file); 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) char const * const * cucul_get_import_list(void)
CACA_ALIAS(caca_get_import_list); CACA_ALIAS(caca_get_import_list);



+ 2
- 2
caca/driver/raw.c ファイルの表示

@@ -1,6 +1,6 @@
/* /*
* libcaca Colour ASCII-Art library * libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2002-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -70,7 +70,7 @@ static void raw_display(caca_display_t *dp)
void *buffer; void *buffer;
size_t len; size_t len;


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


+ 2
- 2
caca/figfont.c ファイルの表示

@@ -1,6 +1,6 @@
/* /*
* libcaca Colour ASCII-Art library * libcaca Colour ASCII-Art library
* Copyright (c) 2006-2007 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2002-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -448,7 +448,7 @@ static caca_figfont_t * open_figfont(char const *path)


/* Import buffer into canvas */ /* Import buffer into canvas */
ff->fontcv = caca_create_canvas(0, 0); 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); 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


+ 5
- 4
caca/legacy.c ファイルの表示

@@ -1,6 +1,6 @@
/* /*
* libcaca Colour ASCII-Art library * libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2002-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $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) cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *buf, char const *format)
{ {
caca_canvas_t *cv = caca_create_canvas(0, 0); 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) if(ret < 0)
{ {
caca_free_canvas(cv); caca_free_canvas(cv);
@@ -124,7 +125,7 @@ cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *cv, char const *format)
return NULL; 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) if(!ex->data)
{ {
free(ex); free(ex);


+ 6
- 6
cxx/caca++.cpp ファイルの表示

@@ -291,14 +291,14 @@ char const *const * Canvas::getImportList(void)
return caca_get_import_list(); 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) char const *const * Canvas::getExportList(void)
@@ -306,9 +306,9 @@ char const *const * Canvas::getExportList(void)
return caca_get_export_list(); 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) 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)


+ 3
- 3
cxx/caca++.h ファイルの表示

@@ -137,10 +137,10 @@ __class Canvas
int freeFrame(unsigned int); int freeFrame(unsigned int);


char const * const * getImportList(void); 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); char const * const * getExportList(void);
void *exportMemory(char const *, size_t *);
void *exportToMemory(char const *, size_t *);


static int Rand(int, int); static int Rand(int, int);
static char const * getVersion(); static char const * getVersion();


+ 1
- 1
cxx/cxxtest.cpp ファイルの表示

@@ -64,7 +64,7 @@ int main(int argc, char *argv[])
// Import buffer into a canvas // Import buffer into a canvas
pig = new Canvas(); pig = new Canvas();
pig->setColorANSI(CACA_LIGHTMAGENTA, CACA_TRANSPARENT); pig->setColorANSI(CACA_LIGHTMAGENTA, CACA_TRANSPARENT);
pig->importMemory(pigstring, strlen(pigstring), "text");
pig->importFromMemory(pigstring, strlen(pigstring), "text");
} }
catch(int e) { catch(int e) {
cerr << "Error while importing image (" << e << ")" << endl; cerr << "Error while importing image (" << e << ")" << endl;


+ 2
- 2
examples/blit.c ファイルの表示

@@ -1,6 +1,6 @@
/* /*
* blit libcaca blit test program * blit libcaca blit test program
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2006-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -58,7 +58,7 @@ int main(int argc, char *argv[])


sprite = caca_create_canvas(0, 0); sprite = caca_create_canvas(0, 0);
caca_set_color_ansi(sprite, CACA_LIGHTRED, CACA_BLACK); 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_set_canvas_handle(sprite, caca_get_canvas_width(sprite) / 2,
caca_get_canvas_height(sprite) / 2); caca_get_canvas_height(sprite) / 2);




+ 3
- 3
examples/export.c ファイルの表示

@@ -1,6 +1,6 @@
/* /*
* export libcaca export test program * export libcaca export test program
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2006-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -76,7 +76,7 @@ int main(int argc, char *argv[])
if(file) if(file)
{ {
cv = caca_create_canvas(0, 0); 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); fprintf(stderr, "%s: `%s' has unknown format\n", argv[0], file);
exit(-1); 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); fwrite(buffer, len, 1, stdout);
free(buffer); free(buffer);




+ 2
- 2
examples/figfont.c ファイルの表示

@@ -1,6 +1,6 @@
/* /*
* figfont libcaca FIGfont test program * figfont libcaca FIGfont test program
* Copyright (c) 2007 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2007-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -47,7 +47,7 @@ int main(int argc, char *argv[])
caca_put_figchar(cv, argv[2]++[0]); 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); fwrite(buffer, len, 1, stdout);
free(buffer); free(buffer);




+ 2
- 2
examples/font2tga.c ファイルの表示

@@ -1,6 +1,6 @@
/* /*
* font2tga libcaca font test program * font2tga libcaca font test program
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2006-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -74,7 +74,7 @@ int main(int argc, char *argv[])


caca_free_font(f); 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); fwrite(buffer, len, 1, stdout);
free(buffer); free(buffer);




+ 1
- 1
examples/import.c ファイルの表示

@@ -40,7 +40,7 @@ int main(int argc, char *argv[])
return -1; 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]); fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]);
caca_free_canvas(cv); caca_free_canvas(cv);


+ 5
- 5
examples/spritedit.c ファイルの表示

@@ -1,6 +1,6 @@
/* /*
* spritedit sprite editor for libcaca * spritedit sprite editor for libcaca
* Copyright (c) 2003 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2003-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -61,18 +61,18 @@ int main(int argc, char **argv)
for(i = 0; i < 4; i++) for(i = 0; i < 4; i++)
{ {
caca_set_frame(sprite, 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 /* Export our sprite in a memory buffer. We could save this to
* disk afterwards. */ * 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 /* Free our sprite and reload it from the memory buffer. We could
* load this from disk, too. */ * load this from disk, too. */
caca_free_canvas(sprite); caca_free_canvas(sprite);
sprite = caca_create_canvas(0, 0); sprite = caca_create_canvas(0, 0);
caca_import_memory(sprite, buffer, len, "caca");
caca_import_canvas_from_memory(sprite, buffer, len, "caca");
free(buffer); free(buffer);


/* Print each sprite frame to stdout */ /* Print each sprite frame to stdout */
@@ -80,7 +80,7 @@ int main(int argc, char **argv)
{ {
caca_set_frame(sprite, i); caca_set_frame(sprite, i);
printf("Frame #%i\n", 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); fwrite(buffer, len, 1, stdout);
free(buffer); free(buffer);
} }


+ 3
- 2
examples/swallow.c ファイルの表示

@@ -1,6 +1,6 @@
/* /*
* swallow swallow another libcaca application * swallow swallow another libcaca application
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2006-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -87,7 +87,8 @@ int main(int argc, char **argv)


for(i = 0; i < 4; i++) 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) if(bytes[i] > 0)
{ {


+ 4
- 4
examples/text.c ファイルの表示

@@ -1,6 +1,6 @@
/* /*
* text canvas text import/export * text canvas text import/export
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2006-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -41,7 +41,7 @@ int main(int argc, char *argv[])
int i, j; int i, j;


pig = caca_create_canvas(0, 0); 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, cv = caca_create_canvas(caca_get_canvas_width(pig) * 2,
caca_get_canvas_height(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); fwrite(buffer, len, 1, stdout);
free(buffer); free(buffer);


caca_rotate_left(cv); 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); fwrite(buffer, len, 1, stdout);
free(buffer); free(buffer);




+ 3
- 3
examples/transform.c ファイルの表示

@@ -1,6 +1,6 @@
/* /*
* unicode libcaca Unicode rendering test program * unicode libcaca Unicode rendering test program
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2006-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -59,11 +59,11 @@ int main(int argc, char *argv[])
sprite = caca_create_canvas(0, 0); sprite = caca_create_canvas(0, 0);


caca_set_color_ansi(sprite, CACA_LIGHTMAGENTA, CACA_BLACK); 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_blit(image, 55, 0, sprite, NULL);


caca_set_color_ansi(sprite, CACA_LIGHTGREEN, CACA_BLACK); 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_blit(image, 30, 1, sprite, NULL);


caca_set_color_ansi(image, CACA_LIGHTCYAN, CACA_BLACK); caca_set_color_ansi(image, CACA_LIGHTCYAN, CACA_BLACK);


+ 12
- 13
ruby/caca-canvas.c ファイルの表示

@@ -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( caca_##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,7 +30,7 @@ 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(caca_get_##x (_SELF)); \
return INT2NUM(caca_get_##x (_SELF)); \
} }


static void canvas_free(void * p) static void canvas_free(void * p)
@@ -40,7 +40,7 @@ static void canvas_free(void * p)


static VALUE canvas_alloc(VALUE klass) static VALUE canvas_alloc(VALUE klass)
{ {
VALUE obj;
VALUE obj;
obj = Data_Wrap_Struct(klass, NULL, canvas_free, NULL); obj = Data_Wrap_Struct(klass, NULL, canvas_free, NULL);
return obj; return obj;
} }
@@ -534,32 +534,32 @@ static VALUE render_canvas(VALUE self, VALUE font, VALUE width, VALUE height, VA
return b; 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; 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) if(bytes <= 0)
rb_raise(rb_eRuntimeError, strerror(errno)); rb_raise(rb_eRuntimeError, strerror(errno));


return self; 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; 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) if(bytes <= 0)
rb_raise(rb_eRuntimeError, strerror(errno)); rb_raise(rb_eRuntimeError, strerror(errno));


return self; return self;
} }


static VALUE export_memory(VALUE self, VALUE format)
static VALUE export_to_memory(VALUE self, VALUE format)
{ {
size_t bytes; size_t bytes;
void *result; void *result;
VALUE ret; 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); ret = rb_str_new(result, bytes);
free(result); free(result);
return ret; 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, "free_frame", free_frame, 1);


rb_define_method(cCanvas, "render", render_canvas, 4); 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, "export_list", export_list, 0);
rb_define_singleton_method(cCanvas, "import_list", import_list, 0); rb_define_singleton_method(cCanvas, "import_list", import_list, 0);
} }



+ 2
- 2
src/cacadraw.c ファイルの表示

@@ -1,6 +1,6 @@
/* /*
* event event lister for libcaca * event event lister for libcaca
* Copyright (c) 2004 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2004-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -55,7 +55,7 @@ int main(int argc, char **argv)
if(!image) if(!image)
{ {
image = caca_create_canvas(0, 0); 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]); fprintf(stderr, "%s: invalid file `%s'.\n", argv[0], argv[1]);
return 1; return 1;


+ 2
- 2
src/cacaplay.c ファイルの表示

@@ -1,6 +1,6 @@
/* /*
* cacaplay caca file player * cacaplay caca file player
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2006-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -89,7 +89,7 @@ int main(int argc, char **argv)
total += n; total += n;
} }


bytes = caca_import_memory(app, buf, total, "caca");
bytes = caca_import_canvas_from_memory(app, buf, total, "caca");


if(bytes > 0) if(bytes > 0)
{ {


+ 8
- 7
src/cacaserver.c ファイルの表示

@@ -1,7 +1,7 @@
/* /*
* cacaserver Colour ASCII-Art library * cacaserver Colour ASCII-Art library
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org> * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
* 2006 Sam Hocevar <sam@zoy.org>
* 2006-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -213,8 +213,8 @@ restart:
server->read = 12; 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); memmove(server->input, server->input + 1, server->read - 1);
read(0, server->input + server->read - 1, 1); read(0, server->input + server->read - 1, 1);
@@ -224,8 +224,9 @@ restart:
{ {
ssize_t needed, wanted; 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) if(needed < 0)
goto restart; goto restart;


@@ -252,8 +253,8 @@ restart:


/* Get ANSI representation of the image and skip the end-of buffer /* Get ANSI representation of the image and skip the end-of buffer
* linefeed ("\r\n", 2 byte) */ * 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; server->buflen -= 2;


for(i = 0; i < server->client_count; i++) for(i = 0; i < server->client_count; i++)


+ 3
- 3
src/img2txt.c ファイルの表示

@@ -1,6 +1,6 @@
/* /*
* img2txt image to text converter * img2txt image to text converter
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2006-2009 Sam Hocevar <sam@hocevar.net>
* 2007 Jean-Yves Lamoureux <jylam@lnxscene.org> * 2007 Jean-Yves Lamoureux <jylam@lnxscene.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -81,7 +81,7 @@ static void version(void)
{ {
printf( printf(
"img2txt Copyright 2006-2007 Sam Hocevar and Jean-Yves Lamoureux\n" "img2txt Copyright 2006-2007 Sam Hocevar and Jean-Yves Lamoureux\n"
"Internet: <sam@zoy.org> <jylam@lnxscene.org> Version: %s, date: %s\n"
"Internet: <sam@hocevar.net> <jylam@lnxscene.org> Version: %s, date: %s\n"
"\n" "\n"
"img2txt, along with its documentation, may be freely copied and distributed.\n" "img2txt, along with its documentation, may be freely copied and distributed.\n"
"\n" "\n"
@@ -224,7 +224,7 @@ int main(int argc, char **argv)


unload_image(i); 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) if(!export)
{ {
fprintf(stderr, "%s: Can't export to format '%s'\n", argv[0], format); fprintf(stderr, "%s: Can't export to format '%s'\n", argv[0], format);


読み込み中…
キャンセル
保存