1 | // Aseprite Document Library |
2 | // Copyright (c) 2019-2020 Igara Studio S.A. |
3 | // |
4 | // This file is released under the terms of the MIT license. |
5 | // Read LICENSE.txt for more information. |
6 | |
7 | #ifndef DOC_TILE_H_INCLUDED |
8 | #define DOC_TILE_H_INCLUDED |
9 | #pragma once |
10 | |
11 | #include "base/ints.h" |
12 | |
13 | namespace doc { |
14 | |
15 | typedef uint32_t tile_t; // Same as color_t |
16 | typedef uint32_t tile_index; |
17 | typedef uint32_t tileset_index; |
18 | typedef uint32_t tile_flags; |
19 | |
20 | const uint32_t tile_i_shift = 0; // Tile index |
21 | const uint32_t tile_f_shift = 28; // Flags (flip, rotation) |
22 | |
23 | const uint32_t notile = 0; |
24 | const uint32_t tile_i_mask = 0x1fffffff; |
25 | const uint32_t tile_f_mask = 0xe0000000; // 3 flags |
26 | const uint32_t tile_f_flipx = 0x20000000; |
27 | const uint32_t tile_f_flipy = 0x40000000; |
28 | const uint32_t tile_f_90cw = 0x80000000; |
29 | |
30 | inline tile_index tile_geti(const tile_t t) { |
31 | return ((t & tile_i_mask) >> tile_i_shift); |
32 | } |
33 | |
34 | inline tile_flags tile_getf(const tile_t t) { |
35 | return (t & tile_f_mask); |
36 | } |
37 | |
38 | inline tile_t tile(const tile_index i, const tile_flags f) { |
39 | return (((i << tile_i_shift) & tile_i_mask) | |
40 | (f & tile_f_mask)); |
41 | } |
42 | |
43 | } // namespace doc |
44 | |
45 | #endif |
46 | |