1 | // Aseprite Document Library |
---|---|
2 | // Copyright (c) 2001-2018 David Capello |
3 | // |
4 | // This file is released under the terms of the MIT license. |
5 | // Read LICENSE.txt for more information. |
6 | |
7 | #ifdef HAVE_CONFIG_H |
8 | #include "config.h" |
9 | #endif |
10 | |
11 | #include "doc/cel_io.h" |
12 | |
13 | #include "base/serialization.h" |
14 | #include "doc/cel.h" |
15 | #include "doc/subobjects_io.h" |
16 | |
17 | #include <iostream> |
18 | #include <memory> |
19 | |
20 | namespace doc { |
21 | |
22 | using namespace base::serialization; |
23 | using namespace base::serialization::little_endian; |
24 | |
25 | void write_cel(std::ostream& os, const Cel* cel) |
26 | { |
27 | write32(os, cel->id()); |
28 | write16(os, cel->frame()); |
29 | write32(os, cel->dataRef()->id()); |
30 | } |
31 | |
32 | Cel* read_cel(std::istream& is, SubObjectsIO* subObjects, bool setId) |
33 | { |
34 | ObjectId id = read32(is); |
35 | frame_t frame(read16(is)); |
36 | ObjectId celDataId = read32(is); |
37 | CelDataRef celData(subObjects->getCelDataRef(celDataId)); |
38 | if (!celData) |
39 | return nullptr; |
40 | |
41 | std::unique_ptr<Cel> cel(new Cel(frame, celData)); |
42 | if (setId) |
43 | cel->setId(id); |
44 | return cel.release(); |
45 | } |
46 | |
47 | } |
48 |