annotate libmlk-core/mlk/core/image.c @ 453:49e7024f5455

core: image -> mlk_image
author David Demelier <markand@malikania.fr>
date Sat, 18 Feb 2023 20:55:12 +0100
parents 773a082f0b91
children bc5483849614
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
1 /*
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
2 * image.c -- basic image management
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
3 *
445
773a082f0b91 misc: update copyright years
David Demelier <markand@malikania.fr>
parents: 437
diff changeset
4 * Copyright (c) 2020-2023 David Demelier <markand@malikania.fr>
4
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
5 *
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
6 * Permission to use, copy, modify, and/or distribute this software for any
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
7 * purpose with or without fee is hereby granted, provided that the above
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
8 * copyright notice and this permission notice appear in all copies.
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
9 *
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
17 */
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
18
5
b5c649b6367b core: implement sprites, closes #2440
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
19 #include <assert.h>
4
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
20
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
21 #include <SDL_image.h>
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
22
169
eb0a7ab71023 misc: extreme cleanup, closes #2506
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
23 #include "error.h"
111
f17890fe144b image: can load a texture directly
David Demelier <markand@malikania.fr>
parents: 94
diff changeset
24 #include "texture.h"
f17890fe144b image: can load a texture directly
David Demelier <markand@malikania.fr>
parents: 94
diff changeset
25 #include "window.h"
f17890fe144b image: can load a texture directly
David Demelier <markand@malikania.fr>
parents: 94
diff changeset
26 #include "window_p.h"
4
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
27
112
40f22a8188d2 image: set dimensions
David Demelier <markand@malikania.fr>
parents: 111
diff changeset
28 static void
40f22a8188d2 image: set dimensions
David Demelier <markand@malikania.fr>
parents: 111
diff changeset
29 dimensions(struct texture *tex)
40f22a8188d2 image: set dimensions
David Demelier <markand@malikania.fr>
parents: 111
diff changeset
30 {
40f22a8188d2 image: set dimensions
David Demelier <markand@malikania.fr>
parents: 111
diff changeset
31 int w, h;
40f22a8188d2 image: set dimensions
David Demelier <markand@malikania.fr>
parents: 111
diff changeset
32
40f22a8188d2 image: set dimensions
David Demelier <markand@malikania.fr>
parents: 111
diff changeset
33 if (SDL_QueryTexture(tex->handle, NULL, NULL, &w, &h) < 0)
40f22a8188d2 image: set dimensions
David Demelier <markand@malikania.fr>
parents: 111
diff changeset
34 tex->w = tex->h = 0;
40f22a8188d2 image: set dimensions
David Demelier <markand@malikania.fr>
parents: 111
diff changeset
35 else {
40f22a8188d2 image: set dimensions
David Demelier <markand@malikania.fr>
parents: 111
diff changeset
36 tex->w = w;
40f22a8188d2 image: set dimensions
David Demelier <markand@malikania.fr>
parents: 111
diff changeset
37 tex->h = h;
40f22a8188d2 image: set dimensions
David Demelier <markand@malikania.fr>
parents: 111
diff changeset
38 }
40f22a8188d2 image: set dimensions
David Demelier <markand@malikania.fr>
parents: 111
diff changeset
39 }
40f22a8188d2 image: set dimensions
David Demelier <markand@malikania.fr>
parents: 111
diff changeset
40
298
196264679079 misc: remove usage of bool
David Demelier <markand@malikania.fr>
parents: 243
diff changeset
41 int
453
49e7024f5455 core: image -> mlk_image
David Demelier <markand@malikania.fr>
parents: 445
diff changeset
42 mlk_image_open(struct texture *tex, const char *path)
4
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
43 {
94
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 59
diff changeset
44 assert(tex);
5
b5c649b6367b core: implement sprites, closes #2440
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
45 assert(path);
b5c649b6367b core: implement sprites, closes #2440
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
46
111
f17890fe144b image: can load a texture directly
David Demelier <markand@malikania.fr>
parents: 94
diff changeset
47 if (!(tex->handle = IMG_LoadTexture(RENDERER(), path)))
437
e1eebc6bf25d man: initial import
David Demelier <markand@malikania.fr>
parents: 431
diff changeset
48 return MLK_ERR_SDL;
39
9d1421c09dfb core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents: 21
diff changeset
49
112
40f22a8188d2 image: set dimensions
David Demelier <markand@malikania.fr>
parents: 111
diff changeset
50 dimensions(tex);
40f22a8188d2 image: set dimensions
David Demelier <markand@malikania.fr>
parents: 111
diff changeset
51
298
196264679079 misc: remove usage of bool
David Demelier <markand@malikania.fr>
parents: 243
diff changeset
52 return 0;
4
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
53 }
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
54
298
196264679079 misc: remove usage of bool
David Demelier <markand@malikania.fr>
parents: 243
diff changeset
55 int
453
49e7024f5455 core: image -> mlk_image
David Demelier <markand@malikania.fr>
parents: 445
diff changeset
56 mlk_image_openmem(struct texture *tex, const void *buffer, size_t size)
4
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
57 {
5
b5c649b6367b core: implement sprites, closes #2440
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
58 assert(buffer);
b5c649b6367b core: implement sprites, closes #2440
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
59
4
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
60 SDL_RWops *ops = SDL_RWFromConstMem(buffer, size);
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
61
298
196264679079 misc: remove usage of bool
David Demelier <markand@malikania.fr>
parents: 243
diff changeset
62 if (!ops || !(tex->handle = IMG_LoadTexture_RW(RENDERER(), ops, 1)))
437
e1eebc6bf25d man: initial import
David Demelier <markand@malikania.fr>
parents: 431
diff changeset
63 return MLK_ERR_SDL;
4
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
64
112
40f22a8188d2 image: set dimensions
David Demelier <markand@malikania.fr>
parents: 111
diff changeset
65 dimensions(tex);
40f22a8188d2 image: set dimensions
David Demelier <markand@malikania.fr>
parents: 111
diff changeset
66
298
196264679079 misc: remove usage of bool
David Demelier <markand@malikania.fr>
parents: 243
diff changeset
67 return 0;
4
cd58eabb7fb4 core: implement basic images, closes #2441
David Demelier <markand@malikania.fr>
parents:
diff changeset
68 }