"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "caca/canvas.c" between
libcaca-0.99.beta19.tar.gz and libcaca-0.99.beta20.tar.bz2

About: libcaca is a graphics library that outputs text instead of pixels, so that it can work on older video cards or text terminals (something like an advanced AAlib library).

canvas.c  (libcaca-0.99.beta19):canvas.c  (libcaca-0.99.beta20.tar.bz2)
/* /*
* libcaca Colour ASCII-Art library * libcaca Colour ASCII-Art library
* Copyright (c) 2002-2012 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 the main functions used by \e libcaca applications * This file contains the main functions used by \e libcaca applications
skipping to change at line 48 skipping to change at line 48
* Initialise internal \e libcaca structures and the backend that will * Initialise internal \e libcaca structures and the backend that will
* be used for subsequent graphical operations. It must be the first * be used for subsequent graphical operations. It must be the first
* \e libcaca function to be called in a function. caca_free_canvas() * \e libcaca function to be called in a function. caca_free_canvas()
* should be called at the end of the program to free all allocated resources. * should be called at the end of the program to free all allocated resources.
* *
* Both the cursor and the canvas' handle are initialised at the top-left * Both the cursor and the canvas' handle are initialised at the top-left
* corner. * corner.
* *
* If an error occurs, NULL is returned and \b errno is set accordingly: * If an error occurs, NULL is returned and \b errno is set accordingly:
* - \c EINVAL Specified width or height is invalid. * - \c EINVAL Specified width or height is invalid.
* - \c EOVERFLOW Specified width and height overflowed.
* - \c ENOMEM Not enough memory for the requested canvas size. * - \c ENOMEM Not enough memory for the requested canvas size.
* *
* \param width The desired canvas width * \param width The desired canvas width
* \param height The desired canvas height * \param height The desired canvas height
* \return A libcaca canvas handle upon success, NULL if an error occurred. * \return A libcaca canvas handle upon success, NULL if an error occurred.
*/ */
caca_canvas_t * caca_create_canvas(int width, int height) caca_canvas_t * caca_create_canvas(int width, int height)
{ {
caca_canvas_t *cv; caca_canvas_t *cv;
skipping to change at line 203 skipping to change at line 204
* *
* It is an error to try to resize the canvas if an output driver has * It is an error to try to resize the canvas if an output driver has
* been attached to the canvas using caca_create_display(). You need to * been attached to the canvas using caca_create_display(). You need to
* remove the output driver using caca_free_display() before you can change * remove the output driver using caca_free_display() before you can change
* the canvas size again. However, the caca output driver can cause a * the canvas size again. However, the caca output driver can cause a
* canvas resize through user interaction. See the caca_event() documentation * canvas resize through user interaction. See the caca_event() documentation
* for more about this. * for more about this.
* *
* 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 EINVAL Specified width or height is invalid. * - \c EINVAL Specified width or height is invalid.
* - \c EOVERFLOW Specified width and height overflowed.
* - \c EBUSY The canvas is in use by a display driver and cannot be resized. * - \c EBUSY The canvas is in use by a display driver and cannot be resized.
* - \c ENOMEM Not enough memory for the requested canvas size. If this * - \c ENOMEM Not enough memory for the requested canvas size. If this
* happens, the canvas handle becomes invalid and should not be used. * happens, the canvas handle becomes invalid and should not be used.
* *
* \param cv A libcaca canvas. * \param cv A libcaca canvas.
* \param width The desired canvas width. * \param width The desired canvas width.
* \param height The desired canvas height. * \param height The desired canvas height.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int caca_set_canvas_size(caca_canvas_t *cv, int width, int height) int caca_set_canvas_size(caca_canvas_t *cv, int width, int height)
skipping to change at line 365 skipping to change at line 367
return min + (int)((1.0 * (max - min)) * rand() / (RAND_MAX + 1.0)); return min + (int)((1.0 * (max - min)) * rand() / (RAND_MAX + 1.0));
} }
/* /*
* XXX: The following functions are local. * XXX: The following functions are local.
*/ */
int caca_resize(caca_canvas_t *cv, int width, int height) int caca_resize(caca_canvas_t *cv, int width, int height)
{ {
int x, y, f, old_width, old_height, new_size, old_size; int x, y, f, old_width, old_height, old_size;
/* Check for overflow */
int new_size = width * height;
if (new_size < 0 || (width > 0 && new_size / width != height))
{
seterrno(EOVERFLOW);
return -1;
}
old_width = cv->width; old_width = cv->width;
old_height = cv->height; old_height = cv->height;
old_size = old_width * old_height; old_size = old_width * old_height;
_caca_save_frame_info(cv); _caca_save_frame_info(cv);
/* Preload new width and height values into the canvas to optimise /* Preload new width and height values into the canvas to optimise
* dirty rectangle handling */ * dirty rectangle handling */
cv->width = width; cv->width = width;
cv->height = height; cv->height = height;
new_size = width * height;
/* If width or height is smaller (or both), we have the opportunity to /* If width or height is smaller (or both), we have the opportunity to
* reduce or even remove dirty rectangles */ * reduce or even remove dirty rectangles */
if(width < old_width || height < old_height) if(width < old_width || height < old_height)
_caca_clip_dirty_rect_list(cv); _caca_clip_dirty_rect_list(cv);
/* Step 1: if new area is bigger, resize the memory area now. */ /* Step 1: if new area is bigger, resize the memory area now. */
if(new_size > old_size) if(new_size > old_size)
{ {
for(f = 0; f < cv->framecount; f++) for(f = 0; f < cv->framecount; f++)
skipping to change at line 525 skipping to change at line 534
cv->frames[f].width = width; cv->frames[f].width = width;
cv->frames[f].height = height; cv->frames[f].height = height;
} }
/* Reset the current frame shortcuts */ /* Reset the current frame shortcuts */
_caca_load_frame_info(cv); _caca_load_frame_info(cv);
return 0; return 0;
} }
/*
* XXX: The following functions are aliases.
*/
cucul_canvas_t * cucul_create_canvas(int, int) CACA_ALIAS(caca_create_canvas);
int cucul_manage_canvas(cucul_canvas_t *, int (*)(void *), void *)
CACA_ALIAS(caca_manage_canvas);
int cucul_unmanage_canvas(cucul_canvas_t *, int (*)(void *), void *)
CACA_ALIAS(caca_unmanage_canvas);
int cucul_set_canvas_size(cucul_canvas_t *, int, int)
CACA_ALIAS(caca_set_canvas_size);
int cucul_get_canvas_width(cucul_canvas_t const *)
CACA_ALIAS(caca_get_canvas_width);
int cucul_get_canvas_height(cucul_canvas_t const *)
CACA_ALIAS(caca_get_canvas_height);
uint32_t const * cucul_get_canvas_chars(cucul_canvas_t const *)
CACA_ALIAS(caca_get_canvas_chars);
uint32_t const * cucul_get_canvas_attrs(cucul_canvas_t const *)
CACA_ALIAS(caca_get_canvas_attrs);
int cucul_free_canvas(cucul_canvas_t *) CACA_ALIAS(caca_free_canvas);
int cucul_rand(int, int) CACA_ALIAS(caca_rand);
 End of changes. 6 change blocks. 
5 lines changed or deleted 14 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)