2014-10-21 09:21:31 +08:00
|
|
|
// Aseprite Document Library
|
2018-08-09 04:27:26 +08:00
|
|
|
// Copyright (c) 2001-2018 David Capello
|
2014-10-21 09:21:31 +08:00
|
|
|
//
|
|
|
|
|
// This file is released under the terms of the MIT license.
|
|
|
|
|
// Read LICENSE.txt for more information.
|
2011-03-27 04:40:55 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2011-03-27 04:40:55 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
2011-03-27 04:40:55 +08:00
|
|
|
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/cel_io.h"
|
2011-03-27 04:40:55 +08:00
|
|
|
|
|
|
|
|
#include "base/serialization.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/cel.h"
|
2015-01-04 21:58:14 +08:00
|
|
|
#include "doc/subobjects_io.h"
|
2011-03-27 04:40:55 +08:00
|
|
|
|
|
|
|
|
#include <iostream>
|
2018-08-09 04:27:26 +08:00
|
|
|
#include <memory>
|
2011-03-27 04:40:55 +08:00
|
|
|
|
2014-10-21 09:21:31 +08:00
|
|
|
namespace doc {
|
2011-03-27 04:40:55 +08:00
|
|
|
|
|
|
|
|
using namespace base::serialization;
|
|
|
|
|
using namespace base::serialization::little_endian;
|
|
|
|
|
|
2015-04-03 07:42:43 +08:00
|
|
|
void write_cel(std::ostream& os, const Cel* cel)
|
2011-03-27 04:40:55 +08:00
|
|
|
{
|
2015-02-09 22:40:43 +08:00
|
|
|
write32(os, cel->id());
|
2014-07-30 12:28:15 +08:00
|
|
|
write16(os, cel->frame());
|
2015-02-09 22:40:43 +08:00
|
|
|
write32(os, cel->dataRef()->id());
|
2011-03-27 04:40:55 +08:00
|
|
|
}
|
|
|
|
|
|
2015-04-09 07:05:05 +08:00
|
|
|
Cel* read_cel(std::istream& is, SubObjectsIO* subObjects, bool setId)
|
2011-03-27 04:40:55 +08:00
|
|
|
{
|
2015-02-09 22:40:43 +08:00
|
|
|
ObjectId id = read32(is);
|
2014-12-29 07:39:11 +08:00
|
|
|
frame_t frame(read16(is));
|
2015-02-09 22:40:43 +08:00
|
|
|
ObjectId celDataId = read32(is);
|
|
|
|
|
CelDataRef celData(subObjects->getCelDataRef(celDataId));
|
2015-04-15 23:20:41 +08:00
|
|
|
if (!celData)
|
|
|
|
|
return nullptr;
|
2015-01-04 21:58:14 +08:00
|
|
|
|
2018-08-09 04:27:26 +08:00
|
|
|
std::unique_ptr<Cel> cel(new Cel(frame, celData));
|
2015-04-09 07:05:05 +08:00
|
|
|
if (setId)
|
|
|
|
|
cel->setId(id);
|
2011-03-27 04:40:55 +08:00
|
|
|
return cel.release();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|