tinygi

view src/image.c @ 2:72752a1b3dbe

images and shapes
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 21 Jul 2015 04:30:00 +0300
parents
children
line source
1 #include <stdlib.h>
2 #include "tgi_impl.h"
3 #include "image.h"
5 void tgi_init_image(struct image *img)
6 {
7 img->width = img->height = 0;
8 img->pixels = 0;
9 }
11 void tgi_destroy_image(struct image *img)
12 {
13 if(img) {
14 free(img->pixels);
15 }
16 }
18 int tgi_resize_image(struct image *img, int xsz, int ysz)
19 {
20 float *npix = malloc(xsz * ysz * 4 * sizeof *npix);
21 if(!npix) {
22 tgi_log("failed to allocate %dx%d image\n", xsz, ysz);
23 return -1;
24 }
26 free(img->pixels);
27 img->pixels = npix;
28 img->width = xsz;
29 img->height = ysz;
30 return 0;
31 }