2014-10-21 09:21:31 +08:00
|
|
|
// Aseprite Document Library
|
|
|
|
|
// Copyright (c) 2001-2014 David Capello
|
|
|
|
|
//
|
|
|
|
|
// 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"
|
|
|
|
|
#include "base/unique_ptr.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/cel.h"
|
2011-03-27 04:40:55 +08:00
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
// Serialized Cel data:
|
|
|
|
|
//
|
2012-01-06 06:45:03 +08:00
|
|
|
// WORD Frame
|
|
|
|
|
// WORD Image index
|
|
|
|
|
// WORD[2] X, Y
|
|
|
|
|
// WORD Opacity
|
2011-03-27 04:40:55 +08:00
|
|
|
|
|
|
|
|
void write_cel(std::ostream& os, Cel* cel)
|
|
|
|
|
{
|
|
|
|
|
// ObjectId cel_id = objects->addObject(cel);
|
|
|
|
|
// write_raw_uint32(cel_id);
|
|
|
|
|
|
2014-07-30 12:28:15 +08:00
|
|
|
write16(os, cel->frame());
|
|
|
|
|
write16(os, cel->imageIndex());
|
|
|
|
|
write16(os, (int16_t)cel->x());
|
|
|
|
|
write16(os, (int16_t)cel->y());
|
|
|
|
|
write16(os, cel->opacity());
|
2011-03-27 04:40:55 +08:00
|
|
|
|
|
|
|
|
// objects->removeObject(cel_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Cel* read_cel(std::istream& is)
|
|
|
|
|
{
|
|
|
|
|
// ObjectId cel_id = read32();
|
|
|
|
|
|
2014-12-29 07:39:11 +08:00
|
|
|
frame_t frame(read16(is));
|
2011-03-27 04:40:55 +08:00
|
|
|
int imageIndex = read16(is);
|
|
|
|
|
int x = (int16_t)read16(is);
|
|
|
|
|
int y = (int16_t)read16(is);
|
|
|
|
|
int opacity = read16(is);
|
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
base::UniquePtr<Cel> cel(new Cel(frame, imageIndex));
|
2011-03-27 04:40:55 +08:00
|
|
|
|
2011-03-28 11:24:27 +08:00
|
|
|
cel->setPosition(x, y);
|
|
|
|
|
cel->setOpacity(opacity);
|
2011-03-27 04:40:55 +08:00
|
|
|
|
|
|
|
|
// objects->insertObject(cel_id, cel);
|
|
|
|
|
return cel.release();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|