diff options
Diffstat (limited to 'lib/picture/manage.c')
-rw-r--r-- | lib/picture/manage.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/lib/picture/manage.c b/lib/picture/manage.c new file mode 100644 index 0000000..11e5b24 --- /dev/null +++ b/lib/picture/manage.c @@ -0,0 +1,75 @@ +/* **************************************************************************** + * picture/manage.c -- picture management. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> + * + * This file is part of libcasio. + * libcasio is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libcasio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libcasio; if not, see <http://www.gnu.org/licenses/>. + * ************************************************************************* */ +#include "internals.h" +# define alloc_pixels(W, H) \ + casio_alloc(sizeof(casio_pixel_t*) \ + * (H) + sizeof(casio_pixel_t) * (W) * (H), 1) +# define prepare_pixels(I, W, H) { \ + unsigned int PIXPREP_y; \ + casio_pixel_t *PIXPREP_line = (casio_pixel_t*)&(I)[(H)]; \ + for (PIXPREP_y = 0; PIXPREP_y < (H); PIXPREP_y++) { \ + (I)[PIXPREP_y] = PIXPREP_line; \ + PIXPREP_line += (W); \ + }} + +CASIO_EXTERN(int) casio_prepare_picture(casio_picture_t **picturep, + unsigned int width, unsigned int height) +{ + casio_pixel_t **pixels; + casio_picture_t *picture; + + if (!(pixels = alloc_pixels(width, height))) + return (casio_error_alloc); + if (!(*picturep = (picture = (casio_alloc(1, sizeof(casio_picture_t)))))) { + casio_free(pixels); + return (casio_error_alloc); + } + + picture->width = width; + picture->height = height; + picture->pixels = pixels; + + prepare_pixels(pixels, width, height) + + return (casio_ok); +} + +CASIO_EXTERN(void) casio_free_picture(casio_picture_t *picture) +{ + if (!picture) + return ; + + casio_free(picture->pixels); + casio_free(picture); +} + +CASIO_EXTERN(int) casio_get_picture_dimensions(casio_picture_t *picture, + unsigned int *widthp, unsigned int *heightp) +{ + *widthp = picture->width; + *heightp = picture->height; + return (casio_ok); +} + +CASIO_EXTERN(int) casio_access_pixels(casio_picture_t *picture, + casio_pixel_t ***pixelsp) +{ + *pixelsp = picture->pixels; + return (casio_ok); +} |