comparison src/core/image.c @ 59:52792b863ff7

misc: separate core from game
author David Demelier <markand@malikania.fr>
date Tue, 21 Jan 2020 12:42:33 +0100
parents src/image.c@9d1421c09dfb
children ed72843a7194
comparison
equal deleted inserted replaced
58:d7d88ac30611 59:52792b863ff7
1 /*
2 * image.c -- basic image management
3 *
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #include <assert.h>
20 #include <stdbool.h>
21
22 #include <SDL_image.h>
23
24 #include "error_p.h"
25 #include "texture_p.h"
26
27 struct texture *
28 image_openf(const char *path)
29 {
30 assert(path);
31
32 SDL_Surface *surface = IMG_Load(path);
33
34 if (!surface) {
35 error_sdl();
36 return NULL;
37 }
38
39 return texture_from_surface(surface);
40 }
41
42 struct texture *
43 image_openb(const void *buffer, size_t size)
44 {
45 assert(buffer);
46
47 SDL_RWops *ops = SDL_RWFromConstMem(buffer, size);
48 SDL_Surface *surface;
49
50 if (!ops || !(surface = IMG_Load_RW(ops, true))) {
51 error_sdl();
52 return NULL;
53 }
54
55 return texture_from_surface(surface);
56 }