import.c (libcaca-0.99.beta19) | : | import.c (libcaca-0.99.beta20.tar.bz2) | ||
---|---|---|---|---|
/* | /* | |||
* libcaca Colour ASCII-Art library | * libcaca Colour ASCII-Art library | |||
* Copyright (c) 2002-2014 Sam Hocevar <sam@hocevar.net> | * Copyright © 2002—2021 Sam Hocevar <sam@hocevar.net> | |||
* All Rights Reserved | * All Rights Reserved | |||
* | * | |||
* This library is free software. It comes without any warranty, to | * This library is free software. It comes without any warranty, to | |||
* the extent permitted by applicable law. You can redistribute it | * 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 | * 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 | * to Public License, Version 2, as published by Sam Hocevar. See | |||
* http://www.wtfpl.net/ for more details. | * http://www.wtfpl.net/ for more details. | |||
*/ | */ | |||
/* | /* | |||
* This file contains various import functions. | * This file contains various import functions. | |||
skipping to change at line 64 | skipping to change at line 64 | |||
* - \c "text": import ASCII text files. | * - \c "text": import ASCII text files. | |||
* - \c "ansi": import ANSI files. | * - \c "ansi": import ANSI files. | |||
* - \c "utf8": import UTF-8 files with ANSI colour codes. | * - \c "utf8": import UTF-8 files with ANSI colour codes. | |||
* - \c "bin": import BIN files. | * - \c "bin": import BIN files. | |||
* | * | |||
* The number of bytes read is returned. If the file format is valid, but | * The number of bytes read is returned. If the file format is valid, but | |||
* not enough data was available, 0 is returned. | * not enough data was available, 0 is returned. | |||
* | * | |||
* 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 canvas. | * - \c ENOMEM Not enough memory to allocate canvas. | |||
* - \c EOVERFLOW Importing data caused a value overflow. | ||||
* - \c EINVAL Invalid format requested. | * - \c EINVAL Invalid format requested. | |||
* | * | |||
* \param cv A libcaca 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 caca_import_canvas_from_memory(caca_canvas_t *cv, void const *data, | ssize_t caca_import_canvas_from_memory(caca_canvas_t *cv, void const *data, | |||
skipping to change at line 422 | skipping to change at line 423 | |||
ssize_t _import_bin(caca_canvas_t *cv, void const *data, size_t len) | ssize_t _import_bin(caca_canvas_t *cv, void const *data, size_t len) | |||
{ | { | |||
uint8_t const *buf = (uint8_t const *)data; | uint8_t const *buf = (uint8_t const *)data; | |||
size_t i; | size_t i; | |||
int x = 0, y = 0; | int x = 0, y = 0; | |||
caca_set_canvas_size(cv, 0, 0); | caca_set_canvas_size(cv, 0, 0); | |||
caca_set_canvas_size(cv, 160, len / 160); | caca_set_canvas_size(cv, 160, len / 160); | |||
/* Only read an even number of bytes */ | ||||
len &= ~(size_t)1; | ||||
for (i = 0; i < len; i += 2) | for (i = 0; i < len; i += 2) | |||
{ | { | |||
caca_set_color_ansi(cv, buf[i + 1] & 0xf, buf[i + 1] >> 4); | caca_set_color_ansi(cv, buf[i + 1] & 0xf, buf[i + 1] >> 4); | |||
caca_put_char(cv, x, y, caca_cp437_to_utf32(buf[i])); | caca_put_char(cv, x, y, caca_cp437_to_utf32(buf[i])); | |||
++x; | ++x; | |||
if (x >= 160) | if (x >= 160) | |||
{ | { | |||
++y; | ++y; | |||
x = 0; | x = 0; | |||
} | } | |||
} | } | |||
return len & ~(size_t)1; | return len; | |||
} | } | |||
/* | ||||
* XXX: The following functions are aliases. | ||||
*/ | ||||
ssize_t cucul_import_memory(cucul_canvas_t *, void const *, size_t, | ||||
char const *) CACA_ALIAS(caca_import_canvas_from_memory); | ||||
ssize_t cucul_import_file(cucul_canvas_t *, char const *, | ||||
char const *) CACA_ALIAS(caca_import_canvas_from_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); | ||||
End of changes. 5 change blocks. | ||||
4 lines changed or deleted | 8 lines changed or added |