1// Aseprite Document IO Library
2// Copyright (c) 2018-2020 Igara Studio S.A.
3// Copyright (c) 2001-2018 David Capello
4//
5// This file is released under the terms of the MIT license.
6// Read LICENSE.txt for more information.
7
8#ifndef DIO_ASEPRITE_COMMON_H_INCLUDED
9#define DIO_ASEPRITE_COMMON_H_INCLUDED
10#pragma once
11
12#include <map>
13#include <string>
14
15#define ASE_FILE_MAGIC 0xA5E0
16#define ASE_FILE_FRAME_MAGIC 0xF1FA
17
18#define ASE_FILE_FLAG_LAYER_WITH_OPACITY 1
19
20#define ASE_FILE_CHUNK_FLI_COLOR2 4
21#define ASE_FILE_CHUNK_FLI_COLOR 11
22#define ASE_FILE_CHUNK_LAYER 0x2004
23#define ASE_FILE_CHUNK_CEL 0x2005
24#define ASE_FILE_CHUNK_CEL_EXTRA 0x2006
25#define ASE_FILE_CHUNK_COLOR_PROFILE 0x2007
26#define ASE_FILE_CHUNK_EXTERNAL_FILE 0x2008
27#define ASE_FILE_CHUNK_MASK 0x2016
28#define ASE_FILE_CHUNK_PATH 0x2017
29#define ASE_FILE_CHUNK_TAGS 0x2018
30#define ASE_FILE_CHUNK_PALETTE 0x2019
31#define ASE_FILE_CHUNK_USER_DATA 0x2020
32#define ASE_FILE_CHUNK_SLICES 0x2021 // Deprecated chunk (used on dev versions only between v1.2-beta7 and v1.2-beta8)
33#define ASE_FILE_CHUNK_SLICE 0x2022
34#define ASE_FILE_CHUNK_TILESET 0x2023
35
36#define ASE_FILE_LAYER_IMAGE 0
37#define ASE_FILE_LAYER_GROUP 1
38#define ASE_FILE_LAYER_TILEMAP 2
39
40#define ASE_FILE_RAW_CEL 0
41#define ASE_FILE_LINK_CEL 1
42#define ASE_FILE_COMPRESSED_CEL 2
43#define ASE_FILE_COMPRESSED_TILEMAP 3
44
45#define ASE_FILE_NO_COLOR_PROFILE 0
46#define ASE_FILE_SRGB_COLOR_PROFILE 1
47#define ASE_FILE_ICC_COLOR_PROFILE 2
48
49#define ASE_COLOR_PROFILE_FLAG_GAMMA 1
50
51#define ASE_PALETTE_FLAG_HAS_NAME 1
52
53#define ASE_USER_DATA_FLAG_HAS_TEXT 1
54#define ASE_USER_DATA_FLAG_HAS_COLOR 2
55
56#define ASE_CEL_EXTRA_FLAG_PRECISE_BOUNDS 1
57
58#define ASE_SLICE_FLAG_HAS_CENTER_BOUNDS 1
59#define ASE_SLICE_FLAG_HAS_PIVOT_POINT 2
60
61#define ASE_TILESET_FLAG_EXTERNAL_FILE 1
62#define ASE_TILESET_FLAG_EMBEDDED 2
63#define ASE_TILESET_FLAG_ZERO_IS_NOTILE 4
64
65namespace dio {
66
67struct AsepriteHeader {
68 long pos; // TODO used by the encoder in app project
69
70 uint32_t size;
71 uint16_t magic;
72 uint16_t frames;
73 uint16_t width;
74 uint16_t height;
75 uint16_t depth;
76 uint32_t flags;
77 uint16_t speed; // Deprecated, use "duration" of AsepriteFrameHeader
78 uint32_t next;
79 uint32_t frit;
80 uint8_t transparent_index;
81 uint8_t ignore[3];
82 uint16_t ncolors;
83 uint8_t pixel_width;
84 uint8_t pixel_height;
85 int16_t grid_x;
86 int16_t grid_y;
87 uint16_t grid_width;
88 uint16_t grid_height;
89};
90
91struct AsepriteFrameHeader {
92 uint32_t size;
93 uint16_t magic;
94 uint32_t chunks;
95 uint16_t duration;
96};
97
98struct AsepriteChunk {
99 int type;
100 int start;
101};
102
103struct AsepriteExternalFiles {
104 std::map<uint32_t, std::string> to_fn; // ID -> filename
105 std::map<std::string, uint32_t> to_id; // filename -> ID
106 uint32_t lastid = 0;
107};
108
109} // namespace dio
110
111#endif
112