fixed incorrect aseprite linked-cel parsing

This commit is contained in:
Noel Berry 2020-09-16 21:33:41 -07:00
parent e1d2e3066e
commit 8ed97d133e
2 changed files with 43 additions and 40 deletions

View File

@ -48,6 +48,18 @@ Aseprite::Aseprite(const Aseprite& src)
palette = src.palette;
}
Aseprite::Aseprite(Aseprite&& src) noexcept
{
mode = src.mode;
width = src.width;
height = src.height;
layers = std::move(src.layers);
frames = std::move(src.frames);
tags = std::move(src.tags);
slices = std::move(src.slices);
palette = std::move(src.palette);
}
Aseprite& Aseprite::operator=(const Aseprite& src)
{
mode = src.mode;
@ -61,18 +73,6 @@ Aseprite& Aseprite::operator=(const Aseprite& src)
return *this;
}
Aseprite::Aseprite(Aseprite&& src) noexcept
{
mode = src.mode;
width = src.width;
height = src.height;
layers = std::move(src.layers);
frames = std::move(src.frames);
tags = std::move(src.tags);
slices = std::move(src.slices);
palette = std::move(src.palette);
}
Aseprite& Aseprite::operator=(Aseprite&& src) noexcept
{
mode = src.mode;
@ -175,7 +175,7 @@ void Aseprite::Parse(Stream& stream)
switch (chunkType)
{
case Chunks::Layer: ParseLayer(stream, i); break;
case Chunks::Cel: ParseCel(stream, i, (size_t)chunkEnd); break;
case Chunks::Cel: ParseCel(stream, i, chunkEnd); break;
case Chunks::Palette: ParsePalette(stream, i); break;
case Chunks::UserData: ParseUserData(stream, i); break;
case Chunks::FrameTags: ParseTag(stream, i); break;
@ -221,7 +221,6 @@ void Aseprite::ParseCel(Stream& stream, int frameIndex, size_t maxPosition)
cel->y = stream.read<uint16_t>(Endian::Little);
cel->alpha = stream.read<uint8_t>(Endian::Little);
cel->linked_frame_index = -1;
cel->linked_cel_index = -1;
auto celType = stream.read<uint16_t>(Endian::Little);
stream.seek(stream.position() + 7);
@ -248,8 +247,6 @@ void Aseprite::ParseCel(Stream& stream, int frameIndex, size_t maxPosition)
auto size = maxPosition - stream.position();
if (size > INT32_MAX)
size = INT32_MAX;
if (size < 0)
size = 0;
char* buffer = new char[size];
stream.read(buffer, size);
@ -289,7 +286,6 @@ void Aseprite::ParseCel(Stream& stream, int frameIndex, size_t maxPosition)
else if (celType == 1)
{
cel->linked_frame_index = stream.read<uint16_t>(Endian::Little);
cel->linked_cel_index = static_cast<int>(frame.cels.count() - 1);
}
// draw to frame if visible
@ -415,7 +411,15 @@ void Aseprite::RenderCel(Cel* cel, Frame* frame)
Layer& layer = layers[cel->layer_index];
while (cel->linked_frame_index >= 0)
cel = &(frames[cel->linked_frame_index].cels[cel->linked_cel_index]);
{
auto& frame = frames[cel->linked_frame_index];
for (auto& it : frame.cels)
if (it.layer_index == cel->layer_index)
{
cel = &it;
break;
}
}
int t;
unsigned char opacity = MUL_UN8(cel->alpha, layer.alpha, t);

View File

@ -69,7 +69,6 @@ namespace Blah
{
int layer_index = 0;
int linked_frame_index = 0;
int linked_cel_index = 0;
int x = 0;
int y = 0;
unsigned char alpha = 0;
@ -132,8 +131,8 @@ namespace Blah
Aseprite(const char* path);
Aseprite(Stream& stream);
Aseprite(const Aseprite& src);
Aseprite& operator=(const Aseprite& src);
Aseprite(Aseprite&& src) noexcept;
Aseprite& operator=(const Aseprite& src);
Aseprite& operator=(Aseprite&& src) noexcept;
~Aseprite();