Magick.NET icon indicating copy to clipboard operation
Magick.NET copied to clipboard

MagickImageCollection\MagickImageInfo.ReadCollection issue with APNG

Open Bxaa opened this issue 3 years ago • 2 comments

Magick.NET version

Magick.NET-Q16-HDRI-OpenMP-x64 (12.1.0)

Environment (Operating system, version and so on)

Net6.0\Win10x64

Description

Hi, MagickImageInfo.ReadCollection(stream).Count retrun 1 for APNG

Also: New MagickImageCollection(stream) for APNG always return only first frame ---But--- New MagickImageCollection(stream, MagickFormat.APng) return all frames Simple fix for both cases - just force MagickFormat.APng format for all png's as priority by default (no issues with simple png's)

stream.position = 0 - It would be just great if you could add this inside MagickImageInfo.ReadCollection(stream) function (It would be very convenient if after the call it was not necessary to return the stream to the beginning manually and use it in lambda expressions)

Sample animated PNG (APNG) for tests: https://drive.google.com/file/d/1_P2vN8M8aeXmNmtulcWhLhkAYh2QxWAu/view?usp=sharing

Steps to Reproduce

--\--\--

Bxaa avatar Sep 17 '22 23:09 Bxaa

You will need to specify the format because the ImageMagick library cannot detect if the image is an APNG or PNG file. And the library cannot change the position of the stream to 0 because not everybody would want this kind of behavior.

dlemstra avatar Sep 18 '22 08:09 dlemstra

Hi,

APNG extensions are not used. PNGs are used for both animated and normal file types. I haven't encountered *.apng files at all Am I correct in assuming that your library doesn't distinguish them?

I mean to process all PNGs as APNGs as if MagickFormat.APng were specified. That would solve the problem (for both functions)

because not everybody would want this kind of behavior

I don't think so :)

Especially the first one is just getting information and it uses the stream at all just because it is implemented that way It's not like you're obviously reading a file and performing operations on it in a stream - just getting information about the file is implied. And if you're using a stream internally, you have to return the position of the stream to its original state after it's been used in your library.

This is normal behavior for most standard function in .Net Image.FromStream(stream) etc (resuming position to zero for used stream)

There's no way you can use a stream after calling MagickImageInfo.ReadCollection(stream) and MagickImageCollection(stream) and you still have to move the position to the beginning if the stream is needed later. So it just has to be done always manually.

Just simplified example MagickImageCollection i_list = ((Stream s) => MagickImageInfo.ReadCollection(s).Count() > 1 ? new MagickImageCollection(stream) : null)(stream);

So, you will get exeption: "Stream position is at the end of the stream. Make sure to reset the stream position to 0. (Parameter 'stream')"

This is a very very simplified example, imagine that it is all much more complicated...

Sorry my english :) Thx!

Bxaa avatar Sep 18 '22 11:09 Bxaa