forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid_io.cpp
84 lines (73 loc) · 1.93 KB
/
grid_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Aseprite Document Library
// Copyright (C) 2019 Igara Studio S.A.
//
// 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/grid_io.h"
#include "base/serialization.h"
#include "doc/image.h"
#include "doc/image_io.h"
#include "doc/grid.h"
#include <iostream>
namespace doc {
using namespace base::serialization;
using namespace base::serialization::little_endian;
bool write_grid(std::ostream& os, const Grid& grid)
{
write32(os, grid.tileSize().w);
write32(os, grid.tileSize().h);
write32(os, grid.origin().x);
write32(os, grid.origin().y);
write32(os, grid.tileCenter().x);
write32(os, grid.tileCenter().y);
write32(os, grid.tileOffset().x);
write32(os, grid.tileOffset().y);
write32(os, grid.oddRowOffset().x);
write32(os, grid.oddRowOffset().y);
write32(os, grid.oddColOffset().x);
write32(os, grid.oddColOffset().y);
write8(os, grid.hasMask());
if (grid.hasMask())
return write_image(os, grid.mask().get());
else
return true;
}
Grid read_grid(std::istream& is)
{
gfx::Size tileSize;
gfx::Point origin;
gfx::Point tileCenter;
gfx::Point tileOffset;
gfx::Point oddRowOffset;
gfx::Point oddColOffset;
tileSize.w = read32(is);
tileSize.h = read32(is);
origin.x = read32(is);
origin.y = read32(is);
tileCenter.x = read32(is);
tileCenter.y = read32(is);
tileOffset.x = read32(is);
tileOffset.y = read32(is);
oddRowOffset.x = read32(is);
oddRowOffset.y = read32(is);
oddColOffset.x = read32(is);
oddColOffset.y = read32(is);
bool hasMask = read8(is);
Grid grid;
grid.tileSize(tileSize);
grid.origin(origin);
grid.tileCenter(tileCenter);
grid.tileOffset(tileOffset);
grid.oddRowOffset(oddRowOffset);
grid.oddColOffset(oddColOffset);
if (hasMask) {
ImageRef mask(read_image(is));
if (mask)
grid.setMask(mask);
}
return grid;
}
} // namespace doc