forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
decode_file.cpp
48 lines (36 loc) · 1020 Bytes
/
decode_file.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
// Aseprite Document IO Library
// Copyright (c) 2021 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/decode_file.h"
#include "dio/aseprite_decoder.h"
#include "dio/decoder.h"
#include "dio/detect_format.h"
#include "dio/file_interface.h"
#include "doc/document.h"
#include <cassert>
namespace dio {
bool decode_file(DecodeDelegate* delegate,
FileInterface* f)
{
assert(delegate);
assert(f);
uint8_t buf[12];
size_t n = f->readBytes(&buf[0], 12);
FileFormat format = detect_format_by_file_content_bytes(&buf[0], n);
f->seek(0); // Rewind
Decoder* decoder = nullptr;
switch (format) {
case FileFormat::ASE_ANIMATION: decoder = new AsepriteDecoder; break;
}
bool result = false;
if (decoder) {
decoder->initialize(delegate, f);
result = decoder->decode();
delete decoder;
}
return result;
}
} // namespace dio