kettek / apng

APNG decoder and encoder for golang
Other
65 stars 9 forks source link

Can't decode seemingly fine apngs #1

Closed Lucki closed 4 years ago

Lucki commented 4 years ago

Hi there,

thanks for making this library. Picking it up and including it into my PR was pretty simple.

However I can't get most of my test images to decode. They're working fine in Firefox and Chromium but your library throws me: apng: invalid format: not enough pixel data

A working example is the bouncing ball from the Wikipedia site about apng. I had no issues with it.

Everything else I tested isn't working, some examples:

Since I don't really know the internals of apng and this library I'm a bit lost why they're not working while they're playing fine in the browser. Are the examples just malformed apngs or is it something in the library?

kettek commented 4 years ago

Those are much larger files than I have used or tested so perhaps some sort of size-related issue.

I'll inspect this sometime tonight (PST).

kettek commented 4 years ago

Looking at the Firewatch apng -- it is broken, as only the first PNG frame should be tagged as IDAT and all subsequent frames should be fdAT. See this

Would it be possible to fix the source where these are coming from?

kettek commented 4 years ago

CORRECTION there are multiple IDAT chunks as per the spec, and that is due to the larger size.

This seems to be a logic error within the library.

kettek commented 4 years ago

Obviously inspected it bit earlier than predicted, but apng is now properly parsing the Firewatch APNG. I need to do additional tests before committing any changes, and as such, this will likely be committed tonight (PST).

Lucki commented 4 years ago

Those are much larger files

Since Steam is able to display APNGs in the library people are going crazy and are putting whole videos in the cover files. The examples above are some with only minor moving things but they're still huge.

Would it be possible to fix the source where these are coming from?

No, these examples are taken from steamgriddb.com and /r/steamgrid.

This seems to be a logic error within the library.

Not sure if this is great to hear but at least it will make this library better when fixed.

inspected it bit earlier than predicted […] will likely be committed tonight

No need to rush, take your time :wink:

kettek commented 4 years ago

I have updated apng with the appropriate fixes (and implemented some unit tests for the reader so we can ensure things work better going forward). Let me know if the changes work for you so I can close this issue.

Lucki commented 4 years ago

Reading seems to work now without an error. Thanks!

Sadly writing the same image into a file again makes the whole image distorted. I'm basically doing just a reading and writing of the file:

game.CleanImageBytes, err := ioutil.ReadFile(imagePath)
apngImage, err := apng.DecodeAll(bytes.NewBuffer(game.CleanImageBytes))
buf := new(bytes.Buffer)
err = apng.Encode(buf, apngImage)
game.OverlayImageBytes = buf.Bytes()
err = ioutil.WriteFile(imagePath, game.OverlayImageBytes, 0666)
Screenshot ![grafik](https://user-images.githubusercontent.com/1408843/68473990-aa739080-0224-11ea-9c67-b7ae397760fa.png)

Does the writer part also needs some adjustments to be able to write some bigger files?

kettek commented 4 years ago

The writing of multiple IDATs and fdATs looks like they are working properly, however it looks like subsequent animation frames (which are supposed to be blended) are improperly overlaid or something similar. I'll check the see what the potential problem is.

In the meanwhile, if you could create a separate issue for this problem, that would be great, as I am closing this particular issue due to it being fixed by c3e2ab8bf86b89ad3c1e950a70754966e8abe77a. See #2 for the encoding issue.