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