Skip to content

Conversation

@mertenpopp
Copy link
Contributor

I agree that my contributions are licensed under the Flic license, and agree to future changes to the licensing.

@dacap
Copy link
Member

dacap commented Oct 31, 2024

Hi @mertenpopp, previously we were ignoring the number of packets but then it was changed to avoid crashes reading ill-formed files:

bfa1944#diff-b4f3931f9cd1157a04242ce6d73c085199e5b83201a606a1522c4b9843033b50L171

From https://www.compuphase.com/flic.htm#BYTE_RUN I found this about this byte run chunk:

Each line of the image is compressed separately, starting from the top of the image. The first byte of each line is the packet count. It is a holdover from the FLI format and it should be ignored, because it is now possible to have more than 255 packets on a line (for FLC files). Instead, the width of the frame image now is the criterion for decoding: continue decompressing until the number of uncompressed pixels becomes equal to the image width. However, some players still rely on this pack count, so FLIC compilers should still generate them and only set it to zero when the packet count indeed does exceed 255.

So there are still some conditions to check:

  1. if npackets is not 0, we must use the npackets field,
  2. if npackets is 0, we have to use the x < width as stop condition.

If you have a .flc file to share to check/test this it would be great.

@mertenpopp
Copy link
Contributor Author

mertenpopp commented Nov 10, 2024

Hi @dacap,

the fix was necessary to decode the animations for the Linux version of the game Airline Tycoon Deluxe correctly.

I attached an animation file and a screenshot that shows how it looks like WITHOUT the fix.
Anim.zip

With the fix, everything looks fine.

What do you propose? One could use:
int npackets = m_file->read8();
if (npackets == 0) { npackets = INT_MAX; }
while (m_file->ok() && npackets-- != 0 && x < m_width) {...}

Best,
Merten

@dacap dacap self-assigned this Jan 2, 2025
@mippy5
Copy link

mippy5 commented May 25, 2025

I recently came across this issue and discovered the same fix. The resulting image data appears corrupted without it.

@dacap
Copy link
Member

dacap commented May 28, 2025

I'll try to review and merge this change today 🙏

@dacap
Copy link
Member

dacap commented May 28, 2025

Thanks a lot @mertenpopp for the patch and @mippy5 for the feedback. I'll merge this as it's.

What do you propose? One could use:
int npackets = m_file->read8();
if (npackets == 0) { npackets = INT_MAX; }
while (m_file->ok() && npackets-- != 0 && x < m_width) {...}

I'll see what we can do after applying this patch.

@dacap dacap merged commit 3027cc1 into aseprite:main May 28, 2025
dacap added a commit that referenced this pull request May 28, 2025
BRUN chunk can have npackets field=0 in case we have more than 255
packets in FLC files, but FLI files still have this npackets field in
use.

From #3 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants