forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecoder.cpp
More file actions
94 lines (79 loc) · 1.64 KB
/
Copy pathdecoder.cpp
File metadata and controls
94 lines (79 loc) · 1.64 KB
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
85
86
87
88
89
90
91
92
93
94
// Aseprite Document IO Library
// Copyright (c) 2018 Igara Studio S.A.
// Copyright (c) 2017 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#include "dio/decoder.h"
#include "dio/file_interface.h"
#include "doc/document.h"
namespace dio {
Decoder::Decoder()
: m_delegate(nullptr)
, m_f(nullptr)
{
}
Decoder::~Decoder()
{
}
void Decoder::initialize(DecodeDelegate* delegate, FileInterface* f)
{
m_delegate = delegate;
m_f = f;
}
uint8_t Decoder::read8()
{
return m_f->read8();
}
uint16_t Decoder::read16()
{
int b1 = m_f->read8();
int b2 = m_f->read8();
if (m_f->ok()) {
return ((b2 << 8) | b1); // Little endian
}
else
return 0;
}
uint32_t Decoder::read32()
{
int b1 = m_f->read8();
int b2 = m_f->read8();
int b3 = m_f->read8();
int b4 = m_f->read8();
if (m_f->ok()) {
// Little endian
return ((b4 << 24) | (b3 << 16) | (b2 << 8) | b1);
}
else
return 0;
}
uint64_t Decoder::read64()
{
int b1 = m_f->read8();
int b2 = m_f->read8();
int b3 = m_f->read8();
int b4 = m_f->read8();
int b5 = m_f->read8();
int b6 = m_f->read8();
int b7 = m_f->read8();
int b8 = m_f->read8();
if (m_f->ok()) {
// Little endian
return (((long long)b8 << 56) |
((long long)b7 << 48) |
((long long)b6 << 40) |
((long long)b5 << 32) |
((long long)b4 << 24) |
((long long)b3 << 16) |
((long long)b2 << 8) |
(long long)b1);
}
else
return 0;
}
size_t Decoder::readBytes(uint8_t* buf, size_t n)
{
return m_f->readBytes(buf, n);
}
} // namespace dio